public void ReadSpectrogramFrame() { double curAudioPos = app.AudioSource.AudioStream.CurrentTime.TotalMilliseconds; SpectrogramFrame curFrame = SpectrogramHandler.Spectrogram.Frames.Aggregate((x, y) => Math.Abs(x.Timestamp - curAudioPos) < Math.Abs(y.Timestamp - curAudioPos) ? x : y); // Gets the frame with a timestamp closest to curAudioPos // Converts byte valued spectrogram data to double valued spectrum data double[] doubleData = new double[curFrame.SpectrumData.Length]; for (int i = 0; i < doubleData.Length; i++) { doubleData[i] = curFrame.SpectrumData[i]; } spectrumData = doubleData; foreach (Note note in curFrame.Notes) { Analyser.BufferNote(note.NoteIndex); Analyser.GetMusic().CountNote(note.Name + "0"); } // Directly assigns analyser properties from current spectrogram frame Analyser.Notes = curFrame.Notes.ToList(); Analyser.Chords = curFrame.Chords.ToList(); Analyser.CurrentKey = curFrame.KeySignature; Analyser.CalculateNotePercentages(); FrequencyAnalysisToSpectrum(SpectrogramHandler.Spectrogram.FrequencyScale); curFrame = null; doubleData = null; spectrumData = null; GC.Collect(); }