band pass problems
in
Core Library Questions
•
2 years ago
hi,
i have tried to modify the band pass filter example to include more bands (i'm trying to make a simple graphic e.q.). Problem is that i want to only turn down the selected band (moving mouseY over the coloured rectangles) leaving the other frequencies playing. How can i turn down just the one band? Any help, modifications to attached code, etc would be really appreciated.
Cheers,
Josh
- /**
- * Band Pass Filter
- * by Damien Di Fede.
- *
- * This sketch demonstrates how to use the BandPass effect.
- * Move the mouse left and right to change the frequency of the pass band.
- * Move the mouse up and down to change the band width of the pass band.
- */
- import ddf.minim.*;
- import ddf.minim.effects.*;
- Minim minim;
- AudioPlayer groove;
- BandPass bpf;
- BandPass bpf1;
- void setup()
- {
- size(512, 200, P2D);
- minim = new Minim(this);
- groove = minim.loadFile("groove.mp3");
- groove.loop();
- // make a band pass filter with a center frequency of 440 Hz and a bandwidth of 20 Hz
- // the third argument is the sample rate of the audio that will be filtered
- // it is required to correctly compute values used by the filter
- bpf = new BandPass(1000, 300, groove.sampleRate());
- //bpf1 = new BandPass(880, 20, groove.sampleRate());
- groove.addEffect(bpf);
- }
- void draw()
- {
- background(0);
- stroke(255);
- noStroke();
- fill(255, 0, 0);
- //First rect area starting at coordinates (20,0),width = bpf.getBandWidth()/10, height = height
- rect(20,0, bpf.getBandWidth()/10, height);
- //Second rect area starting at coordinates (100,0),width = bpf.getBandWidth()/10, height = height
- fill(0, 255, 0);
- rect(100,0, bpf.getBandWidth()/10, height);
- //Third rect area starting at coordinates (200,0),width = bpf.getBandWidth()/10, height = height
- fill(0, 0, 255);
- rect(200,0, bpf.getBandWidth()/10, height);
- }
- void mouseMoved()
- {
- //initialise local variables
- float passBand = 0;
- float valGain = 0;
- //settings related to first rect
- if(mouseX<20+bpf.getBandWidth()/10 && mouseX>20)
- {
- passBand = map(mouseX, 0, width, 100, 5000);
- valGain = map(mouseY, 0, height, 16,-48);
- }
- //settings related to second rect
- if(mouseX<100+bpf.getBandWidth()/10 && mouseX>100)
- {
- passBand = map(mouseX, 0, width, 100, 5000);
- valGain = map(mouseY, 0, height, 16,-48);
- }
- //settings related to third rect
- if(mouseX<200+bpf.getBandWidth()/10 && mouseX>200)
- {
- passBand = map(mouseX, 0, width, 100, 5000);
- valGain = map(mouseY, 0, height, 16,-48);
- }
- bpf.setFreq(passBand);
- groove.setGain(valGain);
- // prints the new values of the coefficients in the console
- //bpf.printCoeff();
- }
- void stop()
- {
- // always close Minim audio classes when you finish with them
- groove.close();
- // always stop Minim before exiting
- minim.stop();
- super.stop();
- }
1