summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp
diff options
context:
space:
mode:
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);
55/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */ 55/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */
56static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR; 56static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR;
57 57
58/* convert count 16-bit mono to 32-bit mono */ 58/* inline helper to setup buffers when conversion is required */
59static void sample_input_mono16(struct sample_io_data *this, 59static FORCE_INLINE int sample_input_setup(struct sample_io_data *this,
60 struct dsp_buffer **buf_p) 60 struct dsp_buffer **buf_p,
61 int channels,
62 struct dsp_buffer **src,
63 struct dsp_buffer **dst)
61{ 64{
62 struct dsp_buffer *src = *buf_p; 65 struct dsp_buffer *s = *buf_p;
63 struct dsp_buffer *dst = &this->sample_buf; 66 struct dsp_buffer *d = *dst = &this->sample_buf;
64 67
65 *buf_p = dst; 68 *buf_p = d;
66 69
67 if (dst->remcount > 0) 70 if (d->remcount > 0)
68 return; /* data still remains */ 71 return 0; /* data still remains */
72
73 *src = s;
74
75 int count = MIN(s->remcount, SAMPLE_BUF_COUNT);
69 76
70 int count = MIN(src->remcount, SAMPLE_BUF_COUNT); 77 d->remcount = count;
78 d->p32[0] = this->sample_buf_arr[0];
79 d->p32[1] = this->sample_buf_arr[channels - 1];
80 d->proc_mask = s->proc_mask;
81
82 return count;
83}
71 84
72 dst->remcount = count; 85/* convert count 16-bit mono to 32-bit mono */
73 dst->p32[0] = this->sample_buf_arr[0]; 86static void sample_input_mono16(struct sample_io_data *this,
74 dst->p32[1] = this->sample_buf_arr[0]; 87 struct dsp_buffer **buf_p)
75 dst->proc_mask = src->proc_mask; 88{
89 struct dsp_buffer *src, *dst;
90 int count = sample_input_setup(this, buf_p, 1, &src, &dst);
76 91
77 if (count <= 0) 92 if (count <= 0)
78 return; /* purged sample_buf */ 93 return;
79 94
80 const int16_t *s = src->pin[0]; 95 const int16_t *s = src->pin[0];
81 int32_t *d = dst->p32[0]; 96 int32_t *d = dst->p32[0];
@@ -94,23 +109,11 @@ static void sample_input_mono16(struct sample_io_data *this,
94static void sample_input_i_stereo16(struct sample_io_data *this, 109static void sample_input_i_stereo16(struct sample_io_data *this,
95 struct dsp_buffer **buf_p) 110 struct dsp_buffer **buf_p)
96{ 111{
97 struct dsp_buffer *src = *buf_p; 112 struct dsp_buffer *src, *dst;
98 struct dsp_buffer *dst = &this->sample_buf; 113 int count = sample_input_setup(this, buf_p, 2, &src, &dst);
99
100 *buf_p = dst;
101
102 if (dst->remcount > 0)
103 return; /* data still remains */
104
105 int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
106
107 dst->remcount = count;
108 dst->p32[0] = this->sample_buf_arr[0];
109 dst->p32[1] = this->sample_buf_arr[1];
110 dst->proc_mask = src->proc_mask;
111 114
112 if (count <= 0) 115 if (count <= 0)
113 return; /* purged sample_buf */ 116 return;
114 117
115 const int16_t *s = src->pin[0]; 118 const int16_t *s = src->pin[0];
116 int32_t *dl = dst->p32[0]; 119 int32_t *dl = dst->p32[0];
@@ -131,23 +134,11 @@ static void sample_input_i_stereo16(struct sample_io_data *this,
131static void sample_input_ni_stereo16(struct sample_io_data *this, 134static void sample_input_ni_stereo16(struct sample_io_data *this,
132 struct dsp_buffer **buf_p) 135 struct dsp_buffer **buf_p)
133{ 136{
134 struct dsp_buffer *src = *buf_p; 137 struct dsp_buffer *src, *dst;
135 struct dsp_buffer *dst = &this->sample_buf; 138 int count = sample_input_setup(this, buf_p, 2, &src, &dst);
136
137 *buf_p = dst;
138
139 if (dst->remcount > 0)
140 return; /* data still remains */
141
142 int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
143
144 dst->remcount = count;
145 dst->p32[0] = this->sample_buf_arr[0];
146 dst->p32[1] = this->sample_buf_arr[1];
147 dst->proc_mask = src->proc_mask;
148 139
149 if (count <= 0) 140 if (count <= 0)
150 return; /* purged sample_buf */ 141 return;
151 142
152 const int16_t *sl = src->pin[0]; 143 const int16_t *sl = src->pin[0];
153 const int16_t *sr = src->pin[1]; 144 const int16_t *sr = src->pin[1];
@@ -187,23 +178,11 @@ static void sample_input_mono32(struct sample_io_data *this,
187static void sample_input_i_stereo32(struct sample_io_data *this, 178static void sample_input_i_stereo32(struct sample_io_data *this,
188 struct dsp_buffer **buf_p) 179 struct dsp_buffer **buf_p)
189{ 180{
190 struct dsp_buffer *src = *buf_p; 181 struct dsp_buffer *src, *dst;
191 struct dsp_buffer *dst = &this->sample_buf; 182 int count = sample_input_setup(this, buf_p, 2, &src, &dst);
192
193 *buf_p = dst;
194
195 if (dst->remcount > 0)
196 return; /* data still remains */
197
198 int count = MIN(src->remcount, SAMPLE_BUF_COUNT);
199
200 dst->remcount = count;
201 dst->p32[0] = this->sample_buf_arr[0];
202 dst->p32[1] = this->sample_buf_arr[1];
203 dst->proc_mask = src->proc_mask;
204 183
205 if (count <= 0) 184 if (count <= 0)
206 return; /* purged sample_buf */ 185 return;
207 186
208 const int32_t *s = src->pin[0]; 187 const int32_t *s = src->pin[0];
209 int32_t *dl = dst->p32[0]; 188 int32_t *dl = dst->p32[0];