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

FM demo

This demo is a real-time FM synth with mouse / touchpad interface.
Move the mouse in X and Y to change modulator frequency and index, respectively.
Click the mouse to mute / unmute on a particular setting.
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/

////////////////////////////////////////////////////
suggestions (copy and replace any of these items in live code)
mouseX+440 => cf; // manipulate carrier frequency with mouse cf*0.1 => index; // make index depend on carrier frequency
////////////////////////////////////////////////////
live code
global int mouseX, mouseY; global float cg; SinOsc c => dac; SinOsc m => blackhole; 440 => float cf; 550 => float mf => m.freq; 200 => float index; 1.0 => cg; fun void runFM() { while( true ) { cf + (index * m.last()) => c.freq; cg => c.gain; 1::samp => now; } } spork ~ runFM(); fun void RespondToMouseMovement() { while( true ) { mouseX*0.05 => m.freq; mouseY*0.5 => index; 10::ms => now; } } spork ~ RespondToMouseMovement(); 1::week => now;