关于数字麦克风INMP441采集数据的问题
Posted: Thu Sep 17, 2020 2:27 am
使用I2S采集音频数据,目前数据可以成功采集,不过这并不是我最终希望得到的数据,根据datasheet得知INMP441有着-26dBFS的灵敏度,那么请问应当怎样将输出结果转换成声压值?
代码如下:
#define I2S_PORT I2S_NUM_0
#define I2S_SCK 14
#define I2S_WS 15
#define I2S_SD 32
const int BLOCK_SIZE = 128;
void i2s_install(){
//配置I2S
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 44100, //采样频率,默认44100Hz
.bits_per_sample = i2s_bits_per_sample_t(32),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};
i2s_driver_install(I2S_PORT,&i2s_config,0,NULL);
}
void i2s_setpin(){
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
i2s_set_pin(I2S_PORT, &pin_config);
}
void setup() {
Serial.begin(115200);
Serial.println("Configuring I2S...");
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
Serial.println("I2S driver installed.");
}
void loop() {
uint32_t sample = 0;
int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout
if (bytes_read > 0) {
Serial.println(sample);
}
}
代码如下:
#define I2S_PORT I2S_NUM_0
#define I2S_SCK 14
#define I2S_WS 15
#define I2S_SD 32
const int BLOCK_SIZE = 128;
void i2s_install(){
//配置I2S
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 44100, //采样频率,默认44100Hz
.bits_per_sample = i2s_bits_per_sample_t(32),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};
i2s_driver_install(I2S_PORT,&i2s_config,0,NULL);
}
void i2s_setpin(){
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
i2s_set_pin(I2S_PORT, &pin_config);
}
void setup() {
Serial.begin(115200);
Serial.println("Configuring I2S...");
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
Serial.println("I2S driver installed.");
}
void loop() {
uint32_t sample = 0;
int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout
if (bytes_read > 0) {
Serial.println(sample);
}
}