shithub: aubio

Download patch

ref: 87b0c03a3df667611bd79aac04c4df265e04e453
parent: 944c7e1e85e52cb1826716f8a0d58bca6f33d7d1
author: Paul Brossier <piem@piem.org>
date: Sat Feb 9 19:13:56 EST 2013

demos/demo_sink_create_woodblock.py: generate a woodblock like sound

--- /dev/null
+++ b/python/demos/demo_sink_create_woodblock.py
@@ -1,0 +1,38 @@
+#! /usr/bin/env python
+
+import sys
+from math import sin, pi
+from aubio import sink
+from numpy import array
+
+if len(sys.argv) != 2:
+    print 'usage: %s <outputfile>' % sys.argv[0]
+    sys.exit(1)
+
+samplerate = 44100      # in Hz
+pitch = 2200            # in Hz
+blocksize = 256         # in samples
+duration = 0.02         # in seconds
+
+twopi = pi * 2.
+
+duration = int ( 44100 * duration ) # convert to samples
+attack = 3
+
+period = int ( float(samplerate) /  pitch )
+sinetone = [ 0.7 * sin(twopi * i/ period) for i in range(period) ] 
+sinetone *= int ( duration / period )
+sinetone = array(sinetone, dtype = 'float32')
+
+from math import exp, e
+for i in range(len(sinetone)):
+    sinetone[i] *= exp( - e * float(i) / len(sinetone))
+for i in range(attack):
+    sinetone[i] *= exp( e * (float(i) / attack - 1 ) )
+
+my_sink = sink(sys.argv[1], 44100)
+
+i = 0
+while i + blocksize < duration:
+    my_sink(sinetone[i:i+blocksize], blocksize)
+    i += blocksize