import krister.Ess.*; AudioChannel myChannel; // Create channel TriangleWave myWave; // Create triangle waveform Envelope myEnvelope; // Create envelope int numNotes = 200; // Number of notes int noteDuration = 300; // Duration of each note in milliseconds float[] rawSequence = { 100, 100, 90, 80, 100, 90, 80, 100, 90, 80, 500, 600, 100, 100, 90, 80, 100, 90, 80, 100, 90, 80, 500, 600, 100, 100, 90, 80, 100, 90, 80, 100, 90, 80, 500, 600, 900, 800, 850, 900, 0, 900, 800, 850, 900, 100, 90, 80, 50 }; void setup() { size(100, 100); Ess.start(this); // Start Ess myChannel = new AudioChannel(); // Create a new AudioChannel myChannel.initChannel(myChannel.frames(rawSequence.length * noteDuration)); int current = 0; myWave = new TriangleWave(480, 0.3); // Create triangle wave EPoint[] myEnv = new EPoint[3]; // Three-step breakpoint function myEnv[0] = new EPoint(0, 0); // Start at 0 myEnv[1] = new EPoint(0.25, 1); // Attack myEnv[2] = new EPoint(10, 0); // Release myEnvelope = new Envelope(myEnv); // Bind Envelope to the breakpoint function int time = 0; for (int i = 0; i < rawSequence.length; i++) { myWave.frequency = rawSequence[current]; // Update waveform frequency int begin = myChannel.frames(time); // Starting position within Channel int e = int(noteDuration * 0.8); int end = myChannel.frames(e); // Ending position with Channel myWave.generate(myChannel, begin, end); // Render triangle wave myEnvelope.filter(myChannel, begin, end); // Apply envelope current++; // Move to next note time += noteDuration; // Increment the Channel output point } myChannel.play(); // Play the sound! } void draw() { } // Empty draw() keeps the program running void stop() { Ess.stop(); // When program stops, stop Ess too super.stop(); }