Problem with large wav file?

Bagheera

13-02-2007 15:35:00

Here's the code:


soundManager = new OgreAL::SoundManager();

OgreAL::Sound *sound = soundManager->createSound("AWing", "AWing.wav", true);
sound->setRelativeToListener(true);
sound->play();

OgreAL::Sound *bgSound = soundManager->createSound("FinalDuel", "FinalDuel.wav", true);
bgSound->setRelativeToListener(true);
bgSound->play();


If I comment out the 2nd block, the game loads up and loops the sound correctly. If I uncomment the 2nd block (which means loading a 25 MBs wav file into memory), an exception is thrown during loading of the game (before I can see anything) detailing:

(In the log file)

17:18:39: *-*-* OgreAL Initialization
17:18:39: MovableObjectFactory for type 'OgreAL_Sound' registered.
17:18:39: MovableObjectFactory for type 'OgreAL_Listener' registered.
17:18:39: *-*-* Creating OpenAL
17:18:39: OpenAL Devices: NVIDIA(R) nForce(TM) Audio, Generic Hardware, Generic Software,
17:18:39: Choosing: NVIDIA(R) nForce(TM) Audio
17:18:39: Supported Formats
17:18:39: -----------------
17:18:39: EAX 2.0 Detected
17:18:39: Termination handler: uncaught exception!
17:18:39: Unregistering ResourceManager for type BspLevel
17:18:39: *-*-* OGRE Shutdown


And in the exception thrown dialog:
Error #3
Function: OgreAL::Sound::~Sound
Description: OpenAL Error: There is no current context.
Stack unwinding: <<beginning of stack>>


I guess I shouldn't load a wav file that big into memory anyway... I tried using the stream function and it said that streaming wave files is not supported. I can use an application to convert it to ogg and stream, but I am wondering still - What is the problem here?

CaseyB

13-02-2007 17:50:35

Hmmm, I see a couple of weird things going on here! If you look at the log file you posted, the list of supported formats is empty! That's odd because it should even list things like Monophonic sound! That probably doesn't have anything to do with why it's failing, it's just strange. It could be failing because of some OpenAL / alut imposed max buffer size. I'll look into that tonight and see what I can find. Have you though about compressing the sound into an Ogg file and streaming it?

kinggori

13-02-2007 18:17:03

i was looking at some old code I had in ogre that a friend of mine was working on and he used to set a buffer size. I don't know what this is or how it works so sorry i can't really help further.

If you want to convert wav to ogg as CaesyB sugeested here is a free app that does that:
http://www.mgshareware.com/frmmain.shtml

Bagheera

13-02-2007 19:14:51

I doubt it's a problem with OpenAL Casey as I've used the library before with my previous project and played the exact same .wav file (which is the reason I've tried it now) and it worked alright. I'll look through the code I used to loat it into memory soon and post it...

CaseyB

13-02-2007 19:23:12

WavSound::WavSound(Ogre::String name, Ogre::String soundFile, bool loop, AudioFormat format) : Sound(name)
{
alGenBuffers(1, &mBuffer);
checkError(__FUNCTION__);

ALbyte* filename = reinterpret_cast<ALbyte*>(const_cast<char*>(soundFile.c_str()));
alutLoadWAVFile(filename, &mFormat, &mData, &mSize, &mFreq, &mLoop);

// Use a different buffer format?
FormatData *formatData = SoundManager::getSingleton().retrieveFormatData(format);
if(formatData)
mFormat = formatData->formatEnum;

alBufferData(mBuffer, mFormat, mData, mSize, mFreq);
alutUnloadWAV(mFormat, mData, mSize, mFreq);

mLoop = loop?AL_TRUE:AL_FALSE;

createAndBindSource();
}
Here's the code that I use to create the source and buffer for a WavSound. As you can see, I pass mSize into the alutLoadWAVFile where it gets set to the size of the file that was loaded and then I use that size to load the OpenAL buffer. You can try setting a break point at the alutLoadWAVFile() line in OgreALWavSound.cpp and see what the size returned from that is. If it's an alut problem then I'll rethink how this is done becuase alut is depricated anyway.

Bagheera

13-02-2007 21:33:16

For clarification: After I made my previous post I remembered that my previous project stopped playing large wav files (IE the music files) too, but since I didnt check for ALErrors it didnt crash, just never played the music files. I never checked into this since it was after I was already done with the project, but I suspect it had something to do with upgrading the OpenAL version to a newer 1.1 or some such...

Also I stopped your code and it crashes at the following function:


void Sound::createAndBindSource()
{
if(SoundManager::getSingleton().xRamSupport())
{
SoundManager::getSingleton().eaxSetBufferMode(1, &mBuffer, SoundManager::xRamHardware);
}

alGenSources(1, &mSource);
initSource();
checkError(__FUNCTION__);

alSourcei(mSource, AL_BUFFER, mBuffer);
checkError(__FUNCTION__); }


It generates an AL Error at the alSourcei function, and an exception is thrown in the following checkError. I checked the mSize parameter you talked about and it does work, the value makes perfect sense (It was indeed the number of bytes in the actual file). For some reason it cannot stick the newly created source to the buffer...

CaseyB

13-02-2007 21:54:42

Awesome job debugging, I appreciate that! I'll look into it! Just to warn you I most likely wont get a chance until early next week. If you have some kind of web hosting could you put that file up and PM me so I can try the same test case that you have?

Bagheera

13-02-2007 22:05:06

Sadly I don't =/ It's a 27 MBs .wav music file, nothing fancy.

Let's see - 44.1 KHz, 2 channel, 16 bits per sample.




Sadly a new problem arrised - I converted it to .ogg, and used createSoundStream. Didn't work - here's the exception:

Same "no current context" error, however in a different function:
OgreAL::Sound:initSource.


Sorry for causing so much trouble =p

CaseyB

13-02-2007 22:09:26

Sorry for causing so much trouble =pIt's not trouble, it's user acceptability testing! :D I'm just glad that you give such good descriptions!

I think this may be linked to the weird thing where it's not listing any supported buffer types. Seems you've got a decent enough sound card... I'm not sure about that one!

Bagheera

13-02-2007 22:12:16

And it can still play a short .wav file. So at least .wav buffer type must be supported =p

CaseyB

13-02-2007 22:18:14

By buffer type it mean things like Monophonic, Stereo, 5.1 Channel, etc. So if it can't find a supported type that means it shouldn't play at all! Which is obviously wrong if it's playing your short wav file!

Bagheera

13-02-2007 23:41:36

Ok check it out:

First I determined that generally my application is ok by placing the ogg music you play in your basic demo in mine and streaming that - it works. So I thought maybe my ogg is bad - I tried it with the PlayOggVorbis sample app that comes with the OpenAL 1.1 SDK - and it works. So the ogg itself that I use is fine.

You can look at the source code for the PlayOggVorbis32 and compare, see if there's any ogg vorbis formats you're missing or some such. That's the only explanation I have for why OgreAL would play one .ogg file but not another... I'd do this myself but I'm too lazy and I'm working on other areas of my project in the mean time =p

PS: While I was at it, I tried letting the "PlayStatic" openal sdk example to play my long .wav music file, and it failed. So... It's not you, it's openal! =D

CaseyB

14-02-2007 00:02:48

You can look at the source code for the PlayOggVorbis32 and compare, see if there's any ogg vorbis formats you're missing or some such.I'll look into that, thanks!

PS: While I was at it, I tried letting the "PlayStatic" openal sdk example to play my long .wav music file, and it failed. So... It's not you, it's openal! =DHA! Good to know! :wink: