Krotos Modules 3
Loading...
Searching...
No Matches
IRConvolver.cpp
Go to the documentation of this file.
1namespace krotos
2{
3 IRConvolver::IRConvolver() : m_headBlockSize(0), m_tailBlockSize(0), m_irBuffer(nullptr) {}
4
6
8
14
16
18 {
19 std::unique_ptr<Convolver> conv{convolver};
20 {
21 ScopedLock convolverLock(m_convolverMutex);
22 m_convolver.swap(conv);
23 }
24 }
25
27
28 void IRConvolver::resetConvolver(FloatBuffer::Ptr irBuffer, float headBlockSize, float tailBlockSize)
29 {
30 jassert(headBlockSize > 0 && tailBlockSize > 0);
31 m_headBlockSize = headBlockSize;
32 m_tailBlockSize = tailBlockSize;
33 if (m_irBuffer != irBuffer)
34 m_irBuffer = irBuffer;
35
36 auto convolver = std::make_unique<Convolver>();
37 const bool successInit = convolver->init(static_cast<size_t>(headBlockSize), static_cast<size_t>(tailBlockSize),
38 m_irBuffer->data(), m_irBuffer->getSize());
39 if (successInit != true)
40 {
41 jassert(true);
42 }
43
44 setConvolver(convolver.release());
45 }
46
48
49 void IRConvolver::process(const float* input, float* output, int len)
50 {
51 // This is the hopefully one and only rare exception where we need to
52 // lock a mutex in the realtime audio thread :-/ (however, the according
53 // convolver mutex is locked somewhere else only once for a very short and
54 // rare swapping operation, so this shouldn't be a problem, and most operating
55 // systems internally try spinning before performing an expensive context switch,
56 // so we will never give up the context here probably).
57 juce::ScopedLock convolverLock(m_convolverMutex);
58
59 if (m_convolver != nullptr)
60 m_convolver->process(input, output, static_cast<size_t>(len));
61
62 else
63 std::memset(output, 0, static_cast<size_t>(static_cast<unsigned long>(len) * sizeof(float)));
64 }
65} // namespace krotos
Definition Convolver.h:4
ReferenceCountedObjectPtr< FloatBuffer > Ptr
Definition IRConvolver.h:6
float m_tailBlockSize
Definition IRConvolver.h:48
Convolver * getConvolver()
Definition IRConvolver.cpp:15
void clearConvolver()
Definition IRConvolver.cpp:47
virtual ~IRConvolver()
Definition IRConvolver.cpp:5
float m_headBlockSize
Definition IRConvolver.h:47
FloatBuffer::Ptr m_irBuffer
Definition IRConvolver.h:50
void resetConvolver()
Definition IRConvolver.cpp:26
CriticalSection m_convolverMutex
Definition IRConvolver.h:52
void clearImpulseResponse()
Definition IRConvolver.cpp:9
FloatBuffer::Ptr getImpulseResponse() const
Definition IRConvolver.cpp:7
IRConvolver()
Definition IRConvolver.cpp:3
void setConvolver(Convolver *convolver)
Definition IRConvolver.cpp:17
std::unique_ptr< Convolver > m_convolver
Definition IRConvolver.h:53
void process(const float *input, float *output, int len)
Definition IRConvolver.cpp:49
Definition AirAbsorptionFilter.cpp:2