Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: webrtc/modules/audio_processing/level_controller/down_sampler.cc

Issue 2090583002: New module for the adaptive level controlling functionality in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected the initial behavior for the peak level estimate, and ensured a nonzero minimum peak leveā€¦ Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/level_controller/down_sampler.h"
12
13 #include <string.h>
14 #include <vector>
15
16 #include "webrtc/base/checks.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/modules/audio_processing/level_controller/biquad_filter.h"
19 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
20
21 namespace webrtc {
22 namespace {
23
24 // Bandlimiter coefficients computed based on that only
25 // the first 40 bins of the spectrum for the downsampled
26 // signal are used.
27 // [B,A] = butter(2,(41/64*4000)/8000)
28 const BiQuadCoefficients kLowPassFilterCoefficients_16kHz = {
29 {0.1455f, 0.2911f, 0.1455f},
30 {-0.6698f, 0.2520f}};
31
32 // [B,A] = butter(2,(41/64*4000)/16000)
33 const BiQuadCoefficients kLowPassFilterCoefficients_32kHz = {
34 {0.0462f, 0.0924f, 0.0462f},
35 {-1.3066f, 0.4915f}};
36
37 // [B,A] = butter(2,(41/64*4000)/24000)
38 const BiQuadCoefficients kLowPassFilterCoefficients_48kHz = {
39 {0.0226f, 0.0452f, 0.0226f},
40 {-1.5320f, 0.6224f}};
41
42 // TODO(peah): Increase in case there is problem with aliasing.
43 const int kNumCascadedBiquads = 1;
44
45 } // namespace
46
47 DownSampler::DownSampler(ApmDataDumper* data_dumper, int sample_rate_hz)
48 : data_dumper_(data_dumper), sample_rate_hz_(sample_rate_hz) {
hlundin-webrtc 2016/06/27 11:21:14 Initialize down_sampling_factor_ in the initialize
peah-webrtc 2016/06/27 22:51:47 Done.
49 RTC_DCHECK(sample_rate_hz_ == AudioProcessing::kSampleRate8kHz ||
50 sample_rate_hz_ == AudioProcessing::kSampleRate16kHz ||
51 sample_rate_hz_ == AudioProcessing::kSampleRate32kHz ||
52 sample_rate_hz_ == AudioProcessing::kSampleRate48kHz);
53 if (sample_rate_hz_ == AudioProcessing::kSampleRate16kHz) {
54 low_pass_filter_.reset(new BiQuadFilter(kLowPassFilterCoefficients_16kHz,
55 kNumCascadedBiquads));
56 down_sampling_factor_ = 2;
57 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate32kHz) {
58 low_pass_filter_.reset(new BiQuadFilter(kLowPassFilterCoefficients_32kHz,
59 kNumCascadedBiquads));
60 down_sampling_factor_ = 4;
61 } else if (sample_rate_hz_ == AudioProcessing::kSampleRate48kHz) {
62 low_pass_filter_.reset(new BiQuadFilter(kLowPassFilterCoefficients_48kHz,
63 kNumCascadedBiquads));
64 down_sampling_factor_ = 6;
65 } else {
66 low_pass_filter_.reset();
67 down_sampling_factor_ = 1;
68 }
69 }
70 DownSampler::~DownSampler() {}
71
72 void DownSampler::DownSample(rtc::ArrayView<const float> in,
73 rtc::ArrayView<float> out) {
74 data_dumper_->DumpWav("lc_down_sampler_input", in, sample_rate_hz_, 1);
75 RTC_DCHECK_EQ(static_cast<size_t>(sample_rate_hz_ *
76 AudioProcessing::kChunkSizeMs / 1000),
77 in.size());
78 RTC_DCHECK_EQ(static_cast<size_t>(AudioProcessing::kSampleRate8kHz *
79 AudioProcessing::kChunkSizeMs / 1000),
80 out.size());
81 const size_t kMaxNumFrames =
82 AudioProcessing::kSampleRate48kHz * AudioProcessing::kChunkSizeMs / 1000;
83 float x[kMaxNumFrames];
84
85 // Band-limit the signal to 4 kHz.
86 if (sample_rate_hz_ != AudioProcessing::kSampleRate8kHz) {
87 low_pass_filter_->Process(in, rtc::ArrayView<float>(x, in.size()));
88 }
89
90 // Downsample the signal.
91 size_t k = 0;
92 for (size_t j = 0; j < out.size(); ++j) {
93 RTC_DCHECK_GT(kMaxNumFrames, k);
94 out[j] = x[k];
hlundin-webrtc 2016/06/27 11:21:14 When sample_rate_hz_ == AudioProcessing::kSampleRa
peah-webrtc 2016/06/27 22:51:47 Great find! Done.
95 k += down_sampling_factor_;
96 }
97
98 data_dumper_->DumpWav("lc_down_sampler_output", out,
99 AudioProcessing::kSampleRate8kHz, 1);
100 }
101
102 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698