1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/*
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2021 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-plugins-art-delay
* Created on: 3 авг. 2021 г.
*
* lsp-plugins-art-delay is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-plugins-art-delay is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-plugins-art-delay. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PRIVATE_PLUGINS_ART_DELAY_H_
#define PRIVATE_PLUGINS_ART_DELAY_H_
#include <lsp-plug.in/plug-fw/plug.h>
#include <lsp-plug.in/dsp-units/ctl/Blink.h>
#include <lsp-plug.in/dsp-units/ctl/Bypass.h>
#include <lsp-plug.in/dsp-units/filters/Equalizer.h>
#include <lsp-plug.in/dsp-units/util/DynamicDelay.h>
#include <private/meta/art_delay.h>
namespace lsp
{
namespace plugins
{
/**
* Artistic Delay Plugin Series
*/
class art_delay: public plug::Module
{
protected:
struct art_delay_t;
class DelayAllocator: public ipc::ITask
{
private:
art_delay *pBase; // Delay base
art_delay_t *pDelay; // Delay pointer
ssize_t nSize; // Requested delay size
public:
explicit DelayAllocator(art_delay *base, art_delay_t *delay);
virtual ~DelayAllocator();
public:
virtual status_t run();
public:
void set_size(ssize_t size) { nSize = size; }
};
typedef struct art_tempo_t
{
float fTempo; // The actual tempo
bool bSync; // Sync flag
plug::IPort *pTempo; // Tempo port
plug::IPort *pRatio; // Ratio port
plug::IPort *pSync; // Sync flag
plug::IPort *pOutTempo; // Output tempo
} art_tempo_t;
typedef struct pan_t
{
float l; // Gain of left channel
float r; // Gain of right channel
} pan_t;
typedef struct art_settings_t
{
float fDelay; // Delay value
float fFeedGain; // Feedback gain
float fFeedLen; // Feedback length
pan_t sPan[2]; // Pan value + gain for each channel
size_t nMaxDelay; // Maximum possible delay
} art_settings_t;
typedef struct art_delay_t
{
dspu::DynamicDelay *pPDelay[2]; // Pending delay (waiting for replace)
dspu::DynamicDelay *pCDelay[2]; // Currently used delay for each channel
dspu::DynamicDelay *pGDelay[2]; // Garbage
dspu::Equalizer sEq[2]; // Equalizers for each channel
dspu::Bypass sBypass[2]; // Bypass
dspu::Blink sOutOfRange; // Blink
dspu::Blink sFeedOutRange; // Feedback is out of range
DelayAllocator *pAllocator; // Allocator
bool bStereo; // Mode: Mono/stereo
bool bOn; // Delay is enabled
bool bSolo; // Soloing flag
bool bMute; // Muting flag
bool bUpdated; // Update flag
bool bValidRef; // Valid reference flag
ssize_t nDelayRef; // Reference to delay
float fOutDelay; // Output delay
float fOutFeedback; // Output feedback delay
float fOutTempo; // Output tempo
float fOutFeedTempo; // Output tempo
float fOutDelayRef; // Output delay reference value
art_settings_t sOld; // Old settings
art_settings_t sNew; // New settings
plug::IPort *pOn; // On
plug::IPort *pTempoRef; // Tempo reference
plug::IPort *pPan[2]; // Panning
plug::IPort *pSolo; // Solo flag
plug::IPort *pMute; // Mute flag
plug::IPort *pDelayRef; // Delay reference
plug::IPort *pDelayMul; // Delay reference multiplier
plug::IPort *pBarFrac; // Bar fraction
plug::IPort *pBarDenom; // Bar denominator
plug::IPort *pBarMul; // Bar multiplier
plug::IPort *pFrac; // Add fraction
plug::IPort *pDenom; // Add denominator
plug::IPort *pDelay; // Add delay
plug::IPort *pEqOn; // Equalizer on
plug::IPort *pLcfOn; // Low-cut filter on
plug::IPort *pLcfFreq; // Low-cut filter frequency
plug::IPort *pHcfOn; // High-cut filter on
plug::IPort *pHcfFreq; // High-cut filter frequency
plug::IPort *pBandGain[meta::art_delay_metadata::EQ_BANDS]; // Band gain for each filter
plug::IPort *pGain; // Output gain
// Feedback control
plug::IPort *pFeedOn; // Feedback on
plug::IPort *pFeedGain; // Feedback gain
plug::IPort *pFeedTempoRef; // Tempo reference for feedback
plug::IPort *pFeedBarFrac; // Bar fraction
plug::IPort *pFeedBarDenom; // Bar denominator
plug::IPort *pFeedBarMul; // Bar multiplier
plug::IPort *pFeedFrac; // Add fraction
plug::IPort *pFeedDenom; // Add denominator
plug::IPort *pFeedDelay; // Add delay
// Outputs
plug::IPort *pOutDelay; // Output delay
plug::IPort *pOutFeedback; // Output feedback delay
plug::IPort *pOutOfRange; // Out of range status
plug::IPort *pOutFeedRange; // Feedbsck out of range status
plug::IPort *pOutLoop; // Dependency loop
plug::IPort *pOutTempo; // Actual tempo
plug::IPort *pOutFeedTempo; // Actual feedback tempo
plug::IPort *pOutDelayRef; // Actual delay reference value
} art_delay_t;
protected:
bool bStereoIn;
bool bMono; // Mono switch
size_t nMaxDelay; // Maximum delay
pan_t sOldDryPan[2]; // Old panning + gain
pan_t sNewDryPan[2]; // New panning + gain
float *vOutBuf[2]; // Output buffer
float *vGainBuf; // Gain control buffer
float *vDelayBuf; // Delay control buffer
float *vFeedBuf; // Feedback delay control buffer
float *vTempBuf; // Temporary buffer for delay processing
art_tempo_t *vTempo; // Tempo settings
art_delay_t *vDelays; // Delay lines
volatile uint32_t nMemUsed; // Overall memory usage by delay lines
dspu::Bypass sBypass[2]; // Bypasses
ipc::IExecutor *pExecutor;
plug::IPort *pIn[2]; // Input ports
plug::IPort *pOut[2]; // Output ports
plug::IPort *pBypass; // Bypass
plug::IPort *pMaxDelay; // Maximum possible delay
plug::IPort *pPan[2]; // Panning
plug::IPort *pDryGain; // Dry gain
plug::IPort *pWetGain; // Wet gain
plug::IPort *pDryOn; // Dry enable
plug::IPort *pWetOn; // Wet enable
plug::IPort *pMono; // Mono/Stereo switch
plug::IPort *pFeedback; // Enable feedback for all delays
plug::IPort *pFeedGain; // Feedback gain control
plug::IPort *pOutGain; // Overall output gain
plug::IPort *pOutDMax; // Maximum delay output value
plug::IPort *pOutMemUse; // Memory usage
uint8_t *pData;
protected:
static inline float decode_ratio(size_t v);
inline size_t decode_max_delay_value(size_t v);
bool check_delay_ref(art_delay_t *ad);
void sync_delay(art_delay_t *ad);
void process_delay(art_delay_t *ad, float **out, const float * const *in, size_t samples, size_t i, size_t count);
static void dump_pan(dspu::IStateDumper *v, const char *name, const pan_t *pan, size_t n);
static void dump_art_settings(dspu::IStateDumper *v, const char *name, const art_settings_t *as);
static void dump_art_delay(dspu::IStateDumper *v, const art_delay_t *ad);
static void dump_art_tempo(dspu::IStateDumper *v, const art_tempo_t *at);
public:
explicit art_delay(const meta::plugin_t *metadata, bool stereo_in);
virtual ~art_delay();
virtual void init(plug::IWrapper *wrapper, plug::IPort **ports);
virtual void destroy();
public:
virtual bool set_position(const plug::position_t *pos);
virtual void update_settings();
virtual void update_sample_rate(long sr);
virtual void process(size_t samples);
virtual void dump(dspu::IStateDumper *v) const;
};
} // namespace plugins
} // namespace lsp
#endif /* PRIVATE_PLUGINS_ART_DELAY_H_ */
|