Phase 12: Improve audio transitions and verify sample-accurate timing
This commit is contained in:
parent
461689dd44
commit
05140c2e93
29 changed files with 795 additions and 33 deletions
38
src/dsp/ramp.c
Normal file
38
src/dsp/ramp.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "xtc/xtc_dsp.h"
|
||||
#include <math.h>
|
||||
|
||||
float xtc_dsp_finite(float sample)
|
||||
{
|
||||
return !isfinite(sample) || fpclassify(sample) == FP_SUBNORMAL ? 0.0f : sample;
|
||||
}
|
||||
xtc_result xtc_gain_ramp_reset(xtc_gain_ramp *ramp, float value)
|
||||
{
|
||||
if (!ramp || !isfinite(value)) return XTC_ERR_INVALID_ARGUMENT;
|
||||
ramp->current = ramp->target = value;
|
||||
ramp->remaining = 0;
|
||||
return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_gain_ramp_target(xtc_gain_ramp *ramp, float target, size_t frames)
|
||||
{
|
||||
if (!ramp || !isfinite(target) || frames > 65536) return XTC_ERR_INVALID_ARGUMENT;
|
||||
ramp->target = target;
|
||||
ramp->remaining = frames;
|
||||
if (!frames) ramp->current = target;
|
||||
return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_gain_ramp_process(xtc_gain_ramp *ramp, float *left, float *right, size_t frames)
|
||||
{
|
||||
size_t i;
|
||||
if (!ramp || !left || (right && left == right) || frames > 65536)
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
for (i = 0; i < frames; ++i) {
|
||||
if (ramp->remaining) {
|
||||
ramp->current = (float)((double)ramp->current +
|
||||
((double)ramp->target - ramp->current) / (double)ramp->remaining);
|
||||
if (!--ramp->remaining) ramp->current = ramp->target;
|
||||
}
|
||||
left[i] = xtc_dsp_finite(left[i] * ramp->current);
|
||||
if (right) right[i] = xtc_dsp_finite(right[i] * ramp->current);
|
||||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue