-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWavShaper.h
89 lines (75 loc) · 1.91 KB
/
WavShaper.h
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
#pragma once
#include "AudioFile.h"
#include "IPlugUtilities.h"
#include "IPlug_include_in_plug_hdr.h"
#include <cstdlib>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <algorithm>
using std::vector;
const static int MAX_SHAPE_SAMPLES = 4800; // Samples in 1 period (4800 = 20Hz @ 96k or 10Hz @ 48k)
const static double HALF_SHAPE_SAMPLES = MAX_SHAPE_SAMPLES / 2;
const static double SHAPE_SAMPLE_SCALE = 1.0 / (MAX_SHAPE_SAMPLES);
const int kNumPresets = 1;
enum EParams
{
kGainI = 0,
kGainO = 1,
kEnable = 2,
kFade = 3,
kOffset = 4,
kRotation = 5,
kOptimize = 6,
kCenter = 7,
kBank = 8,
kNumParams
};
using namespace iplug;
using namespace igraphics;
namespace fs = std::filesystem;
struct shapeTarget
{
float samplesL[MAX_SHAPE_SAMPLES] = {0.};
float samplesR[MAX_SHAPE_SAMPLES] = {0.};
std::string name = "((init))";
bool init = true;
};
struct shapeTargetV2
{
vector<float> left;
vector<float> right;
std::string name = "((init))";
int nBanks = 0;
bool init = true;
};
template <class type>
type lerp(type a, type b, double t)
{
return a + (b - a) * t;
}
class WavShaper final : public Plugin
{
public:
WavShaper(const InstanceInfo& info);
bool SerializeState(IByteChunk& chunk) const override;
int UnserializeState(const IByteChunk& chunk, int startPos) override;
void DoPreset(const char* name);
void loadShape(const char* name);
#if IPLUG_DSP // http://bit.ly/2S64BDd
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
#endif
private:
double multiplier = 0.0;
sample last;
int lastBank;
shapeTargetV2 targets;
sample doShapingL(sample in);
sample doShapingR(sample in);
int findInSampleSet(sample in);
void updateUI();
void loadShape(int num, bool reinit);
void loadShape();
void copyToPluginDir(fs::path src);
void optimizeShape();
};