diff options
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/audio.c b/src/audio.c index e282f94..5ac4b13 100644 --- a/src/audio.c +++ b/src/audio.c @@ -32,15 +32,16 @@ static void audio_mix(void *data, Uint8 *stream, int len) { for ( i=0; i<AUDIO_MAX_SOUNDS; i++ ) { if ( !a->sounds[i].inuse ) continue; - amount = (a->sounds[i].dlen - a->sounds[i].dpos); + if ( amount > len ) { /* The sound remaining in this channel more than fills the buffer */ amount = len; } for ( j=0; j<amount; j++ ) { - stream[j] += a->sounds[i].data[a->sounds[i].dpos + j]; + float samp = a->sounds[i].data[a->sounds[i].dpos + j]; + stream[j] += samp * a->sounds[i].volume; } a->sounds[i].dpos += amount; @@ -57,9 +58,9 @@ static void audio_mix(void *data, Uint8 *stream, int len) { } -void audio_play(AudioContext *a, char *file, float volume) { +void audio_play(AudioContext *a, char *file, float volume, int repeat) { - int idx, i; + int idx; SDL_AudioSpec wave; Uint8 *data; Uint32 dlen; @@ -89,21 +90,14 @@ void audio_play(AudioContext *a, char *file, float volume) { SDL_ConvertAudio(&cvt); SDL_FreeWAV(data); - /* Perform volume adjustment here */ - int16_t *aud = (int16_t *)cvt.buf; - for ( i=0; i<dlen/2; i++ ) { - float samp = aud[i]; - samp *= volume; - aud[i] = samp; - } - /* Put the sound data in the slot */ SDL_LockAudio(); - a->sounds[idx].data = cvt.buf; + a->sounds[idx].data = (Uint16 *)cvt.buf; a->sounds[idx].dlen = cvt.len_cvt; a->sounds[idx].dpos = 0; a->sounds[idx].inuse = 1; - a->sounds[idx].repeat = 1; + a->sounds[idx].repeat = repeat; + a->sounds[idx].volume = volume; SDL_UnlockAudio(); } @@ -139,7 +133,7 @@ AudioContext *audio_setup() { } SDL_PauseAudio(0); - audio_play(a, "moan", 0.4); + audio_play(a, "moan", 0.4, 1); return a; |