#include <string.h>
#include <assert.h>
#include <glib.h>
+#include <glibmm.h>
+#include <fftw3.h>
+
+#include "pbd/malign.h"
+
+#include "ardour/buffer_set.h"
+#include "ardour/chan_mapping.h"
#include "ardour/libardour_visibility.h"
+#include "ardour/types.h"
namespace ARDOUR { namespace DSP {
*/
class DspShm {
public:
- DspShm ()
+ DspShm (size_t s = 0)
: _data (0)
, _size (0)
{
assert (sizeof(float) == sizeof (int32_t));
assert (sizeof(float) == sizeof (int));
+ allocate (s);
}
~DspShm () {
- free (_data);
+ cache_aligned_free (_data);
}
/** [re] allocate memory in host's memory space
* @param s size, total number of float or integer elements to store.
*/
void allocate (size_t s) {
- _data = realloc (_data, sizeof(float) * s);
+ if (s == _size) { return; }
+ cache_aligned_free (_data);
+ cache_aligned_malloc ((void**) &_data, sizeof (float) * s);
if (_data) { _size = s; }
}
* @param max result, max value found in range
* @param n_samples number of samples to analyze
*/
- void peaks (float *data, float &min, float &max, uint32_t n_samples);
+ void peaks (const float *data, float &min, float &max, uint32_t n_samples);
/** non-linear power-scale meter deflection
*
*/
float log_meter_coeff (float coeff);
+ void process_map (BufferSet* bufs,
+ const ChanMapping& in,
+ const ChanMapping& out,
+ pframes_t nframes, framecnt_t offset,
+ const DataType&);
+
/** 1st order Low Pass filter */
class LIBARDOUR_API LowPass {
public:
};
/** Biquad Filter */
- class LIBARDOUR_API BiQuad {
+ class LIBARDOUR_API Biquad {
public:
enum Type {
LowPass,
*
* @param samplerate Samplerate
*/
- BiQuad (double samplerate);
- BiQuad (const BiQuad &other);
+ Biquad (double samplerate);
+ Biquad (const Biquad &other);
/** process audio data
*
*/
void compute (Type t, double freq, double Q, double gain);
+ /** setup filter, set coefficients directly */
+ void configure (double a1, double a2, double b0, double b1, double b2);
+
/** filter transfer function (filter response for spectrum visualization)
* @param freq frequency
* @return gain at given frequency in dB (clamped to -120..+120)
double _b0, _b1, _b2;
};
+ class LIBARDOUR_API FFTSpectrum {
+ public:
+ FFTSpectrum (uint32_t window_size, double rate);
+ ~FFTSpectrum ();
+
+ /** set data to be analyzed and pre-process with hanning window
+ * n_samples + offset must not be larger than the configured window_size
+ *
+ * @param data raw audio data
+ * @param n_samples number of samples to write to analysis buffer
+ * @param offset destination offset
+ */
+ void set_data_hann (float const * const data, const uint32_t n_samples, const uint32_t offset = 0);
+
+ /** process current data in buffer */
+ void execute ();
+
+ /** query
+ * @param bin the frequency bin 0 .. window_size / 2
+ * @param norm gain factor (set equal to @bin for 1/f normalization)
+ * @return signal power at given bin (in dBFS)
+ */
+ float power_at_bin (const uint32_t bin, const float norm = 1.f) const;
+
+ float freq_at_bin (const uint32_t bin) const {
+ return bin * _fft_freq_per_bin;
+ }
+
+ private:
+ static Glib::Threads::Mutex fft_planner_lock;
+ float* hann_window;
+
+ void init (uint32_t window_size, double rate);
+ void reset ();
+
+ uint32_t _fft_window_size;
+ uint32_t _fft_data_size;
+ double _fft_freq_per_bin;
+
+ float* _fft_data_in;
+ float* _fft_data_out;
+ float* _fft_power;
+
+ fftwf_plan _fftplan;
+ };
+
} } /* namespace */
#endif