Key features
The plugin framework offers several advantages over traditional C-based opcode development:- C++ abstractions: Type-safe classes that wrap Csound’s C API
- Template-based design: Generic plugin base classes for different input/output configurations
- STL-style containers: Iterator-based access to arrays, audio signals, and fsig data
- Simplified memory management: RAII-style wrappers for Csound’s memory allocation
- Thread control: Clear specification of execution threads (i-time, k-rate, a-rate)
Plugin architecture
Plugins are built around a few core concepts:Base classes
The framework provides template base classes for different opcode types:Plugin<N, M>: For opcodes with N outputs and M inputsInPlug<N>: For opcodes with only inputs (no outputs, or multiple outputs/inputs)FPlugin<N, M>: For fsig (spectral) processing opcodes
Container classes
Utility classes provide convenient access to Csound data:AudioSig: Audio signal wrapper with sample-accurate offset handlingVector<T>: One-dimensional array containerFsig: Phase vocoder frame dataTable: Function table containerAuxMem<T>: Dynamic memory allocation using Csound’s allocator
Csound engine access
TheCsound class wraps the Csound engine, providing methods for:
- Error and warning messages
- System parameters (sample rate, control rate, channel count)
- MIDI information
- Memory allocation
- FFT operations
- Global variables
Thread types
Opcodes can run at different execution rates:Typical workflow
Creating a plugin opcode typically involves:- Define a struct/class inheriting from
Plugin<N, M>orInPlug<N> - Implement
init()for initialization - Implement
kperf()for k-rate oraperf()for a-rate processing - Optionally implement
deinit()for cleanup - Register the opcode using the
plugin<T>()template function - Export the registration function via
on_load()
Build system integration
Plugins are typically built as shared libraries that Csound loads dynamically. The framework supports two build modes:- BUILD_PLUGINS: Creates standalone plugin modules
- Static linking: Integrates opcodes directly into Csound
Next steps
C++ opcode framework
Detailed API reference for the plugin framework
Creating opcodes
Step-by-step guide to creating your first opcode
Examples
Real-world opcode implementations from the Csound codebase