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) }; }
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(); }