From 394521881072eb49b29352f479a8f17ee403fbd6 Mon Sep 17 00:00:00 2001 From: Dan Everton Date: Tue, 21 Feb 2006 21:48:06 +0000 Subject: Proper working sound in the SDL sim. Add option to write raw audio to a file, use --debugaudio command line option. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8770 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/sdl/sound.c | 66 ++++++++++++++++++++++++++++++++++--------------- uisimulator/sdl/uisdl.c | 10 ++++++-- 2 files changed, 54 insertions(+), 22 deletions(-) (limited to 'uisimulator') diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c index 4b8427ca90..757ebe13c7 100644 --- a/uisimulator/sdl/sound.c +++ b/uisimulator/sdl/sound.c @@ -33,13 +33,19 @@ static bool pcm_paused; static Uint8* pcm_data; static int pcm_data_size; +extern bool debug_audio; + static void sdl_dma_start(const void *addr, size_t size) { pcm_playing = true; + SDL_LockAudio(); + pcm_data = (Uint8 *) addr; pcm_data_size = size; + SDL_UnlockAudio(); + SDL_PauseAudio(0); } @@ -136,37 +142,57 @@ bool pcm_is_playing(void) return pcm_playing; } +char overflow[8192]; +int overflow_amount = 0; + void sdl_audio_callback(void *udata, Uint8 *stream, int len) { - int datalen; - - (void) udata; + int datalen, offset; + FILE *debug = (FILE *)udata; - if (pcm_data_size == 0) { - return; - } - - datalen = (len > pcm_data_size) ? pcm_data_size : len; + /* At all times we need to write a full 'len' bytes to stream. */ - memcpy(stream, pcm_data, datalen); + if (pcm_data_size <= len) { + /* Play what we have */ + memcpy(stream, pcm_data, pcm_data_size); - pcm_data_size -= datalen; - pcm_data += datalen; + if (debug != NULL) { + fwrite(pcm_data, sizeof(Uint8), pcm_data_size, debug); + } - if (pcm_data_size == 0) { - void (*get_more)(unsigned char**, size_t*) = callback_for_more; - if (get_more) { - get_more(&pcm_data, &pcm_data_size); - } else { - pcm_data_size = 0; - pcm_data = NULL; + offset = pcm_data_size; + datalen = len - pcm_data_size; + + /* Get some more */ + callback_for_more(&pcm_data, &pcm_data_size); + + /* Play enough of that to keep the audio buffer full */ + memcpy(stream + offset, pcm_data, datalen); + + if (debug != NULL) { + fwrite(pcm_data, sizeof(Uint8), datalen, debug); + } + } else { + datalen = len; + memcpy(stream, pcm_data, len); + + if (debug != NULL) { + fwrite(pcm_data, sizeof(Uint8), len, debug); } } + + pcm_data_size -= datalen; + pcm_data += datalen; } int pcm_init(void) { SDL_AudioSpec fmt; + FILE *debug = NULL; + + if (debug_audio) { + debug = fopen("audiodebug.raw", "wb"); + } /* Set 16-bit stereo audio at 44Khz */ fmt.freq = 44100; @@ -174,14 +200,14 @@ int pcm_init(void) fmt.channels = 2; fmt.samples = 512; fmt.callback = sdl_audio_callback; - fmt.userdata = NULL; + fmt.userdata = debug; /* Open the audio device and start playing sound! */ if(SDL_OpenAudio(&fmt, NULL) < 0) { fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); return -1; } - + sdl_dma_stop(); return 0; diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 1e36bfa223..3d802ba4de 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c @@ -51,7 +51,9 @@ SDL_Thread *gui_thread; SDL_TimerID tick_timer_id; bool lcd_display_redraw = true; /* Used for player simulator */ -char having_new_lcd=true; /* Used for player simulator */ +char having_new_lcd = true; /* Used for player simulator */ + +bool debug_audio = false; long start_tick; @@ -190,7 +192,10 @@ int main(int argc, char *argv[]) if (argc >= 1) { int x; for (x = 1; x < argc; x++) { - if (!strcmp("--background", argv[x])) { + if (!strcmp("--debugaudio", argv[x])) { + debug_audio = true; + printf("Writing debug audio file.\n"); + } else if (!strcmp("--background", argv[x])) { background = true; printf("Using background image.\n"); } else if (!strcmp("--old_lcd", argv[x])) { @@ -203,6 +208,7 @@ int main(int argc, char *argv[]) } else { printf("rockboxui\n"); printf("Arguments:\n"); + printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); printf(" --background \t Use background image of hardware\n"); printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); printf(" --zoom \t window zoom (will disable backgrounds)\n"); -- cgit v1.2.3