This is the first project I've done in processing, and it's a project for my ISTA class at Arizona.
It's a simple program that plays two waveforms, and changes the frequency based on mouse position. You can toggle various filters with the number keys. Enjoy!
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
//Audio signal
AudioOutput out;
//Waveforms
SquareWave square;
SawWave saw;
//Effects
LowPassSP lowSP;
LowPassFS lowFS;
BandPass band;
HighPassSP highSP;
NotchFilter notch;
//Font for text
PFont font;
void setup(){
size (1000, 500);
font = loadFont("CenturySchoolbook-28.vlw");
textFont(font);
minim = new Minim(this);
out = minim.getLineOut();
// create a square and saw waves with a frequency of 440 Hz,
// an amplitude of 1 and the sample rate at 44
square = new SquareWave(500, 1, 44100);
saw = new SawWave(210, 1, 44100);
// create the filters with various settings
lowFS = new LowPassFS(200, 44100);
lowSP = new LowPassSP(200, 44100);
highSP = new HighPassSP(800, 44100);
band = new BandPass(300, 200, 44100);
notch = new NotchFilter(200, 200, 44100);
// attach signals to output
out.addSignal(square);
out.addSignal(saw);
}
// Prints the instructions and draws the waveform.
void draw(){
stroke(#FFFF00);
background(100);
text("There are 2 tones being played.\n"
+ "The X mouse axis changes the pitch of the square wave.\n"
+ "The Y mouse axis changes the pitch of the saw wave.\n"
+ "Press 1, 2, 3, 4 or 5 to toggle low-pass SP filter, high-pass SP filter,\n"
+ "low-pass FS filter, band pass filter, or notch filter, respectively.\n"
+ "The waveform below is updated in real time. ", 15, 30);
// To draw the waveform, I took the frequency values returned by the audio out
// and connected them with a line. I had to multiply each by 50 to make sure it
// showed sufficient differentiation between values.