import beads.*; AudioContext ac; Glide carrierFreq, modFreqRatio; void setup() { size(300,300); ac = new AudioContext(); /* * This is a copy of Lesson 3 with some mouse control. */ //this time we use the Glide object because it smooths the mouse input. carrierFreq = new Glide(ac, 500); modFreqRatio = new Glide(ac, 1); Function modFreq = new Function(carrierFreq, modFreqRatio) { public float calculate() { return x[0] * x[1]; } }; WavePlayer freqModulator = new WavePlayer(ac, modFreq, Buffer.SINE); Function carrierMod = new Function(freqModulator, carrierFreq) { public float calculate() { return x[0] * 400.0 + x[1]; } }; WavePlayer wp = new WavePlayer(ac, carrierMod, Buffer.SINE); Gain g = new Gain(ac, 1, 0.1); g.addInput(wp); ac.out.addInput(g); ac.start(); } /* * The drawing code also has some mouse listening code now. */ color fore = color(255, 102, 204); color back = color(0,0,0); /* * Just do the work straight into Processing's draw() method. */ void draw() { loadPixels(); //set the background Arrays.fill(pixels, back); //scan across the pixels for(int i = 0; i < width; i++) { //for each pixel work out where in the current audio buffer we are int buffIndex = i * ac.getBufferSize() / width; //then work out the pixel height of the audio data at that point int vOffset = (int)((1 + ac.out.getValue(0, buffIndex)) * height / 2); //draw into Processing's convenient 1-D array of pixels pixels[vOffset * height + i] = fore; } updatePixels(); //mouse listening code here carrierFreq.setValue((float)mouseX / width * 1000 + 50); modFreqRatio.setValue((1 - (float)mouseY / height) * 10 + 0.1); }