cwFlowProc.cpp: Allow interactive changing of audio_delay() delay param.

This commit is contained in:
kevin 2023-05-25 16:02:00 -04:00
parent a4188a7ff0
commit abcaa093c7

View File

@ -118,8 +118,8 @@ namespace cw
goto errLabel; goto errLabel;
} }
errLabel: errLabel:
return rc; return rc;
} }
rc_t destroy( instance_t* ctx ) rc_t destroy( instance_t* ctx )
@ -1130,8 +1130,8 @@ namespace cw
} }
/* /*
rc_t exec( instance_t* ctx ) rc_t exec( instance_t* ctx )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
const abuf_t* ibuf0 = nullptr; const abuf_t* ibuf0 = nullptr;
const abuf_t* ibuf1 = nullptr; const abuf_t* ibuf1 = nullptr;
@ -1139,22 +1139,22 @@ namespace cw
unsigned oChIdx = 0; unsigned oChIdx = 0;
if((rc = var_get(ctx,kIn0PId, kAnyChIdx, ibuf0 )) != kOkRC ) if((rc = var_get(ctx,kIn0PId, kAnyChIdx, ibuf0 )) != kOkRC )
goto errLabel; goto errLabel;
if((rc = var_get(ctx,kIn1PId, kAnyChIdx, ibuf1 )) != kOkRC ) if((rc = var_get(ctx,kIn1PId, kAnyChIdx, ibuf1 )) != kOkRC )
goto errLabel; goto errLabel;
if((rc = var_get(ctx,kOutPId, kAnyChIdx, obuf)) != kOkRC ) if((rc = var_get(ctx,kOutPId, kAnyChIdx, obuf)) != kOkRC )
goto errLabel; goto errLabel;
oChIdx = _exec( ctx, ibuf0, obuf, oChIdx ); oChIdx = _exec( ctx, ibuf0, obuf, oChIdx );
oChIdx = _exec( ctx, ibuf1, obuf, oChIdx ); oChIdx = _exec( ctx, ibuf1, obuf, oChIdx );
assert( oChIdx == obuf->chN ); assert( oChIdx == obuf->chN );
errLabel: errLabel:
return rc; return rc;
} }
*/ */
rc_t exec( instance_t* ctx ) rc_t exec( instance_t* ctx )
@ -1537,7 +1537,7 @@ namespace cw
inst_t* inst = (inst_t*)ctx->userPtr; inst_t* inst = (inst_t*)ctx->userPtr;
for(unsigned i=0; i<inst->pvN; ++i) for(unsigned i=0; i<inst->pvN; ++i)
destroy(inst->pvA[i]); destroy(inst->pvA[i]);
mem::release(inst->pvA); mem::release(inst->pvA);
mem::release(inst); mem::release(inst);
@ -2384,8 +2384,53 @@ namespace cw
return kOkRC; return kOkRC;
} }
rc_t _update_delay( instance_t* ctx, variable_t* var )
{
rc_t rc = kOkRC;
inst_t* inst = (inst_t*)ctx->userPtr;
abuf_t* ibuf = nullptr;
real_t delayMs = 0;
unsigned delayFrameN = 0;
if((rc = var_get(ctx,kInPId, kAnyChIdx, ibuf )) != kOkRC )
goto errLabel;
if((rc = var_get( var, delayMs )) != kOkRC )
goto errLabel;
delayFrameN = (unsigned)(fabs(delayMs) * ibuf->srate / 1000.0);
if( delayFrameN > inst->maxDelayFrameN )
{
delayFrameN = inst->maxDelayFrameN;
cwLogWarning("The audio delay length is limited to %i milliseconds.", (int)((delayFrameN * 1000) / ibuf->srate));
}
vop::zero(inst->delayBuf->buf,inst->delayBuf->chN*inst->delayBuf->frameN);
for(unsigned i=0; i<ibuf->chN; ++i)
{
inst->cntV[i] = delayFrameN;
inst->idxV[i] = 0;
}
errLabel:
return rc;
}
rc_t value( instance_t* ctx, variable_t* var ) rc_t value( instance_t* ctx, variable_t* var )
{ return kOkRC; } {
rc_t rc = kOkRC;
switch( var->vid )
{
case kDelayMsPId:
rc = _update_delay(ctx,var);
break;
}
return rc;
}
rc_t exec( instance_t* ctx ) rc_t exec( instance_t* ctx )
{ {
@ -2405,30 +2450,30 @@ namespace cw
// for each channel // for each channel
for(unsigned i=0; i<ibuf->chN; ++i) for(unsigned i=0; i<ibuf->chN; ++i)
{
sample_t* isig = ibuf->buf + i*ibuf->frameN;
sample_t* osig = obuf->buf + i*obuf->frameN;
sample_t* dsig = dbuf->buf + i*dbuf->frameN;
unsigned di = inst->idxV[i];
// if the delay is set to zero samples
if( inst->cntV[i] == 0 )
memcpy(osig,isig,ibuf->frameN * sizeof(sample_t));
else
{ {
sample_t* isig = ibuf->buf + i*ibuf->frameN; // otherwise the delay is non-zero positive sample count
sample_t* osig = obuf->buf + i*obuf->frameN; for(unsigned j=0; j<ibuf->frameN; ++j)
sample_t* dsig = dbuf->buf + i*dbuf->frameN;
unsigned di = inst->idxV[i];
// if the delay is set to zero samples
if( inst->cntV[i] == 0 )
memcpy(osig,isig,ibuf->frameN * sizeof(sample_t));
else
{ {
// otherwise the delay is non-zero positive sample count osig[j] = dsig[di]; // read delay output
for(unsigned j=0; j<ibuf->frameN; ++j) dsig[di] = isig[j]; // set delay input
{ di = (di+1) % inst->cntV[i]; // update the delay index
osig[j] = dsig[di]; // read delay output
dsig[di] = isig[j]; // set delay input
di = (di+1) % inst->cntV[i]; // update the delay index
}
} }
// store the delay index for the next cycle
inst->idxV[i] = di;
} }
// store the delay index for the next cycle
inst->idxV[i] = di;
}
errLabel: errLabel:
return rc; return rc;
} }
@ -2610,9 +2655,9 @@ namespace cw
kDbFlPId, kDbFlPId,
kWndMsPId, kWndMsPId,
kPeakDbPId, kPeakDbPId,
kOutPId, kOutPId,
kPeakFlPId, kPeakFlPId,
kClipFlPId kClipFlPId
}; };
@ -2648,28 +2693,28 @@ namespace cw
// create a audio_meter object for each input channel // create a audio_meter object for each input channel
for(unsigned i=0; i<srcBuf->chN; ++i) for(unsigned i=0; i<srcBuf->chN; ++i)
{ {
real_t wndMs, peakThreshDb; real_t wndMs, peakThreshDb;
bool dbFl; bool dbFl;
// get the audio_meter variable values // get the audio_meter variable values
if((rc = var_register_and_get( ctx, i, if((rc = var_register_and_get( ctx, i,
kDbFlPId, "dbFl", dbFl, kDbFlPId, "dbFl", dbFl,
kWndMsPId, "wndMs", wndMs, kWndMsPId, "wndMs", wndMs,
kPeakDbPId, "peakDb", peakThreshDb )) != kOkRC ) kPeakDbPId, "peakDb", peakThreshDb )) != kOkRC )
{ {
goto errLabel; goto errLabel;
} }
// get the audio_meter variable values // get the audio_meter variable values
if((rc = var_register( ctx, i, if((rc = var_register( ctx, i,
kOutPId, "out", kOutPId, "out",
kPeakFlPId, "peakFl", kPeakFlPId, "peakFl",
kClipFlPId, "clipFl" )) != kOkRC ) kClipFlPId, "clipFl" )) != kOkRC )
{ {
goto errLabel; goto errLabel;
} }
unsigned maxWndMs = std::max(wndMs,1000.0f); unsigned maxWndMs = std::max(wndMs,1000.0f);
// create the audio_meter instance // create the audio_meter instance
if((rc = dsp::audio_meter::create( inst->mtrA[i], srcBuf->srate, maxWndMs, wndMs, peakThreshDb)) != kOkRC ) if((rc = dsp::audio_meter::create( inst->mtrA[i], srcBuf->srate, maxWndMs, wndMs, peakThreshDb)) != kOkRC )
@ -2721,9 +2766,9 @@ namespace cw
for(unsigned i=0; i<chN; ++i) for(unsigned i=0; i<chN; ++i)
{ {
dsp::audio_meter::exec( inst->mtrA[i], srcBuf->buf + i*srcBuf->frameN, srcBuf->frameN ); dsp::audio_meter::exec( inst->mtrA[i], srcBuf->buf + i*srcBuf->frameN, srcBuf->frameN );
var_set(ctx, kOutPId, i, inst->mtrA[i]->outDb ); var_set(ctx, kOutPId, i, inst->mtrA[i]->outDb );
var_set(ctx, kPeakFlPId, i, inst->mtrA[i]->peakFl ); var_set(ctx, kPeakFlPId, i, inst->mtrA[i]->peakFl );
var_set(ctx, kClipFlPId, i, inst->mtrA[i]->clipFl ); var_set(ctx, kClipFlPId, i, inst->mtrA[i]->clipFl );
} }
errLabel: errLabel: