Skip to content

Commit

Permalink
Merge branch 'hotfix/polyshaper_fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed May 30, 2018
2 parents e0439b3 + 868b874 commit d24e8dd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 15 deletions.
54 changes: 39 additions & 15 deletions hi_modules/effects/fx/ShapeFX.cpp
Expand Up @@ -294,6 +294,8 @@ void ShapeFX::prepareToPlay(double sampleRate, int samplesPerBlock)
lDcRemover.setCoefficients(dcCoeffs);
rDcRemover.setCoefficients(dcCoeffs);



limiter.setSampleRate(sampleRate);
limiter.setAttack(0.03);
limiter.setRelease(100.0);
Expand Down Expand Up @@ -591,12 +593,16 @@ void ShapeFX::updateMix()
PolyshapeFX::PolyshapeFX(MainController *mc, const String &uid, int numVoices):
VoiceEffectProcessor(mc, uid, numVoices),
driveChain(new ModulatorChain(mc, "Drive Modulation", numVoices, Modulation::Mode::GainMode, this)),
driveBuffer(1, 0)
driveBuffer(1, 0),
polyUpdater(*this)
{


for (int i = 0; i < numVoices; i++)
{
oversamplers.add(new ShapeFX::Oversampler(2, 2, ShapeFX::Oversampler::FilterType::filterHalfBandPolyphaseIIR, false));
dcRemovers.add(new SimpleOnePole());
driveSmoothers[i] = LinearSmoothedValue<float>(1.0f);
}

initShapers();
Expand Down Expand Up @@ -722,6 +728,11 @@ void PolyshapeFX::prepareToPlay(double sampleRate, int samplesPerBlock)
{
VoiceEffectProcessor::prepareToPlay(sampleRate, samplesPerBlock);

for (int i = 0; i < NUM_POLYPHONIC_VOICES; i++)
{
driveSmoothers[i].reset(sampleRate, 0.05);
}

for (auto os : oversamplers)
{
os->initProcessing(samplesPerBlock);
Expand All @@ -740,36 +751,42 @@ void PolyshapeFX::prepareToPlay(double sampleRate, int samplesPerBlock)

void PolyshapeFX::applyEffect(int voiceIndex, AudioSampleBuffer &b, int startSample, int numSamples)
{


float* driveValues = getCurrentModulationValues(DriveModulation, voiceIndex, startSample);

if (voiceIndex >= NUM_POLYPHONIC_VOICES)
return;

auto& smoother = driveSmoothers[voiceIndex];

smoother.setValue(drive - 1.0f);


float* l = b.getWritePointer(0, startSample);
float* r = b.getWritePointer(1, startSample);

if (mode == ShapeFX::ShapeMode::Sin || mode == ShapeFX::ShapeMode::TanCos)
{
for (int i = 0; i < numSamples; i++)
{
l[i] = (l[i]) * (1.0f + driveValues[i] * (drive-1.0f)) + bias;
r[i] = (r[i]) * (1.0f + driveValues[i] * (drive-1.0f)) + bias;

const float driveValue = smoother.getNextValue();

l[i] = (l[i]) * (1.0f + driveValues[i] * (driveValue)) + bias;
r[i] = (r[i]) * (1.0f + driveValues[i] * (driveValue)) + bias;
}
}
else
{
for (int i = 0; i < numSamples; i++)
{
l[i] = (l[i] + bias) * (1.0f + driveValues[i] * (drive - 1.0f));
r[i] = (r[i] + bias) * (1.0f + driveValues[i] * (drive - 1.0f));

const float driveValue = smoother.getNextValue();

l[i] = (l[i] + bias) * (1.0f + driveValues[i] * (driveValue));
r[i] = (r[i] + bias) * (1.0f + driveValues[i] * (driveValue));
}
}





if (oversampling)
{
dsp::AudioBlock<float> block(b.getArrayOfWritePointers(), 2, startSample, numSamples);
Expand All @@ -793,21 +810,28 @@ void PolyshapeFX::applyEffect(int voiceIndex, AudioSampleBuffer &b, int startSam

if (bias != 0.0f)
dcRemovers[voiceIndex]->processSamples(b, startSample, numSamples);

}

void PolyshapeFX::getWaveformTableValues(int /*displayIndex*/, float const** tableValues, int& numValues, float& normalizeValue)
{
const float driveValue = driveChain->getOutputValue() * drive;

displayPeak = driveValue;

ShapeFX::generateRampForDisplayValue(displayTable, 1.0f + displayPeak);
shapers[mode]->processBlock(displayTable, unusedTable, SAMPLE_LOOKUP_TABLE_SIZE);

*tableValues = displayTable;
numValues = SAMPLE_LOOKUP_TABLE_SIZE;
normalizeValue = 1.0f;
}

void PolyshapeFX::recalculateDisplayTable()
{
ShapeFX::generateRampForDisplayValue(displayTable, drive);

shapers[mode]->processBlock(displayTable, unusedTable, SAMPLE_LOOKUP_TABLE_SIZE);
triggerWaveformUpdate();

}



}
27 changes: 27 additions & 0 deletions hi_modules/effects/fx/ShapeFX.h
Expand Up @@ -244,6 +244,7 @@ class ShapeFX : public MasterEffectProcessor,

private:



TableShaper * getTableShaper();
const TableShaper * getTableShaper() const;
Expand Down Expand Up @@ -289,6 +290,7 @@ class ShapeFX : public MasterEffectProcessor,

SpinLock scriptLock;


Result shapeResult;

ScopedPointer<Oversampler> oversampler;
Expand Down Expand Up @@ -437,6 +439,24 @@ class PolyshapeFX : public VoiceEffectProcessor,

private:

struct PolyUpdater : public Timer
{
PolyUpdater(PolyshapeFX& parent_) :
parent(parent_)
{
startTimer(50);
};

void timerCallback() override
{
parent.triggerWaveformUpdate();
}

PolyshapeFX& parent;
};

void updateSmoothedGainers();

class TableUpdater : public SafeChangeListener
{
public:
Expand Down Expand Up @@ -468,6 +488,9 @@ class PolyshapeFX : public VoiceEffectProcessor,
OwnedArray<ShapeFX::ShaperBase> shapers;
OwnedArray<ShapeFX::Oversampler> oversamplers;
float drive = 1.0f;

Array<LinearSmoothedValue<float>> driveSmoothers;

int mode = ShapeFX::ShapeMode::Linear;
bool oversampling = false;
ScopedPointer<ModulatorChain> driveChain;
Expand All @@ -477,6 +500,10 @@ class PolyshapeFX : public VoiceEffectProcessor,

ScopedPointer<TableUpdater> tableUpdater;

float displayPeak = 0.0f;

PolyUpdater polyUpdater;

float bias = 0.0f;

float displayTable[SAMPLE_LOOKUP_TABLE_SIZE];
Expand Down

0 comments on commit d24e8dd

Please sign in to comment.