From 7b9dfc9952cf4af12de14fa21831a9324b7bc025 Mon Sep 17 00:00:00 2001 From: jepler Date: Mon, 9 Sep 2019 20:12:35 -0500 Subject: nrf: i2s: tune audio buffering .. based on some tasks I found that caused stuttering: # Test SD and printing while True: os.listdir('.') # Test bulk I/O while True: len(open('somefile.wav', 'rb').read()) Each of these tasks *WAS* worse and I am improving them in a separate PR by adding RUN_BACKGROUND_TASKS to them. --- ports/nrf/common-hal/audiobusio/I2SOut.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ports/nrf/common-hal/audiobusio/I2SOut.c b/ports/nrf/common-hal/audiobusio/I2SOut.c index e167e964f..ac369277f 100644 --- a/ports/nrf/common-hal/audiobusio/I2SOut.c +++ b/ports/nrf/common-hal/audiobusio/I2SOut.c @@ -247,12 +247,14 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self, self->samples_signed = samples_signed; choose_i2s_clocking(self, sample_rate); - /* Allocate buffers based on a maximum duration */ - enum { buffer_length_ms = 8 }; - self->buffer_length = MAX( - 2*max_buffer_length, - sample_rate * buffer_length_ms * self->bytes_per_sample - * self->channel_count / 1000); + /* Allocate buffers based on a maximum duration + * This duration was chosen empirically based on what would + * cause os.listdir('') to cause stuttering. It seems like a + * rather long time. + */ + enum { buffer_length_ms = 16 }; + self->buffer_length = sample_rate * buffer_length_ms + * self->bytes_per_sample * self->channel_count / 1000; self->buffer_length = (self->buffer_length + 3) & ~3; self->buffers[0] = m_malloc(self->buffer_length, false); self->buffers[1] = m_malloc(self->buffer_length, false); -- cgit v1.2.3