24 BEGIN_IGRAPHICS_NAMESPACE
26 static const float SENDER_THRESHOLD = (float)
DBToAmp(-90.);
29 template <
int MAXNC = 1,
typename T =
float>
35 std::array<T, MAXNC> vals {0};
39 ISenderData(
int ctrlTag,
int nChans,
int chanOffset)
42 , chanOffset(chanOffset)
46 ISenderData(
int ctrlTag,
const std::array<T, MAXNC>& vals,
int nChans = MAXNC,
int chanOffset = 0)
49 , chanOffset(chanOffset)
56 template <
int MAXNC = 1,
int QUEUE_SIZE = 64,
typename T =
float>
60 static constexpr
int kUpdateMessage = 0;
72 while(mQueue.ElementsAvailable())
85 template <
int MAXNC = 1,
int QUEUE_SIZE = 64>
90 void ProcessBlock(sample** inputs,
int nFrames,
int ctrlTag,
int nChans = MAXNC,
int chanOffset = 0)
94 for (
auto s = 0; s < nFrames; s++)
96 for (
auto c = chanOffset; c < (chanOffset + nChans); c++)
98 d.vals[c] += std::fabs((
float) inputs[c][s]);
104 for (
auto c = chanOffset; c < (chanOffset + nChans); c++)
106 d.vals[c] /= (float) nFrames;
110 if(sum > SENDER_THRESHOLD || mPreviousSum > SENDER_THRESHOLD)
116 float mPreviousSum = 1.f;
120 template <
int MAXNC = 1,
int QUEUE_SIZE = 64,
int MAXBUF = 128>
126 void ProcessBlock(sample** inputs,
int nFrames,
int ctrlTag,
int nChans = MAXNC,
int chanOffset = 0)
128 for (
auto s = 0; s < nFrames; s++)
130 if(mBufCount == MAXBUF)
133 for (
auto c = chanOffset; c < (chanOffset + nChans); c++)
135 sum += mRunningSum[c];
136 mRunningSum[c] = 0.f;
139 if (sum > SENDER_THRESHOLD || mPreviousSum > SENDER_THRESHOLD)
141 mBuffer.ctrlTag = ctrlTag;
142 mBuffer.nChans = nChans;
143 mBuffer.chanOffset = chanOffset;
151 for (
auto c = chanOffset; c < (chanOffset + nChans); c++)
153 mBuffer.vals[c][mBufCount] = (float) inputs[c][s];
154 mRunningSum[c] += std::fabs( (
float) inputs[c][s]);
163 std::array<float, MAXNC> mRunningSum {0.};
164 float mPreviousSum = 1.f;
168 END_IGRAPHICS_NAMESPACE
A lock-free SPSC queue used to transfer data between threads based on MLQueue.h by Randy Jones based ...
IBufferSender is a utility class which can be used to defer buffer data for sending to the GUI...
virtual void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize=0, const void *pData=nullptr)
SendControlMsgFromDelegate (Abbreviation: SCMFD) WARNING: should not be called on the realtime audio ...
void ProcessBlock(sample **inputs, int nFrames, int ctrlTag, int nChans=MAXNC, int chanOffset=0)
Queue peaks from sample buffers into the sender, checking the data is over the required threshold...
ISenderData is used to represent a typed data packet, that may contain values for multiple channels...
void TransmitData(IEditorDelegate &dlg)
Pops elements off the queue and sends messages to controls.
This pure virtual interface delegates communication in both directions between a UI editor and someth...
void ProcessBlock(sample **inputs, int nFrames, int ctrlTag, int nChans=MAXNC, int chanOffset=0)
Queue sample buffers into the sender, checking the data is over the required threshold.
static double DBToAmp(double dB)
Calculates gain from a given dB value.
void PushData(const ISenderData< MAXNC, T > &d)
Pushes a data element onto the queue.
IPeakSender is a utility class which can be used to defer peak data from sample buffers for sending t...
ISender is a utility class which can be used to defer data from the realtime audio processing and sen...
A lock-free SPSC queue used to transfer data between threads based on MLQueue.h by Randy Jones based ...