From ad55de1e7e0d9fad2a06a26435579d067fbc63a6 Mon Sep 17 00:00:00 2001 From: Buginator Date: Sun, 11 Jul 2010 16:59:58 +0000 Subject: [PATCH] Prevent overlapping sounds when looking at intel information. fixes ticket:60 2.3: r11147 trunk: r11148 git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/branches/qt-trunk@11149 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/sound/openal_track.c | 24 ++++++++++++++++++++++++ lib/sound/track.h | 1 + src/intelmap.c | 24 ++++++++++++++++-------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/sound/openal_track.c b/lib/sound/openal_track.c index 4d913fcb0..b2a497d67 100644 --- a/lib/sound/openal_track.c +++ b/lib/sound/openal_track.c @@ -956,6 +956,30 @@ AUDIO_STREAM* sound_PlayStreamWithBuf(PHYSFS_file* fileHandle, float volume, voi #endif } +/** Checks if the stream is playing. + * \param stream the stream to check + * \post true if playing, false otherwise. + * + */ +BOOL sound_isStreamPlaying(AUDIO_STREAM *stream) +{ +#if !defined(WZ_NOSOUND) + ALint state; + + if (stream) + { + alGetSourcei(stream->source, AL_SOURCE_STATE, &state); + sound_GetError(); + if (state == AL_PLAYING) + { + return true; + } + } + return false; + +#endif +} + /** Stops the current stream from playing. * \param stream the stream to stop * \post The stopped stream will be destroyed on the next invocation of diff --git a/lib/sound/track.h b/lib/sound/track.h index 005811286..e795c9b56 100644 --- a/lib/sound/track.h +++ b/lib/sound/track.h @@ -130,6 +130,7 @@ void sound_SetStoppedCallback( AUDIO_CALLBACK pStopTrackCallback ); UDWORD sound_GetTrackTimeLastFinished( SDWORD iTrack ); void sound_SetTrackTimeLastFinished( SDWORD iTrack, UDWORD iTime ); +extern BOOL sound_isStreamPlaying(AUDIO_STREAM *stream); extern void sound_StopStream(AUDIO_STREAM* stream); extern void sound_PauseStream(AUDIO_STREAM* stream); extern void sound_ResumeStream(AUDIO_STREAM* stream); diff --git a/src/intelmap.c b/src/intelmap.c index 209c89a28..4b22930dc 100644 --- a/src/intelmap.c +++ b/src/intelmap.c @@ -62,6 +62,7 @@ #include "multiplay.h" #include "lib/sound/cdaudio.h" #include "lib/sequence/sequence.h" +#include "lib/sound/track.h" #include "scriptextern.h" @@ -968,32 +969,39 @@ void intIntelButtonPressed(BOOL proxMsg, UDWORD id) if (psResearch != NULL) { static const float maxVolume = 1.f; + static AUDIO_STREAM *playing = NULL; + + // only play the sample once, otherwise, they tend to overlap each other + if (sound_isStreamPlaying(playing)) + { + sound_StopStream(playing); + } switch(psResearch->iconID) { case IMAGE_RES_DROIDTECH: - audio_PlayStream("sequenceaudio/res_droid.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_droid.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_WEAPONTECH: - audio_PlayStream("sequenceaudio/res_weapons.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_weapons.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_COMPUTERTECH: - audio_PlayStream("sequenceaudio/res_com.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_com.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_POWERTECH: - audio_PlayStream("sequenceaudio/res_pow.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_pow.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_SYSTEMTECH: - audio_PlayStream("sequenceaudio/res_systech.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_systech.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_STRUCTURETECH: - audio_PlayStream("sequenceaudio/res_strutech.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_strutech.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_CYBORGTECH: - audio_PlayStream("sequenceaudio/res_droid.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_droid.ogg", maxVolume, NULL, NULL); break; case IMAGE_RES_DEFENCE: - audio_PlayStream("sequenceaudio/res_strutech.ogg", maxVolume, NULL, NULL); + playing = audio_PlayStream("sequenceaudio/res_strutech.ogg", maxVolume, NULL, NULL); break; } }