diff --git a/include/AdmRenderer.h b/include/AdmRenderer.h index d773baa..e50801c 100644 --- a/include/AdmRenderer.h +++ b/include/AdmRenderer.h @@ -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 m_mapNoLfeToLfe; // Vector holding the last unique set metadata for each object in the stream std::vector m_objectMetadata; diff --git a/include/Tests.h b/include/Tests.h index d1ccf45..7f18589 100644 --- a/include/Tests.h +++ b/include/Tests.h @@ -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, }; diff --git a/source/AdmRenderer.cpp b/source/AdmRenderer.cpp index 1ea8ef3..4fb488a 100644 --- a/source/AdmRenderer.cpp +++ b/source/AdmRenderer.cpp @@ -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); @@ -235,13 +241,32 @@ namespace admrender { // Store the metadata m_objectMetadata[iObj] = metadata; // Calculate a new gain vector with this metadata - std::vector directGains; - std::vector diffuseGains; - m_objectGainCalc->CalculateGains(metadata, directGains, diffuseGains); + std::vector directGainsNoLFE; + std::vector 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 directGains; + std::vector 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;