|
3 | 3 |
|
4 | 4 | #include "main.h" |
5 | 5 |
|
6 | | -#if CONFIG_OPENAI_BOARD_ESP32_S3 |
7 | 6 | #define OPUS_OUT_BUFFER_SIZE 1276 // 1276 bytes is recommended by opus_encode |
| 7 | + |
| 8 | +#if CONFIG_OPENAI_BOARD_ESP32_S3 // Default ESP32-S3 board config |
8 | 9 | #define SAMPLE_RATE 8000 |
9 | 10 | #define BUFFER_SAMPLES 320 |
10 | 11 |
|
| 12 | +#define I2S_DATA_OUT_PORT I2S_NUM_0 |
| 13 | +#define I2S_DATA_IN_PORT I2S_NUM_1 |
11 | 14 | #define MCLK_PIN 0 |
12 | 15 | #define DAC_BCLK_PIN 15 |
13 | 16 | #define DAC_LRCLK_PIN 16 |
14 | 17 | #define DAC_DATA_PIN 17 |
15 | 18 | #define ADC_BCLK_PIN 38 |
16 | 19 | #define ADC_LRCLK_PIN 39 |
17 | 20 | #define ADC_DATA_PIN 40 |
18 | | -#elif CONFIG_OPENAI_BOARD_M5_ATOMS3R |
| 21 | +#elif CONFIG_OPENAI_BOARD_M5_ATOMS3R // ATOMS3R board with Atomic EchoBase |
19 | 22 | #include "es8311.h" |
20 | | -#define OPUS_OUT_BUFFER_SIZE 1276 // 1276 bytes is recommended by opus_encode |
21 | | -#define SAMPLE_RATE 16000 //! EchoBase not support 8K sample rate :) |
22 | | -#define BUFFER_SAMPLES (320 * 2) |
| 23 | +#define SAMPLE_RATE 16000 //! EchoBase not support 8K sample rate :) |
| 24 | +#define BUFFER_SAMPLES (320 * 2) |
23 | 25 |
|
24 | | -#define I2C_PORT I2C_NUM_1 |
| 26 | +#define I2C_PORT I2C_NUM_1 |
25 | 27 | #define I2C_FREQ_HZ 400000 |
26 | 28 | #define I2C_SCL_PIN 39 |
27 | 29 | #define I2C_SDA_PIN 38 |
28 | 30 |
|
29 | | -#define I2S_PORT I2S_NUM_1 |
30 | | -#define MCLK_PIN -1 |
| 31 | +#define I2S_DATA_OUT_PORT I2S_NUM_1 |
| 32 | +#define I2S_DATA_IN_PORT I2S_DATA_OUT_PORT |
| 33 | +#define MCLK_PIN -1 |
31 | 34 | #define DAC_BCLK_PIN 8 |
32 | 35 | #define DAC_LRCLK_PIN 6 |
33 | 36 | #define DAC_DATA_PIN 5 |
@@ -154,7 +157,7 @@ void oai_init_audio_capture() { |
154 | 157 | } |
155 | 158 |
|
156 | 159 | i2s_pin_config_t pin_config_out = { |
157 | | - .mck_io_num = -1, |
| 160 | + .mck_io_num = MCLK_PIN, |
158 | 161 | .bck_io_num = DAC_BCLK_PIN, |
159 | 162 | .ws_io_num = DAC_LRCLK_PIN, |
160 | 163 | .data_out_num = DAC_DATA_PIN, |
@@ -188,11 +191,7 @@ void oai_audio_decode(uint8_t *data, size_t size) { |
188 | 191 |
|
189 | 192 | if (decoded_size > 0) { |
190 | 193 | size_t bytes_written = 0; |
191 | | -#if CONFIG_OPENAI_BOARD_ESP32_S3 |
192 | | - i2s_write(I2S_NUM_0, output_buffer, BUFFER_SAMPLES * sizeof(opus_int16), |
193 | | - &bytes_written, portMAX_DELAY); |
194 | | -#elif CONFIG_OPENAI_BOARD_M5_ATOMS3R |
195 | | - i2s_write(I2S_PORT, output_buffer, BUFFER_SAMPLES * sizeof(opus_int16), |
| 194 | + i2s_write(I2S_DATA_OUT_PORT, output_buffer, BUFFER_SAMPLES * sizeof(opus_int16), |
196 | 195 | &bytes_written, portMAX_DELAY); |
197 | 196 | #endif |
198 | 197 | } |
@@ -227,13 +226,8 @@ void oai_init_audio_encoder() { |
227 | 226 | void oai_send_audio(PeerConnection *peer_connection) { |
228 | 227 | size_t bytes_read = 0; |
229 | 228 |
|
230 | | -#if CONFIG_OPENAI_BOARD_ESP32_S3 |
231 | | - i2s_read(I2S_NUM_1, encoder_input_buffer, BUFFER_SAMPLES, &bytes_read, |
| 229 | + i2s_read(I2S_DATA_IN_PORT, encoder_input_buffer, BUFFER_SAMPLES, &bytes_read, |
232 | 230 | portMAX_DELAY); |
233 | | -#elif CONFIG_OPENAI_BOARD_M5_ATOMS3R |
234 | | - i2s_read(I2S_PORT, encoder_input_buffer, BUFFER_SAMPLES, &bytes_read, |
235 | | - portMAX_DELAY); |
236 | | -#endif |
237 | 231 |
|
238 | 232 | auto encoded_size = |
239 | 233 | opus_encode(opus_encoder, encoder_input_buffer, BUFFER_SAMPLES / 2, |
|
0 commit comments