Python Module Pyo Trial

Pyo is a Python module written in C to help digital signal processing script creation. It provides a complete set of classes to build audio softwares, compose algorithmic musics or simply explore audio processing with a simple, mature and powerful programming language. from Pyo HP

PYO Install

Install on Windows10 64bi. PYO is sensitive to the Python version. Installation documentation says suppoting Python 2.7 (up to 1.0.1), 3.5 (up to 1.0.1), 3.6 and Python 3.7 and 3.8.

PYO1.0.01.0.11.0.21.0.31.0.4
Python 2.7okok
Python 3.5okok
Python 3.6ok
Python 3.7ok
Python 3.8ok

Here we use Python 3.8 and PYO 1.0.4. I downloaded the 3.8.10 installer python-3.8.10-amd64.exe from the Python download page. When you launch the installer and install Python, Python will be installed in the
C:\Users\<UserName>\AppData\Local\Programs\Python folder.

Python.exe and Python Script path are added in PATH of environment valiables as below.

C:\Users\<UsetName>\AppData\Local\Programs\Python\Python38
C:\Users\<UsetName>\AppData\Local\Programs\Python\Python38\Scripts

There is one techneque when adding to the PATH.Bring
C:\Users\<UsetName>\AppData\Local\Microsoft\WindowsApps to the bottom. If you don't do this, when you start python on the command line, python won't start and the Microsoft Store will start.

PYO can be installed by using next command refered from this site.

# for python 3.8 under Windows (`py` is the python launcher command)
>py -3.8 -m pip install --user pyo


Example Program

I try to run a example program. Sample programs are posted on this site.

# sintest.py
from pyo import *

# Boot PYO Server
s = Server().boot()

# Reduce gain by 20 dB
s.amp = 0.1

# Generate Sin Wave and output
a = Sine().out()

# Display GUI
s.gui(locals())

Save the program named sintest.py as UTF-8. When launched sintest.py from the command prompt, the following GUI is displayed. Press the Start button to start generating the sound, and move the Amplitude knob to change the volume of the sound.

>python sintest.py

Enter a.freq=200 in the Inspector Box below the window. The frequency of generating wave is changed to 200Hz.

By adding the following lines to the program, you can display a slider to edit the parameters of the sine wave.

# Display sliders for editing parameters
a.ctrl(title="SIN Wave")

And by adding following lines, you can display the wave shape.

# Display waveshape
sp = Scope(a)
sp.setGain(0.5) # Vertical axis magnification 0.5 => -6dB
sp.poll(1)      # Display waveshape with start button


Wave Shape Type

Sawthooth
The program for sawtooth wave generating is shown below. The order of the line that generate the table determines the number of overtones. This number determins the sharpness of the shape of the waveform. The larger the number, the sharper the shape of the waveform. Instead, it takes time to generate the waveform.

from pyo import *

# Boot PYO Server
s = Server().boot()

# Make Sawthooth Table
t = SawTable(order=12).normalize() # ←←←←←

# Ganarate Wave using the Table
a = Osc(table=t, freq=100, mul=0.5).out()

# Display waveshape
sp = Scope(a)
sp.setGain(0.5)
sp.poll(1)

# Display GUI
s.gui(locals())

Square
Modified the line indicated by the arrow.

# Make Square Table
t = SquareTable(order=15).normalize()

Triangle
Modified the line indicated by the arrow. Looking at the waveform, a waveform that looks round for a triangle wave is generated.

# Make Triangle Table
t = TriangleTable(order=12).normalize()


Receiving MIDI

It's easy to use Raw Midi to receive MIDI.

from pyo import *

# List of MIDI Device
pm_list_devices()

# Boot PYO Server
s = Server()

# Specify the ID of the target MIDI device (listed by pm_list_devices ()) 
# in setMidiInputDevice () of the server. ID = 99 opens all connected MIDI devices.
# Before start PYO server, need to connect MIDI device.
s.setMidiInputDevice (99)

# Start PYO Server
s.boot().start()

print("Play with your Midi controllers...")

# Display MIDI device by HEX
def event(status, data1, data2):
    print("%02x %02x %02x" % (status, data1, data2))

# Receive MIDI raw data
scan = RawMidi(event)

# Display GUI
s.gui(locals())

After connecting a MIDI device to your computer, you can run the above program to list the MIDI devices and display the MIDI data.



Sounds by MIDI

This program is to sound by MIDI. To play a keyboard and receives MIDI Note On with Pyo to make a sound. Receive MIDI Note On with a function called Notein. The volume of Note is determined by the property 'velocity', which represents the strength of playing, which the function has. Port seems to be a function that generates portamento, but here it generates a amplitue p to make a sound only when the key is pressed. Also, since the property 'pitch' of Notein represents the frequency(Hz), this property is used as it is as the transmission frequency freq to control the generator Osc.

from pyo import *

# List of MIDI Device
pm_list_devices()

# Boot PYO Server
s = Server()

# Before start PYO server, need to connect MIDI device.
s.setMidiInputDevice(99) 

# Start PYO Server
s.boot().start()

# Receive NoteOns with four polyphonic.
notes = Notein(poly=4, scale=1, mul=1.0) 

# Make Sawthooth Table
t=SawTable(order=12).normalize()

# p =1 when getting NoteOn, p=0 when the key is released.
p = Port(notes['velocity'], .001, 0.01) 

# Generate Tone with frequency and amplitude, mul.
a = Osc(table=t,freq=notes['pitch'], mul=p).out()

sp=Scope(a)
sp.setGain(0.5)
sp.setLength(1.0) # holizintal axis 1sec
sp.poll(1)

s.gui(locals())