Skip to content

Commit

Permalink
remove some of the 44.1 kHz dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hollance committed May 2, 2024
1 parent c1ba43e commit 54527f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
12 changes: 7 additions & 5 deletions Source/AudioProcessing/Biquads.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#pragma once

#define MAX_CHANNELS 2

class Biquads
{
public:
Biquads() : a0(0.0f), a1(0.0f), a2(0.0f), b1(0.0f), b2(0.0f), c0(0.0f), d0(0.0f), isModifiedBiquad(false)
{
}

void prepareToPlay(float sampleRate) noexcept
void prepareToPlay(float newSampleRate) noexcept
{
// TODO: don't hardcode the SAMPLE_RATE!
sampleRate = newSampleRate;
}

void reset() noexcept
Expand Down Expand Up @@ -55,7 +53,7 @@ class Biquads
c0 = 1.0f;
d0 = 0.0f;

float theta = fc * PI / SAMPLE_RATE;
float theta = fc * PI / sampleRate;
if (theta >= 0.49f * PI) {
theta = 0.49f * PI;
}
Expand Down Expand Up @@ -84,6 +82,10 @@ class Biquads
}

private:
static constexpr int MAX_CHANNELS = 2;

float sampleRate;

// Filter state:
float priorIn_2[MAX_CHANNELS]; // x[n - 2]
float priorIn_1[MAX_CHANNELS]; // x[n - 1]
Expand Down
3 changes: 3 additions & 0 deletions Source/AudioProcessing/Granulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "Granulate.h"
#include <cmath>

// TODO: make independent of SAMPLE_RATE
#define SAMPLE_RATE 44100

Granulate::Granulate(unsigned int nVoices, const char* data, int size)
{
rng.setSeedRandomly();
Expand Down
2 changes: 0 additions & 2 deletions Source/AudioProcessing/Granulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
// This code was taken from STK (https://github.com/thestk/stk) and modified to
// work with JUCE. Also tweaked it a bit for readability and to silence warnings.

// TODO: make independent of SAMPLE_RATE


class Granulate
{
Expand Down
8 changes: 5 additions & 3 deletions Source/AudioProcessing/InputSaturation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class InputSaturation
evenGain = 0.3f;
}

void prepareToPlay(float sampleRate) noexcept
void prepareToPlay(float newSampleRate) noexcept
{
sampleRate = newSampleRate;
coef = 0.0f;
setFrequencyRolloff(4000.0f);
}
Expand Down Expand Up @@ -69,8 +70,7 @@ class InputSaturation
{
if (f < 0.0f) { f = 0.0f; }

// TODO: don't hardcode sample rate here!
coef = f * (2.0f * PI) / SAMPLE_RATE;
coef = f * (2.0f * PI) / sampleRate;
if (coef > 1.0f) {
coef = 1.0f;
} else if (coef < 0.0f) {
Expand Down Expand Up @@ -182,6 +182,8 @@ class InputSaturation
}

private:
float sampleRate;

float evenGain;
float oddGain;

Expand Down
3 changes: 0 additions & 3 deletions Source/shameConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

#define PI 3.14159265359f

// TODO: don't hardcode the sample rate
#define SAMPLE_RATE 44100

enum EShameEnvironments
{
eEnvironmentEnvironment,
Expand Down

0 comments on commit 54527f5

Please sign in to comment.