Skip to content

Commit 2c8993f

Browse files
committed
audio_render: fix audio channel swap problem
1 parent 7676ffc commit 2c8993f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

main/src/user/audio_render.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ esp_err_t i2s_write_wrapper(i2s_port_t i2s_num, const void *src, size_t size, si
2323
uint32_t idx = 0;
2424
const uint8_t *data = (const uint8_t *)src;
2525
while (size > 0) {
26-
int16_t data_l = data[idx+1] << 8 | data[idx];
27-
int16_t data_r = data[idx+3] << 8 | data[idx+2];
26+
int16_t data_l = data[idx+3] << 8 | data[idx+2];
27+
int16_t data_r = data[idx+1] << 8 | data[idx];
2828
fifo_write((data_l + data_r) / 2);
2929
idx += 4;
3030
size -= 4;
@@ -50,15 +50,15 @@ void render_sample_block(short *sample_buff_ch0, short *sample_buff_ch1, int num
5050
TickType_t max_wait = 20 / portTICK_PERIOD_MS; // portMAX_DELAY = bad idea
5151
for (int i = 0; i < num_samples; i++) {
5252
/* low - high / low - high */
53-
const char samp32[4] = {ptr_l[0], ptr_l[1], ptr_r[0], ptr_r[1]};
53+
const char samp32[4] = {ptr_r[0], ptr_r[1], ptr_l[0], ptr_l[1]}; // ESP32 CPU is Little Endian
5454
i2s_write_wrapper(0, (const char *)&samp32, sizeof(samp32), &bytes_written, max_wait);
5555

5656
// DMA buffer full - retry
5757
if (bytes_written == 0) {
5858
i--;
5959
} else {
60-
ptr_r += stride;
6160
ptr_l += stride;
61+
ptr_r += stride;
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)