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 _remoteIO = _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 _remoteIO.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 _remoteIO.Initialize(); _auGraph.Initialize(); // mic setting }
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(); }
void prepareExtAudioFile() { // Opening Audio File _extAudioFile = ExtAudioFile.OpenURL(_url); // Getting file data format _srcFormat = _extAudioFile.FileDataFormat; // Setting the channel number of the output format same to the input format _dstFormat = AudioUnitUtils.AUCanonicalASBD(_sampleRate, _srcFormat.ChannelsPerFrame); // setting reading format as audio unit cannonical format _extAudioFile.ClientDataFormat = _dstFormat; // getting total frame _totalFrames = _extAudioFile.FileLengthFrames; // Seeking to the file head _extAudioFile.Seek(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(); }
protected override void init(DisposableI parent, Stream stream, int instanceCount, bool looped, Loader.LoadedCallbackMethod loadedCallback) { base.init(parent, stream, instanceCount, looped, loadedCallback); try { audio = parent.FindParentOrSelfWithException <Audio>(); audio.UpdateCallback += Update; this.data = base.data; this.channels = base.channels; this.bitDepth = base.bitDepth; desc = AudioUnitUtils.AUCanonicalASBD(sampleRate, channels); desc.FormatFlags = (AudioFormatFlags)((int)AudioFormatFlags.IsSignedInteger | (int)AudioFormatFlags.IsPacked | (int)AudioFormatFlags.IsNonInterleaved); for (int i = 0; i != instanceCount; ++i) { inactiveInstances.AddLast(new SoundWAVInstance(this, looped)); } } catch (Exception e) { FailedToLoad = true; Loader.AddLoadableException(e); Dispose(); if (loadedCallback != null) { loadedCallback(this, false); } return; } Loaded = true; if (loadedCallback != null) { loadedCallback(this, true); } }
void prepareExtAudioFile() { // Opening Audio File _extAudioFile = ExtAudioFile.OpenURL(_url); // Getting file data format _srcFormat = _extAudioFile.FileDataFormat; // Setting the channel number of the output format same to the input format _dstFormat = AudioUnitUtils.AUCanonicalASBD(_sampleRate, _srcFormat.ChannelsPerFrame); // setting reading format as audio unit cannonical format _extAudioFile.ClientDataFormat = _dstFormat; // getting total frame _totalFrames = _extAudioFile.FileLengthFrames; // Aloocating AudoBufferList _buffer = new AudioBufferList((uint)_srcFormat.ChannelsPerFrame, (uint)(sizeof(uint) * _totalFrames)); _numberOfChannels = _srcFormat.ChannelsPerFrame; // Reading all frame into the buffer _extAudioFile.Read((uint)_totalFrames, _buffer); }