Skip to content

Commit

Permalink
Use the gaussian filter table for the chorus effect
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Feb 14, 2024
1 parent 9c6516e commit 5c5da9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
29 changes: 18 additions & 11 deletions alc/effects/chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,30 @@

#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <limits>
#include <variant>
#include <vector>

#include "alc/effects/base.h"
#include "almalloc.h"
#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/ambidefs.h"
#include "core/bufferline.h"
#include "core/context.h"
#include "core/devformat.h"
#include "core/cubic_tables.h"
#include "core/device.h"
#include "core/effects/base.h"
#include "core/effectslot.h"
#include "core/mixer.h"
#include "core/mixer/defs.h"
#include "core/resampler_limits.h"
#include "intrusive_ptr.h"
#include "opthelpers.h"

struct BufferStorage;

namespace {

Expand Down Expand Up @@ -300,16 +303,20 @@ void ChorusState::process(const size_t samplesToDo, const al::span<const FloatBu
delaybuf[offset&bufmask] = samplesIn[0][i];

// Tap for the left output.
uint delay{offset - (ldelays[i]>>MixerFracBits)};
float mu{static_cast<float>(ldelays[i]&MixerFracMask) * (1.0f/MixerFracOne)};
lbuffer[i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask],
delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu);
size_t delay{offset - (ldelays[i]>>MixerFracBits)};
size_t phase{(ldelays[i]>>(MixerFracBits-gCubicTable.sTableBits))&gCubicTable.sTableMask};
lbuffer[i] = delaybuf[(delay+1) & bufmask]*gCubicTable.getCoeff0(phase) +
delaybuf[(delay ) & bufmask]*gCubicTable.getCoeff1(phase) +
delaybuf[(delay-1) & bufmask]*gCubicTable.getCoeff2(phase) +
delaybuf[(delay-2) & bufmask]*gCubicTable.getCoeff3(phase);

// Tap for the right output.
delay = offset - (rdelays[i]>>MixerFracBits);
mu = static_cast<float>(rdelays[i]&MixerFracMask) * (1.0f/MixerFracOne);
rbuffer[i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask],
delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu);
phase = (rdelays[i]>>(MixerFracBits-gCubicTable.sTableBits))&gCubicTable.sTableMask;
rbuffer[i] = delaybuf[(delay+1) & bufmask]*gCubicTable.getCoeff0(phase) +
delaybuf[(delay ) & bufmask]*gCubicTable.getCoeff1(phase) +
delaybuf[(delay-1) & bufmask]*gCubicTable.getCoeff2(phase) +
delaybuf[(delay-2) & bufmask]*gCubicTable.getCoeff3(phase);

// Accumulate feedback from the average delay of the taps.
delaybuf[offset&bufmask] += delaybuf[(offset-avgdelay) & bufmask] * feedback;
Expand Down
10 changes: 0 additions & 10 deletions common/alnumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ constexpr auto GetCounterSuffix(size_t count) noexcept -> const char*

constexpr inline float lerpf(float val1, float val2, float mu) noexcept
{ return val1 + (val2-val1)*mu; }
constexpr inline float cubic(float val1, float val2, float val3, float val4, float mu) noexcept
{
const float mu2{mu*mu}, mu3{mu2*mu};
const float a0{-0.5f*mu3 + mu2 + -0.5f*mu};
const float a1{ 1.5f*mu3 + -2.5f*mu2 + 1.0f};
const float a2{-1.5f*mu3 + 2.0f*mu2 + 0.5f*mu};
const float a3{ 0.5f*mu3 + -0.5f*mu2};
return val1*a0 + val2*a1 + val3*a2 + val4*a3;
}

constexpr inline double lerpd(double val1, double val2, double mu) noexcept
{ return val1 + (val2-val1)*mu; }

Expand Down

0 comments on commit 5c5da9e

Please sign in to comment.