Skip to content

Commit d3afda6

Browse files
committed
esp32s2: i2s: must reset buffer, otherwise wave samples don't start
.. and other housekeeping when starting to play a sample
1 parent 3522264 commit d3afda6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ports/esp32s2/i2s_common.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) {
186186
}
187187

188188
self->sample = sample;
189+
self->loop = loop;
189190
self->bytes_per_sample = audiosample_bits_per_sample(sample) / 8;
190191
self->channel_count = audiosample_channel_count(sample);
191192
bool single_buffer;
@@ -195,12 +196,15 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) {
195196
audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed,
196197
&max_buffer_length, &spacing);
197198
self->samples_signed = samples_signed;
198-
self->loop = loop;
199199
self->playing = true;
200200
self->paused = false;
201201
self->stopping = false;
202+
self->sample_data = self->sample_end = NULL;
202203
// We always output stereo so output twice as many bits.
203204
// uint16_t bits_per_sample_output = bits_per_sample * 2;
205+
206+
audiosample_reset_buffer(self->sample, false, 0);
207+
204208
ESP_CALL_RAISE(i2s_set_sample_rates(self->instance, audiosample_sample_rate(sample)));
205209
i2s_fill_buffer(self);
206210
}

0 commit comments

Comments
 (0)