I'm using IDF 5.1.2, compiling for an esp32-s3. My code reads a few bytes from an mp3 file in order to determine the file sample rate, and then I'd like to configure my I2S channel accordingly:
Code: Select all
i2s_config.clk_cfg.sample_rate_hz = mp3_info.hz;
i2s_channel_reconfig_std_clock(tx_handle, &i2s_config.clk_cfg);
though, oddly, I still hear sound. But I'd like to understand what I'm apparently doing wrong.E (2614) i2s_std: i2s_channel_reconfig_std_clock(264): this handle is not working in standard mode
More thoroughly, my code looks like the following, which I cribbed mostly from the code on this page:
https://docs.espressif.com/projects/esp ... td-tx-mode
Code: Select all
// ------------------------------
// Set up I2S
i2s_chan_handle_t tx_handle;
// i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM, I2S_ROLE_MASTER);
i2s_chan_config_t chan_cfg = {
.id = I2S_NUM_0, // I2S port number
.role = I2S_ROLE_MASTER, // Master role
.dma_desc_num = 4, // Number of DMA descriptors
.dma_frame_num = 1023, // Number of frames per DMA descriptor
.auto_clear = true, // Auto clear on underflow
};
// Allocate a new TX channel and get the handle of this channel
i2s_new_channel(&chan_cfg, &tx_handle, NULL);
// Setting the configurations.
// The slot configuration and clock configuration can be generated by the macros.
// These two helper macros are defined in 'i2s_std.h' which can only be used in STD mode.
// They can help to specify the slot and clock configurations for initialization or updating
i2s_std_config_t i2s_config = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED,
.bclk = I2S_BCLK,
.ws = I2S_WS,
.dout = I2S_DO,
.din = I2S_GPIO_UNUSED,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false,
},
},
};
// ... determine sample rate from file...
// Now that we've determined the sample rate of our file,
// we can "reconfigure" our i2s channel accurately.
i2s_config.clk_cfg.sample_rate_hz = mp3_info.hz;
i2s_channel_reconfig_std_clock(tx_handle, &i2s_config.clk_cfg);
// Initialize the channel
i2s_channel_init_std_mode(tx_handle, &i2s_config);
// Enable the channel
i2s_channel_enable(tx_handle);