Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorolipet <olivier.belanger@umontreal.ca>2007-08-23 07:15:47 (GMT)
committer olipet <olivier.belanger@umontreal.ca>2007-08-23 07:15:47 (GMT)
commit6c2f94e8f68957f8e42f1e65b492c05baf8a5704 (patch)
treef9f30593cab0fd6200c0988a07fd85d14565cb04
parentecaa8b4029a921f118b44a9ad3f618b291722bd0 (diff)
beginning on sound stuff
-rw-r--r--data/sound/playSineWave6
-rw-r--r--data/sound/sequence12
-rw-r--r--data/sound/sndInfo4
-rwxr-xr-xsound/snd.py55
4 files changed, 77 insertions, 0 deletions
diff --git a/data/sound/playSineWave b/data/sound/playSineWave
new file mode 100644
index 0000000..8cda42e
--- /dev/null
+++ b/data/sound/playSineWave
@@ -0,0 +1,6 @@
+import sys
+sys.path.append('/usr/share/activities/Pippy.activity/sound')
+from snd import *
+playSine()
+audioOut()
+
diff --git a/data/sound/sequence b/data/sound/sequence
new file mode 100644
index 0000000..f870094
--- /dev/null
+++ b/data/sound/sequence
@@ -0,0 +1,12 @@
+import sys
+import random
+sys.path.append('/usr/share/activities/Pippy.activity/sound')
+from snd import *
+for i in range(25):
+ pitch = random.randint(500,2000)
+ amp = 5000
+ dur = 0.1
+ starttime = i * 0.1
+ playSine(pitch, amp, dur, starttime)
+audioOut()
+
diff --git a/data/sound/sndInfo b/data/sound/sndInfo
new file mode 100644
index 0000000..f40accb
--- /dev/null
+++ b/data/sound/sndInfo
@@ -0,0 +1,4 @@
+import sys
+sys.path.append('/usr/share/activities/Pippy.activity/sound')
+from snd import *
+print playSine.__doc__
diff --git a/sound/snd.py b/sound/snd.py
new file mode 100755
index 0000000..0e972e4
--- /dev/null
+++ b/sound/snd.py
@@ -0,0 +1,55 @@
+#! /usr/bin/env python
+import os
+import csnd
+
+orchlines = []
+scorelines = []
+instrlist = []
+
+
+def quit(self):
+ perf.Stop()
+ perf.Join()
+ cs.Reset()
+ cs = None
+
+def playSine( pitch=1000, amp=5000, dur=1, starttime=0):
+ """Play a sine wave (pitch = [1000], amp = [5000], dur = [1], starttime = [0])"""
+ if not 1 in instrlist:
+ orchlines.append("instr 1\n")
+ orchlines.append("asig oscil p5, p4, 1\n")
+ orchlines.append("out asig\n")
+ orchlines.append("endin\n")
+ instrlist.append(1)
+
+ scorelines.append("i1 %f %f %f %f\n" % (float(starttime), float(dur), float(pitch), float(amp)))
+
+def audioOut():
+ path = os.path.dirname(os.path.abspath(__file__))
+ csd = open(path + "/temp.csd", "w")
+ csd.write("<CsoundSynthesizer>\n")
+ csd.write("<CsOptions>\n")
+ csd.write("-+rtaudio=alsa -odevaudio -m0 -d -b256 -B512\n")
+ csd.write("</CsOptions>\n")
+ csd.write("<CsInstruments>\n")
+ csd.write("sr=16000\n")
+ csd.write("ksmps=64\n")
+ csd.write("nchnls=1\n")
+ for line in orchlines:
+ csd.write(line)
+ csd.write("</CsInstruments>\n")
+ csd.write("<CsScore>\n")
+ csd.write("f1 0 1024 10 1\n")
+ for line in scorelines:
+ csd.write(line)
+ csd.write("e\n")
+ csd.write("</CsScore>\n")
+ csd.write("</CsoundSynthesizer>\n")
+ csd.close()
+
+ cs = csnd.Csound()
+ cs.Compile(path + '/temp.csd')
+ perf = csnd.CsoundPerformanceThread(cs)
+ perf.Play()
+
+