-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathObjectPanner.cpp
More file actions
92 lines (73 loc) · 3.35 KB
/
ObjectPanner.cpp
File metadata and controls
92 lines (73 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*############################################################################*/
/*# #*/
/*# Pan mono objects on a speaker layout in real-time. #*/
/*# Copyright © 2025 Peter Stitt #*/
/*# #*/
/*# Filename: ObjectPanner.cpp #*/
/*# Version: 0.1 #*/
/*# Date: 10/09/2025 #*/
/*# Author(s): Peter Stitt #*/
/*# Licence: LGPL + proprietary #*/
/*# #*/
/*############################################################################*/
#include "ObjectPanner.h"
#include <assert.h>
namespace spaudio {
ObjectPanner::ObjectPanner() : m_coeffInterp(0)
{
}
ObjectPanner::~ObjectPanner()
{
}
bool ObjectPanner::Configure(OutputLayout layout, unsigned sampleRate, float fadeTimeMilliSec)
{
if (fadeTimeMilliSec < 0.f)
return false;
m_layout = Layout::getMatchingLayout(layout);
m_pspGainCalc = std::make_unique<PointSourcePannerGainCalc>(layout);
m_gainsTmp.resize(m_pspGainCalc->getNumChannels());
m_gains.resize(m_layout.getNumChannels());
m_coeffInterp = GainInterp<double>(static_cast<int>(m_gains.size()));
m_fadingTimeMilliSec = fadeTimeMilliSec;
m_fadingSamples = (unsigned)std::round(0.001f * m_fadingTimeMilliSec * (float)sampleRate);
return true;
}
void ObjectPanner::Reset()
{
m_coeffInterp.Reset();
}
int ObjectPanner::GetNumSpeakers()
{
return static_cast<int>(m_layout.getNumChannels());
}
void ObjectPanner::SetPosition(const PolarPosition<double>& polPosition)
{
m_pspGainCalc->CalculateGains(polPosition, m_gainsTmp);
insertLFE(m_gainsTmp, m_gains);
m_coeffInterp.SetGainVector(m_gains, m_fadingSamples);
}
void ObjectPanner::Process(float* pfSrc, unsigned nSamplesIn, float** ppDst, unsigned int nSamplesOut, unsigned int nOffset)
{
assert(nSamplesIn + nOffset <= nSamplesOut); // Cannot write beyond the of the output buffers!
m_coeffInterp.Process(pfSrc, ppDst, nSamplesIn, nOffset);
}
void ObjectPanner::ProcessAccumul(float* pfSrc, unsigned nSamplesIn, float** ppDst, unsigned int nSamplesOut, unsigned int nOffset, float fGain)
{
assert(nSamplesIn + nOffset <= nSamplesOut); // Cannot write beyond the of the output buffers!
m_coeffInterp.ProcessAccumul(pfSrc, ppDst, nSamplesIn, nOffset, fGain);
}
void ObjectPanner::insertLFE(const std::vector<double>& inGains, std::vector<double>& outGains)
{
if (!m_layout.hasLfe()) // No LFE to insert so just copy the gain vector
{
outGains = inGains;
return;
}
size_t iCount = 0;
for (size_t i = 0; i < m_layout.getNumChannels(); ++i)
if (!m_layout.getChannel(i).getIsLfe())
outGains[i] = inGains[iCount++];
else
outGains[i] = 0.;
}
}