| 1 | /* |
| 2 | Copyright 2018 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS-IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "dsp/channel_converter.h" |
| 18 | |
| 19 | #include <cmath> |
| 20 | |
| 21 | #include "base/constants_and_types.h" |
| 22 | #include "base/logging.h" |
| 23 | #include "base/simd_utils.h" |
| 24 | |
| 25 | namespace vraudio { |
| 26 | |
| 27 | void ConvertStereoFromMono(const AudioBuffer& input, AudioBuffer* output) { |
| 28 | DCHECK(output); |
| 29 | DCHECK_EQ(input.num_channels(), kNumMonoChannels); |
| 30 | DCHECK_EQ(output->num_channels(), kNumStereoChannels); |
| 31 | DCHECK_EQ(input.num_frames(), output->num_frames()); |
| 32 | StereoFromMonoSimd(length: input.num_frames(), mono: &input[0][0], left: &(*output)[0][0], |
| 33 | right: &(*output)[1][0]); |
| 34 | } |
| 35 | |
| 36 | void ConvertMonoFromStereo(const AudioBuffer& input, AudioBuffer* output) { |
| 37 | DCHECK(output); |
| 38 | DCHECK_EQ(input.num_channels(), kNumStereoChannels); |
| 39 | DCHECK_EQ(output->num_channels(), kNumMonoChannels); |
| 40 | DCHECK_EQ(input.num_frames(), output->num_frames()); |
| 41 | MonoFromStereoSimd(length: input.num_frames(), left: &input[0][0], right: &input[1][0], |
| 42 | mono: &(*output)[0][0]); |
| 43 | } |
| 44 | |
| 45 | } // namespace vraudio |
| 46 | |