summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjepler <jepler@gmail.com>2019-09-09 19:25:52 -0500
committerjepler <jepler@gmail.com>2019-09-09 19:25:52 -0500
commitfe9605a6a39e92f368658fb731f38ce0830ebe68 (patch)
treeeb1971bdb493f1ffa42f841e9f934cd712094ec6
parent82427612d15ac85d0a34132ace7f8369dacd66ef (diff)
nrf: i2s: Comment this slightly tricksy code
-rw-r--r--ports/nrf/common-hal/audiobusio/I2SOut.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ports/nrf/common-hal/audiobusio/I2SOut.c b/ports/nrf/common-hal/audiobusio/I2SOut.c
index 25ae48f59..e18ed9269 100644
--- a/ports/nrf/common-hal/audiobusio/I2SOut.c
+++ b/ports/nrf/common-hal/audiobusio/I2SOut.c
@@ -167,11 +167,17 @@ stopping: ;
self->sample_data += bytecount;
bytesleft -= bytecount;
}
+
+ // Find the last frame of real audio data and replicate its samples until
+ // you have 32 bits worth, which is the fundamental unit of nRF I2S DMA
if (self->bytes_per_sample == 1 && self->channel_count == 1) {
- self->hold_value = 0x01010101 * *(uint8_t*)(buffer-1);
+ // For 8-bit mono, 4 copies of the final sample are required
+ self->hold_value = 0x01010101 * *(uint8_t*)(buffer-1);
} else if (self->bytes_per_sample == 2 && self->channel_count == 2) {
+ // For 16-bit stereo, 1 copy of the final sample is required
self->hold_value = *(uint32_t*)(buffer-4);
} else {
+ // For 8-bit stereo and 16-bit mono, 2 copies of the final sample are required
self->hold_value = 0x00010001 * *(uint16_t*)(buffer-2);
}
}