Created
November 18, 2013 14:59
-
-
Save emsk/7529159 to your computer and use it in GitHub Desktop.
シリアルポートから取得した加速度データによって音を鳴らす
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Receive sensor data and play guitar sound. | |
- Mac OS X 10.6.8 Snow Leopard | |
- SuperCollider 3.6.5 | |
- LilyPad Arduino USB ... https://www.sparkfun.com/products/11190 | |
- FLORA Accelerometer (LSM303) ... http://www.adafruit.com/products/1247 | |
*/ | |
// 1. boot | |
( | |
s.options.device_("ASIO : ASIO4ALL v2"); | |
s.boot; | |
) | |
// 2. define guitar synth | |
( | |
SynthDef(\guitar, { | |
arg sensor = 1.0, pitch = #[52, 57, 62, 67, 71, 76]; | |
var out = Mix.fill(pitch.size, { | |
arg i; | |
var trigger, pluck, period, string; | |
trigger = HPZ1.kr(sensor > (0.25 + (i * 0.1))).abs; | |
pluck = PinkNoise.ar(Decay.kr(trigger, 0.05)); | |
period = pitch.at(i).midicps.reciprocal; | |
string = CombL.ar(pluck, period, period, 4); | |
Pan2.ar(string, i * 0.2 - 0.5); | |
}); | |
LPF.ar(out, 12000); | |
LeakDC.ar(out); | |
Out.ar(0, out); | |
}).add; | |
~guitar = Synth(\guitar); | |
) | |
// 3. receive sensor data from Arduino | |
( | |
SerialPort.listDevices; | |
~arduino = ArduinoSMS("/dev/tty.usbmodem411", 9600); | |
~arduino.action = { | |
arg ... msg; | |
var sensor = msg[0].asInteger.abs / 1000; | |
msg[0].postln; | |
~guitar.set(\sensor, sensor); | |
} | |
) | |
// 4. change guitar pitch | |
~guitar.setn(\pitch, [52, 57, 62, 67, 71, 76]); // sample 1 (default) | |
~guitar.setn(\pitch, Array.series(15, 50, 7)); // sample 2 | |
~guitar.setn(\pitch, Array.series(6, 52, 4)); // sample 3 | |
// 5. quit | |
( | |
~arduino.close; | |
~guitar.free; | |
s.quit; | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment