Homework 2 is about synthesizing an auditory streaming illusion using FM tones.

More complex FM demo with envelopes

Like FM demo but with 2 carriers and 3 ADSR envelopes.
Similar to the last figure in Chowning's 1973 article. Experiment with browser page zoom to work with different parameter ranges!
The code is based on FM synthesis "by hand" from https://chuck.cs.princeton.edu/doc/examples/

////////////////////////////////////////////////////
////////////////////////////////////////////////////
live code
global int mouseX, mouseY; global Event playNote, finishNote; SinOsc c => ADSR e => dac; SinOsc c2 => ADSR e2 => dac; SinOsc m => ADSR e3 => blackhole; 440 => float cf; 225 => float cf2; // detuned from octave below 882 => m.freq; // detuned from octave above 200 => float index; e.set( 10::ms, 8::ms, .5, 500::ms ); e2.set( 10::ms, 8::ms, .5, 1000::ms ); e3.set( 10::ms, 8::ms, 1.0, 400::ms ); fun void runADSR() { while (true) { playNote => now; e.keyOn(); e2.keyOn(); e3.keyOn(); finishNote => now; e.keyOff(); e2.keyOff(); e3.keyOff(); } } spork ~ runADSR(); fun void runFM() { while( true ) { cf + (index * e3.last()) => c.freq; cf2 + (index * e3.last()) => c2.freq; 1::samp => now; } } spork ~ runFM(); fun void RespondToMouseMovement() { while( true ) { e3.set( 10::ms, 8::ms, 1.0, mouseX::ms ); mouseY => index; 10::ms => now; } } spork ~ RespondToMouseMovement(); 1::week => now;