After successfully implementing minBLEP on a Sawtooth wave WITHOUT Hard Sync, using the following code, I am trying without luck to implement Hard Sync.
Normal minBLEP - works perfectly:
Code: Select all
mPhase += mPhaseIncrement;
index = (index+1)%cirBuffSize;
//Normal minBLEP:
while(mPhase >= 1.0)
{
mPhase -= 1.0;
double exactCrossTime = 1.0-((mPhaseIncrement-mPhase)/mPhaseIncrement);
populateCircularBufferForSawtoothWave(exactCrossTime, 1.f);
}
circularBuffer[index] += (mPhase-mPhaseIncrement);
double output = 1.7f *(circularBuffer[index] - 0.4f);
circularBuffer[index] = 0.0;Code: Select all
inline void ZeusOsc::populateCircularBufferForSawtoothWave(float offset, float scale)
{
const float *minBlep;
MinBlepData *blepData= new MinBlepData();
minBlep= blepData->getBlep();
for(int i = 0; i < (cirBuffSize-1); i++)
{
double tempIndex = (offset*overS)+(i*overS);
double tempFraction = tempIndex-floor(tempIndex);
circularBuffer[(index+i)%cirBuffSize] += (scale-LERP(tempFraction, minBlep[(int)floor(tempIndex)], minBlep[(int)ceil(tempIndex)]) * scale);
}
delete blepData;
}My Problem
What I need help with guys, if possible, is that my code for the 'Master resets Slave minBLEP' is not right:
Code: Select all
mSyncPhase += mSyncPhaseIncrement;
//Master resets Slave minBLEP:
if(mSyncPhase >= 1.0)
{
mPhase = 0.0;
mSyncPhase -= 1.f;
double masterPeriod = 1.f/mSyncFrequency;
double slavePeriod = 1.f/mFrequency;
double slaveIsThisManySamplesThrough = fmod (masterPeriod,slavePeriod);
double scale = slaveIsThisManySamplesThrough/slavePeriod;
double exactCrossTime = scale-((mPhaseIncrement-mPhase)/mPhaseIncrement);
float slaveWillBeResetTo = safediv((mPhaseIncrement * mSyncPhase), mSyncPhaseIncrement);
populateCircularBufferForSawtoothWave(exactCrossTime, scale);
mPhase = slaveWillBeResetTo;
}
}
mPhase += mPhaseIncrement;
index = (index+1)%cirBuffSize;
//Normal minBLEP:
while(mPhase >= 1.0)
{
mPhase -= 1.0;
double exactCrossTime = 1.0-((mPhaseIncrement-mPhase)/mPhaseIncrement);
populateCircularBufferForSawtoothWave(exactCrossTime, 1.f);
}
circularBuffer[index] += (mPhase-mPhaseIncrement);
double output = 1.7f *(circularBuffer[index] - 0.4f);
circularBuffer[index] = 0.0;1 - I can hear the aliasing on a test note with Master 15 semitones below the Slave.
2 - I can see the aliasing:

3 - The waveform looks about right aside from a 'bump', which looks like a sync function maybe, after the slave has been reset:

Incidentally, I originally had:
Code: Select all
double exactCrossTime = 1.f-((mPhaseIncrement-mPhase)/mPhaseIncrement);
So I suppose that at least one of scale, exactCrossTime or slaveWillBeResetTo are wrong or maybe my entire logic for 'Master resets Slave minBLEP' is wrong
Can anybody spot my mistakes/ correct the code. Thanks in advance
Dave







