Commits

Dave Dribin  committed 8805156

Move setInputCallback from the graph to the node. Retain the DDAudioUnit inside the node.

  • Participants
  • Parent commits 3a40448

Comments (0)

Files changed (4)

File lib/DDAudioUnitGraph.h

                               subType: (OSType) subType
                          manufacturer: (OSType) manufacturer;
 
-- (DDAudioUnitNode *) addNodeWithDescription:
-    (AudioComponentDescription *) description;
+- (DDAudioUnitNode *) addNodeWithDescription: (AudioComponentDescription *) description;
 
 - (DDAudioUnitNode *) addNodeWithComponent: (DDAudioComponent *) component;
 
 
 - (void) disconnectAll;
 
-- (void) setInputCallback: (AURenderCallback) renderCallBack
-                  context: (void *) context
-                  forNode: (DDAudioUnitNode *) sourceNode
-                    input: (UInt32) input;
-
 - (void) open;
 
 - (void) update;

File lib/DDAudioUnitGraph.m

     return [self addNodeWithDescription: &description];
 }
 
-- (DDAudioUnitNode *) addNodeWithDescription:
-    (AudioComponentDescription *) description;
+- (DDAudioUnitNode *) addNodeWithDescription: (AudioComponentDescription *) description;
 {
     AUNode node;
     THROW_IF(AUGraphAddNode(mGraph, description, &node));
     THROW_IF(AUGraphClearConnections(mGraph));
 }
 
-- (void) setInputCallback: (AURenderCallback) renderCallBack
-                  context: (void *) context
-                  forNode: (DDAudioUnitNode *) sourceNode
-                    input: (UInt32) input;
-{
-    AURenderCallbackStruct callback = {
-        .inputProc = renderCallBack,
-        .inputProcRefCon = context
-    };
-    THROW_IF(AUGraphSetNodeInputCallback(mGraph, [sourceNode AUNode], input,
-                                         &callback));
-}
-
 - (void) open;
 {
     THROW_IF(AUGraphOpen(mGraph));

File lib/DDAudioUnitNode.h

 {
     AUNode mNode;
     DDAudioUnitGraph * mGraph;
+    DDAudioUnit * mAudioUnit;
 }
 
 - (id) initWithAUNode: (AUNode) node inGraph: (DDAudioUnitGraph *) graph;
 
 - (DDAudioUnit *) audioUnit;
 
+- (void) setInputCallback: (AURenderCallback) renderCallBack
+                  context: (void *) context
+                 forInput: (UInt32) input;
+
 @end

File lib/DDAudioUnitNode.m

     return self;
 }
 
-- (void) delloc
+- (void) dealloc
 {
+    [mAudioUnit release];
+    [super dealloc];
 }
 
 - (AUNode) AUNode;
 
 - (DDAudioUnit *) audioUnit;
 {
-    AudioUnit audioUnit;
-    THROW_IF(AUGraphNodeInfo([mGraph AUGraph],
-                             [self AUNode],
-                             NULL, &audioUnit));
-    return [[[DDAudioUnit alloc] initWithAudioUnit: audioUnit] autorelease];
+    if (mAudioUnit == nil) {
+        AudioUnit audioUnit;
+        THROW_IF(AUGraphNodeInfo([mGraph AUGraph],
+                                 [self AUNode],
+                                 NULL, &audioUnit));
+        mAudioUnit = [[DDAudioUnit alloc] initWithAudioUnit: audioUnit];
+    }
+    
+    return mAudioUnit;
+}
+
+- (void) setInputCallback: (AURenderCallback) renderCallBack
+                  context: (void *) context
+                 forInput: (UInt32) input;
+{
+    AURenderCallbackStruct callback = {
+        .inputProc = renderCallBack,
+        .inputProcRefCon = context
+    };
+    THROW_IF(AUGraphSetNodeInputCallback([mGraph AUGraph], [self AUNode], input,
+                                         &callback));
 }
 
 @end