OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate32kHz) { | 62 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate32kHz) { |
63 low_pass_filter_.Initialize(kLowPassFilterCoefficients_32kHz); | 63 low_pass_filter_.Initialize(kLowPassFilterCoefficients_32kHz); |
64 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate48kHz) { | 64 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate48kHz) { |
65 low_pass_filter_.Initialize(kLowPassFilterCoefficients_48kHz); | 65 low_pass_filter_.Initialize(kLowPassFilterCoefficients_48kHz); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 void DownSampler::DownSample(rtc::ArrayView<const float> in, | 69 void DownSampler::DownSample(rtc::ArrayView<const float> in, |
70 rtc::ArrayView<float> out) { | 70 rtc::ArrayView<float> out) { |
71 data_dumper_->DumpWav("lc_down_sampler_input", in, sample_rate_hz_, 1); | 71 data_dumper_->DumpWav("lc_down_sampler_input", in, sample_rate_hz_, 1); |
72 RTC_DCHECK_EQ(static_cast<size_t>(sample_rate_hz_ * | 72 RTC_DCHECK_EQ(sample_rate_hz_ * AudioProcessing::kChunkSizeMs / 1000, |
73 AudioProcessing::kChunkSizeMs / 1000), | |
74 in.size()); | 73 in.size()); |
75 RTC_DCHECK_EQ(static_cast<size_t>(AudioProcessing::kSampleRate8kHz * | 74 RTC_DCHECK_EQ( |
76 AudioProcessing::kChunkSizeMs / 1000), | 75 AudioProcessing::kSampleRate8kHz * AudioProcessing::kChunkSizeMs / 1000, |
77 out.size()); | 76 out.size()); |
78 const size_t kMaxNumFrames = | 77 const size_t kMaxNumFrames = |
79 AudioProcessing::kSampleRate48kHz * AudioProcessing::kChunkSizeMs / 1000; | 78 AudioProcessing::kSampleRate48kHz * AudioProcessing::kChunkSizeMs / 1000; |
80 float x[kMaxNumFrames]; | 79 float x[kMaxNumFrames]; |
81 | 80 |
82 // Band-limit the signal to 4 kHz. | 81 // Band-limit the signal to 4 kHz. |
83 if (sample_rate_hz_ != AudioProcessing::kSampleRate8kHz) { | 82 if (sample_rate_hz_ != AudioProcessing::kSampleRate8kHz) { |
84 low_pass_filter_.Process(in, rtc::ArrayView<float>(x, in.size())); | 83 low_pass_filter_.Process(in, rtc::ArrayView<float>(x, in.size())); |
85 | 84 |
86 // Downsample the signal. | 85 // Downsample the signal. |
87 size_t k = 0; | 86 size_t k = 0; |
88 for (size_t j = 0; j < out.size(); ++j) { | 87 for (size_t j = 0; j < out.size(); ++j) { |
89 RTC_DCHECK_GT(kMaxNumFrames, k); | 88 RTC_DCHECK_GT(kMaxNumFrames, k); |
90 out[j] = x[k]; | 89 out[j] = x[k]; |
91 k += down_sampling_factor_; | 90 k += down_sampling_factor_; |
92 } | 91 } |
93 } else { | 92 } else { |
94 std::copy(in.data(), in.data() + in.size(), out.data()); | 93 std::copy(in.data(), in.data() + in.size(), out.data()); |
95 } | 94 } |
96 | 95 |
97 data_dumper_->DumpWav("lc_down_sampler_output", out, | 96 data_dumper_->DumpWav("lc_down_sampler_output", out, |
98 AudioProcessing::kSampleRate8kHz, 1); | 97 AudioProcessing::kSampleRate8kHz, 1); |
99 } | 98 } |
100 | 99 |
101 } // namespace webrtc | 100 } // namespace webrtc |
OLD | NEW |