Fix base audio node class not setting effectsHead and headNode after creation (fixes effect chain addition to stream output).

Change audio metering yet again.........
Uninit/reInit effects and down mixer nodes when input/output formats are set. Without doing this connecting non-stereo inputs fails. It's possible to be smarter about this by comparing the channel counts, but that's probably not worth it?
This commit is contained in:
Zakk 2020-02-24 01:53:36 -05:00
parent 8cbac8a54a
commit d1ffac94ec
7 changed files with 61 additions and 17 deletions

View file

@ -72,7 +72,6 @@
OSStatus err;
err = AudioUnitGetParameter(self.audioUnit, kStereoMixerParam_PostAveragePower, kAudioUnitScope_Output, bus, &result);
//err = AudioUnitGetParameter(self.audioUnit, kStereoMixerParam_PostAveragePower, kAudioUnitScope_Output, 0, &result);
if (err)
@ -88,9 +87,7 @@
Float32 result = 0;
OSStatus err;
err = AudioUnitGetParameter(self.audioUnit, kStereoMixerParam_PostAveragePower, kAudioUnitScope_Input, bus, &result);
//err = AudioUnitGetParameter(self.audioUnit, kStereoMixerParam_PostAveragePower, kAudioUnitScope_Output, 0, &result);
err = AudioUnitGetParameter(self.audioUnit, kStereoMixerParam_PostAveragePower, kAudioUnitScope_Input, bus, &result);
if (err)
{
@ -192,6 +189,20 @@
-(bool)setInputStreamFormat:(AVAudioFormat *)format bus:(UInt32)bus
{
bool retVal;
NSDictionary *saveData = [self saveDataForPrivateRestore];
AudioUnitUninitialize(self.audioUnit);
retVal = [super setInputStreamFormat:format bus:bus];
[self willInitializeNode];
AudioUnitInitialize(self.audioUnit);
[self didInitializeNode];
[self restoreDataFromPrivateRestore:saveData];
return retVal;
}
-(UInt32)getNextInputElement
{
UInt32 elementCount = 0;

View file

@ -104,6 +104,32 @@
}
-(bool)setInputStreamFormat:(AVAudioFormat *)format bus:(UInt32)bus
{
bool retval;
NSMutableDictionary *saveDict = [NSMutableDictionary dictionary];
[self saveDataToDict:saveDict];
AudioUnitUninitialize(self.audioUnit);
[self willInitializeNode];
retval = [super setInputStreamFormat:format bus:bus];
AudioUnitInitialize(self.audioUnit);
[self restoreDataFromDict:saveDict];
return retval;
}
-(bool)setOutputStreamFormat:(AVAudioFormat *)format bus:(UInt32)bus
{
bool retval;
NSMutableDictionary *saveDict = [NSMutableDictionary dictionary];
[self saveDataToDict:saveDict];
AudioUnitUninitialize(self.audioUnit);
[self willInitializeNode];
retval = [super setOutputStreamFormat:format bus:bus];
AudioUnitInitialize(self.audioUnit);
[self restoreDataFromDict:saveDict];
return retval;
}
-(void)saveDataToDict:(NSMutableDictionary *)saveDict
{
@ -114,7 +140,11 @@
[saveDict setObject:subType forKey:@"subType"];
[saveDict setObject:manufacturer forKey:@"manufacturer"];
[saveDict setObject:auType forKey:@"componentType"];
[saveDict setObject:self.name forKey:@"name"];
if (self.name)
{
[saveDict setObject:self.name forKey:@"name"];
}
[saveDict setObject:[NSNumber numberWithBool:self.bypass] forKey:@"bypass"];
CFPropertyListRef saveData;

View file

@ -384,7 +384,7 @@ OSStatus encoderRenderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
{
for (NSUInteger i = 0; i < self.previewMixer.channelCount - previewArray.count; i++)
{
[previewArray addObject:@(-240.0f)];
[previewArray addObject:@(-60.0f)];
}
} else {
@ -403,7 +403,7 @@ OSStatus encoderRenderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
{
for (NSUInteger i = 0; i < self.encodeMixer.channelCount - streamArray.count; i++)
{
[streamArray addObject:@(-240.0f)];
[streamArray addObject:@(-60.0f)];
}
} else {

View file

@ -214,6 +214,8 @@
if (err)
{
NSLog(@"AudioUnitSetProperty(MakeConnection) failed for %@ -> %@, err: %d", node, toNode, err);
NSLog(@"%@ OUTPUT %@", node, [node outputFormatForBus:outBus]);
NSLog(@"%@ INPUT %@", toNode, [toNode inputFormatForBus:inBus]);
return NO;
}

View file

@ -50,7 +50,7 @@
for (NSUInteger i = 0; i < self.channelCount - inputArray.count; i++)
{
[inputArray addObject:@(-240.0f)];
[inputArray addObject:@(-60.0f)];
}
} else {
@ -68,7 +68,7 @@
{
for (NSUInteger i = 0; i < self.downMixer.outputChannelCount - outputArray.count; i++)
{
[outputArray addObject:@(-240.0f)];
[outputArray addObject:@(-60.0f)];
}
} else {

View file

@ -263,6 +263,8 @@ UInt32 inNumberFrames,
dispatch_async(dispatch_get_main_queue(), completionHandler);
}
}
self.effectsHead = self;
self.headNode = self;
return YES;
}

View file

@ -15,7 +15,7 @@
-(float)convertDbToLinear:(float)dbVal
{
float minDB = -160.0f;
float minDB = -60.0f;
float level;
if (dbVal < minDB)
{
@ -23,11 +23,10 @@
} else if (dbVal >= 0.0f) {
level = 1.0f;
} else {
float minAmp = powf(10.0f, 0.05f * minDB);
float invAmpRange = 1.0f/(1.0f - minAmp);
float amp = powf(10.0f, 0.05f * dbVal);
float adjAmp = (amp - minAmp) * invAmpRange;
level = powf(adjAmp, 1.0f/2.0f);
//Just try a percentage?
float rawpercent = dbVal/60.0f;
level = 1.0f - fabs(rawpercent);
}
return level;
@ -60,14 +59,14 @@
if (!level1)
{
level1 = @(-240.0f);
level1 = @(-60.0f);
level2 = level1;
}
float useLevel = [self convertDbToLinear:level1.floatValue];
float useLevel2 = [self convertDbToLinear:level2.floatValue];
leftgrad = [[NSGradient alloc] initWithColorsAndLocations:[NSColor greenColor], 0.0f, [NSColor yellowColor], 0.5f, [NSColor redColor], 1.0f, nil];
leftgrad = [[NSGradient alloc] initWithColorsAndLocations:[NSColor greenColor], 0.0f, [NSColor yellowColor], 0.667f, [NSColor redColor], 1.0f, nil];
//backgroundGrad = [[NSGradient alloc] initWithColorsAndLocations:[NSColor colorWithRed:0.0f green:0.2f blue:0.0 alpha:1.0], 0.0f, [NSColor colorWithRed:0.2f green:0.2f blue:0.0f alpha:1.0f], 0.5f, [NSColor colorWithRed:0.2f green:0.0f blue:0.0f alpha:1.0f], 1.0f, nil];
[self.backgroundColor setFill];
NSRectFill(dirtyRect);