| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 14 matching lines...) Expand all Loading... |
| 25 num_channels_(0) { | 25 num_channels_(0) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 template <typename T> | 28 template <typename T> |
| 29 PushResampler<T>::~PushResampler() { | 29 PushResampler<T>::~PushResampler() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 template <typename T> | 32 template <typename T> |
| 33 int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz, | 33 int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz, |
| 34 int dst_sample_rate_hz, | 34 int dst_sample_rate_hz, |
| 35 int num_channels) { | 35 size_t num_channels) { |
| 36 if (src_sample_rate_hz == src_sample_rate_hz_ && | 36 if (src_sample_rate_hz == src_sample_rate_hz_ && |
| 37 dst_sample_rate_hz == dst_sample_rate_hz_ && | 37 dst_sample_rate_hz == dst_sample_rate_hz_ && |
| 38 num_channels == num_channels_) | 38 num_channels == num_channels_) |
| 39 // No-op if settings haven't changed. | 39 // No-op if settings haven't changed. |
| 40 return 0; | 40 return 0; |
| 41 | 41 |
| 42 if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 || | 42 if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 || |
| 43 num_channels <= 0 || num_channels > 2) | 43 num_channels <= 0 || num_channels > 2) |
| 44 return -1; | 44 return -1; |
| 45 | 45 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono, | 61 sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono, |
| 62 dst_size_10ms_mono)); | 62 dst_size_10ms_mono)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 return 0; | 65 return 0; |
| 66 } | 66 } |
| 67 | 67 |
| 68 template <typename T> | 68 template <typename T> |
| 69 int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst, | 69 int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst, |
| 70 size_t dst_capacity) { | 70 size_t dst_capacity) { |
| 71 const size_t src_size_10ms = | 71 const size_t src_size_10ms = src_sample_rate_hz_ * num_channels_ / 100; |
| 72 static_cast<size_t>(src_sample_rate_hz_ * num_channels_ / 100); | 72 const size_t dst_size_10ms = dst_sample_rate_hz_ * num_channels_ / 100; |
| 73 const size_t dst_size_10ms = | |
| 74 static_cast<size_t>(dst_sample_rate_hz_ * num_channels_ / 100); | |
| 75 if (src_length != src_size_10ms || dst_capacity < dst_size_10ms) | 73 if (src_length != src_size_10ms || dst_capacity < dst_size_10ms) |
| 76 return -1; | 74 return -1; |
| 77 | 75 |
| 78 if (src_sample_rate_hz_ == dst_sample_rate_hz_) { | 76 if (src_sample_rate_hz_ == dst_sample_rate_hz_) { |
| 79 // The old resampler provides this memcpy facility in the case of matching | 77 // The old resampler provides this memcpy facility in the case of matching |
| 80 // sample rates, so reproduce it here for the sinc resampler. | 78 // sample rates, so reproduce it here for the sinc resampler. |
| 81 memcpy(dst, src, src_length * sizeof(T)); | 79 memcpy(dst, src, src_length * sizeof(T)); |
| 82 return static_cast<int>(src_length); | 80 return static_cast<int>(src_length); |
| 83 } | 81 } |
| 84 if (num_channels_ == 2) { | 82 if (num_channels_ == 2) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 return static_cast<int>( | 99 return static_cast<int>( |
| 102 sinc_resampler_->Resample(src, src_length, dst, dst_capacity)); | 100 sinc_resampler_->Resample(src, src_length, dst, dst_capacity)); |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 // Explictly generate required instantiations. | 104 // Explictly generate required instantiations. |
| 107 template class PushResampler<int16_t>; | 105 template class PushResampler<int16_t>; |
| 108 template class PushResampler<float>; | 106 template class PushResampler<float>; |
| 109 | 107 |
| 110 } // namespace webrtc | 108 } // namespace webrtc |
| OLD | NEW |