Game Development Community

Sounds get mixed up

by Eric Hartman · in Torque Game Engine · 06/18/2004 (8:22 pm) · 48 replies

Surely theres a thread about this but I cant seem to find it.

When you join or host a game, disconnect, then re-join or re-host, the sounds get mixed up. In starter.fps all the different crossbow sounds become the explosion sound or in my game when you run the footstep sound is the thunder sound. It happens every single time.
Page«First 1 2 3 Next»
#41
04/03/2005 (9:17 am)
It took me a while to hunt this bug down, and here is the fix for it.

engine/audio/audioBuffer.cc
ALuint AudioBuffer::getALBuffer()
{
.
.
.
  // before exiting the function and right after 
  alDeleteBuffers(1, &malBuffer);

  // (add this) clear the tag
   malBuffer = 0;

   return 0;
}
What was happening was that when reading a .wav or .ogg file fails (above the instructions, not shown) the malBuffer is released but the tag is not cleared. So, in subsequent entries to this function another audio file would actually allocate the same buffer then a previously failed attempt will reenter the function and validate a false malBuffer tag with this instruction
if (alIsBuffer(malBuffer))
   {
      return malBuffer;
   }

Second bug is not related to "sound getting mixed up", but prevents a memory leak.
Resource<AudioBuffer> AudioBuffer::find(const char *filename)
{
.
.
.
// replace the existing [i]else if[/i] statement with this
      else if (f2 && ResourceManager->getPathOf(f2))
      {
         buffer = ResourceManager->load(f2);
         if (bool(buffer) == false)
         {
            AudioBuffer *temp = new AudioBuffer(StringTable->insert(f2));
            ResourceManager->add(f2, temp);
            buffer = ResourceManager->load(f2);
         }
      }
.
.
.
}
This eliminates new AudoBuffer being created on every entry to this condition.
edit: corrected typos
edit: added the second load(f2)
edit: corrected some verbage
#42
04/03/2005 (9:59 am)
Akio, thanks for the malbuffer 0 find..

for the second one, do you not still need the resmanager->load called after you add it ? I haven't looked at it close enough to tell yet.
#43
04/03/2005 (10:11 am)
Clint,
Yes, very good find. I left that out when removing some debug dumps. Let me edit the above comment.
#44
04/03/2005 (10:27 am)
Nice work Akio !
Time for some testing :)
#45
04/03/2005 (10:33 am)
Ahh ok. I see right above that chunk of code. it looks like it thinks it's trying to load the ogg, but just tries to load the wav again..

here:
if (bool(buffer) == false)
   {
      // wav file doesn't exist, try ogg file instead
      S32 len = dStrlen(filename);
      if (len>3 && !dStricmp(filename+len-4,".wav"))
      {
         f2 = (char*)FrameAllocator::alloc(len+1);
         dStrcpy(f2,filename);
         f2[len-3] = 'o';
         f2[len-2] = 'g';
         f2[len-1] = 'g';
         buffer = ResourceManager->load(filename);
      }
   }


that ResourceManager->load should be using f2

then you don't have to do your buffer checks inside that loop I think as it'll never get there more than once for a given file.

6 in one hand, half a dozen in the other :)
#46
04/03/2005 (10:41 am)
Clint,
Yes, I see what you're talking about. If you change the load to
if (bool(buffer) == false)
   {
      // wav file doesn't exist, try ogg file instead
      S32 len = dStrlen(filename);
      if (len>3 && !dStricmp(filename+len-4,".wav"))
      {
         f2 = (char*)FrameAllocator::alloc(len+1);
         dStrcpy(f2,filename);
         f2[len-3] = 'o';
         f2[len-2] = 'g';
         f2[len-1] = 'g';
         buffer = ResourceManager->load(f2);
      }
   }
Then my original fix in this routine can be removed.

Good find, again:)
#47
04/03/2005 (2:18 pm)
On my list to review this for 1.4
#48
04/08/2005 (12:39 pm)
There is also an issue with sounds and 4x4 vehicles. www.garagegames.com/mg/forums/result.thread.php?qt=21938
this thread explains it alot better than I ever could. I definitely think Torque needs a major overhaul in the sound department. glad to hear you are working on that in 1.4 Ben :).
Page«First 1 2 3 Next»