Skip to content

Commit ebf0901

Browse files
authored
Merge pull request #5079 from dhalbert/debug-audio
Fix various RP2040 and SAMD audio issues
2 parents 1e53cf4 + 4608877 commit ebf0901

File tree

13 files changed

+228
-139
lines changed

13 files changed

+228
-139
lines changed

locale/circuitpython.pot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ msgstr ""
493493
msgid "Attempted heap allocation when VM not running."
494494
msgstr ""
495495

496+
#: ports/raspberrypi/audio_dma.c
497+
msgid "Audio conversion not implemented"
498+
msgstr ""
499+
496500
#: shared-bindings/wifi/Radio.c
497501
msgid "AuthMode.OPEN is not used with password"
498502
msgstr ""
@@ -1217,6 +1221,10 @@ msgstr ""
12171221
msgid "Insufficient encryption"
12181222
msgstr ""
12191223

1224+
#: ports/raspberrypi/audio_dma.c
1225+
msgid "Internal audio buffer too small"
1226+
msgstr ""
1227+
12201228
#: ports/stm/common-hal/busio/UART.c
12211229
msgid "Internal define error"
12221230
msgstr ""

ports/atmel-samd/audio_dma.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,13 @@ void audio_dma_load_next_block(audio_dma_t *dma) {
157157
if (dma->loop) {
158158
audiosample_reset_buffer(dma->sample, dma->single_channel_output, dma->audio_channel);
159159
} else {
160-
descriptor->DESCADDR.reg = 0;
160+
if ((output_buffer_length == 0) && dma_transfer_status(SHARED_RX_CHANNEL) & 0x3) {
161+
// Nothing further to read and previous buffer is finished.
162+
audio_dma_stop(dma);
163+
} else {
164+
// Break descriptor chain.
165+
descriptor->DESCADDR.reg = 0;
166+
}
161167
}
162168
}
163169
descriptor->BTCTRL.bit.VALID = true;
@@ -214,21 +220,23 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
214220
if (output_signed != samples_signed) {
215221
output_spacing = 1;
216222
max_buffer_length /= dma->spacing;
217-
dma->first_buffer = (uint8_t *)m_realloc(dma->first_buffer, max_buffer_length);
218-
if (dma->first_buffer == NULL) {
223+
}
224+
225+
dma->first_buffer = (uint8_t *)m_realloc(dma->first_buffer, max_buffer_length);
226+
if (dma->first_buffer == NULL) {
227+
return AUDIO_DMA_MEMORY_ERROR;
228+
}
229+
dma->first_buffer_free = true;
230+
if (!single_buffer) {
231+
dma->second_buffer = (uint8_t *)m_realloc(dma->second_buffer, max_buffer_length);
232+
if (dma->second_buffer == NULL) {
219233
return AUDIO_DMA_MEMORY_ERROR;
220234
}
221-
dma->first_buffer_free = true;
222-
if (!single_buffer) {
223-
dma->second_buffer = (uint8_t *)m_realloc(dma->second_buffer, max_buffer_length);
224-
if (dma->second_buffer == NULL) {
225-
return AUDIO_DMA_MEMORY_ERROR;
226-
}
227-
}
228-
dma->signed_to_unsigned = !output_signed && samples_signed;
229-
dma->unsigned_to_signed = output_signed && !samples_signed;
230235
}
231236

237+
dma->signed_to_unsigned = !output_signed && samples_signed;
238+
dma->unsigned_to_signed = output_signed && !samples_signed;
239+
232240
dma->event_channel = 0xff;
233241
if (!single_buffer) {
234242
dma->second_descriptor = (DmacDescriptor *)m_malloc(sizeof(DmacDescriptor), false);

ports/atmel-samd/common-hal/audiobusio/I2SOut.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
void i2sout_reset(void) {
7272
// Make sure the I2S peripheral is running so we can see if the resources we need are free.
7373
#ifdef SAM_D5X_E5X
74-
// Connect the clock units to the 2mhz clock. It can't disable without it.
74+
// Connect the clock units to the 2MHz clock. It can't disable without it.
7575
connect_gclk_to_peripheral(5, I2S_GCLK_ID_0);
7676
connect_gclk_to_peripheral(5, I2S_GCLK_ID_1);
7777
#endif
@@ -83,7 +83,7 @@ void i2sout_reset(void) {
8383

8484
// Make sure the I2S peripheral is running so we can see if the resources we need are free.
8585
#ifdef SAM_D5X_E5X
86-
// Connect the clock units to the 2mhz clock by default. They can't reset without it.
86+
// Connect the clock units to the 2MHz clock by default. They can't reset without it.
8787
disconnect_gclk_from_peripheral(5, I2S_GCLK_ID_0);
8888
disconnect_gclk_from_peripheral(5, I2S_GCLK_ID_1);
8989

@@ -222,7 +222,6 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t *self) {
222222
reset_pin_number(self->word_select->number);
223223
self->word_select = NULL;
224224
reset_pin_number(self->data->number);
225-
self->data = NULL;
226225
}
227226

228227
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
@@ -288,7 +287,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
288287
I2S->TXCTRL.reg = serctrl;
289288
#endif
290289

291-
// The DFLL is always a 48mhz clock
290+
// The DFLL is always a 48MHz clock
292291
enable_clock_generator(self->gclk, CLOCK_48MHZ, divisor);
293292
connect_gclk_to_peripheral(self->gclk, I2S_GCLK_ID_0 + self->clock_unit);
294293

0 commit comments

Comments
 (0)