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

Side by Side Diff: webrtc/voice_engine/utility.cc

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix compile Created 4 years, 11 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
« no previous file with comments | « webrtc/voice_engine/utility.h ('k') | webrtc/voice_engine/voe_base_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 16 matching lines...) Expand all
27 RemixAndResample(src_frame.data_, src_frame.samples_per_channel_, 27 RemixAndResample(src_frame.data_, src_frame.samples_per_channel_,
28 src_frame.num_channels_, src_frame.sample_rate_hz_, 28 src_frame.num_channels_, src_frame.sample_rate_hz_,
29 resampler, dst_frame); 29 resampler, dst_frame);
30 dst_frame->timestamp_ = src_frame.timestamp_; 30 dst_frame->timestamp_ = src_frame.timestamp_;
31 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_; 31 dst_frame->elapsed_time_ms_ = src_frame.elapsed_time_ms_;
32 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_; 32 dst_frame->ntp_time_ms_ = src_frame.ntp_time_ms_;
33 } 33 }
34 34
35 void RemixAndResample(const int16_t* src_data, 35 void RemixAndResample(const int16_t* src_data,
36 size_t samples_per_channel, 36 size_t samples_per_channel,
37 int num_channels, 37 size_t num_channels,
38 int sample_rate_hz, 38 int sample_rate_hz,
39 PushResampler<int16_t>* resampler, 39 PushResampler<int16_t>* resampler,
40 AudioFrame* dst_frame) { 40 AudioFrame* dst_frame) {
41 const int16_t* audio_ptr = src_data; 41 const int16_t* audio_ptr = src_data;
42 int audio_ptr_num_channels = num_channels; 42 size_t audio_ptr_num_channels = num_channels;
43 int16_t mono_audio[AudioFrame::kMaxDataSizeSamples]; 43 int16_t mono_audio[AudioFrame::kMaxDataSizeSamples];
44 44
45 // Downmix before resampling. 45 // Downmix before resampling.
46 if (num_channels == 2 && dst_frame->num_channels_ == 1) { 46 if (num_channels == 2 && dst_frame->num_channels_ == 1) {
47 AudioFrameOperations::StereoToMono(src_data, samples_per_channel, 47 AudioFrameOperations::StereoToMono(src_data, samples_per_channel,
48 mono_audio); 48 mono_audio);
49 audio_ptr = mono_audio; 49 audio_ptr = mono_audio;
50 audio_ptr_num_channels = 1; 50 audio_ptr_num_channels = 1;
51 } 51 }
52 52
53 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_, 53 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_,
54 audio_ptr_num_channels) == -1) { 54 audio_ptr_num_channels) == -1) {
55 LOG(LS_ERROR) << "InitializeIfNeeded failed: sample_rate_hz = " 55 LOG(LS_ERROR) << "InitializeIfNeeded failed: sample_rate_hz = "
56 << sample_rate_hz << ", dst_frame->sample_rate_hz_ = " 56 << sample_rate_hz << ", dst_frame->sample_rate_hz_ = "
57 << dst_frame->sample_rate_hz_ 57 << dst_frame->sample_rate_hz_
58 << ", audio_ptr_num_channels = " << audio_ptr_num_channels; 58 << ", audio_ptr_num_channels = " << audio_ptr_num_channels;
59 assert(false); 59 assert(false);
60 } 60 }
61 61
62 const size_t src_length = samples_per_channel * audio_ptr_num_channels; 62 const size_t src_length = samples_per_channel * audio_ptr_num_channels;
63 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, 63 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_,
64 AudioFrame::kMaxDataSizeSamples); 64 AudioFrame::kMaxDataSizeSamples);
65 if (out_length == -1) { 65 if (out_length == -1) {
66 LOG(LS_ERROR) << "Resample failed: audio_ptr = " << audio_ptr 66 LOG(LS_ERROR) << "Resample failed: audio_ptr = " << audio_ptr
67 << ", src_length = " << src_length 67 << ", src_length = " << src_length
68 << ", dst_frame->data_ = " << dst_frame->data_; 68 << ", dst_frame->data_ = " << dst_frame->data_;
69 assert(false); 69 assert(false);
70 } 70 }
71 dst_frame->samples_per_channel_ = 71 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels;
72 static_cast<size_t>(out_length / audio_ptr_num_channels);
73 72
74 // Upmix after resampling. 73 // Upmix after resampling.
75 if (num_channels == 1 && dst_frame->num_channels_ == 2) { 74 if (num_channels == 1 && dst_frame->num_channels_ == 2) {
76 // The audio in dst_frame really is mono at this point; MonoToStereo will 75 // The audio in dst_frame really is mono at this point; MonoToStereo will
77 // set this back to stereo. 76 // set this back to stereo.
78 dst_frame->num_channels_ = 1; 77 dst_frame->num_channels_ = 1;
79 AudioFrameOperations::MonoToStereo(dst_frame); 78 AudioFrameOperations::MonoToStereo(dst_frame);
80 } 79 }
81 } 80 }
82 81
83 void MixWithSat(int16_t target[], 82 void MixWithSat(int16_t target[],
84 int target_channel, 83 size_t target_channel,
85 const int16_t source[], 84 const int16_t source[],
86 int source_channel, 85 size_t source_channel,
87 size_t source_len) { 86 size_t source_len) {
88 assert(target_channel == 1 || target_channel == 2); 87 assert(target_channel == 1 || target_channel == 2);
89 assert(source_channel == 1 || source_channel == 2); 88 assert(source_channel == 1 || source_channel == 2);
90 89
91 if (target_channel == 2 && source_channel == 1) { 90 if (target_channel == 2 && source_channel == 1) {
92 // Convert source from mono to stereo. 91 // Convert source from mono to stereo.
93 int32_t left = 0; 92 int32_t left = 0;
94 int32_t right = 0; 93 int32_t right = 0;
95 for (size_t i = 0; i < source_len; ++i) { 94 for (size_t i = 0; i < source_len; ++i) {
96 left = source[i] + target[i * 2]; 95 left = source[i] + target[i * 2];
(...skipping 12 matching lines...) Expand all
109 int32_t temp = 0; 108 int32_t temp = 0;
110 for (size_t i = 0; i < source_len; ++i) { 109 for (size_t i = 0; i < source_len; ++i) {
111 temp = source[i] + target[i]; 110 temp = source[i] + target[i];
112 target[i] = WebRtcSpl_SatW32ToW16(temp); 111 target[i] = WebRtcSpl_SatW32ToW16(temp);
113 } 112 }
114 } 113 }
115 } 114 }
116 115
117 } // namespace voe 116 } // namespace voe
118 } // namespace webrtc 117 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/utility.h ('k') | webrtc/voice_engine/voe_base_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698