simultaneous drawing and FFT with Minim in Java
in
Core Library Questions
•
2 years ago
Hello,
I'm a Belgian engineering student currently in the proces of writing an java application that transforms the line input of a soundcard into an osciloscope. For everything input related i'm using Processing and Minim as a component in the application.
I've got the drawing of the signal working, but i'm currently experiencing problems with determining the frequency of the input signal (i'm using an ipod with a 1k Hz MP3 file on it).
I've tried two seperate things:
I've tried to use timers to determine the period of the signal, but this returns rubbish values which start large and slowly converge to zero. I suppose this is due to noise.
- public void draw()
- {
- background(255);
- stroke(0);
- line(0,300,800,300);
- // draws waveform and calculates the period in real time by measuring the time it takes to complete one cycle in milliseconds
- for(int i = 0; i < in.bufferSize() - 1; i++)
- {
- line(i, 300 + in.left.get(i)*200, i+1, 300 + in.left.get(i+1)*200);
- //period calculation
- if (in.left.get(i) * in.left.get(i+1) <= 0 && firstRoot == false ) //tests whether the first root has been passed
- {
- beginTime = System.nanoTime(); //stores the time the first root has been passed
- firstRoot = true; // first root has been passed
- }
- else if (in.left.get(i) * in.left.get(i+1) <= 0 && secondRoot == false) // tests whether the second root has been passed
- {
- secondRoot = true; //second root has been passed
- }
- else if (in.left.get(i) * in.left.get(i+1) <=0 && secondRoot == true) // tests whether the third root has been passed
- {
- nanoperiod = System.nanoTime() - beginTime; //determines the time it took to complete the cycle
- System.out.println(nanoperiod/1000000000.0); //convert to second and print to Console #DEBUG
- secondRoot = false; // reset the second root
- beginTime = System.currentTimeMillis(); //reset begintime
- }
- }
- }
Thanks in advance,
Frank Vanbever
1