summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2009-09-21 17:04:40 +0000
committerJeffrey Goode <jeffg7@gmail.com>2009-09-21 17:04:40 +0000
commit81f268ad48aa3917a5d3a0e3e4718377b6558449 (patch)
treed9d1c0d631c7e26609efd9fe1c8bf6c3ac0a7546
parent75b7a1f8873ae3c384d3c9816c7a630f2069665c (diff)
downloadrockbox-81f268ad48aa3917a5d3a0e3e4718377b6558449.tar.gz
rockbox-81f268ad48aa3917a5d3a0e3e4718377b6558449.zip
Potential fix for FS#10572: limiter + time stretch produces garbage output
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22772 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/dsp.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index 5aa93ccc7c..5f9749c02c 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -227,7 +227,37 @@ static long album_peak;
227static long replaygain; 227static long replaygain;
228static bool crossfeed_enabled; 228static bool crossfeed_enabled;
229 229
230#define AUDIO_DSP (dsp_conf[CODEC_IDX_AUDIO])
231#define VOICE_DSP (dsp_conf[CODEC_IDX_VOICE])
232
233/* The internal format is 32-bit samples, non-interleaved, stereo. This
234 * format is similar to the raw output from several codecs, so the amount
235 * of copying needed is minimized for that case.
236 */
237
238#define RESAMPLE_RATIO 4 /* Enough for 11,025 Hz -> 44,100 Hz */
239
240static int32_t small_sample_buf[SMALL_SAMPLE_BUF_COUNT] IBSS_ATTR;
241static int32_t small_resample_buf[SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO] IBSS_ATTR;
242
243static int32_t *big_sample_buf = NULL;
244static int32_t *big_resample_buf = NULL;
245static int big_sample_buf_count = -1; /* -1=unknown, 0=not available */
246
247static int sample_buf_count;
248static int32_t *sample_buf;
249static int32_t *resample_buf;
250
251#define SAMPLE_BUF_LEFT_CHANNEL 0
252#define SAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2)
253#define RESAMPLE_BUF_LEFT_CHANNEL 0
254#define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO)
255
230/* limiter */ 256/* limiter */
257/* MAX_COUNT is largest possible sample count in limiter_process. This is
258 needed in case time stretch makes the count in dsp_process larger than
259 the limiter buffer. */
260#define MAX_COUNT MAX(SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO / 2, LIMITER_BUFFER_SIZE)
231static int count_adjust; 261static int count_adjust;
232static bool limiter_buffer_active; 262static bool limiter_buffer_active;
233static bool limiter_buffer_full; 263static bool limiter_buffer_full;
@@ -238,7 +268,7 @@ static int32_t *start_lim_buf[2] IBSS_ATTR,
238static uint16_t lim_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR; 268static uint16_t lim_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR;
239static uint16_t *start_peak IBSS_ATTR, 269static uint16_t *start_peak IBSS_ATTR,
240 *end_peak IBSS_ATTR; 270 *end_peak IBSS_ATTR;
241static uint16_t out_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR; 271static uint16_t out_buf_peak[MAX_COUNT] IBSS_ATTR;
242static uint16_t *out_buf_peak_index IBSS_ATTR; 272static uint16_t *out_buf_peak_index IBSS_ATTR;
243static uint16_t release_peak IBSS_ATTR; 273static uint16_t release_peak IBSS_ATTR;
244static int32_t in_samp IBSS_ATTR, 274static int32_t in_samp IBSS_ATTR,
@@ -276,32 +306,6 @@ const long gain_steps[49] ICONST_ATTR = { 0x10000000,
276 0x4EA84FE, 0x4C6D00E, 0x4A41E78, 0x48268DF, 0x461A81C, 306 0x4EA84FE, 0x4C6D00E, 0x4A41E78, 0x48268DF, 0x461A81C,
277 0x441D53E, 0x422E985, 0x404DE62}; 307 0x441D53E, 0x422E985, 0x404DE62};
278 308
279#define AUDIO_DSP (dsp_conf[CODEC_IDX_AUDIO])
280#define VOICE_DSP (dsp_conf[CODEC_IDX_VOICE])
281
282/* The internal format is 32-bit samples, non-interleaved, stereo. This
283 * format is similar to the raw output from several codecs, so the amount
284 * of copying needed is minimized for that case.
285 */
286
287#define RESAMPLE_RATIO 4 /* Enough for 11,025 Hz -> 44,100 Hz */
288
289static int32_t small_sample_buf[SMALL_SAMPLE_BUF_COUNT] IBSS_ATTR;
290static int32_t small_resample_buf[SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO] IBSS_ATTR;
291
292static int32_t *big_sample_buf = NULL;
293static int32_t *big_resample_buf = NULL;
294static int big_sample_buf_count = -1; /* -1=unknown, 0=not available */
295
296static int sample_buf_count;
297static int32_t *sample_buf;
298static int32_t *resample_buf;
299
300#define SAMPLE_BUF_LEFT_CHANNEL 0
301#define SAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2)
302#define RESAMPLE_BUF_LEFT_CHANNEL 0
303#define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO)
304
305 309
306/* Clip sample to signed 16 bit range */ 310/* Clip sample to signed 16 bit range */
307static inline int32_t clip_sample_16(int32_t sample) 311static inline int32_t clip_sample_16(int32_t sample)