public MainViewModel() { _audioService = new AudioService(); MeasureCommand = new Command(async() => { IsLoading = true; Path = await _audioService.RecordSample(TimeSpan.FromSeconds(10)); var wav = new WavService(_path); var movAvgData = wav.Data.Where((x, i) => i % 48 == 0).Select(x => (double)x).ToArray(); var peaksMovAvgData = movAvgData.FindPeaks(); // debug: Metadata = $"{nameof(peaksMovAvgData)}: {peaksMovAvgData.Length}"; const double treshold = 6450.0; var beats = peaksMovAvgData.Where(p => movAvgData[p] > treshold).ToArray(); Metadata = $"BPM: {beats.Length * 3}"; // since 2 beats mean one heart beat & there are 6 10sec periods in one minute DataCalculated?.Invoke(movAvgData); IsLoading = false; }); }
protected void RaiseDataCalculated(IEnumerable <Parameter> parameters) { DataCalculated?.Invoke(this, parameters); }