public MainForm() { InitializeComponent(); buffer = new Byte[512]; audio = new RtAudio(); //audio1 = new RtAudio(); mixer = new RtStreamMixer(); // Setup Test Logging EventLoggerManager.TraceLoggingEvent += new LoggingEventHandler(EventLoggerManager_TraceLoggingEvent); EventLoggerManager.DebugLoggingEvent += new LoggingEventHandler(EventLoggerManager_DebugLoggingEvent); EventLoggerManager.InfoLoggingEvent += new LoggingEventHandler(EventLoggerManager_InfoLoggingEvent); EventLoggerManager.WarnLoggingEvent += new LoggingEventHandler(EventLoggerManager_WarnLoggingEvent); EventLoggerManager.ErrorLoggingEvent += new LoggingEventHandler(EventLoggerManager_ErrorLoggingEvent); EventLoggerManager.CriticalLoggingEvent += new LoggingEventHandler(EventLoggerManager_CriticalLoggingEvent); List <RtAudio.Api> compileApis = RtAudio.getCompiledApi(); // List the currently compiled APIs. logger.Debug("Compiled Apis:"); foreach (RtAudio.Api api in compileApis) { //Console.WriteLine(" {0}", api.ToString()); logger.Debug(String.Format(" {0}", api.ToString())); } // end foreach // Enumerate Devices uint deviceCount = audio.getDeviceCount(); //Console.WriteLine("Device Count: {0}", deviceCount); logger.Debug(String.Format("Device Count: {0}", deviceCount)); //Console.WriteLine("Found Devices:"); logger.Debug("Found Devices:"); for (uint idx = 0; deviceCount > idx; idx++) { RtAudio.DeviceInfo info = audio.getDeviceInfo(idx); //Console.WriteLine("ID {1}: {0}:", info.name, idx); //Console.WriteLine(" InputChannels: {0}", info.inputChannels); //Console.WriteLine(" OutputChannels: {0}", info.outputChannels); //Console.WriteLine(" DuplexChannels: {0}", info.duplexChannels); logger.Debug(String.Format("ID {1}: {0}:", info.name, idx)); logger.Debug(String.Format(" InputChannels: {0}", info.inputChannels)); logger.Debug(String.Format(" OutputChannels: {0}", info.outputChannels)); logger.Debug(String.Format(" DuplexChannels: {0}", info.duplexChannels)); if (info.inputChannels > 0) { inputCombo.Items.Add(info.name); inputCombo.SelectedIndex = 0; } // end if if (info.outputChannels > 0) { outputCombo.Items.Add(info.name); outputCombo.SelectedIndex = 0; } // end if } // end for }
private void startLoopback_Click(object sender, EventArgs e) { if (streamRunning == false) { int inputID = 0, outputID = 0; string selectedInput = inputCombo.SelectedItem as String; string selectedOutput = outputCombo.SelectedItem as String; for (int idx = 0; audio.getDeviceCount() > idx; idx++) { RtAudio.DeviceInfo info = audio.getDeviceInfo((uint)idx); if (info.name.Contains(selectedInput)) { inputID = idx; } // end if if (info.name.Contains(selectedOutput)) { outputID = idx; } // end if } // end for RtAudio.StreamParameters inputParams = new RtAudio.StreamParameters(); inputParams.deviceId = (uint)inputID; inputParams.nChannels = 2; RtAudio.StreamParameters outputParams = new RtAudio.StreamParameters(); outputParams.deviceId = (uint)outputID; outputParams.nChannels = 2; RtAudio.StreamOptions options = new RtAudio.StreamOptions(); options.priority = (int)RtAudioStreamFlags.RTAUDIO_SCHEDULE_REALTIME; options.flags = (int)RtAudioStreamFlags.RTAUDIO_MINIMIZE_LATENCY; //uint frames = 512; //audio.openStream(null, inputParams, RtAudioFormat.RTAUDIO_SINT8, 44100, 256, loopbackCallback, null, options); //audio1.openStream(outputParams, null, RtAudioFormat.RTAUDIO_SINT8, 44100, 256, loopbackCallback1, null, options); /*duplexStream = new RtDuplexStream(RtAudioFormat.RTAUDIO_SINT32, 2, 44100, 32, 256); * duplexStream.selectInputDevice((int)inputID); * duplexStream.selectOutputDevice((int)outputID); * duplexStream.Open(); * duplexStream.Start();*/ inputStream = new RtInputStream(RtAudioFormat.RTAUDIO_FLOAT32, 2, 44100, 32, 512); inputStream.Format.options = options; inputStream.selectInputDevice(inputID); inputStream.Name = "FooBar"; inputStream2 = new RtInputStream(RtAudioFormat.RTAUDIO_FLOAT32, 2, 44100, 32, 512); inputStream2.Format.options = options; inputStream2.selectInputDevice(0); inputStream2.Name = "FooBar 2"; //inputStream.callbackFired +=new EventHandler(inputStream_callbackFired); outputStream = new RtOutputStream(RtAudioFormat.RTAUDIO_FLOAT32, 2, 44100, 32, 512); outputStream.Format.options = options; outputStream.selectOutputDevice(outputID); mixer.AddInputStream(inputStream, 1.0f, -1.0f); mixer.AddInputStream(inputStream2, 1.0f, 1.0f); mixer.SetOutputStream(outputStream); mixer.Start(); //outputStream.callbackFired += new EventHandler(inputStream_callbackFired); //inputStream.Open(); //outputStream.Open(); //inputStream.Start(); //outputStream.Start(); // Change button text startLoopback.Text = "Stop Loopback"; streamRunning = true; // Start the stream //audio.startStream(); //audio1.startStream(); } else { mixer.Stop(); //audio.stopStream(); //audio.closeStream(); streamRunning = false; //duplexStream.Stop(); //duplexStream.Abort(); startLoopback.Text = "Start Loopback"; } // end if }