public class SpectralPeakProcessor extends java.lang.Object implements AudioProcessor
This class implements a spectral peak follower as described in Sethares et al. 2009 - Spectral Tools for Dynamic Tonality and Audio Morphing - section "Analysis-Resynthessis". It calculates a noise floor and picks spectral peaks rising above a calculated noise floor with a certain factor. The noise floor is determined using a simple median filter.
Parts of the code is modified from the code accompanying "Spectral Tools for Dynamic Tonality and Audio Morphing".
To get the spectral peaks from an audio frame, call getPeakList
AudioDispatcher dispatcher = new AudioDispatcher(stream, fftsize, overlap);
dispatcher.addAudioProcessor(spectralPeakFollower);
dispatcher.addAudioProcessor(new AudioProcessor() {
public void processingFinished() {
}
public boolean process(AudioEvent audioEvent) {
float[] noiseFloor = SpectralPeakProcessor.calculateNoiseFloor(spectralPeakFollower.getMagnitudes(), medianFilterLength, noiseFloorFactor);
List
Modifier and Type | Class and Description |
---|---|
static class |
SpectralPeakProcessor.SpectralPeak |
Constructor and Description |
---|
SpectralPeakProcessor(int bufferSize,
int overlap,
int sampleRate) |
Modifier and Type | Method and Description |
---|---|
static float[] |
calculateNoiseFloor(float[] magnitudes,
int medianFilterLength,
float noiseFloorFactor)
Calculate a noise floor for an array of magnitudes.
|
static java.util.List<java.lang.Integer> |
findLocalMaxima(float[] magnitudes,
float[] noisefloor)
Finds the local magintude maxima and stores them in the given list.
|
static java.util.List<SpectralPeakProcessor.SpectralPeak> |
findPeaks(float[] magnitudes,
float[] frequencyEstimates,
java.util.List<java.lang.Integer> localMaximaIndexes,
int numberOfPeaks,
int minDistanceInCents) |
float[] |
getFrequencyEstimates() |
float[] |
getMagnitudes() |
static float |
median(double[] arr) |
static double |
median(float[] m) |
static float |
percentile(double[] arr,
double p)
Returns the p-th percentile of values in an array.
|
boolean |
process(AudioEvent audioEvent)
Process the audio event.
|
void |
processingFinished()
Notify the AudioProcessor that no more data is available and processing
has finished.
|
public SpectralPeakProcessor(int bufferSize, int overlap, int sampleRate)
public boolean process(AudioEvent audioEvent)
AudioProcessor
process
in interface AudioProcessor
audioEvent
- The audio event that contains audio data.public void processingFinished()
AudioProcessor
processingFinished
in interface AudioProcessor
public float[] getMagnitudes()
public float[] getFrequencyEstimates()
public static float[] calculateNoiseFloor(float[] magnitudes, int medianFilterLength, float noiseFloorFactor)
magnitudes
- The magnitudes of the current frame.medianFilterLength
- The length of the median filter used to determine the noise floor.noiseFloorFactor
- The noise floor is multiplied with this factor to determine if the
information is either noise or an interesting spectral peak.public static java.util.List<java.lang.Integer> findLocalMaxima(float[] magnitudes, float[] noisefloor)
magnitudes
- The magnitudes.noisefloor
- The noise floor.public static java.util.List<SpectralPeakProcessor.SpectralPeak> findPeaks(float[] magnitudes, float[] frequencyEstimates, java.util.List<java.lang.Integer> localMaximaIndexes, int numberOfPeaks, int minDistanceInCents)
magnitudes
- the magnitudes..frequencyEstimates
- The frequency estimates for each bin.localMaximaIndexes
- The indexes of the local maxima.numberOfPeaks
- The requested number of peaks.minDistanceInCents
- The minimum distance in cents between the peakspublic static final float median(double[] arr)
public static final float percentile(double[] arr, double p)
arr
- An array of sample data values that define relative standing.
The contents of the input array are sorted by this method.p
- The percentile value in the range 0..1, inclusive.public static double median(float[] m)