0
101 Feb 29, 2008 at 21:38

I’m trying to get sounds loaded from memory rather than a file, and I’ve found the alutCreateBufferFromFile and alutCreateBufferFromFileImage methods, so I tried replacing my alutLoadWAVFile as you can see below, but the function always returns 0. I know the path and sound file are good because it works perfectly with alutLoadWAVFile. Anyone got any ideas?

ALboolean Sound::LoadWav() {

alGenSources(1, &mSource);
if (alGetError() != AL_NO_ERROR) {
return AL_FALSE;
}

//alutLoadWAVFile((char*)mFilePath.GetCString(), &format, &data, &size, &freq, &loop);
alGetError();
ALuint mBuffer = alutCreateBufferFromFile("test/sounds/FancyPants.wav");
if (mBuffer ==  AL_NONE) {
return AL_FALSE;
}

. . .


6 Replies

0
167 Feb 29, 2008 at 23:18

Do you check alutGetError after the buffer creation fails and if so, what does it return?

0
101 Mar 01, 2008 at 20:03

I changed the buffer creation block to this:

ALenum foo = alutGetError();
mBuffer = alutCreateBufferFromFile("test/sounds/FancyPants.wav");
ALenum bar = alutGetError();
const char* error = alutGetErrorString(bar);


foo = 0, bar = 515, and the error string read “The operation was invalid in the current ALUT state.”

0
167 Mar 01, 2008 at 20:56

Sounds like ALUT is not getting initialized properly. When you call alutInit() does it return an error?

0
101 Mar 01, 2008 at 23:38

I don’t call alutInit. I use an explicit context creation:

   mCurrentDevice = alcOpenDevice(NULL);

if (mCurrentDevice == NULL) {
return AL_FALSE;
}
alcGetError(mCurrentDevice);

mCurrentContext = alcCreateContext(mCurrentDevice, NULL);
if (!mCurrentContext) {
return AL_FALSE;
}

alcMakeContextCurrent(mCurrentContext);
alGetError();

return AL_TRUE;
}


But as I described, I can use alutLoadWAVFile and it works just fine.

0
167 Mar 02, 2008 at 01:52

Well, I haven’t actually used OpenAL or ALUT myself, so I could be wrong. But it looks from the docs as if alutLoadWAVFile is a deprecated function and perhaps it doesn’t require ALUT to be initialized at all.

Anyway, ALUT does offer initialization routines and your practice of using it without ever initializing it is suspect, I think. I bet if you initialize it (using alutInitWithoutContext() since you create the context yourself), your problems will go away. Correspondingly you should call alutExit() someplace in your shutdown code.

0
101 Mar 03, 2008 at 20:37

Ah, that was it after all. I recall that I removed the alutInit line after it caused a crash, but I bet if it was trying to init the context after I had already done so, that’s not surprising. alutInitWithoutContext works fine. Thanks!