Skip to content

Commit

Permalink
Ouros SIMD
Browse files Browse the repository at this point in the history
Added SIMD
  • Loading branch information
codygeary authored Sep 2, 2024
1 parent 343e497 commit f84da7d
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/Ouros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include "rack.hpp"
#include "plugin.hpp"
using simd::float_4;

const float twoPi = 2.0f * M_PI;
simd::float_4 twoPiSIMD = simd::float_4(twoPi);

using namespace rack;

Expand Down Expand Up @@ -44,8 +48,6 @@ class CircularBuffer {
}
};

static const float twoPi = 2.0f * M_PI;

struct Ouros : Module {

static inline float linearInterpolation(float a, float b, float fraction) {
Expand Down Expand Up @@ -335,7 +337,14 @@ struct Ouros : Module {
latch[c] = true;
risingState[c] = true;
}



// Initialize SIMD variables
simd::float_4 phases, places;
simd::float_4 rateVec(rate), multi_rateVec(multi_rate);
simd::float_4 twoPiVec(2 * M_PI), fiveVec(5.0f);
simd::float_4 zeroVec(0.0f), oneVec(1.0f);

for (int i = 0; i < 4; i++) {

/////////////////////
Expand Down Expand Up @@ -411,7 +420,7 @@ struct Ouros : Module {
place[c][i] += rate * deltaTime;
}

oscPhase[c][i] -= (int)oscPhase[c][i];
oscPhase[c][i] -= static_cast<int>(oscPhase[c][i]);

if (place[c][i] >= 1.0f) place[c][i] -= 1.0f; // Wrap

Expand All @@ -428,19 +437,27 @@ struct Ouros : Module {
place[c][3] = 0.0f;
oscPhase[c][3] = 0.0f;
}

////////////
//COMPUTE the Oscillator Shape
oscOutput[c][i] = clamp(5.0f * sinf(twoPi * oscPhase[c][i]), -5.0f, 5.0f);

if (i<2){
//Output Voltage
outputs[L_OUTPUT + i].setVoltage(oscOutput[c][i],c);
}

// Store phase values in SIMD vectors
phases[i] = oscPhase[c][i];
places[i] = place[c][i];

prevPhaseResetInput[c]= PhaseResetInput;
}

// Compute oscillator shape using SIMD
simd::float_4 phaseVector = phases * twoPiVec;
simd::float_4 sinValues = simd::sin(phaseVector);
simd::float_4 outputValues = clamp(fiveVec * sinValues, -5.0f, 5.0f);

// Store results and output the voltages
for (int i = 0; i < 4; i++) {
oscOutput[c][i] = outputValues[i];
if (i < 2) {
outputs[L_OUTPUT + i].setVoltage(oscOutput[c][i], c);
}
}

lastoscPhase[c][2] = oscPhase[c][2];
// Handling for wrapping around 0
for (int i = 0; i < 4; i++) {
Expand All @@ -455,8 +472,7 @@ struct Ouros : Module {
sampleIndex = clamp(sampleIndex, 0, 1023);
waveBuffers[0][sampleIndex] = outputs[L_OUTPUT].getVoltage(0);
waveBuffers[1][sampleIndex] = outputs[R_OUTPUT].getVoltage(0);



}//void process

};
Expand Down

0 comments on commit f84da7d

Please sign in to comment.