Skip to content

Commit c8f969f

Browse files
committed
samd: audio-dma: avoid memory allocations
With the previous change, stereo mp3 playback changed from needing 4 2304-byte allocations to needing 2 4604-byte allocations. This was enough to cause MemoryErrors with regularity. By using m_realloc() here, the existing memory region can be used. m_realloc() also works on the first invocation, because m_realloc(NULL, sz) just calls m_malloc of sz.
1 parent cb6193b commit c8f969f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/atmel-samd/audio_dma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
203203
if (output_signed != samples_signed) {
204204
output_spacing = 1;
205205
max_buffer_length /= dma->spacing;
206-
dma->first_buffer = (uint8_t*) m_malloc(max_buffer_length, false);
206+
dma->first_buffer = (uint8_t*) m_realloc(dma->first_buffer, max_buffer_length);
207207
if (dma->first_buffer == NULL) {
208208
return AUDIO_DMA_MEMORY_ERROR;
209209
}
210210
dma->first_buffer_free = true;
211211
if (!single_buffer) {
212-
dma->second_buffer = (uint8_t*) m_malloc(max_buffer_length, false);
212+
dma->second_buffer = (uint8_t*) m_realloc(dma->second_buffer, max_buffer_length);
213213
if (dma->second_buffer == NULL) {
214214
return AUDIO_DMA_MEMORY_ERROR;
215215
}

0 commit comments

Comments
 (0)