Audio: General cleanup and empty chunk checking

Upstream functions which return empty chunks on error do not return nil,
so the caller should check for an empty duration instead.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-02-13 01:05:15 -08:00
parent a78933ca80
commit 3cc97b5574
5 changed files with 66 additions and 11 deletions

View file

@ -101,13 +101,14 @@ void scale_by_volume(float *buffer, size_t count, float volume) {
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
if(!chunk) {
if(!chunk || ![chunk duration]) {
if([self endOfStream] == YES) {
break;
}
if(paused || !streamFormatChanged) {
continue;
}
usleep(500);
} else {
[self writeChunk:chunk];
chunk = nil;
@ -472,7 +473,7 @@ static float db_to_scale(float db) {
}
- (void)dealloc {
DLog(@"Decoder dealloc");
DLog(@"Converter dealloc");
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.volumeScaling" context:kConverterNodeContext];

View file

@ -16,6 +16,8 @@
#import "BufferChain.h"
#import "Logging.h"
#import "AudioPlayer.h"
extern void scale_by_volume(float *buffer, size_t count, float volume);
@ -152,6 +154,7 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
}
- (void)dealloc {
DLog(@"Equalizer dealloc");
[self cleanUp];
[self removeObservers];
}
@ -320,13 +323,14 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
if(!chunk) {
if(!chunk || ![chunk duration]) {
if([self endOfStream] == YES) {
break;
}
if(paused) {
continue;
}
usleep(500);
} else {
[self writeChunk:chunk];
chunk = nil;
@ -354,13 +358,23 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
return nil;
}
if(!inputFormat.mSampleRate ||
!inputFormat.mBitsPerChannel ||
!inputFormat.mChannelsPerFrame ||
!inputFormat.mBytesPerFrame ||
!inputFormat.mFramesPerPacket ||
!inputFormat.mBytesPerPacket) {
processEntered = NO;
return nil;
}
if((enableEqualizer && !equalizerInitialized) ||
memcmp(&inputFormat, &lastInputFormat, sizeof(inputFormat)) != 0 ||
inputChannelConfig != lastInputChannelConfig) {
lastInputFormat = inputFormat;
lastInputChannelConfig = inputChannelConfig;
[self fullShutdown];
if(![self setup]) {
if(enableEqualizer && ![self setup]) {
processEntered = NO;
return nil;
}

View file

@ -11,6 +11,8 @@
#import "DSPFSurroundNode.h"
#import "Logging.h"
#import "FSurroundFilter.h"
#define OCTAVES 5
@ -51,6 +53,7 @@ static void * kDSPFSurroundNodeContext = &kDSPFSurroundNodeContext;
}
- (void)dealloc {
DLog(@"FreeSurround dealloc");
[self cleanUp];
[self removeObservers];
}
@ -139,13 +142,14 @@ static void * kDSPFSurroundNodeContext = &kDSPFSurroundNodeContext;
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
if(!chunk) {
if(!chunk || ![chunk duration]) {
if([self endOfStream] == YES) {
break;
}
if(paused) {
continue;
}
usleep(500);
} else {
[self writeChunk:chunk];
chunk = nil;
@ -173,13 +177,23 @@ static void * kDSPFSurroundNodeContext = &kDSPFSurroundNodeContext;
return nil;
}
if(!inputFormat.mSampleRate ||
!inputFormat.mBitsPerChannel ||
!inputFormat.mChannelsPerFrame ||
!inputFormat.mBytesPerFrame ||
!inputFormat.mFramesPerPacket ||
!inputFormat.mBytesPerPacket) {
processEntered = NO;
return nil;
}
if((enableFSurround && !fsurround) ||
memcmp(&inputFormat, &lastInputFormat, sizeof(inputFormat)) != 0 ||
inputChannelConfig != lastInputChannelConfig) {
lastInputFormat = inputFormat;
lastInputChannelConfig = inputChannelConfig;
[self fullShutdown];
if(![self setup]) {
if(enableFSurround && ![self setup]) {
processEntered = NO;
return nil;
}

View file

@ -127,6 +127,7 @@ static void unregisterMotionListener(void) {
}
- (void)dealloc {
DLog(@"HRTF dealloc");
[self cleanUp];
[self removeObservers];
}
@ -264,13 +265,14 @@ static void unregisterMotionListener(void) {
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
if(!chunk) {
if(!chunk || ![chunk duration]) {
if([self endOfStream] == YES) {
break;
}
if(paused) {
continue;
}
usleep(500);
} else {
[self writeChunk:chunk];
chunk = nil;
@ -298,13 +300,23 @@ static void unregisterMotionListener(void) {
return nil;
}
if(!inputFormat.mSampleRate ||
!inputFormat.mBitsPerChannel ||
!inputFormat.mChannelsPerFrame ||
!inputFormat.mBytesPerFrame ||
!inputFormat.mFramesPerPacket ||
!inputFormat.mBytesPerPacket) {
processEntered = NO;
return nil;
}
if((enableHrtf && !hrtf) ||
memcmp(&inputFormat, &lastInputFormat, sizeof(inputFormat)) != 0 ||
inputChannelConfig != lastInputChannelConfig) {
lastInputFormat = inputFormat;
lastInputChannelConfig = inputChannelConfig;
[self fullShutdown];
if(![self setup]) {
if(enableHrtf && ![self setup]) {
processEntered = NO;
return nil;
}
@ -316,7 +328,7 @@ static void unregisterMotionListener(void) {
}
AudioChunk *chunk = [self readChunkAsFloat32:4096];
if(!chunk) {
if(!chunk || ![chunk duration]) {
processEntered = NO;
return nil;
}

View file

@ -11,6 +11,8 @@
#import "DSPRubberbandNode.h"
#import "Logging.h"
#import <rubberband/rubberband-c.h>
static void * kDSPRubberbandNodeContext = &kDSPRubberbandNodeContext;
@ -60,6 +62,7 @@ static void * kDSPRubberbandNodeContext = &kDSPRubberbandNodeContext;
}
- (void)dealloc {
DLog(@"Rubber Band dealloc");
[self cleanUp];
[self removeObservers];
}
@ -343,13 +346,14 @@ static void * kDSPRubberbandNodeContext = &kDSPRubberbandNodeContext;
@autoreleasepool {
AudioChunk *chunk = nil;
chunk = [self convert];
if(!chunk) {
if(!chunk || ![chunk duration]) {
if([self endOfStream] == YES) {
break;
}
if(paused) {
continue;
}
usleep(500);
} else {
[self writeChunk:chunk];
chunk = nil;
@ -381,13 +385,23 @@ static void * kDSPRubberbandNodeContext = &kDSPRubberbandNodeContext;
return nil;
}
if(!inputFormat.mSampleRate ||
!inputFormat.mBitsPerChannel ||
!inputFormat.mChannelsPerFrame ||
!inputFormat.mBytesPerFrame ||
!inputFormat.mFramesPerPacket ||
!inputFormat.mBytesPerPacket) {
processEntered = NO;
return nil;
}
if((enableRubberband && !ts) ||
memcmp(&inputFormat, &lastInputFormat, sizeof(inputFormat)) != 0 ||
inputChannelConfig != lastInputChannelConfig) {
lastInputFormat = inputFormat;
lastInputChannelConfig = inputChannelConfig;
[self fullShutdown];
if(![self setup]) {
if(enableRubberband && ![self setup]) {
processEntered = NO;
return nil;
}