Example usage for com.badlogic.gdx.audio.analysis FFT FFT

List of usage examples for com.badlogic.gdx.audio.analysis FFT FFT

Introduction

In this page you can find the example usage for com.badlogic.gdx.audio.analysis FFT FFT.

Prototype

public FFT(int timeSize, float sampleRate) 

Source Link

Document

Constructs an FFT that will accept sample buffers that are timeSize long and have been recorded with a sample rate of sampleRate.

Usage

From source file:com.kvw.oscdroid.channels.AnalogChannel.java

License:Open Source License

/**
 * Perform FFT, determine largest frequency component and set as frequency
 *///from www.j av  a2  s.  c o  m
private void calcFreq() {
    float fIndex = -1;
    float maxMag = -1;
    float[] mags;

    float[] fft_array = new float[NUM_SAMPLES];

    FFT fft = new FFT(NUM_SAMPLES, mSampleRates[chTimeDiv]);

    for (int i = 0; i < NUM_SAMPLES; i++)
        fft_array[i] = (float) mDataSet[i];

    fft.forward(fft_array);
    mags = fft.getSpectrum();

    for (int i = 1; i < mags.length; i++) {
        if (mags[i] > maxMag) {
            maxMag = mags[i];
            fIndex = i;
        }
    }

    //Somehow the calculated frequency differs a factor 2. Compensate by dividing by 2
    chFrequency = (float) mSampleRates[chTimeDiv] * fIndex / mags.length / 2;

    //      Log.d(TAG,"Mag: " + maxMag + " Index: " + fIndex + " Freq: " + chFrequency + " SR: " + mSampleRates[chTimeDiv]);

    fft = null;
    fft_array = null;
    mags = null;
}