From 2d749cabeb92b3da78f32927fbeb300aab5749dc Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 19 Apr 2025 13:46:13 -0400 Subject: [PATCH] cwAudioBuf.h/cpp : Added damping to meter calculation and create() arg. 'meterDampCoeff'. --- cwAudioBuf.cpp | 14 +++++++++----- cwAudioBuf.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cwAudioBuf.cpp b/cwAudioBuf.cpp index d229497..f6c2799 100644 --- a/cwAudioBuf.cpp +++ b/cwAudioBuf.cpp @@ -103,6 +103,8 @@ namespace cw sample_t* zeroBuf; // buffer of zeros unsigned zeroBufCnt; // max of all dspFrameCnt for all devices. + + float meter_damp_coeff; } audioBuf_t; inline audioBuf_t* _handleToPtr( handle_t h ) { return handleToPtr(h); } @@ -263,7 +265,7 @@ namespace cw } } -cw::rc_t cw::audio::buf::create( handle_t& hRef, unsigned devCnt, unsigned meterMs ) +cw::rc_t cw::audio::buf::create( handle_t& hRef, unsigned devCnt, unsigned meterMs, float meterDampCoeff ) { rc_t rc; @@ -274,7 +276,8 @@ cw::rc_t cw::audio::buf::create( handle_t& hRef, unsigned devCnt, unsigned meter p->devArray = mem::allocZ(devCnt ); p->devCnt = devCnt; - + p->meter_damp_coeff = meterDampCoeff; + hRef.set(p); setMeterMs(hRef,meterMs); @@ -422,11 +425,10 @@ cw::rc_t cw::audio::buf::update( sample_t* dp = cp->b + cp->ii; const sample_t* ep = dp + n0; - // update the meter if( cwIsFlag(cp->fl,kMeterFl) ) { - cp->m[cp->mi] = _cmApMeter(sp,pp->audioFramesCnt,pp->chCnt); + cp->m[cp->mi] = (1.0f - p->meter_damp_coeff) * cp->m[cp->mi] + p->meter_damp_coeff*_cmApMeter(sp,pp->audioFramesCnt,pp->chCnt); cp->mi = (cp->mi + 1) % cp->mn; } @@ -538,7 +540,9 @@ cw::rc_t cw::audio::buf::update( // update the meter if( cwIsFlag(cp->fl,kMeterFl) ) { - cp->m[cp->mi] = _cmApMeter(((sample_t*)pp->audioBytesPtr)+j,pp->audioFramesCnt,pp->chCnt); + //cp->m[cp->mi] = _cmApMeter(((sample_t*)pp->audioBytesPtr)+j,pp->audioFramesCnt,pp->chCnt); + cp->m[cp->mi] = (1.0f - p->meter_damp_coeff) * cp->m[cp->mi] + p->meter_damp_coeff*_cmApMeter(((sample_t*)pp->audioBytesPtr)+j,pp->audioFramesCnt,pp->chCnt); + cp->mi = (cp->mi + 1) % cp->mn; } diff --git a/cwAudioBuf.h b/cwAudioBuf.h index 48b7eea..273b508 100644 --- a/cwAudioBuf.h +++ b/cwAudioBuf.h @@ -66,7 +66,7 @@ namespace cw // Allocate and initialize an audio buffer. // devCnt - count of devices this buffer will handle. // meterMs - length of the meter buffers in milliseconds (automatically limit to the range:10 to 1000) - rc_t create( handle_t& hRef, unsigned devCnt, unsigned meterMs ); + rc_t create( handle_t& hRef, unsigned devCnt, unsigned meterMs, float meterDampCoeff=0.4 ); // Deallocate and release any resource held by an audio buffer allocated via initialize(). rc_t destroy( handle_t& hRef );