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.
This commit is contained in:
Jeff Epler 2020-01-27 08:49:41 -06:00
parent cb6193bbc7
commit c8f969feb5
1 changed files with 2 additions and 2 deletions

View File

@ -203,13 +203,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
if (output_signed != samples_signed) { if (output_signed != samples_signed) {
output_spacing = 1; output_spacing = 1;
max_buffer_length /= dma->spacing; 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) { if (dma->first_buffer == NULL) {
return AUDIO_DMA_MEMORY_ERROR; return AUDIO_DMA_MEMORY_ERROR;
} }
dma->first_buffer_free = true; dma->first_buffer_free = true;
if (!single_buffer) { 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) { if (dma->second_buffer == NULL) {
return AUDIO_DMA_MEMORY_ERROR; return AUDIO_DMA_MEMORY_ERROR;
} }