1
1
#pragma once
2
2
#include < stdint.h>
3
+
3
4
#include " Utils/Logger.h"
4
5
/* !
5
6
* @file
6
7
* @defgroup audio_driver Audio Driver
7
8
* @defgroup enumerations Public enumeration types
8
9
*/
9
10
10
- // To increase the max volume e.g. for ai_thinker (ES8388) 2957 or A202 -> set to 1 or 2
11
- // 0 AUX volume is LINE level
12
- // 1 you can control the AUX volume with setVolume()
11
+ // To increase the max volume e.g. for ai_thinker (ES8388) 2957 or A202 -> set
12
+ // to 1 or 2 0 AUX volume is LINE level 1 you can control the AUX volume with
13
+ // setVolume()
13
14
#ifndef AI_THINKER_ES8388_VOLUME_HACK
14
- # define AI_THINKER_ES8388_VOLUME_HACK 1
15
+ #define AI_THINKER_ES8388_VOLUME_HACK 1
15
16
#endif
16
17
17
18
// Default volume at startup
18
19
#ifndef DRIVER_DEFAULT_VOLUME
19
- # define DRIVER_DEFAULT_VOLUME 70
20
+ #define DRIVER_DEFAULT_VOLUME 70
20
21
#endif
21
22
22
23
// Define the default gain for the microphone amp (see values from
23
24
// es_mic_gain_t) Alternativly you can call es8388_set_mic_gain(es_mic_gain_t
24
25
// gain) if you prefer to use value from an comprehensive enum
25
26
#ifndef ES8388_DEFAULT_INPUT_GAIN
26
- # define ES8388_DEFAULT_INPUT_GAIN 25
27
+ #define ES8388_DEFAULT_INPUT_GAIN 25
27
28
#endif
28
29
29
30
// / Fixed Definitions
@@ -86,13 +87,18 @@ typedef enum {
86
87
*/
87
88
typedef enum {
88
89
RATE_8K = 0 , /* !< set to 8k samples per second */
89
- RATE_11K, /* !< set to 11.025k samples per second */
90
- RATE_16K, /* !< set to 16k samples in per second */
91
- RATE_22K, /* !< set to 22.050k samples per second */
92
- RATE_24K, /* !< set to 24k samples in per second */
93
- RATE_32K, /* !< set to 32k samples in per second */
94
- RATE_44K, /* !< set to 44.1k samples per second */
95
- RATE_48K, /* !< set to 48k samples per second */
90
+ RATE_11K, /* !< set to 11.025k samples per second */
91
+ RATE_16K, /* !< set to 16k samples in per second */
92
+ RATE_22K, /* !< set to 22.050k samples per second */
93
+ RATE_24K, /* !< set to 24k samples in per second */
94
+ RATE_32K, /* !< set to 32k samples in per second */
95
+ RATE_44K, /* !< set to 44.1k samples per second */
96
+ RATE_48K, /* !< set to 48k samples per second */
97
+ RATE_88K, /* !< set to 88.2k samples per second */
98
+ RATE_96K, /* !< set to 96k samples per second */
99
+ RATE_128K, /* !< set to 128K samples per second */
100
+ RATE_176K, /* !< set to 176.4K samples per second */
101
+ RATE_192K, /* !< set to 192k samples per second */
96
102
} samplerate_t ;
97
103
98
104
/* *
@@ -101,13 +107,13 @@ typedef enum {
101
107
* @ingroup enumerations
102
108
*/
103
109
typedef enum {
104
- BIT_LENGTH_MIN = -1 ,
105
- BIT_LENGTH_16BITS = 0x03 ,
106
- BIT_LENGTH_18BITS = 0x02 ,
107
- BIT_LENGTH_20BITS = 0x01 ,
108
- BIT_LENGTH_24BITS = 0x00 ,
109
- BIT_LENGTH_32BITS = 0x04 ,
110
- BIT_LENGTH_MAX,
110
+ BIT_LENGTH_MIN = -1 ,
111
+ BIT_LENGTH_16BITS = 0x03 ,
112
+ BIT_LENGTH_18BITS = 0x02 ,
113
+ BIT_LENGTH_20BITS = 0x01 ,
114
+ BIT_LENGTH_24BITS = 0x00 ,
115
+ BIT_LENGTH_32BITS = 0x04 ,
116
+ BIT_LENGTH_MAX,
111
117
} sample_bits_t ;
112
118
113
119
/* *
@@ -117,10 +123,10 @@ typedef enum {
117
123
*/
118
124
typedef enum {
119
125
I2S_NORMAL = 0 , /* !< set normal I2S format */
120
- I2S_LEFT = 1 , /* !< set all left format */
121
- I2S_RIGHT = 2 , /* !< set all right format */
122
- I2S_DSP = 3 , /* !< set dsp/pcm format */
123
- TDM = 4 , /* !< set tdm format */
126
+ I2S_LEFT = 1 , /* !< set all left format */
127
+ I2S_RIGHT = 2 , /* !< set all right format */
128
+ I2S_DSP = 3 , /* !< set dsp/pcm format */
129
+ TDM = 4 , /* !< set tdm format */
124
130
} i2s_format_t ;
125
131
126
132
/* *
@@ -129,20 +135,19 @@ typedef enum {
129
135
* @ingroup enumerations
130
136
*/
131
137
typedef enum {
132
- MIC_GAIN_MIN = -1 ,
133
- MIC_GAIN_0DB = 0 ,
134
- MIC_GAIN_3DB = 3 ,
135
- MIC_GAIN_6DB = 6 ,
136
- MIC_GAIN_9DB = 9 ,
137
- MIC_GAIN_12DB = 12 ,
138
- MIC_GAIN_15DB = 15 ,
139
- MIC_GAIN_18DB = 18 ,
140
- MIC_GAIN_21DB = 21 ,
141
- MIC_GAIN_24DB = 24 ,
142
- MIC_GAIN_MAX,
138
+ MIC_GAIN_MIN = -1 ,
139
+ MIC_GAIN_0DB = 0 ,
140
+ MIC_GAIN_3DB = 3 ,
141
+ MIC_GAIN_6DB = 6 ,
142
+ MIC_GAIN_9DB = 9 ,
143
+ MIC_GAIN_12DB = 12 ,
144
+ MIC_GAIN_15DB = 15 ,
145
+ MIC_GAIN_18DB = 18 ,
146
+ MIC_GAIN_21DB = 21 ,
147
+ MIC_GAIN_24DB = 24 ,
148
+ MIC_GAIN_MAX,
143
149
} es_mic_gain_t ;
144
150
145
-
146
151
/* *
147
152
* @enum codec_mode_t
148
153
* @brief Select media hal codec mode
@@ -151,27 +156,35 @@ typedef enum {
151
156
typedef enum {
152
157
CODEC_MODE_MIN = -1 ,
153
158
CODEC_MODE_NONE = 0x00 ,
154
- CODEC_MODE_ENCODE = 0x01 , /* !< select adc */
155
- CODEC_MODE_DECODE = 0x02 , /* !< select dac */
156
- CODEC_MODE_BOTH = 0x03 , /* !< select both adc and dac */
157
- CODEC_MODE_LINE_IN = 0x04 , /* !< set adc channel */
159
+ CODEC_MODE_ENCODE = 0x01 , /* !< select adc */
160
+ CODEC_MODE_DECODE = 0x02 , /* !< select dac */
161
+ CODEC_MODE_BOTH = 0x03 , /* !< select both adc and dac */
162
+ CODEC_MODE_LINE_IN = 0x04 , /* !< set adc channel */
158
163
CODEC_MODE_MAX
159
164
} codec_mode_t ;
160
165
166
+ typedef enum {
167
+ CHANNELS2 = 2 ,
168
+ CHANNELS8 = 8 ,
169
+ CHANNELS16 = 16 ,
170
+ } channels_t ;
161
171
162
172
/* *
163
173
* @brief I2s interface configuration for audio codec chip
164
174
* @ingroup audio_driver
165
175
*/
166
176
typedef struct {
167
- /* !< Audio codec chip mode: if the microcontroller is master the codec must be slave! */
177
+ /* !< Audio codec chip mode: if the microcontroller is master the codec must be
178
+ * slave! */
168
179
i2s_master_slave_t mode;
169
180
/* !< I2S interface format */
170
181
i2s_format_t fmt;
171
182
/* !< I2S sample rate in samples per second */
172
183
samplerate_t rate;
173
184
/* !< i2s number of bits per sample */
174
185
sample_bits_t bits;
186
+ /* !< i2s number of channels */
187
+ channels_t channels;
175
188
} I2SDefinition;
176
189
177
190
/* *
@@ -180,13 +193,11 @@ typedef struct {
180
193
typedef struct {
181
194
input_device_t input_device; /* !< set adc channel */
182
195
output_device_t output_device; /* !< set dac channel */
183
- I2SDefinition i2s; /* !< set I2S interface configuration */
196
+ I2SDefinition i2s; /* !< set I2S interface configuration */
184
197
} codec_config_t ;
185
198
186
199
#ifdef __cplusplus
187
200
}
188
201
// automatically use namespace
189
202
using namespace audio_driver ;
190
203
#endif
191
-
192
-
0 commit comments