From e6524ea945a32782e4c541ec662777f38d4a188b Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 8 Mar 2025 11:21:13 -0500 Subject: [PATCH] cwWaveTableBank.h/cpp : Fixed memory leak and added loadThreadCnt arg. to create(). --- cwWaveTableBank.cpp | 24 +++++++++++++----------- cwWaveTableBank.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cwWaveTableBank.cpp b/cwWaveTableBank.cpp index 5ca836b..0b93390 100644 --- a/cwWaveTableBank.cpp +++ b/cwWaveTableBank.cpp @@ -167,20 +167,21 @@ namespace cw for(unsigned i=0; iinstrN; ++i ) _destroy_instr(p->instrA[i]); - + + mem::release(p->instrA); mem::release(p); return rc; } unsigned _alloc_wt( const wt_bank_t* p, - wt_t* wt, - wt_tid_t tid, - srate_t srate, - const sample_t* aV, - unsigned posn_smp_idx, - unsigned aN, - double hz, - double rms) + wt_t* wt, + wt_tid_t tid, + srate_t srate, + const sample_t* aV, + unsigned posn_smp_idx, + unsigned aN, + double hz, + double rms) { wt->tid = tid; wt->aN = aN; @@ -396,7 +397,7 @@ namespace cw } -cw::rc_t cw::wt_bank::create( handle_t& hRef, unsigned padSmpN, const char* instr_json_fname ) +cw::rc_t cw::wt_bank::create( handle_t& hRef, unsigned padSmpN, const char* instr_json_fname, unsigned loadThreadCnt ) { rc_t rc = kOkRC; @@ -409,7 +410,7 @@ cw::rc_t cw::wt_bank::create( handle_t& hRef, unsigned padSmpN, const char* inst hRef.set(p); if( instr_json_fname != nullptr ) - if((rc = load(hRef,instr_json_fname)) != kOkRC ) + if((rc = load(hRef,instr_json_fname,loadThreadCnt)) != kOkRC ) { hRef.clear(); } @@ -536,6 +537,7 @@ errLabel: //_audio_buf_free(abuf); + mem::release(argsA); mem::release(taskA); destroy(threadTasksH); diff --git a/cwWaveTableBank.h b/cwWaveTableBank.h index 0366ed1..50d7d70 100644 --- a/cwWaveTableBank.h +++ b/cwWaveTableBank.h @@ -19,7 +19,7 @@ namespace cw typedef struct dsp::multi_ch_wt_seq_osc::multi_ch_wt_seq_str multi_ch_wt_seq_t; - rc_t create( handle_t& hRef, unsigned padSmpN, const char* instr_json_fname=nullptr ); + rc_t create( handle_t& hRef, unsigned padSmpN, const char* instr_json_fname=nullptr, unsigned loadThreadCnt=16 ); rc_t destroy( handle_t& hRef ); void report( handle_t h );