Phase 9: Add native processors and reproducible Linux release tooling
This commit is contained in:
parent
7db5fb7738
commit
de403b37d7
43 changed files with 1656 additions and 19 deletions
|
|
@ -14,11 +14,17 @@ struct xtc_plan {
|
|||
double *phases;
|
||||
double sample_rate;
|
||||
float input_gain;
|
||||
uint64_t position;
|
||||
xtc_native **native;
|
||||
};
|
||||
|
||||
void xtc_plan_destroy(xtc_plan *plan)
|
||||
{
|
||||
if (plan == NULL) return;
|
||||
if (plan->native) {
|
||||
size_t i; for (i = 0; i < plan->node_count * 2; ++i) xtc_native_destroy(plan->native[i]);
|
||||
}
|
||||
free(plan->native);
|
||||
free(plan->nodes);
|
||||
free(plan->order);
|
||||
free(plan->offsets);
|
||||
|
|
@ -55,6 +61,7 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate,
|
|||
plan->max_frames = max_frames;
|
||||
plan->sample_rate = sample_rate;
|
||||
plan->input_gain = 1.0f;
|
||||
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));
|
||||
plan->offsets = calloc(plan->node_count + 1U, sizeof(*plan->offsets));
|
||||
|
|
@ -63,7 +70,7 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate,
|
|||
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->nodes == NULL || plan->order == NULL || plan->offsets == NULL ||
|
||||
if (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);
|
||||
|
|
@ -83,6 +90,16 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate,
|
|||
plan->render[node] = (unsigned char)(has_output || graph->require_output_nodes ?
|
||||
plan->nodes[node].type == XTC_NODE_OUTPUT : terminal);
|
||||
}
|
||||
for (node = 0; node < plan->node_count; ++node) {
|
||||
if (plan->nodes[node].type == XTC_NODE_NATIVE) {
|
||||
size_t side;
|
||||
for (side = 0; side < 2; ++side) {
|
||||
result = xtc_native_create(&plan->nodes[node].native, sample_rate, max_frames,
|
||||
plan->nodes[node].value, &plan->native[side * plan->node_count + node]);
|
||||
if (result != XTC_OK) { xtc_plan_destroy(plan); return result; }
|
||||
}
|
||||
}
|
||||
}
|
||||
plan->offsets[plan->node_count] = cursor;
|
||||
*out_plan = plan;
|
||||
return XTC_OK;
|
||||
|
|
@ -91,6 +108,8 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate,
|
|||
xtc_result xtc_plan_reset(xtc_plan *plan)
|
||||
{
|
||||
if (plan == NULL) return XTC_ERR_INVALID_ARGUMENT;
|
||||
{ size_t i; for (i = 0; i < plan->node_count * 2; ++i) xtc_native_reset(plan->native[i]); }
|
||||
plan->position = 0;
|
||||
memset(plan->phases, 0, plan->node_count * sizeof(*plan->phases));
|
||||
memset(plan->peaks, 0, plan->node_count * sizeof(*plan->peaks));
|
||||
return XTC_OK;
|
||||
|
|
@ -115,7 +134,7 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input,
|
|||
{
|
||||
size_t index, frame, edge, channel;
|
||||
if (plan == NULL || output == NULL || (right && right == output)) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (frame_count > plan->max_frames) return XTC_ERR_CAPACITY;
|
||||
if (frame_count > plan->max_frames || plan->position > UINT64_MAX - frame_count) return XTC_ERR_CAPACITY;
|
||||
if (frame_count == 0U) return XTC_OK;
|
||||
/* All external input reads finish before output is written, allowing aliasing.
|
||||
* Nonfinite input/arithmetic becomes silence per sample, never persistent DSP state. */
|
||||
|
|
@ -150,6 +169,16 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input,
|
|||
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,
|
||||
buffer, frame_count, plan->position, NULL, 0};
|
||||
xtc_result result = xtc_native_process(plan->native[channel * plan->node_count + node], &block);
|
||||
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) plan->peaks[node] = channel && plan->peaks[node] > peak ? plan->peaks[node] : peak;
|
||||
}
|
||||
|
|
@ -160,6 +189,7 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input,
|
|||
destination[frame] = isfinite(sample) ? sample : 0.0f;
|
||||
}
|
||||
}
|
||||
plan->position += frame_count;
|
||||
return XTC_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue