source: python/demos/demo_sink_create_woodblock.py @ f36277c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since f36277c was 87b0c03, checked in by Paul Brossier <piem@piem.org>, 12 years ago

demos/demo_sink_create_woodblock.py: generate a woodblock like sound

  • Property mode set to 100755
File size: 951 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4from math import sin, pi
5from aubio import sink
6from numpy import array
7
8if len(sys.argv) != 2:
9    print 'usage: %s <outputfile>' % sys.argv[0]
10    sys.exit(1)
11
12samplerate = 44100      # in Hz
13pitch = 2200            # in Hz
14blocksize = 256         # in samples
15duration = 0.02         # in seconds
16
17twopi = pi * 2.
18
19duration = int ( 44100 * duration ) # convert to samples
20attack = 3
21
22period = int ( float(samplerate) /  pitch )
23sinetone = [ 0.7 * sin(twopi * i/ period) for i in range(period) ] 
24sinetone *= int ( duration / period )
25sinetone = array(sinetone, dtype = 'float32')
26
27from math import exp, e
28for i in range(len(sinetone)):
29    sinetone[i] *= exp( - e * float(i) / len(sinetone))
30for i in range(attack):
31    sinetone[i] *= exp( e * (float(i) / attack - 1 ) )
32
33my_sink = sink(sys.argv[1], 44100)
34
35i = 0
36while i + blocksize < duration:
37    my_sink(sinetone[i:i+blocksize], blocksize)
38    i += blocksize
Note: See TracBrowser for help on using the repository browser.