public void DetectOnsets(float sensitivity = 1.5f) { onsetDetection = new OnsetDetection(PCMStream, SAMPLE_SIZE); // Has finished reading in the audio file bool finished = false; // Set the pcm data back to the beginning SetTrackPosition(0); do { // Read in audio data and find the flux values until end of audio file finished = onsetDetection.AddFlux(ReadMonoPCM()); }while (!finished); // Find peaks onsetDetection.FindOnsets(sensitivity); }
public void Analyze() { amplitudeDetection = new AmplitudeDetection(); onsetDetection = new OnsetDetection(sampleRate, sampleSize, timePerSample); heldNoteDetection = new HeldNoteDetection(); pcmStream.Position = 0; int nSample = 0; do { float[] samples = ReadMonoPCM(); if (samples == null) { break; } float time = nSample * timePerSample; fft.RealFFT(samples, true); float[] fftSpectrum = fft.GetPowerSpectrum(); amplitudeDetection.AnalyzeSpectrum(fftSpectrum, time); heldNoteDetection.AnalyzeSpectrum(fftSpectrum, time); onsetDetection.AddFlux(fftSpectrum); nSample++; }while (true); amplitudeDetection.AbsAndNormalize(); // Find peaks onsetDetection.FindOnsets(1.5f); onsetDetection.NormalizeOnsets(); AddOnsets(SongElements); heldNoteDetection.AddHeldNotes(SongElements); }