Game Development Community

Long audio files screw up sound volumes after alxStop()

by Robert Rose · in Torque Game Engine · 02/16/2008 (1:25 am) · 2 replies

I've had background music working for a while, but now I'm trying to get the music to *stop* playing at a point in my game so I can emphasize certain sound effects.

The problem is this: If I stop playing the background music *all* other sound effects played from that point on are played about 1/10th their regular volume... until I *restart* the background music. It doesn't even have to be the same song file, it can be a different one, but for the gap in between I can barely hear anything.

I thought the problem might be my .ogg encoder so I tried a variety of different encoding options and even different encoding programs.. No help. I tried using .wav files instead of .ogg. No Help.

Then I discovered it has nothing to do with ogg or wav, but the *length* of the audio file. Long .wav files cause the volume to drop-off. Short, looping sound effects don't mess it up.

If I stop the music and leave it off, rather than turning it back on after 10-15 seconds, the volume seems to come back on its own after a certain period of time but I haven't measured it.

My music code is almost straight out of the examples:

$MusicAudioType   = 4;

new AudioDescription(AudioMusic)
{
     volume = 1.0;
     isLooping = true;
     is3D = false;
     type = $MusicAudioType;
};

new AudioProfile(LoadingMusicProfile)
{
   filename = "~/data/sound/bgmusic.ogg";
   description = "AudioMusic";
   preload = true;
};


function BGMStartLoading()
{
   $BGM::loading = alxPlay(LoadingMusicProfile);
   error("loading music is " @ $BGM::loading);
}

function BGMStopLoading()
{
   if($BGM::loading != 0)
   {
      error("stopping loading music");
      alxStop($BGM::loading);
   }
   
   $BGM::loading = 0;
}

Has anyone else encountered this? What gets me is it's still playing the sound effects, they're just 1/10th the previous volume.

#1
02/16/2008 (2:06 am)
I came up with the hackiest of hacky workarounds. I don't like this at all, but somehow continuing to play *something* fixes it.

new AudioProfile(LoadingMusicProfile)
{
   filename = "~/data/sound/bgmusic.wav";
   description = "AudioMusic";
   preload = true;
};

new AudioProfile(SilenceMusicProfile)
{
   filename = "~/data/sound/testing.ogg";
   description = "AudioMusic";
   preload = true;
};

function BGMStartLoading()
{
   $BGM::loading = alxPlay(LoadingMusicProfile);
   error("loading music is " @ $BGM::loading);
}

function BGMStopLoading()
{
   alxStop($BGM::loading);
   $BGM::loading = alxPlay(SilenceMusicProfile);
}
#2
02/16/2008 (2:14 am)
The plot thickens. I thought I'd try having the silence .ogg file not loop by doing this:

new AudioDescription(AudioMusic)
{
     volume = 1.0;
     isLooping = true;
     is3D = false;
     type = $MusicAudioType;
};

new AudioDescription(AudioMusicNoLoop)
{
     volume = 1.0;
     isLooping = false;
     is3D = false;
     type = $MusicAudioType;
};

new AudioProfile(LoadingMusicProfile)
{
   filename = "~/data/sound/bgmusic.ogg";
   description = "AudioMusic";
   preload = true;
};

new AudioProfile(SilenceMusicProfile)
{
   filename = "~/data/sound/testing.ogg";
   description = "AudioMusicNoLoop";
   preload = true;
};

function BGMStartLoading()
{
   $BGM::loading = alxPlay(LoadingMusicProfile);
   error("loading music is " @ $BGM::loading);
}

function BGMStopLoading()
{
   alxStop($BGM::loading);
   $BGM::loading = alxPlay(SilenceMusicProfile);
}

But this STILL causes it to loop. I think what's happening is the alxPlay that occurs right after the last alxStop is inheriting the stream/profile properties of the previous sound.