summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-01-27 08:49:41 -0600
committerJeff Epler <jepler@gmail.com>2020-01-27 08:49:41 -0600
commitc8f969feb5f8dcdbe7716403e0a48d63ebb19352 (patch)
tree05401cc15f0cbdc72b628d713649ba9e344e0ce5
parentcb6193bbc76ee702128c44a95bc8184abcb04177 (diff)
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.
-rw-r--r--ports/atmel-samd/audio_dma.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c
index 0478cc9bf..352af8980 100644
--- a/ports/atmel-samd/audio_dma.c
+++ b/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;
}