Skip to content

Commit

Permalink
create active white noise effect with a dry/wet knob
Browse files Browse the repository at this point in the history
  • Loading branch information
katsar0v committed Jul 10, 2020
1 parent d00aa15 commit 18b18ae
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/effects/builtin/linkwitzriley8eqeffect.cpp
src/effects/builtin/loudnesscontoureffect.cpp
src/effects/builtin/metronomeeffect.cpp
src/effects/builtin/whitenoiseeffect.cpp
src/effects/builtin/moogladder4filtereffect.cpp
src/effects/builtin/parametriceqeffect.cpp
src/effects/builtin/phasereffect.cpp
Expand Down
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ def sources(self, build):
"src/effects/builtin/autopaneffect.cpp",
"src/effects/builtin/phasereffect.cpp",
"src/effects/builtin/metronomeeffect.cpp",
"src/effects/builtin/whitenoiseeffect.cpp",
"src/effects/builtin/tremoloeffect.cpp",

"src/engine/effects/engineeffectsmanager.cpp",
Expand Down
6 changes: 4 additions & 2 deletions src/effects/builtin/builtinbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef __MACAPPSTORE__
#include "effects/builtin/reverbeffect.h"
#endif
#include "effects/builtin/echoeffect.h"
#include "effects/builtin/autopaneffect.h"
#include "effects/builtin/phasereffect.h"
#include "effects/builtin/echoeffect.h"
#include "effects/builtin/loudnesscontoureffect.h"
#include "effects/builtin/metronomeeffect.h"
#include "effects/builtin/phasereffect.h"
#include "effects/builtin/tremoloeffect.h"
#include "effects/builtin/whitenoiseeffect.h"

BuiltInBackend::BuiltInBackend(QObject* pParent)
: EffectsBackend(pParent, EffectBackendType::BuiltIn) {
Expand Down Expand Up @@ -51,6 +52,7 @@ BuiltInBackend::BuiltInBackend(QObject* pParent)
#endif
registerEffect<PhaserEffect>();
registerEffect<MetronomeEffect>();
registerEffect<WhiteNoiseEffect>();
registerEffect<TremoloEffect>();
}

Expand Down
80 changes: 80 additions & 0 deletions src/effects/builtin/whitenoiseeffect.cpp
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;
}
}
51 changes: 51 additions & 0 deletions src/effects/builtin/whitenoiseeffect.h
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);
};

0 comments on commit 18b18ae

Please sign in to comment.