libcsound
Python bindings for Csound (fork of ctcsound)
These bindings require Csound 7 or later.
Installation
Csound
Csound does not need to be installed manually: when it cannot be found, libcsound installs csound 7 automatically on import, on Linux, macOS and Windows (unless LIBCSOUND_INSTALL is set to 0 or false). On macOS the install runs under sudo, so it needs either an interactive terminal or passwordless sudo (as on CI runners); on Windows it is machine-wide and needs Administrator rights, so an interactive or already-elevated session is required.
To install csound manually instead, use the official installers. See https://github.com/csound/csound/releases
In Linux / macOS:
curl -fsSL https://csound-plugins.github.io/getcsound.sh | bash
In Windows:
irm https://csound-plugins.github.io/getcsound.ps1 | iex
This installs the latest version of csound 7.
libcsound
pip install libcsound
Environment variables
The csound shared library is located and loaded when libcsound is imported, so these variables must be set before importing it.
LIBCSOUNDPATH: absolute path to the csound shared library to load. When set, no other search is performed. If unset, the library is searched in the system path.
LIBCSOUND_INSTALL: set to 0 or false to disable the automatic installation of csound when it cannot be found.
Quick Start
Rendering in real-time using a render thread
import libcsound
csound = libcsound.Csound()
csound.setOption('-odac')
csound.compileOrc(r'''
sr = 44100 ; Modify to fit your system
ksmps = 64
nchnls = 2
0dbfs = 1
instr 1
kchan init -1
kchan = (kchan + metro:k(1)) % nchnls
if changed:k(kchan) == 1 then
println "Channel: %d", kchan + 1
endif
asig = pinker() * 0.2
outch kchan + 1, asig
endin
''')
csound.start()
thread = csound.performanceThread()
thread.play()
# Schedule an instance of instr 1 for 10 seconds
thread.scoreEvent(0, "i", [1, 0, 10])
input("Press any key to stop...\n")
thread.stop()
thread.join()
csound.destroy()
Render offline
import libcsound
csound = libcsound.Csound()
csound.setOption('-ooutfile.wav')
csound.compileOrc(r'''
sr = 44100
ksmps = 64
nchnls = 2
0dbfs = 1
instr 1
kchan init -1
kchan = (kchan + metro:k(1)) % nchnls
if changed:k(kchan) == 1 then
println "Channel: %d", kchan + 1
endif
asig = pinker() * 0.2
outch kchan + 1, asig
endin
''')
csound.start()
csound.event("i", [1, 0, 10])
csound.setEndMarker(10)
# Perform until the end of the score
while not csound.performKsmps():
pass
Documentation
Metadata
Release files for libcsound 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| libcsound-1.0.0.tar.gz | 1.3 MB | Details |
Release files / libcsound-1.0.0.tar.gz
| Download URL | libcsound-1.0.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6260aba9e5de5d79b2eb70ef4ff90326f27e62c42b9e20d9ce7617048193913c
|
|
BLAKE2b-256 checksum How to use checksums |
126918c73cc52062e00636ff8737323c3bf067b0a3bb9c228dd1e275f586be55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|