File: 08_fft_spec.py

package info (click to toggle)
python-pyo 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,692 kB
  • sloc: ansic: 137,415; python: 135,293; makefile: 390; cpp: 242; sh: 163
file content (27 lines) | stat: -rw-r--r-- 679 bytes parent folder | download
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
#! /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 __future__ import division
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())