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.
crypto-aes
Jeff Epler 3 years ago
parent cb6193bbc7
commit c8f969feb5
  1. 4
      ports/atmel-samd/audio_dma.c

@ -203,13 +203,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
if (output_signed != samples_signed) {
output_spacing = 1;
max_buffer_length /= dma->spacing;
dma->first_buffer = (uint8_t*) m_malloc(max_buffer_length, false);
dma->first_buffer = (uint8_t*) m_realloc(dma->first_buffer, max_buffer_length);
if (dma->first_buffer == NULL) {
return AUDIO_DMA_MEMORY_ERROR;
}
dma->first_buffer_free = true;
if (!single_buffer) {
dma->second_buffer = (uint8_t*) m_malloc(max_buffer_length, false);
dma->second_buffer = (uint8_t*) m_realloc(dma->second_buffer, max_buffer_length);
if (dma->second_buffer == NULL) {
return AUDIO_DMA_MEMORY_ERROR;
}

Loading…
Cancel
Save