1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dan Everton 2006-02-21 21:48:06 +00:00
parent 8850c61ee1
commit 3945218810
2 changed files with 55 additions and 23 deletions

View file

@ -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;
int datalen, offset;
FILE *debug = (FILE *)udata;
/* At all times we need to write a full 'len' bytes to stream. */
if (pcm_data_size <= len) {
/* Play what we have */
memcpy(stream, pcm_data, pcm_data_size);
if (debug != NULL) {
fwrite(pcm_data, sizeof(Uint8), pcm_data_size, debug);
}
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);
(void) udata;
if (pcm_data_size == 0) {
return;
if (debug != NULL) {
fwrite(pcm_data, sizeof(Uint8), len, debug);
}
}
datalen = (len > pcm_data_size) ? pcm_data_size : len;
memcpy(stream, pcm_data, datalen);
pcm_data_size -= datalen;
pcm_data += datalen;
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;
}
}
}
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;

View file

@ -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");