summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-03-27 19:52:15 -0400
committerMichael Sevakis <jethead71@rockbox.org>2012-04-29 10:00:56 +0200
commitc9bcbe202d010234f76d1046880a790fe2c3a067 (patch)
tree2f15438664ad1b196d6ed8b78065cd050d351956 /apps/plugins/mpegplayer
parentc9c13497736d8be077663f4458948f7bd526841b (diff)
downloadrockbox-c9bcbe202d010234f76d1046880a790fe2c3a067.tar.gz
rockbox-c9bcbe202d010234f76d1046880a790fe2c3a067.zip
Fundamentally rewrite much of the audio DSP.
Creates a standard buffer passing, local data passing and messaging system for processing stages. Stages can be moved to their own source files to reduce clutter and ease assimilation of new ones. dsp.c becomes dsp_core.c which supports an engine and framework for effects. Formats and change notifications are passed along with the buffer so that they arrive at the correct time at each stage in the chain regardless of the internal delays of a particular one. Removes restrictions on the number of samples that can be processed at a time and it pays attention to destination buffer size restrictions without having to limit input count, which also allows pcmbuf to remain fuller and safely set its own buffer limits as it sees fit. There is no longer a need to query input/output counts given a certain number of input samples; just give it the sizes of the source and destination buffers. Works in harmony with stages that are not deterministic in terms of sample input/output ratio (like both resamplers but most notably the timestretch). As a result it fixes quirks with timestretch hanging up with certain settings and it now operates properly throughout its full settings range. Change-Id: Ib206ec78f6f6c79259c5af9009fe021d68be9734 Reviewed-on: http://gerrit.rockbox.org/200 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'apps/plugins/mpegplayer')
-rw-r--r--apps/plugins/mpegplayer/audio_thread.c56
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.c8
2 files changed, 38 insertions, 26 deletions
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: