Skip to content

Commit cfd8288

Browse files
committed
esp2s2: enlarge stack-buffer, use it instead of i2s_zero_dma_buffer
.. it's not clear that there was a problem with i2s_zero_dma_buffer, but just in case.
1 parent d3afda6 commit cfd8288

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ports/esp32s2/i2s_common.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <string.h>
28+
2729
#include "py/runtime.h"
2830

2931
#include "i2s_common.h"
@@ -69,8 +71,17 @@ static void i2s_fill_buffer(i2s_t *self) {
6971
if (self->instance < 0 || self->instance >= I2S_NUM_MAX) {
7072
return;
7173
}
72-
if (self->paused || !self->sample) {
73-
i2s_zero_dma_buffer(self->instance);
74+
#define STACK_BUFFER_SIZE (512)
75+
int16_t signed_samples[STACK_BUFFER_SIZE / sizeof(int16_t)];
76+
mp_printf(&mp_plat_print, "playing=%d paused=%d stopping=%d sample@%p sample_data=%p..%p\n", self->playing, self->paused, self->stopping, self->sample, self->sample_data, self->sample_end);
77+
78+
if (!self->playing || self->paused || !self->sample) {
79+
memset(signed_samples, 0, sizeof(signed_samples));
80+
81+
size_t bytes_written = 0;
82+
do {
83+
ESP_CALL_RAISE(i2s_write(self->instance, signed_samples, sizeof(signed_samples), &bytes_written, 0));
84+
} while (bytes_written != 0);
7485
return;
7586
}
7687
while (!self->stopping) {
@@ -102,7 +113,6 @@ static void i2s_fill_buffer(i2s_t *self) {
102113
ESP_CALL_RAISE(i2s_write_expand(self->instance, self->sample_data, bytecount, 8, 16, &bytes_written, 0));
103114
}
104115
} else {
105-
#define STACK_BUFFER_SIZE (64)
106116
const size_t bytes_per_output_frame = 4;
107117
size_t bytes_per_input_frame = self->channel_count * self->bytes_per_sample;
108118
size_t framecount = MIN(STACK_BUFFER_SIZE / bytes_per_output_frame, bytecount / bytes_per_input_frame);

0 commit comments

Comments
 (0)