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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm trying Tutorial chapter 9 about FFT. The example code suggestion is this:
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:
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:
However, the visualisation is again just a flat line.....
R.
Last edit: spamrefuse 2017-09-08
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hello,
I have experiment the same problems. Perhaps we need to join effort and fix the java code ourselves?
I'm not all that hot on how the audio bits work, however it's possible that the tutorial has just got out of sync with the actual API. For all the tutorial chapters there is code in the github repo which should mirror what the chapters do. Can you use this as a starting point: https://github.com/openimaj/openimaj/tree/master/documentation/tutorial/tutorial-code/src/main/java/org/openimaj/docs/tutorial/fund/audio
Great information Jonathan. Thanks for clarifying this.
@Jonathan that was it. The GIT source code works perflectly (at least for MFCC). The documentation is running behind. ;-)