Skip to main content

libcsound

Python bindings for Csound (fork of ctcsound)

These bindings can be used with any version of csound >= 6.18. Csound 7 is explicitely supported and is the recommended version.

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 and Windows the automatic install needs an interactive, elevated session, so in non-interactive environments csound must be installed beforehand.

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()

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.scoreEvent("i", [1, 0, 10])
csound.setEndMarker(10)
# Perform until the end of the score
while not csound.performKsmps():
    pass

Documentation

https://libcsound.readthedocs.io/en/latest/

Metadata

Release files for libcsound 0.17.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libcsound 0.17.4
File Size Uploaded
libcsound-0.17.4.tar.gz 1.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for libcsound 0.17.4
File Interpreter ABI Platform
libcsound-0.17.4-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / libcsound-0.17.4.tar.gz

Download URL libcsound-0.17.4.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
a9d1786ef880066eabb88e9a54b1f1ccaa84a1c7cb9046404ef9eff2e16ab8f5
BLAKE2b-256 checksum
How to use checksums
b3858cacb9290df36308882cbfb5ae2a160d693d2b4197012f7aa0dbddbbe9a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.29

Release files / libcsound-0.17.4-py3-none-any.whl

Download URL libcsound-0.17.4-py3-none-any.whl
Size 208.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98e55e4a14c38682d5d8606df567b7cfe28c5043214cf6c31db24376a59a15e8
BLAKE2b-256 checksum
How to use checksums
c839d4bd4b643a2ffcfe20af60872ecb9fe736df15ed3a970c495a1aacc23007
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.29

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page