Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NAM/wavenet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void wavenet::_Layer::process_(const Eigen::MatrixXf &input,
// Mix-in condition
this->_z += this->_input_mixin.process(condition);
if (this->_activation == "Hardtanh")
hard_tanh_(this->_z);
hard_tanh_(this->_z);
else if (this->_activation == "Tanh")
tanh_(this->_z);
else if (this->_activation == "ReLU")
Expand Down
13 changes: 6 additions & 7 deletions dsp/ImpulseResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@

#include "ImpulseResponse.h"

dsp::ImpulseResponse::ImpulseResponse(const WDL_String &fileName,
dsp::ImpulseResponse::ImpulseResponse(const char* fileName,
const double sampleRate)
: mWavState(dsp::wav::LoadReturnCode::ERROR_OTHER) {
// Try to load the WAV
this->mWavState =
dsp::wav::Load(fileName, this->mRawAudio, this->mRawAudioSampleRate);
this->mWavState = dsp::wav::Load(fileName, this->mRawAudio,
this->mRawAudioSampleRate);
if (this->mWavState != dsp::wav::LoadReturnCode::SUCCESS) {
std::stringstream ss;
ss << "Failed to load IR at " << fileName.Get() << std::endl;
ss << "Failed to load IR at " << fileName << std::endl;
} else
// Set the weights based on the raw audio.
this->_SetWeights(sampleRate);
}

iplug::sample **dsp::ImpulseResponse::Process(iplug::sample **inputs,
const size_t numChannels,
const size_t numFrames) {
double **dsp::ImpulseResponse::Process(double **inputs, const size_t numChannels,
const size_t numFrames) {
this->_PrepareBuffers(numChannels, numFrames);
this->_UpdateHistory(inputs, numChannels, numFrames);

Expand Down
13 changes: 4 additions & 9 deletions dsp/ImpulseResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@
//
// Impulse response processing

#ifndef ImpulseResponse_h
#define ImpulseResponse_h
#pragma once

#include <filesystem>

#include <Eigen/Dense>

#include "IPlugConstants.h" // sample
#include "dsp.h"
#include "wav.h"
#include "wdlstring.h" // WDL_String

namespace dsp {
class ImpulseResponse : public History {
public:
ImpulseResponse(const WDL_String &fileName, const double sampleRate);
iplug::sample **Process(iplug::sample **inputs, const size_t numChannels,
const size_t numFrames) override;
ImpulseResponse(const char* fileName, const double sampleRate);
double **Process(double **inputs, const size_t numChannels,
const size_t numFrames) override;
// TODO states for the IR class
dsp::wav::LoadReturnCode GetWavState() const { return this->mWavState; };

Expand All @@ -45,5 +42,3 @@ class ImpulseResponse : public History {
Eigen::VectorXf mWeight;
};
}; // namespace dsp

#endif /* ImpulseResponse_h */
14 changes: 6 additions & 8 deletions dsp/NoiseGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ dsp::noise_gate::Trigger::Trigger()

double signum(const double val) { return (0.0 < val) - (val < 0.0); }

iplug::sample **dsp::noise_gate::Trigger::Process(iplug::sample **inputs,
const size_t numChannels,
const size_t numFrames) {
double **dsp::noise_gate::Trigger::Process(double **inputs,
const size_t numChannels,
const size_t numFrames) {
this->_PrepareBuffers(numChannels, numFrames);

// A bunch of numbers we'll use a few times.
Expand Down Expand Up @@ -87,8 +87,7 @@ iplug::sample **dsp::noise_gate::Trigger::Process(iplug::sample **inputs,

// Copy input to output
for (auto c = 0; c < numChannels; c++)
memcpy(this->mOutputs[c].data(), inputs[c],
numFrames * sizeof(iplug::sample));
memcpy(this->mOutputs[c].data(), inputs[c], numFrames * sizeof(double));
return this->_GetPointers();
}

Expand Down Expand Up @@ -129,9 +128,8 @@ void dsp::noise_gate::Trigger::_PrepareBuffers(const size_t numChannels,

// Gain========================================================================

iplug::sample **dsp::noise_gate::Gain::Process(iplug::sample **inputs,
const size_t numChannels,
const size_t numFrames) {
double **dsp::noise_gate::Gain::Process(double **inputs, const size_t numChannels,
const size_t numFrames) {
// Assume that SetGainReductionDB() was just called to get data from a
// trigger. Could use listeners...
this->_PrepareBuffers(numChannels, numFrames);
Expand Down
15 changes: 6 additions & 9 deletions dsp/NoiseGate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// Created by Steven Atkinson on 2/5/23.
//

#ifndef NoiseGate_h
#define NoiseGate_h
#pragma once

#include <cmath>
#include <unordered_set>
Expand All @@ -33,8 +32,8 @@ const double MINIMUM_LOUDNESS_POWER = pow(10.0, MINIMUM_LOUDNESS_DB / 10.0);
// The class that applies the gain reductions calculated by a trigger instance.
class Gain : public DSP {
public:
iplug::sample **Process(iplug::sample **inputs, const size_t numChannels,
const size_t numFrames) override;
double **Process(double **inputs, const size_t numChannels,
const size_t numFrames) override;

void SetGainReductionDB(std::vector<std::vector<double>> &gainReductionDB) {
this->mGainReductionDB = gainReductionDB;
Expand Down Expand Up @@ -82,8 +81,8 @@ class Trigger : public DSP {
public:
Trigger();

iplug::sample **Process(iplug::sample **inputs, const size_t numChannels,
const size_t numFrames) override;
double **Process(double **inputs, const size_t numChannels,
const size_t numFrames) override;
std::vector<std::vector<double>> GetGainReduction() const {
return this->mGainReductionDB;
};
Expand Down Expand Up @@ -135,6 +134,4 @@ class Trigger : public DSP {
};

}; // namespace noise_gate
}; // namespace dsp

#endif /* NoiseGate_h */
}; // namespace dsp
6 changes: 3 additions & 3 deletions dsp/RecursiveLinearFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ recursive_linear_filter::Base::Base(const size_t inputDegree,
this->mOutputCoefficients.resize(outputDegree);
}

iplug::sample **recursive_linear_filter::Base::Process(iplug::sample **inputs,
const size_t numChannels,
const size_t numFrames) {
double **recursive_linear_filter::Base::Process(double **inputs,
const size_t numChannels,
const size_t numFrames) {
this->_PrepareBuffers(numChannels, numFrames);
long inputStart = 0;
long outputStart = 0;
Expand Down
16 changes: 6 additions & 10 deletions dsp/RecursiveLinearFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
//
// Recursive linear filters (LPF, HPF, Peaking, Shelving)

#ifndef RecursiveLinearFilter_h
#define RecursiveLinearFilter_h
#pragma once

#include "IPlugConstants.h" // sample
#include "dsp.h"
#include <cmath> // pow, sin
#include <vector>
Expand All @@ -22,8 +20,8 @@ namespace recursive_linear_filter {
class Base : public dsp::DSP {
public:
Base(const size_t inputDegree, const size_t outputDegree);
iplug::sample **Process(iplug::sample **inputs, const size_t numChannels,
const size_t numFrames) override;
double **Process(double **inputs, const size_t numChannels,
const size_t numFrames) override;

protected:
// Methods
Expand All @@ -41,8 +39,8 @@ class Base : public dsp::DSP {
// First index is channel
// Second index, [0] is the current input/output, [1] is the previous, [2] is
// before that, etc.
std::vector<std::vector<iplug::sample>> mInputHistory;
std::vector<std::vector<iplug::sample>> mOutputHistory;
std::vector<std::vector<double>> mInputHistory;
std::vector<std::vector<double>> mOutputHistory;
// Indices for history.
// Designates which index is currently "0". Use modulus to wrap around.
long mInputStart;
Expand Down Expand Up @@ -121,6 +119,4 @@ class HighShelf : public Biquad {
public:
void SetParams(const BiquadParams &params) override;
};
}; // namespace recursive_linear_filter

#endif /* RecursiveLinearFilter_h */
}; // namespace recursive_linear_filter
5 changes: 1 addition & 4 deletions dsp/Resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// Created by Steven Atkinson on 1/2/23.
//

#ifndef Resample_h
#define Resample_h
#pragma once

#include <cmath>
#include <stdexcept>
Expand Down Expand Up @@ -83,5 +82,3 @@ void dsp::ResampleCubic(const std::vector<T> &inputs,
time += resampledTimeIncrement;
}
}

#endif /* Resample_h */
7 changes: 3 additions & 4 deletions dsp/dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void dsp::DSP::_AllocateOutputPointers(const size_t numChannels) {
if (this->mOutputPointers != nullptr)
throw std::runtime_error(
"Tried to re-allocate over non-null mOutputPointers");
this->mOutputPointers = new iplug::sample *[numChannels];
this->mOutputPointers = new double *[numChannels];
if (this->mOutputPointers == nullptr)
throw std::runtime_error("Failed to allocate pointer to output buffer!\n");
this->mOutputPointersSize = numChannels;
Expand All @@ -36,7 +36,7 @@ void dsp::DSP::_DeallocateOutputPointers() {
this->mOutputPointersSize = 0;
}

iplug::sample **dsp::DSP::_GetPointers() {
double **dsp::DSP::_GetPointers() {
for (auto c = 0; c < this->_GetNumChannels(); c++)
this->mOutputPointers[c] = this->mOutputs[c].data();
return this->mOutputPointers;
Expand Down Expand Up @@ -91,8 +91,7 @@ void dsp::History::_RewindHistory() {
this->mHistoryIndex = this->mHistoryRequired;
}

void dsp::History::_UpdateHistory(iplug::sample **inputs,
const size_t numChannels,
void dsp::History::_UpdateHistory(double **inputs, const size_t numChannels,
const size_t numFrames) {
this->_EnsureHistorySize(numFrames);
if (numChannels < 1)
Expand Down
15 changes: 6 additions & 9 deletions dsp/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <unordered_map>
#include <vector>

#include "IPlugConstants.h"

// Version 2 DSP abstraction ==================================================

namespace dsp {
Expand All @@ -24,9 +22,8 @@ class DSP {
// The output shall be a pointer-to-pointers of matching size.
// This object instance will own the data referenced by the pointers and be
// responsible for its allocation and deallocation.
virtual iplug::sample **Process(iplug::sample **inputs,
const size_t numChannels,
const size_t numFrames) = 0;
virtual double **Process(double **inputs, const size_t numChannels,
const size_t numFrames) = 0;
// Update the parameters of the DSP object according to the provided params.
// Not declaring a pure virtual bc there's no concrete definition that can
// use Params.
Expand All @@ -48,7 +45,7 @@ class DSP {
}
// Return a pointer-to-pointers for the DSP's output buffers (all channels)
// Assumes that ._PrepareBuffers() was called recently enough.
iplug::sample **_GetPointers();
double **_GetPointers();
// Resize mOutputs to (numChannels, numFrames) and ensure that the raw
// pointers are also keeping up.
virtual void _PrepareBuffers(const size_t numChannels,
Expand All @@ -61,11 +58,11 @@ class DSP {
// The output array into which the DSP module's calculations will be written.
// Pointers to this member's data will be returned by .Process(), and std
// Will ensure proper allocation.
std::vector<std::vector<iplug::sample>> mOutputs;
std::vector<std::vector<double>> mOutputs;
// A pointer to pointers of which copies will be given out as the output of
// .Process(). This object will ensure proper allocation and deallocation of
// the first level; The second level points to .data() from mOutputs.
iplug::sample **mOutputPointers;
double **mOutputPointers;
size_t mOutputPointersSize;
};

Expand All @@ -85,7 +82,7 @@ class History : public DSP {
void _AdvanceHistoryIndex(const size_t bufferSize);
// Drop the new samples into the history array.
// Manages history array size
void _UpdateHistory(iplug::sample **inputs, const size_t numChannels,
void _UpdateHistory(double **inputs, const size_t numChannels,
const size_t numFrames);

// The history array that's used for DSP calculations.
Expand Down
4 changes: 2 additions & 2 deletions dsp/wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ bool ReadChunkAndSkipJunk(std::ifstream &file, char *chunkID) {
return file.good();
}

dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
dsp::wav::LoadReturnCode dsp::wav::Load(const char *fileName,
std::vector<float> &audio,
double &sampleRate) {
// FYI: https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
// Open the WAV file for reading
std::ifstream wavFile(fileName.Get(), std::ios::binary);
std::ifstream wavFile(fileName, std::ios::binary);

// Check if the file was opened successfully
if (!wavFile.is_open()) {
Expand Down
9 changes: 2 additions & 7 deletions dsp/wav.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
// Created by Steven Atkinson on 12/31/22.
//

#ifndef wav_h
#define wav_h

#include "wdlstring.h" // WDL_String
#pragma once

namespace dsp {
namespace wav {
Expand All @@ -30,7 +27,7 @@ enum class LoadReturnCode {
// And note the sample rate.
//
// Returns: as per return cases above
LoadReturnCode Load(const WDL_String &fileName, std::vector<float> &audio,
LoadReturnCode Load(const char *fileName, std::vector<float> &audio,
double &sampleRate);

// Load samples, 16-bit
Expand All @@ -47,5 +44,3 @@ void _LoadSamples32(std::ifstream &wavFile, const int chunkSize,
int _ReadSigned24BitInt(std::ifstream &stream);
}; // namespace wav
}; // namespace dsp

#endif /* wav_h */
4 changes: 2 additions & 2 deletions format.bash → format.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Apply project formatting (i.e. clang-format with LLVM style)
#
# Usage:
# $ bash format.bash
# $ ./format.sh

echo "Formatting..."

Expand All @@ -12,4 +12,4 @@ echo "Formatting complete!"
echo "You can stage all of the files using:"
echo ""
echo ' git ls-files "*.h" "*.cpp" | xargs git add'
echo ""
echo ""