void prepareAudioUnit ()
		{
			// AudioSession
			AudioSession.Initialize ();
			AudioSession.SetActive (true);
			AudioSession.Category = AudioSessionCategory.PlayAndRecord;
			AudioSession.PreferredHardwareIOBufferDuration = 0.005f;            

			// Getting AudioComponent Remote output 
			_audioComponent = AudioComponent.FindComponent (AudioTypeOutput.Remote);

			// creating an audio unit instance
			_audioUnit = new AudioUnit (_audioComponent);

			// turning on microphone
			_audioUnit.SetEnableIO (true,
                AudioUnitScopeType.Input,
                1 // Remote Input
			);

			// setting audio format
			_audioUnit.SetAudioFormat (_dstFormat, 
                AudioUnitScopeType.Input, 
                0 // Remote Output
			);  

			var format = AudioStreamBasicDescription.CreateLinearPCM (_sampleRate, bitsPerChannel: 32);
			format.FormatFlags = AudioStreamBasicDescription.AudioFormatFlagsAudioUnitCanonical;
			_audioUnit.SetAudioFormat (format, AudioUnitScopeType.Output, 1);

			// setting callback method
			_audioUnit.SetRenderCallback (_audioUnit_RenderCallback, AudioUnitScopeType.Global);

			_audioUnit.Initialize ();
			_audioUnit.Start ();
		}
예제 #2
0
        void SetupRemoteIO()
        {
            AudioComponentDescription desc = new AudioComponentDescription ();
            desc.ComponentType = AudioComponentType.Output;
            desc.ComponentSubType = 0x72696f63;

            desc.ComponentManufacturer = AudioComponentManufacturerType.Apple;

            desc.ComponentFlags = 0;
            desc.ComponentFlagsMask = 0;

            var component = AudioComponent.FindNextComponent (null, desc);

            rioUnit = new AudioUnit (component);

            rioUnit.SetEnableIO (true, AudioUnitScopeType.Input, 1);
            rioUnit.SetRenderCallback (renderDelegate, AudioUnitScopeType.Input, 0);

            audioFormat = new AudioStreamBasicDescription();

            audioFormat.Format = AudioFormatType.LinearPCM;
            audioFormat.SampleRate = sampleRate;

            audioFormat.ChannelsPerFrame = 2;
            audioFormat.FramesPerPacket = 1;
            audioFormat.BitsPerChannel = 8 * sizeof(int);
            audioFormat.BytesPerPacket = sizeof(int);
            audioFormat.BytesPerFrame = sizeof(int);

            audioFormat.FormatFlags = AudioStreamBasicDescription.AudioFormatFlagsAudioUnitCanonical;

            rioUnit.SetAudioFormat (audioFormat, AudioUnitScopeType.Input, 0);
            rioUnit.SetAudioFormat (audioFormat, AudioUnitScopeType.Output, 1);
            rioUnit.Initialize ();

            unitCreated = true;

            FFTBufferManager = new FFTBufferManager (maxFPS, this);
            FFTBufferManager.Setup ();

            rioUnit.Start ();

            unitIsRunning = true;
        }
        void prepareAudioUnit()
        {
            // Updated for deprecated AudioSession
            var session = AVAudioSession.SharedInstance();
            NSError error;

            if (session == null)
            {
                var alert = new UIAlertView("Session error", "Unable to create audio session", null, "Cancel");
                alert.Show();
                alert.Clicked += delegate
                {
                    alert.DismissWithClickedButtonIndex(0, true);
                    return;
                };
            }
            session.SetActive(true);
            session.SetCategory(AVAudioSessionCategory.PlayAndRecord);
            session.SetPreferredIOBufferDuration(0.005, out error);    

            // Getting AudioComponent Remote output 
            _audioComponent = AudioComponent.FindComponent(AudioTypeOutput.Remote);

            // creating an audio unit instance
            _audioUnit = new AudioUnit(_audioComponent);

            // turning on microphone
            _audioUnit.SetEnableIO(true,
                AudioUnitScopeType.Input,
                1 // Remote Input
            );

            // setting audio format
            _audioUnit.SetAudioFormat(_dstFormat, 
                AudioUnitScopeType.Input, 
                0 // Remote Output
            );  

            var format = AudioStreamBasicDescription.CreateLinearPCM(_sampleRate, bitsPerChannel: 32);
            format.FormatFlags = AudioStreamBasicDescription.AudioFormatFlagsNativeFloat;
            _audioUnit.SetAudioFormat(format, AudioUnitScopeType.Output, 1);

            // setting callback method
            _audioUnit.SetRenderCallback(_audioUnit_RenderCallback, AudioUnitScopeType.Global);

            _audioUnit.Initialize();
            _audioUnit.Start();
        }