80 lines
3.1 KiB
C++
80 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
|
#include <atomic>
|
|
#include <array>
|
|
#include <signalsmith-stretch.h>
|
|
|
|
class CrilleBassStripAudioProcessor final : public juce::AudioProcessor
|
|
{
|
|
public:
|
|
CrilleBassStripAudioProcessor();
|
|
~CrilleBassStripAudioProcessor() override = default;
|
|
|
|
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
|
|
void releaseResources() override {}
|
|
bool isBusesLayoutSupported(const BusesLayout& layouts) const override;
|
|
void processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
|
|
|
|
juce::AudioProcessorEditor* createEditor() override;
|
|
bool hasEditor() const override { return true; }
|
|
const juce::String getName() const override { return "Crille Bass Strip"; }
|
|
bool acceptsMidi() const override { return false; }
|
|
bool producesMidi() const override { return false; }
|
|
bool isMidiEffect() const override { return false; }
|
|
double getTailLengthSeconds() const override { return 0.0; }
|
|
int getNumPrograms() override { return 1; }
|
|
int getCurrentProgram() override { return 0; }
|
|
void setCurrentProgram(int) override {}
|
|
const juce::String getProgramName(int) override { return {}; }
|
|
void changeProgramName(int, const juce::String&) override {}
|
|
void getStateInformation(juce::MemoryBlock&) override;
|
|
void setStateInformation(const void*, int) override;
|
|
|
|
juce::AudioProcessorValueTreeState apvts;
|
|
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
|
|
|
|
float getGateInputLevelDb() const noexcept { return gateInputLevelDb.load(); }
|
|
float getCompressorInputLevelDb() const noexcept { return compressorInputLevelDb.load(); }
|
|
float getCompressorGainReductionDb() const noexcept { return compressorGainReductionDb.load(); }
|
|
double getDownTuneLatencyMs() const noexcept { return downTuneLatencyMs; }
|
|
float getDetectedFrequencyHz() const noexcept { return detectedFrequencyHz.load(std::memory_order_relaxed);}
|
|
|
|
private:
|
|
using Filter = juce::dsp::IIR::Filter<float>;
|
|
|
|
// DownTune
|
|
signalsmith::stretch::SignalsmithStretch<float> downTune;
|
|
juce::AudioBuffer<float> downTuneBuffer;
|
|
// Pitch detection
|
|
static constexpr int pitchBufferSize = 4096;
|
|
|
|
std::array<float, pitchBufferSize> pitchBuffer {};
|
|
int pitchWritePosition = 0;
|
|
int pitchSamplesCollected = 0;
|
|
int pitchAnalysisCounter = 0;
|
|
|
|
std::atomic<float> detectedFrequencyHz { 0.0f };
|
|
|
|
void updatePitchDetector(
|
|
const float* input,
|
|
int numSamples
|
|
);
|
|
|
|
void analysePitch();
|
|
|
|
juce::dsp::Compressor<float> compressor;
|
|
juce::dsp::ProcessorDuplicator<Filter, juce::dsp::IIR::Coefficients<float>> lowShelf, lowMid, mid, highShelf;
|
|
double currentSampleRate = 44100.0;
|
|
double downTuneLatencyMs = 0.0;
|
|
std::vector<float> gateEnvelope;
|
|
|
|
std::atomic<float> gateInputLevelDb { -80.0f };
|
|
std::atomic<float> compressorInputLevelDb { -80.0f };
|
|
std::atomic<float> compressorGainReductionDb { 0.0f };
|
|
|
|
void updateFilters();
|
|
static float getBufferPeak(const juce::AudioBuffer<float>& buffer) noexcept;
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessor)
|
|
}; |