summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2009-08-12 18:12:25 +0000
committerJeffrey Goode <jeffg7@gmail.com>2009-08-12 18:12:25 +0000
commit0dc2fb576045e73876973b9ac4f8a9434aa7e68e (patch)
tree3fa61a3aeae0d09affb55eb4a5950a48a502ea66
parent27934e26b7b8ea470db4c92936e61c835635ac0b (diff)
downloadrockbox-0dc2fb576045e73876973b9ac4f8a9434aa7e68e.tar.gz
rockbox-0dc2fb576045e73876973b9ac4f8a9434aa7e68e.zip
Adds DSP testing and WAV writing to test_codec
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22279 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugin.c2
-rw-r--r--apps/plugin.h6
-rw-r--r--apps/plugins/test_codec.c89
3 files changed, 87 insertions, 10 deletions
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 = {
465 dsp_dither_enable, 465 dsp_dither_enable,
466 dsp_configure, 466 dsp_configure,
467 dsp_process, 467 dsp_process,
468 dsp_input_count,
469 dsp_output_count,
468#endif /* CONFIG_CODEC == SWCODEC */ 470#endif /* CONFIG_CODEC == SWCODEC */
469 471
470 /* playback control */ 472 /* 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);
133#define PLUGIN_MAGIC 0x526F634B /* RocK */ 133#define PLUGIN_MAGIC 0x526F634B /* RocK */
134 134
135/* increase this every time the api struct changes */ 135/* increase this every time the api struct changes */
136#define PLUGIN_API_VERSION 166 136#define PLUGIN_API_VERSION 167
137 137
138/* update this to latest version if a change to the api struct breaks 138/* update this to latest version if a change to the api struct breaks
139 backwards compatibility (and please take the opportunity to sort in any 139 backwards compatibility (and please take the opportunity to sort in any
140 new function which are "waiting" at the end of the function table) */ 140 new function which are "waiting" at the end of the function table) */
141#define PLUGIN_MIN_API_VERSION 166 141#define PLUGIN_MIN_API_VERSION 167
142 142
143/* plugin return codes */ 143/* plugin return codes */
144enum plugin_status { 144enum plugin_status {
@@ -594,6 +594,8 @@ struct plugin_api {
594 intptr_t value); 594 intptr_t value);
595 int (*dsp_process)(struct dsp_config *dsp, char *dest, 595 int (*dsp_process)(struct dsp_config *dsp, char *dest,
596 const char *src[], int count); 596 const char *src[], int count);
597 int (*dsp_input_count)(struct dsp_config *dsp, int count);
598 int (*dsp_output_count)(struct dsp_config *dsp, int count);
597#endif /* CONFIG_CODEC == SWCODC */ 599#endif /* CONFIG_CODEC == SWCODC */
598 600
599 /* playback control */ 601 /* 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 {
107static struct test_track_info track; 107static struct test_track_info track;
108static bool taginfo_ready = true; 108static bool taginfo_ready = true;
109 109
110static bool use_dsp;
111
110static volatile unsigned int elapsed; 112static volatile unsigned int elapsed;
111static volatile bool codec_playing; 113static volatile bool codec_playing;
112static volatile long endtick; 114static volatile long endtick;
@@ -150,6 +152,10 @@ static inline void int2le16(unsigned char* buf, int16_t x)
150 buf[1] = (x & 0xff00) >> 8; 152 buf[1] = (x & 0xff00) >> 8;
151} 153}
152 154
155/* 32KB should be enough */
156static unsigned char wavbuffer[32*1024];
157static unsigned char dspbuffer[32*1024];
158
153void init_wav(char* filename) 159void init_wav(char* filename)
154{ 160{
155 wavinfo.totalsamples = 0; 161 wavinfo.totalsamples = 0;
@@ -198,13 +204,42 @@ static void* codec_get_buffer(size_t *size)
198 return codec_mallocbuf; 204 return codec_mallocbuf;
199} 205}
200 206
207static int process_dsp(const void *ch1, const void *ch2, int count)
208{
209 const char *src[2] = { ch1, ch2 };
210 int written_count = 0;
211 char *dest = dspbuffer;
212
213 while (count > 0)
214 {
215 int out_count = rb->dsp_output_count(ci.dsp, count);
216
217 int inp_count = rb->dsp_input_count(ci.dsp, out_count);
218
219 if (inp_count <= 0)
220 break;
221
222 if (inp_count > count)
223 inp_count = count;
224
225 out_count = rb->dsp_process(ci.dsp, dest, src, inp_count);
226
227 if (out_count <= 0)
228 break;
229
230 written_count += out_count;
231 dest += out_count * 4;
232
233 count -= inp_count;
234 }
235
236 return written_count;
237}
238
201/* Null output */ 239/* Null output */
202static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count) 240static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
203{ 241{
204 /* Always successful - just discard data */ 242 if (use_dsp) process_dsp(ch1, ch2, count);
205 (void)ch1;
206 (void)ch2;
207 (void)count;
208 243
209 /* Prevent idle poweroff */ 244 /* Prevent idle poweroff */
210 rb->reset_poweroff_timer(); 245 rb->reset_poweroff_timer();
@@ -212,9 +247,6 @@ static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
212 return true; 247 return true;
213} 248}
214 249
215/* 64KB should be enough */
216static unsigned char wavbuffer[64*1024];
217
218static inline int32_t clip_sample(int32_t sample) 250static inline int32_t clip_sample(int32_t sample)
219{ 251{
220 if ((int16_t)sample != sample) 252 if ((int16_t)sample != sample)
@@ -234,10 +266,29 @@ static bool pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
234 unsigned char* p = wavbuffer; 266 unsigned char* p = wavbuffer;
235 const int scale = wavinfo.sampledepth - 15; 267 const int scale = wavinfo.sampledepth - 15;
236 const int dc_bias = 1 << (scale - 1); 268 const int dc_bias = 1 << (scale - 1);
269 int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
237 270
238 /* Prevent idle poweroff */ 271 /* Prevent idle poweroff */
239 rb->reset_poweroff_timer(); 272 rb->reset_poweroff_timer();
240 273
274 if (use_dsp) {
275 count = process_dsp(ch1, ch2, count);
276 wavinfo.totalsamples += count;
277 if (channels == 1)
278 {
279 unsigned char *s = dspbuffer, *d = dspbuffer;
280 int c = count;
281 while (c-- > 0)
282 {
283 *d++ = *s++;
284 *d++ = *s++;
285 s++;
286 s++;
287 }
288 }
289 rb->write(wavinfo.fd, dspbuffer, count * 2 * channels);
290 } else {
291
241 if (wavinfo.sampledepth <= 16) { 292 if (wavinfo.sampledepth <= 16) {
242 data1_16 = ch1; 293 data1_16 = ch1;
243 data2_16 = ch2; 294 data2_16 = ch2;
@@ -306,11 +357,11 @@ static bool pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
306 357
307 wavinfo.totalsamples += count; 358 wavinfo.totalsamples += count;
308 rb->write(wavinfo.fd, wavbuffer, p - wavbuffer); 359 rb->write(wavinfo.fd, wavbuffer, p - wavbuffer);
360 } /* else */
309 361
310 return true; 362 return true;
311} 363}
312 364
313
314/* Set song position in WPS (value in ms). */ 365/* Set song position in WPS (value in ms). */
315static void set_elapsed(unsigned int value) 366static void set_elapsed(unsigned int value)
316{ 367{
@@ -401,6 +452,8 @@ static void set_offset(size_t value)
401/* Configure different codec buffer parameters. */ 452/* Configure different codec buffer parameters. */
402static void configure(int setting, intptr_t value) 453static void configure(int setting, intptr_t value)
403{ 454{
455 if (use_dsp)
456 rb->dsp_configure(ci.dsp, setting, value);
404 switch(setting) 457 switch(setting)
405 { 458 {
406 case DSP_SWITCH_FREQUENCY: 459 case DSP_SWITCH_FREQUENCY:
@@ -444,6 +497,8 @@ static void init_ci(void)
444 ci.discard_codec = discard_codec; 497 ci.discard_codec = discard_codec;
445 ci.set_offset = set_offset; 498 ci.set_offset = set_offset;
446 ci.configure = configure; 499 ci.configure = configure;
500 ci.dsp = (struct dsp_config *)rb->dsp_configure(NULL, DSP_MYDSP,
501 CODEC_IDX_AUDIO);
447 502
448 /* --- "Core" functions --- */ 503 /* --- "Core" functions --- */
449 504
@@ -580,6 +635,9 @@ static enum plugin_status test_track(const char* filename)
580 ci.new_track = 0; 635 ci.new_track = 0;
581 ci.seek_time = 0; 636 ci.seek_time = 0;
582 637
638 if (use_dsp)
639 rb->dsp_configure(ci.dsp, DSP_RESET, 0);
640
583 starttick = *rb->current_tick; 641 starttick = *rb->current_tick;
584 642
585 codec_playing = true; 643 codec_playing = true;
@@ -676,14 +734,28 @@ enum plugin_status plugin_start(const void* parameter)
676 "Speed test", 734 "Speed test",
677 "Speed test folder", 735 "Speed test folder",
678 "Write WAV", 736 "Write WAV",
737 "Speed test w/DSP",
738 "Speed test folder w/DSP",
739 "Write WAV w/DSP",
740 "Quit",
679 ); 741 );
680 742
743show_menu:
681 rb->lcd_clear_display(); 744 rb->lcd_clear_display();
682 745
683 result=rb->do_menu(&menu,&selection, NULL, false); 746 result=rb->do_menu(&menu,&selection, NULL, false);
684 747
748 if (result == 6)
749 {
750 res = PLUGIN_OK;
751 goto exit;
752 }
753
685 scandir = 0; 754 scandir = 0;
686 755
756 if ((use_dsp = ((result >= 3) && (result <=5)))) {
757 result -= 3;
758 }
687 if (result==0) { 759 if (result==0) {
688 wavinfo.fd = -1; 760 wavinfo.fd = -1;
689 log_init(false); 761 log_init(false);
@@ -750,6 +822,7 @@ enum plugin_status plugin_start(const void* parameter)
750 822
751 while (rb->button_get(true) != TESTCODEC_EXITBUTTON); 823 while (rb->button_get(true) != TESTCODEC_EXITBUTTON);
752 } 824 }
825 goto show_menu;
753 826
754exit: 827exit:
755 log_close(); 828 log_close();