Jump to content


alutCreateBufferFromFileImage never works


6 replies to this topic

#1 jackskelyton

    New Member

  • Members
  • Pip
  • 9 posts

Posted 29 February 2008 - 09:38 PM

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;

   }


. . .



#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 29 February 2008 - 11:18 PM

Do you check alutGetError after the buffer creation fails and if so, what does it return?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 jackskelyton

    New Member

  • Members
  • Pip
  • 9 posts

Posted 01 March 2008 - 08:03 PM

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."

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 01 March 2008 - 08:56 PM

Sounds like ALUT is not getting initialized properly. When you call alutInit() does it return an error?
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 jackskelyton

    New Member

  • Members
  • Pip
  • 9 posts

Posted 01 March 2008 - 11:38 PM

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.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 02 March 2008 - 01:52 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 jackskelyton

    New Member

  • Members
  • Pip
  • 9 posts

Posted 03 March 2008 - 08:37 PM

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users