cwFlow,cwFlowProc,cwFlowTypes: Changes to support proc's taking a variable count of numbered inputs.

This commit is contained in:
kevin 2022-11-11 13:09:07 -05:00
parent 3b050ab640
commit 79022916fe
4 changed files with 103 additions and 22 deletions

View File

@ -137,6 +137,7 @@ namespace cw
const char* type_str = nullptr; const char* type_str = nullptr;
unsigned type_flag = 0; unsigned type_flag = 0;
bool srcVarFl = false; bool srcVarFl = false;
bool srcOptFl = false;
var_desc_t* vd = mem::allocZ<var_desc_t>(); var_desc_t* vd = mem::allocZ<var_desc_t>();
vd->label = var_obj->pair_label(); vd->label = var_obj->pair_label();
@ -158,7 +159,9 @@ namespace cw
} }
// get the variable description // get the variable description
if((rc = vd->cfg->getv_opt("srcFl", srcVarFl,"value",vd->val_cfg)) != kOkRC ) if((rc = vd->cfg->getv_opt("srcFl", srcVarFl,
"srcOptFl", srcOptFl,
"value",vd->val_cfg)) != kOkRC )
{ {
rc = cwLogError(rc,"Parsing optional fields failed on class:%s variable: '%s'.", cd->label, vd->label ); rc = cwLogError(rc,"Parsing optional fields failed on class:%s variable: '%s'.", cd->label, vd->label );
goto errLabel; goto errLabel;
@ -168,9 +171,10 @@ namespace cw
vd->type |= type_flag; vd->type |= type_flag;
if( srcVarFl ) if( srcVarFl )
{
vd->flags |= kSrcVarFl; vd->flags |= kSrcVarFl;
}
if( srcOptFl )
vd->flags |= kSrcOptVarFl;
vd->link = cd->varDescL; vd->link = cd->varDescL;
cd->varDescL = vd; cd->varDescL = vd;

View File

@ -564,7 +564,7 @@ namespace cw
// print a minutes counter // print a minutes counter
inst->durSmpN += src_abuf->frameN; inst->durSmpN += src_abuf->frameN;
if( inst->durSmpN % ((unsigned)src_abuf->srate*60) == 0 ) if( inst->durSmpN % ((unsigned)src_abuf->srate*60) == 0 )
printf("%5.1f min\n", inst->durSmpN/(src_abuf->srate*60)); printf("audio file out: %5.1f min\n", inst->durSmpN/(src_abuf->srate*60));
} }
@ -982,35 +982,64 @@ namespace cw
namespace audio_merge namespace audio_merge
{ {
enum { enum {
kIn0PId,
kIn1PId,
kGainPId, kGainPId,
kOutPId, kOutPId,
kInBasePId,
}; };
typedef struct typedef struct
{ {
unsigned srcN;
} inst_t; } inst_t;
rc_t create( instance_t* ctx ) rc_t create( instance_t* ctx )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
const abuf_t* abuf0 = nullptr; //
const abuf_t* abuf1 = nullptr;
unsigned outChN = 0; unsigned outChN = 0;
unsigned frameN = 0;
// get the source audio buffer srate_t srate = 0;
if((rc = var_register_and_get(ctx, kAnyChIdx,
kIn0PId,"in0",abuf0, inst_t* inst = mem::allocZ<inst_t>();
kIn1PId,"in1",abuf1 )) != kOkRC )
ctx->userPtr = inst;
for(unsigned i=0; 1; ++i)
{ {
goto errLabel; const abuf_t* abuf = nullptr; //
char label[32];
snprintf(label,31,"in%i",i);
label[31] = 0;
// TODO: allow non-contiguous source labels
// the source labels must be contiguous
if( !var_has_value( ctx, label, kAnyChIdx ) )
break;
// get the source audio buffer
if((rc = var_register_and_get(ctx, kAnyChIdx,kInBasePId+i,label,abuf )) != kOkRC )
{
goto errLabel;
}
if( i == 0 )
{
frameN = abuf->frameN;
srate = abuf->srate;
}
else
{
// TODO: check srate and frameN are same as first src
}
inst->srcN += 1;
outChN += abuf->chN;
} }
assert( abuf0->frameN == abuf1->frameN ); //outChN = abuf0->chN + abuf1->chN;
outChN = abuf0->chN + abuf1->chN;
// register the gain // register the gain
for(unsigned i=0; i<outChN; ++i) for(unsigned i=0; i<outChN; ++i)
@ -1018,14 +1047,20 @@ namespace cw
goto errLabel; goto errLabel;
// create the output audio buffer // create the output audio buffer
rc = var_register_and_set( ctx, "out", kOutPId, kAnyChIdx, abuf0->srate, outChN, abuf0->frameN ); rc = var_register_and_set( ctx, "out", kOutPId, kAnyChIdx, srate, outChN, frameN );
errLabel: errLabel:
return rc; return rc;
} }
rc_t destroy( instance_t* ctx ) rc_t destroy( instance_t* ctx )
{ return kOkRC; } {
inst_t* inst = (inst_t*)ctx->userPtr;
mem::release(inst);
return kOkRC;
}
rc_t value( instance_t* ctx, variable_t* var ) rc_t value( instance_t* ctx, variable_t* var )
{ return kOkRC; } { return kOkRC; }
@ -1052,6 +1087,7 @@ namespace cw
return outChIdx; return outChIdx;
} }
/*
rc_t exec( instance_t* ctx ) rc_t exec( instance_t* ctx )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -1074,6 +1110,31 @@ namespace cw
assert( oChIdx == obuf->chN ); assert( oChIdx == obuf->chN );
errLabel:
return rc;
}
*/
rc_t exec( instance_t* ctx )
{
rc_t rc = kOkRC;
inst_t* inst = (inst_t*)ctx->userPtr;
abuf_t* obuf = nullptr;
unsigned oChIdx = 0;
if((rc = var_get(ctx,kOutPId, kAnyChIdx, obuf)) != kOkRC )
goto errLabel;
for(unsigned i=0; i<inst->srcN; ++i)
{
const abuf_t* ibuf = nullptr;
if((rc = var_get(ctx,kInBasePId+i, kAnyChIdx, ibuf )) != kOkRC )
goto errLabel;
oChIdx = _exec( ctx, ibuf, obuf, oChIdx );
}
errLabel: errLabel:
return rc; return rc;
} }
@ -1087,6 +1148,7 @@ namespace cw
}; };
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
// //

View File

@ -1013,9 +1013,10 @@ void cw::flow::class_dict_print( flow_t* p )
for(; vd!=nullptr; vd=vd->link) for(; vd!=nullptr; vd=vd->link)
{ {
const char* srcFlStr = vd->flags&kSrcVarFl ? "src" : " "; const char* srcFlStr = vd->flags & kSrcVarFl ? "src" : " ";
const char* srcOptFlStr = vd->flags & kSrcOptVarFl ? "srcOpt" : " ";
printf(" %10s 0x%08x %s %s\n", cwStringNullGuard(vd->label), vd->type, srcFlStr, cwStringNullGuard(vd->docText) ); printf(" %10s 0x%08x %s %s %s\n", cwStringNullGuard(vd->label), vd->type, srcFlStr, srcOptFlStr, cwStringNullGuard(vd->docText) );
} }
} }
} }
@ -1162,6 +1163,17 @@ cw::rc_t cw::flow::var_channelize( instance_t* inst, const char* var_label, uns
bool cw::flow::var_exists( instance_t* inst, const char* label, unsigned chIdx ) bool cw::flow::var_exists( instance_t* inst, const char* label, unsigned chIdx )
{ return _var_find_on_label_and_ch(inst,label,chIdx) != nullptr; } { return _var_find_on_label_and_ch(inst,label,chIdx) != nullptr; }
bool cw::flow::var_has_value( instance_t* inst, const char* label, unsigned chIdx )
{
variable_t* varPtr = nullptr;
rc_t rc;
if((rc = var_find( inst, label, chIdx, varPtr )) != kOkRC )
return false;
return varPtr->value != nullptr;
}
cw::rc_t cw::flow::var_find( instance_t* inst, unsigned vid, unsigned chIdx, variable_t*& varRef ) cw::rc_t cw::flow::var_find( instance_t* inst, unsigned vid, unsigned chIdx, variable_t*& varRef )
{ {

View File

@ -115,7 +115,9 @@ namespace cw
typedef rc_t (*member_value_func_t)( struct instance_str* ctx, struct variable_str* var ); typedef rc_t (*member_value_func_t)( struct instance_str* ctx, struct variable_str* var );
enum enum
{ {
kSrcVarFl = 0x01 kSrcVarFl = 0x01,
kSrcOptVarFl = 0x02
}; };
typedef struct class_members_str typedef struct class_members_str
@ -397,6 +399,7 @@ namespace cw
void _var_destroy( variable_t* var ); void _var_destroy( variable_t* var );
bool var_exists( instance_t* inst, const char* label, unsigned chIdx ); bool var_exists( instance_t* inst, const char* label, unsigned chIdx );
bool var_has_value( instance_t* inst, const char* label, unsigned chIdx );
rc_t var_find( instance_t* inst, const char* var_label, unsigned chIdx, const variable_t*& varRef ); rc_t var_find( instance_t* inst, const char* var_label, unsigned chIdx, const variable_t*& varRef );
rc_t var_find( instance_t* inst, const char* var_label, unsigned chIdx, variable_t*& varRef ); rc_t var_find( instance_t* inst, const char* var_label, unsigned chIdx, variable_t*& varRef );