Last active
May 4, 2019 13:31
-
-
Save standinga/6f47369617ad9db78f080c1a810e4b2b to your computer and use it in GitHub Desktop.
updated initWithComponentDescription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (instancetype)initWithComponentDescription:(AudioComponentDescription)componentDescription options:(AudioComponentInstantiationOptions)options error:(NSError **)outError { | |
self = [super initWithComponentDescription:componentDescription options:options error:outError]; | |
if (self == nil) { return nil; } | |
// initialize Buffer | |
_buffer = Buffer(); | |
_buffer.maxFrames = 0; | |
_buffer.pcmBuffer = nullptr; | |
_buffer.mutableAudioBufferList = nullptr; | |
// Initialize a default format for the busses. | |
AVAudioFormat *defaultFormat = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100.0 channels:2]; | |
// Create parameter objects. | |
AUParameter *param1 = [AUParameterTree createParameterWithIdentifier:@"param1" name:@"Parameter 1" address:myParam1 min:0 max:100 unit:kAudioUnitParameterUnit_Percent unitName:nil flags:0 valueStrings:nil dependentParameters:nil]; | |
// Initialize the parameter values. | |
param1.value = 1.0; | |
// Create the parameter tree. | |
_parameterTree = [AUParameterTree createTreeWithChildren:@[ param1 ]]; | |
// Create the input and output busses (AUAudioUnitBus). | |
_inputBus = [[AUAudioUnitBus alloc] initWithFormat:defaultFormat error:nil]; | |
_outputBus = [[AUAudioUnitBus alloc] initWithFormat:defaultFormat error:nil]; | |
// Create the input and output bus arrays (AUAudioUnitBusArray). | |
_inputBusArray = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self busType:AUAudioUnitBusTypeInput busses:@[_inputBus]]; | |
_outputBusArray = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self busType:AUAudioUnitBusTypeOutput busses:@[_outputBus]]; | |
// A function to provide string representations of parameter values. | |
_parameterTree.implementorStringFromValueCallback = ^(AUParameter *param, const AUValue *__nullable valuePtr) { | |
AUValue value = valuePtr == nil ? param.value : *valuePtr; | |
switch (param.address) { | |
case myParam1: | |
return [NSString stringWithFormat:@"%.f", value]; | |
default: | |
return @"?"; | |
} | |
}; | |
__block Buffer *buffer = &_buffer; | |
_parameterTree.implementorValueObserver = ^(AUParameter *param, AUValue value) { | |
buffer->volume = value; | |
}; | |
self.maximumFramesToRender = 512; | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment