xtc/tests/integration/test_steinberg_sdk.c
2026-11-06 18:13:49 +01:00

59 lines
3 KiB
C

#define _POSIX_C_SOURCE 200809L
#include "xtc/xtc_plugin.h"
#include "xtc/xtc_project.h"
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
xtc_plugin_spec gain, synth, actual;
xtc_plugin *g = NULL, *s = NULL;
float in[256], out[256], wet[256];
size_t i;
xtc_project *project = NULL, *loaded = NULL;
uint64_t track;
char document[] = "/tmp/xtc-sdk-project-XXXXXX";
int fd;
xtc_midi_event events[] = {
{0}, {0}
};
assert(argc == 2 && argv[1][0] == '/');
assert(xtc_plugin_probe(argv[1],0,48000,&gain) == XTC_OK);
assert(gain.format == XTC_PLUGIN_VST3 && gain.inputs == 1 && !gain.instrument);
assert(!strcmp(gain.path,argv[1]) && !strcmp(gain.label,"xtc SDK Half Gain"));
assert(xtc_plugin_probe_format(XTC_PLUGIN_VST3,argv[1],1,48000,&synth) == XTC_OK);
assert(synth.instrument && !synth.inputs && strcmp(synth.identifier,gain.identifier));
assert(xtc_plugin_probe(argv[1],2,48000,&actual) == XTC_ERR_UNSUPPORTED); /* Controller, not audio. */
assert(xtc_plugin_probe(argv[1],3,48000,&actual) == XTC_ERR_NOT_FOUND);
assert(xtc_project_create(&project) == XTC_OK && xtc_project_create(&loaded) == XTC_OK);
assert(xtc_project_add_track(project,"SDK Sine",&track) == XTC_OK);
assert(xtc_project_set_instrument(project,track,&synth) == XTC_OK);
fd = mkstemp(document); assert(fd >= 0 && close(fd) == 0);
assert(xtc_project_save(project,document) == XTC_OK && xtc_project_load(loaded,document) == XTC_OK);
assert(xtc_project_get_instrument(loaded,track,&actual) == XTC_OK);
assert(!strcmp(actual.path,argv[1]) && !strcmp(actual.identifier,synth.identifier));
assert(unlink(document) == 0); xtc_project_destroy(project); xtc_project_destroy(loaded);
assert(xtc_plugin_create(&gain,48000,256,&g) == XTC_OK);
assert(xtc_plugin_create(&synth,48000,256,&s) == XTC_OK);
for (i = 0; i < 256; ++i) in[i] = i % 2 ? -.75f : .25f;
assert(xtc_plugin_process_at(g,in,out,256,48000) == XTC_OK);
for (i = 0; i < 256; ++i) assert(out[i] == in[i]*.5f);
events[0].type = XTC_MIDI_NOTE_ON; events[0].offset = 13;
events[0].channel = 3; events[0].pitch = 69; events[0].velocity = 127;
events[1] = events[0]; events[1].type = XTC_MIDI_NOTE_OFF; events[1].offset = 200;
assert(xtc_plugin_process_midi_at(s,events,2,out,256,0) == XTC_OK);
for (i = 0; i <= 13; ++i) assert(out[i] == 0);
assert(fabsf(out[40]) > .05f);
for (i = 200; i < 256; ++i) assert(out[i] == 0);
assert(xtc_plugin_process(g,out,wet,256) == XTC_OK);
for (i = 0; i < 256; ++i) assert(wet[i] == out[i]*.5f && isfinite(wet[i]));
assert(xtc_plugin_process_midi(s,NULL,0,out,256) == XTC_OK);
for (i = 0; i < 256; ++i) assert(out[i] == 0);
xtc_plugin_destroy(g); xtc_plugin_destroy(s);
puts("Official SDK gain/synth: bundle discovery, identities, processing, note offsets and release passed.");
return 0;
}