-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
62 lines (47 loc) · 1.92 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using NAudio.CoreAudioApi;
using TunerWinUI.AudioCapturers;
using TunerWinUI.AudioVisualizers;
namespace TunerWinUI;
public sealed partial class MainWindow : Window
{
#region PROPERTIES
public CaptureEngine<short> AudioEngine { get; } = new CEngine16Bit(DataFlow.All);
public RTScope<short> TimeDomainPlot { get; } = new TimeScope16Bit(DispatcherQueue.GetForCurrentThread());
public FFTScope16Bit FrequencyDomainPlot { get; } = new(DispatcherQueue.GetForCurrentThread());
#endregion
public MainWindow()
{
InitializeComponent();
}
private void ToggleCapture_Click(object sender, RoutedEventArgs e)
{
if (AudioEngine.IsBusyCapturing)
{
AudioEngine.StopCapture();
SourceDeviceCombo.IsEnabled = true;
SamplingRateCombo.IsEnabled = true;
FFTSizeCombo.IsEnabled = true;
CaptureButtonSymbol.Symbol = Symbol.Play;
}
else
{
var selectedSampleRate = SamplingRateCombo.SelectedItem?.ToString();
if (selectedSampleRate != null)
{
var intValue = int.Parse(selectedSampleRate.Split(" ")[0]);
AudioEngine.SampleRate = intValue;
FrequencyDomainPlot.SampleRate = intValue;
}
FrequencyDomainPlot.FFTSize = (int)FFTSizeCombo.SelectedItem;
AudioEngine.StartCapture(SourceDeviceCombo.SelectedItem?.ToString() ?? string.Empty, TimeDomainPlot, FrequencyDomainPlot);
CaptureButtonSymbol.Symbol = Symbol.Stop;
SourceDeviceCombo.IsEnabled = false;
SamplingRateCombo.IsEnabled = false;
FFTSizeCombo.IsEnabled = false;
}
}
private void RefreshOnlineDevices_Click(object sender, RoutedEventArgs e) => AudioEngine.RefreshAvailableDevicesList(DataFlow.Capture);
}