From da1203fd83231a1a67d9a13112bfd49c955c66e9 Mon Sep 17 00:00:00 2001
From: Oli Larkin <olilarkin@googlemail.com>
Date: Sat, 1 Apr 2023 21:25:40 +0200
Subject: [PATCH 1/4] format.bash -> format.sh

---
 format.bash => format.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
 rename format.bash => format.sh (91%)
 mode change 100644 => 100755

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 ""

From 7f848ce754903b4aa10e9e5417bbb420364957a6 Mon Sep 17 00:00:00 2001
From: Oli Larkin <olilarkin@googlemail.com>
Date: Sat, 1 Apr 2023 21:24:41 +0200
Subject: [PATCH 2/4] Remove IPlug2 code from NAMCore. Sample is always float

---
 dsp/ImpulseResponse.cpp       | 13 +++++-----
 dsp/ImpulseResponse.h         |  8 +++---
 dsp/NoiseGate.cpp             | 14 +++++------
 dsp/NoiseGate.h               |  8 +++---
 dsp/RecursiveLinearFilter.cpp |  6 ++---
 dsp/RecursiveLinearFilter.h   |  9 +++----
 dsp/dsp.cpp                   | 47 +++++++++++++++++------------------
 dsp/dsp.h                     | 36 +++++++++++----------------
 dsp/wav.cpp                   |  4 +--
 dsp/wav.h                     |  3 +--
 dsp/wavenet.cpp               |  2 +-
 11 files changed, 68 insertions(+), 82 deletions(-)

diff --git a/dsp/ImpulseResponse.cpp b/dsp/ImpulseResponse.cpp
index 4ecd5d9..d4081d7 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) {
+float **dsp::ImpulseResponse::Process(float **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..56b6f27 100644
--- a/dsp/ImpulseResponse.h
+++ b/dsp/ImpulseResponse.h
@@ -13,17 +13,15 @@
 
 #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);
+  float **Process(float **inputs, const size_t numChannels,
+                  const size_t numFrames) override;
   // TODO states for the IR class
   dsp::wav::LoadReturnCode GetWavState() const { return this->mWavState; };
 
diff --git a/dsp/NoiseGate.cpp b/dsp/NoiseGate.cpp
index 8ee12fa..4adfe52 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) {
+float **dsp::noise_gate::Trigger::Process(float **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(float));
   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) {
+float **dsp::noise_gate::Gain::Process(float **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..4f6647c 100644
--- a/dsp/NoiseGate.h
+++ b/dsp/NoiseGate.h
@@ -33,8 +33,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;
+  float **Process(float **inputs, const size_t numChannels,
+                  const size_t numFrames) override;
 
   void SetGainReductionDB(std::vector<std::vector<double>> &gainReductionDB) {
     this->mGainReductionDB = gainReductionDB;
@@ -82,8 +82,8 @@ class Trigger : public DSP {
 public:
   Trigger();
 
-  iplug::sample **Process(iplug::sample **inputs, const size_t numChannels,
-                          const size_t numFrames) override;
+  float **Process(float **inputs, const size_t numChannels,
+                  const size_t numFrames) override;
   std::vector<std::vector<double>> GetGainReduction() const {
     return this->mGainReductionDB;
   };
diff --git a/dsp/RecursiveLinearFilter.cpp b/dsp/RecursiveLinearFilter.cpp
index 38ebda2..30fff9b 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) {
+float **recursive_linear_filter::Base::Process(float **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..611bff7 100644
--- a/dsp/RecursiveLinearFilter.h
+++ b/dsp/RecursiveLinearFilter.h
@@ -9,7 +9,6 @@
 #ifndef RecursiveLinearFilter_h
 #define RecursiveLinearFilter_h
 
-#include "IPlugConstants.h" // sample
 #include "dsp.h"
 #include <cmath> // pow, sin
 #include <vector>
@@ -22,8 +21,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;
+  float **Process(float **inputs, const size_t numChannels,
+                  const size_t numFrames) override;
 
 protected:
   // Methods
@@ -41,8 +40,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<float>> mInputHistory;
+  std::vector<std::vector<float>> mOutputHistory;
   // Indices for history.
   // Designates which index is currently "0". Use modulus to wrap around.
   long mInputStart;
diff --git a/dsp/dsp.cpp b/dsp/dsp.cpp
index b97052f..f9a1544 100644
--- a/dsp/dsp.cpp
+++ b/dsp/dsp.cpp
@@ -19,9 +19,9 @@ constexpr auto _INPUT_BUFFER_SAFETY_FACTOR = 32;
 
 DSP::DSP() { this->_stale_params = true; }
 
-void DSP::process(iplug::sample **inputs, iplug::sample **outputs,
-                  const int num_channels, const int num_frames,
-                  const double input_gain, const double output_gain,
+void DSP::process(float **inputs, float **outputs, const int num_channels,
+                  const int num_frames, const double input_gain,
+                  const double output_gain,
                   const std::unordered_map<std::string, double> &params) {
   this->_get_params_(params);
   this->_apply_input_level_(inputs, num_channels, num_frames, input_gain);
@@ -46,7 +46,7 @@ void DSP::_get_params_(
   }
 }
 
-void DSP::_apply_input_level_(iplug::sample **inputs, const int num_channels,
+void DSP::_apply_input_level_(float **inputs, const int num_channels,
                               const int num_frames, const double gain) {
   // Must match exactly; we're going to use the size of _input_post_gain later
   // for num_frames.
@@ -69,7 +69,7 @@ void DSP::_process_core_() {
     this->_core_dsp_output[i] = this->_input_post_gain[i];
 }
 
-void DSP::_apply_output_level_(iplug::sample **outputs, const int num_channels,
+void DSP::_apply_output_level_(float **outputs, const int num_channels,
                                const int num_frames, const double gain) {
   for (int c = 0; c < num_channels; c++)
     for (int s = 0; s < num_frames; s++)
@@ -206,8 +206,8 @@ inline float fast_tanh_(const float x) {
 }
 
 inline float hard_tanh_(const float x) {
-    const float t = x < -1 ? -1 : x;
-    return t > 1 ? 1 : t;
+  const float t = x < -1 ? -1 : x;
+  return t > 1 ? 1 : t;
 }
 
 void tanh_(Eigen::MatrixXf &x, const long i_start, const long i_end,
@@ -232,25 +232,25 @@ void tanh_(Eigen::MatrixXf &x) {
   }
 }
 
-void hard_tanh_(Eigen::MatrixXf& x, const long i_start, const long i_end,
-    const long j_start, const long j_end) {
-    for (long j = j_start; j < j_end; j++)
-        for (long i = i_start; i < i_end; i++)
-            x(i, j) = hard_tanh_(x(i, j));
+void hard_tanh_(Eigen::MatrixXf &x, const long i_start, const long i_end,
+                const long j_start, const long j_end) {
+  for (long j = j_start; j < j_end; j++)
+    for (long i = i_start; i < i_end; i++)
+      x(i, j) = hard_tanh_(x(i, j));
 }
 
-void hard_tanh_(Eigen::MatrixXf& x, const long j_start, const long j_end) {
-    hard_tanh_(x, 0, x.rows(), j_start, j_end);
+void hard_tanh_(Eigen::MatrixXf &x, const long j_start, const long j_end) {
+  hard_tanh_(x, 0, x.rows(), j_start, j_end);
 }
 
-void hard_tanh_(Eigen::MatrixXf& x) {
-    float* ptr = x.data();
+void hard_tanh_(Eigen::MatrixXf &x) {
+  float *ptr = x.data();
 
-    long size = x.rows() * x.cols();
+  long size = x.rows() * x.cols();
 
-    for (long pos = 0; pos < size; pos++) {
-        ptr[pos] = hard_tanh_(ptr[pos]);
-    }
+  for (long pos = 0; pos < size; pos++) {
+    ptr[pos] = hard_tanh_(ptr[pos]);
+  }
 }
 
 void Conv1D::set_params_(std::vector<float>::iterator &params) {
@@ -534,7 +534,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 float *[numChannels];
   if (this->mOutputPointers == nullptr)
     throw std::runtime_error("Failed to allocate pointer to output buffer!\n");
   this->mOutputPointersSize = numChannels;
@@ -550,7 +550,7 @@ void dsp::DSP::_DeallocateOutputPointers() {
   this->mOutputPointersSize = 0;
 }
 
-iplug::sample **dsp::DSP::_GetPointers() {
+float **dsp::DSP::_GetPointers() {
   for (auto c = 0; c < this->_GetNumChannels(); c++)
     this->mOutputPointers[c] = this->mOutputs[c].data();
   return this->mOutputPointers;
@@ -605,8 +605,7 @@ void dsp::History::_RewindHistory() {
   this->mHistoryIndex = this->mHistoryRequired;
 }
 
-void dsp::History::_UpdateHistory(iplug::sample **inputs,
-                                  const size_t numChannels,
+void dsp::History::_UpdateHistory(float **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 1e5efeb..1d8ea9c 100644
--- a/dsp/dsp.h
+++ b/dsp/dsp.h
@@ -1,7 +1,5 @@
 #pragma once
 
-#if IPLUG_DSP
-
 #include <filesystem>
 #include <iterator>
 #include <memory>
@@ -9,7 +7,6 @@
 #include <unordered_map>
 #include <vector>
 
-#include "IPlugConstants.h"
 #include <Eigen/Dense>
 
 enum EArchitectures {
@@ -43,9 +40,9 @@ class DSP {
   // 3. The core DSP algorithm is run (This is what should probably be
   //    overridden in subclasses).
   // 4. The output level is applied and the result stored to `output`.
-  virtual void process(iplug::sample **inputs, iplug::sample **outputs,
-                       const int num_channels, const int num_frames,
-                       const double input_gain, const double output_gain,
+  virtual void process(float **inputs, float **outputs, const int num_channels,
+                       const int num_frames, const double input_gain,
+                       const double output_gain,
                        const std::unordered_map<std::string, double> &params);
   // Anything to take care of before next buffer comes in.
   // For example:
@@ -75,7 +72,7 @@ class DSP {
 
   // Apply the input gain
   // Result populates this->_input_post_gain
-  void _apply_input_level_(iplug::sample **inputs, const int num_channels,
+  void _apply_input_level_(float **inputs, const int num_channels,
                            const int num_frames, const double gain);
 
   // i.e. ensure the size is correct.
@@ -87,7 +84,7 @@ class DSP {
   virtual void _process_core_();
 
   // Copy this->_core_dsp_output to output and apply the output volume
-  void _apply_output_level_(iplug::sample **outputs, const int num_channels,
+  void _apply_output_level_(float **outputs, const int num_channels,
                             const int num_frames, const double gain);
 };
 
@@ -154,12 +151,12 @@ void tanh_(Eigen::MatrixXf &x, const long i_start, const long i_end);
 void tanh_(Eigen::MatrixXf &x);
 
 // In-place Hardtanh on (N,M) array
-void hard_tanh_(Eigen::MatrixXf& x, const long i_start, const long i_end,
-    const long j_start, const long j_end);
+void hard_tanh_(Eigen::MatrixXf &x, const long i_start, const long i_end,
+                const long j_start, const long j_end);
 // Subset of the columns
-void hard_tanh_(Eigen::MatrixXf& x, const long i_start, const long i_end);
+void hard_tanh_(Eigen::MatrixXf &x, const long i_start, const long i_end);
 
-void hard_tanh_(Eigen::MatrixXf& x);
+void hard_tanh_(Eigen::MatrixXf &x);
 
 class Conv1D {
 public:
@@ -324,9 +321,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 float **Process(float **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.
@@ -348,7 +344,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();
+  float **_GetPointers();
   // Resize mOutputs to (numChannels, numFrames) and ensure that the raw
   // pointers are also keeping up.
   virtual void _PrepareBuffers(const size_t numChannels,
@@ -361,11 +357,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<float>> 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;
+  float **mOutputPointers;
   size_t mOutputPointersSize;
 };
 
@@ -385,7 +381,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(float **inputs, const size_t numChannels,
                       const size_t numFrames);
 
   // The history array that's used for DSP calculations.
@@ -404,5 +400,3 @@ class History : public DSP {
   void _RewindHistory();
 };
 }; // namespace dsp
-
-#endif // IPLUG_DSP
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<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()) {
diff --git a/dsp/wav.h b/dsp/wav.h
index 7079873..74b369c 100644
--- a/dsp/wav.h
+++ b/dsp/wav.h
@@ -8,7 +8,6 @@
 #ifndef wav_h
 #define wav_h
 
-#include "wdlstring.h" // WDL_String
 
 namespace dsp {
 namespace wav {
@@ -30,7 +29,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
diff --git a/dsp/wavenet.cpp b/dsp/wavenet.cpp
index e466b78..59d10b5 100644
--- a/dsp/wavenet.cpp
+++ b/dsp/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")

From e169fb6c459eee3fc17b2d24a730cc6bf32c7b78 Mon Sep 17 00:00:00 2001
From: Oli Larkin <olilarkin@googlemail.com>
Date: Sat, 1 Apr 2023 21:35:29 +0200
Subject: [PATCH 3/4] Use #pragma once for include guard, format

---
 dsp/ImpulseResponse.h       | 5 +----
 dsp/NoiseGate.h             | 7 ++-----
 dsp/RecursiveLinearFilter.h | 7 ++-----
 dsp/Resample.h              | 5 +----
 dsp/wav.h                   | 6 +-----
 5 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/dsp/ImpulseResponse.h b/dsp/ImpulseResponse.h
index 56b6f27..d19de70 100644
--- a/dsp/ImpulseResponse.h
+++ b/dsp/ImpulseResponse.h
@@ -6,8 +6,7 @@
 //
 // Impulse response processing
 
-#ifndef ImpulseResponse_h
-#define ImpulseResponse_h
+#pragma once
 
 #include <filesystem>
 
@@ -43,5 +42,3 @@ class ImpulseResponse : public History {
   Eigen::VectorXf mWeight;
 };
 }; // namespace dsp
-
-#endif /* ImpulseResponse_h */
diff --git a/dsp/NoiseGate.h b/dsp/NoiseGate.h
index 4f6647c..1b15ed1 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 <cmath>
 #include <unordered_set>
@@ -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.h b/dsp/RecursiveLinearFilter.h
index 611bff7..51d443a 100644
--- a/dsp/RecursiveLinearFilter.h
+++ b/dsp/RecursiveLinearFilter.h
@@ -6,8 +6,7 @@
 //
 // Recursive linear filters (LPF, HPF, Peaking, Shelving)
 
-#ifndef RecursiveLinearFilter_h
-#define RecursiveLinearFilter_h
+#pragma once
 
 #include "dsp.h"
 #include <cmath> // pow, sin
@@ -120,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
\ 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 <cmath>
 #include <stdexcept>
@@ -83,5 +82,3 @@ void dsp::ResampleCubic(const std::vector<T> &inputs,
     time += resampledTimeIncrement;
   }
 }
-
-#endif /* Resample_h */
diff --git a/dsp/wav.h b/dsp/wav.h
index 74b369c..01fce60 100644
--- a/dsp/wav.h
+++ b/dsp/wav.h
@@ -5,9 +5,7 @@
 //  Created by Steven Atkinson on 12/31/22.
 //
 
-#ifndef wav_h
-#define wav_h
-
+#pragma once
 
 namespace dsp {
 namespace wav {
@@ -46,5 +44,3 @@ void _LoadSamples32(std::ifstream &wavFile, const int chunkSize,
 int _ReadSigned24BitInt(std::ifstream &stream);
 }; // namespace wav
 }; // namespace dsp
-
-#endif /* wav_h */

From 6d64b8c2cbca43abc5e650a44336bf308057998c Mon Sep 17 00:00:00 2001
From: Steven Atkinson <steven@atkinson.mn>
Date: Sun, 2 Apr 2023 11:52:12 -0700
Subject: [PATCH 4/4] Double is default sample type

---
 dsp/ImpulseResponse.cpp       |  2 +-
 dsp/ImpulseResponse.h         |  2 +-
 dsp/NoiseGate.cpp             |  6 +++---
 dsp/NoiseGate.h               |  4 ++--
 dsp/RecursiveLinearFilter.cpp |  2 +-
 dsp/RecursiveLinearFilter.h   |  6 +++---
 dsp/dsp.cpp                   |  6 +++---
 dsp/dsp.h                     | 10 +++++-----
 8 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/dsp/ImpulseResponse.cpp b/dsp/ImpulseResponse.cpp
index d4081d7..34fe31c 100644
--- a/dsp/ImpulseResponse.cpp
+++ b/dsp/ImpulseResponse.cpp
@@ -24,7 +24,7 @@ dsp::ImpulseResponse::ImpulseResponse(const char* fileName,
     this->_SetWeights(sampleRate);
 }
 
-float **dsp::ImpulseResponse::Process(float **inputs, const size_t numChannels,
+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 d19de70..7a14027 100644
--- a/dsp/ImpulseResponse.h
+++ b/dsp/ImpulseResponse.h
@@ -19,7 +19,7 @@ namespace dsp {
 class ImpulseResponse : public History {
 public:
   ImpulseResponse(const char* fileName, const double sampleRate);
-  float **Process(float **inputs, const size_t numChannels,
+  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; };
diff --git a/dsp/NoiseGate.cpp b/dsp/NoiseGate.cpp
index 4adfe52..2ea6f4b 100644
--- a/dsp/NoiseGate.cpp
+++ b/dsp/NoiseGate.cpp
@@ -18,7 +18,7 @@ dsp::noise_gate::Trigger::Trigger()
 
 double signum(const double val) { return (0.0 < val) - (val < 0.0); }
 
-float **dsp::noise_gate::Trigger::Process(float **inputs,
+double **dsp::noise_gate::Trigger::Process(double **inputs,
                                           const size_t numChannels,
                                           const size_t numFrames) {
   this->_PrepareBuffers(numChannels, numFrames);
@@ -87,7 +87,7 @@ float **dsp::noise_gate::Trigger::Process(float **inputs,
 
   // Copy input to output
   for (auto c = 0; c < numChannels; c++)
-    memcpy(this->mOutputs[c].data(), inputs[c], numFrames * sizeof(float));
+    memcpy(this->mOutputs[c].data(), inputs[c], numFrames * sizeof(double));
   return this->_GetPointers();
 }
 
@@ -128,7 +128,7 @@ void dsp::noise_gate::Trigger::_PrepareBuffers(const size_t numChannels,
 
 // Gain========================================================================
 
-float **dsp::noise_gate::Gain::Process(float **inputs, const size_t numChannels,
+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...
diff --git a/dsp/NoiseGate.h b/dsp/NoiseGate.h
index 1b15ed1..b859778 100644
--- a/dsp/NoiseGate.h
+++ b/dsp/NoiseGate.h
@@ -32,7 +32,7 @@ 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:
-  float **Process(float **inputs, const size_t numChannels,
+  double **Process(double **inputs, const size_t numChannels,
                   const size_t numFrames) override;
 
   void SetGainReductionDB(std::vector<std::vector<double>> &gainReductionDB) {
@@ -81,7 +81,7 @@ class Trigger : public DSP {
 public:
   Trigger();
 
-  float **Process(float **inputs, const size_t numChannels,
+  double **Process(double **inputs, const size_t numChannels,
                   const size_t numFrames) override;
   std::vector<std::vector<double>> GetGainReduction() const {
     return this->mGainReductionDB;
diff --git a/dsp/RecursiveLinearFilter.cpp b/dsp/RecursiveLinearFilter.cpp
index 30fff9b..1fe6751 100644
--- a/dsp/RecursiveLinearFilter.cpp
+++ b/dsp/RecursiveLinearFilter.cpp
@@ -20,7 +20,7 @@ recursive_linear_filter::Base::Base(const size_t inputDegree,
   this->mOutputCoefficients.resize(outputDegree);
 }
 
-float **recursive_linear_filter::Base::Process(float **inputs,
+double **recursive_linear_filter::Base::Process(double **inputs,
                                                const size_t numChannels,
                                                const size_t numFrames) {
   this->_PrepareBuffers(numChannels, numFrames);
diff --git a/dsp/RecursiveLinearFilter.h b/dsp/RecursiveLinearFilter.h
index 51d443a..cb609be 100644
--- a/dsp/RecursiveLinearFilter.h
+++ b/dsp/RecursiveLinearFilter.h
@@ -20,7 +20,7 @@ namespace recursive_linear_filter {
 class Base : public dsp::DSP {
 public:
   Base(const size_t inputDegree, const size_t outputDegree);
-  float **Process(float **inputs, const size_t numChannels,
+  double **Process(double **inputs, const size_t numChannels,
                   const size_t numFrames) override;
 
 protected:
@@ -39,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<float>> mInputHistory;
-  std::vector<std::vector<float>> 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;
diff --git a/dsp/dsp.cpp b/dsp/dsp.cpp
index 33de251..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 float *[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;
 }
 
-float **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,7 +91,7 @@ void dsp::History::_RewindHistory() {
   this->mHistoryIndex = this->mHistoryRequired;
 }
 
-void dsp::History::_UpdateHistory(float **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 7ef8d68..fdc2971 100644
--- a/dsp/dsp.h
+++ b/dsp/dsp.h
@@ -22,7 +22,7 @@ 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 float **Process(float **inputs, const size_t numChannels,
+  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
@@ -45,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.
-  float **_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,
@@ -58,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<float>> 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.
-  float **mOutputPointers;
+  double **mOutputPointers;
   size_t mOutputPointersSize;
 };
 
@@ -82,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(float **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.
