Phase 8: Add stereo track mixer, automation and undo/redo
This commit is contained in:
parent
cacc086805
commit
7db5fb7738
45 changed files with 1611 additions and 130 deletions
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
C99/POSIX control code loads bounded WAV files and prepares immutable clip
|
||||
plans. Callback rendering reads only preloaded samples. The audio source node
|
||||
passes the mono timeline mix through the ordinary modular graph.
|
||||
passes the mono or paired stereo timeline mix through the ordinary modular graph.
|
||||
|
||||
The recorder uses a lock-free SPSC ring: callback push, control-thread drain,
|
||||
and finish/destroy only after callback quiescence. WAV headers, file writing
|
||||
and final rename occur on the control thread. See docs/AUDIO_FILES.md and
|
||||
include/xtc/xtc_audio.h for ownership, limits and recovery behavior.
|
||||
|
||||
Phase 8 track gain/pan/mute/solo and automation are prepared with each region;
|
||||
see ../../docs/MIXER.md. Raw recording remains mono and bypasses track settings.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#define _XOPEN_SOURCE 700
|
||||
#include "wave_internal.h"
|
||||
#include "../project/project_internal.h"
|
||||
#include "../mixer/mix_internal.h"
|
||||
#include "../graph/graph_internal.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
typedef struct { uint64_t start, end, offset; size_t asset; } region;
|
||||
typedef struct { uint64_t start, end, offset; size_t asset, track; } region;
|
||||
struct xtc_audio_plan {
|
||||
xtc_mix_snapshot mix;
|
||||
xtc_wave waves[64];
|
||||
char paths[64][XTC_ASSET_PATH_BYTES];
|
||||
region regions[XTC_PROJECT_MAX_CLIPS];
|
||||
|
|
@ -73,6 +74,8 @@ xtc_result xtc_audio_plan_create(const xtc_project *project, unsigned int rate,
|
|||
plan = calloc(1, sizeof(*plan));
|
||||
if (!plan) return XTC_ERR_OUT_OF_MEMORY;
|
||||
plan->rate = rate;
|
||||
result = xtc_mix_prepare(project, rate, &plan->mix);
|
||||
if (result != XTC_OK) { free(plan); return result; }
|
||||
for (i = 0; i < project->clip_count; ++i) {
|
||||
const xtc_clip_info *clip = project->clips + i;
|
||||
size_t a; region *r;
|
||||
|
|
@ -92,7 +95,7 @@ xtc_result xtc_audio_plan_create(const xtc_project *project, unsigned int rate,
|
|||
if (total > 67108864U) { result = XTC_ERR_CAPACITY; break; }
|
||||
}
|
||||
r = plan->regions + plan->count++;
|
||||
r->asset = a;
|
||||
r->asset = a; r->track = xtc_mix_track(&plan->mix, clip->track_id);
|
||||
result = xtc_project_tick_to_sample(project, clip->start_tick, rate, &r->start);
|
||||
if (result == XTC_OK) result = xtc_project_tick_to_sample(project, clip->start_tick + clip->length_tick, rate, &r->end);
|
||||
if (result == XTC_OK) result = xtc_project_tick_to_sample(project, clip->offset_tick, rate, &r->offset);
|
||||
|
|
@ -106,11 +109,12 @@ size_t xtc_audio_plan_issues(const xtc_audio_plan *plan, const char **path)
|
|||
if (path) *path = plan ? plan->first_issue : "";
|
||||
return plan ? plan->issues : 0;
|
||||
}
|
||||
xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position, float *output, size_t frames)
|
||||
xtc_result xtc_audio_plan_render_stereo(const xtc_audio_plan *plan, uint64_t position, float *output, float *right, size_t frames)
|
||||
{
|
||||
size_t i, j;
|
||||
if (!plan || !output || frames > 65536U || position > UINT64_MAX - frames) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!plan || !output || (right && right == output) || frames > 65536U || position > UINT64_MAX - frames) return XTC_ERR_INVALID_ARGUMENT;
|
||||
memset(output, 0, frames * sizeof(*output));
|
||||
if (right) memset(right, 0, frames * sizeof(*right));
|
||||
for (i = 0; i < plan->count; ++i) {
|
||||
const region *r = plan->regions + i;
|
||||
const xtc_wave *wave = plan->waves + r->asset;
|
||||
|
|
@ -123,10 +127,18 @@ xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position,
|
|||
double fraction;
|
||||
if (source >= (double)wave->frames) continue;
|
||||
index = (size_t)source; fraction = source - (double)index;
|
||||
output[j] += (float)(wave->samples[index] * (1.0 - fraction) +
|
||||
float sample = (float)(wave->samples[index] * (1.0 - fraction) +
|
||||
(index + 1 < wave->frames ? wave->samples[index + 1] : wave->samples[index]) * fraction);
|
||||
output[j] += sample * xtc_mix_level(&plan->mix, r->track, position + j, right ? 0U : 2U);
|
||||
if (right) right[j] += sample * xtc_mix_level(&plan->mix, r->track, position + j, 1);
|
||||
}
|
||||
}
|
||||
for (j = 0; j < frames; ++j) if (!isfinite(output[j])) output[j] = 0;
|
||||
for (j = 0; j < frames; ++j) {
|
||||
if (!isfinite(output[j])) output[j] = 0;
|
||||
if (right && !isfinite(right[j])) right[j] = 0;
|
||||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
|
||||
xtc_result xtc_audio_plan_render(const xtc_audio_plan *p, uint64_t position, float *out, size_t frames)
|
||||
{ return xtc_audio_plan_render_stereo(p, position, out, NULL, frames); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue