summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/dsp_sample_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/dsp/dsp_sample_input.c')
-rw-r--r--lib/rbcodec/dsp/dsp_sample_input.c92
1 files changed, 50 insertions, 42 deletions
diff --git a/lib/rbcodec/dsp/dsp_sample_input.c b/lib/rbcodec/dsp/dsp_sample_input.c
index 284f34c96a..65d2a110e1 100644
--- a/lib/rbcodec/dsp/dsp_sample_input.c
+++ b/lib/rbcodec/dsp/dsp_sample_input.c
@@ -21,12 +21,12 @@
21 ****************************************************************************/ 21 ****************************************************************************/
22#include "config.h" 22#include "config.h"
23#include "system.h" 23#include "system.h"
24#include "fixedpoint.h"
24#include "dsp_core.h" 25#include "dsp_core.h"
25#include "dsp_sample_io.h" 26#include "dsp_sample_io.h"
27#include "dsp_proc_entry.h"
26 28
27#if 1 29#if 0
28#include <debug.h>
29#else
30#undef DEBUGF 30#undef DEBUGF
31#define DEBUGF(...) 31#define DEBUGF(...)
32#endif 32#endif
@@ -50,6 +50,8 @@
50 50
51extern void dsp_sample_output_init(struct sample_io_data *this); 51extern void dsp_sample_output_init(struct sample_io_data *this);
52extern void dsp_sample_output_flush(struct sample_io_data *this); 52extern void dsp_sample_output_flush(struct sample_io_data *this);
53extern void dsp_sample_output_format_change(struct sample_io_data *this,
54 struct sample_format *format);
53 55
54#define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */ 56#define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */
55/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */ 57/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */
@@ -75,8 +77,8 @@ static FORCE_INLINE int sample_input_setup(struct sample_io_data *this,
75 int count = MIN(s->remcount, SAMPLE_BUF_COUNT); 77 int count = MIN(s->remcount, SAMPLE_BUF_COUNT);
76 78
77 d->remcount = count; 79 d->remcount = count;
78 d->p32[0] = this->sample_buf_arr[0]; 80 d->p32[0] = this->sample_buf_p[0];
79 d->p32[1] = this->sample_buf_arr[channels - 1]; 81 d->p32[1] = this->sample_buf_p[channels - 1];
80 d->proc_mask = s->proc_mask; 82 d->proc_mask = s->proc_mask;
81 83
82 return count; 84 return count;
@@ -210,9 +212,9 @@ static void sample_input_ni_stereo32(struct sample_io_data *this,
210} 212}
211 213
212/* set the to-native sample conversion function based on dsp sample 214/* set the to-native sample conversion function based on dsp sample
213 * parameters */ 215 * parameters - depends upon stereo_mode and sample_depth */
214static void dsp_sample_input_format_change(struct sample_io_data *this, 216void dsp_sample_input_format_change(struct sample_io_data *this,
215 struct dsp_buffer **buf_p) 217 struct sample_format *format)
216{ 218{
217 static const sample_input_fn_type fns[STEREO_NUM_MODES][2] = 219 static const sample_input_fn_type fns[STEREO_NUM_MODES][2] =
218 { 220 {
@@ -227,33 +229,35 @@ static void dsp_sample_input_format_change(struct sample_io_data *this,
227 sample_input_mono32 }, 229 sample_input_mono32 },
228 }; 230 };
229 231
230 struct dsp_buffer *src = *buf_p; 232 if (this->sample_buf.remcount > 0)
231 struct dsp_buffer *dst = &this->sample_buf; 233 return;
232
233 /* Ack configured format change */
234 format_change_ack(&this->format);
235 234
236 if (dst->remcount > 0) 235 DSP_PRINT_FORMAT(DSP Input, this->format);
237 {
238 *buf_p = dst;
239 return; /* data still remains */
240 }
241 236
242 DSP_PRINT_FORMAT(DSP Input, -1, src->format); 237 this->format_dirty = 0;
238 this->sample_buf.format = *format;
239 this->input_samples = fns[this->stereo_mode]
240 [this->sample_depth > NATIVE_DEPTH ? 1 : 0];
241}
243 242
244 /* new format - remember it and pass it along */ 243/* increment the format version counter */
245 dst->format = src->format; 244static void format_change_set(struct sample_io_data *this)
246 this->input_samples[0] = fns[this->stereo_mode] 245{
247 [this->sample_depth > NATIVE_DEPTH ? 1 : 0]; 246 if (this->format_dirty)
247 return;
248 248
249 this->input_samples[0](this, buf_p); 249 this->format.version = (uint8_t)(this->format.version + 1) ?: 1;
250 this->format_dirty = 1;
251}
250 252
251 if (*buf_p == dst) /* buffer switch? */ 253/* discard the sample buffer */
252 format_change_ack(&src->format); 254static void dsp_sample_input_flush(struct sample_io_data *this)
255{
256 this->sample_buf.remcount = 0;
253} 257}
254 258
255static void dsp_sample_input_init(struct sample_io_data *this, 259static void INIT_ATTR dsp_sample_input_init(struct sample_io_data *this,
256 enum dsp_ids dsp_id) 260 enum dsp_ids dsp_id)
257{ 261{
258 int32_t *lbuf, *rbuf; 262 int32_t *lbuf, *rbuf;
259 263
@@ -274,17 +278,15 @@ static void dsp_sample_input_init(struct sample_io_data *this,
274 return; 278 return;
275 } 279 }
276 280
277 this->sample_buf_arr[0] = lbuf; 281 this->sample_buf_p[0] = lbuf;
278 this->sample_buf_arr[1] = rbuf; 282 this->sample_buf_p[1] = rbuf;
279
280 this->input_samples[0] = sample_input_ni_stereo32;
281 this->input_samples[1] = dsp_sample_input_format_change;
282} 283}
283 284
284/* discard the sample buffer */ 285static void INIT_ATTR dsp_sample_io_init(struct sample_io_data *this,
285static void dsp_sample_input_flush(struct sample_io_data *this) 286 enum dsp_ids dsp_id)
286{ 287{
287 this->sample_buf.remcount = 0; 288 dsp_sample_input_init(this, dsp_id);
289 dsp_sample_output_init(this);
288} 290}
289 291
290void dsp_sample_io_configure(struct sample_io_data *this, 292void dsp_sample_io_configure(struct sample_io_data *this,
@@ -294,13 +296,12 @@ void dsp_sample_io_configure(struct sample_io_data *this,
294 switch (setting) 296 switch (setting)
295 { 297 {
296 case DSP_INIT: 298 case DSP_INIT:
297 dsp_sample_input_init(this, (enum dsp_ids)value); 299 dsp_sample_io_init(this, (enum dsp_ids)value);
298 dsp_sample_output_init(this);
299 break; 300 break;
300 301
301 case DSP_RESET: 302 case DSP_RESET:
302 /* Reset all sample descriptions to default */ 303 /* Reset all sample descriptions to default */
303 format_change_set(&this->format); 304 format_change_set(this);
304 this->format.num_channels = 2; 305 this->format.num_channels = 2;
305 this->format.frac_bits = WORD_FRACBITS; 306 this->format.frac_bits = WORD_FRACBITS;
306 this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH; 307 this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH;
@@ -311,14 +312,14 @@ void dsp_sample_io_configure(struct sample_io_data *this,
311 break; 312 break;
312 313
313 case DSP_SET_FREQUENCY: 314 case DSP_SET_FREQUENCY:
315 format_change_set(this);
314 value = value > 0 ? value : NATIVE_FREQUENCY; 316 value = value > 0 ? value : NATIVE_FREQUENCY;
315 format_change_set(&this->format);
316 this->format.frequency = value; 317 this->format.frequency = value;
317 this->format.codec_frequency = value; 318 this->format.codec_frequency = value;
318 break; 319 break;
319 320
320 case DSP_SET_SAMPLE_DEPTH: 321 case DSP_SET_SAMPLE_DEPTH:
321 format_change_set(&this->format); 322 format_change_set(this);
322 this->format.frac_bits = 323 this->format.frac_bits =
323 value <= NATIVE_DEPTH ? WORD_FRACBITS : value; 324 value <= NATIVE_DEPTH ? WORD_FRACBITS : value;
324 this->format.output_scale = 325 this->format.output_scale =
@@ -327,7 +328,7 @@ void dsp_sample_io_configure(struct sample_io_data *this,
327 break; 328 break;
328 329
329 case DSP_SET_STEREO_MODE: 330 case DSP_SET_STEREO_MODE:
330 format_change_set(&this->format); 331 format_change_set(this);
331 this->format.num_channels = value == STEREO_MONO ? 1 : 2; 332 this->format.num_channels = value == STEREO_MONO ? 1 : 2;
332 this->stereo_mode = value; 333 this->stereo_mode = value;
333 break; 334 break;
@@ -336,5 +337,12 @@ void dsp_sample_io_configure(struct sample_io_data *this,
336 dsp_sample_input_flush(this); 337 dsp_sample_input_flush(this);
337 dsp_sample_output_flush(this); 338 dsp_sample_output_flush(this);
338 break; 339 break;
340
341 case DSP_SET_PITCH:
342 format_change_set(this);
343 value = value > 0 ? value : (1 << 16);
344 this->format.frequency =
345 fp_mul(value, this->format.codec_frequency, 16);
346 break;
339 } 347 }
340} 348}