Skip to content

Instantly share code, notes, and snippets.

@tado
Last active October 9, 2016 20:52
Show Gist options
  • Save tado/315cb6a8ca88d3f83b7cf3c92a6de78d to your computer and use it in GitHub Desktop.
Save tado/315cb6a8ca88d3f83b7cf3c92a6de78d to your computer and use it in GitHub Desktop.
Sonic Piで、自作Synthをつくる ref: http://qiita.com/yoppa/items/829d25addf499824d2f9
use_synth :fm
play 60
sleep 0.5
Sonic Pi.app/etc/synthdefs/designs/sonic_pi/synths
SynthDef("piTest", {
//出力先のバスを引数で設定
arg out_bus = 0;
//440HzのSin波生成
var mix = SinOsc.ar(440).dup;
//Envelope生成
var env = EnvGen.ar(Env.perc(0.0, 1.0, 1.0), doneAction: 2);
//Envelope適用
mix = mix * env;
Out.ar(out_bus, mix);
}
//ファイルの出力先を指定
).writeDefFile("/Users/tado/Desktop/my-synths");
#Synth定義を読み込む(フォルダの場所を指定)
load_synthdefs "/Users/tado/Desktop/my-synths"
#Synth名を指定
use_synth :piTest
play 60
sleep 1.0
SynthDef("piTest", {
//音程と音量を引数を指定
arg note = 52, amp = 1, out_bus = 0;
//音程(MIDI番号)から周波数へ
var freq = note.midicps;
//周波数をSin波に適用
var mix = SinOsc.ar(freq).dup;
var env = EnvGen.ar(Env.perc(0.0, 1.0, 1.0), doneAction: 2);
mix = mix * env;
Out.ar(out_bus, mix);
}
).writeDefFile("/Users/tado/Desktop/my-synths");
load_synthdefs "/Users/tado/Desktop/my-synths"
use_synth :piTest
loop do
play rrand_i(40, 80), amp: rrand(0.5, 0.8)
sleep 0.5
end
SynthDef("piTest", {
arg out_bus = 0, note = 52, amp = 1, attack = 0, release = 1, pan=0;
var freq = note.midicps;
var mix = SinOsc.ar(freq);
var env = EnvGen.ar(Env.perc(attack, release, 1.0), doneAction: 2);
//Panを適用
mix = Pan2.ar(mix * env, pan);
Out.ar(out_bus, mix);
}
).writeDefFile("/Users/tado/Desktop/my-synths");
load_synthdefs "/Users/tado/Desktop/my-synths"
use_synth :piTest
loop do
play rrand_i(40, 80), amp: rrand(0.5, 0.8), pan: rrand(-0.8, 0.8), release: 2.0
sleep 0.5
end
SynthDef("piTest", {
arg out_bus = 0, note = 52, amp = 1, attack = 0, release = 1, detune = 1.01, pan=0;
var freq = note.midicps;
var mix = MoogFF.ar(
Pulse.ar([freq,freq*0.5], 0.8),
freq*2.5,
128
);
var env = EnvGen.ar(Env.perc(attack, release, amp), doneAction: 2);
mix = Pan2.ar(mix * env, pan);
Out.ar(out_bus, mix);
}
).writeDefFile("/Users/tado/Desktop/my-synths");
load_synthdefs "/Users/tado/Desktop/my-synths"
use_synth :piTest
live_loop :live do
with_fx :flanger do
use_random_seed 8
32.times do
3.times do
ns = (scale :c1, :mixolydian, num_octaves: 8)
play ns.choose, attack: 0.0, release: 2.0, amp: 1.5
end
sleep 0.25
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment