Loading...
Logo
Processing Forum
Hey folks, im trying to throw together a quick and dirty little FFT processing patch, that does an FFT on the audio currently being played (so not any loaded mp3 file, we are using another player for that). Im planning on using numbers from this FFT to drive 15 strips of RGB LEDS that I have connected to an Arduino. So basically:

*Listen to system audio
*perform FFT
*send numbers to Arduino

However Im having problems. I hacked the FFT example patch, but nothing is seemingly going on. I try doing an FFT to the current signal(out), and then use the drawing example to visualize it, so I can confirm it is actually working.

Here is my code so far: 
 
Copy code
  1. import ddf.minim.analysis.*;
  2. import ddf.minim.*;
  3. import ddf.minim.signals.*;
  4.  
  5. Minim minim;
  6. AudioPlayer jingle;
  7. AudioOutput out;
  8. AudioInput input;
  9. FFT fft;
  10. String windowName;
  11.  
  12. void setup()
  13. {
  14.   size(512, 200, P3D);
  15.   textMode(SCREEN);
  16.  
  17.   minim = new Minim(this);
  18.   out = minim.getLineOut(Minim.STEREO, 2048);
  19.   // create an FFT object that has a time-domain buffer 
  20.   // the same size as jingle's sample buffer
  21.   // note that this needs to be a power of two 
  22.   // and that it means the size of the spectrum
  23.   // will be 512. see the online tutorial for more info.
  24.   fft = new FFT(out.bufferSize(), out.sampleRate());
  25.  
  26. }
  27.  
  28. void draw()
  29. {
  30.   background(0);
  31.   stroke(255);
  32.   // perform a forward FFT on the samples in jingle's left buffer
  33.   // note that if jingle were a MONO file, 
  34.   // this would be the same as using jingle.right or jingle.left
  35.   fft.forward(out.mix);
  36.   for(int i = 0; i < fft.specSize(); i++)
  37.   {
  38.     // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
  39.     line(i, height, i, height - fft.getBand(i)*10);
  40.   }
  41.   fill(128);
  42. }
  43.  
  44. void stop()
  45. {
  46.   // always close Minim audio classes when you finish with them
  47.   out.close();
  48.   minim.stop();
  49.  
  50.   super.stop();
  51. }
However nothing is drawn in my sketch window when I run it(with a song playing in Foobar in the background). I also get the following message from minim:
=== Minim Error ===
=== Likely buffer underrun in AudioOutput.

This, however should always happen on launch. It should only be an issue if the error is spammed in the output window.

Any help here?


Replies(4)

sorry maybe im misunderstanding what you want to do... so foobar is playing something and you want to route it to your processing sketch, right? then your processing sketch analyze it... so...its input at the processing sketch, right?

adding this line at setup():

input = minim.getLineIn(Minim.STEREO, 2048);

and changing this:

 fft = new FFT(input.bufferSize(), input.sampleRate());

and this at draw():
fft.forward(input.mix);

well...using input and not output... so .... now, depending on you OS, you should  route your "media player" signal, for example using Jack in linux, Soundflowerbed in macOS, not sure how to do it in Windows...
not sure if im being clear , do you understand what i mean?
i think you are trying "to catch the sound output of your computer" (in this case a media player) but you need to route it first, with any audio routing software
hope this helps
Well yes you understand what im trying to do here perfectly. Basically have Winamp or Foobar or something play music, and have processing perform an FFT on that audio signal.

However, using  input = minim.getLineIn(Minim.STEREO, 2048); results in the FFT being done on my MICROPHONE signal, as in the signal coming in to the computer, which is not what I am wanting to do. I want the signal being output by the computer to route into my processing sketch. I would hate to have to feed the signal into the computer once again using speakers and the microphone.

As far as I can see in the JavaDocs  minim.getLineOut(Minim.STEREO, 2048); is what I should be using....no?
ok :O)

so i think it is still INPUT in the processing sketch,

in windows:
  1. Select your sound properties through the control panel or the sound icon in your system tray.
  2. Click on the properties tab.
  3. Check the recording box.
  4. Make sure Wave Out Mix is selected (It’s sometimes called stereo mix, or mono mix).
so now not the microphone is being routed to your processing sketch....all your "systemsound" is being routed

for linux or macos you can use jack or soundflowerbed or things like that
hope this helps!

You are completely right my friend! I didnt catch that the first time around. Thank you very much =)

Now onto extracting bin amplitudes and sending some representation of those to an Arduino board. Thanks a bunch