Fix stuff
This commit is contained in:
@@ -51,11 +51,9 @@ Plugin::Descriptor PLUGIN_EXPORT disintegrator_plugin_descriptor =
|
||||
DisintegratorEffect::DisintegratorEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key) :
|
||||
Effect(&disintegrator_plugin_descriptor, parent, key),
|
||||
m_disintegratorControls(this),
|
||||
m_lp(Engine::mixer()->processingSampleRate()),
|
||||
m_hp(Engine::mixer()->processingSampleRate()),
|
||||
m_needsUpdate(true)
|
||||
{
|
||||
sampleRateChanged();
|
||||
emit sampleRateChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,12 +61,13 @@ DisintegratorEffect::DisintegratorEffect(Model* parent, const Descriptor::SubPlu
|
||||
void DisintegratorEffect::sampleRateChanged()
|
||||
{
|
||||
m_sampleRate = Engine::mixer()->processingSampleRate();
|
||||
m_sampleRateMult = m_sampleRate / 44100.f;
|
||||
m_lp.setSampleRate(m_sampleRate);
|
||||
m_hp.setSampleRate(m_sampleRate);
|
||||
m_lp = new BasicFilters<2>(Engine::mixer()->processingSampleRate());
|
||||
m_hp = new BasicFilters<2>(Engine::mixer()->processingSampleRate());
|
||||
m_lp->setFilterType(0);
|
||||
m_hp->setFilterType(1);
|
||||
m_needsUpdate = true;
|
||||
|
||||
m_bufferSize = (m_sampleRate / 44100.f) * 200.f + 1.f;
|
||||
m_bufferSize = m_sampleRate * 0.01f + 1.f;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
m_inBuf[i].resize(m_bufferSize);
|
||||
@@ -93,19 +92,20 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
|
||||
const ValueBuffer * freqBuf = m_disintegratorControls.m_lowCutModel.valueBuffer();
|
||||
|
||||
// Update filters
|
||||
if (m_needsUpdate || m_disintegratorControls.m_highCutModel.isValueChanged())
|
||||
if(m_needsUpdate || m_disintegratorControls.m_highCutModel.isValueChanged())
|
||||
{
|
||||
m_lp.setLowpass(m_disintegratorControls.m_highCutModel.value());
|
||||
m_lp->calcFilterCoeffs(m_disintegratorControls.m_highCutModel.value(), 0.5);
|
||||
|
||||
}
|
||||
if (m_needsUpdate || m_disintegratorControls.m_lowCutModel.isValueChanged())
|
||||
if(m_needsUpdate || m_disintegratorControls.m_lowCutModel.isValueChanged())
|
||||
{
|
||||
m_hp.setHighpass(m_disintegratorControls.m_lowCutModel.value());
|
||||
m_hp->calcFilterCoeffs(m_disintegratorControls.m_lowCutModel.value(), 0.5);
|
||||
}
|
||||
m_needsUpdate = false;
|
||||
|
||||
for (fpp_t f = 0; f < frames; ++f)
|
||||
{
|
||||
const float amount = amountBuf ? amountBuf->value(f) : m_disintegratorControls.m_amountModel.value();
|
||||
const float amount = (amountBuf ? amountBuf->value(f) : m_disintegratorControls.m_amountModel.value()) * 0.001f * m_sampleRate;
|
||||
const int type = typeBuf ? typeBuf->value(f) : m_disintegratorControls.m_typeModel.value();
|
||||
const float freq = freqBuf ? freqBuf->value(f) : m_disintegratorControls.m_freqModel.value();
|
||||
|
||||
@@ -127,75 +127,56 @@ bool DisintegratorEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frame
|
||||
|
||||
// Generate white noise or sine wave, apply filters, subtract the
|
||||
// result from the buffer read point and store in a variable.
|
||||
sampleFrame delayModInput = {0, 0};
|
||||
switch (type)
|
||||
{
|
||||
case 0:// Mono Noise
|
||||
case 0://Mono Noise
|
||||
{
|
||||
newInBufLoc[0] = fast_rand() / (float)FAST_RAND_MAX;
|
||||
|
||||
newInBufLoc[0] = m_hp.update(newInBufLoc[0], 0);
|
||||
newInBufLoc[0] = m_lp.update(newInBufLoc[0], 0);
|
||||
|
||||
newInBufLoc[0] = realfmod(m_inBufLoc - newInBufLoc[0] * amount * m_sampleRateMult, m_bufferSize);
|
||||
newInBufLoc[1] = newInBufLoc[0];
|
||||
|
||||
// Distance between samples
|
||||
newInBufLocFrac[0] = fmod(newInBufLoc[0], 1);
|
||||
newInBufLocFrac[1] = newInBufLocFrac[0];
|
||||
|
||||
delayModInput[0] = fast_rand() / (float)FAST_RAND_MAX * 2.f - 1.f;
|
||||
delayModInput[1] = delayModInput[0];
|
||||
break;
|
||||
}
|
||||
case 1:// Stereo Noise
|
||||
case 1://Stereo Noise
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
newInBufLoc[i] = fast_rand() / (float)FAST_RAND_MAX;
|
||||
|
||||
newInBufLoc[i] = m_hp.update(newInBufLoc[i], 0);
|
||||
newInBufLoc[i] = m_lp.update(newInBufLoc[i], 0);
|
||||
|
||||
newInBufLoc[i] = realfmod(m_inBufLoc - newInBufLoc[i] * amount * m_sampleRateMult, m_bufferSize);
|
||||
|
||||
// Distance between samples
|
||||
newInBufLocFrac[i] = fmod(newInBufLoc[i], 1);
|
||||
}
|
||||
|
||||
delayModInput[0] = fast_rand() / (float)FAST_RAND_MAX * 2.f - 1.f;
|
||||
delayModInput[1] = fast_rand() / (float)FAST_RAND_MAX * 2.f - 1.f;
|
||||
break;
|
||||
}
|
||||
case 2:// Sine Wave
|
||||
case 2://Sine Wave
|
||||
{
|
||||
m_sineLoc = fmod(m_sineLoc + (freq / m_sampleRate * F_2PI), F_2PI);
|
||||
|
||||
newInBufLoc[0] = (sin(m_sineLoc) + 1) * 0.5f;
|
||||
|
||||
newInBufLoc[0] = realfmod(m_inBufLoc - newInBufLoc[0] * amount * m_sampleRateMult, m_bufferSize);
|
||||
newInBufLoc[1] = newInBufLoc[0];
|
||||
|
||||
// Distance between samples
|
||||
newInBufLocFrac[0] = fmod(newInBufLoc[0], 1);
|
||||
newInBufLocFrac[1] = newInBufLocFrac[0];
|
||||
|
||||
delayModInput[0] = sin(m_sineLoc);
|
||||
delayModInput[1] = delayModInput[0];
|
||||
break;
|
||||
}
|
||||
case 3:// Self-Modulation
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
newInBufLoc[i] = (qBound(-1.f, s[i], 1.f) + 1) * 0.5f;
|
||||
|
||||
newInBufLoc[i] = m_hp.update(newInBufLoc[i], 0);
|
||||
newInBufLoc[i] = m_lp.update(newInBufLoc[i], 0);
|
||||
|
||||
newInBufLoc[i] = realfmod(m_inBufLoc - newInBufLoc[i] * amount * m_sampleRateMult, m_bufferSize);
|
||||
|
||||
// Distance between samples
|
||||
newInBufLocFrac[i] = fmod(newInBufLoc[i], 1);
|
||||
}
|
||||
|
||||
delayModInput[0] = qBound(-1.f, s[0], 1.f);
|
||||
delayModInput[1] = qBound(-1.f, s[1], 1.f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
newInBufLoc[i] = delayModInput[i];
|
||||
|
||||
if (type != 2)// Sine mode doesn't use filters
|
||||
{
|
||||
newInBufLoc[i] = m_hp->update(newInBufLoc[i], i);
|
||||
newInBufLoc[i] = m_lp->update(newInBufLoc[i], i);
|
||||
}
|
||||
|
||||
newInBufLoc[i] = (newInBufLoc[i] + 1) * 0.5f;
|
||||
|
||||
newInBufLoc[i] = realfmod(m_inBufLoc - newInBufLoc[i] * amount, m_bufferSize);
|
||||
|
||||
// Distance between samples
|
||||
newInBufLocFrac[i] = fmod(newInBufLoc[i], 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (newInBufLocFrac[i] == 0)
|
||||
@@ -239,8 +220,8 @@ inline float DisintegratorEffect::realfmod(float k, float n)
|
||||
|
||||
void DisintegratorEffect::clearFilterHistories()
|
||||
{
|
||||
m_lp.clearHistory();
|
||||
m_hp.clearHistory();
|
||||
m_lp->clearHistory();
|
||||
m_hp->clearHistory();
|
||||
}
|
||||
|
||||
|
||||
@@ -255,3 +236,4 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main(Model* parent, void* data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -58,13 +58,13 @@ private:
|
||||
|
||||
float m_sineLoc = 0;
|
||||
|
||||
StereoLinkwitzRiley m_lp;
|
||||
StereoLinkwitzRiley m_hp;
|
||||
BasicFilters<2> * m_lp;
|
||||
BasicFilters<2> * m_hp;
|
||||
bool m_needsUpdate;
|
||||
|
||||
float m_sampleRate;
|
||||
float m_sampleRateMult;
|
||||
int m_bufferSize = 201;
|
||||
int m_bufferSize = 500;
|
||||
|
||||
friend class DisintegratorControls;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ DisintegratorControls::DisintegratorControls(DisintegratorEffect* effect) :
|
||||
m_effect(effect),
|
||||
m_lowCutModel(20.0f, 20.0f, 20000.0f, 0.01f, this, tr("Low Cut Frequency")),
|
||||
m_highCutModel(20000.0f, 20.0f, 20000.0f, 0.01f, this, tr("High Cut Frequency")),
|
||||
m_amountModel(30.0f, 0.0f, 200.0f, 0.01f, this, tr("Amount")),
|
||||
m_amountModel(1.6f, 0.0f, 10.0f, 0.001f, this, tr("Amount")),
|
||||
m_typeModel(this, tr("Type")),
|
||||
m_freqModel(100.0f, 1.0f, 21050.0f, 0.01f, this, tr("Frequency"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user