Skip to content

Commit

Permalink
Merge pull request #34 from TheSlowGrowth/feature/ui
Browse files Browse the repository at this point in the history
Feature/UI
  • Loading branch information
TheSlowGrowth authored Aug 16, 2024
2 parents ee8d8dc + 25c8d6f commit e1ded02
Show file tree
Hide file tree
Showing 50 changed files with 6,549 additions and 2,471 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"recommendations": [
"davidschuldenfrei.gtest-adapter",
"ms-vscode.cpptools",
"vadimcn.vscode-lldb"
]
}
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"preLaunchTask": "buildTests-TapeLooperDSP",

"osx": {
"type": "lldb",
"MIMode": "lldb",
},
"windows": {
Expand All @@ -101,6 +102,7 @@
"preLaunchTask": "buildTests-TapeLooper",

"osx": {
"type": "lldb",
"MIMode": "lldb",
},
"windows": {
Expand All @@ -123,6 +125,7 @@
"preLaunchTask": "build plugin",

"osx": {
"type": "lldb",
"MIMode": "lldb",
},
"windows": {
Expand All @@ -144,6 +147,7 @@
"preLaunchTask": "build plugin",

"osx": {
"type": "lldb",
"MIMode": "lldb",
"program": "${workspaceFolder}/plugin/build/TapeLooperPlugin_artefacts/Debug/Standalone/Tape Looper Plugin.app/Contents/MacOS/Tape Looper Plugin",
},
Expand Down
10 changes: 8 additions & 2 deletions dsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ set(HEADER_FILES

add_subdirectory(lib/sprout)

add_library(${TARGET} INTERFACE)
target_include_directories(${TARGET} INTERFACE
add_library(${TARGET}
src/dsp/DspHelpers.cpp
)
target_include_directories(${TARGET} INTERFACE
src/
${CMAKE_CURRENT_SOURCE_DIR}/lib/sprout/
)
target_include_directories(${TARGET} PRIVATE
src/
${CMAKE_CURRENT_SOURCE_DIR}/lib/sprout/
)
Expand Down
41 changes: 36 additions & 5 deletions dsp/src/dsp/AudioBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ template <size_t numChannels, typename FloatType = float>
class AudioBufferPtr
{
public:
AudioBufferPtr(FloatType* const* buffer, size_t numSamples) :
size_(numSamples)
AudioBufferPtr(FloatType* const* buffer, size_t numSamplesPerChannel) :
size_(numSamplesPerChannel)
{
for (size_t ch = 0; ch < numChannels; ch++)
buffer_[ch] = buffer[ch];
Expand All @@ -37,11 +37,21 @@ class AudioBufferPtr
return buffer_[channelIdx];
}

FloatType* operator[](size_t channelIdx) const
const FloatType* operator[](size_t channelIdx) const
{
return buffer_[channelIdx];
}

FloatType* const* getChannelPointers()
{
return buffer_;
}

const FloatType* const* getChannelPointers() const
{
return buffer_;
}

operator AudioBufferPtr<numChannels, const FloatType>() const
{
return AudioBufferPtr<numChannels, const FloatType>(buffer_, size_);
Expand All @@ -54,6 +64,25 @@ class AudioBufferPtr
buffer_[ch][i] = value;
}

void copyToChannel(size_t destChannel, const FloatType* const srcSamples, size_t numSamples)
{
for (size_t i = 0; i < std::min(numSamples, size_); i++)
buffer_[destChannel][i] = srcSamples[i];
}

void addToChannel(size_t destChannel, const FloatType* const srcSamples, size_t numSamples)
{
for (size_t i = 0; i < std::min(numSamples, size_); i++)
buffer_[destChannel][i] += srcSamples[i];
}

void applyGain(FloatType value)
{
for (size_t ch = 0; ch < numChannels; ch++)
for (size_t i = 0; i < size_; i++)
buffer_[ch][i] *= value;
}

AudioBufferPtr<numChannels, FloatType> subBlock(size_t startSample, size_t length = size_t(-1)) const
{
const auto resultMaxLength = std::max(size_ - startSample, size_t(0));
Expand All @@ -64,15 +93,17 @@ class AudioBufferPtr
return result;
}

FloatType* buffer_[numChannels];
const size_t size_;

protected:
// private ctor for use in subBlock()
AudioBufferPtr(size_t numSamples) :
size_(numSamples) {}

FloatType* buffer_[numChannels];
};

template <size_t numSamples, size_t numChannels, typename FloatType = float>
template <size_t numChannels, size_t numSamples, typename FloatType = float>
class AudioBuffer : public AudioBufferPtr<numChannels, FloatType>
{
public:
Expand Down
141 changes: 141 additions & 0 deletions dsp/src/dsp/DspHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include "DspHelpers.h"

/* original script taken from pichenettes/stmlib */
const float pitchRatioHigh[257] = {
// clang-format off
6.151958251e-04, 6.517772725e-04, 6.905339660e-04, 7.315952524e-04,
7.750981699e-04, 8.211879055e-04, 8.700182794e-04, 9.217522585e-04,
9.765625000e-04, 1.034631928e-03, 1.096154344e-03, 1.161335073e-03,
1.230391650e-03, 1.303554545e-03, 1.381067932e-03, 1.463190505e-03,
1.550196340e-03, 1.642375811e-03, 1.740036559e-03, 1.843504517e-03,
1.953125000e-03, 2.069263856e-03, 2.192308688e-03, 2.322670146e-03,
2.460783301e-03, 2.607109090e-03, 2.762135864e-03, 2.926381010e-03,
3.100392680e-03, 3.284751622e-03, 3.480073118e-03, 3.687009034e-03,
3.906250000e-03, 4.138527712e-03, 4.384617376e-03, 4.645340293e-03,
4.921566601e-03, 5.214218180e-03, 5.524271728e-03, 5.852762019e-03,
6.200785359e-03, 6.569503244e-03, 6.960146235e-03, 7.374018068e-03,
7.812500000e-03, 8.277055425e-03, 8.769234752e-03, 9.290680586e-03,
9.843133202e-03, 1.042843636e-02, 1.104854346e-02, 1.170552404e-02,
1.240157072e-02, 1.313900649e-02, 1.392029247e-02, 1.474803614e-02,
1.562500000e-02, 1.655411085e-02, 1.753846950e-02, 1.858136117e-02,
1.968626640e-02, 2.085687272e-02, 2.209708691e-02, 2.341104808e-02,
2.480314144e-02, 2.627801298e-02, 2.784058494e-02, 2.949607227e-02,
3.125000000e-02, 3.310822170e-02, 3.507693901e-02, 3.716272234e-02,
3.937253281e-02, 4.171374544e-02, 4.419417382e-02, 4.682209615e-02,
4.960628287e-02, 5.255602595e-02, 5.568116988e-02, 5.899214454e-02,
6.250000000e-02, 6.621644340e-02, 7.015387802e-02, 7.432544469e-02,
7.874506562e-02, 8.342749089e-02, 8.838834765e-02, 9.364419230e-02,
9.921256575e-02, 1.051120519e-01, 1.113623398e-01, 1.179842891e-01,
1.250000000e-01, 1.324328868e-01, 1.403077560e-01, 1.486508894e-01,
1.574901312e-01, 1.668549818e-01, 1.767766953e-01, 1.872883846e-01,
1.984251315e-01, 2.102241038e-01, 2.227246795e-01, 2.359685782e-01,
2.500000000e-01, 2.648657736e-01, 2.806155121e-01, 2.973017788e-01,
3.149802625e-01, 3.337099635e-01, 3.535533906e-01, 3.745767692e-01,
3.968502630e-01, 4.204482076e-01, 4.454493591e-01, 4.719371563e-01,
5.000000000e-01, 5.297315472e-01, 5.612310242e-01, 5.946035575e-01,
6.299605249e-01, 6.674199271e-01, 7.071067812e-01, 7.491535384e-01,
7.937005260e-01, 8.408964153e-01, 8.908987181e-01, 9.438743127e-01,
1.000000000e+00, 1.059463094e+00, 1.122462048e+00, 1.189207115e+00,
1.259921050e+00, 1.334839854e+00, 1.414213562e+00, 1.498307077e+00,
1.587401052e+00, 1.681792831e+00, 1.781797436e+00, 1.887748625e+00,
2.000000000e+00, 2.118926189e+00, 2.244924097e+00, 2.378414230e+00,
2.519842100e+00, 2.669679708e+00, 2.828427125e+00, 2.996614154e+00,
3.174802104e+00, 3.363585661e+00, 3.563594873e+00, 3.775497251e+00,
4.000000000e+00, 4.237852377e+00, 4.489848193e+00, 4.756828460e+00,
5.039684200e+00, 5.339359417e+00, 5.656854249e+00, 5.993228308e+00,
6.349604208e+00, 6.727171322e+00, 7.127189745e+00, 7.550994501e+00,
8.000000000e+00, 8.475704755e+00, 8.979696386e+00, 9.513656920e+00,
1.007936840e+01, 1.067871883e+01, 1.131370850e+01, 1.198645662e+01,
1.269920842e+01, 1.345434264e+01, 1.425437949e+01, 1.510198900e+01,
1.600000000e+01, 1.695140951e+01, 1.795939277e+01, 1.902731384e+01,
2.015873680e+01, 2.135743767e+01, 2.262741700e+01, 2.397291323e+01,
2.539841683e+01, 2.690868529e+01, 2.850875898e+01, 3.020397801e+01,
3.200000000e+01, 3.390281902e+01, 3.591878555e+01, 3.805462768e+01,
4.031747360e+01, 4.271487533e+01, 4.525483400e+01, 4.794582646e+01,
5.079683366e+01, 5.381737058e+01, 5.701751796e+01, 6.040795601e+01,
6.400000000e+01, 6.780563804e+01, 7.183757109e+01, 7.610925536e+01,
8.063494719e+01, 8.542975067e+01, 9.050966799e+01, 9.589165292e+01,
1.015936673e+02, 1.076347412e+02, 1.140350359e+02, 1.208159120e+02,
1.280000000e+02, 1.356112761e+02, 1.436751422e+02, 1.522185107e+02,
1.612698944e+02, 1.708595013e+02, 1.810193360e+02, 1.917833058e+02,
2.031873347e+02, 2.152694823e+02, 2.280700718e+02, 2.416318240e+02,
2.560000000e+02, 2.712225522e+02, 2.873502844e+02, 3.044370214e+02,
3.225397888e+02, 3.417190027e+02, 3.620386720e+02, 3.835666117e+02,
4.063746693e+02, 4.305389646e+02, 4.561401437e+02, 4.832636481e+02,
5.120000000e+02, 5.424451043e+02, 5.747005687e+02, 6.088740429e+02,
6.450795775e+02, 6.834380053e+02, 7.240773439e+02, 7.671332234e+02,
8.127493386e+02, 8.610779292e+02, 9.122802874e+02, 9.665272962e+02,
1.024000000e+03, 1.084890209e+03, 1.149401137e+03, 1.217748086e+03,
1.290159155e+03, 1.366876011e+03, 1.448154688e+03, 1.534266447e+03,
// clang-format on
};

/* original script taken from pichenettes/stmlib */
const float pitchRatioLow[257] = {
// clang-format off
1.000000000e+00, 1.000225659e+00, 1.000451370e+00, 1.000677131e+00,
1.000902943e+00, 1.001128806e+00, 1.001354720e+00, 1.001580685e+00,
1.001806701e+00, 1.002032768e+00, 1.002258886e+00, 1.002485055e+00,
1.002711275e+00, 1.002937546e+00, 1.003163868e+00, 1.003390242e+00,
1.003616666e+00, 1.003843141e+00, 1.004069668e+00, 1.004296246e+00,
1.004522874e+00, 1.004749554e+00, 1.004976285e+00, 1.005203068e+00,
1.005429901e+00, 1.005656786e+00, 1.005883722e+00, 1.006110709e+00,
1.006337747e+00, 1.006564836e+00, 1.006791977e+00, 1.007019169e+00,
1.007246412e+00, 1.007473707e+00, 1.007701053e+00, 1.007928450e+00,
1.008155898e+00, 1.008383398e+00, 1.008610949e+00, 1.008838551e+00,
1.009066205e+00, 1.009293910e+00, 1.009521667e+00, 1.009749475e+00,
1.009977334e+00, 1.010205245e+00, 1.010433207e+00, 1.010661221e+00,
1.010889286e+00, 1.011117403e+00, 1.011345571e+00, 1.011573790e+00,
1.011802061e+00, 1.012030384e+00, 1.012258758e+00, 1.012487183e+00,
1.012715661e+00, 1.012944189e+00, 1.013172770e+00, 1.013401401e+00,
1.013630085e+00, 1.013858820e+00, 1.014087607e+00, 1.014316445e+00,
1.014545335e+00, 1.014774277e+00, 1.015003270e+00, 1.015232315e+00,
1.015461411e+00, 1.015690560e+00, 1.015919760e+00, 1.016149011e+00,
1.016378315e+00, 1.016607670e+00, 1.016837077e+00, 1.017066536e+00,
1.017296046e+00, 1.017525609e+00, 1.017755223e+00, 1.017984889e+00,
1.018214607e+00, 1.018444376e+00, 1.018674198e+00, 1.018904071e+00,
1.019133996e+00, 1.019363973e+00, 1.019594002e+00, 1.019824083e+00,
1.020054216e+00, 1.020284401e+00, 1.020514637e+00, 1.020744926e+00,
1.020975266e+00, 1.021205659e+00, 1.021436104e+00, 1.021666600e+00,
1.021897149e+00, 1.022127749e+00, 1.022358402e+00, 1.022589107e+00,
1.022819863e+00, 1.023050672e+00, 1.023281533e+00, 1.023512446e+00,
1.023743411e+00, 1.023974428e+00, 1.024205498e+00, 1.024436619e+00,
1.024667793e+00, 1.024899019e+00, 1.025130297e+00, 1.025361627e+00,
1.025593009e+00, 1.025824444e+00, 1.026055931e+00, 1.026287470e+00,
1.026519061e+00, 1.026750705e+00, 1.026982401e+00, 1.027214149e+00,
1.027445949e+00, 1.027677802e+00, 1.027909707e+00, 1.028141664e+00,
1.028373674e+00, 1.028605736e+00, 1.028837851e+00, 1.029070017e+00,
1.029302237e+00, 1.029534508e+00, 1.029766832e+00, 1.029999209e+00,
1.030231638e+00, 1.030464119e+00, 1.030696653e+00, 1.030929239e+00,
1.031161878e+00, 1.031394569e+00, 1.031627313e+00, 1.031860109e+00,
1.032092958e+00, 1.032325859e+00, 1.032558813e+00, 1.032791820e+00,
1.033024879e+00, 1.033257991e+00, 1.033491155e+00, 1.033724372e+00,
1.033957641e+00, 1.034190964e+00, 1.034424338e+00, 1.034657766e+00,
1.034891246e+00, 1.035124779e+00, 1.035358364e+00, 1.035592003e+00,
1.035825694e+00, 1.036059437e+00, 1.036293234e+00, 1.036527083e+00,
1.036760985e+00, 1.036994940e+00, 1.037228947e+00, 1.037463008e+00,
1.037697121e+00, 1.037931287e+00, 1.038165506e+00, 1.038399777e+00,
1.038634102e+00, 1.038868479e+00, 1.039102910e+00, 1.039337393e+00,
1.039571929e+00, 1.039806518e+00, 1.040041160e+00, 1.040275855e+00,
1.040510603e+00, 1.040745404e+00, 1.040980258e+00, 1.041215165e+00,
1.041450125e+00, 1.041685138e+00, 1.041920204e+00, 1.042155323e+00,
1.042390495e+00, 1.042625720e+00, 1.042860998e+00, 1.043096329e+00,
1.043331714e+00, 1.043567151e+00, 1.043802642e+00, 1.044038185e+00,
1.044273782e+00, 1.044509433e+00, 1.044745136e+00, 1.044980892e+00,
1.045216702e+00, 1.045452565e+00, 1.045688481e+00, 1.045924450e+00,
1.046160473e+00, 1.046396549e+00, 1.046632678e+00, 1.046868860e+00,
1.047105096e+00, 1.047341385e+00, 1.047577727e+00, 1.047814123e+00,
1.048050572e+00, 1.048287074e+00, 1.048523630e+00, 1.048760239e+00,
1.048996902e+00, 1.049233618e+00, 1.049470387e+00, 1.049707210e+00,
1.049944086e+00, 1.050181015e+00, 1.050417999e+00, 1.050655035e+00,
1.050892125e+00, 1.051129269e+00, 1.051366466e+00, 1.051603717e+00,
1.051841021e+00, 1.052078378e+00, 1.052315790e+00, 1.052553255e+00,
1.052790773e+00, 1.053028345e+00, 1.053265971e+00, 1.053503650e+00,
1.053741383e+00, 1.053979169e+00, 1.054217010e+00, 1.054454903e+00,
1.054692851e+00, 1.054930852e+00, 1.055168907e+00, 1.055407016e+00,
1.055645178e+00, 1.055883395e+00, 1.056121664e+00, 1.056359988e+00,
1.056598366e+00, 1.056836797e+00, 1.057075282e+00, 1.057313821e+00,
1.057552413e+00, 1.057791060e+00, 1.058029760e+00, 1.058268515e+00,
1.058507323e+00, 1.058746185e+00, 1.058985101e+00, 1.059224071e+00,
// clang-format on
};
20 changes: 16 additions & 4 deletions dsp/src/dsp/DspHelpers.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
/**
* Copyright (C) Johannes Elliesen, 2021
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -184,3 +184,15 @@ MANUAL_INLINE constexpr Type limit(Type value, Type min, Type max)
{
return value < min ? min : (max < value ? max : value);
}

extern const float pitchRatioHigh[257];
extern const float pitchRatioLow[257];

MANUAL_INLINE float semitonesToRatio(float semitones)
{
float pitch = semitones + 128.0f;
int32_t integral = int32_t(pitch);
float fractional = pitch - float(integral);

return pitchRatioHigh[integral] * pitchRatioLow[int32_t(fractional * 256.0f)];
}
11 changes: 6 additions & 5 deletions dsp/src/dsp/Player.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
/**
* Copyright (C) Johannes Elliesen, 2021
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -95,14 +95,15 @@ class Player
{
const auto postGainTarget = (isPlaying_) ? paramPostProcessorGain : 0.0f;
const auto speedTarget = limit(paramSpeed, minSpeed_, maxSpeed_);
const auto speedModulationAmtTarget = speedModulationAmt;

if (playbackLength_ < 1)
return;

for (size_t i = 0; i < outputToAddTo.size_; i++)
{
const auto postGain = postGainSmoother_.smooth(postGainTarget, postGainSmootherTimeConstant);
const auto speedModulation = speedModulator_.getAndAdvance() * speedModulationAmt;
const auto speedModulation = speedModulator_.getAndAdvance() * speedModulationAmtTarget;
const auto speed = speedModulation + speedSmoother_.smooth(speedTarget, speedSmootherTimeConstant);

// the final two samples we need to interpolate for the current output sample
Expand Down
4 changes: 2 additions & 2 deletions dsp/src/dsp/Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Recorder
for (; i < input.size_; i++)
{
for (size_t ch = 0; ch < numChannels; ch++)
buffer_[ch][recHeadIdx_] = input.buffer_[ch][i];
buffer_[ch][recHeadIdx_] = input[ch][i];
recHeadIdx_++;
if (recHeadIdx_ == buffer_.size_)
{
Expand All @@ -93,7 +93,7 @@ class Recorder
for (size_t ch = 0; ch < numChannels; ch++)
{
const auto xFadedSample = linMap(xfadePhase_,
input.buffer_[ch][i],
input[ch][i],
buffer_[ch][recHeadIdx_]);
buffer_[ch][recHeadIdx_] = xFadedSample;
}
Expand Down
2 changes: 1 addition & 1 deletion dsp/src/dsp/TapeGrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TapeGrainProcessor
private:
static constexpr auto clockedNoiseFreq_ = FloatType(8000);
static constexpr auto clockedNoiseJitter_ = FloatType(0.6);
static constexpr auto maxAmount_ = FloatType(12);
static constexpr auto maxAmount_ = FloatType(24);

ClockedNoiseGenerator<FloatType, sampleRate> noise_;
Biquad<FloatType> noiseFilter_;
Expand Down
Loading

0 comments on commit e1ded02

Please sign in to comment.