Optimized: Fixed point calculations

This commit is contained in:
Dejvino
2026-03-01 16:39:29 +01:00
parent bdfd216b4a
commit 6fe8488994
4 changed files with 189 additions and 197 deletions
+13 -6
View File
@@ -32,6 +32,13 @@ template <typename Mutex>
using SynthLockGuard = std::lock_guard<Mutex>;
#endif
// Fixed-point constants
#define FP_SHIFT 15
#define FP_ONE (1 << FP_SHIFT)
#define FP_HALF (1 << (FP_SHIFT - 1))
#define FP_MAX 32767
#define FP_MIN -32768
/**
* @class SynthEngine
* @brief A portable, platform-agnostic synthesizer engine.
@@ -102,11 +109,11 @@ public:
enum Op { OP_ADD, OP_MUL, OP_SUB, OP_DIV, OP_MIN, OP_MAX };
Type type = EMPTY;
float param = 0.5f; // 0.0 to 1.0
int32_t param = FP_HALF; // 0.0 to 1.0 -> 0 to 32768
int rotation = 0; // 0:N, 1:E, 2:S, 3:W (Output direction)
float value = 0.0f; // Current output sample
float next_value = 0.0f; // For double-buffering in processGridStep
float phase = 0.0f; // For Oscillator, Noise state
int32_t value = 0; // Current output sample (Q15)
int32_t next_value = 0; // For double-buffering
int32_t phase = 0; // For Oscillator, Noise state, Filter state
uint32_t phase_accumulator = 0; // For Oscillators (Fixed point optimization)
};
@@ -125,7 +132,7 @@ public:
SynthMutex gridMutex;
// Helper to process one sample step of the grid
float processGridStep();
int32_t processGridStep();
private:
uint32_t _sampleRate;
@@ -140,7 +147,7 @@ private:
void rebuildProcessingOrder_locked();
// Internal random number generator
float _random();
int32_t _random();
};
#endif // SYNTH_ENGINE_H