ActionVisualizer.MainWindow.StartStopSineWave C# (CSharp) Method

StartStopSineWave() private method

private StartStopSineWave ( ) : void
return void
        private void StartStopSineWave()
        {
            if (waveOut == null)
            {
                button1.Content = "Stop Sound";
                Console.WriteLine("User Selected Channels: " + selectedChannels);
                WaveOutCapabilities outdeviceInfo = WaveOut.GetCapabilities(0);
                waveOutChannels = outdeviceInfo.Channels;
                waveOut = new WaveOut();

                int waveOutDevices = WaveOut.DeviceCount;
                for (int i = 0; i < waveOutDevices; i++)
                {
                    outdeviceInfo = WaveOut.GetCapabilities(i);
                    Console.WriteLine("Device {0}: {1}, {2} channels",
                            i, outdeviceInfo.ProductName, outdeviceInfo.Channels);
                }

                List<IWaveProvider> inputs = new List<IWaveProvider>();
                frequencies = new List<int>();
                centerbins = new List<int>();

                for (int c = 0; c < selectedChannels; c++)
                {
                        //Original Sine Wave generation
                        inputs.Add(new SineWaveProvider32(minFrequency + c * frequencyStep, 0.5f, 44100, 1));
                        frequencies.Add(minFrequency + c * frequencyStep);
                        centerbins.Add((int)Math.Round((minFrequency + c * frequencyStep) / 10.768));
                }

                var splitter = new MultiplexingWaveProvider(inputs, selectedChannels);
                try
                {
                    waveOut.Init(splitter);
                    waveOut.Play();
                }
                catch (System.ArgumentException)
                {
                    Console.WriteLine("Invalid audio channel count. Please select a lower number of audio channels");
                }

                //Console.WriteLine("Number of Channels: " + wOut.NumberOfBuffers);
                Console.WriteLine("Number of Channels: " + waveOut.OutputWaveFormat.Channels);
            }
            else
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
                button1.Content = "Start Sound";

                frequencies.Clear();
                centerbins.Clear();
            }
        }