diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /media/libcubeb/src/cubeb_panner.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
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 000000000..bd96ed6ef --- /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); +} + |