xtc/include/xtc/xtc_processor.h

59 lines
2.9 KiB
C

#ifndef XTC_PROCESSOR_H
#define XTC_PROCESSOR_H
#include "xtc_native.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XTC_PROCESSOR_ABI 2U
#define XTC_PROCESSOR_PARAMETERS 16U
#define XTC_PROCESSOR_STATE_MAX (80U + 8U * XTC_PROCESSOR_PARAMETERS)
typedef struct {
unsigned int id;
char name[64], unit[16];
float minimum, maximum, default_value;
} xtc_parameter_info;
typedef struct {
unsigned int offset, id;
float value;
} xtc_parameter_event;
typedef struct {
unsigned int abi_version;
size_t struct_size;
char identifier[64];
xtc_native_kind kind;
size_t parameter_count;
xtc_parameter_info parameters[XTC_PROCESSOR_PARAMETERS];
xtc_result (*prepare)(double rate, size_t max_frames, const float *values, size_t count, void **state);
void (*reset)(void *state);
xtc_result (*process)(void *state, const xtc_native_block *block);
void (*parameter)(void *state, unsigned int id, float value);
void (*destroy)(void *state);
} xtc_processor_descriptor;
typedef struct xtc_processor xtc_processor;
/* Descriptors are copied. Trusted C callbacks, exact version/size matching,
* mono ports (stereo = two independent instances). Control: prepare/destroy;
* single audio owner: reset/process/parameter. No callback allocation/I/O/locks.
* Reset clears transient voices/history, retaining parameter values. */
xtc_result xtc_processor_validate(const xtc_processor_descriptor *descriptor);
xtc_result xtc_processor_create(const xtc_processor_descriptor *descriptor, double rate, size_t frames,
xtc_processor **out);
void xtc_processor_destroy(xtc_processor *processor);
void xtc_processor_reset(xtc_processor *processor);
/* Validate all events before touching output/state. At equal offsets parameter
* events run in array order before MIDI events. Up to 256 events of each type.
* A callback failure zeros the entire block and resets transient state.
* Parameter values already applied remain applied. No rollback of plugin DSP. */
xtc_result xtc_processor_process(xtc_processor *processor, const xtc_native_block *block,
const xtc_parameter_event *events, size_t count);
/* Quiescent control thread only. Portable little-endian config: identifier and
* stable parameter IDs/float32 values; no pointers, voices, delays or hidden DSP
* state. Restore prepares a new instance transactionally; old handles are intact.
* Descriptors requiring opaque assets/state are outside this parameter-only ABI.
* Format/ID/range mismatches are errors, never silent clamping. */
xtc_result xtc_processor_save(const xtc_processor *processor, void *data, size_t capacity, size_t *written);
xtc_result xtc_processor_restore(const xtc_processor_descriptor *descriptor, double rate, size_t frames,
const void *data, size_t size, xtc_processor **out);
#ifdef __cplusplus
}
#endif
#endif