Architecture
The Csound C API follows an instance-based design where you create and manageCSOUND instances:
Core workflow
A typical Csound application follows this sequence:- Initialize - Call
csoundInitialize()andcsoundCreate() - Configure - Set options with
csoundSetOption() - Compile - Load instruments with
csoundCompile()orcsoundCompileOrc() - Start - Prepare for performance with
csoundStart() - Perform - Process audio in a loop with
csoundPerformKsmps() - Cleanup - Call
csoundReset()andcsoundDestroy()
Example: Complete performance cycle
Return values and error handling
Most Csound API functions return status codes defined in theCSOUND_STATUS enum:
Operation completed successfully
Unspecified failure
Failed during initialization
Failed during performance
Failed to allocate requested memory
Termination requested by SIGINT or SIGTERM
Thread safety
EachCSOUND instance is independent and can be used in separate threads. However, operations on a single instance are generally not thread-safe. When accessing channels or shared data:
- Use
csoundLockChannel()andcsoundUnlockChannel()for manual synchronization - Use atomic operations for control channels when available
- Prefer the thread-safe channel get/set functions
Data types
Opaque pointer to a Csound instance. All API functions require this pointer.
Audio sample type, either
float or double depending on build configuration. Check with csoundGetSizeOfMYFLT().Configuration parameters structure. Access with
csoundGetParams().API categories
The C API is organized into functional groups:- Initialization - Creating and configuring Csound instances
- Compilation - Loading and compiling orchestras and scores
- Performance - Real-time audio processing
- Audio I/O - Direct access to audio buffers
- Messaging - Message callbacks and logging
- Channels - Software bus communication
- Tables - Function table manipulation
- Utilities - Helper functions and system information
Platform considerations
The API uses platform-specific visibility macros:PUBLIC- Marks functions exported from the library- Functions are available on all platforms (Windows, macOS, Linux, WASI)
- Header file:
csound.hcontains all public API declarations