diff options
author | Robin Gareus <robin@gareus.org> | 2020-02-02 20:54:58 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-02-06 17:30:22 +0100 |
commit | 00fcf6719c348c84da0e9b4d8a689c485234dde0 (patch) | |
tree | bc0ded0020102328dfeae6d3e8556c448b78146e /libs/ardour/ardour | |
parent | bfebe43a02bbafacfaccd7d2f0bb3f10d13067fd (diff) |
Update DSP::Convolution
Expose zita-convolver bindings, to allow for
custom NxM convolution matrices, and dedicated FIR processors.
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r-- | libs/ardour/ardour/convolver.h | 123 |
1 files changed, 102 insertions, 21 deletions
diff --git a/libs/ardour/ardour/convolver.h b/libs/ardour/ardour/convolver.h index 642f9b0b04..2aca6d6917 100644 --- a/libs/ardour/ardour/convolver.h +++ b/libs/ardour/ardour/convolver.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Robin Gareus <robin@gareus.org> + * Copyright (C) 2018-2020 Robin Gareus <robin@gareus.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,24 +23,120 @@ #include "zita-convolver/zita-convolver.h" #include "ardour/libardour_visibility.h" + +#include "ardour/buffer_set.h" +#include "ardour/chan_mapping.h" #include "ardour/readable.h" namespace ARDOUR { namespace DSP { -class LIBARDOUR_API Convolver : public SessionHandleRef { +class LIBARDOUR_API Convolution : public SessionHandleRef +{ public: + Convolution (Session&, uint32_t n_in, uint32_t n_out); + virtual ~Convolution () {} + + bool add_impdata ( + uint32_t c_in, + uint32_t c_out, + boost::shared_ptr<Readable> r, + float gain = 1.0, + uint32_t pre_delay = 0, + sampleoffset_t offset = 0, + samplecnt_t length = 0, + uint32_t channel = 0); + + bool ready () const; + uint32_t latency () const { return _n_samples; } + uint32_t n_inputs () const { return _n_inputs; } + uint32_t n_outputs () const { return _n_outputs; } + + void restart (); + void run (BufferSet&, ChanMapping const&, ChanMapping const&, pframes_t, samplecnt_t); + +protected: + ArdourZita::Convproc _convproc; + + uint32_t _n_samples; + uint32_t _max_size; + uint32_t _offset; + bool _configured; + +private: + class ImpData : public Readable + { + public: + ImpData (uint32_t ci, uint32_t co, boost::shared_ptr<Readable> r, float g, float d, sampleoffset_t s = 0, samplecnt_t l = 0, uint32_t c = 0) + : c_in (ci) + , c_out (co) + , gain (g) + , delay (d) + , _readable (r) + , _offset (s) + , _length (l) + , _channel (c) + {} + + uint32_t c_in; + uint32_t c_out; + float gain; + uint32_t delay; + + samplecnt_t read (Sample* s, samplepos_t pos, samplecnt_t cnt, int c = -1) const { + return _readable->read (s, pos + _offset, cnt, _channel); + } + + samplecnt_t readable_length () const { + samplecnt_t rl = _readable->readable_length (); + if (rl < _offset) { + return 0; + } else if (_length > 0) { + return std::min (rl - _offset, _length); + } else { + return rl - _offset; + } + } + + uint32_t n_channels () const { + return _readable->n_channels (); + } + + private: + boost::shared_ptr<Readable> _readable; + sampleoffset_t _offset; + samplecnt_t _length; + uint32_t _channel; + }; + + std::vector<ImpData> _impdata; + uint32_t _n_inputs; + uint32_t _n_outputs; +}; + +class LIBARDOUR_API Convolver : public Convolution +{ +public: enum IRChannelConfig { Mono, ///< 1 in, 1 out; 1ch IR MonoToStereo, ///< 1 in, 2 out, stereo IR M -> L, M -> R Stereo, ///< 2 in, 2 out, stereo IR L -> L, R -> R || 4 chan IR L -> L, L -> R, R -> R, R -> L }; + static uint32_t ircc_in (IRChannelConfig irc) { + return irc < Stereo ? 1 : 2; + } + + static uint32_t ircc_out (IRChannelConfig irc) { + return irc == Mono ? 1 : 2; + } + struct IRSettings { - IRSettings () { - gain = 1.0; + IRSettings () + { + gain = 1.0; pre_delay = 0.0; - channel_gain[0] = channel_gain[1] = channel_gain[2] = channel_gain[3] = 1.0; + channel_gain[0] = channel_gain[1] = channel_gain[2] = channel_gain[3] = 1.0; channel_delay[0] = channel_delay[1] = channel_delay[2] = channel_delay[3] = 0; }; @@ -66,31 +162,16 @@ public: } }; - Convolver (Session&, std::string const&, IRChannelConfig irc = Mono, IRSettings irs = IRSettings ()); - void run (float*, uint32_t); + void run_mono (float*, uint32_t); void run_stereo (float* L, float* R, uint32_t); - uint32_t latency () const { return _n_samples; } - - uint32_t n_inputs () const { return _irc < Stereo ? 1 : 2; } - uint32_t n_outputs () const { return _irc == Mono ? 1 : 2; } - - bool ready () const; - private: - void reconfigure (); std::vector<boost::shared_ptr<Readable> > _readables; - ArdourZita::Convproc _convproc; IRChannelConfig _irc; IRSettings _ir_settings; - - uint32_t _n_samples; - uint32_t _max_size; - uint32_t _offset; - bool _configured; }; } } /* namespace */ |