Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_i2s_mono_mode' into 'master'
Browse files Browse the repository at this point in the history
i2s_stream: fix abnormal recording when setting i2s to single channel

See merge request adf/esp-adf-internal!1336
  • Loading branch information
jason-mao committed Sep 12, 2024
2 parents ce64fea + ce7b0cc commit 35c629e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
48 changes: 46 additions & 2 deletions components/audio_stream/include/i2s_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,55 @@ typedef struct {

#define I2S_STREAM_CFG_DEFAULT() I2S_STREAM_CFG_DEFAULT_WITH_PARA(I2S_NUM_0, 44100, I2S_DATA_BIT_WIDTH_16BIT, AUDIO_STREAM_WRITER)

#define I2S_STREAM_CFG_DEFAULT_WITH_PARA(port, rate, bits, stream_type) { \
#define I2S_STREAM_CFG_DEFAULT_WITH_PARA(port, rate, bits, stream_type) I2S_STREAM_CFG_DEFAULT_WITH_TYLE_AND_CH(port, rate, bits, stream_type, I2S_SLOT_MODE_STEREO)

#if CONFIG_IDF_TARGET_ESP32
#define I2S_STD_PHILIPS_SLOT_DEFAULT_ADF_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
I2S_STD_SLOT_LEFT : I2S_STD_SLOT_BOTH, \
.ws_width = bits_per_sample, \
.ws_pol = false, \
.bit_shift = true, \
.msb_right = (bits_per_sample <= I2S_DATA_BIT_WIDTH_16BIT) ? \
true : false, \
}
#elif CONFIG_IDF_TARGET_ESP32S2
#define I2S_STD_PHILIPS_SLOT_DEFAULT_ADF_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
I2S_STD_SLOT_LEFT : I2S_STD_SLOT_BOTH, \
.ws_width = bits_per_sample, \
.ws_pol = false, \
.bit_shift = true, \
.msb_right = true, \
}
#else
#define I2S_STD_PHILIPS_SLOT_DEFAULT_ADF_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
I2S_STD_SLOT_LEFT : I2S_STD_SLOT_BOTH, \
.ws_width = bits_per_sample, \
.ws_pol = false, \
.bit_shift = true, \
.left_align = true, \
.big_endian = false, \
.bit_order_lsb = false \
}
#endif


#define I2S_STREAM_CFG_DEFAULT_WITH_TYLE_AND_CH(port, rate, bits, stream_type, channel) { \
.type = stream_type, \
.std_cfg = { \
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(rate), \
.slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(bits, I2S_SLOT_MODE_STEREO), \
.slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_ADF_CONFIG(bits, channel), \
.gpio_cfg = { \
.invert_flags = { \
.mclk_inv = false, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ int av_stream_audio_write(char *buf, int len, TickType_t wait_time, bool uac_en)
int ret = audio_element_output(i2s_io_writer, buf, len);
if (ret < 0) {
ESP_LOGE(TAG, "i2s write failed");
} else {
bytes_writen = ret;
}
}
return bytes_writen;
Expand Down
2 changes: 1 addition & 1 deletion examples/recorder/pipeline_raw_http/main/record_raw_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void app_main(void)
http_stream_writer = http_stream_init(&http_cfg);

ESP_LOGI(TAG, "[3.2] Create i2s stream to read audio data from codec chip");
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT_WITH_PARA(CODEC_ADC_I2S_PORT, 44100, 16, AUDIO_STREAM_READER);
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT_WITH_TYLE_AND_CH(CODEC_ADC_I2S_PORT, 44100, 16, AUDIO_STREAM_READER, 1);
i2s_cfg.type = AUDIO_STREAM_READER;
i2s_cfg.out_rb_size = 16 * 1024; // Increase buffer to avoid missing data in bad network conditions
i2s_stream_reader = i2s_stream_init(&i2s_cfg);
Expand Down

0 comments on commit 35c629e

Please sign in to comment.