niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_ |
| 12 | #define WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | 8b06200 | 2013-07-12 08:28:10 +0000 | [diff] [blame^] | 14 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | class AudioFrame; |
| 19 | |
andrew@webrtc.org | 294be77 | 2012-05-22 03:28:41 +0000 | [diff] [blame] | 20 | // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h. |
andrew@webrtc.org | 459955f | 2012-05-29 22:13:14 +0000 | [diff] [blame] | 21 | // Change reference parameters to pointers. Consider using a namespace rather |
| 22 | // than a class. |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 23 | class AudioFrameOperations { |
| 24 | public: |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 25 | // Upmixes mono |src_audio| to stereo |dst_audio|. This is an out-of-place |
| 26 | // operation, meaning src_audio and dst_audio must point to different |
| 27 | // buffers. It is the caller's responsibility to ensure that |dst_audio| is |
| 28 | // sufficiently large. |
| 29 | static void MonoToStereo(const int16_t* src_audio, int samples_per_channel, |
| 30 | int16_t* dst_audio); |
| 31 | // |frame.num_channels_| will be updated. This version checks for sufficient |
| 32 | // buffer size and that |num_channels_| is mono. |
| 33 | static int MonoToStereo(AudioFrame* frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 35 | // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place |
| 36 | // operation, meaning |src_audio| and |dst_audio| may point to the same |
| 37 | // buffer. |
| 38 | static void StereoToMono(const int16_t* src_audio, int samples_per_channel, |
| 39 | int16_t* dst_audio); |
| 40 | // |frame.num_channels_| will be updated. This version checks that |
| 41 | // |num_channels_| is stereo. |
| 42 | static int StereoToMono(AudioFrame* frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 44 | // Swap the left and right channels of |frame|. Fails silently if |frame| is |
| 45 | // not stereo. |
| 46 | static void SwapStereoChannels(AudioFrame* frame); |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 47 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 48 | // Zeros out the audio and sets |frame.energy| to zero. |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 49 | static void Mute(AudioFrame& frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 51 | static int Scale(float left, float right, AudioFrame& frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 53 | static int ScaleWithSat(float scale, AudioFrame& frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 56 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
andrew@webrtc.org | 9c4f6a5 | 2012-04-26 22:32:03 +0000 | [diff] [blame] | 58 | #endif // #ifndef WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_ |