Strange error

Lazarus

08-05-2008 16:04:02

Hi!

First of all sorry for my bad english.
I want to port my project's sound class from Fmod to OgreAL, everything go well but after a few played sound files it is become crazy and play wrong files. (example if i want to play reload.wav it plays shot.wav instead, and play reload.wav later... at wrong time)

This is the class

int channel = 0;
#define MAX_SOUND_CHANNEL 29
bool loop_channel[MAX_SOUND_CHANNEL] = {false};

class zahSound
{
public:

OgreAL::Sound *sound;
Ogre::String name;

zahSound()
{
}

void init(int id)
{
name = "sound_" + toStr(id);
}

void play(Ogre::String file_name, bool loop, int volume, float pitch = 1)
{
if(volume > 0 && options_sound_volume > 0)
{
// delete prev sound, if it is exist
if(soundManager->hasSound(name))
soundManager->destroySound(name);

// load sound
sound = soundManager->createSound(name, file_name, loop);

// set volume sound->setGain((((float)volume)/200)*options_sound_volume);

// set speed
sound->setPitch(pitch*slow_time);

// play
sound->play();

// remember if it is looped
if (loop == true)
loop_channel[channel] = true;

// set next channel
while (true)
{
channel++;

if(channel > MAX_SOUND_CHANNEL)
channel = 1;

if (loop_channel[channel] == false) // if this channel is not looped
break;
}
}
}

void unload(int setChannel)
{
if(soundManager->hasSound(name))
soundManager->destroySound(name);

loop_channel[setChannel] = false;
}

void setFreq(int pitch)
{
sound->setPitch(pitch*slow_time);
}

void setVolume(float vol)
{
sound->setGain((((float)vol)/200)*options_sound_volume);
}

void setPaused(bool pause)
{
if(sound->isPaused() && pause == false)
sound->pause();
else if(!sound->isPaused() && pause == true)
sound->pause();
}
};

zahSound sounds[MAX_SOUND_CHANNEL];


This is how i play them
sounds[channel].play("shot.ogg", false, 800, rand(0.9, 1.1));

Maybe soundManager->destroySound(name); is not the proper way to destroy them?

Thanks!

pra

09-05-2008 09:31:31

i had that one once, too, i even submitted a workaround patch to SVN, but it wasn't accepted (yet?)
it seems the buffers get mixed up under certain circumstances, i'm not sure why, though.. I haven't solved that one, I decided to implement OpenAL myself...

And soundManager->destroySound(name); is the proper way, at least it should be.

Lazarus

09-05-2008 11:13:24

The Sound::unqueueBuffers() right? I found it, applied into OgreALSound.cpp, rebuilded the libaries, but nothing changed.