C ABI Reference
The C ABI is the stable boundary every language binding and plugin host builds on; see C++ API Reference for the C++ surface and C ABI versions for struct versioning. The room-acoustics calls are covered under Geometric Room Acoustics.
Handles, analysis and utilities
For FFI integration. Two parallel entry-point styles are provided: handle-based (takes a SonareAudio*) and sample-based (takes a raw float* buffer).
#include <sonare/sonare_c.h>
// Audio handle
SonareError sonare_audio_from_buffer(const float* data, size_t length, int sample_rate,
SonareAudio** out);
SonareError sonare_audio_from_memory(const uint8_t* data, size_t length, SonareAudio** out);
// options NULL downmixes; SonareAudioFileOptions.channel_index selects one source channel
SonareError sonare_audio_from_file(const char* path, const SonareAudioFileOptions* options,
SonareAudio** out); // Not available in WASM
SonareError sonare_audio_file_num_channels(const char* path, int* out_channels); // Not available in WASM
void sonare_audio_destroy(SonareAudio* audio);
const float* sonare_audio_data(const SonareAudio* audio);
size_t sonare_audio_length(const SonareAudio* audio);
int sonare_audio_sample_rate(const SonareAudio* audio);
float sonare_audio_duration_sec(const SonareAudio* audio);
// Handle-based analysis (avoids copying samples across the FFI boundary)
SonareError sonare_audio_detect_bpm(const SonareAudio* audio, float bpm_min, float bpm_max,
float* out_bpm);
SonareError sonare_audio_detect_key(const SonareAudio* audio, SonareKey* out_key);
SonareError sonare_audio_detect_beats(const SonareAudio* audio, float bpm_min, float bpm_max,
float** out_times, size_t* out_count);
SonareError sonare_audio_detect_downbeats(const SonareAudio* audio,
float** out_times, size_t* out_count);
SonareError sonare_audio_detect_onsets(const SonareAudio* audio,
float** out_times, size_t* out_count);
// Sample-based analysis (use when you already have a raw float buffer)
SonareError sonare_detect_bpm(const float* samples, size_t length, int sample_rate,
float bpm_min, float bpm_max, float* out_bpm);
SonareError sonare_detect_key(const float* samples, size_t length, int sample_rate,
const SonareDetectKeyOptions* options, SonareKey* out_key,
float* out_tuning_cents);
SonareError sonare_detect_beats(const float* samples, size_t length, int sample_rate,
float bpm_min, float bpm_max,
float** out_times, size_t* out_count);
SonareError sonare_detect_downbeats(const float* samples, size_t length, int sample_rate,
float** out_times, size_t* out_count);
SonareError sonare_detect_onsets(const float* samples, size_t length, int sample_rate,
const SonareOnsetDetectConfig* config,
float** out_times, size_t* out_count);
// Full-result analysis serialized to a camelCase JSON object (chords, sections,
// timbre, dynamics, rhythm, melody, form, per-beat strength). *out_json is
// heap-allocated; release it with sonare_free_string. options NULL takes the
// defaults of sonare_music_analyze_options_init; its progress_callback and
// cancel_callback report and stop the run.
SonareError sonare_analyze_json(const float* samples, size_t length, int sample_rate,
const SonareMusicAnalyzeOptions* options, char** out_json);
// Memory management
void sonare_free_floats(float* ptr);
void sonare_free_ints(int* ptr);
void sonare_free_bytes(uint8_t* ptr);
void sonare_free_string(char* ptr); // heap char* from *_json and other string-returning C ABI calls
void sonare_free_key_candidates(SonareKeyCandidate* ptr); // arrays from sonare_detect_key_candidates
// Every result struct has its own matching releaser named after the struct,
// e.g. sonare_free_stft_result / _mel_result / _mfcc_result / _chroma_result /
// _pitch_result / _hpss_result. Release a struct only with its own function.
// Resampling and the 12-TET scale quantizer (both declared in sonare_c.h itself)
SonareError sonare_resample(const float* samples, size_t length, int sample_rate,
int target_sample_rate, float** out, size_t* out_length); // free *out with sonare_free_floats
SonareError sonare_scale_quantize_midi(int root, uint16_t mode_mask, float scale_reference_midi,
float midi, float* out_quantized_midi);
SonareError sonare_scale_correction_semitones(int root, uint16_t mode_mask, float scale_reference_midi,
float midi, float* out_semitones);
SonareError sonare_scale_pitch_class_enabled(int root, uint16_t mode_mask, int pitch_class,
int* out_enabled);
// Utility
const char* sonare_error_message(SonareError error);
const char* sonare_last_error_message(void); // thread-local detail for the last failure
SonareError sonare_last_error_code(void); // code recorded beside the last message; why a handle-returning call returned NULL
size_t sonare_last_diagnostic_count(void); // non-fatal warnings the last call published on this thread (e.g. an undeclared send routed through an implicit aux)
SonareError sonare_last_diagnostic(size_t index, SonareDiagnostic* out); // code, message and severity of one of them
const char* sonare_version(void);
uint32_t sonare_abi_version(void); // packed aggregate ABI version; compare against compile-time SONARE_ABI_VERSION to detect a struct-layout/contract mismatch before exchanging POD across the boundary
uint32_t sonare_engine_abi_version(void); // realtime command-queue ABI, not part of sonare_abi_version()
int sonare_has_feature(const char* name); // 1 if the build has the named feature ("ffmpeg" decodes M4A/AAC/FLAC/OGG, "vocalEdit", "mastering", ...), 0 otherwise
SonareError sonare_capabilities_json(char** out_json); // version, ABI versions, features and decode backends; release with sonare_free_stringEvery C ABI call that returns SonareError clears the thread-local detail and the previous error code on entry, preventing a stale message from leaking into a later result. A call that cannot allocate returns an error code instead of terminating the host, and leaves every out-pointer NULL and every count 0. Diagnostic accessors and void cleanup helpers deliberately do not clear it, so callers may release partial output before reading sonare_last_error_message(). Every failure sets that message. A call that succeeds with a recoverable problem publishes it through sonare_last_diagnostic_count() and sonare_last_diagnostic(index, &out) instead; each SonareDiagnostic carries a stable dotted code, a message and a severity, valid until the next call that records or clears a diagnostic on the thread.
Error codes follow one split. A refused argument (out of range, non-finite, an unknown id, name or enum ordinal) is SONARE_ERROR_INVALID_PARAMETER with a message naming it. A call that fails because of earlier configuration or the object's state is SONARE_ERROR_INVALID_STATE: an unprepared engine, a full strip, MIDI CC, controller-binding, external-destination or sidechain table, a bus or lane change that earlier routing, pan or retained delay forbids, a master-strip setter before sonare_engine_set_master_strip_json, a full instrument rack, a bound instrument that cannot take already-scheduled SysEx, and a project bounce or clip export whose derived length or event count the engine or file format cannot hold. SONARE_ERROR_OUT_OF_MEMORY is reserved for a failed allocation, which leaves the state unchanged.
SonareKey carries only root, mode, and confidence. There is no name field on the struct — format the human-readable name yourself from the enum values.
sonare_audio_file_num_channels(path, out_channels) probes a file's source channel count without decoding it. A SonareAudio handle carries one plane, so sonare_audio_from_file downmixes unless SonareAudioFileOptions.channel_index (seed the struct with sonare_audio_file_options_init) names one source channel; SONARE_AUDIO_CHANNEL_DOWNMIX (-1) is the default. Neither call is available in WASM. Release a handle with sonare_audio_destroy, not a sonare_free_* function.
Each operation has one entry point, and an operation is extended through an options struct rather than a second function: *_options_init seeds the struct with every default and writes struct_size, and passing NULL takes those defaults. The all-in-one analysis (chords, sections, timbre, dynamics, rhythm, melody, and form, with per-beat strength) is sonare_analyze_json, which returns a camelCase JSON string you free with sonare_free_string; per-stage progress and cancellation are the progress_callback and cancel_callback members of SonareMusicAnalyzeOptions.
Example: load audio and detect BPM, key and beats
#include <sonare/sonare_c.h>
#include <stdio.h>
static const char* kPitchNames[] = {
"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
// Indexed by SonareMode: SONARE_MODE_MAJOR (0) through SONARE_MODE_LOCRIAN (6).
static const char* kModeNames[] = {
"major", "minor", "dorian", "phrygian", "lydian", "mixolydian", "locrian"};
int main() {
SonareAudio* audio = NULL;
SonareError err;
// Load audio
err = sonare_audio_from_file("music.mp3", NULL, &audio);
if (err != SONARE_OK) {
printf("Error: %s\n", sonare_error_message(err));
return 1;
}
// Detect BPM (uses the audio handle directly, no extra data copy)
float bpm;
err = sonare_audio_detect_bpm(audio, 60.0f, 200.0f, &bpm);
if (err == SONARE_OK) {
printf("BPM: %.1f\n", bpm);
}
// Detect key (SonareKey holds root + mode + confidence)
SonareKey key;
err = sonare_audio_detect_key(audio, &key);
if (err == SONARE_OK) {
printf("Key: %s %s (confidence: %.0f%%)\n",
kPitchNames[key.root],
kModeNames[key.mode],
key.confidence * 100);
}
// Detect beats
float* beat_times = NULL;
size_t beat_count = 0;
err = sonare_audio_detect_beats(audio, 60.0f, 200.0f, &beat_times, &beat_count);
if (err == SONARE_OK) {
printf("Beats: %zu\n", beat_count);
sonare_free_floats(beat_times);
}
sonare_audio_destroy(audio);
return 0;
}Sample-based variants
If you already hold raw samples (e.g., from another audio source), use the sample-based variants instead of constructing a SonareAudio handle:
sonare_detect_bpm(samples, length, sample_rate, 60.0f, 200.0f, &out_bpm);
sonare_detect_key(samples, length, sample_rate, NULL, &out_key, &out_tuning_cents);
sonare_detect_beats(samples, length, sample_rate, 60.0f, 200.0f, &out_times, &out_count);
sonare_analyze_json(samples, length, sample_rate, NULL, &out_json);Helper families
Several helper families also have sample-based C ABI entry points:
| Family | Examples |
|---|---|
| Effects | sonare_hpss, sonare_time_stretch, sonare_phase_vocoder, sonare_pitch_shift, sonare_spectral_edit, sonare_normalize, sonare_normalize_rms, sonare_trim |
| Features | sonare_stft, sonare_mel_spectrogram, sonare_mfcc, sonare_chroma, sonare_chroma_cqt, sonare_nnls_chroma, sonare_spectral_*, sonare_pitch_yin, sonare_pitch_pyin |
| Room acoustics | sonare_analyze_impulse_response, sonare_synthesize_rir, sonare_estimate_room, sonare_room_morph, sonare_room_morph_stereo |
| Conversions and resampling | sonare_resample; see include/sonare/sonare_c.h for the full list |
sonare_chroma_cqt computes a constant-Q chromagram (librosa.feature.chroma_cqt equivalent) alongside the note-activation sonare_chroma. SonareMfccOptions carries fmin_hz, fmax_hz, htk and a cepstral lifter (0 disables liftering).
The FFT settings the bindings expose are options-struct members of the one entry point: SonareHpssOptions holds n_fft, hop_length and use_soft_mask, and sonare_hpss writes the residual through a non-NULL out_residual; SonareTimeStretchOptions and SonarePitchShiftOptions hold n_fft and hop_length; and SonareTrimOptions holds frame_length and hop_length. SonareAnalyzeImpulseResponseOptions holds min_decay_db, while SonareNnlsChromaOptions holds enable_stft_blend, stft_blend_weight, stft_blend_n_fft and the CQT hop_length.
Project and synth patch notes
A project or engine sample rate must be a whole number of hertz within its supported range (sonare_project_set_sample_rate takes [8000, 384000]); a fractional rate returns SONARE_ERROR_INVALID_PARAMETER, and project JSON with a fractional sample_rate fails to load with SONARE_ERROR_INVALID_FORMAT and the diagnostic invalid_sample_rate.
Project editing lives in sonare_c_project.h. sonare_project_set_clip_loop(project, clip_id, loop_mode, loop_length_ppq, loop_crossfade_ppq) accepts the optional equal-power seam crossfade as the final argument. It must be finite and non-negative; 0 keeps a hard loop. The engine clamps it to the available pre-roll and half the loop, and ignores it under warp.
Synth patches
SonareSynthPatch is the NativeSynth patch accepted by the synth_instruments list of SonareProjectBounceOptions (sonare_project_bounce) and by sonare_engine_set_synth_instrument. It leads with struct_size, written by sonare_synth_patch_init, which seeds the patch with the init values; a struct_size below sizeof(SonareSynthPatch) is refused with SONARE_ERROR_INVALID_PARAMETER. The layout is declared in sonare_c_types_analysis.h; beside the base numeric fields it carries the sample-engine block, series highpass, converter block, pitch_offset_cents, retrigger, engine_params / engine_param_count, the second presence word present_fields2 (bits SONARE_SYNTH_FIELD2_*) with drift_rate_hz, amp_delay_ms, amp_hold_ms, filter_delay_ms, filter_hold_ms and one_shot, and lfo_shape (SonareSynthLfoShape).
lfo_shape is SONARE_SYNTH_LFO_SHAPE_BASE (0, keep the base patch's), _TRIANGLE (1), _SINE (2) or _RANDOM (3, a smoothed sample-and-hold seeded per voice, so a bounce repeats it); it shapes both the vibrato and the tremolo LFO at every destination. filter_model also takes SONARE_SYNTH_FILTER_SVF_4POLE (5), an unsaturated 24 dB/octave lowpass built from two state-variable sections. sonare_synth_enum_names answers the sample loop mode, sample key track, retrigger, LFO shape, part rig mode and sample-descriptor loop mode tables as well (SONARE_SYNTH_ENUM_SAMPLE_LOOP_MODE, _SAMPLE_KEY_TRACK, _RETRIGGER, _LFO_SHAPE, _PART_RIG_MODE, _SAMPLE_DESC_LOOP_MODE).
retrigger is SONARE_SYNTH_RETRIGGER_BASE (0), SONARE_SYNTH_RETRIGGER_FREE (1), or SONARE_SYNTH_RETRIGGER_NOTE (2). FREE varies oscillator phases, unison jitter, drift, and engine-noise streams per note; NOTE derives them from the note number, so the same note after its tail ends renders the same samples. Neither mode resets state outside the voice, such as controllers, shared instrument resonances, or effect tails.
The present_fields mask has 31 bits in use and present_fields2 is the second word; a further extension appends another presence word rather than widening either. Enum fields have no presence bits because zero keeps the base, while every real enum value is non-zero. Setting SONARE_SYNTH_FIELD_MOD_ROUTINGS with num_mod_routings == 0 clears the base mod matrix; a non-empty table replaces it.
engine_params is a borrowed list of SonareSynthEngineParam {key, value} that sets the selected engine's own model fields by key (bow force, breath pressure, lip tension, strike position, FM operator levels, the FM algorithm, mode ratios). Keys are the engine section's fields in lowerCamelCase (bowForce, ranks2.level); an unknown key, another engine's key, a key given twice, a non-finite value or a value outside the field's range fails the call with SONARE_ERROR_INVALID_PARAMETER naming the key. Every other numeric patch field is held to the same rule: a non-finite value or one outside the range sonare_synth_patch_param_info() publishes is refused rather than clamped, as is a num_mod_routings outside [0, 8] and a struct_size below the struct's size (on an SF2 instrument config too). A modulation source or destination ordinal outside its enum, and a modulation depth that is non-finite or beyond ±9600 destination units, are refused likewise. sonare_synth_engine_param_info(engine_mode, &json) writes a JSON array of descriptors for an engine's section fields, and sonare_synth_patch_param_info(&json) one for every numeric patch field plus one_shot; release either string with sonare_free_string. The default and sample modes answer []. Each descriptor is {name, type, integer, min, max, default, unit} plus, for a field that only reaches the voice under conditions on other fields, activeWhen: an array of alternatives, each a list of {key, scope, relation, value} that must all hold. The field reaches the voice when every condition of at least one alternative holds, which is what a UI needs to gray out an inactive control. A patch that sets only an engine mode voices that engine's base preset.
Values the C ABI refuses rather than clamps or reads as a default (all SONARE_ERROR_INVALID_PARAMETER):
- Mixer pan outside
[-1, 1]and width outside[0, 2], insonare_project_set_track_pan, the C mixer strip, track lanes and automation breakpoints; a lane fader outside the fader range. - Mixer true-peak oversampling other than 4 or 8 (
SonareMixerAddStripOptions.true_peak_oversample, 4 by default). - An enum ordinal outside its enum, for synth modulation sources and destinations, sample loop modes and key tracks,
norm_type(0 to 3), the room-estimate mode, late-reverb model, material preset, pitch class, mode, vocal-edit target, formant and merge modes, dither and automation curve shapes. - A graph connection
mixother than 0 (replace) or 1 (add). A zero-initialized connection is replace, so set 1 on every edge that should sum. - A non-finite
top_dbinsonare_trim_silenceandsonare_split_silence, a non-finite pre-emphasis or de-emphasis coefficient or initial value, and a negative or non-finite note-segmentationsegmentation_threshold_centsormin_note_ms. - A hum
fundamental_hz±search_range_hzwindow outside[1 Hz, 0.49 × sample rate]. - A negative seek position, and an enabled punch range with no frames.
- A realtime voice-changer configuration value that is non-finite or out of range: the handle keeps its previous configuration, and the message names the field and its range.
The librosa-parity helpers are also exposed through the C API:
| Category | Helpers |
|---|---|
| Emphasis and silence | sonare_preemphasis, sonare_deemphasis, sonare_trim_silence, sonare_split_silence |
| Framing and padding | sonare_frame_signal, sonare_pad_center, sonare_fix_length, sonare_fix_frames |
| Picking and normalization | sonare_peak_pick, sonare_vector_normalize |
| Feature utilities | sonare_pcen, sonare_tonnetz, sonare_tempogram, sonare_plp |
| dB conversions | sonare_power_to_db, sonare_amplitude_to_db, sonare_db_to_power, sonare_db_to_amplitude |
| Time/frame conversion | sonare_frames_to_samples, sonare_samples_to_frames |
| Decomposition / denoising | sonare_decompose (SonareDecomposeOptions.init is "random" or "nndsvd"), sonare_decompose_stems, sonare_decompose_stems_linked, sonare_nn_filter |
The linked stem entry point fits one shared NMF model from the channel-averaged magnitude, then applies the same soft mask to each channel's complex spectrum so interchannel phase and level stay aligned. Its flat output is indexed as (component, channel, sample), with num_channels channels per component; out_n_components receives the component count and out_frames the samples per (component, channel), equal to length. out_w and out_h use the same factor shapes as sonare_decompose_stems.
SonareError sonare_decompose_stems_linked(const float* const* channels, size_t num_channels,
size_t length, int sample_rate,
const SonareDecomposeStemsConfig* config, float** out,
size_t* out_frames, int* out_n_components, float** out_w,
size_t* out_w_length, float** out_h,
size_t* out_h_length);Header index
The current C ABI is split across focused headers. Use this index when a symbol is not in the compact examples above:
| Header | Surface |
|---|---|
sonare_c.h | Umbrella header. Transitively pulls in every other public header (the engine and voice-changer surfaces arrive through sonare_c_effects.h), and itself declares the aggregate SONARE_ABI_VERSION / sonare_abi_version(), sonare_resample, the 12-TET scale quantizer, and the per-result releasers |
sonare_c_types.h | Umbrella for the shared types and functions (sonare_c_types_*.h): audio handles, handle-based and sample-based detection, key candidates, downbeats, the options structs, engine lane/bus/send structs (SonareEngineTrackLane, SonareEngineBus, SonareEngineTrackSend), the SonareChannelLayout enum, error/diagnostic/version helpers, sonare_capabilities_json and sonare_has_feature |
sonare_c_project.h | Headless project/arrangement lifecycle, track/clip counts and editing (sonare_project_clip_count), MIDI events and MIDI-FX (sonare_project_set_midi_events, set_midi_fx, bake_midi_fx), compile and sonare_project_bounce (built-in, NativeSynth and SoundFont instruments are lists in SonareProjectBounceOptions), warp maps, loop-recording takes and comp segments, NativeSynth and SoundFont/SF2 instrument bindings, assist sidecar, chord/key annotations, SONARE_PROJECT_ABI_VERSION |
sonare_c_features.h | Focused analysis, STFT/mel/MFCC/chroma, inverse features, CQT/VQT, pitch, tempogram/PLP, LUFS |
sonare_c_effects.h | HPSS/editing DSP, region-based spectral editing (sonare_spectral_edit, modes GAIN/ATTENUATE/MUTE/HEAL), decomposition/remix helpers; it includes the engine and voice-changer headers |
sonare_c_engine.h | RealtimeEngine C ABI: transport (play/stop/seek/loop/tempo/time-signature), live parameter and automation-lane control, MIDI push/drain (CC, panic, SysEx, external MIDI destinations), capture, and telemetry (SonareEngineTelemetry, meter telemetry drain, SonareEngineTelemetryError) |
sonare_c_voice_changer.h | Realtime voice changer: create/destroy, config (POD and JSON, live-safe hand-off), per-block process (mono/interleaved/planar-stereo), built-in preset lookup, latency |
sonare_c_acoustic.h | RIR synthesis from room geometry, equivalent-room estimation, offline room-character morphing, SONARE_ACOUSTIC_ABI_VERSION |
sonare_c_metering.h | Peak/RMS/crest/DC/true peak (plus the both-channel sonare_metering_crest_factor_db_stereo), clipping, dynamic range, stereo correlation/width, vectorscope, phase scope, spectrum, multi-channel interleaved LUFS (sonare_lufs_interleaved) and EBU R128 loudness range (sonare_ebur128_loudness_range_lu) |
sonare_c_mastering.h | Presets, full chains (sonare_master_audio, with SonareMasterAudioOptions progress and cancel callbacks), named processors and the machine-readable processor catalog, assistant/profile/preview JSON and their *_stereo entry points, streaming mastering chain with latency and realized-stage inspection (sonare_streaming_mastering_chain_stage_names), streaming EQ, repair/dynamics one-shot helpers |
sonare_c_mixing.h | Channel strip controls, sends, buses, VCA groups, automation, meters, goniometer, scene presets |
sonare_c_streaming.h | StreamAnalyzer, bounded unread output (max_pending_frames), compact frame reads, pending/drop-aware updating stats, tuning/normalization controls |
sonare_c_transcribe.h | Audio to MIDI notes on a musical grid: SonareTranscribeConfig, sonare_transcribe, sonare_transcribe_config_init |
sonare_c_polyphony.h | Editing one note of a chord: SonarePolyphonicConfig, sonare_polyphonic_analyze, and a render back to audio |
sonare_c_vocal_edit.h, sonare_c_vocal_project.h | Offline, non-destructive editing of monophonic vocal notes, and binding the rendered result back to a project clip |
sonare_c_playback.h | Playback renderer: decoded movie audio to headphones (binaural) or stereo / 5.1 / 7.1 speakers; sonare_playback_renderer_render_offline(renderer, in, frames, in_channels, &out, &out_frames, &out_channels) resets an existing renderer and renders a whole buffer through it, matching sonare_playback_render_interleaved for the same configuration and leaving the diagnostics describing that render (release the output with sonare_free_floats) |
sonare_c_sample_bank.h | Host-supplied PCM and keymaps for the sample synthesis engine |
sonare_c_assist.h | Composition assist: the built-in rule-based generative modules, previewed or applied over a project |
sonare_c_types_*.h, sonare_c_project_*.h | Split-outs pulled in by sonare_c_types.h and sonare_c_project.h (analysis, engine and enum types; annotate, core, edit, external-stems, instruments, MIDI, part-rig and timeline project calls). Include the umbrella header rather than these |
Room acoustics, surround and realtime engine notes
For room acoustics in the C ABI:
SonareRirSynthConfigcovers geometry, absorption,material_preset,absorption_bands/scattering_bands,ism_order,seed,max_seconds,mixing_time_ms,crossfade_ms,late_model, and the air-absorption group (see Air absorption in large rooms).- Wall material is resolved in order: a non-zero
material_preset(SONARE_MATERIAL_PRESET_*) wins, then a non-NULLabsorption_bands, then scalarabsorption. SonareRoomEstimateConfigcovers aspect/absorption priors,reference_absorption,min_decay_db,noise_floor_margin_db,prefer_eyring,n_octave_bands, and analyzermode.sonare_room_estimate_config_initsetsreference_absorptionto the library default (0.15); every field is then read literally, so a value outside [0.01, 0.99], 0 included, is refused withSONARE_ERROR_INVALID_PARAMETER. The estimated volume scales with the cube of the prior.- Analyzer mode is one of
SONARE_ACOUSTIC_MODE_AUTO,SONARE_ACOUSTIC_MODE_BLIND, orSONARE_ACOUSTIC_MODE_IMPULSE_RESPONSE.
For surround/multichannel engine buses in the C ABI:
SonareChannelLayoutenumerates the speaker bed:SONARE_CHANNEL_LAYOUT_MONO(0),SONARE_CHANNEL_LAYOUT_STEREO(1),SONARE_CHANNEL_LAYOUT_5_1(2), andSONARE_CHANNEL_LAYOUT_7_1(3). Values matchsonare::ChannelLayoutand are part of the ABI/JSON wire format.SonareEngineBus.channel_layoutsets a bus's speaker bed (the master bus carries the project output layout; defaults to stereo).SonareEngineTrackLane.source_channel_layoutmust beSONARE_CHANNEL_LAYOUT_STEREO:sonare_engine_set_track_lanesreturnsSONARE_ERROR_INVALID_PARAMETERfor a mono, 5.1 or 7.1 lane because multichannel lane input is not implemented. A zero-initialized lane reads as mono (SONARE_CHANNEL_LAYOUT_MONOis 0), so setSTEREOexplicitly on every lane. The list holds at mostSONARE_ENGINE_MAX_TRACK_LANES(32) lanes; a longer one isSONARE_ERROR_INVALID_PARAMETERwith the messageat most 32 track lanes are supported, while a valid list that earlier configuration refuses (an automation id table that cannot hold the added tracks, a retained clip delay past the alignment ceiling) isSONARE_ERROR_INVALID_STATE.- The realtime lane mixer pans each mono/stereo lane into a 5.1/7.1 destination from the strip's
surroundPanposition, sums buses plane by plane, and publishes per-plane (wide) meters.azimuth,divergence, andlfeaffect placement;elevationanddistanceare reserved. See realtime engine surround group buses.
For realtime insert automation and external MIDI in the C ABI:
Track, master, and bus strips each have insert-bypass and realtime-safe parameter setters. Parameter names are the JSON keys reported by
sonare_mastering_insert_param_info(insert, sample_rate, &json); an unsupported or non-realtime-safe name returnsSONARE_ERROR_INVALID_PARAMETER.sonare_engine_resolve_{track,master,bus}_insert_automation_idconverts an insert parameter name into the numeric id accepted bysonare_engine_set_automation_laneandsonare_engine_set_parameter, whosesmoothedargument (non-zero) ramps the change.sonare_engine_set_param_smoothing_mschanges the shared ramp time (20 ms by default;0makes changes immediate).sonare_engine_push_midi_program(engine, destination_id, group, channel, program, bank_valid, bank_msb, bank_lsb, render_frame)andsonare_engine_push_midi_input_program(engine, group, channel, program, bank_valid, bank_msb, bank_lsb, offset_in_block_samples)push a live program change with an optional bank, packed as one MIDI 2.0 Program Change so the receiver's own gates apply. A non-zero bank withbank_validzero isSONARE_ERROR_INVALID_PARAMETER. What the receiver does with it:Receiver Follows the program change? SoundFont player Yes, selects bank and program under its own gates NativeSynth bound with use_gm_programsYes, resolves each channel's voice from them NativeSynth whose patch plays the GM kit (the drum-kitpreset, or a percussion patch withgm_kiton)Yes, as the GS drum-set select on every channel Every other receiver (the built-in synth, any other NativeSynth patch, a part with RX PROGRAM CHANGE off, an MPE member channel) Accepted and ignored Every live MIDI push (
sonare_engine_push_midi_note_on,_note_off,_cc,_pitch_bend,_channel_pressure,_poly_pressure,_program,_umpand thesonare_engine_push_midi_input_*forms) refuses a value outside its MIDI range withSONARE_ERROR_INVALID_PARAMETERand a message naming the argument and the range (channel must be in [0, 15]). Pushing to a disabled input source isSONARE_ERROR_INVALID_STATE, and a full input queue isSONARE_ERROR_OUT_OF_MEMORY.sonare_engine_set_parameterandsonare_engine_set_automation_lanerefuse a parameter id in the reserved mixer namespace (0x4D58xxxx) that is not a master id, withSONARE_ERROR_INVALID_PARAMETER.sonare_engine_set_track_sends(engine, track_id, sends, send_count)andsonare_engine_set_track_output_bus(engine, track_id, output_bus_id)change one track lane's sends or output bus (0is the master mix) without restating the lane list;sonare_engine_set_track_lanesstill replaces every lane.sonare_engine_push_midi_sysexcopies one complete SysEx frame, including0xF0and0xF7; its size must be 1–512 bytes.sonare_engine_set_midi_destination_externalmoves a destination out of the internal instrument rack and into the host-drained output queue. Up to 16 destinations may be external. Clock/transport forwarding is opt-in throughsonare_engine_set_external_midi_clock_enabled; those messages use destination0xFFFFFFFF.On the host/control thread, call
sonare_engine_drain_external_midirepeatedly until it returns zero events, then deliver each 1–3-byte MIDI 1.0 message to the device.max_eventsmust be at least 4 because one queued UMP (Universal MIDI Packet) record can expand to four messages. Monitorsonare_engine_external_midi_dropped_countto detect a host that is draining too slowly. SysEx/Data and other UMP messages that cannot be lowered to MIDI 1.0 are not emitted by this drain API.Each drained
SonareEngineTelemetryrecord'serrorfield is aSonareEngineTelemetryErrorordinal (sonare_c_types_engine.h):NONE = 0;1–18cover queue and capacity overflows (command queue, pending-command, boundary, telemetry, capture, automation-bind-target, insert-automation, MIDI-clock, metronome), a non-realtime-safe or unprepared command, stale automation lanes and clip-page underrun;20isMAX_CHANNELS_EXCEEDEDand21isPARAMETER_BASE_OVERFLOW.
Canonical C ABI contracts
The sonare_master_audio and sonare_master_audio_stereo entries require a preset or overrides_json. Two NULL selectors return SONARE_ERROR_INVALID_PARAMETER. For an identity chain, pass a NULL preset and "{}" overrides.
Read project outputs after a SONARE_OK return. Allocation failures leave compile and MIDI export output slots empty. When a required feature is compiled out, check for SONARE_ERROR_NOT_SUPPORTED and the notCompiledIn reason. In that case, sonare_last_refusal_entry() names the entry and there are no argument subjects.
The stereo pair and note-editing entry points keep their contracts in the C ABI names and signatures below:
SonareError sonare_mastering_apply_pair_processor_stereo(
const char* processor, const float* source_left, const float* source_right,
size_t source_length, const float* reference_left, const float* reference_right,
size_t reference_length, int reference_sample_rate, int sample_rate,
const SonareMasteringParam* params, size_t param_count, SonareMasteringStereoResult* out);
SonareError sonare_mastering_ab_match_loudness_stereo(
const float* source_left, const float* source_right, size_t source_length,
const float* reference_left, const float* reference_right, size_t reference_length,
int reference_sample_rate, int sample_rate, float** out_left, float** out_right,
size_t* out_length, SonareLoudnessMatch* out_match);The stereo pair processor supports only match.abCrossfade. The source left/right channels and the reference left/right channels must each have equal lengths; source and reference may differ in length, and the call returns the shorter pair length. sonare_mastering_ab_match_loudness_stereo applies one shared gain to both source channels, preserves the source length and stereo image, and applies no ceiling. The two output channels are heap-allocated with out_length samples each and released with sonare_free_floats. Pass NULL for out_match when the match details are not needed.
Every two-buffer entry takes the reference's own rate: sonare_mastering_apply_pair_processor, sonare_mastering_apply_pair_processor_stereo, sonare_mastering_analyze_pair, sonare_mastering_ab_match_loudness and sonare_mastering_ab_match_loudness_stereo have an int reference_sample_rate after reference_length, and sonare_eq_match(eq, source, source_length, sample_rate, reference, reference_length, reference_sample_rate, max_bands) is the EQ-match counterpart. A reference at another rate is resampled onto sample_rate first and equal rates take no resample pass, so the output and any delay estimate are in source-rate samples; a rate of 0 or below is SONARE_ERROR_INVALID_PARAMETER. sonare_mixing_assistant_suggest takes const int* track_sample_rates after track_lengths (NULL: every track at sample_rate), each track is resampled onto the call's rate, and the suggested scene is the scene member of the JSON document it returns.
SonareError sonare_streaming_mastering_chain_set_parameter(
SonareStreamingMasteringChain* handle, const char* key, double value);
SonareError sonare_render_notes(
const float* samples, size_t length, int sample_rate,
const SonareNoteObject* notes, size_t note_count,
const float* envelopes, size_t envelope_count, const float* f0_hz,
const int32_t* voiced, size_t n_frames, float frame_rate,
const SonareNoteRenderConfig* config, float** out, size_t* out_length);
SonareError sonare_decompose_note_pitch(
const float* f0_hz, const int32_t* voiced, size_t n_frames,
float frame_rate, float median_hz, float vibrato_cutoff_hz,
SonarePitchDecompositionResult* out);sonare_streaming_mastering_chain_set_parameter takes a full dotted key for an enabled, prepared stage. The key must be realtime-safe; structural, disabled-stage, and unknown keys are rejected before mutation. Serialize it with processing, flushing, reset, and prepare at a block boundary; existing DSP instances, audio history, and latency remain in place.
For sonare_render_notes, f0_hz may be NULL when no pitch-curve edit needs it, and voiced is optional. A non-NULL voiced array requires f0_hz; a NULL array infers voicing from usable positive finite F0, while a zero flag suppresses an otherwise usable F0. sonare_decompose_note_pitch requires a non-NULL F0 track with n_frames > 0, but its voiced flags are optional and use the same usable-F0 rule. A non-positive or non-finite F0 frame contributes no pitch measurement.
To classify processors in the C ABI, sonare_mastering_processor_catalog(&json) writes a JSON array string [{"id","kind","realtimeInsertable","stereoOnly","latencySamples","tailSamples","realtimeCost","channelPolicy","category","params","slots"}, ...]. kind is realtime/offline/pair, and realtimeInsertable is true exactly for the ids in sonare_mastering_insert_names(). latencySamples and tailSamples are representative default-configuration probes (48 kHz / 512 samples); configuration-dependent values should come from sonare_mastering_insert_timing. realtimeCost is a coarse low/moderate/high algorithmic estimate for live inserts, not a hardware benchmark, and is null for non-insert ids. channelPolicy tells a surround host how the mixer wraps the processor, category is the stable UI grouping derived from the id namespace, and params contains descriptors for realtime and construction keys (empty for non-insert processors). Each descriptor includes name, id, rtSafe, type, min, max, minExclusive, maxExclusive, maxRelativeTo, default, unit, scale, uiMin, uiMax, dependsOn, choices, and slot. slots lists conditional key groups as {name,parent,activation,minCrossoverCutoffs}. The id universe is the union of sonare_mastering_processor_names(), the insert set, and sonare_mastering_pair_processor_names(), so hosts can filter a processor picker without hardcoding ids. Release the catalog string with sonare_free_string; the *_names() getters, by contrast, return thread-local pointers that are never freed or cached across threads.
The focused C ABI queries are:
SonareError sonare_mastering_insert_param_info(const char* insert, int sample_rate,
char** out_json);
SonareError sonare_mastering_insert_timing(const char* insert, const char* params,
int sample_rate, int* out_latency_samples,
int* out_tail_samples);
SonareError sonare_mastering_preset_params_json(const char* preset, char** json_out);minExclusive and maxExclusive specify whether the corresponding bound itself is refused. See Insert parameter descriptors for the shared descriptor fields.
sonare_mastering_insert_param_names accepts insert IDs and returns NULL with SONARE_ERROR_INVALID_PARAMETER for an unknown ID. sonare_mastering_insert_param_info accepts processor-catalog IDs, including offline repair stages, and writes their JSON descriptor array, released with sonare_free_string; an unknown ID returns SONARE_ERROR_INVALID_PARAMETER and leaves out_json NULL. Besides name, id, rtSafe, type, min, max, default, choices and slot, a descriptor declares what a control needs beyond the accepted range: unit (read from the processor that consumes the key, from a closed set: dB, dBFS, LUFS, Hz, ms, s, samples, m, cm, mm, deg, percent, degC, V, inPerSec, dBPerOct, semitones, cents, ratio, bits, count, N, midiNote, bpm, none), scale (linear or log), an optional display range uiMin / uiMax inside [min, max], and dependsOn, the sibling keys whose live value bounds this one, each as this <relation> factor * sibling, and coupledWith, the other sibling keys that move the accepted range (min / max are measured with them at their defaults). The sample_rate argument resolves every key whose maxRelativeTo is "nyquist" to the bound accepted at that host rate (the lower of the host's Nyquist and any cap fixed when the insert is built); a rate out of range is SONARE_ERROR_INVALID_PARAMETER, and a rate of 0 is the rate-less query, which keeps the 24000 cap of the 48 kHz probe. sonare_mastering_insert_timing rejects unknown keys and reports the configured latency and tail. sonare_mastering_preset_params_json returns {"version":1,"params":{...}}; release its heap-owned string with sonare_free_string. The catalog's repair.* entries publish their parameters through the same descriptor, carry no automation id, and are never rtSafe; every entry also carries causal (false for repair.declick, repair.declip and repair.trimSilence, true for the other repair stages and every insert). repair.decrackle, repair.dehum, repair.denoiseClassical and repair.dereverbClassical are realtime inserts under their ids; declick and declip stay offline. Enum-valued parameters accept their choices name beside the number; sonare_mastering_enum_value(processor, key, name, &is_enum, &value) resolves a name. sonare_capability_catalog_json(&json) combines the processor catalog, built-in mastering, synth, mixing-scene, and voice-changer preset lists, and detailed masteringPresets entries.
Realtime voice presets are exposed in C as sonare_realtime_voice_changer_preset_names(), sonare_realtime_voice_changer_preset_json(), and sonare_realtime_voice_changer_validate_preset_json(). The typed preset selector is the SonareVoiceCharacterPreset enum (SONARE_VC_PRESET_NEUTRAL_MONITOR = 0 through SONARE_VC_PRESET_RADIO_VOICE = 11); sonare_voice_character_preset_id(preset) returns its canonical id string (NULL for unknown values), and the SONARE_REALTIME_VOICE_CHANGER_PRESET_IDS macro provides the newline-separated id list for compile-time binding generation. The native POD config ABI is SONARE_VOICE_CHANGER_ABI_VERSION; it is separate from the preset JSON schemaVersion.
Additional C ABI entry points
Pitch, voice and repair (sonare_c_effects.h, sonare_c_mastering.h):
| Function | Purpose |
|---|---|
sonare_auto_tune(samples, length, sample_rate, key, config, &out, &out_length, &out_key) | Offline automatic pitch correction of a monophonic recording to the scale of a key. key is a SonareKey or NULL to detect it (a named key is taken as certain, so out_key reports confidence 1); config may be NULL, and only scale_reference_midi, retune_amount, max_correction_semitones, retune_speed_ms and vibrato_threshold_cents are read. The output has the input's length; release it with sonare_free_floats |
sonare_voice_change(samples, length, sample_rate, &config, &out, &out_length) | Offline pitch and formant change with a SonareVoiceChangeConfig (seed it with sonare_voice_change_config_init: pitch_semitones 0, formant_factor 1, formant_mode relative; every field is then read literally). SONARE_FORMANT_MODE_RELATIVE (0) is the warp applied after the pitch shift, so the formants follow the pitch; SONARE_FORMANT_MODE_ABSOLUTE (1) is the formant shift relative to the input, so 1 keeps the formants in place. A relative-mode formant_factor outside [0.55, 1.65], and an absolute request that would hold the formants further against the pitch shift than absolute mode allows, are refused with SONARE_ERROR_INVALID_PARAMETER |
sonare_mastering_repair_analyze(channels, channel_count, length, sample_rate, request_json, &json) | Per-channel repair defects plus the stages the assistant recommends, as JSON (defects, channels, declipThresholdSafe, integratedLufs, recommended, explanation). request_json is NULL or {"preferStreamingSafe": true}; dereverb is never recommended. Release the string with sonare_free_string |
sonare_mastering_repair_apply(channels, channel_count, length, sample_rate, stages_json, progress, user_data, out_channels, &reports_json, cancel, cancel_user_data) | Applies [{"stage": ..., ...settings}] to every channel in the fixed order declip, declick, decrackle, dehum, denoise, dereverb whatever order the array gives; a repeated stage, an unknown stage and an unknown setting are SONARE_ERROR_INVALID_PARAMETER. out_channels are caller-owned planes (they may alias the input) written only on success; the reports are [{stage, scope, reports}], scope being "channel" (one report per channel) or "linked" (one for the set). Either callback may be NULL; a nonzero cancel result returns SONARE_ERROR_CANCELLED |
sonare_streaming_loudness_gain(samples, length, sample_rate, config_json, &out) and _stereo(left, right, ...) | Measures a SonareStreamingLoudnessGain (loudness_static_gain_db, true_peak_dbtp, integrated_lufs) at the loudness stage's input, for the loudness_static_gain_db and loudness_static_gain_peak_dbtp members of SonareStreamingMasteringChainOptions passed to sonare_streaming_mastering_chain_create. The gain equals what the offline chain applies, ceiling clamp included; config_json is NULL or an overrides object with the keys sonare_master_audio takes |
Realtime engine (sonare_c_engine.h; scheduled render_frame is an int64_t. Use -1 for the next block head. Values below -1 are refused):
| Function | Purpose |
|---|---|
sonare_engine_upsert_clip(engine, &clip), sonare_engine_remove_clip(engine, clip_id) | Replace or add one clip, or remove one, leaving the rest of the published set as it was. A refused clip leaves the set unchanged; removing an unknown id is SONARE_ERROR_INVALID_PARAMETER. Control thread only |
sonare_engine_reset_processor_state(engine, render_frame) | Queues a reset of every mixer and effect processor to its prepared state, so playback queued after it starts from the state an offline bounce starts from. Instruments keep their state; while playing, it cuts running tails like a seek |
sonare_engine_prime_offline_parameters(engine, num_channels, block_size) | The offline pre-roll that bounce and freeze run, without rendering. A host driving sonare_engine_render_offline calls it once before the first chunk. A channel count or block size above the prepared maximum is SONARE_ERROR_INVALID_PARAMETER; an unprepared engine is SONARE_ERROR_INVALID_STATE |
sonare_engine_count_in_end_sample(engine, start_sample, bars, &end_sample) | The sample at which a count-in of bars bars from start_sample ends, counted on the tempo map from the start of the bar containing start_sample. bars <= 0 writes start_sample; a negative start_sample is SONARE_ERROR_INVALID_PARAMETER |
sonare_engine_tail_samples(engine, &samples) | Upper bound of the longest audible tail after the last input, in samples (2147483647 means unbounded) |
sonare_engine_graph_latency_samples_q8(engine, &latency_q8) | Processing latency in 1/256 samples, the value telemetry records carry |
sonare_engine_can_set_lane_sidechain, sonare_engine_can_set_bus_sidechain, sonare_engine_can_set_master_sidechain | Report, without changing anything, whether the matching set_*_sidechain would accept a binding. out_refusal receives a SonareSidechainRefusal: NONE (0), INVALID_TARGET, INSERT_OUT_OF_RANGE, UNDECLARED_SOURCE, INVALID_SOURCE_KIND, SELF_KEY, CYCLE, TABLE_FULL, PLAN_REFUSED (1 through 8) |
sonare_engine_resolve_track_lane_automation_id(engine, track_id, "faderDb" or "pan", &id), sonare_engine_resolve_bus_automation_id(engine, bus_id, "faderDb", &id) | Reserved automation ids that name the track or bus rather than its position, so they keep driving it across sonare_engine_set_track_lanes and sonare_engine_set_track_buses reorders and fail as an unknown target once it is removed |
sonare_engine_resolve_master_automation_id(engine, "faderDb", "pan" or "width", &id) | The same for the master strip, which always exists, so the id never goes stale. Any other name is SONARE_ERROR_INVALID_PARAMETER and sets id to 0 |
An offline render, bounce, freeze or pre-roll with a block size larger than the one the engine was prepared with is refused with SONARE_ERROR_INVALID_PARAMETER. sonare_engine_set_track_strip_json, sonare_engine_set_bus_strip_json and sonare_engine_set_master_strip_json refuse a key the scene reader does not consume, naming it (unknown strip key 'strips[0].faderDB'); keys starting with $ or x- and the snake_case aliases are still accepted.
Mixer and project (sonare_c_mixing.h, sonare_c_project_core.h, sonare_c_project_edit.h):
| Function | Purpose |
|---|---|
sonare_mixer_set_output_bus(mixer, source_id, bus_id) | Routes an offline mixer strip or bus into a submix after construction. It replaces the source's main connection and refuses, before changing anything, an unknown id, a non-bus destination, the master as source, a self-route, or a cycle through connections or sends; an added submix reaches the master only once it is routed there too |
sonare_mixer_flush_meters(mixer) | Marks the end of the signal for every strip and bus meter, folding the true-peak reading's pending group delay into the published snapshot. Call it after the last block of an offline or one-shot run; a later process call starts a new signal |
sonare_project_unresolved_audio_source_by_index(project, index, &source) | Reads an unresolved audio source descriptor by zero-based index, in the order of sonare_project_unresolved_audio_source_id_by_index. name_or_uri is truncated to 127 bytes |
sonare_chord_symbol_from_analysis(root, quality, bass, &root_pc, &quality, extensions, capacity, &extension_count, &slash_bass_pc), sonare_key_mode_from_analysis(mode, &out_mode) | Convert a detected chord or key into the fields of an arrangement annotation (SonareProjectChordSymbol, SonareProjectKeySegment) through the library's own reduction table, instead of mapping the two differently numbered vocabularies by hand. extensions are scale degrees, up to 32 |
sonare_align_take_to_reference(reference, reference_len, reference_sample_rate, take, take_len, take_sample_rate, config, &anchors, &count, &alignment) | Aligns a take, which may be recorded at another rate than the reference: the take is resampled onto the reference's grid and both anchor axes come back in reference-rate samples, to be scaled by the project rate over the reference rate before setting a warp map |
sonare_project_get_audio_source_uri(project, source_id, &uri) | The full, untruncated URI of an audio source id, as a heap copy released with sonare_free_string |
sonare_project_add_loop_recording_takes takes a SonareProjectLoopRecordingDesc whose flags word is 0 (keep a partial last take) or SONARE_PROJECT_LOOP_RECORDING_DROP_PARTIAL_TAIL (do not create it); any other bit is SONARE_ERROR_INVALID_PARAMETER. A partial last take is kept but not made active when an earlier complete take exists, and is marked "partial": true in the project JSON; a remainder of one frame or less creates no take.