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; }); }
public Wav ReadFile(string path) { if (File.Exists(path)) { var file = File.ReadAllBytes(path); var formatData = new WavService().ReturnFormatData(file); return(formatData); } return(null); }
public void SetUp() { Wav = new WavService(); }