File: 07-hilbert-transform.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 (54 lines) | stat: -rw-r--r-- 1,319 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
07-hilbert-transform.py - Barberpole-like phasing effect.

This example uses two frequency shifters (based on complex
modulation) linearly shifting the frequency content of a sound.

Frequency shifting is similar to ring modulation, except the
upper and lower sidebands are separated into individual outputs.

"""
from pyo import *


class ComplexMod:
    """
    Complex modulation used to shift the frequency
    spectrum of the input sound.
    """

    def __init__(self, hilb, freq):
        # Quadrature oscillator (sine, cosine).
        self._quad = Sine(freq, [0, 0.25])
        # real * cosine.
        self._mod1 = hilb["real"] * self._quad[1]
        # imaginary * sine.
        self._mod2 = hilb["imag"] * self._quad[0]
        # Up shift corresponds to the sum frequencies.
        self._up = (self._mod1 + self._mod2) * 0.7

    def out(self, chnl=0):
        self._up.out(chnl)
        return self


s = Server().boot()

# Large spectrum source.
src = PinkNoise(0.2)

# Apply the Hilbert transform.
hilb = Hilbert(src)

# LFOs controlling the amount of frequency shifting.
lf1 = Sine(0.03, mul=6)
lf2 = Sine(0.05, mul=6)

# Stereo Single-Sideband Modulation.
wetl = ComplexMod(hilb, lf1).out()
wetr = ComplexMod(hilb, lf2).out(1)

# Mixed with the dry sound.
dry = src.mix(2).out()

s.gui(locals())