Phase 15: host trusted LADSPA processors with persisted graph state
This commit is contained in:
parent
c3eadee891
commit
f72314b5a3
24 changed files with 1046 additions and 70 deletions
|
|
@ -17,6 +17,7 @@ struct xtc_plan {
|
|||
float input_gain;
|
||||
uint64_t position;
|
||||
xtc_native **native;
|
||||
xtc_plugin **plugins;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -33,6 +34,11 @@ void xtc_plan_destroy(xtc_plan *plan)
|
|||
for (i = 0; i < plan->node_count * 2; ++i)
|
||||
xtc_native_destroy(plan->native[i]);
|
||||
}
|
||||
if (plan->plugins) {
|
||||
size_t i;
|
||||
for (i = 0; i < plan->node_count * 2; ++i) xtc_plugin_destroy(plan->plugins[i]);
|
||||
}
|
||||
free(plan->plugins);
|
||||
free(plan->native);
|
||||
free(plan->nodes);
|
||||
free(plan->order);
|
||||
|
|
@ -81,6 +87,7 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t
|
|||
plan->max_frames = max_frames;
|
||||
plan->sample_rate = sample_rate;
|
||||
plan->input_gain = 1.0f;
|
||||
plan->plugins = calloc(storage_nodes * 2U,sizeof(*plan->plugins));
|
||||
plan->native = calloc(storage_nodes * 2U, sizeof(*plan->native));
|
||||
plan->nodes = calloc(storage_nodes, sizeof(*plan->nodes));
|
||||
plan->order = calloc(storage_nodes, sizeof(*plan->order));
|
||||
|
|
@ -90,7 +97,7 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t
|
|||
plan->buffers = calloc(storage_nodes * max_frames * 2U, sizeof(*plan->buffers));
|
||||
plan->peaks = calloc(storage_nodes, sizeof(*plan->peaks));
|
||||
plan->phases = calloc(storage_nodes, sizeof(*plan->phases));
|
||||
if (plan->native == NULL || plan->nodes == NULL || plan->order == NULL || plan->offsets == NULL ||
|
||||
if (plan->plugins == NULL || plan->native == NULL || plan->nodes == NULL || plan->order == NULL || plan->offsets == NULL ||
|
||||
plan->sources == NULL || plan->render == NULL || plan->buffers == NULL || plan->peaks == NULL ||
|
||||
plan->phases == NULL) {
|
||||
xtc_plan_destroy(plan);
|
||||
|
|
@ -116,6 +123,14 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t
|
|||
: terminal);
|
||||
}
|
||||
for (node = 0; node < plan->node_count; ++node) {
|
||||
if (plan->nodes[node].type == XTC_NODE_PLUGIN) {
|
||||
size_t side;
|
||||
for (side = 0; side < 2; ++side) {
|
||||
result = xtc_plugin_create(&plan->nodes[node].plugin,sample_rate,max_frames,
|
||||
&plan->plugins[side * plan->node_count + node]);
|
||||
if (result != XTC_OK) { xtc_plan_destroy(plan); return result; }
|
||||
}
|
||||
}
|
||||
if (plan->nodes[node].type == XTC_NODE_NATIVE) {
|
||||
size_t side;
|
||||
for (side = 0; side < 2; ++side) {
|
||||
|
|
@ -211,19 +226,19 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input, const flo
|
|||
const float *midi_source = channel ? instrument_right : instrument;
|
||||
for (index = 0U; index < plan->node_count; ++index) {
|
||||
size_t node = plan->order[index];
|
||||
xtc_node spec = plan->nodes[node];
|
||||
const xtc_node *spec = &plan->nodes[node];
|
||||
float *buffer = plan->buffers + (channel * plan->node_count + node) * plan->max_frames;
|
||||
float peak = 0.0f;
|
||||
double phase = plan->phases[node];
|
||||
for (frame = 0U; frame < frame_count; ++frame) {
|
||||
float sample = 0.0f;
|
||||
if (spec.type == XTC_NODE_INSTRUMENT) {
|
||||
if (spec->type == XTC_NODE_INSTRUMENT) {
|
||||
sample = midi_source ? midi_source[frame] : 0.0f;
|
||||
} else if (spec.type == XTC_NODE_AUDIO) {
|
||||
} else if (spec->type == XTC_NODE_AUDIO) {
|
||||
sample = audio_source ? audio_source[frame] : 0.0f;
|
||||
} else if (spec.type == XTC_NODE_OSCILLATOR) {
|
||||
} else if (spec->type == XTC_NODE_OSCILLATOR) {
|
||||
sample = (float)sin(XTC_TAU * phase);
|
||||
phase += (double)spec.value / plan->sample_rate;
|
||||
phase += (double)spec->value / plan->sample_rate;
|
||||
if (phase >= 1.0)
|
||||
phase -= 1.0;
|
||||
} else {
|
||||
|
|
@ -232,16 +247,16 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input, const flo
|
|||
for (edge = plan->offsets[node]; edge < plan->offsets[node + 1U]; ++edge)
|
||||
sample += plan->buffers[(channel * plan->node_count + plan->sources[edge]) * plan->max_frames +
|
||||
frame];
|
||||
if (spec.type == XTC_NODE_GAIN)
|
||||
sample *= spec.value;
|
||||
if (spec->type == XTC_NODE_GAIN)
|
||||
sample *= spec->value;
|
||||
}
|
||||
sample = xtc_dsp_finite(sample);
|
||||
buffer[frame] = sample;
|
||||
if (fabsf(sample) > peak)
|
||||
peak = fabsf(sample);
|
||||
}
|
||||
if (spec.type == XTC_NODE_NATIVE) {
|
||||
xtc_native_block block = {spec.native.kind == XTC_NATIVE_EFFECT ? buffer : NULL,
|
||||
if (spec->type == XTC_NODE_NATIVE) {
|
||||
xtc_native_block block = {spec->native.kind == XTC_NATIVE_EFFECT ? buffer : NULL,
|
||||
buffer,
|
||||
frame_count,
|
||||
plan->position,
|
||||
|
|
@ -255,9 +270,18 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input, const flo
|
|||
return result;
|
||||
}
|
||||
}
|
||||
if (spec->type == XTC_NODE_PLUGIN) {
|
||||
xtc_result result = xtc_plugin_process(plan->plugins[channel * plan->node_count + node],
|
||||
spec->plugin.inputs ? buffer : NULL,buffer,frame_count);
|
||||
if (result != XTC_OK) {
|
||||
memset(output,0,frame_count*sizeof(*output));
|
||||
if (right) memset(right,0,frame_count*sizeof(*right));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (!right || channel == 1)
|
||||
plan->phases[node] = phase;
|
||||
if (spec.type == XTC_NODE_METER)
|
||||
if (spec->type == XTC_NODE_METER)
|
||||
plan->peaks[node] = channel && plan->peaks[node] > peak ? plan->peaks[node] : peak;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue