1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef DSPUTIL_H_
7 #define DSPUTIL_H_
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #include <stdint.h>
14 
15 #include "cras_audio_format.h"
16 
17 /* Converts from interleaved int16_t samples to non-interleaved float samples.
18  * The int16_t samples have range [-32768, 32767], and the float samples have
19  * range [-1.0, 1.0].
20  * Args:
21  *    input - The interleaved input buffer. Every "channels" samples is a frame.
22  *    output - Pointers to output buffers. There are "channels" output buffers.
23  *    channels - The number of samples per frame.
24  *    frames - The number of frames to convert.
25  * Returns:
26  *    Negative error if format isn't supported, otherwise 0.
27  */
28 int dsp_util_deinterleave(uint8_t *input, float *const *output, int channels,
29 			  snd_pcm_format_t format, int frames);
30 
31 /* Converts from non-interleaved float samples to interleaved int16_t samples.
32  * The int16_t samples have range [-32768, 32767], and the float samples have
33  * range [-1.0, 1.0]. This is the inverse of dsputil_deinterleave().
34  * Args:
35  *    input - Pointers to input buffers. There are "channels" input buffers.
36  *    output - The interleaved output buffer. Every "channels" samples is a
37  *        frame.
38  *    channels - The number of samples per frame.
39  *    frames - The number of frames to convert.
40  * Returns:
41  *    Negative error if format isn't supported, otherwise 0.
42  */
43 int dsp_util_interleave(float *const *input, uint8_t *output, int channels,
44 			snd_pcm_format_t format, int frames);
45 
46 /* Disables denormal numbers in floating point calculation. Denormal numbers
47  * happens often in IIR filters, and it can be very slow.
48  */
49 void dsp_enable_flush_denormal_to_zero();
50 
51 #ifdef __cplusplus
52 } /* extern "C" */
53 #endif
54 
55 #endif /* DSPUTIL_H_ */
56