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(); }
private void GenerateSpectrogramImage() { if (MySpectrogramHandler == null) { return; } spectrogramImage = new Bitmap(MySpectrogramHandler.Spectrogram.Frames.Count, MySpectrogramHandler.Spectrogram.FrequencyBins); projectionRect = new RectangleF(0, 0, spectrogramImage.Width, spectrogramImage.Height); binsPerPixel = (float)spectrogramImage.Height / this.Height; framesPerPixel = (float)spectrogramImage.Width / this.Width; byte pixelVal; for (int i = 0; i < MySpectrogramHandler.Spectrogram.Frames.Count; i++) { SpectrogramFrame frame = MySpectrogramHandler.Spectrogram.Frames[i]; for (int j = 0; j < MySpectrogramHandler.Spectrogram.FrequencyBins; j++) { pixelVal = frame.SpectrumData[j]; spectrogramImage.SetPixel(i, MySpectrogramHandler.Spectrogram.FrequencyBins - 1 - j, Color.FromArgb(pixelVal, pixelVal, pixelVal)); } } }