diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs deleted file mode 100644 index 7945aa7..0000000 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Correlator.DataService; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using NAudio.CoreAudioApi; -using NAudio.Wave; -using Prism.Commands; -using Prism.Events; -using Prism.Mvvm; -using Prism.Services.Dialogs; - -namespace Correlator.ViewModels -{ - public class AuditionViewModel : BindableBase, IDialogAware - { - #region DelegateCommand - - public DelegateCommand GoBackCommand { get; set; } - public DelegateCommand ListenRedSensorCommand { get; } - public DelegateCommand RedSensorMuteCommand { get; } - public DelegateCommand ListenBlueSensorCommand { get; } - public DelegateCommand BlueSensorMuteCommand { get; } - - #endregion - - #region VM - - public string Title { get; private set; } = string.Empty; - public event Action RequestClose; - private int _currentVolume; - - public int CurrentVolume - { - get => _currentVolume; - set - { - _currentVolume = value; - RaisePropertyChanged(); - } - } - - #endregion - - private bool _isStartRecording; - private bool _isRedSensor; - private readonly ISerialPortService _serialPortService; - private readonly IAudioService _audioService; - - private static readonly Lazy LazyWaveIn = new Lazy( - () => new WaveIn { WaveFormat = new WaveFormat(7500, 1) } - ); - - public AuditionViewModel(ISerialPortService serialPortService, IAudioService audioService, - IEventAggregator eventAggregator) - { - _serialPortService = serialPortService; - _audioService = audioService; - - GoBackCommand = new DelegateCommand(delegate - { - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - - CurrentVolume = GetCurrentMicVolume(); - - ListenRedSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = true; - ListenAudio(); - }); - - RedSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - ListenBlueSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = false; - ListenAudio(); - }); - BlueSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - //音频监听 - LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) - { - _isStartRecording = true; - - var buffer = args.Buffer; - - var sts = new float[buffer.Length / 2]; - var outIndex = 0; - for (var i = 0; i < buffer.Length; i += 2) - { - sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; - } - - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - eventAggregator.GetEvent().Publish(sts); - } - else - { - eventAggregator.GetEvent().Publish(sts); - } - }; - - LazyWaveIn.Value.RecordingStopped += delegate { _isStartRecording = false; }; - } - - /// - /// 听音指令 - /// - private void ListenAudio() - { - if (_isStartRecording) - { - CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); - _audioService.Stop(); - _isStartRecording = false; - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - //TODO 保存原始PCM数据到文件 - // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", - // FileMode.Append, FileAccess.Write)) - // { - // foreach (var cache in FlowStatus.RedSoundCaches) - // { - // fs.Write(cache, 0, cache.Length); - // } - // } - - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); - } - else - { - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); - } - - //波形图停止模拟 - // LazyWaveIn.Value.StopRecording(); - } - else - { - var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; - - CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - RuntimeCache.CurrentListenSoundDevCode = devCode; - _audioService.Start(devCode); - _isStartRecording = true; - - //波形图开始模拟 - // LazyWaveIn.Value.StartRecording(); - } - } - - #region 静音 - - //函数名不能改,否则会报找不到函数错误,dll里面定好了的 - [DllImport("user32.dll")] - private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); - - [DllImport("user32.dll")] - private static extern byte MapVirtualKey(uint uCode, uint uMapType); - - private void SetCurrentMicVolume() - { - if (_currentVolume > 0) - { - //静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = 0; - } - else - { - //非静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = GetCurrentMicVolume(); - } - } - - #endregion - - private int GetCurrentMicVolume() - { - var enumerator = new MMDeviceEnumerator(); - - //获取音频输入设备 - var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); - } - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - } - - public void OnDialogOpened(IDialogParameters parameters) - { - } - } -} \ No newline at end of file diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs deleted file mode 100644 index 7945aa7..0000000 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Correlator.DataService; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using NAudio.CoreAudioApi; -using NAudio.Wave; -using Prism.Commands; -using Prism.Events; -using Prism.Mvvm; -using Prism.Services.Dialogs; - -namespace Correlator.ViewModels -{ - public class AuditionViewModel : BindableBase, IDialogAware - { - #region DelegateCommand - - public DelegateCommand GoBackCommand { get; set; } - public DelegateCommand ListenRedSensorCommand { get; } - public DelegateCommand RedSensorMuteCommand { get; } - public DelegateCommand ListenBlueSensorCommand { get; } - public DelegateCommand BlueSensorMuteCommand { get; } - - #endregion - - #region VM - - public string Title { get; private set; } = string.Empty; - public event Action RequestClose; - private int _currentVolume; - - public int CurrentVolume - { - get => _currentVolume; - set - { - _currentVolume = value; - RaisePropertyChanged(); - } - } - - #endregion - - private bool _isStartRecording; - private bool _isRedSensor; - private readonly ISerialPortService _serialPortService; - private readonly IAudioService _audioService; - - private static readonly Lazy LazyWaveIn = new Lazy( - () => new WaveIn { WaveFormat = new WaveFormat(7500, 1) } - ); - - public AuditionViewModel(ISerialPortService serialPortService, IAudioService audioService, - IEventAggregator eventAggregator) - { - _serialPortService = serialPortService; - _audioService = audioService; - - GoBackCommand = new DelegateCommand(delegate - { - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - - CurrentVolume = GetCurrentMicVolume(); - - ListenRedSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = true; - ListenAudio(); - }); - - RedSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - ListenBlueSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = false; - ListenAudio(); - }); - BlueSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - //音频监听 - LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) - { - _isStartRecording = true; - - var buffer = args.Buffer; - - var sts = new float[buffer.Length / 2]; - var outIndex = 0; - for (var i = 0; i < buffer.Length; i += 2) - { - sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; - } - - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - eventAggregator.GetEvent().Publish(sts); - } - else - { - eventAggregator.GetEvent().Publish(sts); - } - }; - - LazyWaveIn.Value.RecordingStopped += delegate { _isStartRecording = false; }; - } - - /// - /// 听音指令 - /// - private void ListenAudio() - { - if (_isStartRecording) - { - CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); - _audioService.Stop(); - _isStartRecording = false; - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - //TODO 保存原始PCM数据到文件 - // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", - // FileMode.Append, FileAccess.Write)) - // { - // foreach (var cache in FlowStatus.RedSoundCaches) - // { - // fs.Write(cache, 0, cache.Length); - // } - // } - - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); - } - else - { - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); - } - - //波形图停止模拟 - // LazyWaveIn.Value.StopRecording(); - } - else - { - var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; - - CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - RuntimeCache.CurrentListenSoundDevCode = devCode; - _audioService.Start(devCode); - _isStartRecording = true; - - //波形图开始模拟 - // LazyWaveIn.Value.StartRecording(); - } - } - - #region 静音 - - //函数名不能改,否则会报找不到函数错误,dll里面定好了的 - [DllImport("user32.dll")] - private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); - - [DllImport("user32.dll")] - private static extern byte MapVirtualKey(uint uCode, uint uMapType); - - private void SetCurrentMicVolume() - { - if (_currentVolume > 0) - { - //静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = 0; - } - else - { - //非静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = GetCurrentMicVolume(); - } - } - - #endregion - - private int GetCurrentMicVolume() - { - var enumerator = new MMDeviceEnumerator(); - - //获取音频输入设备 - var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); - } - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - } - - public void OnDialogOpened(IDialogParameters parameters) - { - } - } -} \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 75ad8f3..7ff4fb6 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -815,7 +815,7 @@ return; } - //删除小于1K的音频 + //删除小于50K的音频 foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs deleted file mode 100644 index 7945aa7..0000000 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Correlator.DataService; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using NAudio.CoreAudioApi; -using NAudio.Wave; -using Prism.Commands; -using Prism.Events; -using Prism.Mvvm; -using Prism.Services.Dialogs; - -namespace Correlator.ViewModels -{ - public class AuditionViewModel : BindableBase, IDialogAware - { - #region DelegateCommand - - public DelegateCommand GoBackCommand { get; set; } - public DelegateCommand ListenRedSensorCommand { get; } - public DelegateCommand RedSensorMuteCommand { get; } - public DelegateCommand ListenBlueSensorCommand { get; } - public DelegateCommand BlueSensorMuteCommand { get; } - - #endregion - - #region VM - - public string Title { get; private set; } = string.Empty; - public event Action RequestClose; - private int _currentVolume; - - public int CurrentVolume - { - get => _currentVolume; - set - { - _currentVolume = value; - RaisePropertyChanged(); - } - } - - #endregion - - private bool _isStartRecording; - private bool _isRedSensor; - private readonly ISerialPortService _serialPortService; - private readonly IAudioService _audioService; - - private static readonly Lazy LazyWaveIn = new Lazy( - () => new WaveIn { WaveFormat = new WaveFormat(7500, 1) } - ); - - public AuditionViewModel(ISerialPortService serialPortService, IAudioService audioService, - IEventAggregator eventAggregator) - { - _serialPortService = serialPortService; - _audioService = audioService; - - GoBackCommand = new DelegateCommand(delegate - { - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - - CurrentVolume = GetCurrentMicVolume(); - - ListenRedSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = true; - ListenAudio(); - }); - - RedSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - ListenBlueSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = false; - ListenAudio(); - }); - BlueSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - //音频监听 - LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) - { - _isStartRecording = true; - - var buffer = args.Buffer; - - var sts = new float[buffer.Length / 2]; - var outIndex = 0; - for (var i = 0; i < buffer.Length; i += 2) - { - sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; - } - - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - eventAggregator.GetEvent().Publish(sts); - } - else - { - eventAggregator.GetEvent().Publish(sts); - } - }; - - LazyWaveIn.Value.RecordingStopped += delegate { _isStartRecording = false; }; - } - - /// - /// 听音指令 - /// - private void ListenAudio() - { - if (_isStartRecording) - { - CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); - _audioService.Stop(); - _isStartRecording = false; - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - //TODO 保存原始PCM数据到文件 - // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", - // FileMode.Append, FileAccess.Write)) - // { - // foreach (var cache in FlowStatus.RedSoundCaches) - // { - // fs.Write(cache, 0, cache.Length); - // } - // } - - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); - } - else - { - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); - } - - //波形图停止模拟 - // LazyWaveIn.Value.StopRecording(); - } - else - { - var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; - - CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - RuntimeCache.CurrentListenSoundDevCode = devCode; - _audioService.Start(devCode); - _isStartRecording = true; - - //波形图开始模拟 - // LazyWaveIn.Value.StartRecording(); - } - } - - #region 静音 - - //函数名不能改,否则会报找不到函数错误,dll里面定好了的 - [DllImport("user32.dll")] - private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); - - [DllImport("user32.dll")] - private static extern byte MapVirtualKey(uint uCode, uint uMapType); - - private void SetCurrentMicVolume() - { - if (_currentVolume > 0) - { - //静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = 0; - } - else - { - //非静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = GetCurrentMicVolume(); - } - } - - #endregion - - private int GetCurrentMicVolume() - { - var enumerator = new MMDeviceEnumerator(); - - //获取音频输入设备 - var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); - } - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - } - - public void OnDialogOpened(IDialogParameters parameters) - { - } - } -} \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 75ad8f3..7ff4fb6 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -815,7 +815,7 @@ return; } - //删除小于1K的音频 + //删除小于50K的音频 foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); diff --git a/Correlator/Views/AudioFileView.xaml.cs b/Correlator/Views/AudioFileView.xaml.cs index 69b5eff..76e7f1b 100644 --- a/Correlator/Views/AudioFileView.xaml.cs +++ b/Correlator/Views/AudioFileView.xaml.cs @@ -34,8 +34,7 @@ InitializeComponent(); _capture = new WasapiLoopbackCapture(); // 捕获电脑发出的声音 - _visualizer = new AudioVisualizer(512); - + _visualizer = dataService.GetAudioVisualizer(512); _allColors = dataService.GetAllHsvColors(); // 获取所有的渐变颜色 (HSV 颜色) _capture.WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(7500, 1); diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs deleted file mode 100644 index 7945aa7..0000000 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Correlator.DataService; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using NAudio.CoreAudioApi; -using NAudio.Wave; -using Prism.Commands; -using Prism.Events; -using Prism.Mvvm; -using Prism.Services.Dialogs; - -namespace Correlator.ViewModels -{ - public class AuditionViewModel : BindableBase, IDialogAware - { - #region DelegateCommand - - public DelegateCommand GoBackCommand { get; set; } - public DelegateCommand ListenRedSensorCommand { get; } - public DelegateCommand RedSensorMuteCommand { get; } - public DelegateCommand ListenBlueSensorCommand { get; } - public DelegateCommand BlueSensorMuteCommand { get; } - - #endregion - - #region VM - - public string Title { get; private set; } = string.Empty; - public event Action RequestClose; - private int _currentVolume; - - public int CurrentVolume - { - get => _currentVolume; - set - { - _currentVolume = value; - RaisePropertyChanged(); - } - } - - #endregion - - private bool _isStartRecording; - private bool _isRedSensor; - private readonly ISerialPortService _serialPortService; - private readonly IAudioService _audioService; - - private static readonly Lazy LazyWaveIn = new Lazy( - () => new WaveIn { WaveFormat = new WaveFormat(7500, 1) } - ); - - public AuditionViewModel(ISerialPortService serialPortService, IAudioService audioService, - IEventAggregator eventAggregator) - { - _serialPortService = serialPortService; - _audioService = audioService; - - GoBackCommand = new DelegateCommand(delegate - { - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - - CurrentVolume = GetCurrentMicVolume(); - - ListenRedSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = true; - ListenAudio(); - }); - - RedSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - ListenBlueSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = false; - ListenAudio(); - }); - BlueSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - //音频监听 - LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) - { - _isStartRecording = true; - - var buffer = args.Buffer; - - var sts = new float[buffer.Length / 2]; - var outIndex = 0; - for (var i = 0; i < buffer.Length; i += 2) - { - sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; - } - - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - eventAggregator.GetEvent().Publish(sts); - } - else - { - eventAggregator.GetEvent().Publish(sts); - } - }; - - LazyWaveIn.Value.RecordingStopped += delegate { _isStartRecording = false; }; - } - - /// - /// 听音指令 - /// - private void ListenAudio() - { - if (_isStartRecording) - { - CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); - _audioService.Stop(); - _isStartRecording = false; - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - //TODO 保存原始PCM数据到文件 - // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", - // FileMode.Append, FileAccess.Write)) - // { - // foreach (var cache in FlowStatus.RedSoundCaches) - // { - // fs.Write(cache, 0, cache.Length); - // } - // } - - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); - } - else - { - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); - } - - //波形图停止模拟 - // LazyWaveIn.Value.StopRecording(); - } - else - { - var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; - - CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - RuntimeCache.CurrentListenSoundDevCode = devCode; - _audioService.Start(devCode); - _isStartRecording = true; - - //波形图开始模拟 - // LazyWaveIn.Value.StartRecording(); - } - } - - #region 静音 - - //函数名不能改,否则会报找不到函数错误,dll里面定好了的 - [DllImport("user32.dll")] - private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); - - [DllImport("user32.dll")] - private static extern byte MapVirtualKey(uint uCode, uint uMapType); - - private void SetCurrentMicVolume() - { - if (_currentVolume > 0) - { - //静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = 0; - } - else - { - //非静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = GetCurrentMicVolume(); - } - } - - #endregion - - private int GetCurrentMicVolume() - { - var enumerator = new MMDeviceEnumerator(); - - //获取音频输入设备 - var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); - } - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - } - - public void OnDialogOpened(IDialogParameters parameters) - { - } - } -} \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 75ad8f3..7ff4fb6 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -815,7 +815,7 @@ return; } - //删除小于1K的音频 + //删除小于50K的音频 foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); diff --git a/Correlator/Views/AudioFileView.xaml.cs b/Correlator/Views/AudioFileView.xaml.cs index 69b5eff..76e7f1b 100644 --- a/Correlator/Views/AudioFileView.xaml.cs +++ b/Correlator/Views/AudioFileView.xaml.cs @@ -34,8 +34,7 @@ InitializeComponent(); _capture = new WasapiLoopbackCapture(); // 捕获电脑发出的声音 - _visualizer = new AudioVisualizer(512); - + _visualizer = dataService.GetAudioVisualizer(512); _allColors = dataService.GetAllHsvColors(); // 获取所有的渐变颜色 (HSV 颜色) _capture.WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(7500, 1); diff --git a/Correlator/Views/AuditionView.xaml b/Correlator/Views/AuditionView.xaml deleted file mode 100644 index 40447f8..0000000 --- a/Correlator/Views/AuditionView.xaml +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Correlator/App.xaml.cs b/Correlator/App.xaml.cs index da1aa71..9277341 100644 --- a/Correlator/App.xaml.cs +++ b/Correlator/App.xaml.cs @@ -50,7 +50,6 @@ containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); - containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); containerRegistry.RegisterDialog(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index f593d28..2f0ef52 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -278,7 +278,6 @@ - @@ -290,9 +289,6 @@ AudioFileView.xaml - - AuditionView.xaml - BigPictureView.xaml @@ -330,7 +326,6 @@ MSBuild:Compile - diff --git a/Correlator/DataService/ApplicationDataServiceImpl.cs b/Correlator/DataService/ApplicationDataServiceImpl.cs index 1b830bb..d3f9463 100644 --- a/Correlator/DataService/ApplicationDataServiceImpl.cs +++ b/Correlator/DataService/ApplicationDataServiceImpl.cs @@ -99,6 +99,11 @@ return 0; } } + + public AudioVisualizer GetAudioVisualizer(int waveDataSize) + { + return new AudioVisualizer(waveDataSize); + } public Color[] GetAllHsvColors() { diff --git a/Correlator/DataService/IApplicationDataService.cs b/Correlator/DataService/IApplicationDataService.cs index 0dc0b5a..c2c29a7 100644 --- a/Correlator/DataService/IApplicationDataService.cs +++ b/Correlator/DataService/IApplicationDataService.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.Windows.Media; using Correlator.Model; +using Correlator.Util; namespace Correlator.DataService { @@ -23,6 +24,8 @@ /// /// int GetSoundVelocity(string material, int pipeDiameter); + + AudioVisualizer GetAudioVisualizer(int waveDataSize); /// /// 获取 HSV 中所有的基础颜色 (饱和度和明度均为最大值) diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs deleted file mode 100644 index 7945aa7..0000000 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Correlator.DataService; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using NAudio.CoreAudioApi; -using NAudio.Wave; -using Prism.Commands; -using Prism.Events; -using Prism.Mvvm; -using Prism.Services.Dialogs; - -namespace Correlator.ViewModels -{ - public class AuditionViewModel : BindableBase, IDialogAware - { - #region DelegateCommand - - public DelegateCommand GoBackCommand { get; set; } - public DelegateCommand ListenRedSensorCommand { get; } - public DelegateCommand RedSensorMuteCommand { get; } - public DelegateCommand ListenBlueSensorCommand { get; } - public DelegateCommand BlueSensorMuteCommand { get; } - - #endregion - - #region VM - - public string Title { get; private set; } = string.Empty; - public event Action RequestClose; - private int _currentVolume; - - public int CurrentVolume - { - get => _currentVolume; - set - { - _currentVolume = value; - RaisePropertyChanged(); - } - } - - #endregion - - private bool _isStartRecording; - private bool _isRedSensor; - private readonly ISerialPortService _serialPortService; - private readonly IAudioService _audioService; - - private static readonly Lazy LazyWaveIn = new Lazy( - () => new WaveIn { WaveFormat = new WaveFormat(7500, 1) } - ); - - public AuditionViewModel(ISerialPortService serialPortService, IAudioService audioService, - IEventAggregator eventAggregator) - { - _serialPortService = serialPortService; - _audioService = audioService; - - GoBackCommand = new DelegateCommand(delegate - { - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - - CurrentVolume = GetCurrentMicVolume(); - - ListenRedSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = true; - ListenAudio(); - }); - - RedSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - ListenBlueSensorCommand = new DelegateCommand(delegate - { - _isRedSensor = false; - ListenAudio(); - }); - BlueSensorMuteCommand = new DelegateCommand(SetCurrentMicVolume); - - //音频监听 - LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) - { - _isStartRecording = true; - - var buffer = args.Buffer; - - var sts = new float[buffer.Length / 2]; - var outIndex = 0; - for (var i = 0; i < buffer.Length; i += 2) - { - sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; - } - - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - eventAggregator.GetEvent().Publish(sts); - } - else - { - eventAggregator.GetEvent().Publish(sts); - } - }; - - LazyWaveIn.Value.RecordingStopped += delegate { _isStartRecording = false; }; - } - - /// - /// 听音指令 - /// - private void ListenAudio() - { - if (_isStartRecording) - { - CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); - _audioService.Stop(); - _isStartRecording = false; - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - //TODO 保存原始PCM数据到文件 - // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", - // FileMode.Append, FileAccess.Write)) - // { - // foreach (var cache in FlowStatus.RedSoundCaches) - // { - // fs.Write(cache, 0, cache.Length); - // } - // } - - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); - } - else - { - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); - } - - //波形图停止模拟 - // LazyWaveIn.Value.StopRecording(); - } - else - { - var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; - - CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - RuntimeCache.CurrentListenSoundDevCode = devCode; - _audioService.Start(devCode); - _isStartRecording = true; - - //波形图开始模拟 - // LazyWaveIn.Value.StartRecording(); - } - } - - #region 静音 - - //函数名不能改,否则会报找不到函数错误,dll里面定好了的 - [DllImport("user32.dll")] - private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo); - - [DllImport("user32.dll")] - private static extern byte MapVirtualKey(uint uCode, uint uMapType); - - private void SetCurrentMicVolume() - { - if (_currentVolume > 0) - { - //静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = 0; - } - else - { - //非静音 - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); - keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - - CurrentVolume = GetCurrentMicVolume(); - } - } - - #endregion - - private int GetCurrentMicVolume() - { - var enumerator = new MMDeviceEnumerator(); - - //获取音频输入设备 - var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); - } - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - } - - public void OnDialogOpened(IDialogParameters parameters) - { - } - } -} \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 75ad8f3..7ff4fb6 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -815,7 +815,7 @@ return; } - //删除小于1K的音频 + //删除小于50K的音频 foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); diff --git a/Correlator/Views/AudioFileView.xaml.cs b/Correlator/Views/AudioFileView.xaml.cs index 69b5eff..76e7f1b 100644 --- a/Correlator/Views/AudioFileView.xaml.cs +++ b/Correlator/Views/AudioFileView.xaml.cs @@ -34,8 +34,7 @@ InitializeComponent(); _capture = new WasapiLoopbackCapture(); // 捕获电脑发出的声音 - _visualizer = new AudioVisualizer(512); - + _visualizer = dataService.GetAudioVisualizer(512); _allColors = dataService.GetAllHsvColors(); // 获取所有的渐变颜色 (HSV 颜色) _capture.WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(7500, 1); diff --git a/Correlator/Views/AuditionView.xaml b/Correlator/Views/AuditionView.xaml deleted file mode 100644 index 40447f8..0000000 --- a/Correlator/Views/AuditionView.xaml +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Correlator/Views/AuditionView.xaml.cs b/Correlator/Views/AuditionView.xaml.cs deleted file mode 100644 index 3f2a986..0000000 --- a/Correlator/Views/AuditionView.xaml.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.Collections.Generic; -using System.Drawing; -using System.Windows.Controls; -using Correlator.Events; -using Correlator.SensorHubTag; -using Correlator.Util; -using Prism.Events; - -namespace Correlator.Views -{ - public partial class AuditionView : UserControl - { - public AuditionView(IEventAggregator eventAggregator) - { - InitializeComponent(); - - var redSensorPlot = RedSensorScottPlotChart.Plot; - //去掉网格线 - redSensorPlot.Grid(false); - //去掉四周坐标轴 - redSensorPlot.Frameless(); - - var blueSensorPlot = BlueSensorScottPlotChart.Plot; - //去掉网格线 - blueSensorPlot.Grid(false); - //去掉四周坐标轴 - blueSensorPlot.Frameless(); - - eventAggregator.GetEvent().Subscribe(delegate(float[] floats) - { - //更新波形图Y轴 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RedSensorScottPlotChart.Plot.Clear(); - RedSensorScottPlotChart.Refresh(); - - var xDoubles = new List(); - var yDoubles = new List(); - - for (var i = 0; i < floats.Length; i++) - { - xDoubles.Add(i); - yDoubles.Add(floats[i]); - } - - RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen); - RedSensorScottPlotChart.Refresh(); - } - else - { - BlueSensorScottPlotChart.Plot.Clear(); - BlueSensorScottPlotChart.Refresh(); - - var xDoubles = new List(); - var yDoubles = new List(); - - for (var i = 0; i < floats.Length; i++) - { - xDoubles.Add(i); - yDoubles.Add(floats[i]); - } - - BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen); - BlueSensorScottPlotChart.Refresh(); - } - }); - } - } -} \ No newline at end of file