From 645e67fee45cb2cee65a67cda5b2d20231b41e59 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 2 Aug 2024 13:37:35 -0400 Subject: [PATCH] cwWaveTableBank.cpp : PV map now fills in missing velocities between sampled velocities. --- cwWaveTableBank.cpp | 46 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/cwWaveTableBank.cpp b/cwWaveTableBank.cpp index 04db5c5..11b8dbd 100644 --- a/cwWaveTableBank.cpp +++ b/cwWaveTableBank.cpp @@ -178,13 +178,13 @@ namespace cw double hz, double rms) { - wt->tid = tid; - wt->aN = aN; - wt->hz = hz; - wt->rms = rms; + wt->tid = tid; + wt->aN = aN; + wt->hz = hz; + wt->rms = rms; wt->cyc_per_loop = 1; - wt->srate = srate; - wt->pad_smpN = p->padSmpN; + wt->srate = srate; + wt->pad_smpN = p->padSmpN; wt->posn_smp_idx = posn_smp_idx; unsigned allocSmpCnt = p->padSmpN + wt->aN + p->padSmpN; @@ -207,8 +207,14 @@ namespace cw rc_t _create_instr_pv_map( instr_t* instr ) { rc_t rc = kOkRC; - instr->pvM = mem::allocZ(midi::kMidiVelCnt * midi::kMidiNoteCnt ); + + // each row contains the velocities for a given pitch + instr->pvM = mem::allocZ(midi::kMidiNoteCnt * midi::kMidiVelCnt ); + for(unsigned i=0; ipitchN; ++i) + { + unsigned vel0 = 0; + for(unsigned j=0; jpitchA[i].velN; ++j) { unsigned pitch = instr->pitchA[i].midi_pitch; @@ -219,10 +225,32 @@ namespace cw if( vel >= midi::kMidiVelCnt ) rc = cwLogError(kInvalidArgRC,"An invalid velocity value (%i) was encountered.",vel); + + multi_ch_wt_seq_t* mcs = &instr->pitchA[i].velA[j].mc_seq; + + // if there is a gap between vel0 and vel + if( vel0 > 0 ) + { + // find the center of the gap + unsigned vel_c = vel0 + (vel-vel0)/2; + + // vel0:vel_c = mcs0 + for(unsigned v=vel0+1; v<=vel_c; ++v) + { + instr->pvM[(v*midi::kMidiNoteCnt) + pitch ] = instr->pvM[(vel0*midi::kMidiNoteCnt) + pitch ]; + } + + // vel_c+1:vel-1 = mcs + for(unsigned v=vel_c+1; vpvM[(v*midi::kMidiNoteCnt) + pitch ] = mcs; + } + } - instr->pvM[(vel*midi::kMidiNoteCnt) + pitch ] = &instr->pitchA[i].velA[j].mc_seq; - + instr->pvM[(vel*midi::kMidiNoteCnt) + pitch ] = mcs; + vel0 = vel; } + } if( rc != kOkRC ) rc = cwLogError(rc,"Pitch-velocy map creation failed on instrument:'%s'.",cwStringNullGuard(instr->label));