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 #include "webrtc/voice_engine/utility.h" | 11 #include "webrtc/voice_engine/utility.h" |
12 | 12 |
13 #include "webrtc/audio/utility/audio_frame_operations.h" | 13 #include "webrtc/audio/utility/audio_frame_operations.h" |
14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 16 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/modules/include/module_common_types.h" | 19 #include "webrtc/modules/include/module_common_types.h" |
20 #include "webrtc/voice_engine/voice_engine_defines.h" | 20 #include "webrtc/voice_engine/voice_engine_defines.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace voe { | 23 namespace voe { |
24 | 24 |
25 void RemixAndResample(const AudioFrame& src_frame, | 25 void RemixAndResample(const AudioFrame& src_frame, |
26 PushResampler<int16_t>* resampler, | 26 PushResampler<int16_t>* resampler, |
27 AudioFrame* dst_frame) { | 27 AudioFrame* dst_frame) { |
28 RemixAndResample(src_frame.data_, src_frame.samples_per_channel_, | 28 RemixAndResample(src_frame.data(), src_frame.samples_per_channel_, |
29 src_frame.num_channels_, src_frame.sample_rate_hz_, | 29 src_frame.num_channels_, src_frame.sample_rate_hz_, |
30 resampler, dst_frame); | 30 resampler, dst_frame); |
31 dst_frame->timestamp_ = src_frame.timestamp_; | 31 dst_frame->timestamp_ = src_frame.timestamp_; |
32 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_; | 32 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_; |
33 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_; | 33 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_; |
34 } | 34 } |
35 | 35 |
36 void RemixAndResample(const int16_t* src_data, | 36 void RemixAndResample(const int16_t* src_data, |
37 size_t samples_per_channel, | 37 size_t samples_per_channel, |
38 size_t num_channels, | 38 size_t num_channels, |
(...skipping 18 matching lines...) Expand all Loading... |
57 audio_ptr_num_channels = dst_frame->num_channels_; | 57 audio_ptr_num_channels = dst_frame->num_channels_; |
58 } | 58 } |
59 | 59 |
60 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_, | 60 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_, |
61 audio_ptr_num_channels) == -1) { | 61 audio_ptr_num_channels) == -1) { |
62 FATAL() << "InitializeIfNeeded failed: sample_rate_hz = " << sample_rate_hz | 62 FATAL() << "InitializeIfNeeded failed: sample_rate_hz = " << sample_rate_hz |
63 << ", dst_frame->sample_rate_hz_ = " << dst_frame->sample_rate_hz_ | 63 << ", dst_frame->sample_rate_hz_ = " << dst_frame->sample_rate_hz_ |
64 << ", audio_ptr_num_channels = " << audio_ptr_num_channels; | 64 << ", audio_ptr_num_channels = " << audio_ptr_num_channels; |
65 } | 65 } |
66 | 66 |
| 67 // TODO(yujo): for muted input frames, don't resample. Either 1) allow |
| 68 // resampler to return output length without doing the resample, so we know |
| 69 // how much to zero here; or 2) make resampler accept a hint that the input is |
| 70 // zeroed. |
67 const size_t src_length = samples_per_channel * audio_ptr_num_channels; | 71 const size_t src_length = samples_per_channel * audio_ptr_num_channels; |
68 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, | 72 int out_length = resampler->Resample(audio_ptr, src_length, |
| 73 dst_frame->mutable_data(), |
69 AudioFrame::kMaxDataSizeSamples); | 74 AudioFrame::kMaxDataSizeSamples); |
70 if (out_length == -1) { | 75 if (out_length == -1) { |
71 FATAL() << "Resample failed: audio_ptr = " << audio_ptr | 76 FATAL() << "Resample failed: audio_ptr = " << audio_ptr |
72 << ", src_length = " << src_length | 77 << ", src_length = " << src_length |
73 << ", dst_frame->data_ = " << dst_frame->data_; | 78 << ", dst_frame->mutable_data() = " << dst_frame->mutable_data(); |
74 } | 79 } |
75 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels; | 80 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels; |
76 | 81 |
77 // Upmix after resampling. | 82 // Upmix after resampling. |
78 if (num_channels == 1 && dst_frame->num_channels_ == 2) { | 83 if (num_channels == 1 && dst_frame->num_channels_ == 2) { |
79 // The audio in dst_frame really is mono at this point; MonoToStereo will | 84 // The audio in dst_frame really is mono at this point; MonoToStereo will |
80 // set this back to stereo. | 85 // set this back to stereo. |
81 dst_frame->num_channels_ = 1; | 86 dst_frame->num_channels_ = 1; |
82 AudioFrameOperations::MonoToStereo(dst_frame); | 87 AudioFrameOperations::MonoToStereo(dst_frame); |
83 } | 88 } |
(...skipping 30 matching lines...) Expand all Loading... |
114 int32_t temp = 0; | 119 int32_t temp = 0; |
115 for (size_t i = 0; i < source_len; ++i) { | 120 for (size_t i = 0; i < source_len; ++i) { |
116 temp = source[i] + target[i]; | 121 temp = source[i] + target[i]; |
117 target[i] = WebRtcSpl_SatW32ToW16(temp); | 122 target[i] = WebRtcSpl_SatW32ToW16(temp); |
118 } | 123 } |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
122 } // namespace voe | 127 } // namespace voe |
123 } // namespace webrtc | 128 } // namespace webrtc |
OLD | NEW |