File: 02_fft_cross.py

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (36 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
# encoding: utf-8
"""
Performs the cross-synthesis of two sounds.

"""
from pyo import *

s = Server(duplex=0).boot()

snd1 = SfPlayer("../snds/baseballmajeur_m.aif", loop=True).mix(2)
snd2 = FM(carrier=[75, 100, 125, 150], ratio=[0.999, 0.5005], index=20, mul=0.4).mix(2)

size = 1024
olaps = 4

fin1 = FFT(snd1, size=size, overlaps=olaps)
fin2 = FFT(snd2, size=size, overlaps=olaps)

# get the magnitude of the first sound
mag = Sqrt(fin1["real"] * fin1["real"] + fin1["imag"] * fin1["imag"], mul=10)
# scale `real` and `imag` parts of the second sound by the magnitude of the first one
real = fin2["real"] * mag
imag = fin2["imag"] * mag

fout = IFFT(real, imag, size=size, overlaps=olaps)
ffout = fout.mix(2).out()

# change of fft size must be done on all fft and ifft objects at the same time!
def setSize(x):
    fin1.size = x
    fin2.size = x
    fout.size = x


s.gui(locals())