1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef SPEECH_EQ_H
5 #define SPEECH_EQ_H
6 
7 #include "iirfilt.h"
8 
9 // use more frame_size * sizeof(float) ram
10 #ifdef __arm__
11 #define EQ_USE_CMSIS_IIR
12 #endif
13 
14 #define MAX_VQE_EQ_BAND 6
15 
16 typedef struct
17 {
18     enum IIR_BIQUARD_TYPE type;
19     union
20     {
21         /* Raw config, used when type is IIR_BIQUARD_RAW */
22         struct
23         {
24             float a1; float a2; float b0; float b1; float b2;
25         } raw;
26         /* Generate coeffs using user defined params, used in other type */
27         struct
28         {
29             float f0; float gain; float q;
30         } design;
31     };
32 } BiquardParam;
33 
34 typedef struct
35 {
36     int32_t     bypass;
37     float       gain;
38     int32_t     num;
39 	BiquardParam params[MAX_VQE_EQ_BAND];
40 } EqConfig;
41 
42 typedef struct EqState_ EqState;
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 EqState *eq_init(int32_t sample_rate, int32_t frame_size, const EqConfig *cfg);
49 
50 int32_t eq_destroy(EqState *st);
51 
52 int32_t eq_set_config(EqState *st, const EqConfig *cfg);
53 
54 int32_t eq_process(EqState *st, int16_t *pcm_buf, int32_t pcm_len);
55 
56 int32_t eq_process_int24(EqState *st, int32_t *pcm_buf, int32_t pcm_len);
57 
58 int32_t eq_process_float(EqState *st, float *pcm_buf, int32_t pcm_len);
59 
60 int32_t eq_process2(EqState *st, int16_t *pcm_buf, int32_t pcm_len, int32_t stride);
61 
62 int32_t eq_process2_int24(EqState *st, int32_t *pcm_buf, int32_t pcm_len, int32_t stride);
63 
64 int32_t eq_process2_float(EqState *st, float *pcm_buf, int32_t pcm_len, int32_t stride);
65 
66 float eq_get_required_mips(EqState *st);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif