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 29 matching lines...) Expand all Loading... | |
40 } | 40 } |
41 | 41 |
42 if (resampler->InitializeIfNeeded(src_frame.sample_rate_hz_, | 42 if (resampler->InitializeIfNeeded(src_frame.sample_rate_hz_, |
43 dst_frame->sample_rate_hz_, | 43 dst_frame->sample_rate_hz_, |
44 audio_ptr_num_channels) == -1) { | 44 audio_ptr_num_channels) == -1) { |
45 LOG_FERR3(LS_ERROR, InitializeIfNeeded, src_frame.sample_rate_hz_, | 45 LOG_FERR3(LS_ERROR, InitializeIfNeeded, src_frame.sample_rate_hz_, |
46 dst_frame->sample_rate_hz_, audio_ptr_num_channels); | 46 dst_frame->sample_rate_hz_, audio_ptr_num_channels); |
47 assert(false); | 47 assert(false); |
48 } | 48 } |
49 | 49 |
50 const int src_length = src_frame.samples_per_channel_ * | 50 const size_t src_length = src_frame.samples_per_channel_ * |
51 audio_ptr_num_channels; | 51 audio_ptr_num_channels; |
52 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, | 52 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, |
53 AudioFrame::kMaxDataSizeSamples); | 53 AudioFrame::kMaxDataSizeSamples); |
54 if (out_length == -1) { | 54 if (out_length == -1) { |
55 LOG_FERR3(LS_ERROR, Resample, audio_ptr, src_length, dst_frame->data_); | 55 LOG_FERR3(LS_ERROR, Resample, audio_ptr, src_length, dst_frame->data_); |
56 assert(false); | 56 assert(false); |
57 } | 57 } |
58 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels; | 58 dst_frame->samples_per_channel_ = |
59 static_cast<size_t>(out_length / audio_ptr_num_channels); | |
59 | 60 |
60 // Upmix after resampling. | 61 // Upmix after resampling. |
61 if (src_frame.num_channels_ == 1 && dst_frame->num_channels_ == 2) { | 62 if (src_frame.num_channels_ == 1 && dst_frame->num_channels_ == 2) { |
62 // The audio in dst_frame really is mono at this point; MonoToStereo will | 63 // The audio in dst_frame really is mono at this point; MonoToStereo will |
63 // set this back to stereo. | 64 // set this back to stereo. |
64 dst_frame->num_channels_ = 1; | 65 dst_frame->num_channels_ = 1; |
65 AudioFrameOperations::MonoToStereo(dst_frame); | 66 AudioFrameOperations::MonoToStereo(dst_frame); |
66 } | 67 } |
67 | 68 |
68 dst_frame->timestamp_ = src_frame.timestamp_; | 69 dst_frame->timestamp_ = src_frame.timestamp_; |
69 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_; | 70 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_; |
70 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_; | 71 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_; |
71 } | 72 } |
72 | 73 |
73 void DownConvertToCodecFormat(const int16_t* src_data, | 74 void DownConvertToCodecFormat(const int16_t* src_data, |
74 int samples_per_channel, | 75 size_t samples_per_channel, |
75 int num_channels, | 76 int num_channels, |
pbos-webrtc
2015/07/14 08:15:10
size_t for num_channels?
| |
76 int sample_rate_hz, | 77 int sample_rate_hz, |
77 int codec_num_channels, | 78 int codec_num_channels, |
78 int codec_rate_hz, | 79 int codec_rate_hz, |
79 int16_t* mono_buffer, | 80 int16_t* mono_buffer, |
80 PushResampler<int16_t>* resampler, | 81 PushResampler<int16_t>* resampler, |
81 AudioFrame* dst_af) { | 82 AudioFrame* dst_af) { |
82 assert(samples_per_channel <= kMaxMonoDataSizeSamples); | 83 assert(samples_per_channel <= kMaxMonoDataSizeSamples); |
83 assert(num_channels == 1 || num_channels == 2); | 84 assert(num_channels == 1 || num_channels == 2); |
84 assert(codec_num_channels == 1 || codec_num_channels == 2); | 85 assert(codec_num_channels == 1 || codec_num_channels == 2); |
85 dst_af->Reset(); | 86 dst_af->Reset(); |
(...skipping 14 matching lines...) Expand all Loading... | |
100 if (resampler->InitializeIfNeeded( | 101 if (resampler->InitializeIfNeeded( |
101 sample_rate_hz, destination_rate, num_channels) != 0) { | 102 sample_rate_hz, destination_rate, num_channels) != 0) { |
102 LOG_FERR3(LS_ERROR, | 103 LOG_FERR3(LS_ERROR, |
103 InitializeIfNeeded, | 104 InitializeIfNeeded, |
104 sample_rate_hz, | 105 sample_rate_hz, |
105 destination_rate, | 106 destination_rate, |
106 num_channels); | 107 num_channels); |
107 assert(false); | 108 assert(false); |
108 } | 109 } |
109 | 110 |
110 const int in_length = samples_per_channel * num_channels; | 111 const size_t in_length = samples_per_channel * num_channels; |
111 int out_length = resampler->Resample( | 112 int out_length = resampler->Resample( |
112 src_data, in_length, dst_af->data_, AudioFrame::kMaxDataSizeSamples); | 113 src_data, in_length, dst_af->data_, AudioFrame::kMaxDataSizeSamples); |
113 if (out_length == -1) { | 114 if (out_length == -1) { |
114 LOG_FERR3(LS_ERROR, Resample, src_data, in_length, dst_af->data_); | 115 LOG_FERR3(LS_ERROR, Resample, src_data, in_length, dst_af->data_); |
115 assert(false); | 116 assert(false); |
116 } | 117 } |
117 | 118 |
118 dst_af->samples_per_channel_ = out_length / num_channels; | 119 dst_af->samples_per_channel_ = static_cast<size_t>(out_length / num_channels); |
119 dst_af->sample_rate_hz_ = destination_rate; | 120 dst_af->sample_rate_hz_ = destination_rate; |
120 dst_af->num_channels_ = num_channels; | 121 dst_af->num_channels_ = num_channels; |
121 } | 122 } |
122 | 123 |
123 void MixWithSat(int16_t target[], | 124 void MixWithSat(int16_t target[], |
124 int target_channel, | 125 int target_channel, |
125 const int16_t source[], | 126 const int16_t source[], |
126 int source_channel, | 127 int source_channel, |
127 int source_len) { | 128 size_t source_len) { |
128 assert(target_channel == 1 || target_channel == 2); | 129 assert(target_channel == 1 || target_channel == 2); |
129 assert(source_channel == 1 || source_channel == 2); | 130 assert(source_channel == 1 || source_channel == 2); |
130 | 131 |
131 if (target_channel == 2 && source_channel == 1) { | 132 if (target_channel == 2 && source_channel == 1) { |
132 // Convert source from mono to stereo. | 133 // Convert source from mono to stereo. |
133 int32_t left = 0; | 134 int32_t left = 0; |
134 int32_t right = 0; | 135 int32_t right = 0; |
135 for (int i = 0; i < source_len; ++i) { | 136 for (size_t i = 0; i < source_len; ++i) { |
136 left = source[i] + target[i * 2]; | 137 left = source[i] + target[i * 2]; |
137 right = source[i] + target[i * 2 + 1]; | 138 right = source[i] + target[i * 2 + 1]; |
138 target[i * 2] = WebRtcSpl_SatW32ToW16(left); | 139 target[i * 2] = WebRtcSpl_SatW32ToW16(left); |
139 target[i * 2 + 1] = WebRtcSpl_SatW32ToW16(right); | 140 target[i * 2 + 1] = WebRtcSpl_SatW32ToW16(right); |
140 } | 141 } |
141 } else if (target_channel == 1 && source_channel == 2) { | 142 } else if (target_channel == 1 && source_channel == 2) { |
142 // Convert source from stereo to mono. | 143 // Convert source from stereo to mono. |
143 int32_t temp = 0; | 144 int32_t temp = 0; |
144 for (int i = 0; i < source_len / 2; ++i) { | 145 for (size_t i = 0; i < source_len / 2; ++i) { |
145 temp = ((source[i * 2] + source[i * 2 + 1]) >> 1) + target[i]; | 146 temp = ((source[i * 2] + source[i * 2 + 1]) >> 1) + target[i]; |
146 target[i] = WebRtcSpl_SatW32ToW16(temp); | 147 target[i] = WebRtcSpl_SatW32ToW16(temp); |
147 } | 148 } |
148 } else { | 149 } else { |
149 int32_t temp = 0; | 150 int32_t temp = 0; |
150 for (int i = 0; i < source_len; ++i) { | 151 for (size_t i = 0; i < source_len; ++i) { |
151 temp = source[i] + target[i]; | 152 temp = source[i] + target[i]; |
152 target[i] = WebRtcSpl_SatW32ToW16(temp); | 153 target[i] = WebRtcSpl_SatW32ToW16(temp); |
153 } | 154 } |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 } // namespace voe | 158 } // namespace voe |
158 } // namespace webrtc | 159 } // namespace webrtc |
OLD | NEW |