Beispiel #1
0
 static extern int AUGraphSetNodeInputCallback(IntPtr inUnit, Int32 inDestNode, UInt32 inDestInputNumber, AudioUnit.AURenderCallbackStrct inInputCallback);
        void prepareAUGraph()
        {
            // Creating audio graph instance
            _auGraph = AUGraph.CreateInstance();

            // Adding Remote IO node  to AUGraph
            AudioComponentDescription cd = new AudioComponentDescription()
            {
                componentType = AudioComponentDescription.AudioComponentType.kAudioUnitType_Output,
                componentSubType = AudioComponentDescription.AudioComponentSubType.kAudioUnitSubType_RemoteIO,
                componentManufacturer = AudioComponentDescription.AudioComponentManufacturerType.kAudioUnitManufacturer_Apple,
                componentFlags = 0,
                componentFlagsMask = 0
            };
            int remoteIONode = _auGraph.AddNode(cd);

            // Preparing AudioComponentDescrption of MultiChannelMixer
            cd.componentType = AudioComponentDescription.AudioComponentType.kAudioUnitType_Mixer;
            cd.componentSubType = AudioComponentDescription.AudioComponentSubType.kAudioUnitSubType_MultiChannelMixer;
            int multiChannelMixerNode = _auGraph.AddNode(cd);

            // Setting callback method as the case of Audio Unit            
            for (int i = 0; i < _waveDef.Length; i++)
            {
                var callbackStruct = new AudioUnit.AURenderCallbackStrct();
                callbackStruct.inputProc = device_renderCallback; // setting callback function
                callbackStruct.inputProcRefCon = GCHandle.ToIntPtr(_handle); // a pointer that passed to the renderCallback (IntPtr inRefCon) 
                _auGraph.AUGraphSetNodeInputCallback(
                    multiChannelMixerNode,
                    (uint)i, // bus number
                    callbackStruct);
            }            

            var remoteIOAudioUnit = _auGraph.GetNodeInfo(remoteIONode);
            var multiChannelMixerAudioUnit = _auGraph.GetNodeInfo(multiChannelMixerNode);

            // Getting an AudioUnit canonical description
            var audioFormat = AudioUnitUtils.AUCanonicalASBD(44100.0, 2);

            // applying the audio format to each audio units
            remoteIOAudioUnit.SetAudioFormat(audioFormat, AudioUnit.AudioUnitScopeType.kAudioUnitScope_Input, 0);
            multiChannelMixerAudioUnit.SetAudioFormat(audioFormat, AudioUnit.AudioUnitScopeType.kAudioUnitScope_Input, 0);
            
            // connecting multiChannelMixerNode(bus:0) to remoteIONode(bus:0)
            _auGraph.ConnnectNodeInput(
                multiChannelMixerNode, 
                0, // output bus                
                remoteIONode, 
                0  // input bus
                );
            
            // graph initialization
            _auGraph.Initialize();
        }
Beispiel #3
0
        public void AUGraphSetNodeInputCallback(int inDestNode, uint inDestInputNumber, AudioUnit.AURenderCallbackStrct inInputCallback)
        {
            int err = AUGraphSetNodeInputCallback(_auGraph,
                                                  inDestNode, inDestInputNumber, inInputCallback);

            if (err != 0)
            {
                throw new ArgumentException(String.Format("Error code:", err));
            }
        }