cwDynRefTbl.cpp : Fixed bug in _fill_level_lookup_table() where incorrect index was used.

Added missing: release(p->levelLookupA) in _destroy().
This commit is contained in:
kevin 2023-10-21 09:54:23 -04:00
parent f68e98082c
commit 6938e5a278

View File

@ -13,10 +13,10 @@ namespace cw
{ {
typedef struct dyn_ref_tbl_str typedef struct dyn_ref_tbl_str
{ {
dyn_ref_t* dynRefA; dyn_ref_t* dynRefA; // dynRefA[ dynRefN ] one entry per dyn. level
unsigned dynRefN; unsigned dynRefN; //
unsigned* levelLookupA; unsigned* levelLookupA; // levelLoopA[ levelLookupN ] - one entry per velocity value (0-127)
unsigned levelLookupN; unsigned levelLookupN; // levelLooupN = kMidiVelCnt
} dyn_ref_tbl_t; } dyn_ref_tbl_t;
@ -31,6 +31,7 @@ namespace cw
std::for_each(p->dynRefA, p->dynRefA+p->dynRefN, relse ); std::for_each(p->dynRefA, p->dynRefA+p->dynRefN, relse );
mem::release(p->dynRefA); mem::release(p->dynRefA);
mem::release(p->levelLookupA);
mem::release(p); mem::release(p);
return rc; return rc;
} }
@ -39,13 +40,15 @@ namespace cw
{ {
for(midi::byte_t vel=0; vel<midi::kMidiVelCnt; ++vel) for(midi::byte_t vel=0; vel<midi::kMidiVelCnt; ++vel)
for(unsigned i=0; i<p->levelLookupN; ++i) for(unsigned i=0; i<p->dynRefN; ++i)
if( p->dynRefA[i].velocity >= vel ) if( p->dynRefA[i].velocity >= vel )
{ {
midi::byte_t d0 = p->dynRefA[i].velocity - vel; midi::byte_t d0 = p->dynRefA[i].velocity - vel;
midi::byte_t d1 = i>0 ? (vel - p->dynRefA[i-1].velocity) : d0; midi::byte_t d1 = i>0 ? (vel - p->dynRefA[i-1].velocity) : d0;
unsigned j = d0 <= d1 ? i : i-1; unsigned j = d0 <= d1 ? i : i-1;
assert( vel <= p->levelLookupN );
p->levelLookupA[vel] = p->dynRefA[j].level; p->levelLookupA[vel] = p->dynRefA[j].level;
break; break;
} }