|
24 | 24 | * THE SOFTWARE.
|
25 | 25 | */
|
26 | 26 |
|
| 27 | +#include <string.h> |
| 28 | + |
27 | 29 | #include "py/runtime.h"
|
28 | 30 |
|
29 | 31 | #include "i2s_common.h"
|
@@ -69,8 +71,17 @@ static void i2s_fill_buffer(i2s_t *self) {
|
69 | 71 | if (self->instance < 0 || self->instance >= I2S_NUM_MAX) {
|
70 | 72 | return;
|
71 | 73 | }
|
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); |
74 | 85 | return;
|
75 | 86 | }
|
76 | 87 | while (!self->stopping) {
|
@@ -102,7 +113,6 @@ static void i2s_fill_buffer(i2s_t *self) {
|
102 | 113 | ESP_CALL_RAISE(i2s_write_expand(self->instance, self->sample_data, bytecount, 8, 16, &bytes_written, 0));
|
103 | 114 | }
|
104 | 115 | } else {
|
105 |
| -#define STACK_BUFFER_SIZE (64) |
106 | 116 | const size_t bytes_per_output_frame = 4;
|
107 | 117 | size_t bytes_per_input_frame = self->channel_count * self->bytes_per_sample;
|
108 | 118 | size_t framecount = MIN(STACK_BUFFER_SIZE / bytes_per_output_frame, bytecount / bytes_per_input_frame);
|
|
0 commit comments