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 | |
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')
-rw-r--r-- | src/audio.c | 20 | ||||
-rw-r--r-- | src/audio.h | 2 | ||||
-rw-r--r-- | src/game.c | 4 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/main.c | 5 |
5 files changed, 24 insertions, 9 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; } diff --git a/src/audio.h b/src/audio.h index 703f6c0..769b398 100644 --- a/src/audio.h +++ b/src/audio.h @@ -18,7 +18,7 @@ #include "types.h" -extern AudioContext *audio_setup(void); +extern AudioContext *audio_setup(int debug); extern void audio_shutdown(AudioContext *ctx); extern void audio_play(AudioContext *a, char *file, float volume, int repeat); @@ -224,7 +224,7 @@ static void game_load_all_connected(Game *game) { } /* Create a new "game" structure */ -Game *game_new(int width, int height, int disable_vbos, int disable_fbos, int disable_shaders) { +Game *game_new(int width, int height, int disable_vbos, int disable_fbos, int disable_shaders, int audio_debug) { Game *g; @@ -261,7 +261,7 @@ Game *game_new(int width, int height, int disable_vbos, int disable_fbos, int di /* Note: render_setup() initialises GLEW, which must be done before loading models. */ /* Audio setup */ - g->audio = audio_setup(); + g->audio = audio_setup(audio_debug); if ( g->audio == NULL ) { fprintf(stderr, "Couldn't initialise audio\n"); free(g); @@ -21,7 +21,7 @@ #include "types.h" extern void game_check_handoff(Game *game); -extern Game *game_new(int width, int height, int disable_vbos, int disable_fbos, int disable_shaders); +extern Game *game_new(int width, int height, int disable_vbos, int disable_fbos, int disable_shaders, int audio_debug); extern void game_shutdown(Game *game); extern Room *game_find_room(Game *game, int rx, int ry, int rz); extern void game_pause(Game *game); @@ -55,6 +55,7 @@ int main(int argc, char *argv[]) { int disable_vbos = 0; int disable_fbos = 0; int disable_shaders = 0; + int audio_debug = 0; const struct option longopts[] = { {"fullscreen", 0, NULL, 'f'}, {"resolution", 1, NULL, 'r'}, {"help", 0, NULL, 'h'}, @@ -62,6 +63,7 @@ int main(int argc, char *argv[]) { {"disable-vbos", 0, &disable_vbos, 1}, {"disable-fbos", 0, &disable_fbos, 1}, {"disable-shaders", 0, &disable_shaders, 1}, + {"audio-debug", 0, &audio_debug, 1}, {0, 0, NULL, 0} }; @@ -107,6 +109,7 @@ int main(int argc, char *argv[]) { printf(" --disable-vbos Disable the use of vertex buffer objects (advanced).\n"); printf(" --disable-fbos Disable the use of framebuffer objects (advanced).\n"); printf(" --disable-shaders Disable the use of shaders (advanced).\n"); + printf(" --audio-debug Print audio debugging messages to stdout (advanced).\n"); printf(" -f, --fullscreen Use the full screen.\n\n"); printf("Allowable values for <res> are as follows:\n\n"); printf("<res> Width Height\n"); @@ -164,7 +167,7 @@ int main(int argc, char *argv[]) { /* World setup */ Game *game; - game = game_new(width, height, disable_vbos, disable_fbos, disable_shaders); + game = game_new(width, height, disable_vbos, disable_fbos, disable_shaders, audio_debug); /* Main loop */ finished = 0; |