Skip to content

Instantly share code, notes, and snippets.

@tado
Last active Dec 26, 2015
Embed
What would you like to do?
// {}.playによる出力
{SinOsc.ar}.play;
// SyntDefに変換
SynthDef("sine", {Out.ar(0, SinOsc.ar)}).play; //left
SynthDef("sine", {Out.ar(1, SinOsc.ar)}).play; //right
// -----------------------------------------
//関数による記述
{ SinOsc.ar(440, 0, 0.2) }.play;
//SynthDefをサーバーに追加
SynthDef.new("test-SinOsc", {
Out.ar(0, SinOsc.ar(440, 0, 0.2))
}).add;
//Synthを演奏
Synth("test-SinOsc");
// -----------------------------------------
//SynthDefの定義(引数あり)
SynthDef.new("test-SinOsc", {
arg freq = 440, amp = 0.2;
Out.ar(0, SinOsc.ar(freq, 0, amp))
}).add;
//Synthを演奏
a = Synth("test-SinOsc"); //440Hz
b = Synth("test-SinOsc", [freq:660]); //660Hz
c = Synth("test-SinOsc", [freq:880, amp:0.5]); //880Hz, amp:0.5
a.set("freq", 330); //440Hz -> 330Hz
b.set("freq", 220, "amp", 0.3); //660Hz -> 220Hz, amp: 0.3
//終了
a.free; b.free; c.free;
// -----------------------------------------
// RM変調
SynthDef.new("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.new("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.new("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([6.1,7.9].reciprocal);
rm = car * (mod1 * mod2);
Out.ar(0, rm);
}).play;
// -----------------------------------------
// AM変調
SynthDef.new("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, rm;
car = SinOsc.ar(440, 0, 0.5);
mod1 = SinOsc.ar(MouseX.kr(1, 4000, 1), 0, 0.5, 0.5);
mod2 = SinOsc.ar([8,7].reciprocal);
rm = car * (mod1 * mod2);
Out.ar(0, rm);
}).play;
// AM + LFNoise
(
SynthDef.new("rand-am",{
arg freq = 440, amp = 0.5, modFreq = 400;
var car, mod1, mod2, rm;
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([8,7].reciprocal).abs);
rm = car * (mod1 * mod2);
Out.ar(0, rm);
}).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", "modFreq", 200]);
Synth("rand-am", ["freq", 880, "amp", 0.2, "modFreq", 100]);
Synth("rand-am", ["freq", 1780, "amp", 0.05, "modFreq", 20]);
)
// -----------------------------------------
//FM変調
//FM基本
SynthDef.new("test-fm",{
arg cfreq = 440, mfreq = 111, index = 200;
var car, mod;
mod = SinOsc.ar(mfreq, 0, index);
car = SinOsc.ar([cfreq, cfreq*1.005] + mod, 0, 0.5);
Out.ar(0, car);
}).play;
//FMマウスで操作
SynthDef.new("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応用1
(
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(10.reciprocal).abs
);
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応用2、エフェクト
(
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]);
)
// FM応用3、コンポーネントごとに
(
SynthDef("carrier", { arg inbus = 2, outbus = 0, freq = 440, carPartial = 1, index = 3, mul = 0.2;
var mod, car;
mod = In.ar(inbus, 1);
Out.ar(
outbus,
SinOsc.ar((freq * carPartial) + mod, 0, mul);
)
}).add;
SynthDef("modulator", { arg outbus = 2, freq, modPartial = 1, index = 3;
Out.ar(
outbus,
SinOsc.ar(freq * modPartial, 0, freq)
*
LFNoise1.kr(Rand(3, 6).reciprocal).abs
*
index
)
}).add;
)
(
var freq = 440;
// modulators for the left channel
Synth.head(s, "modulator", [\outbus, 2, \freq, freq, \modPartial, 0.649, \index, 2]);
Synth.head(s, "modulator", [\outbus, 2, \freq, freq, \modPartial, 1.683, \index, 2.31]);
// modulators for the right channel
Synth.head(s, "modulator", [\outbus, 4, \freq, freq, \modPartial, 0.729, \index, 1.43]);
Synth.head(s, "modulator", [\outbus, 4, \freq, freq, \modPartial, 2.19, \index, 1.76]);
// left and right channel carriers
Synth.tail(s, "carrier", [\inbus, 2, \outbus, 0, \freq, freq, \carPartial, 1]);
Synth.tail(s, "carrier", [\inbus, 4, \outbus, 1, \freq, freq, \carPartial, 0.97]);
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment