yoppa.org


コンピュータミュージック 2017 - 明治大学先端メディアサイエンス学科

SuperCollider基礎 2 – 変調合成 (RM, AM, FM)

先週学んだSuperColliderで「楽器」を定義する SynthDef を利用して、様々な音響合成の手法について実際に音を聞きながら学んでいきます。まず今回は、ある信号のパラメーターをもう一つの信号で変化(変調)させる「変調合成」という手法について紹介します。変調合成は、信号の何を変調するのかによって、AM(RM)、FMという種類に分けられます。それぞれの変調合成の音色の違いなどに注意しながら、SuperColliderでの実現のやり方を学んでいきましょう。

スライド資料

コードサンプル

// SuperColliderによる音響合成変調合成1- RMとAM
// RM変調
SynthDef("test-rm",{
    var car, mod, rm;
    mod = SinOsc.ar(880, 0, 1.0);
    car = SinOsc.ar([440,442], 0, 0.5);
    rm = car * mod;
    Out.ar(0, rm);
}).play;


// RM変調2 - マウスでModulatorの周波数を変更
SynthDef("test-rm",{
    var car, mod, rm;
    mod = SinOsc.ar(MouseX.kr(1, 4000, 1), 0, 1.0);
    car = SinOsc.ar([440,442], 0, 0.5);
    rm = car * mod;
    Out.ar(0, rm);
}).play;

// RM変調3 - 2つのModulator
SynthDef("test-rm",{
    var car, mod1, mod2, rm;
    car = SinOsc.ar(440, 0, 0.5);
    mod1 = SinOsc.ar(MouseX.kr(1, 4000, 1), 0, 1.0);
    mod2 = SinOsc.ar([1/6.1,1/7.9]);
    rm = car * (mod1 * mod2);
    Out.ar(0, rm);
}).play;

// AM変調
SynthDef("test-am",{
    var car, mod, rm;
    mod = SinOsc.ar(MouseX.kr(1, 4000, 1), 0, 0.5, 0.5);
    car = SinOsc.ar([440,442], 0, 0.5);
    rm = car * mod;
    Out.ar(0, rm);
}).play;

SynthDef.new("test-am",{
    var car, mod1, mod2, am;
    car = SinOsc.ar(440, 0, 0.5);
    mod1 = SinOsc.ar(MouseX.kr(1, 4000, 1), 0, 0.5, 0.5);
    mod2 = SinOsc.ar([1/8,1/7]);
    am = car * (mod1 * mod2);
    Out.ar(0, am);
}).play;

// AM + LFNoise
(
SynthDef("rand-am",{
    arg freq = 440, amp = 0.5, modFreq = 400;
    var car, mod1, mod2, am;
    car = SinOsc.ar(freq, 0, amp);
    mod1 = SinOsc.ar(LFNoise1.kr(5.reciprocal, modFreq), pi.rand, 0.5, 0.5);
    mod2 = SinOsc.ar(LFNoise1.kr([1/8, 1/7])0, 0.5, 0.5);
    am = car * (mod1 * mod2);
    Out.ar(0, am);
}).add;
)

(
Synth("rand-am", ["freq", 110, "amp", 0.2, "modFreq", 1200]);
Synth("rand-am", ["freq", 220, "amp", 0.2, "modFreq", 200]);
Synth("rand-am", ["freq", 440, "amp", 0.2, "modFreq", 200]);
Synth("rand-am", ["freq", 880, "amp", 0.2, "modFreq", 100]);
Synth("rand-am", ["freq", 1780, "amp", 0.05, "modFreq", 20]);
)

//FM基本
SynthDef("test-fm", {
    arg cfreq = 440, mfreq = 111, index = 200;
    var car, mod;
    mod = SinOsc.ar(mfreq, 0, index);
    car = SinOsc.ar([cfreq, cfreq*1.01] + mod, 0, 0.5);
    Out.ar(0, car);
}).play;

//FMマウスで操作
SynthDef("test-fm",{
    var car, mod;
    mod = SinOsc.ar(MouseX.kr(1, 1000, 1), 0,
        MouseY.kr(1, 10000, 1));
    car = SinOsc.ar([440,442] + mod, 0, 0.5);
    Out.ar(0, car);
}).play;

//FM応用
(
SynthDef("fm1", { arg freq = 440, detune = 2, carPartial = 1, modPartial = 1, index = 3, mul = 0.2;
    var mod, car;
    mod = SinOsc.ar(
        [freq, freq+detune] * modPartial, 0,
        freq * index * LFNoise1.kr(1/10)
    );
    car = SinOsc.ar((freq * carPartial) + mod, 0, mul);
    Out.ar(0, car);
}).add;
)

(
Synth("fm1", ["modPartial", 2.4]);
Synth("fm1", ["modPartial", 2.401]);
Synth("fm1", ["freq", 110, "modPartial", 3.1213, "index", 10]);
Synth("fm1", ["freq", 220, "modPartial", 10.99, "index", 20]);
)
//FM + エフェクト
(
SynthDef("fm2", { arg bus = 0, freq = 440, detune = 2, carPartial = 1, modPartial = 1, index = 3, mul = 0.1;
    var mod, car;
    mod = SinOsc.ar(
        [freq, freq+detune] * modPartial,
        0,
        freq * index * LFNoise1.kr(10.reciprocal).abs
    );
    car = SinOsc.ar((freq * carPartial) + mod, 0, mul);
    Out.ar(bus, car);
}).add;

SynthDef("preDelay", { arg inbus = 2;
    ReplaceOut.ar(
        4,
        DelayN.ar(In.ar(inbus, 1), 0.048, 0.048)
    )
}).add;

SynthDef("combs", {
    ReplaceOut.ar(
        6,
        Mix.arFill(7, { CombL.ar(In.ar(4, 1), 0.1, LFNoise1.kr(Rand(0, 0.1), 0.04, 0.05), 15) })
    )
}).add;

SynthDef("allpass", { arg gain = 0.2;
    var source;
    source = In.ar(6, 1);
    4.do({source = AllpassN.ar(source, 0.050, [Rand(0, 0.05), Rand(0, 0.05)], 1) });
    ReplaceOut.ar(8, source * gain)
}).add;

SynthDef("theMixer", { arg gain = 1;
    ReplaceOut.ar(
        0,
        Mix.ar([In.ar(2, 1), In.ar(8, 2)]) * gain
    )
}).add;
)

(
Synth("fm2", ["bus", 2, "freq", 440, "modPartial", 2.4]);
Synth("fm2", ["bus", 2, "freq", 448, "modPartial", 2.401]);
Synth.tail(s, "preDelay");
Synth.tail(s, "combs");
Synth.tail(s, "allpass");
Synth.tail(s, "theMixer", ["gain", 0.64]);
)