xtc/examples/steinberg/render.c
2026-11-06 18:13:49 +01:00

43 lines
2.1 KiB
C

/* Render the SDK sine -> half-gain examples without an audio server. */
#include "xtc/xtc_plugin.h"
#include "xtc/xtc_audio.h"
#include <stdio.h>
int main(int argc, char **argv)
{
xtc_plugin_spec spec;
xtc_plugin *synth = NULL, *gain = NULL;
xtc_recorder *writer = NULL;
xtc_result result = XTC_ERR_INVALID_ARGUMENT;
size_t position;
float dry[256], wet[256];
if (argc != 3) {
fprintf(stderr,"Usage: steinberg-render /absolute/xtc-sdk-examples.vst3 /absolute/new.wav\n");
return 2;
}
result = xtc_plugin_probe_format(XTC_PLUGIN_VST3,argv[1],1,48000,&spec);
if (result == XTC_OK) result = xtc_plugin_create(&spec,48000,256,&synth);
if (result == XTC_OK) result = xtc_plugin_probe_format(XTC_PLUGIN_VST3,argv[1],0,48000,&spec);
if (result == XTC_OK) result = xtc_plugin_create(&spec,48000,256,&gain);
if (result == XTC_OK) result = xtc_recorder_create(argv[2],48000,512,&writer);
for (position = 0; result == XTC_OK && position < 96000; position += 256) {
size_t frames = 96000-position < 256 ? 96000-position : 256;
xtc_midi_event event = {0};
size_t count = 0;
event.channel = 0; event.pitch = 69; event.velocity = 100;
if (!position) { event.type = XTC_MIDI_NOTE_ON; count = 1; }
if (position <= 48000 && position+frames > 48000) {
event.type = XTC_MIDI_NOTE_OFF; event.offset = (unsigned int)(48000-position); count = 1;
}
result = xtc_plugin_process_midi_at(synth,&event,count,dry,frames,position);
if (result == XTC_OK) result = xtc_plugin_process_at(gain,dry,wet,frames,position);
if (result == XTC_OK) {
xtc_recorder_push(writer,wet,frames);
result = xtc_recorder_drain(writer);
}
}
if (result == XTC_OK) result = xtc_recorder_finish(writer);
xtc_recorder_destroy(writer); xtc_plugin_destroy(gain); xtc_plugin_destroy(synth);
if (result != XTC_OK) { fprintf(stderr,"SDK example render failed (%d).\n",(int)result); return 1; }
puts("Rendered 2 seconds at 48 kHz: A4 for 1 second, then silence.");
return 0;
}