-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuForm.cs
55 lines (49 loc) · 1.7 KB
/
MenuForm.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
using FftSharp;
using Microsoft.VisualBasic;
using NAudio.CoreAudioApi;
using NAudio.CoreAudioApi.Interfaces;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace AudioMonitor
{
public partial class MenuForm : Form
{
public readonly MMDevice[] AudioDevices = new MMDeviceEnumerator()
.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active)
.ToArray();
public MenuForm()
{
InitializeComponent();
foreach (MMDevice device in AudioDevices)
{
string deviceType = device.DataFlow == DataFlow.Capture ? "Input" : "Output";
string deviceLabel = $"{deviceType} - {device.FriendlyName}";
lbDevice.Items.Add(deviceLabel);
}
lbDevice.SelectedIndex = 0;
}
private WasapiCapture GetSelectedDevice()
{
MMDevice selectedDevice = AudioDevices[lbDevice.SelectedIndex];
return selectedDevice.DataFlow == DataFlow.Render
? new WasapiLoopbackCapture(selectedDevice)
: new WasapiCapture(selectedDevice, true, 10);
}
private void button2_Click(object sender, EventArgs e)
{
WasapiCapture captureDevice = GetSelectedDevice();
this.WindowState= FormWindowState.Minimized;
new FftMonitorForm(captureDevice).ShowDialog();
this.WindowState= FormWindowState.Normal;
}
}
}