Prevent overlapping sounds when looking at intel information.

fixes ticket:60

2.3:r11147

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@11148 4a71c877-e1ca-e34f-864e-861f7616d084
master
Buginator 2010-07-11 16:57:21 +00:00 committed by Git SVN Gateway
parent 2e7466cbe8
commit 0dca1b06a1
3 changed files with 41 additions and 8 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;
}
}