import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.ugens.*; Minim minim; AudioOutput mainOut; Summer sawSummer; MoogFilter moog; float waveSize = 100.f; void setup() { size( 800, 400 ); colorMode(HSB, 360, 1, 1); minim = new Minim(this); mainOut = minim.getLineOut(); sawSummer = new Summer(); moog = new MoogFilter( 3000.f, 0.2f ); sawSummer.patch( moog ).patch( mainOut ); mainOut.pauseNotes(); mainOut.setTempo( 130.f ); float baseFreq = 60.f; FlutterSaw( 0.f, 200.f, "C2", 0.f ); FlutterSaw( 8.f, 192.f, "G3", -1f ); FlutterSaw( 16.f, 184.f, "E5", 1f ); FlutterSaw( 32.f, 168.f, "D6", 0.5f ); FlutterSaw( 32.01f, 167.99f, "D6", -0.5f ); FrequencySweep( 32.f, 8.f, 3000.f, 10000.f ); FrequencySweep( 44.f, 4.f, 10000.f, 8000.f ); FrequencySweep( 48.f, 8.f, 8000.f, 200.f ); FrequencySweep( 62.f, 4.f, 200.f, 2000.f ); ResonanceSweep( 66.f, 4.f, 0.2f, 0.8f ); FrequencySweep( 74.f, 12.f, 2000.f, 400.f ); ResonanceSweep( 74.f, 12.f, 0.8f, 0.f ); ResonanceSweep( 86.f, 2.f, 0.f, 0.2f ); ResonanceSweep( 88.f, 2.f, 0.2f, 0.f ); ResonanceSweep( 90.f, 2.f, 0.f, 0.3f ); ResonanceSweep( 92.f, 2.f, 0.3f, 0.01f ); ResonanceSweep( 94.f, 3.f, 0.01f, 0.9f ); FrequencySweep( 98.f, 24.f, 400.f, 1000.f ); ResonanceSweep( 122.f, 24.f, 0.9f, 0.05f ); FrequencySweep( 122.f, 12.f, 1000.f, Frequency.ofPitch( "C8" ).asHz() ); mainOut.resumeNotes(); } ////////////////////////////////////////////////// // // DRAWING DOWN HERE // float hueForSample( float sample ) { return map( abs(sample), 0, 1, 120, 450 ); } // draw is run many times void draw() { // erase the window to black float lastRez = moog.resonance.getLastValue(); float lastFreq = moog.frequency.getLastValue() / 22100.f; background( lastFreq * 360.f, 0.5, lastRez ); // draw using a white stroke stroke( 255 ); // draw the waveforms float[] left = mainOut.left.toArray(); float[] right = mainOut.right.toArray(); for( int i = 0; i < mainOut.bufferSize() - 1; i++ ) { // find the x position of each buffer value float x1 = map( i, 0, mainOut.bufferSize(), 0, width ); float x2 = map( i+1, 0, mainOut.bufferSize(), 0, width ); // draw a line from one buffer position to the next for both channels stroke( hueForSample( left[i] ), 1, 1 ); line( x1, height/2 - waveSize + left[i]*waveSize, x2, height/2 - waveSize + left[i+1]*waveSize); stroke( hueForSample( right[i] ), 1, 1 ); line( x1, height/2 + waveSize + right[i]*waveSize, x2, height/2 + waveSize + right[i+1]*waveSize); } } // stop is run when the user presses stop void stop() { // close the AudioOutput mainOut.close(); // stop the minim object minim.stop(); super.stop(); }