Commit 6a530426 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Follow style guide on use of DCHECK

WebAudio legacy code often does something like:

  DCHECK(foo);
  if (!foo)
    return;

The style guide says the if/return should be removed; DCHECK failures
should not be handled.

Part 2 of N: Update a few more files and for the most obvious cases
where we can remove the if/return.

Bug: 957654
Change-Id: Ie5a30a67a58b88df9b5eb579d06894c710c9b1dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758593Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689158}
parent b8d5ab25
...@@ -227,11 +227,9 @@ float AudioParamHandler::FinalValue() { ...@@ -227,11 +227,9 @@ float AudioParamHandler::FinalValue() {
void AudioParamHandler::CalculateSampleAccurateValues( void AudioParamHandler::CalculateSampleAccurateValues(
float* values, float* values,
unsigned number_of_values) { unsigned number_of_values) {
bool is_safe = DCHECK(GetDeferredTaskHandler().IsAudioThread());
GetDeferredTaskHandler().IsAudioThread() && values && number_of_values; DCHECK(values);
DCHECK(is_safe); DCHECK_GT(number_of_values, 0u);
if (!is_safe)
return;
CalculateFinalValues(values, number_of_values, IsAudioRate()); CalculateFinalValues(values, number_of_values, IsAudioRate());
} }
...@@ -239,11 +237,9 @@ void AudioParamHandler::CalculateSampleAccurateValues( ...@@ -239,11 +237,9 @@ void AudioParamHandler::CalculateSampleAccurateValues(
void AudioParamHandler::CalculateFinalValues(float* values, void AudioParamHandler::CalculateFinalValues(float* values,
unsigned number_of_values, unsigned number_of_values,
bool sample_accurate) { bool sample_accurate) {
bool is_good = DCHECK(GetDeferredTaskHandler().IsAudioThread());
GetDeferredTaskHandler().IsAudioThread() && values && number_of_values; DCHECK(values);
DCHECK(is_good); DCHECK_GT(number_of_values, 0u);
if (!is_good)
return;
// The calculated result will be the "intrinsic" value summed with all // The calculated result will be the "intrinsic" value summed with all
// audio-rate connections. // audio-rate connections.
......
...@@ -516,15 +516,12 @@ void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event, ...@@ -516,15 +516,12 @@ void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event,
// Sanity check the event. Be super careful we're not getting infected with // Sanity check the event. Be super careful we're not getting infected with
// NaN or Inf. These should have been handled by the caller. // NaN or Inf. These should have been handled by the caller.
bool is_valid = event->GetType() < ParamEvent::kLastType && DCHECK_LT(event->GetType(), ParamEvent::kLastType);
std::isfinite(event->Value()) && DCHECK(std::isfinite(event->Value()));
std::isfinite(event->Time()) && DCHECK(std::isfinite(event->Time()));
std::isfinite(event->TimeConstant()) && DCHECK(std::isfinite(event->TimeConstant()));
std::isfinite(event->Duration()) && event->Duration() >= 0; DCHECK(std::isfinite(event->Duration()));
DCHECK_GE(event->Duration(), 0);
DCHECK(is_valid);
if (!is_valid)
return;
unsigned i = 0; unsigned i = 0;
double insert_time = event->Time(); double insert_time = event->Time();
......
...@@ -195,11 +195,10 @@ void BiquadDSPKernel::GetFrequencyResponse(BiquadDSPKernel& kernel, ...@@ -195,11 +195,10 @@ void BiquadDSPKernel::GetFrequencyResponse(BiquadDSPKernel& kernel,
// updating |kernel| while we're computing the response. // updating |kernel| while we're computing the response.
DCHECK(IsMainThread()); DCHECK(IsMainThread());
bool is_good = DCHECK_GT(n_frequencies, 0);
n_frequencies > 0 && frequency_hz && mag_response && phase_response; DCHECK(frequency_hz);
DCHECK(is_good); DCHECK(mag_response);
if (!is_good) DCHECK(phase_response);
return;
Vector<float> frequency(n_frequencies); Vector<float> frequency(n_frequencies);
double nyquist = kernel.Nyquist(); double nyquist = kernel.Nyquist();
......
...@@ -72,17 +72,15 @@ void ConstantSourceHandler::Process(uint32_t frames_to_process) { ...@@ -72,17 +72,15 @@ void ConstantSourceHandler::Process(uint32_t frames_to_process) {
if (offset_->HasSampleAccurateValues()) { if (offset_->HasSampleAccurateValues()) {
DCHECK_LE(frames_to_process, sample_accurate_values_.size()); DCHECK_LE(frames_to_process, sample_accurate_values_.size());
if (frames_to_process <= sample_accurate_values_.size()) { float* offsets = sample_accurate_values_.Data();
float* offsets = sample_accurate_values_.Data(); offset_->CalculateSampleAccurateValues(offsets, frames_to_process);
offset_->CalculateSampleAccurateValues(offsets, frames_to_process); if (non_silent_frames_to_process > 0) {
if (non_silent_frames_to_process > 0) { memcpy(output_bus->Channel(0)->MutableData() + quantum_frame_offset,
memcpy(output_bus->Channel(0)->MutableData() + quantum_frame_offset, offsets + quantum_frame_offset,
offsets + quantum_frame_offset, non_silent_frames_to_process * sizeof(*offsets));
non_silent_frames_to_process * sizeof(*offsets)); output_bus->ClearSilentFlag();
output_bus->ClearSilentFlag(); } else {
} else { output_bus->Zero();
output_bus->Zero();
}
} }
} else { } else {
float value = offset_->Value(); float value = offset_->Value();
......
...@@ -237,8 +237,6 @@ void ConvolverHandler::CheckNumberOfChannelsForInput(AudioNodeInput* input) { ...@@ -237,8 +237,6 @@ void ConvolverHandler::CheckNumberOfChannelsForInput(AudioNodeInput* input) {
DCHECK(input); DCHECK(input);
DCHECK_EQ(input, &this->Input(0)); DCHECK_EQ(input, &this->Input(0));
if (input != &this->Input(0))
return;
if (shared_buffer_) { if (shared_buffer_) {
unsigned number_of_output_channels = ComputeNumberOfOutputChannels( unsigned number_of_output_channels = ComputeNumberOfOutputChannels(
......
...@@ -34,14 +34,10 @@ DelayDSPKernel::DelayDSPKernel(DelayProcessor* processor) ...@@ -34,14 +34,10 @@ DelayDSPKernel::DelayDSPKernel(DelayProcessor* processor)
: AudioDelayDSPKernel(processor, audio_utilities::kRenderQuantumFrames) { : AudioDelayDSPKernel(processor, audio_utilities::kRenderQuantumFrames) {
DCHECK(processor); DCHECK(processor);
DCHECK_GT(processor->SampleRate(), 0); DCHECK_GT(processor->SampleRate(), 0);
if (!(processor && processor->SampleRate() > 0))
return;
max_delay_time_ = processor->MaxDelayTime(); max_delay_time_ = processor->MaxDelayTime();
DCHECK_GE(max_delay_time_, 0); DCHECK_GE(max_delay_time_, 0);
DCHECK(!std::isnan(max_delay_time_)); DCHECK(!std::isnan(max_delay_time_));
if (max_delay_time_ < 0 || std::isnan(max_delay_time_))
return;
buffer_.Allocate( buffer_.Allocate(
BufferLengthForDelay(max_delay_time_, processor->SampleRate())); BufferLengthForDelay(max_delay_time_, processor->SampleRate()));
......
...@@ -71,12 +71,10 @@ void GainHandler::Process(uint32_t frames_to_process) { ...@@ -71,12 +71,10 @@ void GainHandler::Process(uint32_t frames_to_process) {
// Apply sample-accurate gain scaling for precise envelopes, grain // Apply sample-accurate gain scaling for precise envelopes, grain
// windows, etc. // windows, etc.
DCHECK_LE(frames_to_process, sample_accurate_gain_values_.size()); DCHECK_LE(frames_to_process, sample_accurate_gain_values_.size());
if (frames_to_process <= sample_accurate_gain_values_.size()) { float* gain_values = sample_accurate_gain_values_.Data();
float* gain_values = sample_accurate_gain_values_.Data(); gain_->CalculateSampleAccurateValues(gain_values, frames_to_process);
gain_->CalculateSampleAccurateValues(gain_values, frames_to_process); output_bus->CopyWithSampleAccurateGainValuesFrom(*input_bus, gain_values,
output_bus->CopyWithSampleAccurateGainValuesFrom( frames_to_process);
*input_bus, gain_values, frames_to_process);
}
} else { } else {
// Apply the gain. // Apply the gain.
if (gain_->Value() == 0) { if (gain_->Value() == 0) {
...@@ -111,8 +109,6 @@ void GainHandler::CheckNumberOfChannelsForInput(AudioNodeInput* input) { ...@@ -111,8 +109,6 @@ void GainHandler::CheckNumberOfChannelsForInput(AudioNodeInput* input) {
DCHECK(input); DCHECK(input);
DCHECK_EQ(input, &this->Input(0)); DCHECK_EQ(input, &this->Input(0));
if (input != &this->Input(0))
return;
unsigned number_of_channels = input->NumberOfChannels(); unsigned number_of_channels = input->NumberOfChannels();
......
...@@ -28,11 +28,10 @@ void IIRDSPKernel::GetFrequencyResponse(int n_frequencies, ...@@ -28,11 +28,10 @@ void IIRDSPKernel::GetFrequencyResponse(int n_frequencies,
const float* frequency_hz, const float* frequency_hz,
float* mag_response, float* mag_response,
float* phase_response) { float* phase_response) {
bool is_good = DCHECK_GT(n_frequencies, 0);
n_frequencies > 0 && frequency_hz && mag_response && phase_response; DCHECK(frequency_hz);
DCHECK(is_good); DCHECK(mag_response);
if (!is_good) DCHECK(phase_response);
return;
Vector<float> frequency(n_frequencies); Vector<float> frequency(n_frequencies);
......
...@@ -179,11 +179,8 @@ static void ClampFrequency(float* frequency, ...@@ -179,11 +179,8 @@ static void ClampFrequency(float* frequency,
bool OscillatorHandler::CalculateSampleAccuratePhaseIncrements( bool OscillatorHandler::CalculateSampleAccuratePhaseIncrements(
uint32_t frames_to_process) { uint32_t frames_to_process) {
bool is_good = frames_to_process <= phase_increments_.size() && DCHECK_LE(frames_to_process, phase_increments_.size());
frames_to_process <= detune_values_.size(); DCHECK_LE(frames_to_process, detune_values_.size());
DCHECK(is_good);
if (!is_good)
return false;
if (first_render_) { if (first_render_) {
first_render_ = false; first_render_ = false;
...@@ -364,8 +361,6 @@ void OscillatorHandler::Process(uint32_t frames_to_process) { ...@@ -364,8 +361,6 @@ void OscillatorHandler::Process(uint32_t frames_to_process) {
} }
DCHECK_LE(frames_to_process, phase_increments_.size()); DCHECK_LE(frames_to_process, phase_increments_.size());
if (frames_to_process > phase_increments_.size())
return;
// The audio thread can't block on this lock, so we call tryLock() instead. // The audio thread can't block on this lock, so we call tryLock() instead.
MutexTryLocker try_locker(process_lock_); MutexTryLocker try_locker(process_lock_);
......
...@@ -62,12 +62,10 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) { ...@@ -62,12 +62,10 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) {
if (pan_->HasSampleAccurateValues()) { if (pan_->HasSampleAccurateValues()) {
// Apply sample-accurate panning specified by AudioParam automation. // Apply sample-accurate panning specified by AudioParam automation.
DCHECK_LE(frames_to_process, sample_accurate_pan_values_.size()); DCHECK_LE(frames_to_process, sample_accurate_pan_values_.size());
if (frames_to_process <= sample_accurate_pan_values_.size()) { float* pan_values = sample_accurate_pan_values_.Data();
float* pan_values = sample_accurate_pan_values_.Data(); pan_->CalculateSampleAccurateValues(pan_values, frames_to_process);
pan_->CalculateSampleAccurateValues(pan_values, frames_to_process); stereo_panner_->PanWithSampleAccurateValues(input_bus, output_bus,
stereo_panner_->PanWithSampleAccurateValues( pan_values, frames_to_process);
input_bus, output_bus, pan_values, frames_to_process);
}
} else { } else {
stereo_panner_->PanToTargetValue(input_bus, output_bus, pan_->Value(), stereo_panner_->PanToTargetValue(input_bus, output_bus, pan_->Value(),
frames_to_process); frames_to_process);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment