From 9480bc742c25fea960a3e40ac2fed9f42767324f Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 28 Mar 2025 01:34:54 -0700 Subject: [PATCH] MIDI: Move sample buffer from stack to class Move the stack-based buffer, which is rather large, to the player class instance, where it will be allocated on the heap. Signed-off-by: Christopher Snowhill --- Plugins/MIDI/MIDI/MIDIDecoder.h | 2 ++ Plugins/MIDI/MIDI/MIDIDecoder.mm | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.h b/Plugins/MIDI/MIDI/MIDIDecoder.h index 3664983ef..ecb690e4c 100644 --- a/Plugins/MIDI/MIDI/MIDIDecoder.h +++ b/Plugins/MIDI/MIDI/MIDIDecoder.h @@ -36,6 +36,8 @@ class BMPlayer; long framesLength; long framesFade; long framesRead; + + float outputBuffer[1024 * 2]; } @end diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.mm b/Plugins/MIDI/MIDI/MIDIDecoder.mm index cf68bc619..1c553121b 100644 --- a/Plugins/MIDI/MIDI/MIDIDecoder.mm +++ b/Plugins/MIDI/MIDI/MIDIDecoder.mm @@ -321,9 +321,8 @@ static OSType getOSType(const char *in_) { streamTimestamp = (double)(player->Tell()) / sampleRate; int frames = 1024; - float buffer[frames * 2]; - UInt32 frames_done = player->Play(buffer, frames); + UInt32 frames_done = player->Play(outputBuffer, frames); if(!frames_done) return 0; @@ -336,7 +335,7 @@ static OSType getOSType(const char *in_) { long fadeEnd = (framesRead + frames > localTotalFrames) ? localTotalFrames : (framesRead + frames); long fadePos; - float *buff = buffer; + float *buff = outputBuffer; float fadeScale = (float)(framesFade - (fadeStart - localFramesLength)) / framesFade; float fadeStep = 1.0 / (float)framesFade; @@ -362,7 +361,7 @@ static OSType getOSType(const char *in_) { id audioChunkClass = NSClassFromString(@"AudioChunk"); AudioChunk *chunk = [[audioChunkClass alloc] initWithProperties:[self properties]]; [chunk setStreamTimestamp:streamTimestamp]; - [chunk assignSamples:buffer frameCount:frames]; + [chunk assignSamples:outputBuffer frameCount:frames]; return chunk; } catch (std::exception &e) {