* Add functions for changing the volume of an already created AUDIO_STREAM: sound_GetStreamVolume and sound_SetStreamVolume

* Use these functions in cdaudio.c to change the volume of the currently playing AUDIO_STREAM in function sound_SetMusicVolume

This fixes bug #11579 ("Music volume slider dont work")


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5101 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-05-13 14:01:25 +00:00
parent 44986c3473
commit 5828b26a10
3 changed files with 34 additions and 1 deletions

View File

@ -210,5 +210,9 @@ void sound_SetMusicVolume(float volume)
music_volume = 1.0;
}
/// @TODO Implement code to set the volume of the currently playing stream here
// Change the volume of the current stream as well (if any)
if (cdStream)
{
sound_SetStreamVolume(cdStream, music_volume);
}
}

View File

@ -815,6 +815,33 @@ void sound_ResumeStream(AUDIO_STREAM* stream)
sound_GetError();
}
/** Retrieve the playing volume of the given stream.
*
* @param stream the stream to retrieve the volume for.
*
* @return a floating point value between 0.f and 1.f, representing this
* stream's volume.
*/
float sound_GetStreamVolume(const AUDIO_STREAM* stream)
{
ALfloat volume;
alGetSourcef(stream->source, AL_GAIN, &volume);
return volume;
}
/** Set the playing volume of the given stream.
*
* @param stream the stream to change the volume for.
* @param volume a floating point value between 0.f and 1.f, to use as this
* @c stream's volume.
*/
void sound_SetStreamVolume(AUDIO_STREAM* stream, float volume)
{
stream->volume = volume;
alSourcef(stream->source, AL_GAIN, stream->volume);
}
/** 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

@ -127,6 +127,8 @@ extern void sound_StopStream(AUDIO_STREAM* stream);
extern void sound_PauseStream(AUDIO_STREAM* stream);
extern void sound_ResumeStream(AUDIO_STREAM* stream);
extern AUDIO_STREAM* sound_PlayStreamWithBuf(PHYSFS_file* fileHandle, float volume, void (*onFinished)(void*), void* user_data, size_t streamBufferSize, unsigned int buffer_count);
extern float sound_GetStreamVolume(const AUDIO_STREAM* stream);
extern void sound_SetStreamVolume(AUDIO_STREAM* stream, float volume);
#if defined(__cplusplus)
}