Lade till en knapp för att stämma ner från E till Eb (1 semitone)
This commit is contained in:
1 parent
2a06474177
commit
a26de5091c
10 files changed
+1135
-109
No files matched your search
@@ -0,0 +1,6 @@
|
||||
[submodule "External/signalsmith-stretch"]
|
||||
path = External/signalsmith-stretch
|
||||
url = https://github.com/Signalsmith-Audio/signalsmith-stretch.git
|
||||
[submodule "External/signalsmith-linear"]
|
||||
path = External/signalsmith-linear
|
||||
url = https://github.com/Signalsmith-Audio/linear.git
|
||||
@@ -17,6 +17,8 @@ set(VST3_INSTALL_DIR "C:/Program Files/Common Files/VST3")
|
||||
set(RELEASE_DIR "${CMAKE_SOURCE_DIR}/Release")
|
||||
set(ASIO_SDK_DIR "C:/SDK/asio" CACHE PATH "Path to the Steinberg ASIO SDK")
|
||||
|
||||
add_subdirectory(External/signalsmith-stretch)
|
||||
|
||||
juce_add_plugin(CrilleBassStrip
|
||||
COMPANY_NAME "Crille Audio"
|
||||
BUNDLE_ID "org.crilleaudio.crillebassstrip"
|
||||
@@ -48,6 +50,8 @@ target_include_directories(CrilleBassStrip PRIVATE
|
||||
"${ASIO_SDK_DIR}/common"
|
||||
"${ASIO_SDK_DIR}/host"
|
||||
"${ASIO_SDK_DIR}/host/pc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/External/signalsmith-stretch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/External"
|
||||
)
|
||||
|
||||
target_link_libraries(CrilleBassStrip PRIVATE
|
||||
@@ -100,6 +104,12 @@ target_include_directories(CrilleBassStripApp PRIVATE
|
||||
"${ASIO_SDK_DIR}/common"
|
||||
"${ASIO_SDK_DIR}/host"
|
||||
"${ASIO_SDK_DIR}/host/pc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/External/signalsmith-stretch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/External"
|
||||
)
|
||||
|
||||
target_include_directories(CrilleBassStrip PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/External/signalsmith-stretch"
|
||||
)
|
||||
|
||||
target_link_libraries(CrilleBassStripApp PRIVATE
|
||||
|
||||
+1
Submodule External/signalsmith-linear added at 7bb1c8f367.
+1
Submodule External/signalsmith-stretch added at 88061fd4ed.
Binary file not shown.
+809
-103
File diff suppressed because it is too large.
Load diff
@@ -38,6 +38,11 @@ private:
|
||||
CrilleBassStripAudioProcessor& processor;
|
||||
std::vector<std::unique_ptr<Knob>> knobs;
|
||||
std::vector<std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment>> attachments;
|
||||
juce::ToggleButton downTuneButton;
|
||||
|
||||
std::unique_ptr<
|
||||
juce::AudioProcessorValueTreeState::ButtonAttachment
|
||||
> downTuneAttachment;
|
||||
|
||||
LevelMeter gateInputMeter { LevelMeter::Mode::inputLevel };
|
||||
LevelMeter compressorInputMeter { LevelMeter::Mode::inputLevel };
|
||||
|
||||
+276
-5
@@ -21,6 +21,10 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso
|
||||
{
|
||||
using P = juce::AudioParameterFloat;
|
||||
juce::AudioProcessorValueTreeState::ParameterLayout p;
|
||||
p.add(std::make_unique<juce::AudioParameterBool>(
|
||||
pid("downTuneOn"),
|
||||
"DownTune",
|
||||
false));
|
||||
p.add(std::make_unique<P>(pid("gateThreshold"), "Gate Threshold", juce::NormalisableRange<float>(-80.f, -10.f, 0.1f), -45.f, "dB"));
|
||||
p.add(std::make_unique<P>(pid("gateRelease"), "Gate Release", juce::NormalisableRange<float>(20.f, 500.f, 1.f, 0.5f), 150.f, "ms"));
|
||||
p.add(std::make_unique<P>(pid("gateGain"), "Gate Gain", juce::NormalisableRange<float>(-24.f, 12.f, 0.1f), 0.f, "dB"));
|
||||
@@ -41,6 +45,41 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso
|
||||
void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block)
|
||||
{
|
||||
currentSampleRate = sr;
|
||||
pitchBuffer.fill(0.0f);
|
||||
pitchWritePosition = 0;
|
||||
pitchSamplesCollected = 0;
|
||||
pitchAnalysisCounter = 0;
|
||||
detectedFrequencyHz.store(0.0f, std::memory_order_relaxed);
|
||||
|
||||
downTune.configure(1, 576, 144);
|
||||
downTune.setTransposeSemitones(-1.0);
|
||||
|
||||
downTuneBuffer.setSize(1, block, false, false, true);
|
||||
downTuneBuffer.clear();
|
||||
|
||||
setLatencySamples(
|
||||
downTune.inputLatency() +
|
||||
downTune.outputLatency());
|
||||
downTuneLatencyMs =
|
||||
1000.0 *
|
||||
(downTune.inputLatency() + downTune.outputLatency()) /
|
||||
sr;
|
||||
//debug börjar
|
||||
DBG("DownTune input latency: "
|
||||
<< downTune.inputLatency()
|
||||
<< " samples");
|
||||
|
||||
DBG("DownTune output latency: "
|
||||
<< downTune.outputLatency()
|
||||
<< " samples");
|
||||
|
||||
DBG("DownTune total latency: "
|
||||
<< downTune.inputLatency() + downTune.outputLatency()
|
||||
<< " samples");
|
||||
|
||||
DBG("DownTune latency ms: "
|
||||
<< 1000.0 * (downTune.inputLatency() + downTune.outputLatency()) / sr);
|
||||
// debug slutar
|
||||
juce::dsp::ProcessSpec spec { sr, static_cast<juce::uint32>(block), static_cast<juce::uint32>(getTotalNumOutputChannels()) };
|
||||
compressor.prepare(spec);
|
||||
lowShelf.prepare(spec);
|
||||
@@ -75,6 +114,191 @@ float CrilleBassStripAudioProcessor::getBufferPeak(const juce::AudioBuffer<float
|
||||
peak = juce::jmax(peak, buffer.getMagnitude(channel, 0, buffer.getNumSamples()));
|
||||
return peak;
|
||||
}
|
||||
void CrilleBassStripAudioProcessor::updatePitchDetector(
|
||||
const float* input,
|
||||
int numSamples)
|
||||
{
|
||||
for (int i = 0; i < numSamples; ++i)
|
||||
{
|
||||
pitchBuffer[
|
||||
static_cast<std::size_t>(pitchWritePosition)
|
||||
] = input[i];
|
||||
|
||||
pitchWritePosition =
|
||||
(pitchWritePosition + 1) % pitchBufferSize;
|
||||
|
||||
pitchSamplesCollected =
|
||||
juce::jmin(
|
||||
pitchSamplesCollected + 1,
|
||||
pitchBufferSize
|
||||
);
|
||||
}
|
||||
|
||||
pitchAnalysisCounter += numSamples;
|
||||
|
||||
const int analysisInterval =
|
||||
static_cast<int>(currentSampleRate * 0.1);
|
||||
|
||||
if (pitchSamplesCollected == pitchBufferSize
|
||||
&& pitchAnalysisCounter >= analysisInterval)
|
||||
{
|
||||
pitchAnalysisCounter = 0;
|
||||
analysePitch();
|
||||
}
|
||||
}
|
||||
|
||||
void CrilleBassStripAudioProcessor::analysePitch()
|
||||
{
|
||||
constexpr int downsampleFactor = 4;
|
||||
constexpr int analysisSize =
|
||||
pitchBufferSize / downsampleFactor;
|
||||
|
||||
std::array<float, analysisSize> samples {};
|
||||
|
||||
// pitchWritePosition points to the oldest sample.
|
||||
float mean = 0.0f;
|
||||
|
||||
for (int i = 0; i < analysisSize; ++i)
|
||||
{
|
||||
const int sourcePosition =
|
||||
(pitchWritePosition
|
||||
+ i * downsampleFactor)
|
||||
% pitchBufferSize;
|
||||
|
||||
samples[static_cast<std::size_t>(i)] =
|
||||
pitchBuffer[
|
||||
static_cast<std::size_t>(sourcePosition)
|
||||
];
|
||||
|
||||
mean += samples[static_cast<std::size_t>(i)];
|
||||
}
|
||||
|
||||
mean /= static_cast<float>(analysisSize);
|
||||
|
||||
float energy = 0.0f;
|
||||
|
||||
for (int i = 0; i < analysisSize; ++i)
|
||||
{
|
||||
auto& sample =
|
||||
samples[static_cast<std::size_t>(i)];
|
||||
|
||||
sample -= mean;
|
||||
energy += sample * sample;
|
||||
}
|
||||
|
||||
const float rms =
|
||||
std::sqrt(
|
||||
energy / static_cast<float>(analysisSize)
|
||||
);
|
||||
|
||||
// Ignore silence and very weak signals.
|
||||
if (rms < 0.0005f)
|
||||
{
|
||||
detectedFrequencyHz.store(
|
||||
0.0f,
|
||||
std::memory_order_relaxed
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const float analysisSampleRate =
|
||||
static_cast<float>(currentSampleRate)
|
||||
/ static_cast<float>(downsampleFactor);
|
||||
|
||||
constexpr float minimumFrequencyHz = 30.0f;
|
||||
constexpr float maximumFrequencyHz = 200.0f;
|
||||
|
||||
const int minimumLag =
|
||||
static_cast<int>(
|
||||
analysisSampleRate / maximumFrequencyHz
|
||||
);
|
||||
|
||||
const int maximumLag =
|
||||
juce::jmin(
|
||||
analysisSize - 2,
|
||||
static_cast<int>(
|
||||
analysisSampleRate / minimumFrequencyHz
|
||||
)
|
||||
);
|
||||
|
||||
float bestCorrelation = 0.0f;
|
||||
int bestLag = 0;
|
||||
|
||||
for (int lag = minimumLag;
|
||||
lag <= maximumLag;
|
||||
++lag)
|
||||
{
|
||||
float correlation = 0.0f;
|
||||
float firstEnergy = 0.0f;
|
||||
float secondEnergy = 0.0f;
|
||||
|
||||
const int comparedSamples =
|
||||
analysisSize - lag;
|
||||
|
||||
for (int i = 0;
|
||||
i < comparedSamples;
|
||||
++i)
|
||||
{
|
||||
const float first =
|
||||
samples[static_cast<std::size_t>(i)];
|
||||
|
||||
const float second =
|
||||
samples[
|
||||
static_cast<std::size_t>(i + lag)
|
||||
];
|
||||
|
||||
correlation += first * second;
|
||||
firstEnergy += first * first;
|
||||
secondEnergy += second * second;
|
||||
}
|
||||
|
||||
const float denominator =
|
||||
std::sqrt(firstEnergy * secondEnergy);
|
||||
|
||||
if (denominator > 1.0e-9f)
|
||||
correlation /= denominator;
|
||||
else
|
||||
correlation = 0.0f;
|
||||
|
||||
if (correlation > bestCorrelation)
|
||||
{
|
||||
bestCorrelation = correlation;
|
||||
bestLag = lag;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent unstable note readings.
|
||||
if (bestLag <= 0 || bestCorrelation < 0.25f)
|
||||
{
|
||||
detectedFrequencyHz.store(
|
||||
0.0f,
|
||||
std::memory_order_relaxed
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const float frequency =
|
||||
analysisSampleRate
|
||||
/ static_cast<float>(bestLag);
|
||||
|
||||
const float previousFrequency =
|
||||
detectedFrequencyHz.load(
|
||||
std::memory_order_relaxed
|
||||
);
|
||||
|
||||
const float smoothedFrequency =
|
||||
previousFrequency > 0.0f
|
||||
? previousFrequency * 0.7f
|
||||
+ frequency * 0.3f
|
||||
: frequency;
|
||||
|
||||
detectedFrequencyHz.store(
|
||||
smoothedFrequency,
|
||||
std::memory_order_relaxed
|
||||
);
|
||||
}
|
||||
|
||||
void CrilleBassStripAudioProcessor::updateFilters()
|
||||
{
|
||||
@@ -92,13 +316,60 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer<float>& buffe
|
||||
{
|
||||
juce::ScopedNoDenormals noDenormals;
|
||||
|
||||
// Clear output channels that do not contain input data.
|
||||
for (int c = getTotalNumInputChannels(); c < getTotalNumOutputChannels(); ++c)
|
||||
buffer.clear(c, 0, buffer.getNumSamples());
|
||||
const int numSamples = buffer.getNumSamples();
|
||||
if (buffer.getNumChannels() > 0)
|
||||
{
|
||||
updatePitchDetector(
|
||||
buffer.getReadPointer(0),
|
||||
numSamples
|
||||
);
|
||||
}
|
||||
|
||||
// Copy mono bass input to both stereo output channels.
|
||||
// Clear output channels that do not contain input data.
|
||||
for (int c = getTotalNumInputChannels();
|
||||
c < getTotalNumOutputChannels();
|
||||
++c)
|
||||
{
|
||||
buffer.clear(c, 0, numSamples);
|
||||
}
|
||||
|
||||
// Process the mono bass signal through DownTune.
|
||||
if (numSamples <= downTuneBuffer.getNumSamples())
|
||||
{
|
||||
const float* inputChannels[] =
|
||||
{
|
||||
buffer.getReadPointer(0)
|
||||
};
|
||||
|
||||
float* outputChannels[] =
|
||||
{
|
||||
downTuneBuffer.getWritePointer(0)
|
||||
};
|
||||
|
||||
downTune.process(
|
||||
inputChannels,
|
||||
numSamples,
|
||||
outputChannels,
|
||||
numSamples);
|
||||
|
||||
const bool downTuneEnabled =
|
||||
apvts.getRawParameterValue("downTuneOn")->load() > 0.5f;
|
||||
|
||||
if (downTuneEnabled)
|
||||
{
|
||||
buffer.copyFrom(
|
||||
0,
|
||||
0,
|
||||
downTuneBuffer,
|
||||
0,
|
||||
0,
|
||||
numSamples);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the processed mono bass signal to both stereo output channels.
|
||||
if (buffer.getNumChannels() >= 2)
|
||||
buffer.copyFrom(1, 0, buffer, 0, 0, buffer.getNumSamples());
|
||||
buffer.copyFrom(1, 0, buffer, 0, 0, numSamples);
|
||||
|
||||
// Measure input level before the noise gate.
|
||||
const float gateInputPeak = getBufferPeak(buffer);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuceHeader.h>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
#include <signalsmith-stretch.h>
|
||||
|
||||
class CrilleBassStripAudioProcessor final : public juce::AudioProcessor
|
||||
{
|
||||
@@ -34,13 +37,36 @@ public:
|
||||
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 };
|
||||
|
||||
@@ -129,7 +129,7 @@ StandaloneMainComponent::StandaloneMainComponent()
|
||||
editor = std::make_unique<CrilleBassStripAudioProcessorEditor>(audioEngine.getProcessor());
|
||||
addAndMakeVisible(*editor);
|
||||
|
||||
setSize(1080, 480);
|
||||
setSize(760, 790);
|
||||
}
|
||||
|
||||
StandaloneMainComponent::~StandaloneMainComponent()
|
||||
|
||||
Reference in new issue
Block a user