Deluge Firmware 1.3.0
Build date: 2025.04.16
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
26 [[gnu::always_inline]] static constexpr StereoSample fromMono(q31_t sampleValue) {
27 return StereoSample{
28 .l = sampleValue,
29 .r = sampleValue,
30 };
31 }
32
33 inline void addMono(q31_t sampleValue) {
34 l += sampleValue;
35 r += sampleValue;
36 }
37
38 // Amplitude is probably Q2.29?
39 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 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 inline void addPannedStereo(q31_t sampleValueL, q31_t sampleValueR, int32_t amplitudeL, int32_t amplitudeR) {
63 l += (multiply_32x32_rshift32(sampleValueL, amplitudeL) << 2);
64 r += (multiply_32x32_rshift32(sampleValueR, amplitudeR) << 2);
65 }
66
67 q31_t l = 0;
68 q31_t r = 0;
69};
Definition stereo_sample.h:25