99#define AUDIO_SPEAKER_BCLK 26
1010#define AUDIO_SPEAKER_LRC 13
1111#define AUDIO_SPEAKER_DIN 25
12- #define AUDIO_SPEAKER_VOL 20
1312
14- // audio mic
13+ // audio microphone
1514#define AUDIO_MIC_SD 2
1615#define AUDIO_MIC_WS 15
1716#define AUDIO_MIC_SCK 4
@@ -33,7 +32,7 @@ void setup() {
3332 while (!Serial);
3433 LOG_INFO (" Board setup started" );
3534
36- // speaker
35+ // create 2s speaker
3736 i2s_config_t i2s_speaker_config = {
3837 .mode = (i2s_mode_t )(I2S_MODE_MASTER | I2S_MODE_TX),
3938 .sample_rate = AUDIO_SAMPLE_RATE,
@@ -60,7 +59,7 @@ void setup() {
6059 LOG_ERROR (" Failed to set i2s speaker pins" );
6160 }
6261
63- // mic
62+ // create i2s microphone
6463 i2s_config_t i2s_mic_config = {
6564 .mode = (i2s_mode_t )(I2S_MODE_MASTER | I2S_MODE_RX),
6665 .sample_rate = AUDIO_SAMPLE_RATE,
@@ -87,13 +86,14 @@ void setup() {
8786 LOG_ERROR (" Failed to set i2s mic pins" );
8887 }
8988
90- // codec2
89+ // run codec2 audio loopback on a separate task
9190 xTaskCreate (&audio_task, " audio_task" , 32000 , NULL , 5 , &audio_task_);
9291
9392 LOG_INFO (" Board setup completed" );
9493}
9594
9695void audio_task (void *param) {
96+ // construct and configure codec2
9797 c2_ = codec2_create (CODEC2_MODE_450);
9898 if (c2_ == NULL ) {
9999 LOG_ERROR (" Failed to create Codec2" );
@@ -107,6 +107,7 @@ void audio_task(void *param) {
107107 LOG_INFO (" Codec2 constructed" , c2_samples_per_frame_, c2_bytes_per_frame_);
108108 }
109109
110+ // run loopback record-encode-decode-playback loop
110111 size_t bytes_read, bytes_written;
111112 LOG_INFO (" Audio task started" );
112113 while (true ) {
0 commit comments