Hopefully fix memory usage during playback

Shuffle around @autoreleasepool blocks, and also add one
to the audio processing code in the playback callback, so
audio memory is released during playback instead of
accumulating.

Fixes #379

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2023-10-11 20:11:22 -07:00
parent bc330e75f6
commit 1c95771ed0
No known key found for this signature in database
2 changed files with 62 additions and 62 deletions

View file

@ -93,13 +93,12 @@ void scale_by_volume(float *buffer, size_t count, float volume) {
// when the end of stream is reached. Convert function instead processes what it can,
// and returns 0 samples when it has nothing more to process at the end of stream.
while([self shouldContinue] == YES) {
AudioChunk *chunk = nil;
while(paused) {
usleep(500);
}
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
}
if(!chunk) {
if([self endOfStream] == YES) {
break;
@ -108,13 +107,10 @@ void scale_by_volume(float *buffer, size_t count, float volume) {
continue;
}
} else {
@autoreleasepool {
[self writeChunk:chunk];
chunk = nil;
}
}
if(streamFormatChanged) {
@autoreleasepool {
[self cleanUp];
[self setupWithInputFormat:newInputFormat withInputConfig:newInputChannelConfig outputFormat:self->outputFormat isLossless:rememberedLossless];
}

View file

@ -422,6 +422,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
secondsLatency = 1.0;
while(!stopping) {
@autoreleasepool {
if(outputdevicechanged) {
[self updateDeviceFormat];
outputdevicechanged = NO;
@ -453,6 +454,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
if([outputController shouldContinue] == NO) {
break;
}
}
usleep(5000);
}
@ -1038,6 +1040,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
OutputCoreAudio *_self = (__bridge OutputCoreAudio *)refCon;
int renderedSamples = 0;
@autoreleasepool {
while(renderedSamples < frameCount) {
int inputRemain = _self->inputRemain;
while(!inputRemain) {
@ -1060,6 +1063,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
double secondsRendered = (double)renderedSamples / format->mSampleRate;
[_self updateLatency:secondsRendered];
}
#ifdef _DEBUG
[BadSampleCleaner cleanSamples:(float *)inputData->mBuffers[0].mData