summaryrefslogtreecommitdiffstats
path: root/apps
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 /apps
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
Diffstat (limited to 'apps')
-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;
static long replaygain;
static bool crossfeed_enabled;
+#define AUDIO_DSP (dsp_conf[CODEC_IDX_AUDIO])
+#define VOICE_DSP (dsp_conf[CODEC_IDX_VOICE])
+
+/* The internal format is 32-bit samples, non-interleaved, stereo. This
+ * format is similar to the raw output from several codecs, so the amount
+ * of copying needed is minimized for that case.
+ */
+
+#define RESAMPLE_RATIO 4 /* Enough for 11,025 Hz -> 44,100 Hz */
+
+static int32_t small_sample_buf[SMALL_SAMPLE_BUF_COUNT] IBSS_ATTR;
+static int32_t small_resample_buf[SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO] IBSS_ATTR;
+
+static int32_t *big_sample_buf = NULL;
+static int32_t *big_resample_buf = NULL;
+static int big_sample_buf_count = -1; /* -1=unknown, 0=not available */
+
+static int sample_buf_count;
+static int32_t *sample_buf;
+static int32_t *resample_buf;
+
+#define SAMPLE_BUF_LEFT_CHANNEL 0
+#define SAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2)
+#define RESAMPLE_BUF_LEFT_CHANNEL 0
+#define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO)
+
/* limiter */
+/* MAX_COUNT is largest possible sample count in limiter_process. This is
+ needed in case time stretch makes the count in dsp_process larger than
+ the limiter buffer. */
+#define MAX_COUNT MAX(SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO / 2, LIMITER_BUFFER_SIZE)
static int count_adjust;
static bool limiter_buffer_active;
static bool limiter_buffer_full;
@@ -238,7 +268,7 @@ static int32_t *start_lim_buf[2] IBSS_ATTR,
static uint16_t lim_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR;
static uint16_t *start_peak IBSS_ATTR,
*end_peak IBSS_ATTR;
-static uint16_t out_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR;
+static uint16_t out_buf_peak[MAX_COUNT] IBSS_ATTR;
static uint16_t *out_buf_peak_index IBSS_ATTR;
static uint16_t release_peak IBSS_ATTR;
static int32_t in_samp IBSS_ATTR,
@@ -276,32 +306,6 @@ const long gain_steps[49] ICONST_ATTR = { 0x10000000,
0x4EA84FE, 0x4C6D00E, 0x4A41E78, 0x48268DF, 0x461A81C,
0x441D53E, 0x422E985, 0x404DE62};
-#define AUDIO_DSP (dsp_conf[CODEC_IDX_AUDIO])
-#define VOICE_DSP (dsp_conf[CODEC_IDX_VOICE])
-
-/* The internal format is 32-bit samples, non-interleaved, stereo. This
- * format is similar to the raw output from several codecs, so the amount
- * of copying needed is minimized for that case.
- */
-
-#define RESAMPLE_RATIO 4 /* Enough for 11,025 Hz -> 44,100 Hz */
-
-static int32_t small_sample_buf[SMALL_SAMPLE_BUF_COUNT] IBSS_ATTR;
-static int32_t small_resample_buf[SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO] IBSS_ATTR;
-
-static int32_t *big_sample_buf = NULL;
-static int32_t *big_resample_buf = NULL;
-static int big_sample_buf_count = -1; /* -1=unknown, 0=not available */
-
-static int sample_buf_count;
-static int32_t *sample_buf;
-static int32_t *resample_buf;
-
-#define SAMPLE_BUF_LEFT_CHANNEL 0
-#define SAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2)
-#define RESAMPLE_BUF_LEFT_CHANNEL 0
-#define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO)
-
/* Clip sample to signed 16 bit range */
static inline int32_t clip_sample_16(int32_t sample)