-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathAmbisonicEncoder.cpp
More file actions
79 lines (62 loc) · 3.07 KB
/
AmbisonicEncoder.cpp
File metadata and controls
79 lines (62 loc) · 3.07 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
/*############################################################################*/
/*# #*/
/*# Ambisonic C++ Library #*/
/*# AmbisonicEncoder - Ambisonic Encoder #*/
/*# Copyright © 2007 Aristotel Digenis #*/
/*# #*/
/*# Filename: AmbisonicEncoder.cpp #*/
/*# Version: 0.1 #*/
/*# Date: 19/05/2007 #*/
/*# Author(s): Aristotel Digenis #*/
/*# Licence: MIT #*/
/*# #*/
/*############################################################################*/
#include "AmbisonicEncoder.h"
#include <assert.h>
#include <cmath>
namespace spaudio {
AmbisonicEncoder::AmbisonicEncoder() : m_coeffInterp(0)
{
}
AmbisonicEncoder::~AmbisonicEncoder()
{
}
bool AmbisonicEncoder::Configure(unsigned nOrder, bool b3D, unsigned sampleRate, float fadeTimeMilliSec)
{
bool success = AmbisonicSource::Configure(nOrder, b3D, sampleRate);
if (!success || fadeTimeMilliSec < 0.f)
return false;
m_pfCoeffCurrent.resize(m_nChannelCount);
m_coeffInterp = GainInterp<float>(m_nChannelCount);
m_fadingTimeMilliSec = fadeTimeMilliSec;
m_fadingSamples = (unsigned)std::round(0.001f * m_fadingTimeMilliSec * (float)sampleRate);
return true;
}
void AmbisonicEncoder::Refresh()
{
AmbisonicSource::Refresh();
}
void AmbisonicEncoder::Reset()
{
AmbisonicSource::Reset();
m_coeffInterp.Reset();
}
void AmbisonicEncoder::SetPosition(PolarPosition<float> polPosition)
{
// Update the coefficients
AmbisonicSource::SetPosition(polPosition);
AmbisonicSource::Refresh();
AmbisonicSource::GetCoefficients(m_pfCoeffCurrent);
m_coeffInterp.SetGainVector(m_pfCoeffCurrent, m_fadingSamples);
}
void AmbisonicEncoder::Process(float* pfSrc, unsigned nSamples, BFormat* pfDst, unsigned int nOffset)
{
assert(nSamples + nOffset <= pfDst->GetSampleCount()); // Cannot write beyond the of the destination buffers!
m_coeffInterp.Process(pfSrc, pfDst->m_ppfChannels.get(), nSamples, nOffset);
}
void AmbisonicEncoder::ProcessAccumul(float* pfSrc, unsigned nSamples, BFormat* pfDst, unsigned int nOffset, float fGain)
{
assert(nSamples + nOffset <= pfDst->GetSampleCount()); // Cannot write beyond the of the destination buffers!
m_coeffInterp.ProcessAccumul(pfSrc, pfDst->m_ppfChannels.get(), nSamples, nOffset, fGain);
}
} // namespace spaudio