When I set the channel_format to I2S_CHANNEL_FMT_ONLY_LEFT (see code below), the left channel is correctly isolated, however even and odd 16-bit words are swapped (I'm using 16-bit samples I2S_RX_FIFO_MOD=1).
Is this the expected behavior?
I currently need to swap the words to get the data in the correct order (see swap_16_bit_words below).
To clarify further, when I send a sine wave, this is the data I get out of i2s_read:
58
37
69
70
38
58
-13
12
-59
-39
However, this is what is should be:
37
58
70
69
58
38
12
-13
-39
-59
Is there any to configure the I2S RX FIFO to swap the words to avoid needing to swap them in the application?
Thanks!
Code: Select all
i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX,
.sample_rate = SampleRate_hz, //I2S_SAMPLE_RATE,
.bits_per_sample = bits_per_sample, //I2S_BITS_PER_SAMPLE, // bits per channel
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, //I2S_CHANNEL_FMT_ONLY_RIGHT, //I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
.dma_buf_count = 4 ,
.dma_buf_len = 256,
.use_apll = use_apll,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Interrupt level 1
.fixed_mclk = mclk_mhz // in new IDF, if use_apll is true and fixed_mclk>0, then clock is fixed and equal to this value.
};
void swap_16bit_words(short* pbuff,size_t words_read){
for(int i=1; i<words_read; i+=2){
short temp = pbuff[i];
pbuff[i] = pbuff[i-1];
pbuff[i-1] = temp;
}
}