diff options
| author | jepler <jepler@gmail.com> | 2019-09-09 20:12:35 -0500 |
|---|---|---|
| committer | jepler <jepler@gmail.com> | 2019-09-09 20:13:12 -0500 |
| commit | 7b9dfc9952cf4af12de14fa21831a9324b7bc025 (patch) | |
| tree | 8cadd48b129e4ac829a368ed59b2e912edeaaed8 | |
| parent | c66f5a853644c0bc2bade243b1e7a9e9a69c1b4b (diff) | |
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.
| -rw-r--r-- | ports/nrf/common-hal/audiobusio/I2SOut.c | 14 |
1 files 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); |
