diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index e466b78..59d10b5 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -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") diff --git a/dsp/ImpulseResponse.cpp b/dsp/ImpulseResponse.cpp index 4ecd5d9..34fe31c 100644 --- a/dsp/ImpulseResponse.cpp +++ b/dsp/ImpulseResponse.cpp @@ -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); diff --git a/dsp/ImpulseResponse.h b/dsp/ImpulseResponse.h index bffd5f7..7a14027 100644 --- a/dsp/ImpulseResponse.h +++ b/dsp/ImpulseResponse.h @@ -6,24 +6,21 @@ // // Impulse response processing -#ifndef ImpulseResponse_h -#define ImpulseResponse_h +#pragma once #include #include -#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; }; @@ -45,5 +42,3 @@ class ImpulseResponse : public History { Eigen::VectorXf mWeight; }; }; // namespace dsp - -#endif /* ImpulseResponse_h */ diff --git a/dsp/NoiseGate.cpp b/dsp/NoiseGate.cpp index 8ee12fa..2ea6f4b 100644 --- a/dsp/NoiseGate.cpp +++ b/dsp/NoiseGate.cpp @@ -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. @@ -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(); } @@ -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); diff --git a/dsp/NoiseGate.h b/dsp/NoiseGate.h index 2077a86..b859778 100644 --- a/dsp/NoiseGate.h +++ b/dsp/NoiseGate.h @@ -5,8 +5,7 @@ // Created by Steven Atkinson on 2/5/23. // -#ifndef NoiseGate_h -#define NoiseGate_h +#pragma once #include #include @@ -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> &gainReductionDB) { this->mGainReductionDB = gainReductionDB; @@ -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> GetGainReduction() const { return this->mGainReductionDB; }; @@ -135,6 +134,4 @@ class Trigger : public DSP { }; }; // namespace noise_gate -}; // namespace dsp - -#endif /* NoiseGate_h */ +}; // namespace dsp \ No newline at end of file diff --git a/dsp/RecursiveLinearFilter.cpp b/dsp/RecursiveLinearFilter.cpp index 38ebda2..1fe6751 100644 --- a/dsp/RecursiveLinearFilter.cpp +++ b/dsp/RecursiveLinearFilter.cpp @@ -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; diff --git a/dsp/RecursiveLinearFilter.h b/dsp/RecursiveLinearFilter.h index 1b4f044..cb609be 100644 --- a/dsp/RecursiveLinearFilter.h +++ b/dsp/RecursiveLinearFilter.h @@ -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 // pow, sin #include @@ -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 @@ -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> mInputHistory; - std::vector> mOutputHistory; + std::vector> mInputHistory; + std::vector> mOutputHistory; // Indices for history. // Designates which index is currently "0". Use modulus to wrap around. long mInputStart; @@ -121,6 +119,4 @@ class HighShelf : public Biquad { public: void SetParams(const BiquadParams ¶ms) override; }; -}; // namespace recursive_linear_filter - -#endif /* RecursiveLinearFilter_h */ +}; // namespace recursive_linear_filter \ No newline at end of file diff --git a/dsp/Resample.h b/dsp/Resample.h index 107ce45..66100e7 100644 --- a/dsp/Resample.h +++ b/dsp/Resample.h @@ -5,8 +5,7 @@ // Created by Steven Atkinson on 1/2/23. // -#ifndef Resample_h -#define Resample_h +#pragma once #include #include @@ -83,5 +82,3 @@ void dsp::ResampleCubic(const std::vector &inputs, time += resampledTimeIncrement; } } - -#endif /* Resample_h */ diff --git a/dsp/dsp.cpp b/dsp/dsp.cpp index ac0f831..6ca5a4d 100644 --- a/dsp/dsp.cpp +++ b/dsp/dsp.cpp @@ -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; @@ -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; @@ -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) diff --git a/dsp/dsp.h b/dsp/dsp.h index 666a883..fdc2971 100644 --- a/dsp/dsp.h +++ b/dsp/dsp.h @@ -7,8 +7,6 @@ #include #include -#include "IPlugConstants.h" - // Version 2 DSP abstraction ================================================== namespace dsp { @@ -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. @@ -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, @@ -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> mOutputs; + std::vector> 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; }; @@ -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. diff --git a/dsp/wav.cpp b/dsp/wav.cpp index 89dcbe5..e33296b 100644 --- a/dsp/wav.cpp +++ b/dsp/wav.cpp @@ -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 &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()) { diff --git a/dsp/wav.h b/dsp/wav.h index 7079873..01fce60 100644 --- a/dsp/wav.h +++ b/dsp/wav.h @@ -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 { @@ -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 &audio, +LoadReturnCode Load(const char *fileName, std::vector &audio, double &sampleRate); // Load samples, 16-bit @@ -47,5 +44,3 @@ void _LoadSamples32(std::ifstream &wavFile, const int chunkSize, int _ReadSigned24BitInt(std::ifstream &stream); }; // namespace wav }; // namespace dsp - -#endif /* wav_h */ diff --git a/format.bash b/format.sh old mode 100644 new mode 100755 similarity index 91% rename from format.bash rename to format.sh index 8e0d8ae..1db8446 --- a/format.bash +++ b/format.sh @@ -2,7 +2,7 @@ # Apply project formatting (i.e. clang-format with LLVM style) # # Usage: -# $ bash format.bash +# $ ./format.sh echo "Formatting..." @@ -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 "" \ No newline at end of file +echo ""