8000 stm32,esp32: In machine_i2s, send null samples in underflow situations. · salewski/micropython@0be3b91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0be3b91

Browse files
miketeachmandpgeorge
authored andcommitted
stm32,esp32: In machine_i2s, send null samples in underflow situations.
Eliminate noise data from being sent to the I2S peripheral when the transmitted sample stream is stopped. Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
1 parent 6d9da27 commit 0be3b91

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

ports/esp32/machine_i2s.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ STATIC void machin B29D e_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args,
448448
i2s_config.dma_buf_count = get_dma_buf_count(mode, bits, format, self->ibuf);
449449
i2s_config.dma_buf_len = DMA_BUF_LEN_IN_I2S_FRAMES;
450450
i2s_config.use_apll = false;
451+
i2s_config.tx_desc_auto_clear = true;
451452

452453
// I2S queue size equals the number of DMA buffers
453454
check_esp_err(i2s_driver_install(self->port, &i2s_config, i2s_config.dma_buf_count, &self->i2s_event_queue));

ports/stm32/machine_i2s.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) {
509509
if (self->bits == 32) {
510510
reformat_32_bit_samples((int32_t *)dma_buffer_p, SIZEOF_HALF_DMA_BUFFER_IN_BYTES / (sizeof(uint32_t)));
511511
}
512+
} else {
513+
// underflow. clear buffer to transmit "silence" on the I2S bus
514+
memset(dma_buffer_p, 0, SIZEOF_HALF_DMA_BUFFER_IN_BYTES);
512515
}
513516

514517
// flush cache to RAM so DMA can read the sample data

0 commit comments

Comments
 (0)
0