Some code semantics refactoring.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:37:21 +01:00
commit 0f04e056b2
42 changed files with 3374 additions and 1357 deletions

View file

@ -1,18 +1,22 @@
#ifndef XTC_MIX_INTERNAL_H
#define XTC_MIX_INTERNAL_H
#include "../project/project_internal.h"
typedef struct {
uint64_t sample, tick;
size_t track;
unsigned int parameter;
float value;
} xtc_mix_point;
typedef struct {
xtc_track_info tracks[XTC_PROJECT_MAX_TRACKS];
size_t count, offsets[XTC_PROJECT_MAX_TRACKS][2], lengths[XTC_PROJECT_MAX_TRACKS][2];
xtc_mix_point points[XTC_MAX_AUTOMATION_POINTS];
int any_solo;
} xtc_mix_snapshot;
xtc_result xtc_mix_prepare(const xtc_project *, unsigned int rate, xtc_mix_snapshot *);
size_t xtc_mix_track(const xtc_mix_snapshot *, uint64_t id);
/* side 0/1 stereo, 2 mono (gain only). */

View file

@ -1,6 +1,7 @@
#include "../project/project_internal.h"
#include <math.h>
#include <string.h>
static size_t find_track(const xtc_project *p, uint64_t id)
{
size_t i;
@ -9,8 +10,8 @@ static size_t find_track(const xtc_project *p, uint64_t id)
return i;
return SIZE_MAX;
}
xtc_result xtc_project_set_mix(xtc_project *p, uint64_t id, float gain, float pan, int mute,
int solo)
xtc_result xtc_project_set_mix(xtc_project *p, uint64_t id, float gain, float pan, int mute, int solo)
{
size_t i;
if (!p || !isfinite(gain) || gain < 0 || gain > 4 || !isfinite(pan) || pan < -1 || pan > 1 ||
@ -25,6 +26,7 @@ xtc_result xtc_project_set_mix(xtc_project *p, uint64_t id, float gain, float pa
p->tracks[i].solo = solo;
return XTC_OK;
}
xtc_result xtc_project_set_automation(xtc_project *p, const xtc_automation_point *a)
{
size_t i;
@ -36,8 +38,8 @@ xtc_result xtc_project_set_automation(xtc_project *p, const xtc_automation_point
if (find_track(p, a->track_id) == SIZE_MAX)
return XTC_ERR_NOT_FOUND;
for (i = 0; i < p->automation_count; ++i)
if (p->automation[i].track_id == a->track_id &&
p->automation[i].parameter == a->parameter && p->automation[i].tick == a->tick)
if (p->automation[i].track_id == a->track_id && p->automation[i].parameter == a->parameter &&
p->automation[i].tick == a->tick)
break;
if (i == XTC_MAX_AUTOMATION_POINTS)
return XTC_ERR_CAPACITY;
@ -46,23 +48,21 @@ xtc_result xtc_project_set_automation(xtc_project *p, const xtc_automation_point
p->automation[i] = *a;
return XTC_OK;
}
xtc_result xtc_project_remove_automation(xtc_project *p, uint64_t id,
xtc_automation_parameter param, uint64_t tick)
xtc_result xtc_project_remove_automation(xtc_project *p, uint64_t id, xtc_automation_parameter param, uint64_t tick)
{
size_t i;
if (!p || (param != XTC_AUTOMATION_GAIN && param != XTC_AUTOMATION_PAN) ||
tick > XTC_PROJECT_MAX_TICK)
if (!p || (param != XTC_AUTOMATION_GAIN && param != XTC_AUTOMATION_PAN) || tick > XTC_PROJECT_MAX_TICK)
return XTC_ERR_INVALID_ARGUMENT;
for (i = 0; i < p->automation_count; ++i)
if (p->automation[i].track_id == id && p->automation[i].parameter == param &&
p->automation[i].tick == tick)
if (p->automation[i].track_id == id && p->automation[i].parameter == param && p->automation[i].tick == tick)
break;
if (i == p->automation_count)
return XTC_ERR_NOT_FOUND;
memmove(p->automation + i, p->automation + i + 1,
(--p->automation_count - i) * sizeof(*p->automation));
memmove(p->automation + i, p->automation + i + 1, (--p->automation_count - i) * sizeof(*p->automation));
return XTC_OK;
}
xtc_result xtc_project_automation_count(const xtc_project *p, size_t *n)
{
if (!p || !n)
@ -70,6 +70,7 @@ xtc_result xtc_project_automation_count(const xtc_project *p, size_t *n)
*n = p->automation_count;
return XTC_OK;
}
xtc_result xtc_project_get_automation(const xtc_project *p, size_t i, xtc_automation_point *a)
{
if (!p || !a)

View file

@ -1,6 +1,7 @@
#include "mix_internal.h"
#include <stdlib.h>
#include <string.h>
size_t xtc_mix_track(const xtc_mix_snapshot *m, uint64_t id)
{
size_t i;
@ -9,6 +10,7 @@ size_t xtc_mix_track(const xtc_mix_snapshot *m, uint64_t id)
return i;
return SIZE_MAX;
}
static int compare(const void *left, const void *right)
{
const xtc_mix_point *a = left, *b = right;
@ -18,6 +20,7 @@ static int compare(const void *left, const void *right)
return a->parameter < b->parameter ? -1 : 1;
return a->tick < b->tick ? -1 : a->tick != b->tick;
}
xtc_result xtc_mix_prepare(const xtc_project *p, unsigned int rate, xtc_mix_snapshot *m)
{
size_t i;
@ -51,6 +54,7 @@ xtc_result xtc_mix_prepare(const xtc_project *p, unsigned int rate, xtc_mix_snap
}
return XTC_OK;
}
static float value(const xtc_mix_snapshot *m, size_t track, unsigned int param, uint64_t sample)
{
size_t low = 0, high = m->lengths[track][param], count = high;
@ -72,6 +76,7 @@ static float value(const xtc_mix_snapshot *m, size_t track, unsigned int param,
(double)(p[low].sample - p[low - 1].sample) *
(p[low].value - p[low - 1].value));
}
float xtc_mix_level(const xtc_mix_snapshot *m, size_t track, uint64_t sample, unsigned int side)
{
float gain, pan;