Skip to content

Commit 587d912

Browse files
authored
Merge pull request #16 from lukemcraig/fix-irregular-blocks
handling irregular block sizes correctly
2 parents 798bac4 + c2dabe9 commit 587d912

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

PathSynth.jucer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
reportAppUsage="0" pluginCharacteristicsValue="pluginIsSynth,pluginWantsMidiIn"
55
bundleIdentifier="com.lukemcraig.pathsynth" companyName="Luke M. Craig"
66
pluginManufacturerCode="LMCA" pluginCode="LCPS" aaxIdentifier="com.lukemcraig.pathsynth"
7-
version="0.0.9" headerPath="../../Source">
7+
version="0.0.10" headerPath="../../Source">
88
<MAINGROUP id="xDUIZN" name="PathSynth">
99
<GROUP id="{1846AB2D-ABF1-CBCC-F291-C301634A6D20}" name="Source">
1010
<FILE id="gmjx7y" name="ParameterVTSHelper.cpp" compile="1" resource="0"

Source/PluginProcessor.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,26 @@ void PathSynthAudioProcessor::processBlock(AudioBuffer<float>& buffer, MidiBuffe
341341
oversampledBuffer.clear(0, 0, oversampledBuffer.getNumSamples());
342342

343343
{
344-
int numSamples = samplesPerSubBlock * oversampleFactor;
344+
int numSamplesPerOversampledBlock = samplesPerSubBlock * oversampleFactor;
345345
int totalSamples = buffer.getNumSamples() * oversampleFactor;
346-
for (int startSample = 0; startSample < totalSamples; startSample += numSamples)
346+
int numWholeBlocks = totalSamples / numSamplesPerOversampledBlock;
347+
348+
for (int blockNum = 0; blockNum < numWholeBlocks; ++blockNum)
347349
{
348-
setPath(numSamples);
350+
const int startSample = blockNum * numSamplesPerOversampledBlock;
351+
352+
setPath(numSamplesPerOversampledBlock);
349353

350-
keyboardState.processNextMidiBuffer(midiMessages, startSample, numSamples, true);
351-
synthesiser.renderNextBlock(oversampledBuffer, midiMessages, startSample, numSamples);
354+
keyboardState.processNextMidiBuffer(midiMessages, startSample, numSamplesPerOversampledBlock, true);
355+
synthesiser.renderNextBlock(oversampledBuffer, midiMessages, startSample, numSamplesPerOversampledBlock);
352356
}
353-
// in case the buffer didn't divide evenly. TODO double check this
354-
const int numSamplesLeft = totalSamples % numSamples;
357+
// in case the buffer didn't divide evenly.
358+
const int numSamplesLeft = totalSamples - (numWholeBlocks * numSamplesPerOversampledBlock);
355359
if (numSamplesLeft > 0)
356360
{
357361
const int startSample = totalSamples - numSamplesLeft;
358362

359-
//setPath(numSamplesLeft);
363+
setPath(numSamplesLeft);
360364

361365
keyboardState.processNextMidiBuffer(midiMessages, startSample, numSamplesLeft, true);
362366
synthesiser.renderNextBlock(oversampledBuffer, midiMessages, startSample, numSamplesLeft);
@@ -581,11 +585,14 @@ void PathSynthAudioProcessor::setPath(int numSamples)
581585
}
582586
}
583587
// if we reached the end of the path without finishing, use the final value
584-
if (!filledValue){
585-
if (direction == 0){
588+
if (!filledValue)
589+
{
590+
if (direction == 0)
591+
{
586592
wavetable[i] = iterator.x2;
587593
}
588-
else{
594+
else
595+
{
589596
wavetable[i] = iterator.y2;
590597
}
591598
}

0 commit comments

Comments
 (0)