8000 partial buffer mgmt fix · domdfcoding/circuitpython@fd71d92 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd71d92

Browse files
committed
partial buffer mgmt fix
1 parent f6d7b87 commit fd71d92

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

ports/atmel-samd/audio_dma.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,23 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
214214
if (output_signed != samples_signed) {
215215
output_spacing = 1;
216216
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) {
217+
}
218+
219+
dma->first_buffer = (uint8_t *)m_realloc(dma->first_buffer, max_buffer_length);
220+
if (dma->first_buffer == NULL) {
221+
return AUDIO_DMA_MEMORY_ERROR;
222+
}
223+
dma->first_buffer_free = true;
224+
if (!single_buffer) {
225+
dma->second_buffer = (uint8_t *)m_realloc(dma->second_buffer, max_buffer_length);
226+
if (dma->second_buffer == NULL) {
219227
return AUDIO_DMA_MEMORY_ERROR;
220228
}
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;
230229
}
231230

231+
dma->signed_to_unsigned = !output_signed && samples_signed;
232+
dma->unsigned_to_signed = output_signed && !samples_signed;
233+
232234
dma->event_channel = 0xff;
233235
if (!single_buffer) {
234236
dma->second_descriptor = (DmacDescriptor *)m_malloc(sizeof(DmacDescriptor), false);

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

Lines changed: 4 additions & 5 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

@@ -380,7 +379,7 @@ void common_hal_audiobusio_i2sout_stop(audiobusio_i2sout_obj_t *self) {
380379
}
381380
#endif
382381
disconnect_gclk_from_peripheral(self->gclk, I2S_GCLK_ID_0 + self->clock_unit);
383-
disable_clock_generator(self->gclk);
382+
disable_gclk(self->gclk);
384383

385384
#ifdef SAM_D5X_E5X
386385
connect_gclk_to_peripheral(5, I2S_GCLK_ID_0 + self->clock_unit);

ports/raspberrypi/audio_dma.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,21 @@ void audio_dma_load_next_block(audio_dma_t *dma) {
135135
audio_dma_stop(dma);
136136
return;
137137
}
138+
bool busy0 = dma_channel_is_busy(dma->channel[0]);
139+
bool busy1 = dma_channel_is_busy(dma->channel[1]);
140+
if (busy0 == busy1) {
141+
mp_printf(&mp_plat_print, "busy: %d %d\n", busy0, busy1);
142+
}
138143

144+
if (buffer_length < 256) {
145+
mp_printf(&mp_plat_print, "%d length: %d\n", dma->first_channel_free, buffer_length);
146+
}
139147
audio_dma_convert_signed(dma, buffer, buffer_length, &output_buffer, &output_buffer_length);
140148

141149
// If we don't have an output buffer, save the pointer to first_buffer for use in the single
142150
// buffer special case.
143151
if (dma->first_buffer == NULL) {
152+
mp_printf(&mp_plat_print,"no first buffer\n");
144153
dma->first_buffer = output_buffer;
145154
}
146155

@@ -210,22 +219,24 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
210219
dma->sample_spacing > 1 ||
211220
(dma->sample_resolution != dma->output_resolution)) {
212221
max_buffer_length /= dma->sample_spacing;
213-
dma->first_buffer = (uint8_t *)m_realloc(dma->first_buffer, max_buffer_length);
214-
if (dma->first_buffer == NULL) {
215-
return AUDIO_DMA_MEMORY_ERROR;
216-
}
222+
}
217223

218-
dma->first_buffer_free = true;
219-
if (!single_buffer) {
220-
dma->second_buffer = (uint8_t *)m_realloc(dma->second_buffer, max_buffer_length);
221-
if (dma->second_buffer == NULL) {
222-
return AUDIO_DMA_MEMORY_ERROR;
223-
}
224+
dma->first_buffer = (uint8_t *)m_realloc(dma->first_buffer, max_buffer_length);
225+
if (dma->first_buffer == NULL) {
226+
return AUDIO_DMA_MEMORY_ERROR;
227+
}
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) {
233+
return AUDIO_DMA_MEMORY_ERROR;
224234
}
225-
dma->signed_to_unsigned = !output_signed && samples_signed;
226-
dma->unsigned_to_signed = output_signed && !samples_signed;
227235
}
228236

237+
dma->signed_to_unsigned = !output_signed && samples_signed;
238+
dma->unsigned_to_signed = output_signed && !samples_signed;
239+
229240
if (output_resolution > 8) {
230241
dma->output_size = 2;
231242
} else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
117117
}
118118

119119
// Use the state machine to manage pins.
120-
common_hal_rp2pio_statemachine_construct(&self->state_machine,
120+
common_hal_rp2pio_statemachine_construct(
121+
&self->state_machine,
121122
program, program_len,
122123
44100 * 32 * 6, // Clock at 44.1 khz to warm the DAC up.
123124
NULL, 0,

0 commit comments

Comments
 (0)
0