File: 08_fft_spec.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 (26 lines) | stat: -rw-r--r-- 647 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python
# encoding: utf-8
"""
Display the sonogram of a sound using a PyoMatrixObject.
A better display can be achieved by using a custom drawing.

After the playback ending, call "m.view()" from the
interpreter widget of the Server window to show the spectrum.

"""
from pyo import *

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

son = "../snds/baseballmajeur_m.aif"
info = sndinfo(son)
a = SfPlayer(son, mul=0.25).mix(1).out()

size = 512
m = NewMatrix(width=size, height=info[0] // size)

fin = FFT(a * 100, overlaps=1)
mag = Sqrt(fin["real"] * fin["real"] + fin["imag"] * fin["imag"])
rec = MatrixRec(mag * 2 - 1, m, 0).play()

s.gui(locals())