From 90e3b29502bba481ca1720aefdc8d98817454a4d Mon Sep 17 00:00:00 2001 From: Michael Witte Date: Tue, 18 Jun 2024 22:18:25 +0200 Subject: [PATCH] adjusted room dimensions to 10x10x10 meters and updated constants usage across the codebase --- source/Constants.h | 4 ++++ source/PluginParameters.cpp | 13 +++++++------ source/PluginParameters.h | 15 ++++++++------- source/PluginProcessor.cpp | 31 ++++++++++++++++--------------- source/ui/PannerVisualisation.cpp | 11 ++++++----- 5 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 source/Constants.h diff --git a/source/Constants.h b/source/Constants.h new file mode 100644 index 0000000..74185b1 --- /dev/null +++ b/source/Constants.h @@ -0,0 +1,4 @@ +#pragma once + +constexpr float CUBE_EDGE_LENGTH = 10.0f; +constexpr float HALF_CUBE_EDGE_LENGTH = CUBE_EDGE_LENGTH / 2.0f; \ No newline at end of file diff --git a/source/PluginParameters.cpp b/source/PluginParameters.cpp index a3e4b21..2c1c991 100644 --- a/source/PluginParameters.cpp +++ b/source/PluginParameters.cpp @@ -1,4 +1,5 @@ #include "PluginParameters.h" +#include "Constants.h" juce::AudioProcessorValueTreeState::ParameterLayout PluginParameters::createParameterLayout() { std::vector> params; @@ -188,9 +189,9 @@ void ParameterListener::boundRadius(float radius) { float dz = cos(colatitudeRad); // intersection of the line with the cube boundaries - float tX = (!juce::approximatelyEqual(dx,0.0f)) ? (10.0f / dx) : std::numeric_limits::infinity(); - float tY = (!juce::approximatelyEqual(dy,0.0f)) ? (10.0f / dy) : std::numeric_limits::infinity(); - float tZ = (!juce::approximatelyEqual(dz,0.0f)) ? (10.0f / dz) : std::numeric_limits::infinity(); + float tX = (!juce::approximatelyEqual(dx,0.0f)) ? (HALF_CUBE_EDGE_LENGTH / dx) : std::numeric_limits::infinity(); + float tY = (!juce::approximatelyEqual(dy,0.0f)) ? (HALF_CUBE_EDGE_LENGTH / dy) : std::numeric_limits::infinity(); + float tZ = (!juce::approximatelyEqual(dz,0.0f)) ? (HALF_CUBE_EDGE_LENGTH / dz) : std::numeric_limits::infinity(); // the intersection point is the closest one to the origin float tMin = std::min({std::abs(tX), std::abs(tY), std::abs(tZ)}); @@ -272,9 +273,9 @@ void ParameterListener::updateCartesianCoordinates() float z = radius * cos(colatitudeRad); // always limit the values to the room boundaries - x = jlimit(-10.0f, 10.0f, x); - y = jlimit(-10.0f, 10.0f, y); - z = jlimit(-10.0f, 10.0f, z); + x = jlimit(-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, x); + y = jlimit(-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, y); + z = jlimit(-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, z); float normalizedX = PluginParameters::xRange.convertTo0to1(x); float normalizedY = PluginParameters::yRange.convertTo0to1(y); diff --git a/source/PluginParameters.h b/source/PluginParameters.h index 180bd9f..fe98387 100644 --- a/source/PluginParameters.h +++ b/source/PluginParameters.h @@ -2,6 +2,7 @@ #define BINAURALPANNER_PLUGINPARAMETERS_H #include +#include "Constants.h" class PluginParameters { public: @@ -82,22 +83,22 @@ class PluginParameters { inline static juce::NormalisableRange azimRange {-180.0f, 180.0f, 0.01f}, elevRange {-90.0f, 90.0f, 0.01f}, - distRange {0.0f, 17.4f, 0.1f}, - xRange {-10.f, 10.f, 0.1f}, - yRange {-10.f, 10.f, 0.1f}, - zRange {-10.f, 10.f, 0.1f}, + distRange {0.0f, static_cast(sqrt(pow(HALF_CUBE_EDGE_LENGTH, 2) * 3)), 0.01f}, + xRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}, + yRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}, + zRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}, xLFORateRange {0.0f, 1.5f, 0.1f}, xLFODepthRange {0.0f, 100.f, 0.1f}, xLFOPhaseRange {-180.f, 180.f, 1.f}, - xLFOOffsetRange {-10.f, 10.f, 0.1f}, + xLFOOffsetRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}, yLFORateRange {0.0f, 1.5f, 0.1f}, yLFODepthRange {0.0f, 100.f, 0.1f}, yLFOPhaseRange {-180.f, 180.f, 1.f}, - yLFOOffsetRange {-10.f, 10.f, 0.1f}, + yLFOOffsetRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}, zLFORateRange {0.0f, 1.5f, 0.1f}, zLFODepthRange {0.0f, 100.f, 0.1f}, zLFOPhaseRange {-180.f, 180.f, 1.f}, - zLFOOffsetRange {-10.f, 10.f, 0.1f}; + zLFOOffsetRange {-HALF_CUBE_EDGE_LENGTH, HALF_CUBE_EDGE_LENGTH, 0.01f}; private: diff --git a/source/PluginProcessor.cpp b/source/PluginProcessor.cpp index 3d37d26..5f04e47 100644 --- a/source/PluginProcessor.cpp +++ b/source/PluginProcessor.cpp @@ -1,5 +1,6 @@ #include "PluginProcessor.h" #include "PluginEditor.h" +#include "Constants.h" //============================================================================== AudioPluginAudioProcessor::AudioPluginAudioProcessor() @@ -374,13 +375,13 @@ void AudioPluginAudioProcessor::processLFOs() { float frequency = *parameters.getRawParameterValue("param_xlfo_rate"); float phase = *parameters.getRawParameterValue("param_xlfo_phase"); - float amplitude = *parameters.getRawParameterValue("param_xlfo_depth") / 10.0f; + float amplitude = (*parameters.getRawParameterValue("param_xlfo_depth") / 100) * HALF_CUBE_EDGE_LENGTH; float offset = *parameters.getRawParameterValue("param_xlfo_offset"); xLFO->setFrequency(frequency); float xlfoSample = amplitude * std::sin(xLFO->processSample(degreesToRadians(phase))) + offset; - xlfoSample = juce::jlimit(-10.0f, 10.0f, xlfoSample); + xlfoSample = juce::jlimit(PluginParameters::xRange.start, PluginParameters::xRange.end, xlfoSample); float normalizedX = PluginParameters::xRange.convertTo0to1(xlfoSample); parameters.getParameter("param_x")->setValueNotifyingHost(normalizedX); } @@ -389,13 +390,13 @@ void AudioPluginAudioProcessor::processLFOs() { float frequency = *parameters.getRawParameterValue("param_ylfo_rate"); float phase = *parameters.getRawParameterValue("param_ylfo_phase"); - float amplitude = *parameters.getRawParameterValue("param_ylfo_depth") / 10.0f; + float amplitude = (*parameters.getRawParameterValue("param_ylfo_depth") / 100) * HALF_CUBE_EDGE_LENGTH; float offset = *parameters.getRawParameterValue("param_ylfo_offset"); yLFO->setFrequency(frequency); float ylfoSample = amplitude * std::sin(yLFO->processSample(degreesToRadians(phase))) + offset; - ylfoSample = juce::jlimit(-10.0f, 10.0f, ylfoSample); + ylfoSample = juce::jlimit(PluginParameters::yRange.start, PluginParameters::yRange.end, ylfoSample); float normalizedY = PluginParameters::yRange.convertTo0to1(ylfoSample); parameters.getParameter("param_y")->setValueNotifyingHost(normalizedY); } @@ -404,13 +405,13 @@ void AudioPluginAudioProcessor::processLFOs() { float frequency = *parameters.getRawParameterValue("param_zlfo_rate"); float phase = *parameters.getRawParameterValue("param_zlfo_phase"); - float amplitude = *parameters.getRawParameterValue("param_zlfo_depth") / 10.0f; + float amplitude = (*parameters.getRawParameterValue("param_zlfo_depth") / 100) * HALF_CUBE_EDGE_LENGTH; float offset = *parameters.getRawParameterValue("param_zlfo_offset"); zLFO->setFrequency(frequency); float zlfoSample = amplitude * std::sin(zLFO->processSample(degreesToRadians(phase))) + offset; - zlfoSample = juce::jlimit(-10.0f, 10.0f, zlfoSample); + zlfoSample = juce::jlimit(PluginParameters::zRange.start, PluginParameters::zRange.end, zlfoSample); float normalizedZ = PluginParameters::zRange.convertTo0to1(zlfoSample); parameters.getParameter("param_z")->setValueNotifyingHost(normalizedZ); } @@ -559,7 +560,7 @@ void AudioPluginAudioProcessor::applyPreset(int presetOption) parameters.getParameterAsValue(PluginParameters::XLFO_RATE_ID.getParamID()) = 0.1f; parameters.getParameterAsValue(PluginParameters::XLFO_DEPTH_ID.getParamID()) = 27.3f; parameters.getParameterAsValue(PluginParameters::XLFO_PHASE_ID.getParamID()) = 0.0f; - parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 6.5f; + parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 6.5f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::YLFO_RATE_ID.getParamID()) = 0.9f; parameters.getParameterAsValue(PluginParameters::YLFO_DEPTH_ID.getParamID()) = 44.2f; parameters.getParameterAsValue(PluginParameters::YLFO_PHASE_ID.getParamID()) = 0.0f; @@ -574,11 +575,11 @@ void AudioPluginAudioProcessor::applyPreset(int presetOption) parameters.getParameterAsValue(PluginParameters::XLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::XLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::XLFO_PHASE_ID.getParamID()) = 0.0f; - parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 5.0f; + parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::YLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::YLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::YLFO_PHASE_ID.getParamID()) = 90.0f; - parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = 5.0f; + parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = 5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::ZLFO_RATE_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_DEPTH_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_PHASE_ID.getParamID()) = 0.0f; @@ -589,11 +590,11 @@ void AudioPluginAudioProcessor::applyPreset(int presetOption) parameters.getParameterAsValue(PluginParameters::XLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::XLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::XLFO_PHASE_ID.getParamID()) = 0.0f; - parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 5.0f; + parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = 5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::YLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::YLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::YLFO_PHASE_ID.getParamID()) = 90.0f; - parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = -5.0f; + parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = -5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::ZLFO_RATE_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_DEPTH_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_PHASE_ID.getParamID()) = 0.0f; @@ -604,11 +605,11 @@ void AudioPluginAudioProcessor::applyPreset(int presetOption) parameters.getParameterAsValue(PluginParameters::XLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::XLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::XLFO_PHASE_ID.getParamID()) = 0.0f; - parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = -5.0f; + parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = -5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::YLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::YLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::YLFO_PHASE_ID.getParamID()) = 90.0f; - parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = 5.0f; + parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = 5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::ZLFO_RATE_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_DEPTH_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_PHASE_ID.getParamID()) = 0.0f; @@ -619,11 +620,11 @@ void AudioPluginAudioProcessor::applyPreset(int presetOption) parameters.getParameterAsValue(PluginParameters::XLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::XLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::XLFO_PHASE_ID.getParamID()) = 0.0f; - parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = -5.0f; + parameters.getParameterAsValue(PluginParameters::XLFO_OFFSET_ID.getParamID()) = -5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::YLFO_RATE_ID.getParamID()) = 0.5f; parameters.getParameterAsValue(PluginParameters::YLFO_DEPTH_ID.getParamID()) = 35.0f; parameters.getParameterAsValue(PluginParameters::YLFO_PHASE_ID.getParamID()) = 90.0f; - parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = -5.0f; + parameters.getParameterAsValue(PluginParameters::YLFO_OFFSET_ID.getParamID()) = -5.0f * (HALF_CUBE_EDGE_LENGTH / 10.0f); parameters.getParameterAsValue(PluginParameters::ZLFO_RATE_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_DEPTH_ID.getParamID()) = 0.0f; parameters.getParameterAsValue(PluginParameters::ZLFO_PHASE_ID.getParamID()) = 0.0f; diff --git a/source/ui/PannerVisualisation.cpp b/source/ui/PannerVisualisation.cpp index 0548be2..3aa29d2 100644 --- a/source/ui/PannerVisualisation.cpp +++ b/source/ui/PannerVisualisation.cpp @@ -1,4 +1,5 @@ #include "PannerVisualisation.h" +#include "../Constants.h" PannerVisualisation::PannerVisualisation() : isInitialized(false) { smallCircleRadius = 10.0f; @@ -86,8 +87,8 @@ void PannerVisualisation::mouseDrag(const juce::MouseEvent &event) { } smallCirclePosition = newPos; - float newX = - (newPos.y - center.y) / radius * 10.0f; - float newY = - (newPos.x - center.x) / radius * 10.0f; + float newX = - (newPos.y - center.y) / radius * HALF_CUBE_EDGE_LENGTH; + float newY = - (newPos.x - center.x) / radius * HALF_CUBE_EDGE_LENGTH; listeners.call([newX, newY](Listener& l) { l.pannerChanged(newX, newY); }); @@ -116,11 +117,11 @@ void PannerVisualisation::setVisualPosition(float x, float y, float z) { auto center = bounds.getCentre().toFloat(); float outerRadius = static_cast(bounds.getWidth() / 2.0); - float zScale = ((z + 10) / 20.0f) * 1.5f + 0.5f; + float zScale = ((z + HALF_CUBE_EDGE_LENGTH) / CUBE_EDGE_LENGTH) * 1.5f + 0.5f; smallCircleRadius = 10.0f * zScale; - float newX = center.x - (y / 10.0f) * outerRadius; - float newY = center.y - (x / 10.0f) * outerRadius; + float newX = center.x - (y / HALF_CUBE_EDGE_LENGTH) * outerRadius; + float newY = center.y - (x / HALF_CUBE_EDGE_LENGTH) * outerRadius; smallCirclePosition.setXY(newX, newY);