Loading...
Logo
Processing Forum

beads filter

in Contributed Library Questions  •  1 year ago  
have been using Beads 1 pole filter :

 filter1.setFrequency(1000.0);

is there a way to select  between 2 frequencies, so that i could boost/cut 500-1000?

Replies(2)

Re: beads filter

1 year ago
Perhaps you could chain two BiQuad filters, one set to LP and one set to HP?  See java docs for BiQuad.setType.  A single BiQuad set to Notch might also work.

Re: beads filter

1 year ago
any tips on how i would modify this code to add a gain argument to the biquad filter? I've looked at the documentation, but cant see any gain in the listed biquad constructor summary..would appreciate some help in implementing it into an example.

Copy code
  1. // Filter_03.pde

  2. // in this example, we apply a band-pass filter to a drum loop

  3. import beads.*;

  4. AudioContext ac;

  5. String sourceFile; // this will hold the path to our audio file
  6. SamplePlayer sp; // the SamplePlayer class will be used to play the audio file

  7. // standard gain objects
  8. Gain g;
  9. Glide gainValue;

  10. BiquadFilter filter1; // this is our filter unit generator

  11. void setup()
  12. {
  13.   size(800, 600);
  14.   
  15.   ac = new AudioContext(); // create our AudioContext

  16.   sourceFile = sketchPath("") + "Drum_Loop_01.wav";

  17.   // Try/Catch blocks will inform us if the file can't be found
  18.   try {  
  19.     // initialize our SamplePlayer, loading the file indicated by the sourceFile string
  20.     sp = new SamplePlayer(ac, new Sample(sourceFile));
  21.    }
  22.   catch(Exception e)
  23.   {
  24.     // if there is an error, show an error message (at the bottom of the processing window)
  25.     println("Exception while attempting to load sample!");
  26.     e.printStackTrace(); // then print a technical description of the error
  27.     exit(); // and exit the program
  28.   }
  29.   
  30.   // we would like to play the sample multiple times, so we set KillOnEnd to false
  31.   sp.setKillOnEnd(false);

  32.   filter1 = new BiquadFilter(ac, BiquadFilter.BP_SKIRT, 5000.0f, 0.5f);
  33.   filter1.addInput(sp); // connect the SamplePlayer to the filter

  34.   // as usual, we create a gain that will control the volume of our sample player
  35.   gainValue = new Glide(ac, 0.0, 20);
  36.   g = new Gain(ac, 1, gainValue);
  37.   g.addInput(filter1); // connect the filter to the gain

  38.   ac.out.addInput(g); // connect the Gain to the AudioContext

  39.   ac.start(); // begin audio processing
  40.   
  41.   background(0); // draw a black background
  42.   text("Click to hear a band pass filter with cutoff set to 5000Hz.", 50, 50); // tell the user what to do
  43. }

  44. // although we're not drawing to the screen, we need to have a draw function
  45. // in order to wait for mousePressed events
  46. void draw(){}

  47. // this routine is called whenever a mouse button is pressed on the Processing sketch
  48. void mousePressed()
  49. {
  50.     gainValue.setValue(0.9);
  51.     sp.setToLoopStart(); // move the playback pointer to the first loop point (0.0)
  52.     sp.start(); // play the audio file
  53. }