Implement sound_StopStream, sound_PauseStream and sound_ResumeStream for stopping, pausing and resuming of playing streams initially created with sound_PlayStream

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3578 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-01-27 21:33:10 +00:00
parent 6de5602631
commit f880720628
2 changed files with 65 additions and 0 deletions

View File

@ -724,6 +724,67 @@ AUDIO_STREAM* sound_PlayStream(PHYSFS_file* fileHandle, float volume, void (*onF
return stream;
}
/** Stops the current stream from playing.
* \param stream the stream to stop
* \post The stopped stream will be destroyed on the next invocation of
* sound_UpdateStreams(). So calling this function will result in the
* \c onFinished callback being called and the \c stream pointer becoming
* invalid.
*/
void sound_StopStream(AUDIO_STREAM* stream)
{
assert(stream != NULL);
// Tell OpenAL to stop playing on the given source
alSourceStop(stream->source);
sound_GetError();
}
/** Pauses playing of this stream until playing is resumed with
* sound_ResumeStream() or completely stopped with sound_StopStream().
* \param stream the stream to pause playing for
*/
void sound_PauseStream(AUDIO_STREAM* stream)
{
ALint state;
// To be sure we won't go mutilating this OpenAL source, check wether
// it's playing first.
alGetSourcei(stream->source, AL_SOURCE_STATE, &state);
sound_GetError();
if (state != AL_PLAYING)
{
return;
}
// Pause playing of this OpenAL source
alSourcePause(stream->source);
sound_GetError();
}
/** Resumes playing of a stream that's paused by means of sound_PauseStream().
* \param stream the stream to resume playing for
*/
void sound_ResumeStream(AUDIO_STREAM* stream)
{
ALint state;
// To be sure we won't go mutilating this OpenAL source, check wether
// it's paused first.
alGetSourcei(stream->source, AL_SOURCE_STATE, &state);
sound_GetError();
if (state != AL_PAUSED)
{
return;
}
// Resume playing of this OpenAL source
alSourcePlay(stream->source);
sound_GetError();
}
/** Update the given stream by making sure its buffers remain full
* \param stream the stream to update
* \return true when the stream is still playing, false when it has stopped

View File

@ -134,4 +134,8 @@ void sound_SetStoppedCallback( AUDIO_CALLBACK pStopTrackCallback );
UDWORD sound_GetTrackTimeLastFinished( SDWORD iTrack );
void sound_SetTrackTimeLastFinished( SDWORD iTrack, UDWORD iTime );
extern void sound_StopStream(AUDIO_STREAM* stream);
extern void sound_PauseStream(AUDIO_STREAM* stream);
extern void sound_ResumeStream(AUDIO_STREAM* stream);
#endif // _TRACK_H_