[Core Audio Output] Move output function block
Move the Core Audio output function block to its own declarative function, so that its block variables are isolated, and so that debug traces show up in a more sensible place. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
8dddf6a115
commit
ca6a2f41df
|
@ -667,68 +667,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
|||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)setup {
|
||||
if(_au)
|
||||
[self stop];
|
||||
|
||||
@synchronized(self) {
|
||||
stopInvoked = NO;
|
||||
|
||||
running = NO;
|
||||
stopping = NO;
|
||||
stopped = NO;
|
||||
paused = NO;
|
||||
stopNext = NO;
|
||||
outputDeviceID = -1;
|
||||
restarted = NO;
|
||||
|
||||
downmixer = nil;
|
||||
downmixerForVis = nil;
|
||||
|
||||
AudioComponentDescription desc;
|
||||
NSError *err;
|
||||
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_HALOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
|
||||
_au = [[AUAudioUnit alloc] initWithComponentDescription:desc error:&err];
|
||||
if(err != nil)
|
||||
return NO;
|
||||
|
||||
// Setup the output device before mucking with settings
|
||||
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||
if(device) {
|
||||
BOOL ok = [self setOutputDeviceWithDeviceDict:device];
|
||||
if(!ok) {
|
||||
// Ruh roh.
|
||||
[self setOutputDeviceWithDeviceDict:nil];
|
||||
|
||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
||||
}
|
||||
} else {
|
||||
[self setOutputDeviceWithDeviceDict:nil];
|
||||
}
|
||||
|
||||
_deviceFormat = nil;
|
||||
|
||||
AudioComponent comp = NULL;
|
||||
|
||||
desc.componentType = kAudioUnitType_Effect;
|
||||
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
||||
|
||||
comp = AudioComponentFindNext(comp, &desc);
|
||||
if(!comp)
|
||||
return NO;
|
||||
|
||||
OSStatus _err = AudioComponentInstanceNew(comp, &_eq);
|
||||
if(err)
|
||||
return NO;
|
||||
|
||||
[self updateDeviceFormat];
|
||||
|
||||
- (void)audioOutputBlock {
|
||||
__block AudioUnit eq = _eq;
|
||||
__block AudioStreamBasicDescription *format = &deviceFormat;
|
||||
__block BOOL *eqEnabled = &self->eqEnabled;
|
||||
|
@ -792,6 +731,71 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
|||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
- (BOOL)setup {
|
||||
if(_au)
|
||||
[self stop];
|
||||
|
||||
@synchronized(self) {
|
||||
stopInvoked = NO;
|
||||
|
||||
running = NO;
|
||||
stopping = NO;
|
||||
stopped = NO;
|
||||
paused = NO;
|
||||
stopNext = NO;
|
||||
outputDeviceID = -1;
|
||||
restarted = NO;
|
||||
|
||||
downmixer = nil;
|
||||
downmixerForVis = nil;
|
||||
|
||||
AudioComponentDescription desc;
|
||||
NSError *err;
|
||||
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_HALOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
|
||||
_au = [[AUAudioUnit alloc] initWithComponentDescription:desc error:&err];
|
||||
if(err != nil)
|
||||
return NO;
|
||||
|
||||
// Setup the output device before mucking with settings
|
||||
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||
if(device) {
|
||||
BOOL ok = [self setOutputDeviceWithDeviceDict:device];
|
||||
if(!ok) {
|
||||
// Ruh roh.
|
||||
[self setOutputDeviceWithDeviceDict:nil];
|
||||
|
||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
||||
}
|
||||
} else {
|
||||
[self setOutputDeviceWithDeviceDict:nil];
|
||||
}
|
||||
|
||||
_deviceFormat = nil;
|
||||
|
||||
AudioComponent comp = NULL;
|
||||
|
||||
desc.componentType = kAudioUnitType_Effect;
|
||||
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
||||
|
||||
comp = AudioComponentFindNext(comp, &desc);
|
||||
if(!comp)
|
||||
return NO;
|
||||
|
||||
OSStatus _err = AudioComponentInstanceNew(comp, &_eq);
|
||||
if(err)
|
||||
return NO;
|
||||
|
||||
[self updateDeviceFormat];
|
||||
|
||||
[self audioOutputBlock];
|
||||
|
||||
[_au setMaximumFramesToRender:512];
|
||||
|
||||
|
|
Loading…
Reference in New Issue