diff options
author | Peter Kasting <pkasting@google.com> | 2015-06-11 12:55:50 -0700 |
---|---|---|
committer | Peter Kasting <pkasting@google.com> | 2015-06-11 19:56:03 +0000 |
commit | b7e5054414ff524f9db81dab7917729b8c4c8bcb (patch) | |
tree | 696db72058a796d3d526dd3331f0dcb480c86244 /webrtc/modules/audio_coding/neteq/decision_logic_normal.cc | |
parent | cb180976dd0e9672cde4523d87b5f4857478b5e9 (diff) | |
download | webrtc-b7e5054414ff524f9db81dab7917729b8c4c8bcb.tar.gz |
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
Diffstat (limited to 'webrtc/modules/audio_coding/neteq/decision_logic_normal.cc')
-rw-r--r-- | webrtc/modules/audio_coding/neteq/decision_logic_normal.cc | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/webrtc/modules/audio_coding/neteq/decision_logic_normal.cc b/webrtc/modules/audio_coding/neteq/decision_logic_normal.cc index 89fdb51b0b..e985ee0aa3 100644 --- a/webrtc/modules/audio_coding/neteq/decision_logic_normal.cc +++ b/webrtc/modules/audio_coding/neteq/decision_logic_normal.cc @@ -67,7 +67,8 @@ Operations DecisionLogicNormal::GetDecisionSpecialized( return kNormal; } - const uint32_t five_seconds_samples = 5 * 8000 * fs_mult_; + const uint32_t five_seconds_samples = + static_cast<uint32_t>(5 * 8000 * fs_mult_); // Check if the required packet is available. if (target_timestamp == available_timestamp) { return ExpectedPacketAvailable(prev_mode, play_dtmf); @@ -87,10 +88,11 @@ Operations DecisionLogicNormal::CngOperation(Modes prev_mode, uint32_t target_timestamp, uint32_t available_timestamp) { // Signed difference between target and available timestamp. - int32_t timestamp_diff = (generated_noise_samples_ + target_timestamp) - - available_timestamp; - int32_t optimal_level_samp = - (delay_manager_->TargetLevel() * packet_length_samples_) >> 8; + int32_t timestamp_diff = static_cast<int32_t>( + static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) - + available_timestamp); + int32_t optimal_level_samp = static_cast<int32_t>( + (delay_manager_->TargetLevel() * packet_length_samples_) >> 8); int32_t excess_waiting_time_samp = -timestamp_diff - optimal_level_samp; if (excess_waiting_time_samp > optimal_level_samp / 2) { @@ -182,11 +184,11 @@ Operations DecisionLogicNormal::FuturePacketAvailable( // safety precaution), but make sure that the number of samples in buffer // is no higher than 4 times the optimal level. (Note that TargetLevel() // is in Q8.) - int32_t timestamp_diff = (generated_noise_samples_ + target_timestamp) - - available_timestamp; - if (timestamp_diff >= 0 || + if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >= + available_timestamp || cur_size_samples > - 4 * ((delay_manager_->TargetLevel() * packet_length_samples_) >> 8)) { + ((delay_manager_->TargetLevel() * packet_length_samples_) >> 8) * + 4) { // Time to play this new packet. return kNormal; } else { |