From 0dc2fb576045e73876973b9ac4f8a9434aa7e68e Mon Sep 17 00:00:00 2001 From: Jeffrey Goode Date: Wed, 12 Aug 2009 18:12:25 +0000 Subject: Adds DSP testing and WAV writing to test_codec git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22279 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.c | 2 ++ apps/plugin.h | 6 ++-- apps/plugins/test_codec.c | 89 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 87 insertions(+), 10 deletions(-) (limited to 'apps') diff --git a/apps/plugin.c b/apps/plugin.c index 92df51dbac..238a01c322 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -465,6 +465,8 @@ static const struct plugin_api rockbox_api = { dsp_dither_enable, dsp_configure, dsp_process, + dsp_input_count, + dsp_output_count, #endif /* CONFIG_CODEC == SWCODEC */ /* playback control */ diff --git a/apps/plugin.h b/apps/plugin.h index 9413a38553..9616628e90 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -133,12 +133,12 @@ void* plugin_get_buffer(size_t *buffer_size); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 166 +#define PLUGIN_API_VERSION 167 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 166 +#define PLUGIN_MIN_API_VERSION 167 /* plugin return codes */ enum plugin_status { @@ -594,6 +594,8 @@ struct plugin_api { intptr_t value); int (*dsp_process)(struct dsp_config *dsp, char *dest, const char *src[], int count); + int (*dsp_input_count)(struct dsp_config *dsp, int count); + int (*dsp_output_count)(struct dsp_config *dsp, int count); #endif /* CONFIG_CODEC == SWCODC */ /* playback control */ diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c index 8c44c92409..bae4571067 100644 --- a/apps/plugins/test_codec.c +++ b/apps/plugins/test_codec.c @@ -107,6 +107,8 @@ struct test_track_info { static struct test_track_info track; static bool taginfo_ready = true; +static bool use_dsp; + static volatile unsigned int elapsed; static volatile bool codec_playing; static volatile long endtick; @@ -150,6 +152,10 @@ static inline void int2le16(unsigned char* buf, int16_t x) buf[1] = (x & 0xff00) >> 8; } +/* 32KB should be enough */ +static unsigned char wavbuffer[32*1024]; +static unsigned char dspbuffer[32*1024]; + void init_wav(char* filename) { wavinfo.totalsamples = 0; @@ -198,13 +204,42 @@ static void* codec_get_buffer(size_t *size) return codec_mallocbuf; } +static int process_dsp(const void *ch1, const void *ch2, int count) +{ + const char *src[2] = { ch1, ch2 }; + int written_count = 0; + char *dest = dspbuffer; + + while (count > 0) + { + int out_count = rb->dsp_output_count(ci.dsp, count); + + int inp_count = rb->dsp_input_count(ci.dsp, out_count); + + if (inp_count <= 0) + break; + + if (inp_count > count) + inp_count = count; + + out_count = rb->dsp_process(ci.dsp, dest, src, inp_count); + + if (out_count <= 0) + break; + + written_count += out_count; + dest += out_count * 4; + + count -= inp_count; + } + + return written_count; +} + /* Null output */ static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count) { - /* Always successful - just discard data */ - (void)ch1; - (void)ch2; - (void)count; + if (use_dsp) process_dsp(ch1, ch2, count); /* Prevent idle poweroff */ rb->reset_poweroff_timer(); @@ -212,9 +247,6 @@ static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count) return true; } -/* 64KB should be enough */ -static unsigned char wavbuffer[64*1024]; - static inline int32_t clip_sample(int32_t sample) { if ((int16_t)sample != sample) @@ -234,10 +266,29 @@ static bool pcmbuf_insert_wav(const void *ch1, const void *ch2, int count) unsigned char* p = wavbuffer; const int scale = wavinfo.sampledepth - 15; const int dc_bias = 1 << (scale - 1); + int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2; /* Prevent idle poweroff */ rb->reset_poweroff_timer(); + if (use_dsp) { + count = process_dsp(ch1, ch2, count); + wavinfo.totalsamples += count; + if (channels == 1) + { + unsigned char *s = dspbuffer, *d = dspbuffer; + int c = count; + while (c-- > 0) + { + *d++ = *s++; + *d++ = *s++; + s++; + s++; + } + } + rb->write(wavinfo.fd, dspbuffer, count * 2 * channels); + } else { + if (wavinfo.sampledepth <= 16) { data1_16 = ch1; data2_16 = ch2; @@ -306,11 +357,11 @@ static bool pcmbuf_insert_wav(const void *ch1, const void *ch2, int count) wavinfo.totalsamples += count; rb->write(wavinfo.fd, wavbuffer, p - wavbuffer); + } /* else */ return true; } - /* Set song position in WPS (value in ms). */ static void set_elapsed(unsigned int value) { @@ -401,6 +452,8 @@ static void set_offset(size_t value) /* Configure different codec buffer parameters. */ static void configure(int setting, intptr_t value) { + if (use_dsp) + rb->dsp_configure(ci.dsp, setting, value); switch(setting) { case DSP_SWITCH_FREQUENCY: @@ -444,6 +497,8 @@ static void init_ci(void) ci.discard_codec = discard_codec; ci.set_offset = set_offset; ci.configure = configure; + ci.dsp = (struct dsp_config *)rb->dsp_configure(NULL, DSP_MYDSP, + CODEC_IDX_AUDIO); /* --- "Core" functions --- */ @@ -580,6 +635,9 @@ static enum plugin_status test_track(const char* filename) ci.new_track = 0; ci.seek_time = 0; + if (use_dsp) + rb->dsp_configure(ci.dsp, DSP_RESET, 0); + starttick = *rb->current_tick; codec_playing = true; @@ -676,14 +734,28 @@ enum plugin_status plugin_start(const void* parameter) "Speed test", "Speed test folder", "Write WAV", + "Speed test w/DSP", + "Speed test folder w/DSP", + "Write WAV w/DSP", + "Quit", ); +show_menu: rb->lcd_clear_display(); result=rb->do_menu(&menu,&selection, NULL, false); + if (result == 6) + { + res = PLUGIN_OK; + goto exit; + } + scandir = 0; + if ((use_dsp = ((result >= 3) && (result <=5)))) { + result -= 3; + } if (result==0) { wavinfo.fd = -1; log_init(false); @@ -750,6 +822,7 @@ enum plugin_status plugin_start(const void* parameter) while (rb->button_get(true) != TESTCODEC_EXITBUTTON); } + goto show_menu; exit: log_close(); -- cgit v1.2.3