I2S Data Swapped Using 16-bit Data and ONLY_LEFT (mono)

Shade42
Posts: 2
Joined: Tue Mar 21, 2017 3:36 am

I2S Data Swapped Using 16-bit Data and ONLY_LEFT (mono)

Postby Shade42 » Sat Jun 15, 2019 4:17 pm

I want to just receive a single channel of audio from the I2S interface.
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;
	}
}


ESP_Sprite
Posts: 8999
Joined: Thu Nov 26, 2015 4:08 am

Re: I2S Data Swapped Using 16-bit Data and ONLY_LEFT (mono)

Postby ESP_Sprite » Mon Jun 17, 2019 12:53 am

Yes, this is expected. The current silicon does not have a way to swap the words.

Who is online

Users browsing this forum: Bing [Bot] and 102 guests