Skip to content

Commit 71aee69

Browse files
committed
Spectral Processor now allows to analyze input signal without processing
1 parent 4f3aed5 commit 71aee69

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*******************************************************************************
44

55
=== 1.0.33 ===
6-
6+
* Spectral Processor now allows to analyze input signal without processing.
77

88
=== 1.0.32 ===
99
* Fixes in 3D object loading.

include/lsp-plug.in/dsp-units/util/SpectralProcessor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,23 @@ namespace lsp
148148
*/
149149
void process(float *dst, const float *src, size_t count);
150150

151+
/**
152+
* Perform audio analysis without de-processing
153+
* @param src source buffer
154+
* @param count number of samples to process
155+
*/
156+
void process(const float *src, size_t count);
157+
151158
/**
152159
* Reset state: cleanup internal buffers
153160
*/
154161
void reset();
162+
163+
/**
164+
* Return number of samples remaining before the FFT transform operation occurs
165+
* @return number of samples remaining before the FFT transform occurs
166+
*/
167+
size_t remaining() const;
155168

156169
/**
157170
* Dump the state

src/main/util/SpectralProcessor.cpp

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ namespace lsp
150150
if (bUpdate)
151151
update_settings();
152152

153-
size_t buf_size = 1 << nRank;
154-
size_t frame_size = 1 << (nRank - 1);
153+
const size_t buf_size = 1 << nRank;
154+
const size_t frame_size = 1 << (nRank - 1);
155155

156156
while (count > 0)
157157
{
@@ -183,7 +183,7 @@ namespace lsp
183183
}
184184

185185
// Estimate number of samples to process
186-
size_t to_process = lsp_min(frame_size - nOffset, count);
186+
const size_t to_process = lsp_min(frame_size - nOffset, count);
187187

188188
// Copy data
189189
dsp::copy(&pInBuf[frame_size + nOffset], src, to_process);
@@ -197,6 +197,58 @@ namespace lsp
197197
}
198198
}
199199

200+
void SpectralProcessor::process(const float *src, size_t count)
201+
{
202+
// Check if we need to commit new settings
203+
if (bUpdate)
204+
update_settings();
205+
206+
const size_t buf_size = 1 << nRank;
207+
const size_t frame_size = 1 << (nRank - 1);
208+
209+
while (count > 0)
210+
{
211+
// Need to perform transformations?
212+
if (nOffset >= frame_size)
213+
{
214+
if (pFunc != NULL)
215+
{
216+
// Perform FFT and processing
217+
dsp::pcomplex_r2c(pFftBuf, pInBuf, buf_size); // Convert from real to packed complex
218+
dsp::packed_direct_fft(pFftBuf, pFftBuf, nRank); // Perform direct FFT
219+
pFunc(pObject, pSubject, pFftBuf, nRank); // Call the function
220+
}
221+
222+
// Apply signal to buffer
223+
dsp::move(pOutBuf, &pOutBuf[frame_size], frame_size); // Shift output buffer
224+
dsp::fill_zero(&pOutBuf[frame_size], frame_size); // Fill tail of input buffer with zeros
225+
226+
// Shift input buffer
227+
dsp::move(pInBuf, &pInBuf[frame_size], frame_size); // Shift input buffer
228+
229+
// Reset read/write offset
230+
nOffset = 0;
231+
}
232+
233+
// Estimate number of samples to process
234+
const size_t to_process = lsp_min(frame_size - nOffset, count);
235+
236+
// Copy data
237+
dsp::copy(&pInBuf[frame_size + nOffset], src, to_process);
238+
239+
// Update pointers
240+
nOffset += to_process;
241+
count -= to_process;
242+
src += to_process;
243+
}
244+
}
245+
246+
size_t SpectralProcessor::remaining() const
247+
{
248+
const size_t frame_size = 1 << (nRank - 1);
249+
return frame_size - nOffset;
250+
}
251+
200252
void SpectralProcessor::reset()
201253
{
202254
if (bUpdate) // update_settings() will automaticaly clear the buffer

0 commit comments

Comments
 (0)