1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#include "dsp/stereo_panner.h"
18
19#include <cmath>
20
21#include "base/constants_and_types.h"
22
23namespace vraudio {
24
25const float kStereoLeftRadians = kRadiansFromDegrees * kStereoLeftDegrees;
26const float kStereoRightRadians = kRadiansFromDegrees * kStereoRightDegrees;
27
28void CalculateStereoPanGains(const SphericalAngle& source_direction,
29 std::vector<float>* stereo_gains) {
30 // Note this applies the same panning law as was applied by the ambisonic
31 // equivalent panner to ensure consistency.
32 DCHECK(stereo_gains);
33 stereo_gains->resize(new_size: kNumStereoChannels);
34
35 const float cos_direction_elevation = std::cos(x: source_direction.elevation());
36
37 (*stereo_gains)[0] =
38 0.5f * (1.0f + std::cos(x: kStereoLeftRadians - source_direction.azimuth()) *
39 cos_direction_elevation);
40 (*stereo_gains)[1] =
41 0.5f *
42 (1.0f + std::cos(x: kStereoRightRadians - source_direction.azimuth()) *
43 cos_direction_elevation);
44}
45
46} // namespace vraudio
47

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.cc