Output: Add more setup and format error checking
Some checks are pending
Check if Cog buildable / Build Universal Cog.app (push) Waiting to run
Some checks are pending
Check if Cog buildable / Build Universal Cog.app (push) Waiting to run
Add setup error checking and failure states, and also add a failure state for format changes while the device is already running, in case it returns a nil format structure. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
857ea20512
commit
9951b7cb6a
4 changed files with 32 additions and 16 deletions
|
@ -79,7 +79,9 @@
|
||||||
}
|
}
|
||||||
if(!output) {
|
if(!output) {
|
||||||
output = [[OutputNode alloc] initWithController:self previous:nil];
|
output = [[OutputNode alloc] initWithController:self previous:nil];
|
||||||
[output setupWithInterval:resumeInterval];
|
if(![output setupWithInterval:resumeInterval]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[output setVolume:volume];
|
[output setVolume:volume];
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
|
|
|
@ -45,8 +45,8 @@
|
||||||
|
|
||||||
- (double)secondsBuffered;
|
- (double)secondsBuffered;
|
||||||
|
|
||||||
- (void)setup;
|
- (BOOL)setup;
|
||||||
- (void)setupWithInterval:(BOOL)resumeInterval;
|
- (BOOL)setupWithInterval:(BOOL)resumeInterval;
|
||||||
- (void)process;
|
- (void)process;
|
||||||
- (void)close;
|
- (void)close;
|
||||||
- (void)seek:(double)time;
|
- (void)seek:(double)time;
|
||||||
|
|
|
@ -33,11 +33,11 @@
|
||||||
VisualizationNode *visualizationNode;
|
VisualizationNode *visualizationNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setup {
|
- (BOOL)setup {
|
||||||
[self setupWithInterval:NO];
|
return [self setupWithInterval:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupWithInterval:(BOOL)resumeInterval {
|
- (BOOL)setupWithInterval:(BOOL)resumeInterval {
|
||||||
if(!resumeInterval) {
|
if(!resumeInterval) {
|
||||||
amountPlayed = 0.0;
|
amountPlayed = 0.0;
|
||||||
amountPlayedInterval = 0.0;
|
amountPlayedInterval = 0.0;
|
||||||
|
@ -49,23 +49,26 @@
|
||||||
|
|
||||||
output = [[OutputCoreAudio alloc] initWithController:self];
|
output = [[OutputCoreAudio alloc] initWithController:self];
|
||||||
|
|
||||||
[output setup];
|
if(![output setup]) {
|
||||||
|
output = nil;
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
if(!DSPsLaunched) {
|
if(!DSPsLaunched) {
|
||||||
rubberbandNode = [[DSPRubberbandNode alloc] initWithController:self previous:nil latency:0.1];
|
rubberbandNode = [[DSPRubberbandNode alloc] initWithController:self previous:nil latency:0.1];
|
||||||
if(!rubberbandNode) return;
|
if(!rubberbandNode) return NO;
|
||||||
fsurroundNode = [[DSPFSurroundNode alloc] initWithController:self previous:rubberbandNode latency:0.03];
|
fsurroundNode = [[DSPFSurroundNode alloc] initWithController:self previous:rubberbandNode latency:0.03];
|
||||||
if(!fsurroundNode) return;
|
if(!fsurroundNode) return NO;
|
||||||
equalizerNode = [[DSPEqualizerNode alloc] initWithController:self previous:fsurroundNode latency:0.03];
|
equalizerNode = [[DSPEqualizerNode alloc] initWithController:self previous:fsurroundNode latency:0.03];
|
||||||
if(!equalizerNode) return;
|
if(!equalizerNode) return NO;
|
||||||
hrtfNode = [[DSPHRTFNode alloc] initWithController:self previous:equalizerNode latency:0.03];
|
hrtfNode = [[DSPHRTFNode alloc] initWithController:self previous:equalizerNode latency:0.03];
|
||||||
if(!hrtfNode) return;
|
if(!hrtfNode) return NO;
|
||||||
downmixNode = [[DSPDownmixNode alloc] initWithController:self previous:hrtfNode latency:0.03];
|
downmixNode = [[DSPDownmixNode alloc] initWithController:self previous:hrtfNode latency:0.03];
|
||||||
if(!downmixNode) return;
|
if(!downmixNode) return NO;
|
||||||
|
|
||||||
// Approximately double the chunk size for Vis at 44100Hz
|
// Approximately double the chunk size for Vis at 44100Hz
|
||||||
visualizationNode = [[VisualizationNode alloc] initWithController:self previous:downmixNode latency:8192.0 / 44100.0];
|
visualizationNode = [[VisualizationNode alloc] initWithController:self previous:downmixNode latency:8192.0 / 44100.0];
|
||||||
if(!visualizationNode) return;
|
if(!visualizationNode) return NO;
|
||||||
|
|
||||||
[self setPreviousNode:visualizationNode];
|
[self setPreviousNode:visualizationNode];
|
||||||
|
|
||||||
|
@ -75,6 +78,8 @@
|
||||||
|
|
||||||
previousInput = nil;
|
previousInput = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seek:(double)time {
|
- (void)seek:(double)time {
|
||||||
|
|
|
@ -223,8 +223,12 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
||||||
while(!stopping) {
|
while(!stopping) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
if(outputdevicechanged) {
|
if(outputdevicechanged) {
|
||||||
[self updateDeviceFormat];
|
if([self updateDeviceFormat]) {
|
||||||
outputdevicechanged = NO;
|
outputdevicechanged = NO;
|
||||||
|
} else {
|
||||||
|
usleep(2000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if([outputController shouldReset]) {
|
if([outputController shouldReset]) {
|
||||||
|
@ -474,6 +478,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
||||||
|
|
||||||
- (BOOL)updateDeviceFormat {
|
- (BOOL)updateDeviceFormat {
|
||||||
AVAudioFormat *format = _au.outputBusses[0].format;
|
AVAudioFormat *format = _au.outputBusses[0].format;
|
||||||
|
if(!format) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
if(!_deviceFormat || ![_deviceFormat isEqual:format]) {
|
if(!_deviceFormat || ![_deviceFormat isEqual:format]) {
|
||||||
NSError *err;
|
NSError *err;
|
||||||
|
@ -805,7 +812,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
||||||
|
|
||||||
[_au allocateRenderResourcesAndReturnError:&err];
|
[_au allocateRenderResourcesAndReturnError:&err];
|
||||||
|
|
||||||
[self updateDeviceFormat];
|
if(![self updateDeviceFormat]) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
visController = [VisualizationController sharedController];
|
visController = [VisualizationController sharedController];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue