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

Side by Side Diff: webrtc/modules/audio_processing/audio_buffer.cc

Issue 2320053003: webrtc/modules/audio_processing: Use RTC_DCHECK() instead of assert() (Closed)
Patch Set: rebase Created 4 years, 3 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
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/modules/audio_processing/audio_buffer.h" 11 #include "webrtc/modules/audio_processing/audio_buffer.h"
12 12
13 #include "webrtc/base/checks.h"
13 #include "webrtc/common_audio/include/audio_util.h" 14 #include "webrtc/common_audio/include/audio_util.h"
14 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" 15 #include "webrtc/common_audio/resampler/push_sinc_resampler.h"
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 16 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
16 #include "webrtc/common_audio/channel_buffer.h" 17 #include "webrtc/common_audio/channel_buffer.h"
17 #include "webrtc/modules/audio_processing/common.h" 18 #include "webrtc/modules/audio_processing/common.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 namespace { 21 namespace {
21 22
22 const size_t kSamplesPer16kHzChannel = 160; 23 const size_t kSamplesPer16kHzChannel = 160;
23 const size_t kSamplesPer32kHzChannel = 320; 24 const size_t kSamplesPer32kHzChannel = 320;
24 const size_t kSamplesPer48kHzChannel = 480; 25 const size_t kSamplesPer48kHzChannel = 480;
25 26
26 int KeyboardChannelIndex(const StreamConfig& stream_config) { 27 int KeyboardChannelIndex(const StreamConfig& stream_config) {
27 if (!stream_config.has_keyboard()) { 28 if (!stream_config.has_keyboard()) {
28 assert(false); 29 RTC_NOTREACHED();
29 return 0; 30 return 0;
30 } 31 }
31 32
32 return stream_config.num_channels(); 33 return stream_config.num_channels();
33 } 34 }
34 35
35 size_t NumBandsFromSamplesPerChannel(size_t num_frames) { 36 size_t NumBandsFromSamplesPerChannel(size_t num_frames) {
36 size_t num_bands = 1; 37 size_t num_bands = 1;
37 if (num_frames == kSamplesPer32kHzChannel || 38 if (num_frames == kSamplesPer32kHzChannel ||
38 num_frames == kSamplesPer48kHzChannel) { 39 num_frames == kSamplesPer48kHzChannel) {
(...skipping 15 matching lines...) Expand all
54 num_proc_channels_(num_process_channels), 55 num_proc_channels_(num_process_channels),
55 output_num_frames_(output_num_frames), 56 output_num_frames_(output_num_frames),
56 num_channels_(num_process_channels), 57 num_channels_(num_process_channels),
57 num_bands_(NumBandsFromSamplesPerChannel(proc_num_frames_)), 58 num_bands_(NumBandsFromSamplesPerChannel(proc_num_frames_)),
58 num_split_frames_(rtc::CheckedDivExact(proc_num_frames_, num_bands_)), 59 num_split_frames_(rtc::CheckedDivExact(proc_num_frames_, num_bands_)),
59 mixed_low_pass_valid_(false), 60 mixed_low_pass_valid_(false),
60 reference_copied_(false), 61 reference_copied_(false),
61 activity_(AudioFrame::kVadUnknown), 62 activity_(AudioFrame::kVadUnknown),
62 keyboard_data_(NULL), 63 keyboard_data_(NULL),
63 data_(new IFChannelBuffer(proc_num_frames_, num_proc_channels_)) { 64 data_(new IFChannelBuffer(proc_num_frames_, num_proc_channels_)) {
64 assert(input_num_frames_ > 0); 65 RTC_DCHECK_GT(input_num_frames_, 0u);
65 assert(proc_num_frames_ > 0); 66 RTC_DCHECK_GT(proc_num_frames_, 0u);
66 assert(output_num_frames_ > 0); 67 RTC_DCHECK_GT(output_num_frames_, 0u);
67 assert(num_input_channels_ > 0); 68 RTC_DCHECK_GT(num_input_channels_, 0u);
68 assert(num_proc_channels_ > 0 && num_proc_channels_ <= num_input_channels_); 69 RTC_DCHECK_GT(num_proc_channels_, 0u);
70 RTC_DCHECK_LE(num_proc_channels_, num_input_channels_);
69 71
70 if (input_num_frames_ != proc_num_frames_ || 72 if (input_num_frames_ != proc_num_frames_ ||
71 output_num_frames_ != proc_num_frames_) { 73 output_num_frames_ != proc_num_frames_) {
72 // Create an intermediate buffer for resampling. 74 // Create an intermediate buffer for resampling.
73 process_buffer_.reset(new ChannelBuffer<float>(proc_num_frames_, 75 process_buffer_.reset(new ChannelBuffer<float>(proc_num_frames_,
74 num_proc_channels_)); 76 num_proc_channels_));
75 77
76 if (input_num_frames_ != proc_num_frames_) { 78 if (input_num_frames_ != proc_num_frames_) {
77 for (size_t i = 0; i < num_proc_channels_; ++i) { 79 for (size_t i = 0; i < num_proc_channels_; ++i) {
78 input_resamplers_.push_back(std::unique_ptr<PushSincResampler>( 80 input_resamplers_.push_back(std::unique_ptr<PushSincResampler>(
(...skipping 16 matching lines...) Expand all
95 splitting_filter_.reset(new SplittingFilter(num_proc_channels_, 97 splitting_filter_.reset(new SplittingFilter(num_proc_channels_,
96 num_bands_, 98 num_bands_,
97 proc_num_frames_)); 99 proc_num_frames_));
98 } 100 }
99 } 101 }
100 102
101 AudioBuffer::~AudioBuffer() {} 103 AudioBuffer::~AudioBuffer() {}
102 104
103 void AudioBuffer::CopyFrom(const float* const* data, 105 void AudioBuffer::CopyFrom(const float* const* data,
104 const StreamConfig& stream_config) { 106 const StreamConfig& stream_config) {
105 assert(stream_config.num_frames() == input_num_frames_); 107 RTC_DCHECK_EQ(stream_config.num_frames(), input_num_frames_);
106 assert(stream_config.num_channels() == num_input_channels_); 108 RTC_DCHECK_EQ(stream_config.num_channels(), num_input_channels_);
107 InitForNewData(); 109 InitForNewData();
108 // Initialized lazily because there's a different condition in 110 // Initialized lazily because there's a different condition in
109 // DeinterleaveFrom. 111 // DeinterleaveFrom.
110 const bool need_to_downmix = 112 const bool need_to_downmix =
111 num_input_channels_ > 1 && num_proc_channels_ == 1; 113 num_input_channels_ > 1 && num_proc_channels_ == 1;
112 if (need_to_downmix && !input_buffer_) { 114 if (need_to_downmix && !input_buffer_) {
113 input_buffer_.reset( 115 input_buffer_.reset(
114 new IFChannelBuffer(input_num_frames_, num_proc_channels_)); 116 new IFChannelBuffer(input_num_frames_, num_proc_channels_));
115 } 117 }
116 118
(...skipping 23 matching lines...) Expand all
140 // Convert to the S16 range. 142 // Convert to the S16 range.
141 for (size_t i = 0; i < num_proc_channels_; ++i) { 143 for (size_t i = 0; i < num_proc_channels_; ++i) {
142 FloatToFloatS16(data_ptr[i], 144 FloatToFloatS16(data_ptr[i],
143 proc_num_frames_, 145 proc_num_frames_,
144 data_->fbuf()->channels()[i]); 146 data_->fbuf()->channels()[i]);
145 } 147 }
146 } 148 }
147 149
148 void AudioBuffer::CopyTo(const StreamConfig& stream_config, 150 void AudioBuffer::CopyTo(const StreamConfig& stream_config,
149 float* const* data) { 151 float* const* data) {
150 assert(stream_config.num_frames() == output_num_frames_); 152 RTC_DCHECK_EQ(stream_config.num_frames(), output_num_frames_);
151 assert(stream_config.num_channels() == num_channels_ || num_channels_ == 1); 153 RTC_DCHECK(stream_config.num_channels() == num_channels_ ||
154 num_channels_ == 1);
152 155
153 // Convert to the float range. 156 // Convert to the float range.
154 float* const* data_ptr = data; 157 float* const* data_ptr = data;
155 if (output_num_frames_ != proc_num_frames_) { 158 if (output_num_frames_ != proc_num_frames_) {
156 // Convert to an intermediate buffer for subsequent resampling. 159 // Convert to an intermediate buffer for subsequent resampling.
157 data_ptr = process_buffer_->channels(); 160 data_ptr = process_buffer_->channels();
158 } 161 }
159 for (size_t i = 0; i < num_channels_; ++i) { 162 for (size_t i = 0; i < num_channels_; ++i) {
160 FloatS16ToFloat(data_->fbuf()->channels()[i], 163 FloatS16ToFloat(data_->fbuf()->channels()[i],
161 proc_num_frames_, 164 proc_num_frames_,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // We don't resample the keyboard channel. 370 // We don't resample the keyboard channel.
368 return input_num_frames_; 371 return input_num_frames_;
369 } 372 }
370 373
371 size_t AudioBuffer::num_bands() const { 374 size_t AudioBuffer::num_bands() const {
372 return num_bands_; 375 return num_bands_;
373 } 376 }
374 377
375 // The resampler is only for supporting 48kHz to 16kHz in the reverse stream. 378 // The resampler is only for supporting 48kHz to 16kHz in the reverse stream.
376 void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) { 379 void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) {
377 assert(frame->num_channels_ == num_input_channels_); 380 RTC_DCHECK_EQ(frame->num_channels_, num_input_channels_);
378 assert(frame->samples_per_channel_ == input_num_frames_); 381 RTC_DCHECK_EQ(frame->samples_per_channel_, input_num_frames_);
379 InitForNewData(); 382 InitForNewData();
380 // Initialized lazily because there's a different condition in CopyFrom. 383 // Initialized lazily because there's a different condition in CopyFrom.
381 if ((input_num_frames_ != proc_num_frames_) && !input_buffer_) { 384 if ((input_num_frames_ != proc_num_frames_) && !input_buffer_) {
382 input_buffer_.reset( 385 input_buffer_.reset(
383 new IFChannelBuffer(input_num_frames_, num_proc_channels_)); 386 new IFChannelBuffer(input_num_frames_, num_proc_channels_));
384 } 387 }
385 activity_ = frame->vad_activity_; 388 activity_ = frame->vad_activity_;
386 389
387 int16_t* const* deinterleaved; 390 int16_t* const* deinterleaved;
388 if (input_num_frames_ == proc_num_frames_) { 391 if (input_num_frames_ == proc_num_frames_) {
389 deinterleaved = data_->ibuf()->channels(); 392 deinterleaved = data_->ibuf()->channels();
390 } else { 393 } else {
391 deinterleaved = input_buffer_->ibuf()->channels(); 394 deinterleaved = input_buffer_->ibuf()->channels();
392 } 395 }
393 if (num_proc_channels_ == 1) { 396 if (num_proc_channels_ == 1) {
394 // Downmix and deinterleave simultaneously. 397 // Downmix and deinterleave simultaneously.
395 DownmixInterleavedToMono(frame->data_, input_num_frames_, 398 DownmixInterleavedToMono(frame->data_, input_num_frames_,
396 num_input_channels_, deinterleaved[0]); 399 num_input_channels_, deinterleaved[0]);
397 } else { 400 } else {
398 assert(num_proc_channels_ == num_input_channels_); 401 RTC_DCHECK_EQ(num_proc_channels_, num_input_channels_);
399 Deinterleave(frame->data_, 402 Deinterleave(frame->data_,
400 input_num_frames_, 403 input_num_frames_,
401 num_proc_channels_, 404 num_proc_channels_,
402 deinterleaved); 405 deinterleaved);
403 } 406 }
404 407
405 // Resample. 408 // Resample.
406 if (input_num_frames_ != proc_num_frames_) { 409 if (input_num_frames_ != proc_num_frames_) {
407 for (size_t i = 0; i < num_proc_channels_; ++i) { 410 for (size_t i = 0; i < num_proc_channels_; ++i) {
408 input_resamplers_[i]->Resample(input_buffer_->fbuf_const()->channels()[i], 411 input_resamplers_[i]->Resample(input_buffer_->fbuf_const()->channels()[i],
409 input_num_frames_, 412 input_num_frames_,
410 data_->fbuf()->channels()[i], 413 data_->fbuf()->channels()[i],
411 proc_num_frames_); 414 proc_num_frames_);
412 } 415 }
413 } 416 }
414 } 417 }
415 418
416 void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) { 419 void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) {
417 frame->vad_activity_ = activity_; 420 frame->vad_activity_ = activity_;
418 if (!data_changed) { 421 if (!data_changed) {
419 return; 422 return;
420 } 423 }
421 424
422 assert(frame->num_channels_ == num_channels_ || num_channels_ == 1); 425 RTC_DCHECK(frame->num_channels_ == num_channels_ || num_channels_ == 1);
423 assert(frame->samples_per_channel_ == output_num_frames_); 426 RTC_DCHECK_EQ(frame->samples_per_channel_, output_num_frames_);
424 427
425 // Resample if necessary. 428 // Resample if necessary.
426 IFChannelBuffer* data_ptr = data_.get(); 429 IFChannelBuffer* data_ptr = data_.get();
427 if (proc_num_frames_ != output_num_frames_) { 430 if (proc_num_frames_ != output_num_frames_) {
428 if (!output_buffer_) { 431 if (!output_buffer_) {
429 output_buffer_.reset( 432 output_buffer_.reset(
430 new IFChannelBuffer(output_num_frames_, num_channels_)); 433 new IFChannelBuffer(output_num_frames_, num_channels_));
431 } 434 }
432 for (size_t i = 0; i < num_channels_; ++i) { 435 for (size_t i = 0; i < num_channels_; ++i) {
433 output_resamplers_[i]->Resample( 436 output_resamplers_[i]->Resample(
(...skipping 30 matching lines...) Expand all
464 467
465 void AudioBuffer::SplitIntoFrequencyBands() { 468 void AudioBuffer::SplitIntoFrequencyBands() {
466 splitting_filter_->Analysis(data_.get(), split_data_.get()); 469 splitting_filter_->Analysis(data_.get(), split_data_.get());
467 } 470 }
468 471
469 void AudioBuffer::MergeFrequencyBands() { 472 void AudioBuffer::MergeFrequencyBands() {
470 splitting_filter_->Synthesis(split_data_.get(), data_.get()); 473 splitting_filter_->Synthesis(split_data_.get(), data_.get());
471 } 474 }
472 475
473 } // namespace webrtc 476 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/agc/loudness_histogram.cc ('k') | webrtc/modules/audio_processing/audio_processing_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698