Menu

Tutorial 9: FFT?

spamrefuse
2017-09-08
2018-01-18
  • spamrefuse

    spamrefuse - 2017-09-08

    Hi,

    I'm trying Tutorial chapter 9 about FFT. The example code suggestion is this:

    final AudioWaveform vis = new AudioWaveform( 400, 400 );
    vis.showWindow( "Waveform" );
    final XuggleAudio xa = new XuggleAudio( 
        new URL( "http://www.audiocheck.net/download.php?" +
            "filename=Audio/audiocheck.net_sweep20-20klin.wav" ) );
    
    FourierTransform fft = new FourierTransform( xa );
    SampleChunk sc;
    while( (sc = fft.nextSampleChunk()) != null )
    {
        float[][] fftData = fft.getMagnitudes();
        vis.setData( fftData[0] );
    }
    

    This does not work, as my java in eclipse complains that setData requires doubles, not floats.
    Also, the SampleChunk sc seems to have no purpose in the while loop.
    So I tried to fix it:

    FourierTransform fft = new FourierTransform( xa );
    while( fft.nextSampleChunk() != null )
    {
        float[][] fftData = fft.getMagnitudes();
        int size = fftData[0].length;
        double[] input = new double[size];
        for (int i = 0; i < size; ++i) input[i] = fftData[0][i];
        vis.setData( input );
    }
    

    The visualisation window just has a flat line (say: f(x) = 0 kind of line). The peak is not there!

    But now I wonder whether "SampleChunk sc" should be used inside the while loop in order to visualise the FFT of the "next chunk"..... Anyway, I suspect something is wrong with this example, but I can't see what....


    In Tutorial chapter 10 "getLastGeneratedFeature()" method does not seem to exist; should that be "getLastCalculatedFeature()"? Also "setAxisLocation( 100 )" suggested in the tip does not exist....

    Anyway, I modified the code into this:

    MFCC mfcc = new MFCC( xa );
    SampleChunk sc;
    while ( (sc = xa.nextSampleChunk()) != null ) {
       double[][] mfccs = mfcc.calculateMFCC(sc.getSampleBuffer());
       vis.setData(mfcss[0]);
    }
    

    However, the visualisation is again just a flat line.....

    R.

     

    Last edit: spamrefuse 2017-09-08
  • Anonymous

    Anonymous - 2018-01-18

    Hello,
    I have experiment the same problems. Perhaps we need to join effort and fix the java code ourselves?

     
  • Erick Audet

    Erick Audet - 2018-01-18

    Great information Jonathan. Thanks for clarifying this.

     
  • Erick Audet

    Erick Audet - 2018-01-18

    @Jonathan that was it. The GIT source code works perflectly (at least for MFCC). The documentation is running behind. ;-)

     

Anonymous
Anonymous

Add attachments
Cancel