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 | |
14 #include <stddef.h> | |
the sun
2016/12/02 13:39:55
For size_t? But system include should still go aft
aleloi
2016/12/05 09:18:37
Not according to the style guide...
https://googl
| |
13 | 15 |
14 #include "webrtc/typedefs.h" | 16 #include "webrtc/typedefs.h" |
15 | 17 |
16 namespace webrtc { | 18 namespace webrtc { |
17 | 19 |
18 class AudioFrame; | 20 class AudioFrame; |
19 | 21 |
20 // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h. | 22 // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h. |
21 // Change reference parameters to pointers. Consider using a namespace rather | 23 // Change reference parameters to pointers. Consider using a namespace rather |
22 // than a class. | 24 // than a class. |
23 class AudioFrameOperations { | 25 class AudioFrameOperations { |
24 public: | 26 public: |
27 // Add samples in |frame_to_add| with samples in |result_frame| | |
28 // putting the results in |results_frame|. The fields | |
29 // |vad_activity_| and |speech_type_| of the result frame are | |
30 // updated. If |result_frame| is empty (|samples_per_channel_|==0), | |
31 // the samples in |frame_to_add| are added to it. The number of | |
32 // channels and number of samples per channel must match except when | |
33 // |result_frame| is empty. | |
34 static void Add(const AudioFrame& frame_to_add, AudioFrame* result_frame); | |
35 | |
25 // Upmixes mono |src_audio| to stereo |dst_audio|. This is an out-of-place | 36 // 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 | 37 // 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 | 38 // buffers. It is the caller's responsibility to ensure that |dst_audio| is |
28 // sufficiently large. | 39 // sufficiently large. |
29 static void MonoToStereo(const int16_t* src_audio, size_t samples_per_channel, | 40 static void MonoToStereo(const int16_t* src_audio, |
41 size_t samples_per_channel, | |
30 int16_t* dst_audio); | 42 int16_t* dst_audio); |
31 // |frame.num_channels_| will be updated. This version checks for sufficient | 43 // |frame.num_channels_| will be updated. This version checks for sufficient |
32 // buffer size and that |num_channels_| is mono. | 44 // buffer size and that |num_channels_| is mono. |
33 static int MonoToStereo(AudioFrame* frame); | 45 static int MonoToStereo(AudioFrame* frame); |
34 | 46 |
35 // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place | 47 // 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 | 48 // operation, meaning |src_audio| and |dst_audio| may point to the same |
37 // buffer. | 49 // buffer. |
38 static void StereoToMono(const int16_t* src_audio, size_t samples_per_channel, | 50 static void StereoToMono(const int16_t* src_audio, |
51 size_t samples_per_channel, | |
39 int16_t* dst_audio); | 52 int16_t* dst_audio); |
40 // |frame.num_channels_| will be updated. This version checks that | 53 // |frame.num_channels_| will be updated. This version checks that |
41 // |num_channels_| is stereo. | 54 // |num_channels_| is stereo. |
42 static int StereoToMono(AudioFrame* frame); | 55 static int StereoToMono(AudioFrame* frame); |
43 | 56 |
44 // Swap the left and right channels of |frame|. Fails silently if |frame| is | 57 // Swap the left and right channels of |frame|. Fails silently if |frame| is |
45 // not stereo. | 58 // not stereo. |
46 static void SwapStereoChannels(AudioFrame* frame); | 59 static void SwapStereoChannels(AudioFrame* frame); |
47 | 60 |
48 // Conditionally zero out contents of |frame| for implementing audio mute: | 61 // Conditionally zero out contents of |frame| for implementing audio mute: |
49 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. | 62 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. |
50 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. | 63 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. |
51 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. | 64 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. |
52 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. | 65 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. |
53 static void Mute(AudioFrame* frame, bool previous_frame_muted, | 66 static void Mute(AudioFrame* frame, |
67 bool previous_frame_muted, | |
54 bool current_frame_muted); | 68 bool current_frame_muted); |
55 | 69 |
70 // Zero out contents of frame. | |
71 static void Mute(AudioFrame* frame); | |
72 | |
73 // Halve samples in |frame|. | |
74 static void ApplyHalfGain(AudioFrame* frame); | |
75 | |
56 static int Scale(float left, float right, AudioFrame& frame); | 76 static int Scale(float left, float right, AudioFrame& frame); |
57 | 77 |
58 static int ScaleWithSat(float scale, AudioFrame& frame); | 78 static int ScaleWithSat(float scale, AudioFrame& frame); |
59 }; | 79 }; |
60 | 80 |
61 } // namespace webrtc | 81 } // namespace webrtc |
62 | 82 |
63 #endif // #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_AUDIO_FRAME_OPERATIONS_H_ | 83 #endif // WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ |
OLD | NEW |