-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create active white noise effect with a dry/wet knob
- Loading branch information
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "effects/builtin/whitenoiseeffect.h" | ||
|
||
#include "util/rampingvalue.h" | ||
|
||
namespace { | ||
const QString dryWetParameterId = QStringLiteral("dry_wet"); | ||
} // anonymous namespace | ||
|
||
// static | ||
QString WhiteNoiseEffect::getId() { | ||
return QStringLiteral("org.mixxx.effects.whitenoise"); | ||
} | ||
|
||
// static | ||
EffectManifestPointer WhiteNoiseEffect::getManifest() { | ||
EffectManifestPointer pManifest(new EffectManifest()); | ||
pManifest->setId(getId()); | ||
pManifest->setName(QObject::tr("White Noise")); | ||
pManifest->setAuthor("The Mixxx Team"); | ||
pManifest->setVersion("1.0"); | ||
pManifest->setDescription(QObject::tr("Mix white noise with the input signal")); | ||
pManifest->setEffectRampsFromDry(true); | ||
|
||
// This is dry/wet parameter | ||
EffectManifestParameterPointer intensity = pManifest->addParameter(); | ||
intensity->setId(dryWetParameterId); | ||
intensity->setName(QObject::tr("Dry/Wet")); | ||
intensity->setDescription(QObject::tr("Crossfade the noise with the dry signal")); | ||
intensity->setControlHint(EffectManifestParameter::ControlHint::KNOB_LOGARITHMIC); | ||
intensity->setSemanticHint(EffectManifestParameter::SemanticHint::UNKNOWN); | ||
intensity->setUnitsHint(EffectManifestParameter::UnitsHint::UNKNOWN); | ||
intensity->setDefaultLinkType(EffectManifestParameter::LinkType::LINKED); | ||
intensity->setMinimum(0); | ||
intensity->setDefault(0); | ||
intensity->setMaximum(1); | ||
|
||
return pManifest; | ||
} | ||
|
||
WhiteNoiseEffect::WhiteNoiseEffect(EngineEffect* pEffect) | ||
: m_pDryWetParameter(pEffect->getParameterById(dryWetParameterId)) { | ||
} | ||
|
||
WhiteNoiseEffect::~WhiteNoiseEffect() { | ||
} | ||
|
||
void WhiteNoiseEffect::processChannel( | ||
const ChannelHandle& handle, | ||
WhiteNoiseGroupState* pGroupState, | ||
const CSAMPLE* pInput, | ||
CSAMPLE* pOutput, | ||
const mixxx::EngineParameters& bufferParameters, | ||
const EffectEnableState enableState, | ||
const GroupFeatureState& groupFeatures) { | ||
Q_UNUSED(handle); | ||
Q_UNUSED(groupFeatures); | ||
|
||
WhiteNoiseGroupState& gs = *pGroupState; | ||
|
||
CSAMPLE drywet = m_pDryWetParameter->value(); | ||
RampingValue<CSAMPLE_GAIN> drywet_ramping_value( | ||
drywet, gs.previous_drywet, bufferParameters.framesPerBuffer()); | ||
|
||
std::uniform_real_distribution<> r_distributor(0.0, 1.0); | ||
|
||
for (unsigned int i = 0; i < bufferParameters.samplesPerBuffer(); i++) { | ||
CSAMPLE_GAIN drywet_ramped = drywet_ramping_value.getNext(); | ||
|
||
float noise = static_cast<float>( | ||
r_distributor(gs.gen)); | ||
|
||
pOutput[i] = pInput[i] * (1 - drywet_ramped) + noise * drywet_ramped; | ||
} | ||
|
||
if (enableState == EffectEnableState::Disabling) { | ||
gs.previous_drywet = 0; | ||
} else { | ||
gs.previous_drywet = drywet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <random> | ||
|
||
#include "effects/effectprocessor.h" | ||
#include "engine/effects/engineeffect.h" | ||
#include "engine/effects/engineeffectparameter.h" | ||
#include "engine/filters/enginefilterpansingle.h" | ||
#include "util/class.h" | ||
#include "util/defs.h" | ||
#include "util/sample.h" | ||
#include "util/samplebuffer.h" | ||
#include "util/types.h" | ||
|
||
class WhiteNoiseGroupState final : public EffectState { | ||
public: | ||
WhiteNoiseGroupState(const mixxx::EngineParameters& bufferParameters) | ||
: EffectState(bufferParameters), | ||
previous_drywet(0.0), | ||
gen(rs()) { | ||
} | ||
~WhiteNoiseGroupState() { | ||
} | ||
|
||
CSAMPLE_GAIN previous_drywet; | ||
std::random_device rs; | ||
std::mt19937 gen; | ||
}; | ||
|
||
class WhiteNoiseEffect : public EffectProcessorImpl<WhiteNoiseGroupState> { | ||
public: | ||
WhiteNoiseEffect(EngineEffect* pEffect); | ||
virtual ~WhiteNoiseEffect(); | ||
|
||
static QString getId(); | ||
static EffectManifestPointer getManifest(); | ||
|
||
// See effectprocessor.h | ||
void processChannel(const ChannelHandle& handle, | ||
WhiteNoiseGroupState* pState, | ||
const CSAMPLE* pInput, | ||
CSAMPLE* pOutput, | ||
const mixxx::EngineParameters& bufferParameters, | ||
const EffectEnableState enableState, | ||
const GroupFeatureState& groupFeatures); | ||
|
||
private: | ||
EngineEffectParameter* m_pDryWetParameter; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(WhiteNoiseEffect); | ||
}; |