Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-window-function-to-mfcc-processor #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions core/src/main/java/be/tarsos/dsp/mfcc/MFCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import be.tarsos.dsp.AudioProcessor;
import be.tarsos.dsp.util.fft.FFT;
import be.tarsos.dsp.util.fft.HammingWindow;
import be.tarsos.dsp.util.fft.WindowFunction;


public class MFCC implements AudioProcessor {
Expand All @@ -46,18 +47,21 @@ public class MFCC implements AudioProcessor {
private FFT fft;
private int samplesPerFrame;
private float sampleRate;

public MFCC(int samplesPerFrame, int sampleRate){
this(samplesPerFrame, sampleRate, 30, 30, 133.3334f, ((float)sampleRate)/2f);
}
public MFCC(int samplesPerFrame, float sampleRate, int amountOfCepstrumCoef, int amountOfMelFilters, float lowerFilterFreq, float upperFilterFreq){
this(samplesPerFrame, sampleRate, amountOfCepstrumCoef, amountOfMelFilters, lowerFilterFreq, upperFilterFreq, new HammingWindow());
}

public MFCC(int samplesPerFrame, float sampleRate, int amountOfCepstrumCoef, int amountOfMelFilters, float lowerFilterFreq, float upperFilterFreq) {
public MFCC(int samplesPerFrame, float sampleRate, int amountOfCepstrumCoef, int amountOfMelFilters, float lowerFilterFreq, float upperFilterFreq, WindowFunction windowFunction) {
this.samplesPerFrame = samplesPerFrame;
this.sampleRate = sampleRate;
this.amountOfCepstrumCoef = amountOfCepstrumCoef;
this.amountOfMelFilters = amountOfMelFilters;
this.fft = new FFT(samplesPerFrame, new HammingWindow());
this.fft = new FFT(samplesPerFrame, windowFunction);

this.lowerFilterFreq = Math.max(lowerFilterFreq, 25);
this.upperFilterFreq = Math.min(upperFilterFreq, sampleRate / 2);
calculateFilterBanks();
Expand Down