1313#define I2S0_TAG "i2s-0"
1414#define I2S1_TAG "i2s-1"
1515
16- static int i2s_output_sample_rate = 44100 ;
17- static int i2s_output_bits_per_sample = 16 ;
18-
19- static int i2s_input_sample_rate = 44100 ;
20- static int i2s_input_bits_per_sample = 16 ;
21-
2216static i2s_config_t i2s_output_config = {
2317 .mode = I2S_MODE_MASTER | I2S_MODE_TX
2418#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == CONFIG_AUDIO_INPUT_I2S_NUM )
@@ -28,14 +22,15 @@ static i2s_config_t i2s_output_config = {
2822 .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB ,
2923 .use_apll = 1 , // Use APLL
3024 .sample_rate = 44100 ,
31- .bits_per_sample = 16 ,
25+ .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT ,
3226 .intr_alloc_flags = ESP_INTR_FLAG_LEVEL3 ,
3327 .tx_desc_auto_clear = true, // Auto clear tx descriptor on underflow
3428 .dma_buf_count = 8 ,
3529 .dma_buf_len = 128 ,
3630 .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT , // 2-channels
3731};
3832
33+ #if !defined(CONFIG_AUDIO_INPUT_NONE ) && (CONFIG_AUDIO_OUTPUT_I2S_NUM != CONFIG_AUDIO_INPUT_I2S_NUM )
3934static i2s_config_t i2s_input_config = {
4035 .mode = I2S_MODE_MASTER | I2S_MODE_RX
4136#ifdef CONFIG_AUDIO_INPUT_PDM
@@ -45,17 +40,12 @@ static i2s_config_t i2s_input_config = {
4540 .communication_format = I2S_COMM_FORMAT_I2S_MSB | I2S_COMM_FORMAT_I2S ,
4641 .use_apll = 0 , // Use PLL_D2
4742 .sample_rate = 44100 ,
48- .bits_per_sample = 16 ,
43+ .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT ,
4944 .dma_buf_count = 2 ,
5045 .dma_buf_len = 128 ,
51- #ifdef CONFIG_AUDIO_INPUT_ONLY_LEFT
52- .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT , // left channel only
53- #elif defined(CONFIG_AUDIO_INPUT_ONLY_RIGHT )
54- .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT , // right channel only
55- #else
5646 .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT , // 2-channels
57- #endif
5847};
48+ #endif
5949
6050#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == 0 ) || (CONFIG_AUDIO_INPUT_I2S_NUM == 0 )
6151void i2s0_init (void )
@@ -164,40 +154,10 @@ void i2s_output_deinit(void)
164154#endif
165155}
166156
167- void i2s_set_output_sample_rate (int rate )
157+ void i2s_output_set_sample_rate (int rate )
168158{
169- if (rate != i2s_output_sample_rate ) {
170- i2s_set_sample_rates ( CONFIG_AUDIO_OUTPUT_I2S_NUM , rate ) ;
171- i2s_output_sample_rate = rate ;
159+ if (rate != i2s_output_config . sample_rate ) {
160+ i2s_output_config . sample_rate = rate ;
161+ i2s_set_sample_rates ( CONFIG_AUDIO_OUTPUT_I2S_NUM , i2s_output_config . sample_rate ) ;
172162 }
173163}
174-
175- void i2s_set_input_sample_rate (int rate )
176- {
177- #if !defined(CONFIG_AUDIO_INPUT_NONE ) && (CONFIG_AUDIO_OUTPUT_I2S_NUM != CONFIG_AUDIO_INPUT_I2S_NUM )
178- if (rate != i2s_input_sample_rate ) {
179- i2s_set_sample_rates (CONFIG_AUDIO_INPUT_I2S_NUM , rate );
180- i2s_input_sample_rate = rate ;
181- }
182- #endif
183- }
184-
185- int i2s_get_output_sample_rate (void )
186- {
187- return i2s_output_sample_rate ;
188- }
189-
190- int i2s_get_input_sample_rate (void )
191- {
192- return i2s_input_sample_rate ;
193- }
194-
195- int i2s_get_output_bits_per_sample (void )
196- {
197- return i2s_output_bits_per_sample ;
198- }
199-
200- int i2s_get_input_bits_per_sample (void )
201- {
202- return i2s_input_bits_per_sample ;
203- }
0 commit comments