// Simple Frequency Modulation instrument as it appears in Dodge's book, // Page 95. // Conceived as a "vibrato" instrument. // Vibrato width is a ratio applied to the carrier frequency. // Example: vibwidth = .01 = 1% vibrato width. ( SynthDef(\example6a, {arg dur = 1, amp = -6, carfreq = 440, vibwidth = 0.015, vibrate = 2.0; var env, mod, car; env = EnvGen.kr( Env([0.01, 1, 1, 0.01], [0.01, dur - 0.02, 0.01], \exp), doneAction: 2); vibwidth = vibwidth * carfreq; // vibwidth is a percentage of the carfreq mod = SinOsc.ar(vibrate, 0, vibwidth); car = SinOsc.ar(carfreq + mod, 0, amp.dbamp); Out.ar(0, car * env); }).load(s); ) s = Server.internal.boot; y = s.scope(1); // vibwidth ratio (0 - 1), vibrate (0-20 Hz) s.sendMsg(\s_new, \example6a, -1, 0, 0, \dur, 3, \carfreq, 440, \vibrate, 2.0 , \vibwidth, 0.06); // 1.5% vib width, 2 Hz rate s.sendMsg(\s_new, \example6a, -1, 0, 0, \dur, 3, \carfreq, 440, \vibrate, 2.0 , \vibwidth, 0.015); // 1.5% vib width, 0.5 Hz rate s.sendMsg(\s_new, \example6a, -1, 0, 0, \dur, 6, \carfreq, 440, \vibrate, 0.5 , \vibwidth, 0.015); // 0.75% vib width, 8 Hz rate s.sendMsg(\s_new, \example6a, -1, 0, 0, \dur, 3, \carfreq, 440, \vibrate, 8.0 , \vibwidth, 0.0075); // Frequency Modulation instrument which accepts Index // as a parameter and derives the appropriate deviation ( SynthDef(\example6b, {arg dur = 1, amp = -6, carfreq = 440, modfreq = 200, index = 1; var env, mod, car, deviation; env = EnvGen.kr( Env([0.01, 1, 1, 0.01], [0.01, dur - 0.02, 0.01], \exp), doneAction: 2); deviation = index * modfreq; mod = SinOsc.ar(modfreq, 0, deviation); car = SinOsc.ar(carfreq + mod, 0, amp.dbamp); Out.ar(0, car * env); }).load(s); ) // turn spectrum analyzer on z = FreqScope.new; // FM with index s.sendMsg(\s_new, \example6b, -1, 0, 0, \dur, 6, \carfreq, 400, \modfreq, 200.0, \index, 0.25); s.sendMsg(\s_new, \example6b, -1, 0, 0, \dur, 6, \carfreq, 400, \modfreq, 200.0, \index, 1); s.sendMsg(\s_new, \example6b, -1, 0, 0, \dur, 6, \carfreq, 400, \modfreq, 200.0, \index, 2); s.sendMsg(\s_new, \example6b, -1, 0, 0, \dur, 6, \carfreq, 400, \modfreq, 390.0, \index, 5); // Frequency Modulation instrument which accepts Index // as a parameter and derives the appropriate deviation. // Also accepts C:M Ratio as a parameter and derives fm. ( SynthDef(\example6c, {arg dur = 1, amp = -6, carfreq = 440, cmratio = 0.25, index = 1; var env, mod, car, modfreq, deviation; env = EnvGen.kr( Env([0.01, 1, 1, 0.01], [0.01, dur - 0.02, 0.01], \exp), doneAction: 2); modfreq = carfreq * cmratio; deviation = index * modfreq; mod = SinOsc.ar(modfreq, 0, deviation); car = SinOsc.ar(carfreq + mod, 0, amp.dbamp); Out.ar(0, car * env); }).load(s); ) // FM with index s.sendMsg(\s_new, \example6c, -1, 0, 0, \dur, 6, \carfreq, 400, \cmratio, 0.25, \index, 4); // Introducing XLine. // // XLine.kr(start, end, dur, mul, add, doneAction); // // If the envelope you want to use only has two values, XLine (for exponential line) or Line // are useful UGens. Remember that, with XLine, the line dexcribed cannot cross 0. ( SynthDef(\example6d, {arg dur = 1, amp = -6, modfreq = 220, index = 1, carfreq = 440; var env, mod, car, deviation; env = XLine.kr(1, 0.001, dur, doneAction: 2); deviation = index * modfreq; mod = SinOsc.ar(modfreq, 0, deviation * env); car = SinOsc.ar(carfreq + mod, 0, amp.dbamp); Out.ar(0, car * env); }).load(s); ) // FM with index s.sendMsg(\s_new, \example6d, -1, 0, 0, \dur, 6, \carfreq, 400, \modfreq, 200, \index, 5); y.window.close;