Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| 11 #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_AUDIO_FRAME_OPERATIONS_H_ | 11 #ifndef WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ | 
| 12 #define WEBRTC_MODULES_UTILITY_INCLUDE_AUDIO_FRAME_OPERATIONS_H_ | 12 #define WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ | 
| 13 | 13 | 
| 14 #include "webrtc/modules/include/module_common_types.h" | |
| 
 
the sun
2016/12/01 20:32:46
Please put back the forward declaration of AudioFr
 
aleloi
2016/12/02 12:13:36
Wow, didn't know that! Done.
 
 | |
| 14 #include "webrtc/typedefs.h" | 15 #include "webrtc/typedefs.h" | 
| 15 | 16 | 
| 16 namespace webrtc { | 17 namespace webrtc { | 
| 17 | 18 | 
| 18 class AudioFrame; | |
| 19 | |
| 20 // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h. | 19 // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h. | 
| 21 // Change reference parameters to pointers. Consider using a namespace rather | 20 // Change reference parameters to pointers. Consider using a namespace rather | 
| 22 // than a class. | 21 // than a class. | 
| 23 class AudioFrameOperations { | 22 class AudioFrameOperations { | 
| 24 public: | 23 public: | 
| 24 // Add samples in |frame_to_add| with samples in |result_frame| | |
| 25 // putting the results in |results_frame|. The fields | |
| 26 // |vad_activity_| and |speech_type_| of the result frame are | |
| 27 // updated. If |result_frame| is empty (|samples_per_channel_|==0), | |
| 28 // the samples in |frame_to_add| are added to it. The number of | |
| 29 // channels and number of samples per channel must match except when | |
| 30 // |result_frame| is empty. | |
| 31 static void Add(const AudioFrame& frame_to_add, AudioFrame* result_frame); | |
| 32 | |
| 25 // Upmixes mono |src_audio| to stereo |dst_audio|. This is an out-of-place | 33 // 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 | 34 // 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 | 35 // buffers. It is the caller's responsibility to ensure that |dst_audio| is | 
| 28 // sufficiently large. | 36 // sufficiently large. | 
| 29 static void MonoToStereo(const int16_t* src_audio, size_t samples_per_channel, | 37 static void MonoToStereo(const int16_t* src_audio, | 
| 38 size_t samples_per_channel, | |
| 30 int16_t* dst_audio); | 39 int16_t* dst_audio); | 
| 31 // |frame.num_channels_| will be updated. This version checks for sufficient | 40 // |frame.num_channels_| will be updated. This version checks for sufficient | 
| 32 // buffer size and that |num_channels_| is mono. | 41 // buffer size and that |num_channels_| is mono. | 
| 33 static int MonoToStereo(AudioFrame* frame); | 42 static int MonoToStereo(AudioFrame* frame); | 
| 34 | 43 | 
| 35 // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place | 44 // 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 | 45 // operation, meaning |src_audio| and |dst_audio| may point to the same | 
| 37 // buffer. | 46 // buffer. | 
| 38 static void StereoToMono(const int16_t* src_audio, size_t samples_per_channel, | 47 static void StereoToMono(const int16_t* src_audio, | 
| 48 size_t samples_per_channel, | |
| 39 int16_t* dst_audio); | 49 int16_t* dst_audio); | 
| 40 // |frame.num_channels_| will be updated. This version checks that | 50 // |frame.num_channels_| will be updated. This version checks that | 
| 41 // |num_channels_| is stereo. | 51 // |num_channels_| is stereo. | 
| 42 static int StereoToMono(AudioFrame* frame); | 52 static int StereoToMono(AudioFrame* frame); | 
| 43 | 53 | 
| 44 // Swap the left and right channels of |frame|. Fails silently if |frame| is | 54 // Swap the left and right channels of |frame|. Fails silently if |frame| is | 
| 45 // not stereo. | 55 // not stereo. | 
| 46 static void SwapStereoChannels(AudioFrame* frame); | 56 static void SwapStereoChannels(AudioFrame* frame); | 
| 47 | 57 | 
| 48 // Conditionally zero out contents of |frame| for implementing audio mute: | 58 // Conditionally zero out contents of |frame| for implementing audio mute: | 
| 49 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. | 59 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. | 
| 50 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. | 60 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. | 
| 51 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. | 61 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. | 
| 52 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. | 62 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. | 
| 53 static void Mute(AudioFrame* frame, bool previous_frame_muted, | 63 static void Mute(AudioFrame* frame, | 
| 64 bool previous_frame_muted, | |
| 54 bool current_frame_muted); | 65 bool current_frame_muted); | 
| 55 | 66 | 
| 67 // Zero out contents of frame. | |
| 68 static void Mute(AudioFrame* frame); | |
| 69 | |
| 70 // Halve samples in |frame|. | |
| 71 static void ApplyHalfGain(AudioFrame* frame); | |
| 72 | |
| 56 static int Scale(float left, float right, AudioFrame& frame); | 73 static int Scale(float left, float right, AudioFrame& frame); | 
| 57 | 74 | 
| 58 static int ScaleWithSat(float scale, AudioFrame& frame); | 75 static int ScaleWithSat(float scale, AudioFrame& frame); | 
| 59 }; | 76 }; | 
| 60 | 77 | 
| 78 int16_t ClampToInt16(int32_t input); | |
| 
 
the sun
2016/12/01 20:32:46
Is this unused? I don't find the definition.
 
aleloi
2016/12/02 12:13:35
I've replaced it with saturated_cast. Now removed.
 
 | |
| 79 | |
| 61 } // namespace webrtc | 80 } // namespace webrtc | 
| 62 | 81 | 
| 63 #endif // #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_AUDIO_FRAME_OPERATIONS_H_ | 82 #endif // WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ | 
| OLD | NEW |