Added comments, removed unnecessary detuneWithOctaves function.

This commit is contained in:
root
2019-08-29 20:44:49 -06:00
parent a630f32f21
commit 2fce224480
4 changed files with 15 additions and 11 deletions

View File

@@ -52,6 +52,7 @@ DisintegratorEffect::DisintegratorEffect(Model* parent, const Descriptor::SubPlu
Effect(&disintegrator_plugin_descriptor, parent, key),
m_disintegratorControls(this)
{
// Fill buffer with 200 samples
for (int a = 0; a < 200; ++a)
{
for (int b = 0; b < 2; ++b)
@@ -102,17 +103,22 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
sample_t s[2] = {buf[f][0], buf[f][1]};
// Increment buffer read point
++m_inBufLoc;
if (m_inBufLoc >= 200)
{
m_inBufLoc = 0;
}
// Write dry input to buffer
m_inBuf[0][m_inBufLoc] = s[0];
m_inBuf[1][m_inBufLoc] = s[1];
float newInBufLoc[2] = {0, 0};
float newInBufLocFrac[2] = {0, 0};
// Generate white noise or sine wave, apply filters, subtract the
// result from the buffer read point and store in a variable.
switch (type)
{
case 0:// Mono Noise
@@ -125,6 +131,7 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
newInBufLoc[0] = realfmod(m_inBufLoc - newInBufLoc[0] * amount, 200);
newInBufLoc[1] = newInBufLoc[0];
// Distance between samples
newInBufLocFrac[0] = fmod(newInBufLoc[0], 1);
newInBufLocFrac[1] = newInBufLocFrac[0];
@@ -143,6 +150,7 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
newInBufLoc[0] = realfmod(m_inBufLoc - newInBufLoc[0] * amount, 200);
newInBufLoc[1] = realfmod(m_inBufLoc - newInBufLoc[1] * amount, 200);
// Distance between samples
newInBufLocFrac[0] = fmod(newInBufLoc[0], 1);
newInBufLocFrac[1] = fmod(newInBufLoc[1], 1);
@@ -157,6 +165,7 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
newInBufLoc[0] = realfmod(m_inBufLoc - newInBufLoc[0] * amount, 200);
newInBufLoc[1] = newInBufLoc[0];
// Distance between samples
newInBufLocFrac[0] = fmod(newInBufLoc[0], 1);
newInBufLocFrac[1] = newInBufLocFrac[0];
@@ -176,7 +185,7 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
{
s[b] = m_inBuf[b][floor(newInBufLoc[b])] * (1 - newInBufLocFrac[b]) + m_inBuf[b][ceil(newInBufLoc[b])] * newInBufLocFrac[b];
}
else
else// For when the interpolation wraps around to the beginning of the buffer
{
s[b] = m_inBuf[b][199] * (1 - newInBufLocFrac[b]) + m_inBuf[b][0] * newInBufLocFrac[b];
}
@@ -196,6 +205,7 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
inline void DisintegratorEffect::calcLowpassFilter(sample_t &outSamp, sample_t inSamp, int which, float lpCutoff, float resonance, sample_rate_t Fs)
{
// "if" statement is here so the filter coefficients only need to be calculated when they change
if (m_prevLPCutoff[which] != lpCutoff)
{
m_prevLPCutoff[which] = lpCutoff;
@@ -224,6 +234,7 @@ inline void DisintegratorEffect::calcLowpassFilter(sample_t &outSamp, sample_t i
inline void DisintegratorEffect::calcHighpassFilter(sample_t &outSamp, sample_t inSamp, int which, float hpCutoff, float resonance, sample_rate_t Fs)
{
// "if" statement is here so the filter coefficients only need to be calculated when they change
if (m_prevHPCutoff[which] != hpCutoff)
{
m_prevHPCutoff[which] = hpCutoff;
@@ -250,14 +261,6 @@ inline void DisintegratorEffect::calcHighpassFilter(sample_t &outSamp, sample_t
// Takes input of original Hz and the number of cents to detune it by, and returns the detuned result in Hz.
inline float DisintegratorEffect::detuneWithOctaves(float pitchValue, float detuneValue)
{
return pitchValue * std::exp2(detuneValue);
}
// Handles negative values properly, unlike fmod.
inline float DisintegratorEffect::realfmod(float k, float n)
{

View File

@@ -44,7 +44,6 @@ public:
}
inline float realfmod(float k, float n);
inline float detuneWithOctaves(float pitchValue, float detuneValue);
inline void calcLowpassFilter(sample_t &outSamp, sample_t inSamp, int which, float lpCutoff, float resonance, sample_rate_t Fs);
inline void calcHighpassFilter(sample_t &outSamp, sample_t inSamp, int which, float lpCutoff, float resonance, sample_rate_t Fs);

View File

@@ -79,7 +79,8 @@ DisintegratorControlDialog::DisintegratorControlDialog(DisintegratorControls* co
}
/* Switches between the lowcut/highcut and
frequency knobs depending on the modulation type. */
void DisintegratorControlDialog::updateKnobVisibility()
{
if (m_controls->m_typeModel.value() == 2)

View File

@@ -41,6 +41,7 @@ DisintegratorControls::DisintegratorControls(DisintegratorEffect* effect) :
m_typeModel(this, tr("Type")),
m_freqModel(100.0f, 2.0f, 21050.0f, 0.01f, this, tr("Frequency"))
{
// All of these are much easier to tweak when logarithmic
m_lowCutModel.setScaleLogarithmic(true);
m_highCutModel.setScaleLogarithmic(true);
m_amountModel.setScaleLogarithmic(true);