Skip to content

Commit

Permalink
fix CF_Preview dropping samples near the end of the source when pitch…
Browse files Browse the repository at this point in the history
… shifting

Fixes reaper-oss#1854
  • Loading branch information
cfillion committed Mar 12, 2024
1 parent 216638b commit 6bde8cf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cfillion/pitchshiftsource.cpp
Expand Up @@ -177,20 +177,23 @@ void PitchShiftSource_Audio::getShiftedSamples(const Block &block)
m_ps->Reset(); // to give immediate feedback with very slow play rates
}

bool isLastBlock = false;
do {
const int remaining { block.tx->length - block.tx->samples_out };
ReaSample *sample { block.tx->samples + (block.tx->samples_out * block.tx->nch) };
block.tx->samples_out += m_ps->GetSamples(remaining, sample);
if(block.tx->samples_out >= block.tx->length)
break; // output block is full

// feed the pitch shifter until it has enough data to fill the output block
sourceBlock.samples = m_ps->GetBuffer(sourceBlock.length);
sourceBlock.time_s = m_readTime;
m_src->GetSamples(&sourceBlock);
m_ps->BufferDone(sourceBlock.samples_out);
m_readTime += sourceBlock.samples_out * block.sampleTime;
} while(sourceBlock.samples_out == sourceBlock.length); // until EOF

isLastBlock = sourceBlock.samples_out < sourceBlock.length;
if(isLastBlock)
m_ps->FlushSamples();

const int remaining { block.tx->length - block.tx->samples_out };
ReaSample *sample { block.tx->samples + (block.tx->samples_out * block.tx->nch) };
block.tx->samples_out += m_ps->GetSamples(remaining, sample);
} while(block.tx->samples_out < block.tx->length && !isLastBlock);
}

static unsigned char clamp7b(const int v)
Expand Down

0 comments on commit 6bde8cf

Please sign in to comment.