MCPcopy Create free account
hub / github.com/Signalsmith-Audio/reverb-example-code / DiffusionStep

Class DiffusionStep

reverb-example-code.h:116–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115template<int channels=8>
116struct DiffusionStep {
117 using Array = std::array<double, channels>;
118 double delayMsRange = 50;
119
120 std::array<int, channels> delaySamples;
121 std::array<Delay, channels> delays;
122 std::array<bool, channels> flipPolarity;
123
124 void configure(double sampleRate) {
125 double delaySamplesRange = delayMsRange*0.001*sampleRate;
126 for (int c = 0; c < channels; ++c) {
127 double rangeLow = delaySamplesRange*c/channels;
128 double rangeHigh = delaySamplesRange*(c + 1)/channels;
129 delaySamples[c] = randomInRange(rangeLow, rangeHigh);
130 delays[c].resize(delaySamples[c] + 1);
131 delays[c].reset();
132 flipPolarity[c] = rand()%2;
133 }
134 }
135
136 Array process(Array input) {
137 // Delay
138 Array delayed;
139 for (int c = 0; c < channels; ++c) {
140 delays[c].write(input[c]);
141 delayed[c] = delays[c].read(delaySamples[c]);
142 }
143
144 // Mix with a Hadamard matrix
145 Array mixed = delayed;
146 Hadamard<double, channels>::inPlace(mixed.data());
147
148 // Flip some polarities
149 for (int c = 0; c < channels; ++c) {
150 if (flipPolarity[c]) mixed[c] *= -1;
151 }
152
153 return mixed;
154 }
155};
156
157template<int channels=8, int stepCount=4>
158struct DiffuserEqualLengths {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected