Game Development Community

Stop the Music!

by Aaron Levine · in General Game Discussion · 08/13/2003 (8:47 pm) · 3 replies

Hey guys,

I'm trying to play a short intro music to my game, however the music keeps looping on me.

Here is my code, The music starts fine and sounds great, but just wont stop

Device_Music->Insert                ("Music\NNWMusic.wav", true, true, true);
Device_Music->SetVolume             (1.0f);
Device_Music->Play                  (false);

From what I have read, this should normally work and NOT loop.

I also tried to turn off streaming...
Device_Music->Insert                ("Music\NNWMusic.wav", true, true, false);
Device_Music->SetVolume             (1.0f);
Device_Music->Play                  (false);

I chased the code a little bit, and discovered in RE_MUSIC_Device.cpp

void MUSIC_Device::Play(bool loop)
{
  .
  .
  .
    if (!Muted)
        Device_Sound->Play(ID, true, GetVolume());
  .
  .
  .
}

From that, it looks like the play command is hardcoded to always loop!

I was able to get it to stop looping if
1) I changed the hardcoded true to the variable loop AND
2) My music was NOT flagged to be streaming in the Device_Music->Insert(...)

So first, is this a bug?

Second whats the advantage of having Streaming on vs. off when I insert it?

Its late, and I just dont want to chase any code any more...

Thanks for any help

#1
08/14/2003 (9:15 am)
You did find a bug! I'll fix it right now. It will be available in the upcoming release.

Music is often a giant .wav file and reloading the file is unnecessary and wastes machine resources. So most often you'll want to stream your music.

Ultimately we going to support the ogg loading and streaming, however this is somewhat platform specific code and we're just in the middle of the first platform specific port of the engine. So the ogg support will have to wait until we get a good working version of the engine on all platforms.

Great job finding the bug!

Chris
#2
08/21/2003 (6:01 pm)
Chris, did you also fix the problem where streaming also restarts?

If you fix the
...
// Device_Sound->Play(ID, true, GetVolume());
- to -
Device_Sound->Play(ID, loop, GetVolume());
...
in RE_MUSIC_Device.cpp this will correct the problem if you are not using streaming.

However this will not fix the problem if you are using streaming. What happens in that case is that the tail end of the music buffer is played over and over.

If it is fixed in both cases, can you send me the streaming fix, im scratching my head as to where/how to fix it.

Thanks
#3
08/22/2003 (8:48 am)
Yeah I fixed both bugs. The streaming fix was more complicated than the looping bug. It was deep in the UpdateStream method.

I'll send you the new files.