Skip to content

Commit

Permalink
Fixed bug where Object gain vector did not account for LFE in the out…
Browse files Browse the repository at this point in the history
…put array
  • Loading branch information
peterStitt authored and tguillem committed Feb 16, 2021
1 parent 79bfd48 commit 6e15883
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/AdmRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ namespace admrender {
StreamInformation m_channelInformation;

Layout m_outputLayout;
// Index map to go from the output array excluding LFE to the full array with LFE
std::vector<unsigned int> m_mapNoLfeToLfe;

// Vector holding the last unique set metadata for each object in the stream
std::vector<ObjectMetadata> m_objectMetadata;
Expand Down
2 changes: 1 addition & 1 deletion include/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static inline bool testPointSourcePanner()
velVec.x = 0.;
velVec.y = 0.;
velVec.z = 0.;
for (int i = 0; i < numCh; ++i)
for (unsigned int i = 0; i < numCh; ++i)
{
CartesianPosition speakerDirections = PolarToCartesian(layoutNoLFE.channels[i].polarPosition);
velVec = velVec + CartesianPosition{ gains[i] * speakerDirections.x, gains[i] * speakerDirections.y,gains[i] * speakerDirections.z, };
Expand Down
33 changes: 29 additions & 4 deletions source/AdmRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ namespace admrender {
if (!bBinConf)
return false;

// If the output layout has an LFE then get its index

for (int iSpk = 0; iSpk < m_outputLayout.channels.size(); ++iSpk)
if (!m_outputLayout.channels[iSpk].isLFE)
m_mapNoLfeToLfe.push_back(iSpk);

// Set up the buffers holding the direct and diffuse speaker signals
size_t nAmbiCh = m_outputLayout.channels.size();
m_speakerOut.resize(m_nOutputChannels);
Expand Down Expand Up @@ -235,13 +241,32 @@ namespace admrender {
// Store the metadata
m_objectMetadata[iObj] = metadata;
// Calculate a new gain vector with this metadata
std::vector<double> directGains;
std::vector<double> diffuseGains;
m_objectGainCalc->CalculateGains(metadata, directGains, diffuseGains);
std::vector<double> directGainsNoLFE;
std::vector<double> diffuseGainsNoLFE;
m_objectGainCalc->CalculateGains(metadata, directGainsNoLFE, diffuseGainsNoLFE);

// Apply scattering to the diffuse gains when output is binaural
if (m_RenderLayout == OutputLayout::Binaural)
diffuseGains = multiplyMatVec(m_scatteringMatrix, diffuseGains);
diffuseGainsNoLFE = multiplyMatVec(m_scatteringMatrix, diffuseGainsNoLFE);

std::vector<double> directGains;
std::vector<double> diffuseGains;
// Advance the index of any speakers after the LFE to leave a gap for the LFE
if (m_outputLayout.hasLFE)
{
directGains.resize(m_nOutputChannels, 0.);
diffuseGains.resize(m_nOutputChannels, 0.);
for (unsigned int i = 0; i < m_nOutputChannels - 1; ++i)
{
directGains[m_mapNoLfeToLfe[i]] = directGainsNoLFE[i];
diffuseGains[m_mapNoLfeToLfe[i]] = diffuseGainsNoLFE[i];
}
}
else
{
directGains = directGainsNoLFE;
diffuseGains = diffuseGainsNoLFE;
}

// Get the interpolation time
unsigned int interpLength = 0;
Expand Down

0 comments on commit 6e15883

Please sign in to comment.