summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-05-08 21:27:43 -0400
committerMichael Sevakis <jethead71@rockbox.org>2012-05-08 21:27:43 -0400
commit87a9951cf8014c86a022bf05c9c025b65067811f (patch)
tree51e79e43981fcf8b07be2598da6c127dd64c7d7e /lib/rbcodec/dsp
parent2dda258f99cb5575724d26a32077dad92fb8e181 (diff)
Consolidate some sample input code.
Input functions have common setup sequences that can be placed into an inline function instead of repeating it all repeatedly. Change-Id: I9e62904ff0948651c64ddf160ed4400ed6dc81ff
Diffstat (limited to 'lib/rbcodec/dsp')
-rw-r--r--lib/rbcodec/dsp/dsp_sample_input.c97
1 files changed, 38 insertions, 59 deletions
diff --git a/lib/rbcodec/dsp/dsp_sample_input.c b/lib/rbcodec/dsp/dsp_sample_input.c
index df0b01f8c6..284f34c96a 100644
--- a/lib/rbcodec/dsp/dsp_sample_input.c
+++ b/lib/rbcodec/dsp/dsp_sample_input.c
@@ -55,27 +55,42 @@ extern void dsp_sample_output_flush(struct sample_io_data *this);
/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */
static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR;
-/* convert count 16-bit mono to 32-bit mono */
-static void sample_input_mono16(struct sample_io_data *this,
- struct dsp_buffer **buf_p)
+/* inline helper to setup buffers when conversion is required */
+static FORCE_INLINE int sample_input_setup(struct sample_io_data *this,
+ struct dsp_buffer **buf_p,
+ int channels,
+ struct dsp_buffer **src,
+ struct dsp_buffer **dst)
{
- struct dsp_buffer *src = *buf_p;
- struct dsp_buffer *dst = &this->sample_buf;
+ struct dsp_buffer *s = *buf_p;
+ struct dsp_buffer *d = *dst = &this->sample_buf;
- *buf_p = dst;
+ *buf_p = d;
- if (dst->remcount > 0)
- return; /* data still remains */
+ if (d->remcount > 0)
+ return 0; /* data still remains */
+
+ *src = s;
+
+ int count = MIN(s->remcount, SAMPLE_BUF_COUNT);
- int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
+ d->remcount = count;
+ d->p32[0] = this->sample_buf_arr[0];
+ d->p32[1] = this->sample_buf_arr[channels - 1];
+ d->proc_mask = s->proc_mask;
+
+ return count;
+}
- dst->remcount = count;
- dst->p32[0] = this->sample_buf_arr[0];
- dst->p32[1] = this->sample_buf_arr[0];
- dst->proc_mask = src->proc_mask;
+/* convert count 16-bit mono to 32-bit mono */
+static void sample_input_mono16(struct sample_io_data *this,
+ struct dsp_buffer **buf_p)
+{
+ struct dsp_buffer *src, *dst;
+ int count = sample_input_setup(this, buf_p, 1, &src, &dst);
if (count <= 0)
- return; /* purged sample_buf */
+ return;
const int16_t *s = src->pin[0];
int32_t *d = dst->p32[0];
@@ -94,23 +109,11 @@ static void sample_input_mono16(struct sample_io_data *this,
static void sample_input_i_stereo16(struct sample_io_data *this,
struct dsp_buffer **buf_p)
{
- struct dsp_buffer *src = *buf_p;
- struct dsp_buffer *dst = &this->sample_buf;
-
- *buf_p = dst;
-
- if (dst->remcount > 0)
- return; /* data still remains */
-
- int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
-
- dst->remcount = count;
- dst->p32[0] = this->sample_buf_arr[0];
- dst->p32[1] = this->sample_buf_arr[1];
- dst->proc_mask = src->proc_mask;
+ struct dsp_buffer *src, *dst;
+ int count = sample_input_setup(this, buf_p, 2, &src, &dst);
if (count <= 0)
- return; /* purged sample_buf */
+ return;
const int16_t *s = src->pin[0];
int32_t *dl = dst->p32[0];
@@ -131,23 +134,11 @@ static void sample_input_i_stereo16(struct sample_io_data *this,
static void sample_input_ni_stereo16(struct sample_io_data *this,
struct dsp_buffer **buf_p)
{
- struct dsp_buffer *src = *buf_p;
- struct dsp_buffer *dst = &this->sample_buf;
-
- *buf_p = dst;
-
- if (dst->remcount > 0)
- return; /* data still remains */
-
- int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
-
- dst->remcount = count;
- dst->p32[0] = this->sample_buf_arr[0];
- dst->p32[1] = this->sample_buf_arr[1];
- dst->proc_mask = src->proc_mask;
+ struct dsp_buffer *src, *dst;
+ int count = sample_input_setup(this, buf_p, 2, &src, &dst);
if (count <= 0)
- return; /* purged sample_buf */
+ return;
const int16_t *sl = src->pin[0];
const int16_t *sr = src->pin[1];
@@ -187,23 +178,11 @@ static void sample_input_mono32(struct sample_io_data *this,
static void sample_input_i_stereo32(struct sample_io_data *this,
struct dsp_buffer **buf_p)
{
- struct dsp_buffer *src = *buf_p;
- struct dsp_buffer *dst = &this->sample_buf;
-
- *buf_p = dst;
-
- if (dst->remcount > 0)
- return; /* data still remains */
-
- int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
-
- dst->remcount = count;
- dst->p32[0] = this->sample_buf_arr[0];
- dst->p32[1] = this->sample_buf_arr[1];
- dst->proc_mask = src->proc_mask;
+ struct dsp_buffer *src, *dst;
+ int count = sample_input_setup(this, buf_p, 2, &src, &dst);
if (count <= 0)
- return; /* purged sample_buf */
+ return;
const int32_t *s = src->pin[0];
int32_t *dl = dst->p32[0];