// Example 6- FM
(
Server.default = s = Server.internal.boot;
s.waitForBoot({
s.scope;
f = FreqScope.new(400, 200, 0);
})
)
// 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.
(
var noteObject, score;
noteObject = CtkSynthDef(\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));
vibwidth = vibwidth * carfreq; // vibwidth is a pct of the carfreq
mod = SinOsc.ar(vibrate, 0, vibwidth);
car = SinOsc.ar(carfreq + mod, 0, amp.dbamp);
Out.ar(0, car * env);
});
score = CtkScore.new;
score.add(
// vibwidth ratio (0 - 1), vibrate (0-20 Hz)
noteObject.new(1.0, 3.0).dur_(3.0).carfreq_(440)
.vibrate_(2.0).vibwidth_(0.06),
// 1.5% vib width, 2 Hz rate
noteObject.new(5.0, 3.0).dur_(3.0).carfreq_(440)
.vibrate_(2.0).vibwidth_(0.015),
// 1.5% vib width, 0.5 Hz rate
noteObject.new(9.0, 3.0).dur_(3.0).carfreq_(440)
.vibrate_(0.5).vibwidth_(0.015),
// 0.75% vib width, 8 Hz rate
noteObject.new(13.0, 3.0).dur_(3.0).carfreq_(440)
.vibrate_(8.0).vibwidth_(0.0075)
);
score.play;
)
// Frequency Modulation instrument which accepts Index
// as a parameter and derives the appropriate deviation
(
var noteObject, score;
noteObject = CtkSynthDef(\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));
deviation = index * modfreq;
mod = SinOsc.ar(modfreq, 0, deviation);
car = SinOsc.ar(carfreq + mod, 0, amp.dbamp);
Out.ar(0, car * env);
});
score = CtkScore.new;
score.add(
// FM with index 0.25, 1, 2, and 5
noteObject.new(1.0, 3.0).dur_(3.0).carfreq_(400).modfreq_(100)
.index_(2.5),
noteObject.new(5.0, 3.0).dur_(3.0).carfreq_(800).modfreq_(200)
.index_(2.5),
noteObject.new(9.0, 3.0).dur_(3.0).carfreq_(1200).modfreq_(300)
.index_(2.5),
noteObject.new(13.0, 3.0).dur_(3.0).carfreq_(1600).modfreq_(400)
.index_(2.5)
);
score.play;
)
// 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.
(
var noteObject, note;
noteObject = CtkSynthDef(\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));
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);
});
// FM with index and ratio
note = noteObject.new(1.0, 6.0).dur_(6.0).carfreq_(400)
.cmratio_(0.25).index_(4);
note.play;
)
// 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.
(
var noteObject, note;
noteObject = CtkSynthDef(\example6d, {arg dur = 1, amp = -6, modfreq = 220,
index = 1, carfreq = 440;
var env, mod, car, deviation;
env = XLine.kr(1, 0.0001, dur);
deviation = index * modfreq;
// envelope the modulating SinOsc to create a change of timbre
mod = SinOsc.ar(modfreq, 0, deviation * env);
car = SinOsc.ar(carfreq + mod, 0, amp.dbamp);
Out.ar(0, car * env);
});
// FM with index
note = noteObject.new(1.0, 6.0).dur_(6.0).carfreq_(400)
.modfreq_(200).index_(5);
note.play;
)
/* Read Dodge 5.1 */