Skip to content

Commit

Permalink
Fix some more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xconverge committed Jan 19, 2025
1 parent 598d2f6 commit 2881cfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
7 changes: 2 additions & 5 deletions Software/GuitarPedal/Effect-Modules/polyoctave_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <q/fx/biquad.hpp>
#include <q/support/literals.hpp>

//#include "../Util/EffectState.h"
// #include "../Util/EffectState.h"
#include "../Util/Multirate.h"
#include "../Util/OctaveGenerator.h"

Expand Down Expand Up @@ -78,9 +78,7 @@ void PolyOctaveModule::Init(float sample_rate) {
void PolyOctaveModule::ProcessMono(float in) {
BaseEffectModule::ProcessMono(in);

float input = m_audioLeft;
buff[bin_counter] =
m_audioLeft; // making a workaround for only processing sample by sample instead of block, will add 6 samples of latency
buff[bin_counter] = in; // making a workaround for only processing sample by sample instead of block, will add 6 samples of latency

float dryLevel = GetParameterAsFloat(0);
float down1Level = GetParameterAsFloat(1);
Expand All @@ -107,7 +105,6 @@ void PolyOctaveModule::ProcessMono(float in) {
for (size_t j = 0; j < out_chunk.size(); ++j) {
float mix = eq2(eq1(out_chunk[j]));

const auto dry_signal = buff[j];
mix += dryLevel * buff[j];

buff_out[j] = mix;
Expand Down
42 changes: 8 additions & 34 deletions Software/GuitarPedal/Util/FastSqrt.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
#pragma once

#include <bit>
#include <cstdint>
#include <limits>

// https://en.wikipedia.org/wiki/Fast_inverse_square_root
static constexpr float fastInvSqrt(float number) noexcept {
// static_assert(std::numeric_limits<float>::is_iec559);
// float const y = std::bit_cast<float>(
// 0x5F1FFFF9 - (std::bit_cast<std::uint32_t>(x) >> 1));
// return y * (0.703952253f * (2.38924456f - (x * y * y)));

// Trouble using bit_cast, not a member of std error even when defining c++20 in makefile, using this found at:
// https://www.geeksforgeeks.org/fast-inverse-square-root/
// function to find the inverse square root

const float threehalfs = 1.5F;

float x2 = number * 0.5F;
float y = number;

// evil floating point bit level hacking
long i = *(long *)&y;

// value is pre-assumed
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;

// 1st iteration
y = y * (threehalfs - (x2 * y * y));

// 2nd iteration, this can be removed
// y = y * ( threehalfs - ( x2 * y * y ) );

return y;

// return 1.0/sqrt(x); // work around for compile error using bit_cast
union {
float f;
uint32_t i;
} conv = {.f = number};
conv.i = 0x5f3759df - (conv.i >> 1);
conv.f *= 1.5F - (number * 0.5F * conv.f * conv.f);
return conv.f;
}

static constexpr float fastSqrt(float x) { return fastInvSqrt(x) * x; }
static constexpr float fastSqrt(float x) { return x * fastInvSqrt(x); }

0 comments on commit 2881cfd

Please sign in to comment.