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:
parent
d590a03595
commit
9480bc742c
2 changed files with 5 additions and 4 deletions
|
@ -36,6 +36,8 @@ class BMPlayer;
|
|||
long framesLength;
|
||||
long framesFade;
|
||||
long framesRead;
|
||||
|
||||
float outputBuffer[1024 * 2];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue