diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /media/libcubeb/src/cubeb_panner.cpp | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'media/libcubeb/src/cubeb_panner.cpp')
-rw-r--r-- | media/libcubeb/src/cubeb_panner.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/media/libcubeb/src/cubeb_panner.cpp b/media/libcubeb/src/cubeb_panner.cpp new file mode 100644 index 0000000000..bd96ed6ef0 --- /dev/null +++ b/media/libcubeb/src/cubeb_panner.cpp @@ -0,0 +1,60 @@ +/* + * Copyright © 2014 Mozilla Foundation + * + * This program is made available under an ISC-style license. See the + * accompanying file LICENSE for details. + */ + +#define _USE_MATH_DEFINES +#include <math.h> +#include <stdint.h> + +#include "cubeb_panner.h" + +#ifndef M_PI +#define M_PI 3.14159263 +#endif + +/** + * We use a cos/sin law. + */ + +namespace { +template<typename T> +void cubeb_pan_stereo_buffer(T * buf, uint32_t frames, float pan) +{ + if (pan == 0.0) { + return; + } + /* rescale in [0; 1] */ + pan += 1; + pan /= 2; + float left_gain = float(cos(pan * M_PI * 0.5)); + float right_gain = float(sin(pan * M_PI * 0.5)); + + /* In we are panning on the left, pan the right channel into the left one and + * vice-versa. */ + if (pan < 0.5) { + for (uint32_t i = 0; i < frames * 2; i+=2) { + buf[i] = T(buf[i] + buf[i + 1] * left_gain); + buf[i + 1] = T(buf[i + 1] * right_gain); + } + } else { + for (uint32_t i = 0; i < frames * 2; i+=2) { + buf[i] = T(buf[i] * left_gain); + buf[i + 1] = T(buf[i + 1] + buf[i] * right_gain); + } + } +} +} + +void cubeb_pan_stereo_buffer_float(float * buf, uint32_t frames, float pan) +{ + cubeb_pan_stereo_buffer(buf, frames, pan); +} + +void cubeb_pan_stereo_buffer_int(short * buf, uint32_t frames, float pan) +{ + cubeb_pan_stereo_buffer(buf, frames, pan); +} + |