Пример #1
0
        public IOSAudioProcessor()
        {
            var inputComponent = AudioComponent.FindNextComponent(
                null,
                new AudioComponentDescription
                {
                    ComponentFlags = 0,
                    ComponentFlagsMask = 0,
                    ComponentManufacturer = AudioComponentManufacturerType.Apple,
                    ComponentSubType = (int)AudioTypeOutput.Remote,
                    ComponentType = AudioComponentType.Output
                });

            recorder = inputComponent.CreateAudioUnit();
            recorder.SetEnableIO(true, AudioUnitScopeType.Input, inputBus);
            recorder.SetEnableIO(false, AudioUnitScopeType.Output, outputBus);

            var audioFormat = new AudioStreamBasicDescription
                {
                    SampleRate = StudentDemo.Globals.SAMPLERATE,
                    Format = AudioFormatType.LinearPCM,
                    FormatFlags = AudioFormatFlags.IsSignedInteger | AudioFormatFlags.IsPacked,
                    FramesPerPacket = 1,
                    ChannelsPerFrame = 1,
                    BitsPerChannel = 16,
                    BytesPerPacket = 2,
                    BytesPerFrame = 2
                };

            recorder.SetAudioFormat(audioFormat, AudioUnitScopeType.Output, inputBus);
            recorder.SetAudioFormat(audioFormat, AudioUnitScopeType.Input, outputBus);

            recorder.SetInputCallback(AudioInputCallBack, AudioUnitScopeType.Global, inputBus);

            // TODO: Disable buffers (requires interop)
            aBuffer = new AudioBuffer
                {
                    NumberChannels = 1,
                    DataByteSize = 512 * 2,
                    Data = System.Runtime.InteropServices.Marshal.AllocHGlobal(512 * 2)
                };
        }
        void prepareAudioUnit()
        {
            // AudioSession
            AudioSession.Initialize();
            AudioSession.SetActive(true);
            AudioSession.Category = AudioSessionCategory.PlayAndRecord;
            AudioSession.PreferredHardwareIOBufferDuration = 0.01f;            

            // Getting a RemoteUI AudioUni AudioComponent
            _component = AudioComponent.FindComponent(AudioTypeOutput.Remote);

            // Getting Audiounit
            _audioUnit = AudioUnit.CreateInstance(_component);

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

            // setting AudioStreamBasicDescription
            int AudioUnitSampleTypeSize = (MonoTouch.ObjCRuntime.Runtime.Arch == MonoTouch.ObjCRuntime.Arch.SIMULATOR) ? sizeof(float) : sizeof(uint);
            AudioStreamBasicDescription audioFormat = new AudioStreamBasicDescription()
            {
                SampleRate = _sampleRate,
                Format = AudioFormatType.LinearPCM,
                //kAudioFormatFlagsAudioUnitCanonical = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved | (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift),
                FormatFlags = (AudioFormatFlags)((int)AudioFormatFlags.IsSignedInteger | (int)AudioFormatFlags.IsPacked | (int)AudioFormatFlags.IsNonInterleaved | (int)(kAudioUnitSampleFractionBits << (int)AudioFormatFlags.LinearPCMSampleFractionShift)),
                ChannelsPerFrame = 2,
                BytesPerPacket = AudioUnitSampleTypeSize,
                BytesPerFrame = AudioUnitSampleTypeSize,
                FramesPerPacket = 1,
                BitsPerChannel = 8 * AudioUnitSampleTypeSize,
                Reserved = 0
            };
            _audioUnit.SetAudioFormat(audioFormat, 
                AudioUnitScopeType.Input, 
                0 // Remote output
                );
            _audioUnit.SetAudioFormat(audioFormat, 
                AudioUnitScopeType.Output, 
                1 // Remote input
                );

            // setting callback
            if (MonoTouch.ObjCRuntime.Runtime.Arch == MonoTouch.ObjCRuntime.Arch.SIMULATOR)
                _audioUnit.RenderCallback += new EventHandler<AudioUnitEventArgs>(simulator_callback);
            else
                _audioUnit.RenderCallback += new EventHandler<AudioUnitEventArgs>(device_callback);

            // initialize
            _audioUnit.Initialize();
        }
Пример #3
0
        private void startTalking(UdpClient audioCaller)
        {
            //Stop old recording session

            //Generate new WaveFormat
            //    recorder.WaveFormat = new WaveFormat(16000, 16, 1);
            //    recorder.BufferMilliseconds = 50;
            //    recorder.DataAvailable += SendAudio; //Add event to SendAudio

            //			recorder = new InputAudioQueue (playerFormat);
            //
            //
            //			for (int i = 0; i < BUFFERCOUNT; i++) {
            //				IntPtr aBUff;
            //				//recorder.AllocateBuffer (AUDIOBUFFERSIZE, out aBUff);
            //				byteSize = AUDIOBUFFERSIZE * playerFormat.BytesPerPacket;
            //				recorder.AllocateBufferWithPacketDescriptors (byteSize, AUDIOBUFFERSIZE, out aBUff);
            //				recorder.EnqueueBuffer (aBUff, byteSize, null);
            //				Console.WriteLine ("Buffer allocated, enqueueing");
            //			}

            //New stuffs

            var inputComponent = AudioComponent.FindNextComponent(
                null,
                new AudioComponentDescription
                {
                    ComponentFlags = 0,
                    ComponentFlagsMask = 0,
                    ComponentManufacturer = AudioComponentManufacturerType.Apple,
                    ComponentSubType = (int)AudioTypeOutput.Remote,
                    ComponentType = AudioComponentType.Output
                });

            recorder = inputComponent.CreateAudioUnit();
            recorder.SetEnableIO(true, AudioUnitScopeType.Input, inputBus);
            recorder.SetEnableIO(false, AudioUnitScopeType.Output, outputBus);

            var audioFormat = new AudioStreamBasicDescription
                {
                    SampleRate = Globals.SAMPLERATE,
                    Format = AudioFormatType.LinearPCM,
                    FormatFlags = AudioFormatFlags.IsSignedInteger | AudioFormatFlags.IsPacked,
                    FramesPerPacket = 1,
                    ChannelsPerFrame = 1,
                    BitsPerChannel = 16,
                    BytesPerPacket = 2,
                    BytesPerFrame = 2
                };

            recorder.SetAudioFormat(audioFormat, AudioUnitScopeType.Output, inputBus);
            recorder.SetAudioFormat(audioFormat, AudioUnitScopeType.Input, outputBus);

            recorder.SetInputCallback(AudioInputCallBack, AudioUnitScopeType.Global, inputBus);

            // TODO: Disable buffers (requires interop)
            aBuffer = new AudioBuffer
                {
                    NumberChannels = 1,
                    DataByteSize = 512 * 2,
                    Data = System.Runtime.InteropServices.Marshal.AllocHGlobal(512 * 2)
                };
            isTalking = true;
            //recorder.InputCompleted += SendAudio;
            //recorder.Start ();

            recorder.Initialize ();
            recorder.Start ();
        }
Пример #4
0
        void prepareAudioUnit()
        {
            // Creating AudioComponentDescription instance of RemoteIO Audio Unit
            var cd = new AudioComponentDescription()
            {
                componentType = AudioComponentDescription.AudioComponentType.kAudioUnitType_Output,
                componentSubType = AudioComponentDescription.AudioComponentSubType.kAudioUnitSubType_RemoteIO,
                componentManufacturer = AudioComponentDescription.AudioComponentManufacturerType.kAudioUnitManufacturer_Apple,
                componentFlags = 0,
                componentFlagsMask = 0
            };

            // Getting AudioComponent from the description
            _component = AudioComponent.FindComponent(cd);

            // Getting Audiounit
            _audioUnit = AudioUnit.CreateInstance(_component);

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

            // setting AudioStreamBasicDescription       
            var audioFormat = AudioUnitUtils.AUCanonicalASBD(44100.0, 2);            
            _audioUnit.SetAudioFormat(audioFormat,
                AudioUnit.AudioUnitScopeType.kAudioUnitScope_Input,
                0 // Remote output
                );            
            _audioUnit.SetAudioFormat(audioFormat,
                AudioUnit.AudioUnitScopeType.kAudioUnitScope_Output,
                1 // Remote input
                );

            // setting callback
            _audioUnit.RenderCallback += new EventHandler<AudioUnitEventArgs>(_audioUnit_RenderCallback);                
            // initialize
            _audioUnit.Initialize();
        }
        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 = AudioUnit.CreateInstance(_audioComponent);

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

            // setting audio format
            _audioUnit.SetAudioFormat(_dstFormat, 
                AudioUnitScopeType.Input, 
                0 // Remote Output
                );            
            _audioUnit.SetAudioFormat( AudioUnitUtils.AUCanonicalASBD(_sampleRate, 2),                  
                AudioUnitScopeType.Output,                     
                1 // Remote input                     
                );


            // setting callback method
            _audioUnit.RenderCallback += new EventHandler<AudioUnitEventArgs>(_audioUnit_RenderCallback);

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

            // creating an AudioComponentDescription of the RemoteIO AudioUnit
            AudioComponentDescription cd = new AudioComponentDescription()
            {
                componentType = AudioComponentDescription.AudioComponentType.kAudioUnitType_Output,
                componentSubType = AudioComponentDescription.AudioComponentSubType.kAudioUnitSubType_RemoteIO,
                componentManufacturer = AudioComponentDescription.AudioComponentManufacturerType.kAudioUnitManufacturer_Apple,
                componentFlags = 0,
                componentFlagsMask = 0
            };

            // Getting AudioComponent using the audio component description
            _audioComponent = AudioComponent.FindComponent(cd);

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

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

            // setting audio format
            _audioUnit.SetAudioFormat(_dstFormat, 
                AudioUnit.AudioUnitScopeType.kAudioUnitScope_Input, 
                0 // Remote Output
                );            
            _audioUnit.SetAudioFormat( AudioUnitUtils.AUCanonicalASBD(_sampleRate, 2),                  
                AudioUnit.AudioUnitScopeType.kAudioUnitScope_Output,                     
                1 // Remote input                     
                );


            // setting callback method
            _audioUnit.RenderCallback += new EventHandler<AudioUnitEventArgs>(_audioUnit_RenderCallback);

            _audioUnit.Initialize();
            _audioUnit.Start();
        }
Пример #7
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 ()
		{
			// 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 ();
		}
        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();
        }