~ubuntu-branches/debian/sid/python-pyo/sid

« back to all changes in this revision

Viewing changes to examples/fft/05_fft_delay.py

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-06-08 20:35:45 UTC
  • Revision ID: package-import@ubuntu.com-20120608203545-4z7kcf2lgvpsk18y
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
"""
 
4
Apply spectral delays on a sound.
 
5
 
 
6
"""
 
7
from pyo import *
 
8
 
 
9
s = Server().boot()
 
10
 
 
11
snd = "../snds/ounkmaster.aif"
 
12
chnls = sndinfo(snd)[3]
 
13
size = 1024
 
14
olaps = 4
 
15
num = olaps*chnls # number of streams for ffts
 
16
 
 
17
src = SfPlayer(snd, loop=True, mul=.15)
 
18
delsrc = Delay(src, delay=size/s.getSamplingRate()*2).out()
 
19
 
 
20
# duplicates bin regions and delays to match the number of channels * overlaps
 
21
def duplicate(li, num):
 
22
    tmp = [x for x in li for i in range(num)]
 
23
    return tmp
 
24
 
 
25
binmin = duplicate([3,10,20,27,55,100], num)
 
26
binmax = duplicate([5,15,30,40,80,145], num)
 
27
delays = duplicate([80,20,40,100,60,120], num)
 
28
# delays conversion : number of frames -> seconds
 
29
for i in range(len(delays)):
 
30
    delays[i] = delays[i] * (size/2) / s.getSamplingRate()
 
31
 
 
32
fin = FFT(src*1.25, size=size, overlaps=olaps)
 
33
 
 
34
# splits regions between `binmins` and `binmaxs` with time variation
 
35
lfo = Sine(.1, mul=.65, add=1.35)
 
36
bins = Between(fin["bin"], min=binmin, max=binmax*lfo)
 
37
swre = fin["real"] * bins; swim = fin["imag"] * bins
 
38
# apply delays with mix to match `num` audio streams
 
39
delre = Delay(swre, delay=delays, feedback=.7, maxdelay=2).mix(num)
 
40
delim = Delay(swim, delay=delays, feedback=.7, maxdelay=2).mix(num)
 
41
 
 
42
fout = IFFT(delre, delim, size=size, overlaps=olaps).mix(chnls).out()
 
43
 
 
44
s.gui(locals())