diff options
author | Robin Gareus <robin@gareus.org> | 2016-03-18 20:00:44 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-03-18 20:00:44 +0100 |
commit | 4ef3e251853dec5e7e300618c5135ea33af9ff81 (patch) | |
tree | e61eb6b57508bf1aea62de298392a9a7c0a010a8 /libs/ardour/ardour | |
parent | 2c71196a6cc878866e0deda9653d0e59ac39b960 (diff) |
Add some convenient DSP methods for lua scripts
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r-- | libs/ardour/ardour/dsp_filter.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libs/ardour/ardour/dsp_filter.h b/libs/ardour/ardour/dsp_filter.h index ae2928de93..1b4cb6eed8 100644 --- a/libs/ardour/ardour/dsp_filter.h +++ b/libs/ardour/ardour/dsp_filter.h @@ -20,13 +20,69 @@ #define _dsp_filter_h_ #include <stdint.h> +#include <string.h> +#include <assert.h> +#include <glib.h> #include "ardour/libardour_visibility.h" namespace ARDOUR { namespace DSP { + /** a convenience class for lua scripts to use C memory for DSP operations. + * + * It should be allocated during dsp_init() or dsp_configure(). + */ + class DspShm { + public: + DspShm () + : _data (0) + , _size (0) + { + assert (sizeof(float) == sizeof (int32_t)); + assert (sizeof(float) == sizeof (int)); + } + + ~DspShm () { + free (_data); + } + + void allocate (size_t s) { + _data = realloc (_data, sizeof(float) * s); + if (_data) { _size = s; } + } + + void clear () { + memset (_data, 0, sizeof(float) * _size); + } + + float* to_float (size_t off) { + if (off >= _size) { return 0; } + return &(((float*)_data)[off]); + } + + int32_t* to_int (size_t off) { + if (off >= _size) { return 0; } + return &(((int32_t*)_data)[off]); + } + + void atomic_set_int (size_t off, int32_t val) { + g_atomic_int_set (&(((int32_t*)_data)[off]), val); + } + + int32_t atomic_get_int (size_t off) { + return g_atomic_int_get (&(((int32_t*)_data)[off])); + } + + private: + void* _data; + size_t _size; + }; + void memset (float *data, const float val, const uint32_t n_samples); void mmult (float *data, float *mult, const uint32_t n_samples); + void peaks (float *data, float &min, float &max, uint32_t n_samples); + float log_meter (float power); + float log_meter_coeff (float coeff); class LIBARDOUR_API LowPass { public: |