add flac support and files management app
This commit is contained in:
1 parent
4126ea13a1
commit
45f7b83e7c
12 files changed
+1526
-139
No files matched your search
@@ -47,15 +47,15 @@ esp_err_t myi2s_init(void)
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE, /* I2S主时钟MCLK相对于采样率的倍数(默认256) */
|
||||
},
|
||||
|
||||
.slot_cfg = { /* 声道配置,可用I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)宏函数辅助配置(支持16位宽采样数据) */
|
||||
.slot_cfg = { /* 声道配置,保持 Philips I2S 标准相位,避免采样位移造成噪声 */
|
||||
.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT, /* 声道支持16位宽的采样数据 */
|
||||
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, /* 通道位宽 */
|
||||
.slot_mode = I2S_SLOT_MODE_STEREO, /* 立体声 */
|
||||
.slot_mask = I2S_STD_SLOT_BOTH, /* 启用通道 */
|
||||
.ws_width = I2S_DATA_BIT_WIDTH_16BIT, /* WS信号位宽 */
|
||||
.ws_pol = false, /* WS信号极性 */
|
||||
.bit_shift = true, /* 位移位(Philips模式下配置) */
|
||||
.left_align = true, /* 左对齐 */
|
||||
.bit_shift = true, /* Philips 模式下需要位移位 */
|
||||
.left_align = false, /* 保持 Philips I2S 标准对齐,避免噪声 */
|
||||
.big_endian = false, /* 小端模式 */
|
||||
.bit_order_lsb = false /* MSB */
|
||||
},
|
||||
@@ -106,16 +106,30 @@ void i2s_trx_start(void)
|
||||
* @brief I2S TRX停止
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @note 可重复调用(通道已关闭时直接返回),保证后续 reconfig 一定处于 READY 状态
|
||||
*/
|
||||
void i2s_trx_stop(void)
|
||||
{
|
||||
if (!s_trx_enabled)
|
||||
if (tx_handle != NULL)
|
||||
{
|
||||
return;
|
||||
esp_err_t err = i2s_channel_disable(tx_handle);
|
||||
|
||||
if ((err != ESP_OK) && (err != ESP_ERR_INVALID_STATE))
|
||||
{
|
||||
ESP_ERROR_CHECK(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (rx_handle != NULL)
|
||||
{
|
||||
esp_err_t err = i2s_channel_disable(rx_handle);
|
||||
|
||||
if ((err != ESP_OK) && (err != ESP_ERR_INVALID_STATE))
|
||||
{
|
||||
ESP_ERROR_CHECK(err);
|
||||
}
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(i2s_channel_disable(tx_handle));
|
||||
ESP_ERROR_CHECK(i2s_channel_disable(rx_handle));
|
||||
s_trx_enabled = false;
|
||||
}
|
||||
|
||||
@@ -162,7 +176,7 @@ void i2s_set_samplerate_bits_sample(int samplerate, int bits_sample)
|
||||
{
|
||||
case 24:
|
||||
data_width = I2S_DATA_BIT_WIDTH_24BIT;
|
||||
mclk_multiple = I2S_MCLK_MULTIPLE_384; /* 必须是 3 的倍数 */
|
||||
mclk_multiple = I2S_MCLK_MULTIPLE_384; /* 24bit slot 必须是 3 的倍数 */
|
||||
break;
|
||||
|
||||
case 32:
|
||||
@@ -177,21 +191,18 @@ void i2s_set_samplerate_bits_sample(int samplerate, int bits_sample)
|
||||
break;
|
||||
}
|
||||
|
||||
i2s_trx_stop();
|
||||
i2s_trx_stop(); /* 必须在 READY 状态才能重配 */
|
||||
|
||||
/*
|
||||
* 重配 slot 时驱动内部会用当前 mclk_multiple 重算时钟,
|
||||
* 因此 MCLK 倍数必须在改 slot 之前就设好。
|
||||
*/
|
||||
my_std_cfg.clk_cfg.mclk_multiple = mclk_multiple;
|
||||
my_std_cfg.slot_cfg.data_bit_width = data_width; /* 数据位宽 */
|
||||
/* 先更新我们自己的配置副本 */
|
||||
my_std_cfg.slot_cfg.data_bit_width = data_width; /* 数据位宽 */
|
||||
my_std_cfg.slot_cfg.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO; /* 跟随数据位宽 */
|
||||
my_std_cfg.slot_cfg.ws_width = data_width; /* WS 位宽,与数据位宽一致(50% 占空比) */
|
||||
|
||||
/* 如果需要更新声道或时钟配置,需要在更新前先禁用通道 */
|
||||
ESP_ERROR_CHECK(i2s_channel_reconfig_std_slot(tx_handle, &my_std_cfg.slot_cfg));
|
||||
my_std_cfg.clk_cfg.sample_rate_hz = samplerate; /* 设置采样率 */
|
||||
my_std_cfg.slot_cfg.ws_width = data_width; /* WS 宽度与位宽一致(50% 占空比) */
|
||||
my_std_cfg.slot_cfg.left_align = false; /* Philips I2S 标准相位,左对齐会产生噪声 */
|
||||
my_std_cfg.clk_cfg.sample_rate_hz = (uint32_t)samplerate;
|
||||
my_std_cfg.clk_cfg.mclk_multiple = mclk_multiple;
|
||||
ESP_ERROR_CHECK(i2s_channel_reconfig_std_clock(tx_handle, &my_std_cfg.clk_cfg));
|
||||
|
||||
ESP_ERROR_CHECK(i2s_channel_reconfig_std_slot(tx_handle, &my_std_cfg.slot_cfg));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user