Basic structure
Every plugin opcode follows this basic pattern:Step-by-step tutorial
Let’s create a simple k-rate amplitude scaler opcode.Define the opcode class
Define a struct inheriting from
Plugin<1, 2> (1 output, 2 inputs):myscaler.cpp
Complete example
Here’s the completemyscaler.cpp file:
myscaler.cpp
Advanced patterns
Working with arrays
For array operations, use themyfltvec type:
Audio-rate processing
For a-rate opcodes, useAudioSig for sample-accurate processing:
Using auxiliary memory
For dynamic buffers, useAuxMem<T>:
Variable argument count
For opcodes with variable inputs, usein_count():
Template-based opcodes
Create families of opcodes using templates:Best practices
Error handling
Error handling
Always validate inputs and return appropriate error codes:
Memory management
Memory management
Use
AuxMem<T> for Csound-managed memory, not new/delete:Sample-accurate processing
Sample-accurate processing
For a-rate opcodes, use
AudioSig to respect sample offsets:Thread specification
Thread specification
Choose the correct thread type for your opcode:
thread::i- Init-time only (no perf processing)thread::k- K-rate only (no init)thread::ik- Both init and k-ratethread::a- A-rate only (no init)thread::ia- Both init and a-rate
Build integration
Add your opcode toOpcodes/CMakeLists.txt:
Testing
Create a test.csd file:
test_myscaler.csd
Next steps
Examples
Study real-world opcode implementations
API reference
Complete framework documentation