project1/src/main.c
2024-11-09 14:45:04 +01:00

113 lines
3.1 KiB
C

#include <stdio.h>
#include <sndfile.h>
#include "easy.h"
#include "audiofile.h"
#define BUFFER_SIZE 256 // this is per channel
/*
http://lsp-plug.in/plugins/lv2/comp_delay_x2_stereo
http://lsp-plug.in/plugins/lv2/para_equalizer_x32_lr
http://calf.sourceforge.net/plugins/BassEnhancer
*/
int main(int argc, char *argv[]) {
LilvWorld *world = lilv_world_new();
lilv_world_load_all(world);
// load audio file
SF_INFO sfinfo = {0};
SNDFILE *sndfile;
if ((sndfile = audiofile_read("a.flac", &sfinfo)) == NULL) {
return 1;
}
SNDFILE *out_sndfile;
if ((out_sndfile = audiofile_open_for_write("aout.flac", &sfinfo)) == NULL) {
return 1;
}
// load lilv plugin
const LilvPlugin* plugin = easy_load_plugin(world, "http://lsp-plug.in/plugins/lv2/comp_delay_x2_stereo");
if (plugin == NULL) {
fprintf(stderr, "Plugin not found: comp_delay_x2_stereo (from lsp-plug.in)\n");
return 1;
}
// prepare lilv instance
LilvInstance *instance = lilv_plugin_instantiate(plugin, sfinfo.samplerate, NULL);
float input_left[BUFFER_SIZE];
float input_right[BUFFER_SIZE];
float output_left[BUFFER_SIZE];
float output_right[BUFFER_SIZE];
lilv_instance_connect_port(instance, 0, input_left); // Input L
lilv_instance_connect_port(instance, 1, input_right); // Input R
lilv_instance_connect_port(instance, 2, output_left); // Output L
lilv_instance_connect_port(instance, 3, output_right); // Output R
float sc[BUFFER_SIZE] = {0};
lilv_instance_connect_port(instance, 4, &sc); // Output R
lilv_instance_connect_port(instance, 5, &sc); // Output R
/*float bypass = 0.0f;
lilv_instance_connect_port(instance, 6, &bypass);
float aa = 0.0f;
lilv_instance_connect_port(instance, 8, &aa);*/
/*int mode_r = 2;
float time_r = 999.0f; // ms
lilv_instance_connect_port(instance, 5, &mode_r); // Mode Right
lilv_instance_connect_port(instance, 11, &time_r); // Time Right
float time_dr =1.0f; // ms
lilv_instance_connect_port(instance, 13, &time_dr); // Time Right
float aa = 0.0f;
lilv_instance_connect_port(instance, 4, &aa);*/
lilv_instance_activate(instance);
// start processing
printf("Now processing\n");
float buffer[BUFFER_SIZE * 2];
float out_buffer[BUFFER_SIZE * 2];
int frames_read;
while ((frames_read = sf_readf_float(sndfile, buffer, BUFFER_SIZE))) {
for (sf_count_t i = 0; i < frames_read; i++) {
input_left[i] = buffer[i * 2];
input_right[i] = buffer[i * 2 + 1];
}
lilv_instance_run(instance, frames_read);
for (sf_count_t i = 0; i < frames_read; i++) {
out_buffer[i * 2] = output_left[i];
out_buffer[i * 2 + 1] = output_right[i];
}
sf_writef_float(out_sndfile, out_buffer, frames_read);
}
printf("Done processing\n");
// end processing
lilv_instance_deactivate(instance);
lilv_instance_free(instance);
lilv_world_free(world);
sf_close(sndfile);
sf_close(out_sndfile);
}