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 <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-28 01:34:54 -07:00
parent d590a03595
commit 9480bc742c
2 changed files with 5 additions and 4 deletions

View file

@ -36,6 +36,8 @@ class BMPlayer;
long framesLength; long framesLength;
long framesFade; long framesFade;
long framesRead; long framesRead;
float outputBuffer[1024 * 2];
} }
@end @end

View file

@ -321,9 +321,8 @@ static OSType getOSType(const char *in_) {
streamTimestamp = (double)(player->Tell()) / sampleRate; streamTimestamp = (double)(player->Tell()) / sampleRate;
int frames = 1024; int frames = 1024;
float buffer[frames * 2];
UInt32 frames_done = player->Play(buffer, frames); UInt32 frames_done = player->Play(outputBuffer, frames);
if(!frames_done) if(!frames_done)
return 0; return 0;
@ -336,7 +335,7 @@ static OSType getOSType(const char *in_) {
long fadeEnd = (framesRead + frames > localTotalFrames) ? localTotalFrames : (framesRead + frames); long fadeEnd = (framesRead + frames > localTotalFrames) ? localTotalFrames : (framesRead + frames);
long fadePos; long fadePos;
float *buff = buffer; float *buff = outputBuffer;
float fadeScale = (float)(framesFade - (fadeStart - localFramesLength)) / framesFade; float fadeScale = (float)(framesFade - (fadeStart - localFramesLength)) / framesFade;
float fadeStep = 1.0 / (float)framesFade; float fadeStep = 1.0 / (float)framesFade;
@ -362,7 +361,7 @@ static OSType getOSType(const char *in_) {
id audioChunkClass = NSClassFromString(@"AudioChunk"); id audioChunkClass = NSClassFromString(@"AudioChunk");
AudioChunk *chunk = [[audioChunkClass alloc] initWithProperties:[self properties]]; AudioChunk *chunk = [[audioChunkClass alloc] initWithProperties:[self properties]];
[chunk setStreamTimestamp:streamTimestamp]; [chunk setStreamTimestamp:streamTimestamp];
[chunk assignSamples:buffer frameCount:frames]; [chunk assignSamples:outputBuffer frameCount:frames];
return chunk; return chunk;
} catch (std::exception &e) { } catch (std::exception &e) {