请问是我的硬件有什么问题吗?还是我用的代码有问题?
Code: Select all
i2s_config_t i2s_read_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX,
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM,
.dma_buf_count = 3,
.dma_buf_len = I2S_READLEN,
.use_apll = true,
.tx_desc_auto_clear = true,
.fixed_mclk = 0
};
i2s_pin_config_t i2s_read_pin_config = {
.bck_io_num = GPIO_NUM_5,
.ws_io_num = GPIO_NUM_25,
.data_out_num = GPIO_NUM_26,
.data_in_num = GPIO_NUM_35
};
i2s_driver_install(I2S_NUM, &i2s_read_config, 0, NULL);
i2s_set_pin(I2S_NUM, &i2s_read_pin_config);
/*******************/
printf("[filter-dsp] Initializing MCLK output...\r\n");
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
WRITE_PERI_REG(PIN_CTRL, 0xFFF0);
/*******************/
printf("[filter-dsp] Enabling Passthrough mode...\r\n");
size_t i2s_bytes_read = 0;
size_t i2s_bytes_written = 0;
int16_t i2s_buffer_read[I2S_READLEN / sizeof(int16_t)];
int16_t i2s_buffer_write[I2S_READLEN / sizeof(int16_t)];
while (true) {
i2s_bytes_read = I2S_READLEN;
i2s_read(I2S_NUM, i2s_buffer_read, I2S_READLEN, &i2s_bytes_read, 100);
/* left channel filter */
for (uint32_t i = 0; i < i2s_bytes_read / 2; i += 2)
{
// printf("left: %d\r\n", i2s_buffer_read[i]);
i2s_buffer_write[i] = processSample(i2s_buffer_read[i]);
// printf("left OUT: %d\r\n", i2s_buffer_write[i]);
}
/* right channel filter */
for (uint32_t i = 1; i < i2s_bytes_read / 2; i += 2)
i2s_buffer_write[i] = dummyfilter(i2s_buffer_read[i]) ;
esp_err_t err = i2s_write(I2S_NUM, i2s_buffer_write, i2s_bytes_read, &i2s_bytes_written, 100);
ESP_ERROR_CHECK_WITHOUT_ABORT(err);
}
我用的开发板是 ESP32 LYRAT 4.3,板载的DAC是8388。我要实现的功能其实非常简单, 模拟信号从LINE IN输入,我I2S_READ读取,处理数据后, I2S_WRITE输出。
上述代码运行没有任何报错,但是i2s_read返回的都是0。
没有人遇到跟我一样的问题吗?网上搜了很多资料,发现没人反馈这个问题。