iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
NChanDelay.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12#include "IPlugPlatform.h"
13
14BEGIN_IPLUG_NAMESPACE
15
16// A static delayline used to delay bypassed signals to match mLatency in AAX/VST3/AU
17template<typename T>
18class NChanDelayLine
19{
20public:
21 NChanDelayLine(int nInputChans = 2, int nOutputChans = 2)
22 : mNInChans(nInputChans)
23 , mNOutChans(nOutputChans)
24 {}
25
26 void SetDelayTime(int delayTimeSamples)
27 {
28 mDTSamples = delayTimeSamples;
29 mBuffer.Resize(mNInChans * delayTimeSamples);
30 mWriteAddress = 0;
31 ClearBuffer();
32 }
33
34 void ClearBuffer()
35 {
36 memset(mBuffer.Get(), 0, mNInChans * mDTSamples * sizeof(T));
37 }
38
39 void ProcessBlock(T** inputs, T** outputs, int nFrames)
40 {
41 T* buffer = mBuffer.Get();
42
43 for (auto s = 0 ; s < nFrames; ++s)
44 {
45 for (auto c = 0; c < mNInChans; c++)
46 {
47 if (c < mNOutChans)
48 {
49 T input = inputs[c][s];
50 const int offset = c * mDTSamples;
51 outputs[c][s] = buffer[offset + mWriteAddress];
52 buffer[offset + mWriteAddress] = input;
53 }
54 }
55
56 mWriteAddress++;
57 mWriteAddress %= mDTSamples;
58 }
59 }
60
61private:
62 WDL_TypedBuf<T> mBuffer;
63 uint32_t mNInChans, mNOutChans;
64 uint32_t mWriteAddress = 0;
65 uint32_t mDTSamples = 0;
66} WDL_FIXALIGN;
67
68END_IPLUG_NAMESPACE
Include to get consistently named preprocessor macros for different platforms and logging functionali...