Skip to content

Commit fe9605a

Browse files
committed
nrf: i2s: Comment this slightly tricksy code
1 parent 8242761 commit fe9605a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,17 @@ stopping: ;
167167
self->sample_data += bytecount;
168168
bytesleft -= bytecount;
169169
}
170+
171+
// Find the last frame of real audio data and replicate its samples until
172+
// you have 32 bits worth, which is the fundamental unit of nRF I2S DMA
170173
if (self->bytes_per_sample == 1 && self->channel_count == 1) {
171-
self->hold_value = 0x01010101 * *(uint8_t*)(buffer-1);
174+
// For 8-bit mono, 4 copies of the final sample are required
175+
self->hold_value = 0x01010101 * *(uint8_t*)(buffer-1);
172176
} else if (self->bytes_per_sample == 2 && self->channel_count == 2) {
177+
// For 16-bit stereo, 1 copy of the final sample is required
173178
self->hold_value = *(uint32_t*)(buffer-4);
174179
} else {
180+
// For 8-bit stereo and 16-bit mono, 2 copies of the final sample are required
175181
self->hold_value = 0x00010001 * *(uint16_t*)(buffer-2);
176182
}
177183
}

0 commit comments

Comments
 (0)