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/modules/audio_processing/audio_buffer.h" | 11 #include "webrtc/modules/audio_processing/audio_buffer.h" |
12 | 12 |
13 #include "webrtc/common_audio/include/audio_util.h" | 13 #include "webrtc/common_audio/include/audio_util.h" |
14 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 14 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
16 #include "webrtc/common_audio/channel_buffer.h" | 16 #include "webrtc/common_audio/channel_buffer.h" |
17 #include "webrtc/modules/audio_processing/common.h" | 17 #include "webrtc/modules/audio_processing/common.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const int kSamplesPer16kHzChannel = 160; | 22 const size_t kSamplesPer16kHzChannel = 160; |
23 const int kSamplesPer32kHzChannel = 320; | 23 const size_t kSamplesPer32kHzChannel = 320; |
24 const int kSamplesPer48kHzChannel = 480; | 24 const size_t kSamplesPer48kHzChannel = 480; |
25 | 25 |
26 int KeyboardChannelIndex(const StreamConfig& stream_config) { | 26 int KeyboardChannelIndex(const StreamConfig& stream_config) { |
27 if (!stream_config.has_keyboard()) { | 27 if (!stream_config.has_keyboard()) { |
28 assert(false); | 28 assert(false); |
29 return -1; | 29 return -1; |
30 } | 30 } |
31 | 31 |
32 return stream_config.num_channels(); | 32 return stream_config.num_channels(); |
33 } | 33 } |
34 | 34 |
35 int NumBandsFromSamplesPerChannel(int num_frames) { | 35 size_t NumBandsFromSamplesPerChannel(size_t num_frames) { |
36 int num_bands = 1; | 36 size_t num_bands = 1; |
37 if (num_frames == kSamplesPer32kHzChannel || | 37 if (num_frames == kSamplesPer32kHzChannel || |
38 num_frames == kSamplesPer48kHzChannel) { | 38 num_frames == kSamplesPer48kHzChannel) { |
39 num_bands = rtc::CheckedDivExact(num_frames, | 39 num_bands = rtc::CheckedDivExact(num_frames, kSamplesPer16kHzChannel); |
40 static_cast<int>(kSamplesPer16kHzChannel)); | |
41 } | 40 } |
42 return num_bands; | 41 return num_bands; |
43 } | 42 } |
44 | 43 |
45 } // namespace | 44 } // namespace |
46 | 45 |
47 AudioBuffer::AudioBuffer(int input_num_frames, | 46 AudioBuffer::AudioBuffer(size_t input_num_frames, |
48 int num_input_channels, | 47 int num_input_channels, |
49 int process_num_frames, | 48 size_t process_num_frames, |
50 int num_process_channels, | 49 int num_process_channels, |
51 int output_num_frames) | 50 size_t output_num_frames) |
52 : input_num_frames_(input_num_frames), | 51 : input_num_frames_(input_num_frames), |
53 num_input_channels_(num_input_channels), | 52 num_input_channels_(num_input_channels), |
54 proc_num_frames_(process_num_frames), | 53 proc_num_frames_(process_num_frames), |
55 num_proc_channels_(num_process_channels), | 54 num_proc_channels_(num_process_channels), |
56 output_num_frames_(output_num_frames), | 55 output_num_frames_(output_num_frames), |
57 num_channels_(num_process_channels), | 56 num_channels_(num_process_channels), |
58 num_bands_(NumBandsFromSamplesPerChannel(proc_num_frames_)), | 57 num_bands_(NumBandsFromSamplesPerChannel(proc_num_frames_)), |
59 num_split_frames_(rtc::CheckedDivExact(proc_num_frames_, num_bands_)), | 58 num_split_frames_(rtc::CheckedDivExact(proc_num_frames_, num_bands_)), |
60 mixed_low_pass_valid_(false), | 59 mixed_low_pass_valid_(false), |
61 reference_copied_(false), | 60 reference_copied_(false), |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 337 } |
339 | 338 |
340 int AudioBuffer::num_channels() const { | 339 int AudioBuffer::num_channels() const { |
341 return num_channels_; | 340 return num_channels_; |
342 } | 341 } |
343 | 342 |
344 void AudioBuffer::set_num_channels(int num_channels) { | 343 void AudioBuffer::set_num_channels(int num_channels) { |
345 num_channels_ = num_channels; | 344 num_channels_ = num_channels; |
346 } | 345 } |
347 | 346 |
348 int AudioBuffer::num_frames() const { | 347 size_t AudioBuffer::num_frames() const { |
349 return proc_num_frames_; | 348 return proc_num_frames_; |
350 } | 349 } |
351 | 350 |
352 int AudioBuffer::num_frames_per_band() const { | 351 size_t AudioBuffer::num_frames_per_band() const { |
353 return num_split_frames_; | 352 return num_split_frames_; |
354 } | 353 } |
355 | 354 |
356 int AudioBuffer::num_keyboard_frames() const { | 355 size_t AudioBuffer::num_keyboard_frames() const { |
357 // We don't resample the keyboard channel. | 356 // We don't resample the keyboard channel. |
358 return input_num_frames_; | 357 return input_num_frames_; |
359 } | 358 } |
360 | 359 |
361 int AudioBuffer::num_bands() const { | 360 size_t AudioBuffer::num_bands() const { |
362 return num_bands_; | 361 return num_bands_; |
363 } | 362 } |
364 | 363 |
365 // The resampler is only for supporting 48kHz to 16kHz in the reverse stream. | 364 // The resampler is only for supporting 48kHz to 16kHz in the reverse stream. |
366 void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) { | 365 void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) { |
367 assert(frame->num_channels_ == num_input_channels_); | 366 assert(frame->num_channels_ == num_input_channels_); |
368 assert(frame->samples_per_channel_ == input_num_frames_); | 367 assert(frame->samples_per_channel_ == input_num_frames_); |
369 InitForNewData(); | 368 InitForNewData(); |
370 // Initialized lazily because there's a different condition in CopyFrom. | 369 // Initialized lazily because there's a different condition in CopyFrom. |
371 if ((input_num_frames_ != proc_num_frames_) && !input_buffer_) { | 370 if ((input_num_frames_ != proc_num_frames_) && !input_buffer_) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 437 |
439 void AudioBuffer::SplitIntoFrequencyBands() { | 438 void AudioBuffer::SplitIntoFrequencyBands() { |
440 splitting_filter_->Analysis(data_.get(), split_data_.get()); | 439 splitting_filter_->Analysis(data_.get(), split_data_.get()); |
441 } | 440 } |
442 | 441 |
443 void AudioBuffer::MergeFrequencyBands() { | 442 void AudioBuffer::MergeFrequencyBands() { |
444 splitting_filter_->Synthesis(split_data_.get(), data_.get()); | 443 splitting_filter_->Synthesis(split_data_.get(), data_.get()); |
445 } | 444 } |
446 | 445 |
447 } // namespace webrtc | 446 } // namespace webrtc |
OLD | NEW |