From 34a5de28f0b467ec3177da5b9516d06a69b07f58 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 2 Nov 2023 15:23:46 -0700 Subject: sfx: add volume control to sfx_play() Preparatory commit for experimenting with varying volumes based on distance. Impetus is an interest in making the TV clips always play when the TV appears, but vary the volume with distance. --- src/sfx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/sfx.c') diff --git a/src/sfx.c b/src/sfx.c index 04b0fbc..334833a 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -63,10 +63,16 @@ void sfx_init(void) } -void sfx_play(sfx_sound_t *sound) +/* play sfx, volume 0-1 */ +void sfx_play(sfx_sound_t *sound, float volume) { assert(sound); + if (volume > 1.f) + volume = 1.f; + else if (volume < 0.f) + volume = 0.f; + if (sound->chunk) { int channel; @@ -74,6 +80,7 @@ void sfx_play(sfx_sound_t *sound) if (channel < 0) channel = Mix_GroupOldest(sound->voice); + Mix_Volume(channel, MIX_MAX_VOLUME * volume); Mix_PlayChannel(channel, sound->chunk, 0); } } -- cgit v1.2.3