diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-29 13:14:01 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-29 13:14:01 +0000 |
commit | 570900e819a69a5c522640f2ec48e3802ce4fda9 (patch) | |
tree | e56aa87e5f1b4bd96145bfac772a77ce0adc425a /src/audio.c | |
parent | d59df6ab625af566cf7efb44f374c95c48c809a5 (diff) |
Audio stuff (broken)
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@110 84d2e878-0bd5-11dd-ad15-13eda11d74c5
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; |