/** * This applet demonstrates how to use my Sine class with an Ess AudioStream. * Moving the mouse left and right will smoothly change the frequency of the sine wave. */ import krister.Ess.*; AudioStream speaker; Sine mSine; void setup() { size(400, 200); smooth(); // start up Ess Ess.start(this); // create a new AudioStream speaker = new AudioStream(); // our wave mSine = new Sine(440, 0.4f, speaker.sampleRate); // start speaker.start(); } void draw() { background(0); float sc = 0.5; for (int i = 0; i < width/sc; i++ ) { stroke(255); line(i*sc, height/2 + 100*speaker.buffer[i], (i+1)*sc, height/2 + 100*speaker.buffer[i+1]); stroke(0, 255, 0, 64); if ( i == 64 ) stroke(0, 255, 0); line(i*8, 0, i*8, height); } } void mouseMoved() { mSine.setFreq( map(mouseX, 0, width, 220, 880) ); } void audioStreamWrite(AudioStream s) { mSine.generate(s); } public void stop() { Ess.stop(); super.stop(); }