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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/*
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2021 Stefano Tronci <stefano.tronci@protonmail.com>
*
* This file is part of lsp-dsp-units
* Created on: 31 May 2021
*
* lsp-plugins 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 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. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_DSP_UNITS_NOISE_GENERATOR_H_
#define LSP_PLUG_IN_DSP_UNITS_NOISE_GENERATOR_H_
#include <lsp-plug.in/dsp-units/filters/SpectralTilt.h>
#include <lsp-plug.in/dsp-units/iface/IStateDumper.h>
#include <lsp-plug.in/dsp-units/noise/LCG.h>
#include <lsp-plug.in/dsp-units/noise/MLS.h>
#include <lsp-plug.in/dsp-units/noise/Velvet.h>
namespace lsp
{
namespace dspu
{
enum ng_generator_t
{
NG_GEN_MLS,
NG_GEN_LCG,
NG_GEN_VELVET,
NG_GEN_MAX
};
enum ng_color_t
{
NG_COLOR_WHITE,
NG_COLOR_PINK,
NG_COLOR_RED,
NG_COLOR_BLUE,
NG_COLOR_VIOLET,
NG_COLOR_ARBITRARY,
NG_COLOR_MAX,
NG_COLOR_BROWN = NG_COLOR_RED,
NG_COLOR_BROWNIAN = NG_COLOR_RED
};
class LSP_DSP_UNITS_PUBLIC NoiseGenerator
{
private:
NoiseGenerator & operator = (const NoiseGenerator &);
NoiseGenerator(const NoiseGenerator &);
protected:
enum update_t
{
UPD_MLS = 1 << 0,
UPD_LCG = 1 << 1,
UPD_VELVET = 1 << 2,
UPD_COLOR = 1 << 3,
UPD_OTHER = 1 << 4,
UPD_ALL = UPD_MLS | UPD_LCG | UPD_VELVET | UPD_COLOR | UPD_OTHER
};
typedef struct mls_params_t
{
uint8_t nBits;
MLS::mls_t nSeed;
} mls_params_t;
typedef struct lcg_params_t
{
uint32_t nSeed;
lcg_dist_t enDistribution;
} lcg_params_t;
typedef struct velvet_params_t
{
uint32_t nRandSeed;
uint8_t nMLSnBits;
MLS::mls_t nMLSseed;
vn_core_t enCore;
vn_velvet_type_t enVelvetType;
float fWindowWidth_s;
float fARNdelta;
bool bCrush;
float fCrushProb;
} velvet_params_t;
typedef struct color_params_t
{
ng_color_t enColor;
size_t nOrder;
float fSlope;
stlt_slope_unit_t enSlopeUnit;
} color_params_t;
private:
MLS sMLS;
LCG sLCG;
Velvet sVelvetNoise;
SpectralTilt sColorFilter;
mls_params_t sMLSParams;
lcg_params_t sLCGParams;
velvet_params_t sVelvetParams;
color_params_t sColorParams;
size_t nSampleRate;
ng_generator_t enGenerator;
float fAmplitude;
float fOffset;
size_t nUpdate;
public:
explicit NoiseGenerator();
~NoiseGenerator();
void construct();
void destroy();
protected:
void do_process(float *dst, size_t count);
void update_settings();
public:
/** Initialize random generator.
*
* @param rand_seed seed for the Randomizer generator.
* @param lcg_seed seed for the LCG generator.
*/
void init(
uint8_t mls_n_bits, MLS::mls_t mls_seed,
uint32_t lcg_seed,
uint32_t velvet_rand_seed, uint8_t velvet_mls_n_bits, MLS::mls_t velvet_mls_seed);
/** Initialize random generator, automatic.
*/
void init();
/** Set sample rate
*
* @param sr sample rate
*/
void set_sample_rate(size_t sr);
/** Set the number of bits of the MLS sequence generator.
*
* @param nbits number of bits.
*/
void set_mls_n_bits(uint8_t nbits);
/** Set MLS generator seed.
*
* @param seed MLS seed.
*/
void set_mls_seed(MLS::mls_t seed);
/** Set LCG distribution.
*
* @param dist LCG distribution.
*/
void set_lcg_distribution(lcg_dist_t dist);
/** Set the lcg_dist_telvet noise type. Velvet noise is emitted only if Sparsity is Velvet.
*
* @param type velvet type.
*/
void set_velvet_type(vn_velvet_type_t type);
/** Set the Velvet noise window width in samples. Velvet noise is emitted only if Sparsity is Velvet.
*
* @param width velvet noise width.
*/
void set_velvet_window_width(float width);
/** Set delta parameter for Velvet ARN noise.
*
* @param delta value.
*/
void set_velvet_arn_delta(float delta);
/** Set whether to crush the velvet generator.
*
* @param true to crash.
*/
void set_velvet_crush(bool crush);
/** Set the crushing probability for the velvet generator.
*
* @param crushing probability.
*/
void set_velvet_crushing_probability(float prob);
/** Set which core generator to use.
*
* @param core core generator specification.
*/
void set_generator(ng_generator_t core);
/** Set the noise color.
*
* @param noise color specification.
*/
void set_noise_color(ng_color_t color);
/** Set the coloring filter order.
*
* @param order order.
*/
void set_coloring_order(size_t order);
/** Set the color slope.
*
* @param slope slope.
* çparam unit slope unit
*/
void set_color_slope(float slope, stlt_slope_unit_t unit);
/** Set the noise amplitude.
*
* @param amplitude noise amplitude.
*/
void set_amplitude(float amplitude);
/** Set the noise offset.
*
* @param offset noise offset.
*/
void set_offset(float offset);
/** Output noise to the destination buffer in additive mode
*
* @param dst output wave destination
* @param src input source, allowed to be NULL
* @param count number of samples to synthesise
*/
void process_add(float *dst, const float *src, size_t count);
/** Output noise to the destination buffer in multiplicative mode
*
* @param dst output wave destination
* @param src input source, allowed to be NULL
* @param count number of samples to process
*/
void process_mul(float *dst, const float *src, size_t count);
/** Output noise to a destination buffer overwriting its content
*
* @param dst output wave destination
* @param src input source, allowed to be NULLL
* @param count number of samples to process
*/
void process_overwrite(float *dst, size_t count);
/**
* Get frequency chart of the colouring filter
* @param re real part of the frequency chart
* @param im imaginary part of the frequency chart
* @param f frequencies to calculate value
* @param count number of dots for the chart
*/
void freq_chart(float *re, float *im, const float *f, size_t count);
/**
* Get frequency chart of the whole equalizer
* @param c complex numbers that contain the filter transfer function
* @param f frequencies to calculate filter transfer function
* @param count number of points
*/
void freq_chart(float *c, const float *f, size_t count);
/**
* Dump the state
* @param dumper dumper
*/
void dump(IStateDumper *v) const;
};
}
}
#endif /* LSP_PLUG_IN_DSP_UNITS_NOISE_GENERATOR_H_ */
|