Loading...
Logo
Processing Forum
Hello,
      I've patched together some of the minim examples to achieve what I thought would be real-time audio reactive animation. I have the "kick, snare, hat" example (beatListener) open that I've modified with the AudioRecord example so that instead of kick,snare, and hat responding to a playing .mp3 file, they respond to the live record stream on my PC.

My attempt at the most obvious solution comes up to swap the 'song' variables with the 'line in' values produces the error "Line 23: The constructor AudioResponse.BeatListener(BeatDetect, AudioInput) is undefined" - which I've come to determine is because AudioInput is the wrong kind of value to be passed to BeatListener. 

So my question is how would I go about achieving what I want? Can beatlistener not be used in a live recording stream way that I would like to? Will I need to do some type of value conversion?

Any and ALL feedback is always appreciated.
Thanks.
Copy code

  1. import ddf.minim.*;
  2. import ddf.minim.analysis.*;

  3. Minim minim;

  4. BeatDetect beat;
  5. BeatListener bl;
  6. AudioInput in;
  7. float kickSize, snareSize, hatSize;

  8. void setup()
  9. {
  10.   size(512, 200, P3D);
  11.   
  12.   minim = new Minim(this);
  13.   in = minim.getLineIn(Minim.STEREO, 2048);
  14.   beat = new BeatDetect(in.bufferSize(), in.sampleRate());
  15.  
  16.   beat.setSensitivity(300);  
  17.   kickSize = snareSize = hatSize = 16;
  18.   bl = new BeatListener(beat, in);  
  19.   
  20.   textFont(createFont("Helvetica", 16));
  21.   textAlign(CENTER);
  22. }

  23. void draw()
  24. {
  25.   background(0);
  26.   fill(255);
  27.   if ( beat.isKick() ) kickSize = 32;
  28.   if ( beat.isSnare() ) snareSize = 32;
  29.   if ( beat.isHat() ) hatSize = 32;
  30.   textSize(kickSize);
  31.   text("KICK", width/4, height/2);
  32.   textSize(snareSize);
  33.   text("SNARE", width/2, height/2);
  34.   textSize(hatSize);
  35.   text("HAT", 3*width/4, height/2);
  36.   kickSize = constrain(kickSize * 0.95, 16, 32);
  37.   snareSize = constrain(snareSize * 0.95, 16, 32);
  38.   hatSize = constrain(hatSize * 0.95, 16, 32);
  39. }

  40. void stop()
  41. {
  42.   // always close Minim audio classes when you are finished with them
  43.   song.close();
  44.   // always stop Minim before exiting
  45.   minim.stop();
  46.   // this closes the sketch
  47.   super.stop();
  48. }

Replies(5)

Can you show the BeatDetect class ?
Ummm... Hmm. I'm having difficulty finding it at the moment...

The examples came from the modes\java\libraries\minim\examples\BeatDetect\FrequencyEnergy\ BeatListener directory.

They all execture perfectly normal as long as I don't modify anything, so i assume the BeatDetect class exist somewhere, but I cannot find it. I ran a search and come across BeatDetect.java, but it opened with a different IDE so I'm thinking is not the one being referenced for this code.
Right... and there are two tabs in that file. Frequency Energy and BeatListener. 

BeatListener is it's own class. You have to include it with any modified examples you make. 
It looks like this: 

Copy code
  1. class BeatListener implements AudioListener
  2. {
  3.   private BeatDetect beat;
  4.   private AudioPlayer source;
  5.   
  6.   BeatListener(BeatDetect beat, AudioPlayer source)
  7.   {
  8.     this.source = source;
  9.     this.source.addListener(this);
  10.     this.beat = beat;
  11.   }
  12.   
  13.   void samples(float[] samps)
  14.   {
  15.     beat.detect(source.mix);
  16.   }
  17.   
  18.   void samples(float[] sampsL, float[] sampsR)
  19.   {
  20.     beat.detect(source.mix);
  21.   }
  22. }
The one other thing you have to do is change it to accept a LineIn instead of a AudioPlayer... 
Correct. That is my main question. 

How do I change it to accept a LineIn instead of AudioPlayer?
Change the Declaration and the Argument in the Constructor... ie. 

Copy code
  1.   private BeatDetect beat;
  2.   private AudioPlayer source;
  3.   
  4.   BeatListener(BeatDetect beat, AudioPlayer source)
  5. ... 
becomes

Copy code
  1.   private BeatDetect beat;
  2.   private AudioInput source;
  3.   
  4.   BeatListener(BeatDetect beat, AudioInput source)
  5. ...