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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 // |result_frame| is empty. | 33 // |result_frame| is empty. |
34 static void Add(const AudioFrame& frame_to_add, AudioFrame* result_frame); | 34 static void Add(const AudioFrame& frame_to_add, AudioFrame* result_frame); |
35 | 35 |
36 // 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 |
37 // operation, meaning src_audio and dst_audio must point to different | 37 // operation, meaning src_audio and dst_audio must point to different |
38 // 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 |
39 // sufficiently large. | 39 // sufficiently large. |
40 static void MonoToStereo(const int16_t* src_audio, | 40 static void MonoToStereo(const int16_t* src_audio, |
41 size_t samples_per_channel, | 41 size_t samples_per_channel, |
42 int16_t* dst_audio); | 42 int16_t* dst_audio); |
| 43 |
43 // |frame.num_channels_| will be updated. This version checks for sufficient | 44 // |frame.num_channels_| will be updated. This version checks for sufficient |
44 // buffer size and that |num_channels_| is mono. | 45 // buffer size and that |num_channels_| is mono. |
45 static int MonoToStereo(AudioFrame* frame); | 46 static int MonoToStereo(AudioFrame* frame); |
46 | 47 |
47 // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place | 48 // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place |
48 // operation, meaning |src_audio| and |dst_audio| may point to the same | 49 // operation, meaning |src_audio| and |dst_audio| may point to the same |
49 // buffer. | 50 // buffer. |
50 static void StereoToMono(const int16_t* src_audio, | 51 static void StereoToMono(const int16_t* src_audio, |
51 size_t samples_per_channel, | 52 size_t samples_per_channel, |
52 int16_t* dst_audio); | 53 int16_t* dst_audio); |
| 54 |
53 // |frame.num_channels_| will be updated. This version checks that | 55 // |frame.num_channels_| will be updated. This version checks that |
54 // |num_channels_| is stereo. | 56 // |num_channels_| is stereo. |
55 static int StereoToMono(AudioFrame* frame); | 57 static int StereoToMono(AudioFrame* frame); |
56 | 58 |
| 59 // Downmixes 4 channels |src_audio| to stereo |dst_audio|. This is an in-place |
| 60 // operation, meaning |src_audio| and |dst_audio| may point to the same |
| 61 // buffer. |
| 62 static void QuadToStereo(const int16_t* src_audio, |
| 63 size_t samples_per_channel, |
| 64 int16_t* dst_audio); |
| 65 |
| 66 // |frame.num_channels_| will be updated. This version checks that |
| 67 // |num_channels_| is 4 channels. |
| 68 static int QuadToStereo(AudioFrame* frame); |
| 69 |
| 70 // Downmixes 4 channels |src_audio| to mono |dst_audio|. This is an in-place |
| 71 // operation, meaning |src_audio| and |dst_audio| may point to the same |
| 72 // buffer. |
| 73 static void QuadToMono(const int16_t* src_audio, |
| 74 size_t samples_per_channel, |
| 75 int16_t* dst_audio); |
| 76 |
| 77 // |frame.num_channels_| will be updated. This version checks that |
| 78 // |num_channels_| is 4 channels. |
| 79 static int QuadToMono(AudioFrame* frame); |
| 80 |
| 81 // Downmixes |src_channels| |src_audio| to |dst_channels| |dst_audio|. |
| 82 // This is an in-place operation, meaning |src_audio| and |dst_audio| |
| 83 // may point to the same buffer. Supported channel combinations are |
| 84 // Stereo to Mono, Quad to Mono, and Quad to Stereo. |
| 85 static void DownmixChannels(const int16_t* src_audio, |
| 86 size_t src_channels, |
| 87 size_t samples_per_channel, |
| 88 size_t dst_channels, |
| 89 int16_t* dst_audio); |
| 90 |
| 91 // |frame.num_channels_| will be updated. This version checks that |
| 92 // |num_channels_| and |dst_channels| are valid and performs relevant |
| 93 // downmix. Supported channel combinations are Stereo to Mono, Quad to Mono, |
| 94 // and Quad to Stereo. |
| 95 static int DownmixChannels(size_t dst_channels, |
| 96 AudioFrame* frame); |
| 97 |
57 // Swap the left and right channels of |frame|. Fails silently if |frame| is | 98 // Swap the left and right channels of |frame|. Fails silently if |frame| is |
58 // not stereo. | 99 // not stereo. |
59 static void SwapStereoChannels(AudioFrame* frame); | 100 static void SwapStereoChannels(AudioFrame* frame); |
60 | 101 |
61 // Conditionally zero out contents of |frame| for implementing audio mute: | 102 // Conditionally zero out contents of |frame| for implementing audio mute: |
62 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. | 103 // |previous_frame_muted| && |current_frame_muted| - Zero out whole frame. |
63 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. | 104 // |previous_frame_muted| && !|current_frame_muted| - Fade-in at frame start. |
64 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. | 105 // !|previous_frame_muted| && |current_frame_muted| - Fade-out at frame end. |
65 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. | 106 // !|previous_frame_muted| && !|current_frame_muted| - Leave frame untouched. |
66 static void Mute(AudioFrame* frame, | 107 static void Mute(AudioFrame* frame, |
67 bool previous_frame_muted, | 108 bool previous_frame_muted, |
68 bool current_frame_muted); | 109 bool current_frame_muted); |
69 | 110 |
70 // Zero out contents of frame. | 111 // Zero out contents of frame. |
71 static void Mute(AudioFrame* frame); | 112 static void Mute(AudioFrame* frame); |
72 | 113 |
73 // Halve samples in |frame|. | 114 // Halve samples in |frame|. |
74 static void ApplyHalfGain(AudioFrame* frame); | 115 static void ApplyHalfGain(AudioFrame* frame); |
75 | 116 |
76 static int Scale(float left, float right, AudioFrame& frame); | 117 static int Scale(float left, float right, AudioFrame& frame); |
77 | 118 |
78 static int ScaleWithSat(float scale, AudioFrame& frame); | 119 static int ScaleWithSat(float scale, AudioFrame& frame); |
79 }; | 120 }; |
80 | 121 |
81 } // namespace webrtc | 122 } // namespace webrtc |
82 | 123 |
83 #endif // WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ | 124 #endif // WEBRTC_AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_ |
OLD | NEW |