From c9bcbe202d010234f76d1046880a790fe2c3a067 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Tue, 27 Mar 2012 19:52:15 -0400 Subject: 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 Tested-by: Michael Sevakis --- apps/voice_thread.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'apps/voice_thread.c') diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 07a67256c4..cff703adfa 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c @@ -133,9 +133,8 @@ struct voice_thread_data SpeexBits bits; /* Bit cursor */ struct dsp_config *dsp; /* DSP used for voice output */ struct voice_info vi; /* Copy of clip data */ - const char *src[2]; /* Current output buffer pointers */ int lookahead; /* Number of samples to drop at start of clip */ - int count; /* Count of samples remaining to send to PCM */ + struct dsp_buffer src; /* Speex output buffer/input to DSP */ }; /* Functions called in their repective state that return the next state to @@ -264,9 +263,7 @@ void voice_wait(void) * setup the DSP parameters */ static void voice_data_init(struct voice_thread_data *td) { - td->dsp = (struct dsp_config *)dsp_configure(NULL, DSP_MYDSP, - CODEC_IDX_VOICE); - + td->dsp = dsp_get_config(CODEC_IDX_VOICE); dsp_configure(td->dsp, DSP_RESET, 0); dsp_configure(td->dsp, DSP_SET_FREQUENCY, VOICE_SAMPLE_RATE); dsp_configure(td->dsp, DSP_SET_SAMPLE_DEPTH, VOICE_SAMPLE_DEPTH); @@ -378,7 +375,8 @@ static enum voice_state voice_decode(struct voice_thread_data *td) else { /* If all clips are done and not playing, force pcm playback. */ - voice_start_playback(); + if (voice_unplayed_frames() > 0) + voice_start_playback(); return VOICE_STATE_MESSAGE; } } @@ -387,12 +385,14 @@ static enum voice_state voice_decode(struct voice_thread_data *td) yield(); /* Output the decoded frame */ - td->count = VOICE_FRAME_COUNT - td->lookahead; - td->src[0] = (const char *)&voice_output_buf[td->lookahead]; - td->src[1] = NULL; + td->src.remcount = VOICE_FRAME_COUNT - td->lookahead; + td->src.pin[0] = &voice_output_buf[td->lookahead]; + td->src.pin[1] = NULL; + td->src.proc_mask = 0; + td->lookahead -= MIN(VOICE_FRAME_COUNT, td->lookahead); - if (td->count > 0) + if (td->src.remcount > 0) return VOICE_STATE_BUFFER_INSERT; } @@ -405,12 +405,21 @@ static enum voice_state voice_buffer_insert(struct voice_thread_data *td) if (!queue_empty(&voice_queue)) return VOICE_STATE_MESSAGE; - char *dest = (char *)voice_buf_get(); + struct dsp_buffer dst; - if (dest != NULL) + if ((dst.p16out = voice_buf_get()) != NULL) { - voice_buf_commit(dsp_process(td->dsp, dest, td->src, td->count)); - return VOICE_STATE_DECODE; + dst.remcount = 0; + dst.bufcount = VOICE_PCM_FRAME_COUNT; + + dsp_process(td->dsp, &td->src, &dst); + + voice_buf_commit(dst.remcount); + + /* Unless other effects are introduced to voice that have delays, + all output should have been purged to dst in one call */ + return td->src.remcount > 0 ? + VOICE_STATE_BUFFER_INSERT : VOICE_STATE_DECODE; } sleep(0); -- cgit