added feedback
This commit is contained in:
+83
-36
@@ -5,29 +5,62 @@
|
||||
#include <delay/buffer_multi.hpp>
|
||||
#include <common/mix.hpp>
|
||||
|
||||
template<typename T, size_t numCh>
|
||||
class Delay
|
||||
{
|
||||
dsp::BufferMulti<T, numCh> m_buf;
|
||||
int m_delay_spec[numCh];
|
||||
|
||||
public:
|
||||
Delay(uint maxDelaySize, int delayOffset=0)
|
||||
: m_buf(maxDelaySize)
|
||||
{
|
||||
float delayRagePerWindow = (float)(maxDelaySize-delayOffset)/(float)numCh;
|
||||
|
||||
// Delay spec
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
float base_delay = i*delayRagePerWindow + delayOffset;
|
||||
float z = (float)rand()/(float)RAND_MAX;
|
||||
int delay = (int)(base_delay + z*delayRagePerWindow);
|
||||
|
||||
m_delay_spec[i] = -delay;
|
||||
}
|
||||
}
|
||||
|
||||
void process(T in, T out[numCh])
|
||||
{
|
||||
m_buf = in;
|
||||
m_buf.quer(out, m_delay_spec);
|
||||
++m_buf;
|
||||
}
|
||||
|
||||
void process(T data[numCh])
|
||||
{
|
||||
m_buf = data;
|
||||
m_buf.quer(data, m_delay_spec);
|
||||
++m_buf;
|
||||
}
|
||||
|
||||
void process(T in[numCh], T out[numCh])
|
||||
{
|
||||
m_buf = in;
|
||||
m_buf.quer(out, m_delay_spec);
|
||||
++m_buf;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T, size_t numCh>
|
||||
class Diffusor
|
||||
{
|
||||
dsp::BufferMulti<T, numCh> m_dly;
|
||||
int m_delay_spec[numCh];
|
||||
Delay<T, numCh> m_dly;
|
||||
int m_shuffle_spec[numCh];
|
||||
|
||||
public:
|
||||
Diffusor(uint maxDelaySize)
|
||||
: m_dly(maxDelaySize)
|
||||
{
|
||||
float delayRagePerWindow = (float)maxDelaySize/(float)numCh;
|
||||
|
||||
// Delay spec
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
float base_delay = i*delayRagePerWindow;
|
||||
float z = (float)rand()/(float)RAND_MAX;
|
||||
int delay = (int)(base_delay + z*delayRagePerWindow);
|
||||
|
||||
m_delay_spec[i] = -delay;
|
||||
}
|
||||
|
||||
// Shuffle spec
|
||||
for (int i=0; i < numCh; i++)
|
||||
{
|
||||
@@ -58,27 +91,22 @@ class Diffusor
|
||||
|
||||
inline T process(T in)
|
||||
{
|
||||
m_dly = in;
|
||||
T temp[numCh];
|
||||
m_dly.process(in, temp);
|
||||
|
||||
T qbuf[numCh];
|
||||
m_dly.quer(qbuf, m_delay_spec);
|
||||
++m_dly;
|
||||
Shuffle<T, numCh>::inPlace(temp, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(temp);
|
||||
Householder<T, numCh>::inPlace(temp);
|
||||
|
||||
Shuffle<T, numCh>::inPlace(qbuf, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(qbuf);
|
||||
Householder<T, numCh>::inPlace(qbuf);
|
||||
|
||||
return qbuf[0];
|
||||
return temp[0];
|
||||
}
|
||||
|
||||
inline void process_multi(T data[numCh])
|
||||
inline void process_multi(T in_out[numCh])
|
||||
{
|
||||
m_dly = data;
|
||||
m_dly.quer(data, m_delay_spec);
|
||||
++m_dly;
|
||||
m_dly.process(in_out);
|
||||
|
||||
Shuffle<T, numCh>::inPlace(data, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(data);
|
||||
Shuffle<T, numCh>::inPlace(in_out, m_shuffle_spec);
|
||||
Hadamard<T, numCh>::inPlace(in_out);
|
||||
}
|
||||
|
||||
static inline void split(T in, T out[numCh])
|
||||
@@ -89,10 +117,10 @@ class Diffusor
|
||||
}
|
||||
}
|
||||
|
||||
static inline T combine(T data[numCh])
|
||||
static inline T combine(T in_out[numCh])
|
||||
{
|
||||
Householder<T, numCh>::inPlace(data);
|
||||
return data[0];
|
||||
Householder<T, numCh>::inPlace(in_out);
|
||||
return in_out[0];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -100,14 +128,18 @@ template<typename T, uint numCh>
|
||||
class Reverb
|
||||
{
|
||||
std::array<Diffusor<T, numCh>, 3> m_diffusors;
|
||||
dsp::BufferMulti<T, numCh> m_feedbackDly;
|
||||
Delay<T, numCh> m_feedbackDly;
|
||||
T fb_dly_out[numCh];
|
||||
|
||||
public:
|
||||
Reverb(uint maxDelay)
|
||||
: m_diffusors({maxDelay, maxDelay, maxDelay})
|
||||
, m_feedbackDly(maxDelay)
|
||||
, m_feedbackDly(9600)
|
||||
{
|
||||
|
||||
for (int c=0; c < numCh; c++)
|
||||
{
|
||||
fb_dly_out[c] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void process_multi(float *in, float *out, unsigned numPoints)
|
||||
@@ -120,7 +152,22 @@ class Reverb
|
||||
{
|
||||
diffusor.process_multi(temp);
|
||||
}
|
||||
out[i] = Diffusor<T, numCh>::combine(temp);
|
||||
// Sum
|
||||
for (int c=0; c < numCh; c++)
|
||||
{
|
||||
temp[c] += fb_dly_out[c];
|
||||
}
|
||||
m_feedbackDly.process(temp, fb_dly_out);
|
||||
|
||||
// Mix
|
||||
out[i] = fb_dly_out[0];
|
||||
|
||||
T fb_gain = 0.85;
|
||||
for (int c=0; c < numCh; c++)
|
||||
{
|
||||
fb_dly_out[c] *= fb_gain;
|
||||
}
|
||||
Householder<T, numCh>::inPlace(fb_dly_out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user