diff options
Diffstat (limited to 'apps/plugins/mpegplayer/audio_thread.c')
-rw-r--r-- | apps/plugins/mpegplayer/audio_thread.c | 56 |
1 files changed, 34 insertions, 22 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 | ||