diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Events/RenderAudioOscillogramEvent.cs b/Correlator/Events/RenderAudioOscillogramEvent.cs deleted file mode 100644 index 3768112..0000000 --- a/Correlator/Events/RenderAudioOscillogramEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Events; - -namespace Correlator.Events -{ - public class RenderAudioOscillogramEvent : PubSubEvent - { - } -} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Events/RenderAudioOscillogramEvent.cs b/Correlator/Events/RenderAudioOscillogramEvent.cs deleted file mode 100644 index 3768112..0000000 --- a/Correlator/Events/RenderAudioOscillogramEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Events; - -namespace Correlator.Events -{ - public class RenderAudioOscillogramEvent : PubSubEvent - { - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index fbeaae6..b7694e4 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -546,6 +546,9 @@ configModel.Pipe++; configModel.LocateTimes++; manager.Insert(configModel); + + //清空缓存 + RuntimeCache.SoundCaches.Clear(); } } diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Events/RenderAudioOscillogramEvent.cs b/Correlator/Events/RenderAudioOscillogramEvent.cs deleted file mode 100644 index 3768112..0000000 --- a/Correlator/Events/RenderAudioOscillogramEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Events; - -namespace Correlator.Events -{ - public class RenderAudioOscillogramEvent : PubSubEvent - { - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index fbeaae6..b7694e4 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -546,6 +546,9 @@ configModel.Pipe++; configModel.LocateTimes++; manager.Insert(configModel); + + //清空缓存 + RuntimeCache.SoundCaches.Clear(); } } diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index a5197d0..468ca7f 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -70,15 +70,9 @@ public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); + public static readonly List SoundCaches = new List(); /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// /// 小于1K的音频文件全路径集合 /// public static readonly List SmallAudioFiles = new List(); @@ -87,5 +81,10 @@ /// 列表每页条目数 /// public const int PerPageItemCount = 10; + + /// + /// 采样率 + /// + public const int AudioSampleRate = 7500; } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Events/RenderAudioOscillogramEvent.cs b/Correlator/Events/RenderAudioOscillogramEvent.cs deleted file mode 100644 index 3768112..0000000 --- a/Correlator/Events/RenderAudioOscillogramEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Events; - -namespace Correlator.Events -{ - public class RenderAudioOscillogramEvent : PubSubEvent - { - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index fbeaae6..b7694e4 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -546,6 +546,9 @@ configModel.Pipe++; configModel.LocateTimes++; manager.Insert(configModel); + + //清空缓存 + RuntimeCache.SoundCaches.Clear(); } } diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index a5197d0..468ca7f 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -70,15 +70,9 @@ public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); + public static readonly List SoundCaches = new List(); /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// /// 小于1K的音频文件全路径集合 /// public static readonly List SmallAudioFiles = new List(); @@ -87,5 +81,10 @@ /// 列表每页条目数 /// public const int PerPageItemCount = 10; + + /// + /// 采样率 + /// + public const int AudioSampleRate = 7500; } } \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 7ff4fb6..91e77ea 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -588,7 +588,6 @@ } //计算 - //异步计算数据 new Thread(CalculateData).Start(); } @@ -601,9 +600,10 @@ if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); - var array = LazyCorrelator.Value.locating(11, + var array = LazyCorrelator.Value.locating( + 11, (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, - 7500, + RuntimeCache.AudioSampleRate, int.Parse(_pipeLength), int.Parse(_soundSpeed), 0, 0, 0, 0, @@ -611,7 +611,8 @@ int.Parse(_pipeDiameter), int.Parse(_pipeDiameter), 1, -1, -1, -1, - int.Parse(_lowFrequency), int.Parse(_highFrequency)); + int.Parse(_lowFrequency), int.Parse(_highFrequency) + ); Console.WriteLine(@"MainWindowViewModel => 计算结束"); //数据绑定 @@ -656,10 +657,6 @@ DialogHub.Get.DismissLoadingDialog(); } - else - { - Console.WriteLine(@"MainWindowViewModel => CorrelatorDataModel数据未收集完整"); - } } /// diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2f0ef52..b4a4553 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -239,7 +239,6 @@ - diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index f25f7c5..7bc889d 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -272,20 +272,20 @@ } //保存听音数据 - if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) - { - RuntimeCache.RedSoundCaches.Add(pcm); - } - else - { - RuntimeCache.BlueSoundCaches.Add(pcm); - } + RuntimeCache.SoundCaches.Add(pcm); //将pcm数据写入缓存 _audioService.Write(pcm); - //TODO 波形图数据,暂时无法实现,先用NAudio获取到的声音代替 - // _eventAggregator.GetEvent().Publish(sts); + //波形图数据 + var length = pcm.Length / 4; + var spectrumData = new double[length]; + for (var i = 0; i < length; i++) + { + spectrumData[i] = BitConverter.ToSingle(pcm, i * 4); + } + + _audioService.AudioVisualizer.PushSampleData(spectrumData); } } diff --git a/Correlator/Events/RenderAudioOscillogramEvent.cs b/Correlator/Events/RenderAudioOscillogramEvent.cs deleted file mode 100644 index 3768112..0000000 --- a/Correlator/Events/RenderAudioOscillogramEvent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Prism.Events; - -namespace Correlator.Events -{ - public class RenderAudioOscillogramEvent : PubSubEvent - { - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index fbeaae6..b7694e4 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -546,6 +546,9 @@ configModel.Pipe++; configModel.LocateTimes++; manager.Insert(configModel); + + //清空缓存 + RuntimeCache.SoundCaches.Clear(); } } diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index a5197d0..468ca7f 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -70,15 +70,9 @@ public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); + public static readonly List SoundCaches = new List(); /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// /// 小于1K的音频文件全路径集合 /// public static readonly List SmallAudioFiles = new List(); @@ -87,5 +81,10 @@ /// 列表每页条目数 /// public const int PerPageItemCount = 10; + + /// + /// 采样率 + /// + public const int AudioSampleRate = 7500; } } \ No newline at end of file diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 7ff4fb6..91e77ea 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -588,7 +588,6 @@ } //计算 - //异步计算数据 new Thread(CalculateData).Start(); } @@ -601,9 +600,10 @@ if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); - var array = LazyCorrelator.Value.locating(11, + var array = LazyCorrelator.Value.locating( + 11, (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, - 7500, + RuntimeCache.AudioSampleRate, int.Parse(_pipeLength), int.Parse(_soundSpeed), 0, 0, 0, 0, @@ -611,7 +611,8 @@ int.Parse(_pipeDiameter), int.Parse(_pipeDiameter), 1, -1, -1, -1, - int.Parse(_lowFrequency), int.Parse(_highFrequency)); + int.Parse(_lowFrequency), int.Parse(_highFrequency) + ); Console.WriteLine(@"MainWindowViewModel => 计算结束"); //数据绑定 @@ -656,10 +657,6 @@ DialogHub.Get.DismissLoadingDialog(); } - else - { - Console.WriteLine(@"MainWindowViewModel => CorrelatorDataModel数据未收集完整"); - } } /// diff --git a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs index e90be84..d1f6f4c 100644 --- a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs +++ b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs @@ -195,8 +195,7 @@ CommandSender.SendSoundStopCmd(serialPortService.Sp, DevCode.Dev1); audioService.Stop(); IsRedRecording = false; - RuntimeCache.RedSoundCaches.SaveSoundData(); - RuntimeCache.RedSoundCaches.Clear(); + RuntimeCache.SoundCaches.SaveSoundData(); } /// @@ -209,8 +208,7 @@ CommandSender.SendSoundStopCmd(serialPortService.Sp, DevCode.Dev2); audioService.Stop(); IsBlueRecording = false; - RuntimeCache.BlueSoundCaches.SaveSoundData(); - RuntimeCache.BlueSoundCaches.Clear(); + RuntimeCache.SoundCaches.SaveSoundData(); } public bool CanCloseDialog()