Skip to content

Commit

Permalink
Double also (#91)
Browse files Browse the repository at this point in the history
* Support Double Precision in the library; and in consolidated

1. The airwin_consolidated_base gets processDoubleReplacing
2. The AWConsolidatedProcessor gets supportDoublePrecision true
3. processBlock now does the right either-or branch (with templates!)

Closes #46
Closes #90

* Include type traits
  • Loading branch information
baconpaul authored May 8, 2024
1 parent b0f28be commit 736d9fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
51 changes: 25 additions & 26 deletions src-juce/AWConsolidatedProcessor.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
/*
* Surge XT - a free and open source hybrid synthesizer,
* built by Surge Synth Team
*
* Learn more at https://surge-synthesizer.github.io/
*
* Copyright 2018-2024, various authors, as described in the GitHub
* transaction log.
*
* Surge XT is released under the GNU General Public Licence v3
* or later (GPL-3.0-or-later). The license is found in the "LICENSE"
* file in the root of this repository, or at
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* Surge was a commercial product from 2004-2018, copyright and ownership
* held by Claes Johanson at Vember Audio during that period.
* Claes made Surge open source in September 2018.
*
* All source for Surge XT is available at
* https://github.com/surge-synthesizer/surge
*/
#include <type_traits>

#include "AWConsolidatedProcessor.h"
#include "AWConsolidatedEditor.h"
Expand Down Expand Up @@ -145,8 +125,8 @@ bool AWConsolidatedAudioProcessor::isBusesLayoutSupported(const BusesLayout &lay
return inputValid && outputValid;
}

void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer,
juce::MidiBuffer &midiMessages)
template<typename T>
void AWConsolidatedAudioProcessor::processBlockT(juce::AudioBuffer<T> &buffer)
{
juce::ScopedNoDenormals noDenormals;

Expand Down Expand Up @@ -175,8 +155,8 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer
return;
}

const float *inputs[2];
float *outputs[2];
const T *inputs[2];
T *outputs[2];
inputs[0] = buffer.getReadPointer(0);
inputs[1] =
inBus->getNumberOfChannels() == 2 ? buffer.getReadPointer(1) : buffer.getReadPointer(0);
Expand All @@ -196,9 +176,28 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer
awProcessor->setParameter(i, fxParams[i]->get());
}

awProcessor->processReplacing((float **)inputs, (float **)outputs, buffer.getNumSamples());
if constexpr (std::is_same_v<T, float>)
{
awProcessor->processReplacing((float **)inputs, (float **)outputs, buffer.getNumSamples());
}
else
{
awProcessor->processDoubleReplacing((double **)inputs, (double **)outputs, buffer.getNumSamples());
}
}

void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer,
juce::MidiBuffer &midiMessages)
{
processBlockT(buffer);
}

void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<double> &buffer, juce::MidiBuffer &)
{
processBlockT(buffer);
}


//==============================================================================
bool AWConsolidatedAudioProcessor::hasEditor() const
{
Expand Down
3 changes: 3 additions & 0 deletions src-juce/AWConsolidatedProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
bool isBusesLayoutSupported(const BusesLayout &layouts) const override;

void processBlock(juce::AudioBuffer<float> &, juce::MidiBuffer &) override;
void processBlock(juce::AudioBuffer<double> &, juce::MidiBuffer &) override;
bool supportsDoublePrecisionProcessing() const override { return true; }
template<typename T> void processBlockT(juce::AudioBuffer<T> &);

//==============================================================================
juce::AudioProcessorEditor *createEditor() override;
Expand Down
1 change: 1 addition & 0 deletions src/airwin_consolidated_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct AirwinConsolidatedBase
virtual void programsAreChunks(bool) {}

virtual void processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) = 0;
virtual void processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) = 0;

virtual float
getParameter(VstInt32 index) = 0; // get the parameter value at the specified index
Expand Down

0 comments on commit 736d9fa

Please sign in to comment.