summaryrefslogtreecommitdiff
path: root/apps/plugins/test_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/test_codec.c')
-rw-r--r--apps/plugins/test_codec.c89
1 files changed, 81 insertions, 8 deletions
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();