Index: apps/plugins/test_codec.c =================================================================== --- apps/plugins/test_codec.c (revision 22249) +++ apps/plugins/test_codec.c (working copy) @@ -107,6 +107,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ /* 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 @@ 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 @@ 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 @@ "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 @@ while (rb->button_get(true) != TESTCODEC_EXITBUTTON); } + goto show_menu; exit: log_close(); Index: apps/dsp.c =================================================================== --- apps/dsp.c (revision 22249) +++ apps/dsp.c (working copy) @@ -451,12 +451,12 @@ { static const sample_input_fn_type sample_input_functions[] = { - [SAMPLE_INPUT_LE_NATIVE_MONO] = sample_input_lte_native_mono, [SAMPLE_INPUT_LE_NATIVE_I_STEREO] = sample_input_lte_native_i_stereo, [SAMPLE_INPUT_LE_NATIVE_NI_STEREO] = sample_input_lte_native_ni_stereo, - [SAMPLE_INPUT_GT_NATIVE_MONO] = sample_input_gt_native_mono, + [SAMPLE_INPUT_LE_NATIVE_MONO] = sample_input_lte_native_mono, [SAMPLE_INPUT_GT_NATIVE_I_STEREO] = sample_input_gt_native_i_stereo, [SAMPLE_INPUT_GT_NATIVE_NI_STEREO] = sample_input_gt_native_ni_stereo, + [SAMPLE_INPUT_GT_NATIVE_MONO] = sample_input_gt_native_mono, }; int convert = dsp->stereo_mode; Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 22249) +++ apps/plugin.c (working copy) @@ -465,6 +465,8 @@ dsp_dither_enable, dsp_configure, dsp_process, + dsp_input_count, + dsp_output_count, #endif /* CONFIG_CODEC == SWCODEC */ /* playback control */ Index: apps/plugin.h =================================================================== --- apps/plugin.h (revision 22249) +++ apps/plugin.h (working copy) @@ -133,12 +133,12 @@ #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 @@ 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 */ Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (revision 22249) +++ apps/plugins/SOURCES (working copy) @@ -18,6 +18,7 @@ stopwatch.c vbrfix.c viewer.c +test_codec.c #ifdef HAVE_BACKLIGHT lamp.c #endif /* HAVE_BACKLIGHT */