diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 5d33683..67c2daf 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -232,6 +232,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 5d33683..67c2daf 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -232,6 +232,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Events/AudioSampleEvent.cs b/Correlator/Events/AudioSampleEvent.cs new file mode 100644 index 0000000..2309da1 --- /dev/null +++ b/Correlator/Events/AudioSampleEvent.cs @@ -0,0 +1,9 @@ +using Prism.Events; + +namespace Correlator.Events +{ + public class AudioSampleEvent : PubSubEvent + { + + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 5d33683..67c2daf 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -232,6 +232,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Events/AudioSampleEvent.cs b/Correlator/Events/AudioSampleEvent.cs new file mode 100644 index 0000000..2309da1 --- /dev/null +++ b/Correlator/Events/AudioSampleEvent.cs @@ -0,0 +1,9 @@ +using Prism.Events; + +namespace Correlator.Events +{ + public class AudioSampleEvent : PubSubEvent + { + + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index 97030b7..e8ea51b 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -4,12 +4,14 @@ using System.Linq; using System.Windows.Controls; using System.Windows.Threading; +using Correlator.Events; using Correlator.Model; using Correlator.Util; using HandyControl.Controls; using HandyControl.Data; using NAudio.Wave; using Prism.Commands; +using Prism.Events; using Prism.Mvvm; using Prism.Services.Dialogs; @@ -116,7 +118,7 @@ Interval = new TimeSpan(0, 0, 0, 1) }; - public AudioFileViewModel(IDialogService dialogService) + public AudioFileViewModel(IDialogService dialogService, IEventAggregator eventAggregator) { _audioTimer.Tick += delegate { @@ -132,6 +134,13 @@ } CurrentValue = _audioFileReader.CurrentTime.Seconds; + + var buffer = new float[1000]; + var samplesRead = _audioFileReader.Read(buffer, 0, buffer.Length); + var samples = buffer.Take(samplesRead).Select(x => (double)Math.Abs(x)); + var array = samples.ToArray(); + + eventAggregator.GetEvent().Publish(array); }; GoBackCommand = new DelegateCommand(delegate diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 5d33683..67c2daf 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -232,6 +232,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Events/AudioSampleEvent.cs b/Correlator/Events/AudioSampleEvent.cs new file mode 100644 index 0000000..2309da1 --- /dev/null +++ b/Correlator/Events/AudioSampleEvent.cs @@ -0,0 +1,9 @@ +using Prism.Events; + +namespace Correlator.Events +{ + public class AudioSampleEvent : PubSubEvent + { + + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index 97030b7..e8ea51b 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -4,12 +4,14 @@ using System.Linq; using System.Windows.Controls; using System.Windows.Threading; +using Correlator.Events; using Correlator.Model; using Correlator.Util; using HandyControl.Controls; using HandyControl.Data; using NAudio.Wave; using Prism.Commands; +using Prism.Events; using Prism.Mvvm; using Prism.Services.Dialogs; @@ -116,7 +118,7 @@ Interval = new TimeSpan(0, 0, 0, 1) }; - public AudioFileViewModel(IDialogService dialogService) + public AudioFileViewModel(IDialogService dialogService, IEventAggregator eventAggregator) { _audioTimer.Tick += delegate { @@ -132,6 +134,13 @@ } CurrentValue = _audioFileReader.CurrentTime.Seconds; + + var buffer = new float[1000]; + var samplesRead = _audioFileReader.Read(buffer, 0, buffer.Length); + var samples = buffer.Take(samplesRead).Select(x => (double)Math.Abs(x)); + var array = samples.ToArray(); + + eventAggregator.GetEvent().Publish(array); }; GoBackCommand = new DelegateCommand(delegate diff --git a/Correlator/Views/AudioFileView.xaml b/Correlator/Views/AudioFileView.xaml index 13e4529..996edc6 100644 --- a/Correlator/Views/AudioFileView.xaml +++ b/Correlator/Views/AudioFileView.xaml @@ -66,12 +66,11 @@ Text="File List" /> - + IsEnabled="False" /> SoundSpeedDialog.xaml + diff --git a/Correlator/Events/AudioSampleEvent.cs b/Correlator/Events/AudioSampleEvent.cs new file mode 100644 index 0000000..2309da1 --- /dev/null +++ b/Correlator/Events/AudioSampleEvent.cs @@ -0,0 +1,9 @@ +using Prism.Events; + +namespace Correlator.Events +{ + public class AudioSampleEvent : PubSubEvent + { + + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index 97030b7..e8ea51b 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -4,12 +4,14 @@ using System.Linq; using System.Windows.Controls; using System.Windows.Threading; +using Correlator.Events; using Correlator.Model; using Correlator.Util; using HandyControl.Controls; using HandyControl.Data; using NAudio.Wave; using Prism.Commands; +using Prism.Events; using Prism.Mvvm; using Prism.Services.Dialogs; @@ -116,7 +118,7 @@ Interval = new TimeSpan(0, 0, 0, 1) }; - public AudioFileViewModel(IDialogService dialogService) + public AudioFileViewModel(IDialogService dialogService, IEventAggregator eventAggregator) { _audioTimer.Tick += delegate { @@ -132,6 +134,13 @@ } CurrentValue = _audioFileReader.CurrentTime.Seconds; + + var buffer = new float[1000]; + var samplesRead = _audioFileReader.Read(buffer, 0, buffer.Length); + var samples = buffer.Take(samplesRead).Select(x => (double)Math.Abs(x)); + var array = samples.ToArray(); + + eventAggregator.GetEvent().Publish(array); }; GoBackCommand = new DelegateCommand(delegate diff --git a/Correlator/Views/AudioFileView.xaml b/Correlator/Views/AudioFileView.xaml index 13e4529..996edc6 100644 --- a/Correlator/Views/AudioFileView.xaml +++ b/Correlator/Views/AudioFileView.xaml @@ -66,12 +66,11 @@ Text="File List" /> - + IsEnabled="False" /> ().Subscribe(delegate(double[] doubles) + { + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate + { + if (doubles.Any()) + { + AudioWaveView.Plot.Clear(); + AudioWaveView.Plot.AddSignal(doubles, color: Color.FromArgb(255, 49, 151, 36)); + AudioWaveView.Refresh(); + } + })); + }); } } } \ No newline at end of file