/* * author: Kenneth Knudsen & Ricki Gregersen * description: reads a line from a piece of paper using a webcam * and outputs a tone between 440 and 880 Hz * according to the lines y coordinate */ //use the minim sound library, included in processing 1.0 import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; //CamModule instance for grapping a frame from the webcam CamModule cam; //SoundModule instance for outputting a sine wave at a specific frequence SoundModule sound; //TrackModule instance for translating a y coordinate to a frequency TrackModule track; void setup() { size(640, 480); frameRate(30); //CamModule constructor takes an input of (PApplet, width to grap, height to grap and offset) //this means: we will grap 30x480 pixels from the webcam starting at 320 in the x direction cam = new CamModule(this, 30, height, 320); sound = new SoundModule(this); track = new TrackModule(); } void draw() { //get the bitmap from the webcam PImage frame = cam.bitmap(); //process it and return the position of the line as a frequency float freq = track.processBitmap(frame); //feed the frequency to the soundModule sound.freq(freq); //present the frame grabbed from the webcam to the screen image(frame, 320, 0); } //remember to close the connection made to the soundcard void stop() { super.stop(); sound.stop(); }