Properly return inputFormat for file input.

No longer rely on AUGraphInteractions to find next input/output elements, use CAMultiAudioGraph connection info
This commit is contained in:
Zakk 2020-02-22 21:22:36 -05:00
parent f2c879b99b
commit 1e966d5730
3 changed files with 44 additions and 109 deletions

View file

@ -201,38 +201,21 @@
AudioUnitGetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &elementCount, &elementSize);
UInt32 interactionCnt = 0;
AUGraphCountNodeInteractions(self.graph.graphInst, self.node, &interactionCnt);
AUNodeInteraction *interactions = malloc(sizeof(AUNodeInteraction)*interactionCnt);
AUGraphGetNodeInteractions(self.graph.graphInst, self.node, &interactionCnt, interactions);
useElement = 0;
UInt32 seenIdx = 0;
for (int i=0; i < interactionCnt; i++)
{
useElement = UINT32_MAX;
AUNodeInteraction iact = interactions[i];
if (iact.nodeInteractionType == kAUNodeInteraction_Connection && iact.nodeInteraction.connection.destNode == self.node)
for (UInt32 i=0; i < elementCount; i++)
{
CAMultiAudioConnection *inConn = [self.graph inputConnection:self forBus:i];
if (!inConn)
{
if (seenIdx != iact.nodeInteraction.connection.destInputNumber)
{
useElement = seenIdx;
break;
} else {
seenIdx++;
useElement = iact.nodeInteraction.connection.destInputNumber+1;
}
useElement = i;
break;
}
}
free(interactions);
if (useElement >= elementCount)
if (useElement == UINT32_MAX)
{
useElement = elementCount;
elementCount += 64;
NSDictionary *saveData = [self saveDataForPrivateRestore];
AudioUnitUninitialize(self.audioUnit);
@ -241,7 +224,6 @@
AudioUnitInitialize(self.audioUnit);
[self didInitializeNode];
[self restoreDataFromPrivateRestore:saveData];
}
[self setVolumeOnInputBus:useElement volume:1.0];
@ -257,38 +239,21 @@
AudioUnitGetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Output, 0, &elementCount, &elementSize);
UInt32 interactionCnt = 0;
AUGraphCountNodeInteractions(self.graph.graphInst, self.node, &interactionCnt);
AUNodeInteraction *interactions = malloc(sizeof(AUNodeInteraction)*interactionCnt);
AUGraphGetNodeInteractions(self.graph.graphInst, self.node, &interactionCnt, interactions);
useElement = 0;
UInt32 seenIdx = 0;
for (int i=0; i < interactionCnt; i++)
{
useElement = UINT32_MAX;
AUNodeInteraction iact = interactions[i];
if (iact.nodeInteractionType == kAUNodeInteraction_Connection && iact.nodeInteraction.connection.sourceNode == self.node)
for (UInt32 i=0; i < elementCount; i++)
{
NSArray *outConns = [self.graph outputConnections:self forBus:i];
if (!outConns || outConns.count == 0)
{
if (seenIdx != iact.nodeInteraction.connection.sourceOutputNumber)
{
useElement = seenIdx;
break;
} else {
seenIdx++;
useElement = iact.nodeInteraction.connection.sourceOutputNumber+1;
}
useElement = i;
break;
}
}
free(interactions);
if (useElement >= elementCount)
if (useElement == UINT32_MAX)
{
useElement = elementCount;
elementCount += 64;
NSDictionary *saveData = [self saveDataForPrivateRestore];
AudioUnitUninitialize(self.audioUnit);
@ -299,7 +264,7 @@
[self restoreDataFromPrivateRestore:saveData];
}
[self setVolumeOnOutputBus:useElement volume:1.0];
[self setVolumeOnInputBus:useElement volume:1.0];
return useElement;
}

View file

@ -362,6 +362,10 @@
}
}
-(AVAudioFormat *)inputFormat
{
return _outputFormat;
}
-(void)dealloc

View file

@ -155,42 +155,25 @@
AudioUnitGetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &elementCount, &elementSize);
UInt32 interactionCnt = 0;
AUGraphCountNodeInteractions(self.graph.graphInst, self.node, &interactionCnt);
AUNodeInteraction *interactions = malloc(sizeof(AUNodeInteraction)*interactionCnt);
AUGraphGetNodeInteractions(self.graph.graphInst, self.node, &interactionCnt, interactions);
useElement = 0;
UInt32 seenIdx = 0;
for (int i=0; i < interactionCnt; i++)
{
useElement = UINT32_MAX;
AUNodeInteraction iact = interactions[i];
if (iact.nodeInteractionType == kAUNodeInteraction_Connection && iact.nodeInteraction.connection.destNode == self.node)
for (UInt32 i=0; i < elementCount; i++)
{
CAMultiAudioConnection *inConn = [self.graph inputConnection:self forBus:i];
if (!inConn)
{
if (seenIdx != iact.nodeInteraction.connection.destInputNumber)
{
useElement = seenIdx;
break;
} else {
seenIdx++;
useElement = iact.nodeInteraction.connection.destInputNumber+1;
}
useElement = i;
break;
}
}
free(interactions);
if (useElement >= elementCount)
if (useElement == UINT32_MAX)
{
useElement = elementCount;
elementCount += 64;
AudioUnitSetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &elementCount, sizeof(elementCount));
AudioUnitSetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Output, 0, &elementCount, sizeof(elementCount));
}
[self setVolumeOnInputBus:useElement volume:1.0];
return useElement;
}
@ -203,40 +186,23 @@
UInt32 useElement = 0;
AudioUnitGetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Output, 0, &elementCount, &elementSize);
AudioUnitGetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &elementCount, &elementSize);
UInt32 interactionCnt = 0;
AUGraphCountNodeInteractions(self.graph.graphInst, self.node, &interactionCnt);
AUNodeInteraction *interactions = malloc(sizeof(AUNodeInteraction)*interactionCnt);
AUGraphGetNodeInteractions(self.graph.graphInst, self.node, &interactionCnt, interactions);
useElement = 0;
UInt32 seenIdx = 0;
for (int i=0; i < interactionCnt; i++)
{
useElement = UINT32_MAX;
AUNodeInteraction iact = interactions[i];
if (iact.nodeInteractionType == kAUNodeInteraction_Connection && iact.nodeInteraction.connection.sourceNode == self.node)
for (UInt32 i=0; i < elementCount; i++)
{
NSArray *outConns = [self.graph outputConnections:self forBus:i];
if (!outConns || outConns.count == 0)
{
if (seenIdx != iact.nodeInteraction.connection.sourceOutputNumber)
{
useElement = seenIdx;
break;
} else {
seenIdx++;
useElement = iact.nodeInteraction.connection.sourceOutputNumber+1;
}
useElement = i;
break;
}
}
free(interactions);
if (useElement >= elementCount)
if (useElement == UINT32_MAX)
{
useElement = elementCount;
elementCount += 64;
AudioUnitSetProperty(self.audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Output, 0, &elementCount, sizeof(elementCount));
}