Deluge Firmware 1.3.0
Build date: 2026.11.22
Loading...
Searching...
No Matches
supersaw.h
1/*
2 * Copyright © 2026 Mark Adams
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <algorithm>
20#include <array>
21#include <cstddef>
22#include <cstdint>
23
24namespace deluge::dsp {
25
28class Supersaw {
29public:
30 static constexpr size_t kNumSaws = 7;
31
33 using SidePhases = std::array<uint32_t, kNumSaws - 1>;
34
37 static constexpr SidePhases sidePhasesFrom(uint32_t centrePhase) {
38 SidePhases phases{};
39 for (size_t i = 0; i < phases.size(); i++) {
40 phases[i] = centrePhase + static_cast<uint32_t>(i + 1) * 0x9E3779B9u;
41 }
42 return phases;
43 }
44
47 static constexpr int32_t numSawsFromPulseWidth(uint32_t pulseWidth) {
48 uint32_t pulseWidthAbsolute = (static_cast<int32_t>(pulseWidth) >= 0) ? pulseWidth : -pulseWidth;
49 auto removed = static_cast<int32_t>((static_cast<uint64_t>(pulseWidthAbsolute) * kNumSaws) >> 31);
50 return kNumSaws - std::min<int32_t>(removed, kNumSaws - 1);
51 }
52
58 static void render(int32_t* __restrict__ buffer, int32_t numSamples, uint32_t phaseIncrement, int32_t spread,
59 int32_t numSaws, uint32_t& centrePhase, SidePhases& sidePhases, bool bandLimit);
60};
61
62} // namespace deluge::dsp
Definition supersaw.h:28
static constexpr int32_t numSawsFromPulseWidth(uint32_t pulseWidth)
Definition supersaw.h:47
std::array< uint32_t, kNumSaws - 1 > SidePhases
Phases of the side saws. The centre saw's phase is the regular oscillator phase.
Definition supersaw.h:33
static void render(int32_t *__restrict__ buffer, int32_t numSamples, uint32_t phaseIncrement, int32_t spread, int32_t numSaws, uint32_t &centrePhase, SidePhases &sidePhases, bool bandLimit)
Definition supersaw.cpp:201
static constexpr SidePhases sidePhasesFrom(uint32_t centrePhase)
Definition supersaw.h:37