Block based synthesis and music library
Project description
Klang
Block based synthesis and music library for Python. Klang is German for sound.
Getting Started
Prerequisites
We use Python bindings for PortAudio and RtMidi. On Mac they can be installed via Homebrew.
Installing
Klang can be installed via pip or the setup.py. Note that there is a C extension which needs to be compiled (klang/audio/_envelope.c
).
Running the tests
Tests can be run via with
python3 setup.py test
And coding style tests
PEP8 / Google flavored. With the one exception for variable and argument names (lowerCamelCase
). Function and methods are written_like_this()
.
Primer
Klang provides various audio related blocks, which can be connected to each other. In the following script we create a 440 Hz sine oscillator which output gets send to the sound card.
from klang.audio import Oscillator, Dac
from klang.klang import run_klang
osc = Oscillator(frequency=440.)
dac = Dac(nChannels=1)
osc.output.connect(dac.input)
run_klang(dac)
Each block can have multiple in- and outputs (inputs
and outputs
list attributes). input
and output
are a shorthand property to the first (or primary) in- or output.
Connections
There are two different kind of connections inside Klang: Values and Messages. Values can be any kind of Python object which get polled in each cycle. Messages are a sent to a message queue. The former is mostly used to propgate audio samples and modulation signals through the network (Numpy arrays as values). The latter is used for discrete messages like note messages.
There are also corresponding Relay connections. These are used to build composite blocks (blocks which contain there own network of child blocks). Relays can be used to interface between the inside and outside of an composite block.
Defining The Network
Use the connections connect
method for connecting with other in- or outputs. As a shorthand there are two overloaded operators:
- Pipe operator
|
: Connect multiple blocks in series. - Mix operator
+
: Mix multiple value outputs together.
# Pipe operator
a | b | c
# Is equivalanet to:
# >>> a.output.connect(b.input)
# ... b.output.connect(c.input)
# Mix operator
mixer = a + b + c
# Is equivalanet to:
# >>> mixer = Mixer(nInputs=0)
# ... mixer.add_new_channel()
# ... a.output.connect(mixer.inputs[-1])
# ... mixer.add_new_channel()
# ... b.output.connect(mixer.inputs[-1])
# ... mixer.add_new_channel()
# ... c.output.connect(mixer.inputs[-1])
Authors
- Alexander Theler - Initial work - GitHub
Acknowledgments
Thanks to:
- Nico Neureiter
- Andreas Steiner
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file klang-0.1.2.tar.gz
.
File metadata
- Download URL: klang-0.1.2.tar.gz
- Upload date:
- Size: 73.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3cc0e2298259e635fe88d0b1f2bb55458013301f3e662a5ebeced10103385bc |
|
MD5 | 07a4036fcc0c691c76ddb2a6ef87b730 |
|
BLAKE2b-256 | 377b6ece0c673fa96d2a573ffe73b660336ad633d5bb708b6d8a1a4de0689f21 |
File details
Details for the file klang-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: klang-0.1.2-cp37-cp37m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 99.0 kB
- Tags: CPython 3.7m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4bab0ead0594ea522de2b467b50b49232153c818928202c94db9f66a008c7e5 |
|
MD5 | a754a25a2730536f6e21ab91e8c4d22f |
|
BLAKE2b-256 | c55b647216f8d16cd68427abcf762cba47d7e1fb17dc596d287cf0e8d04fc9cc |