/// <summary> /// Starts sampling audio from a specific device. /// </summary> public void Start(AsioSamplingServiceArgs args) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) throw new Exception("Thread must run in STA for ASIO sampling to work"); _currentDriver = args.Driver; if (!args.Driver.InputChannels.Contains(args.Channel)) throw new Exception("Input channel must be in driver.InputChannels"); // The order here is key // Create buffers before selecting the channel _currentDriver.CreateBuffers(false); _currentInputChannel = args.Driver.InputChannels.Where(x => x.Name == args.Channel.Name).Single(); args.Driver.BufferUpdate += new EventHandler(driver_BufferUpdate); _currentDriver.Start(); }
// Talking directly to the ViewModel like this is not the best. // Usually we want to use bindings and such, but this is simplest for something like this. private void channelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 1) return; Channel channel = e.AddedItems[0] as Channel; AsioSamplingServiceArgs args = new AsioSamplingServiceArgs() { Channel = channel, Driver = ViewModel.LoadedDriver, SamplingRate = 44100 }; ViewModel.RestartSamplingServiceCommand.Execute(args); }