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
|
/*
* 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: 27 Jun 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_VELVET_H_
#define LSP_PLUG_IN_DSP_UNITS_NOISE_VELVET_H_
#include <lsp-plug.in/dsp-units/util/Randomizer.h>
#include <lsp-plug.in/dsp-units/noise/MLS.h>
#include <lsp-plug.in/dsp-units/iface/IStateDumper.h>
namespace lsp
{
namespace dspu
{
enum vn_core_t
{
VN_CORE_MLS, // Only compatible with OVN, OVNA and ARN (not crushed)
VN_CORE_LCG,
VN_CORE_MAX
};
enum vn_velvet_type_t
{
VN_VELVET_OVN,
VN_VELVET_OVNA,
VN_VELVET_ARN,
VN_VELVET_TRN,
VN_VELVET_MAX
};
/** As in GENERALIZATIONS OF VELVET NOISE AND THEIR USE IN 1-BIT MUSIC by Kurt James Werner
* Link: https://dafx2019.bcu.ac.uk/papers/DAFx2019_paper_53.pdf
* Archive: https://web.archive.org/web/20210711144324/https://dafx2019.bcu.ac.uk/papers/DAFx2019_paper_53.pdf
*
* Modified to use MLS samples for OVN, OVNA and ARN (not crushed).
*/
class LSP_DSP_UNITS_PUBLIC Velvet
{
private:
Velvet & operator = (const Velvet &);
Velvet(const Velvet &);
protected:
typedef struct crush_t
{
bool bCrush;
float fCrushProb;
} crush_t;
private:
Randomizer sRandomizer;
MLS sMLS;
vn_core_t enCore;
vn_velvet_type_t enVelvetType;
crush_t sCrushParams;
float fWindowWidth;
float fARNdelta;
float fAmplitude;
float fOffset;
public:
explicit Velvet();
~Velvet();
void construct();
void destroy();
protected:
/** Get a random value in [0, 1) using the Randomizer.
*
*/
float get_random_value();
/** Get a random spike in [-1, 1] using the core generator.
*
*/
float get_spike();
/** Get a crushed spike in [-1, 1] using the core generator.
*
*/
float get_crushed_spike();
void do_process(float *dst, size_t count);
public:
/** Initialise the velvet generator.
*
* @param seed seed for the generator.
*/
void init(uint32_t randseed, uint8_t mlsnbits, MLS::mls_t mlsseed);
/** Initialise the velvet generator with defaults:
*
* Time as seed for randomizer, Max size and max seed for the MLS.
*/
void init();
/** Set the core generator for velvet noise.
*
* @param core generator for the random sequence.
*/
void set_core_type(vn_core_t core);
/** Set the type of the velvet noise.
*
* @param type velvet noise type.
*/
void set_velvet_type(vn_velvet_type_t type);
/** Set velvet noise window width in samples.
*
* @param width velvet noise width.
*/
void set_velvet_window_width(float width);
/** Set delta value for ARN generator.
*
* @param delta delta value.
*/
void set_delta_value(float delta);
/** Set the velvet noise amplitude.
*
* @param amplitude noise amplitude.
*/
void set_amplitude(float amplitude);
/** Set the velvet noise offset.
*
* @param offset noise offset.
*/
void set_offset(float offset);
/** Set whether to produce crushed noise.
*
* @param crush true to activate crushed noise.
*/
void set_crush(bool crush);
/** Set the crushing probability.
*
* @param prob crushing probability.
*/
void set_crush_probability(float prob);
/** Output velvet 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 velvet 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 velvet 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);
/**
* Dump the state
* @param dumper dumper
*/
void dump(IStateDumper *v) const;
};
}
}
#endif /* LSP_PLUG_IN_DSP_UNITS_NOISE_VELVET_H_ */
|