Beispiel #1
0
        public FormMicrophone()
        {
            InitializeComponent();

            if (NAudio.Wave.WaveIn.DeviceCount == 0)
            {
                MessageBox.Show("No audio input devices found.\n\nThis program will now exit.",
                                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
            else
            {
                cbDevice.Items.Clear();
                for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
                {
                    cbDevice.Items.Add(NAudio.Wave.WaveIn.GetCapabilities(i).ProductName);
                }
                cbDevice.SelectedIndex = 0;
            }

            for (int i = 9; i < 16; i++)
            {
                cbFftSize.Items.Add($"2^{i} ({1 << i:N0})");
            }
            cbFftSize.SelectedIndex = 1;

            cmaps = Colormap.GetColormaps();
            foreach (Colormap cmap in cmaps)
            {
                cbColormap.Items.Add(cmap.Name);
            }
            cbColormap.SelectedIndex = cbColormap.Items.IndexOf("Viridis");
        }
Beispiel #2
0
        public MainViewModel()
        {
            //Setup the audio input
            if (NAudio.Wave.WaveIn.DeviceCount == 0)
            {
                //TODO: set NoDevice app state
            }
            else
            {
                DeviceCapabilities = new List <WaveInCapabilities>();
                for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
                {
                    DeviceCapabilities.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
                }
                SelectedDevice = DeviceCapabilities[0];
            }

            //Setup FFT size
            FftSizes = new List <int>()
            {
                512, 1024, 2048, 4096, 8192, 16384, 32768
            };
            SelectedFftSize = FftSizes[1];

            ColorMaps        = Colormap.GetColormaps().ToList();
            SelectedColorMap = ColorMaps.Where(c => c.Name == "Viridis").FirstOrDefault();
            Brightness       = 5;

            timer           = new DispatcherTimer();
            timer.Interval  = TimeSpan.FromMilliseconds(100);
            timer.IsEnabled = true;
            timer.Tick     += Timer_Tick;
            timer.Start();
        }
Beispiel #3
0
        private void SpecInit()
        {
            foreach (string sr in sampleRates)
            {
                cbSampleRate.Items.Add(sr);
            }
            cbSampleRate.SelectedIndex = 2;


            //Init mic inputs into the combo box
            if (NAudio.Wave.WaveIn.DeviceCount == 0)
            {
                MessageBox.Show("No audio input devices found.\n\nThis program will now exit.",
                                "ERROR", MessageBoxButton.OK);
                Close();
            }
            else
            {
                cbMicInput.Items.Clear();
                for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
                {
                    cbMicInput.Items.Add(NAudio.Wave.WaveIn.GetCapabilities(i).ProductName);
                }
                cbMicInput.SelectedIndex = 0;
            }

            //Init fft settings
            for (int i = 9; i < 14; i++)
            {
                cbFFTsize.Items.Add($"({1 << i:N0})");
            }
            cbFFTsize.SelectedIndex = 1;

            //Init fft settings
            for (int i = 0; i < 10; i++)
            {
                cbOverlap.Items.Add($"{i}/{(i+1)}");
            }
            cbOverlap.SelectedIndex = 1;


            //Init colormaps
            cmaps = Colormap.GetColormaps();
            foreach (Colormap cmap in cmaps)
            {
                cbCmaps.Items.Add(cmap.Name);
            }
            cbCmaps.SelectedIndex = cbCmaps.Items.IndexOf("Magma");


            //Timer used to continously update the spectrogram with new data
            specTimer          = new DispatcherTimer();
            specTimer.Interval = TimeSpan.FromMilliseconds(5);
            specTimer.Tick    += new EventHandler(SpecTimer_tick);
            specTimer.Start();

            scrollViewerSpec.ScrollToBottom();
            scrollViewerSpec.ScrollToRightEnd();
        }
Beispiel #4
0
        public void Test_Make_CommonColormaps()
        {
            (double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav");
            int fftSize = 1 << 12;
            var spec    = new SpectrogramGenerator(sampleRate, fftSize, stepSize: 700, maxFreq: 2000);

            spec.SetWindow(FftSharp.Window.Hanning(fftSize / 3)); // sharper window than typical
            spec.Add(audio);

            // delete old colormap files
            foreach (var filePath in System.IO.Directory.GetFiles("../../../../../dev/graphics/", "hal-*.png"))
            {
                System.IO.File.Delete(filePath);
            }

            foreach (var cmap in Colormap.GetColormaps())
            {
                spec.SetColormap(cmap);
                spec.SaveImage($"../../../../../dev/graphics/hal-{cmap.Name}.png");
                Debug.WriteLine($"![](dev/graphics/hal-{cmap.Name}.png)");
            }
        }