From 77f6f4caadfab255eed4d4cfbd471cb981ccb073 Mon Sep 17 00:00:00 2001 From: Steve Bavin Date: Mon, 15 Jun 2009 15:46:09 +0000 Subject: Fix FS#10331 and get mpegplayer working again. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21293 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 47 +++++++++++++++++------------------------------ apps/main.c | 6 ++++++ apps/tdspeed.c | 18 ++++++++++++++---- apps/tdspeed.h | 3 ++- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/apps/dsp.c b/apps/dsp.c index b32b641693..496e333bc5 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -245,20 +245,6 @@ static int32_t *resample_buf; #define RESAMPLE_BUF_LEFT_CHANNEL 0 #define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO) -#if 0 -/* Clip sample to arbitrary limits where range > 0 and min + range = max */ -static inline long clip_sample(int32_t sample, int32_t min, int32_t range) -{ - if ((uint32_t)(sample - min) > (uint32_t)range) - { - int32_t c = min; - if (sample > min) - c += range; - sample = c; - } - return sample; -} -#endif /* Clip sample to signed 16 bit range */ static inline int32_t clip_sample_16(int32_t sample) @@ -282,14 +268,14 @@ void sound_set_pitch(int permille) void tdspeed_setup(struct dsp_config *dspc) { + dspc->tdspeed_active = false; if (dspc == &AUDIO_DSP) { - dspc->tdspeed_active = false; if (!dspc->tdspeed_enabled) return; if (dspc->tdspeed_percent == 0) dspc->tdspeed_percent = 100; - if (!tdspeed_init( + if (!tdspeed_config( dspc->codec_frequency == 0 ? NATIVE_FREQUENCY : dspc->codec_frequency, dspc->stereo_mode != STEREO_MONO, dspc->tdspeed_percent)) @@ -1277,19 +1263,7 @@ int dsp_process(struct dsp_config *dsp, char *dst, const char *src[], int count) /* dsp_input_size MUST be called afterwards */ int dsp_output_count(struct dsp_config *dsp, int count) { - if(!dsp->tdspeed_active) - { - sample_buf = small_sample_buf; - resample_buf = small_resample_buf; - sample_buf_count = SMALL_SAMPLE_BUF_COUNT; - } - else - { - sample_buf = big_sample_buf; - sample_buf_count = big_sample_buf_count; - resample_buf = big_resample_buf; - } - if(dsp->tdspeed_active) + if (dsp->tdspeed_active) count = tdspeed_est_output_size(); if (dsp->resample) { @@ -1324,7 +1298,7 @@ int dsp_input_count(struct dsp_config *dsp, int count) dsp->data.resample_data.delta) >> 16); } - if(dsp->tdspeed_active) + if (dsp->tdspeed_active) count = tdspeed_est_input_size(count); return count; @@ -1464,6 +1438,19 @@ intptr_t dsp_configure(struct dsp_config *dsp, int setting, intptr_t value) return 0; } + if (!dsp->tdspeed_active) + { + sample_buf = small_sample_buf; + resample_buf = small_resample_buf; + sample_buf_count = SMALL_SAMPLE_BUF_COUNT; + } + else + { + sample_buf = big_sample_buf; + sample_buf_count = big_sample_buf_count; + resample_buf = big_resample_buf; + } + return 1; } diff --git a/apps/main.c b/apps/main.c index 642ec5be08..c899912e22 100644 --- a/apps/main.c +++ b/apps/main.c @@ -336,6 +336,9 @@ static void init(void) scrobbler_init(); cuesheet_init(); +#if CONFIG_CODEC == SWCODEC + tdspeed_init(); +#endif /* CONFIG_CODEC == SWCODEC */ audio_init(); button_clear_queue(); /* Empty the keyboard buffer */ @@ -549,6 +552,9 @@ static void init(void) filetype_init(); scrobbler_init(); cuesheet_init(); +#if CONFIG_CODEC == SWCODEC + tdspeed_init(); +#endif /* CONFIG_CODEC == SWCODEC */ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to diff --git a/apps/tdspeed.c b/apps/tdspeed.c index 67f749f6c3..f365e95e03 100644 --- a/apps/tdspeed.c +++ b/apps/tdspeed.c @@ -54,11 +54,8 @@ static struct tdspeed_state_s tdspeed_state; static int32_t *overlap_buffer[2] = { NULL, NULL }; static int32_t *outbuf[2] = { NULL, NULL }; -bool tdspeed_init(int samplerate, bool stereo, int factor) +void tdspeed_init() { - struct tdspeed_state_s *st = &tdspeed_state; - int src_frame_sz; - /* Allocate buffers */ if (overlap_buffer[0] == NULL) overlap_buffer[0] = (int32_t *) buffer_alloc(FIXED_BUFSIZE * sizeof(int32_t)); @@ -68,6 +65,19 @@ bool tdspeed_init(int samplerate, bool stereo, int factor) outbuf[0] = (int32_t *) buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); if (outbuf[1] == NULL) outbuf[1] = (int32_t *) buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); +} + + +bool tdspeed_config(int samplerate, bool stereo, int factor) +{ + struct tdspeed_state_s *st = &tdspeed_state; + int src_frame_sz; + + /* Check buffers were allocated ok */ + if (overlap_buffer[0] == NULL || overlap_buffer[1] == NULL) + return false; + if (outbuf[0] == NULL || outbuf[1] == NULL) + return false; /* Check parameters */ if (factor == 100) diff --git a/apps/tdspeed.h b/apps/tdspeed.h index 6d7cecdcdf..72acebebf8 100644 --- a/apps/tdspeed.h +++ b/apps/tdspeed.h @@ -25,7 +25,8 @@ #define TDSPEED_OUTBUFSIZE 4096 -bool tdspeed_init(int samplerate, bool stereo, int factor); +void tdspeed_init(); +bool tdspeed_config(int samplerate, bool stereo, int factor); long tdspeed_est_output_size(void); long tdspeed_est_input_size(long size); int tdspeed_doit(int32_t *src[], int count); -- cgit v1.2.3