Deluge Firmware
1.3.0
Build date: 2026.08.16
Toggle main menu visibility
Loading...
Searching...
No Matches
stereo_sample.h
1
/*
2
* Copyright © 2014 Synthstrom Audible Limited
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
18
// Ok, creating a class for this is absolutely stupid, but I was a noob at the time! It doesn't add any performance
19
// overhead though.
20
21
#pragma once
22
23
#include "util/functions.h"
24
25
struct
StereoSample
{
26
[[gnu::always_inline]]
static
constexpr
StereoSample
fromMono(q31_t sampleValue) {
27
return
StereoSample
{
28
.l = sampleValue,
29
.r = sampleValue,
30
};
31
}
32
33
[[gnu::always_inline]]
void
addMono(q31_t sampleValue) {
34
l += sampleValue;
35
r += sampleValue;
36
}
37
38
// Amplitude is probably Q2.29?
39
[[gnu::always_inline]]
void
addPannedMono(q31_t sampleValue, int32_t amplitudeL, int32_t amplitudeR) {
40
l += (multiply_32x32_rshift32(sampleValue, amplitudeL) << 2);
41
r += (multiply_32x32_rshift32(sampleValue, amplitudeR) << 2);
42
}
43
44
[[gnu::always_inline]]
void
addStereo(q31_t sampleValueL, q31_t sampleValueR) {
45
l += sampleValueL;
46
r += sampleValueR;
47
}
48
49
[[gnu::always_inline]]
constexpr
StereoSample
operator+(
const
StereoSample
& rhs)
const
{
50
return
StereoSample
{
51
.l = l + rhs.l,
52
.r = r + rhs.r,
53
};
54
}
55
[[gnu::always_inline]]
constexpr
StereoSample
& operator+=(
const
StereoSample
& rhs) {
56
l = l + rhs.l;
57
r = r + rhs.r;
58
return
*
this
;
59
}
60
61
// Amplitude is probably Q2.29?
62
[[gnu::always_inline]]
void
addPannedStereo(q31_t sampleValueL, q31_t sampleValueR, int32_t amplitudeL,
63
int32_t amplitudeR) {
64
l += (multiply_32x32_rshift32(sampleValueL, amplitudeL) << 2);
65
r += (multiply_32x32_rshift32(sampleValueR, amplitudeR) << 2);
66
}
67
68
// Sean: don't initialize l and r to 0 as this introduces performance issues
69
q31_t l;
70
q31_t r;
71
};
StereoSample
Definition
stereo_sample.h:25