Skip to content

Commit 7b9dfc9

Browse files
committed
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.
1 parent c66f5a8 commit 7b9dfc9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ports/nrf/common-hal/audiobusio/I2SOut.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,14 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
247247
self->samples_signed = samples_signed;
248248

249249
choose_i2s_clocking(self, sample_rate);
250-
/* Allocate buffers based on a maximum duration */
251-
enum { buffer_length_ms = 8 };
252-
self->buffer_length = MAX(
253-
2*max_buffer_length,
254-
sample_rate * buffer_length_ms * self->bytes_per_sample
255-
* self->channel_count / 1000);
250+
/* Allocate buffers based on a maximum duration
251+
* This duration was chosen empirically based on what would
252+
* cause os.listdir('') to cause stuttering. It seems like a
253+
* rather long time.
254+
*/
255+
enum { buffer_length_ms = 16 };
256+
self->buffer_length = sample_rate * buffer_length_ms
257+
* self->bytes_per_sample * self->channel_count / 1000;
256258
self->buffer_length = (self->buffer_length + 3) & ~3;
257259
self->buffers[0] = m_malloc(self->buffer_length, false);
258260
self->buffers[1] = m_malloc(self->buffer_length, false);

0 commit comments

Comments
 (0)