Output: Add more setup and format error checking
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
df3a2ad727
commit
b55d0f6586
4 changed files with 32 additions and 16 deletions
|
@ -79,7 +79,9 @@
|
|||
}
|
||||
if(!output) {
|
||||
output = [[OutputNode alloc] initWithController:self previous:nil];
|
||||
[output setupWithInterval:resumeInterval];
|
||||
if(![output setupWithInterval:resumeInterval]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
[output setVolume:volume];
|
||||
@synchronized(chainQueue) {
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
|
||||
- (double)secondsBuffered;
|
||||
|
||||
- (void)setup;
|
||||
- (void)setupWithInterval:(BOOL)resumeInterval;
|
||||
- (BOOL)setup;
|
||||
- (BOOL)setupWithInterval:(BOOL)resumeInterval;
|
||||
- (void)process;
|
||||
- (void)close;
|
||||
- (void)seek:(double)time;
|
||||
|
|
|
@ -33,11 +33,11 @@
|
|||
VisualizationNode *visualizationNode;
|
||||
}
|
||||
|
||||
- (void)setup {
|
||||
[self setupWithInterval:NO];
|
||||
- (BOOL)setup {
|
||||
return [self setupWithInterval:NO];
|
||||
}
|
||||
|
||||
- (void)setupWithInterval:(BOOL)resumeInterval {
|
||||
- (BOOL)setupWithInterval:(BOOL)resumeInterval {
|
||||
if(!resumeInterval) {
|
||||
amountPlayed = 0.0;
|
||||
amountPlayedInterval = 0.0;
|
||||
|
@ -49,23 +49,26 @@
|
|||
|
||||
output = [[OutputCoreAudio alloc] initWithController:self];
|
||||
|
||||
[output setup];
|
||||
if(![output setup]) {
|
||||
output = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if(!DSPsLaunched) {
|
||||
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];
|
||||
if(!fsurroundNode) return;
|
||||
if(!fsurroundNode) return NO;
|
||||
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];
|
||||
if(!hrtfNode) return;
|
||||
if(!hrtfNode) return NO;
|
||||
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
|
||||
visualizationNode = [[VisualizationNode alloc] initWithController:self previous:downmixNode latency:8192.0 / 44100.0];
|
||||
if(!visualizationNode) return;
|
||||
if(!visualizationNode) return NO;
|
||||
|
||||
[self setPreviousNode:visualizationNode];
|
||||
|
||||
|
@ -75,6 +78,8 @@
|
|||
|
||||
previousInput = nil;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)seek:(double)time {
|
||||
|
|
|
@ -223,8 +223,12 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
|||
while(!stopping) {
|
||||
@autoreleasepool {
|
||||
if(outputdevicechanged) {
|
||||
[self updateDeviceFormat];
|
||||
outputdevicechanged = NO;
|
||||
if([self updateDeviceFormat]) {
|
||||
outputdevicechanged = NO;
|
||||
} else {
|
||||
usleep(2000);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if([outputController shouldReset]) {
|
||||
|
@ -474,6 +478,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
|||
|
||||
- (BOOL)updateDeviceFormat {
|
||||
AVAudioFormat *format = _au.outputBusses[0].format;
|
||||
if(!format) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if(!_deviceFormat || ![_deviceFormat isEqual:format]) {
|
||||
NSError *err;
|
||||
|
@ -805,7 +812,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
|||
|
||||
[_au allocateRenderResourcesAndReturnError:&err];
|
||||
|
||||
[self updateDeviceFormat];
|
||||
if(![self updateDeviceFormat]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
visController = [VisualizationController sharedController];
|
||||
|
||||
|
|
Loading…
Reference in a new issue