Skip to content

Commit e5dd78d

Browse files
authored
Merge pull request #2324 from jepler/nrf-i2s-channels-widths
nrf: assign channel width and count correctly
2 parents 2653455 + 1ee35fd commit e5dd78d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,20 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
245245

246246
uint32_t max_buffer_length;
247247
bool single_buffer, samples_signed;
248-
audiosample_get_buffer_structure(sample, /* single channel */ false,
248+
audiosample_get_buffer_structure(sample, /* single channel */ true,
249249
&single_buffer, &samples_signed, &max_buffer_length,
250250
&self->channel_count);
251251
self->single_buffer = single_buffer;
252252
self->samples_signed = samples_signed;
253253

254+
255+
NRF_I2S->CONFIG.SWIDTH = self->bytes_per_sample == 1
256+
? I2S_CONFIG_SWIDTH_SWIDTH_8Bit
257+
: I2S_CONFIG_SWIDTH_SWIDTH_16Bit;
258+
NRF_I2S->CONFIG.CHANNELS = self->channel_count == 1
259+
? I2S_CONFIG_CHANNELS_CHANNELS_Left
260+
: I2S_CONFIG_CHANNELS_CHANNELS_Stereo;
261+
254262
choose_i2s_clocking(self, sample_rate);
255263
/* Allocate buffers based on a maximum duration
256264
* This duration was chosen empirically based on what would
@@ -274,9 +282,6 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
274282
self->stopping = false;
275283
i2s_buffer_fill(self);
276284

277-
NRF_I2S->CONFIG.CHANNELS = self->channel_count == 1 ? I2S_CONFIG_CHANNELS_CHANNELS_Left : I2S_CONFIG_CHANNELS_CHANNELS_Stereo;
278-
279-
280285
NRF_I2S->RXTXD.MAXCNT = self->buffer_length / 4;
281286
NRF_I2S->ENABLE = I2S_ENABLE_ENABLE_Enabled;
282287

0 commit comments

Comments
 (0)