Skip to content

Commit

Permalink
StereoSpatAlgorithm uses an inner algo to make attenuation possible i…
Browse files Browse the repository at this point in the history
…n Cube mode
  • Loading branch information
OKGougou committed Nov 16, 2022
1 parent fe9524c commit d4054bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Source/sg_StereoSpatAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include "sg_StereoSpatAlgorithm.hpp"
#include "sg_DummySpatAlgorithm.hpp"
#include "sg_VbapSpatAlgorithm.hpp"
#include "sg_MbapSpatAlgorithm.hpp"
#include "sg_HybridSpatAlgorithm.hpp"
#include "sg_StaticMap.hpp"
#include "sg_StrongArray.hpp"
#include "sg_TaggedAudioBuffer.hpp"
Expand All @@ -34,6 +37,8 @@ void StereoSpatAlgorithm::updateSpatData(source_index_t const sourceIndex, Sourc
return;
}

mInnerAlgorithm->updateSpatData(sourceIndex, sourceData);

// using fast = juce::dsp::FastMathApproximations;

auto & queue{ mData[sourceIndex].gainsUpdater };
Expand Down Expand Up @@ -62,7 +67,7 @@ void StereoSpatAlgorithm::updateSpatData(source_index_t const sourceIndex, Sourc
//==============================================================================
void StereoSpatAlgorithm::process(AudioConfig const & config,
SourceAudioBuffer & sourcesBuffer,
SpeakerAudioBuffer & /*speakersBuffer*/,
SpeakerAudioBuffer & speakersBuffer,
juce::AudioBuffer<float> & stereoBuffer,
SourcePeaks const & sourcePeaks,
[[maybe_unused]] SpeakersAudioConfig const * altSpeakerConfig)
Expand All @@ -74,6 +79,9 @@ void StereoSpatAlgorithm::process(AudioConfig const & config,
auto const & gainInterpolation{ config.spatGainsInterpolation };
auto const gainFactor{ std::pow(gainInterpolation, 0.1f) * 0.0099f + 0.99f };

mInnerAlgorithm
->process(config, sourcesBuffer, speakersBuffer, stereoBuffer, sourcePeaks, altSpeakerConfig);

auto const numSamples{ sourcesBuffer.getNumSamples() };
for (auto const & source : config.sourcesAudioConfig) {
if (source.value.isMuted || source.value.directOut || sourcePeaks[source.key] < SMALL_GAIN) {
Expand Down Expand Up @@ -150,6 +158,23 @@ std::unique_ptr<AbstractSpatAlgorithm> StereoSpatAlgorithm::make(SpeakerSetup co
StereoSpatAlgorithm::StereoSpatAlgorithm(SpeakerSetup const & speakerSetup, SourcesData const & sources)
{
JUCE_ASSERT_MESSAGE_THREAD;

switch (speakerSetup.spatMode) {
case SpatMode::vbap:
mInnerAlgorithm = std::make_unique<VbapSpatAlgorithm>(speakerSetup.speakers);
break;
case SpatMode::mbap:
mInnerAlgorithm = std::make_unique<MbapSpatAlgorithm>(speakerSetup);
break;
case SpatMode::hybrid:
mInnerAlgorithm = std::make_unique<HybridSpatAlgorithm>(speakerSetup);
break;
case SpatMode::invalid:
break;
}

jassert(mInnerAlgorithm);

fixDirectOutsIntoPlace(sources, speakerSetup);
}

Expand Down
1 change: 1 addition & 0 deletions Source/sg_StereoSpatAlgorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using StereoSourcesData = StrongArray<source_index_t, StereoSourceData, MAX_NUM_
//==============================================================================
class StereoSpatAlgorithm final : public AbstractSpatAlgorithm
{
std::unique_ptr<AbstractSpatAlgorithm> mInnerAlgorithm{};
StereoSourcesData mData{};

public:
Expand Down

0 comments on commit d4054bb

Please sign in to comment.