diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-29 16:15:48 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-29 16:15:48 +0000 |
commit | 6900aeb414c3f26b5bd51c90e0f700f7bf138d2a (patch) | |
tree | 45ffa300065b3221dcbcbb5e8544e6712683198d /src/audio.c | |
parent | 52fc29e109b087342abe432b6ffa563d7172d6e7 (diff) |
Command-line option for audio debugging
Make clipping sound a little less horrendous (still pretty bad)
Count number of clipped samples
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@114 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/audio.c b/src/audio.c index 8e84c5e..6735665 100644 --- a/src/audio.c +++ b/src/audio.c @@ -21,7 +21,7 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { AudioContext *a = data; - int i, j; + int i, j, clip_count; Sint16 *stream = (Sint16 *)stream8; len /= 2; /* Samples */ @@ -32,6 +32,7 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { } /* For each currently playing sound... */ + clip_count = 0; for ( i=0; i<AUDIO_MAX_SOUNDS; i++ ) { /* Playing? */ @@ -40,9 +41,18 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { for ( j=0; j<len; j++ ) { Sint16 samp; + Sint32 test; samp = a->sounds[i].data[a->sounds[i].dpos++]; - stream[j] += samp * a->sounds[i].volume; + test = stream[j] + samp*a->sounds[i].volume; + if ( test > 32767 ) { + if ( stream[j] != 32767 ) { + clip_count++; + } + stream[j] = 32767; + } else { + stream[j] += samp * a->sounds[i].volume; + } if ( a->sounds[i].dpos == a->sounds[i].dlen ) { if ( a->sounds[i].repeat ) { @@ -60,6 +70,8 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { } + if ( a->debug && (clip_count > 0) ) printf("AU: Clipped %i samples.\n", clip_count); + } void audio_play(AudioContext *a, char *file, float volume, int repeat) { @@ -108,7 +120,7 @@ void audio_play(AudioContext *a, char *file, float volume, int repeat) { } /* SDL audio initial setup */ -AudioContext *audio_setup() { +AudioContext *audio_setup(int debug) { AudioContext *a; SDL_AudioSpec fmt; @@ -119,7 +131,7 @@ AudioContext *audio_setup() { if ( a == NULL ) return NULL; /* Initialise audio context */ - a->debug = 0; + a->debug = debug; for ( i=0; i<AUDIO_MAX_SOUNDS; i++ ) { a->sounds[i].inuse = 0; } |