feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 2fcb973 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
|
Rev | Line | |
---|
[87b0c03] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | from math import sin, pi |
---|
| 5 | from aubio import sink |
---|
| 6 | from numpy import array |
---|
| 7 | |
---|
| 8 | if len(sys.argv) != 2: |
---|
| 9 | print 'usage: %s <outputfile>' % sys.argv[0] |
---|
| 10 | sys.exit(1) |
---|
| 11 | |
---|
| 12 | samplerate = 44100 # in Hz |
---|
| 13 | pitch = 2200 # in Hz |
---|
| 14 | blocksize = 256 # in samples |
---|
| 15 | duration = 0.02 # in seconds |
---|
| 16 | |
---|
| 17 | twopi = pi * 2. |
---|
| 18 | |
---|
| 19 | duration = int ( 44100 * duration ) # convert to samples |
---|
| 20 | attack = 3 |
---|
| 21 | |
---|
| 22 | period = int ( float(samplerate) / pitch ) |
---|
| 23 | sinetone = [ 0.7 * sin(twopi * i/ period) for i in range(period) ] |
---|
| 24 | sinetone *= int ( duration / period ) |
---|
| 25 | sinetone = array(sinetone, dtype = 'float32') |
---|
| 26 | |
---|
| 27 | from math import exp, e |
---|
| 28 | for i in range(len(sinetone)): |
---|
| 29 | sinetone[i] *= exp( - e * float(i) / len(sinetone)) |
---|
| 30 | for i in range(attack): |
---|
| 31 | sinetone[i] *= exp( e * (float(i) / attack - 1 ) ) |
---|
| 32 | |
---|
| 33 | my_sink = sink(sys.argv[1], 44100) |
---|
| 34 | |
---|
| 35 | i = 0 |
---|
| 36 | while i + blocksize < duration: |
---|
| 37 | my_sink(sinetone[i:i+blocksize], blocksize) |
---|
| 38 | i += blocksize |
---|
Note: See
TracBrowser
for help on using the repository browser.