diff --git a/cwFlow.cpp b/cwFlow.cpp index 6219c50..01f55b9 100644 --- a/cwFlow.cpp +++ b/cwFlow.cpp @@ -42,6 +42,7 @@ namespace cw { "dc_filter", &dc_filter::members }, { "balance", &balance::members }, { "audio_meter", &audio_meter::members }, + { "audio_marker", &audio_marker::members }, { nullptr, nullptr } }; diff --git a/cwFlowProc.cpp b/cwFlowProc.cpp index 6dac2e6..8a7dc8c 100644 --- a/cwFlowProc.cpp +++ b/cwFlowProc.cpp @@ -1731,7 +1731,7 @@ namespace cw //abuf_set_channel( dstBuf, i, inst->pvA[i]->ola->outV, dstBuf->frameN ); } - + errLabel: return rc; } @@ -2752,6 +2752,104 @@ namespace cw .report = report }; } + + //------------------------------------------------------------------------------------------------------------------ + // + // audio_marker + // + namespace audio_marker + { + enum + { + kInPId, + kMarkPId, + kOutPId + }; + + typedef struct inst_str + { + real_t mark; + } inst_t; + + rc_t create( instance_t* ctx ) + { + rc_t rc = kOkRC; + const abuf_t* abuf = nullptr; // + ctx->userPtr = mem::allocZ(); + + // get the source audio buffer + if((rc = var_register_and_get(ctx, kAnyChIdx,kInPId,"in",abuf )) != kOkRC ) + goto errLabel; + + // register the marker input + if((rc = var_register_and_set( ctx, kAnyChIdx, kMarkPId, "mark", 0.0f )) != kOkRC ) + goto errLabel; + + // create the output audio buffer + rc = var_register_and_set( ctx, "out", kOutPId, kAnyChIdx, abuf->srate, abuf->chN, abuf->frameN ); + + errLabel: + return rc; + } + + rc_t destroy( instance_t* ctx ) + { + inst_t* inst = (inst_t*)(ctx->userPtr); + mem::release(inst); + return kOkRC; + } + + rc_t value( instance_t* ctx, variable_t* var ) + { + return kOkRC; + } + + rc_t exec( instance_t* ctx ) + { + rc_t rc = kOkRC; + const abuf_t* ibuf = nullptr; + abuf_t* obuf = nullptr; + //inst_t* inst = (inst_t*)(ctx->userPtr); + sample_t mark = 1; + + // get the src buffer + if((rc = var_get(ctx,kInPId, kAnyChIdx, ibuf )) != kOkRC ) + goto errLabel; + + // get the dst buffer + if((rc = var_get(ctx,kOutPId, kAnyChIdx, obuf)) != kOkRC ) + goto errLabel; + + + var_get(ctx,kMarkPId,kAnyChIdx,mark); + + // for each channel + for(unsigned i=0; ichN; ++i) + { + sample_t* isig = ibuf->buf + i*ibuf->frameN; + sample_t* osig = obuf->buf + i*obuf->frameN; + + // apply the marker + for(unsigned j=0; jframeN; ++j) + osig[j] = mark + isig[j]; + } + + var_set(ctx,kMarkPId,kAnyChIdx,0.0f); + + errLabel: + return rc; + } + + + class_members_t members = { + .create = create, + .destroy = destroy, + .value = value, + .exec = exec, + .report = nullptr + }; + + } } // flow diff --git a/cwFlowProc.h b/cwFlowProc.h index 9adcb95..15fee86 100644 --- a/cwFlowProc.h +++ b/cwFlowProc.h @@ -21,5 +21,6 @@ namespace cw namespace dc_filter { extern class_members_t members; } namespace balance { extern class_members_t members; } namespace audio_meter { extern class_members_t members; } + namespace audio_marker { extern class_members_t members; } } }