Author Topic: My findings on how to prevent a sound from overlaping itself  (Read 1623 times)

0 Members and 1 Guest are viewing this topic.

argoon

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
My findings on how to prevent a sound from overlaping itself
« on: November 05, 2017, 02:09:24 PM »
After many hours of trying to prevent a sound from playing over itself, when pressing a key continuously and inside the player think loop, after going trough the engine code i found some ways to solve this.

One:

Code: [Select]
const idSoundShader *sound = declManager->FindSound( "sound_name" );
// this above is not really necessary you can do the following instead if you want.
//...StartSound( declManager->FindSound( "sound_name" ), SND_CHANNEL_BODY );

// get the sound emitter (speaker) binded to the ingame entity, btw i tried to get a emitter directly from the master entity but it didn't found any and crashed the engine, why i don't know,
// is strange because afaik all entities can be "speakers"...
idSoundEmitter *emit = gameLocal.FindEntity( "some_speaker" )->GetSoundEmitter( );
if (!( emit->CurrentlyPlaying( ) )) // if sound is not playing
{
        // play it
emit->StartSound( sound, SND_CHANNEL_BODY);
}

Two:

Code: [Select]
const idSoundShader *sound = declManager->FindSound( "sound_name" );
idSoundEmitter *emit = gameLocal.FindEntity( "some_speaker" )->GetSoundEmitter( );
emit->StartSound( sound, SND_CHANNEL_BODY, 0, SSF_PLAY_ONCE ); // SSF_PLAY_ONCE prevents the sound from playing again if it is already playing


Three:  If you don't create a emiter object like above and call the sound directly from a entity it also works. :)

Code: [Select]
const idSoundShader *sound = declManager->FindSound( "sound_name" );
Entity->StartSoundShader( sound, SND_CHANNEL_BODY, SSF_PLAY_ONCE, false, NULL );
« Last Edit: November 05, 2017, 03:16:28 PM by argoon »