summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/mpegplayer/audio_thread.c56
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.c8
-rw-r--r--apps/plugins/test_codec.c51
4 files changed, 63 insertions, 53 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index db690a638a..e5f026c5b4 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -33,6 +33,7 @@ flipit.c
33shopper.c 33shopper.c
34resistor.c 34resistor.c
35 35
36test_codec.c
36 37
37#ifdef USB_ENABLE_HID 38#ifdef USB_ENABLE_HID
38remote_control.c 39remote_control.c
diff --git a/apps/plugins/mpegplayer/audio_thread.c b/apps/plugins/mpegplayer/audio_thread.c
index f976fd6007..b06727f759 100644
--- a/apps/plugins/mpegplayer/audio_thread.c
+++ b/apps/plugins/mpegplayer/audio_thread.c
@@ -36,6 +36,7 @@ struct audio_thread_data
36 unsigned samplerate; /* Current stream sample rate */ 36 unsigned samplerate; /* Current stream sample rate */
37 int nchannels; /* Number of audio channels */ 37 int nchannels; /* Number of audio channels */
38 struct dsp_config *dsp; /* The DSP we're using */ 38 struct dsp_config *dsp; /* The DSP we're using */
39 struct dsp_buffer src; /* Current audio data for DSP processing */
39}; 40};
40 41
41/* The audio thread is stolen from the core codec thread */ 42/* The audio thread is stolen from the core codec thread */
@@ -479,12 +480,13 @@ static void audio_thread(void)
479 /* We need this here to init the EMAC for Coldfire targets */ 480 /* We need this here to init the EMAC for Coldfire targets */
480 init_mad(); 481 init_mad();
481 482
482 td.dsp = (struct dsp_config *)rb->dsp_configure(NULL, DSP_MYDSP, 483 td.dsp = rb->dsp_get_config(CODEC_IDX_AUDIO);
483 CODEC_IDX_AUDIO);
484#ifdef HAVE_PITCHSCREEN 484#ifdef HAVE_PITCHSCREEN
485 rb->sound_set_pitch(PITCH_SPEED_100); 485 rb->sound_set_pitch(PITCH_SPEED_100);
486 rb->dsp_set_timestretch(PITCH_SPEED_100);
486#endif 487#endif
487 rb->dsp_configure(td.dsp, DSP_RESET, 0); 488 rb->dsp_configure(td.dsp, DSP_RESET, 0);
489 rb->dsp_configure(td.dsp, DSP_FLUSH, 0);
488 rb->dsp_configure(td.dsp, DSP_SET_SAMPLE_DEPTH, MAD_F_FRACBITS); 490 rb->dsp_configure(td.dsp, DSP_SET_SAMPLE_DEPTH, MAD_F_FRACBITS);
489 491
490 goto message_wait; 492 goto message_wait;
@@ -631,43 +633,53 @@ static void audio_thread(void)
631 STEREO_MONO : STEREO_NONINTERLEAVED); 633 STEREO_MONO : STEREO_NONINTERLEAVED);
632 } 634 }
633 635
636 td.src.remcount = synth.pcm.length;
637 td.src.pin[0] = synth.pcm.samples[0];
638 td.src.pin[1] = synth.pcm.samples[1];
639 td.src.proc_mask = 0;
640
634 td.state = TSTATE_RENDER_WAIT; 641 td.state = TSTATE_RENDER_WAIT;
635 642
636 /* Add a frame of audio to the pcm buffer. Maximum is 1152 samples. */ 643 /* Add a frame of audio to the pcm buffer. Maximum is 1152 samples. */
637 render_wait: 644 render_wait:
638 if (synth.pcm.length > 0) 645 rb->yield();
646
647 while (1)
639 { 648 {
640 const char *src[2] = 649 struct dsp_buffer dst;
641 { (char *)synth.pcm.samples[0], (char *)synth.pcm.samples[1] }; 650 dst.remcount = 0;
642 int out_count = (synth.pcm.length * CLOCK_RATE 651 dst.bufcount = MAX(td.src.remcount, 1024);
643 + (td.samplerate - 1)) / td.samplerate; 652
644 unsigned char *out_buf; 653 ssize_t size = dst.bufcount * 2 * sizeof(int16_t);
645 ssize_t size = out_count*4;
646 654
647 /* Wait for required amount of free buffer space */ 655 /* Wait for required amount of free buffer space */
648 while ((out_buf = pcm_output_get_buffer(&size)) == NULL) 656 while ((dst.p16out = pcm_output_get_buffer(&size)) == NULL)
649 { 657 {
650 /* Wait one frame */ 658 /* Wait one frame */
651 int timeout = out_count*HZ / td.samplerate; 659 int timeout = dst.bufcount*HZ / td.samplerate;
652 str_get_msg_w_tmo(&audio_str, &td.ev, MAX(timeout, 1)); 660 str_get_msg_w_tmo(&audio_str, &td.ev, MAX(timeout, 1));
653 if (td.ev.id != SYS_TIMEOUT) 661 if (td.ev.id != SYS_TIMEOUT)
654 goto message_process; 662 goto message_process;
655 } 663 }
656 664
657 out_count = rb->dsp_process(td.dsp, out_buf, src, synth.pcm.length); 665 dst.bufcount = size / (2 * sizeof (int16_t));
666 rb->dsp_process(td.dsp, &td.src, &dst);
658 667
659 if (out_count <= 0) 668 if (dst.remcount > 0)
660 break; 669 {
661 670 /* Make this data available to DMA */
662 /* Make this data available to DMA */ 671 pcm_output_commit_data(dst.remcount * 2 * sizeof(int16_t),
663 pcm_output_commit_data(out_count*4, audio_queue.curr->time); 672 audio_queue.curr->time);
664 673
665 /* As long as we're on this timestamp, the time is just 674 /* As long as we're on this timestamp, the time is just
666 incremented by the number of samples */ 675 incremented by the number of samples */
667 audio_queue.curr->time += out_count; 676 audio_queue.curr->time += dst.remcount;
677 }
678 else if (td.src.remcount <= 0)
679 {
680 break;
681 }
668 } 682 }
669
670 rb->yield();
671 } /* end decoding loop */ 683 } /* end decoding loop */
672} 684}
673 685
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c
index 1c3f3c0b92..7f92fb7c69 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.c
+++ b/apps/plugins/mpegplayer/mpeg_settings.c
@@ -457,13 +457,13 @@ static void sync_audio_setting(int setting, bool global)
457 break; 457 break;
458 458
459 case MPEG_AUDIO_CROSSFEED: 459 case MPEG_AUDIO_CROSSFEED:
460 rb->dsp_set_crossfeed((global || settings.crossfeed) ? 460 rb->dsp_crossfeed_enable((global || settings.crossfeed) ?
461 rb->global_settings->crossfeed : false); 461 rb->global_settings->crossfeed : false);
462 break; 462 break;
463 463
464 case MPEG_AUDIO_EQUALIZER: 464 case MPEG_AUDIO_EQUALIZER:
465 rb->dsp_set_eq((global || settings.equalizer) ? 465 rb->dsp_eq_enable((global || settings.equalizer) ?
466 rb->global_settings->eq_enabled : false); 466 rb->global_settings->eq_enabled : false);
467 break; 467 break;
468 468
469 case MPEG_AUDIO_DITHERING: 469 case MPEG_AUDIO_DITHERING:
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index dafcf35710..920be54d56 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -164,6 +164,7 @@ static inline void int2le16(unsigned char* buf, int16_t x)
164 164
165static unsigned char *wavbuffer; 165static unsigned char *wavbuffer;
166static unsigned char *dspbuffer; 166static unsigned char *dspbuffer;
167static int dspbuffer_count;
167 168
168void init_wav(char* filename) 169void init_wav(char* filename)
169{ 170{
@@ -215,34 +216,31 @@ static void* codec_get_buffer(size_t *size)
215 216
216static int process_dsp(const void *ch1, const void *ch2, int count) 217static int process_dsp(const void *ch1, const void *ch2, int count)
217{ 218{
218 const char *src[2] = { ch1, ch2 }; 219 struct dsp_buffer src;
219 int written_count = 0; 220 src.remcount = count;
220 char *dest = dspbuffer; 221 src.pin[0] = ch1;
221 222 src.pin[1] = ch2;
222 while (count > 0) 223 src.proc_mask = 0;
224
225 struct dsp_buffer dst;
226 dst.remcount = 0;
227 dst.p16out = (int16_t *)dspbuffer;
228 dst.bufcount = dspbuffer_count;
229
230 while (1)
223 { 231 {
224 int out_count = rb->dsp_output_count(ci.dsp, count); 232 int old_remcount = dst.remcount;
225 233 rb->dsp_process(ci.dsp, &src, &dst);
226 int inp_count = rb->dsp_input_count(ci.dsp, out_count);
227
228 if (inp_count <= 0)
229 break;
230
231 if (inp_count > count)
232 inp_count = count;
233
234 out_count = rb->dsp_process(ci.dsp, dest, src, inp_count);
235 234
236 if (out_count <= 0) 235 if (dst.bufcount <= 0 ||
236 (src.remcount <= 0 && dst.remcount <= old_remcount))
237 {
238 /* Dest is full or no input left and DSP purged */
237 break; 239 break;
238 240 }
239 written_count += out_count;
240 dest += out_count * 4;
241
242 count -= inp_count;
243 } 241 }
244 242
245 return written_count; 243 return dst.remcount;
246} 244}
247 245
248/* Null output */ 246/* Null output */
@@ -502,7 +500,6 @@ static void configure(int setting, intptr_t value)
502 rb->dsp_configure(ci.dsp, setting, value); 500 rb->dsp_configure(ci.dsp, setting, value);
503 switch(setting) 501 switch(setting)
504 { 502 {
505 case DSP_SWITCH_FREQUENCY:
506 case DSP_SET_FREQUENCY: 503 case DSP_SET_FREQUENCY:
507 DEBUGF("samplerate=%d\n",(int)value); 504 DEBUGF("samplerate=%d\n",(int)value);
508 wavinfo.samplerate = use_dsp ? NATIVE_FREQUENCY : (int)value; 505 wavinfo.samplerate = use_dsp ? NATIVE_FREQUENCY : (int)value;
@@ -525,9 +522,7 @@ static void init_ci(void)
525{ 522{
526 /* --- Our "fake" implementations of the codec API functions. --- */ 523 /* --- Our "fake" implementations of the codec API functions. --- */
527 524
528 ci.dsp = (struct dsp_config *)rb->dsp_configure(NULL, DSP_MYDSP, 525 ci.dsp = rb->dsp_get_config(CODEC_IDX_AUDIO);
529 CODEC_IDX_AUDIO);
530
531 ci.codec_get_buffer = codec_get_buffer; 526 ci.codec_get_buffer = codec_get_buffer;
532 527
533 if (wavinfo.fd >= 0 || checksum) { 528 if (wavinfo.fd >= 0 || checksum) {
@@ -849,6 +844,8 @@ enum plugin_status plugin_start(const void* parameter)
849 844
850 wavbuffer = rb->plugin_get_buffer(&buffer_size); 845 wavbuffer = rb->plugin_get_buffer(&buffer_size);
851 dspbuffer = wavbuffer + buffer_size / 2; 846 dspbuffer = wavbuffer + buffer_size / 2;
847 dspbuffer_count = (buffer_size - (dspbuffer - wavbuffer)) /
848 (2 * sizeof (int16_t));
852 849
853 codec_mallocbuf = rb->plugin_get_audio_buffer(&audiosize); 850 codec_mallocbuf = rb->plugin_get_audio_buffer(&audiosize);
854 /* Align codec_mallocbuf to pointer size, tlsf wants that */ 851 /* Align codec_mallocbuf to pointer size, tlsf wants that */