Commit a519a5eb 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 4 of N: Update a few more files and for the most obvious cases
where we can remove the if/return.

Bug: 957654
Change-Id: I85c8c87e02b319ea1fa95768b7297500d36a0d6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762763
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689982}
parent ffa5ca06
......@@ -39,8 +39,7 @@ using namespace vector_math;
void AudioChannel::ResizeSmaller(size_t new_length) {
DCHECK_LE(new_length, length_);
if (new_length <= length_)
length_ = new_length;
length_ = new_length;
}
void AudioChannel::Scale(float scale) {
......@@ -51,10 +50,8 @@ void AudioChannel::Scale(float scale) {
}
void AudioChannel::CopyFrom(const AudioChannel* source_channel) {
bool is_safe = (source_channel && source_channel->length() >= length());
DCHECK(is_safe);
if (!is_safe)
return;
DCHECK(source_channel);
DCHECK_GE(source_channel->length(), length());
if (source_channel->IsSilent()) {
Zero();
......@@ -68,21 +65,16 @@ void AudioChannel::CopyFromRange(const AudioChannel* source_channel,
unsigned start_frame,
unsigned end_frame) {
// Check that range is safe for reading from sourceChannel.
bool is_range_safe = source_channel && start_frame < end_frame &&
end_frame <= source_channel->length();
DCHECK(is_range_safe);
if (!is_range_safe)
return;
DCHECK(source_channel);
DCHECK_LT(start_frame, end_frame);
DCHECK_LE(end_frame, source_channel->length());
if (source_channel->IsSilent() && IsSilent())
return;
// Check that this channel has enough space.
size_t range_length = end_frame - start_frame;
bool is_range_length_safe = range_length <= length();
DCHECK(is_range_length_safe);
if (!is_range_length_safe)
return;
DCHECK_LE(range_length, length());
const float* source = source_channel->Data();
float* destination = MutableData();
......@@ -100,10 +92,8 @@ void AudioChannel::CopyFromRange(const AudioChannel* source_channel,
}
void AudioChannel::SumFrom(const AudioChannel* source_channel) {
bool is_safe = source_channel && source_channel->length() >= length();
DCHECK(is_safe);
if (!is_safe)
return;
DCHECK(source_channel);
DCHECK_GE(source_channel->length(), length());
if (source_channel->IsSilent())
return;
......
......@@ -44,13 +44,9 @@ AudioDelayDSPKernel::AudioDelayDSPKernel(double max_delay_time,
write_index_(0) {
DCHECK_GT(max_delay_time, 0.0);
DCHECK(!std::isnan(max_delay_time));
if (max_delay_time <= 0.0 || std::isnan(max_delay_time))
return;
size_t buffer_length = BufferLengthForDelay(max_delay_time, sample_rate);
DCHECK(buffer_length);
if (!buffer_length)
return;
buffer_.Allocate(buffer_length);
buffer_.Zero();
......@@ -83,13 +79,8 @@ void AudioDelayDSPKernel::Process(const float* source,
float* buffer = buffer_.Data();
DCHECK(buffer_length);
if (!buffer_length)
return;
DCHECK(source);
DCHECK(destination);
if (!source || !destination)
return;
float sample_rate = this->SampleRate();
double delay_time = 0;
......
......@@ -70,8 +70,6 @@ void AudioDSPKernelProcessor::Process(const AudioBus* source,
uint32_t frames_to_process) {
DCHECK(source);
DCHECK(destination);
if (!source || !destination)
return;
if (!IsInitialized()) {
destination->Zero();
......@@ -80,12 +78,8 @@ void AudioDSPKernelProcessor::Process(const AudioBus* source,
MutexTryLocker try_locker(process_lock_);
if (try_locker.Locked()) {
bool channel_count_matches =
source->NumberOfChannels() == destination->NumberOfChannels() &&
source->NumberOfChannels() == kernels_.size();
DCHECK(channel_count_matches);
if (!channel_count_matches)
return;
DCHECK_EQ(source->NumberOfChannels(), destination->NumberOfChannels());
DCHECK_EQ(source->NumberOfChannels(), kernels_.size());
for (unsigned i = 0; i < kernels_.size(); ++i)
kernels_[i]->Process(source->Channel(i)->Data(),
......@@ -134,8 +128,7 @@ void AudioDSPKernelProcessor::SetNumberOfChannels(unsigned number_of_channels) {
return;
DCHECK(!IsInitialized());
if (!IsInitialized())
number_of_channels_ = number_of_channels;
number_of_channels_ = number_of_channels;
}
bool AudioDSPKernelProcessor::RequiresTailProcessing() const {
......
......@@ -64,18 +64,12 @@ void AudioResampler::Process(AudioSourceProvider* provider,
AudioBus* destination_bus,
uint32_t frames_to_process) {
DCHECK(provider);
if (!provider)
return;
unsigned number_of_channels = kernels_.size();
// Make sure our configuration matches the bus we're rendering to.
bool channels_match =
(destination_bus &&
destination_bus->NumberOfChannels() == number_of_channels);
DCHECK(channels_match);
if (!channels_match)
return;
DCHECK(destination_bus);
DCHECK_EQ(destination_bus->NumberOfChannels(), number_of_channels);
// Setup the source bus.
for (unsigned i = 0; i < number_of_channels; ++i) {
......@@ -85,8 +79,6 @@ void AudioResampler::Process(AudioSourceProvider* provider,
float* fill_pointer =
kernels_[i]->GetSourcePointer(frames_to_process, &frames_needed);
DCHECK(fill_pointer);
if (!fill_pointer)
return;
source_bus_->SetChannelMemory(i, fill_pointer, frames_needed);
}
......
......@@ -66,11 +66,8 @@ float* AudioResamplerKernel::GetSourcePointer(
*number_of_source_frames_needed_p = frames_needed;
// Do bounds checking for the source buffer.
bool is_good = fill_index_ < source_buffer_.size() &&
fill_index_ + frames_needed <= source_buffer_.size();
DCHECK(is_good);
if (!is_good)
return nullptr;
DCHECK_LT(fill_index_, source_buffer_.size());
DCHECK_LE(fill_index_ + frames_needed, source_buffer_.size());
return source_buffer_.Data() + fill_index_;
}
......
......@@ -63,22 +63,16 @@ void DirectConvolver::Process(const float* source_p,
float* dest_p,
uint32_t frames_to_process) {
DCHECK_EQ(frames_to_process, input_block_size_);
if (frames_to_process != input_block_size_)
return;
// Only support kernelSize <= m_inputBlockSize
size_t kernel_size = ConvolutionKernelSize();
DCHECK_LE(kernel_size, input_block_size_);
if (kernel_size > input_block_size_)
return;
float* kernel_p = convolution_kernel_->Data();
// Sanity check
bool is_copy_good = kernel_p && source_p && dest_p && buffer_.Data();
DCHECK(is_copy_good);
if (!is_copy_good)
return;
DCHECK(kernel_p);
DCHECK(source_p);
DCHECK(dest_p);
DCHECK(buffer_.Data());
float* input_p = buffer_.Data() + input_block_size_;
......
......@@ -91,33 +91,19 @@ DownSampler::DownSampler(size_t input_block_size)
void DownSampler::Process(const float* source_p,
float* dest_p,
size_t source_frames_to_process) {
bool is_input_block_size_good = source_frames_to_process == input_block_size_;
DCHECK(is_input_block_size_good);
if (!is_input_block_size_good)
return;
DCHECK_EQ(source_frames_to_process, input_block_size_);
size_t dest_frames_to_process = source_frames_to_process / 2;
bool is_temp_buffer_good = dest_frames_to_process == temp_buffer_.size();
DCHECK(is_temp_buffer_good);
if (!is_temp_buffer_good)
return;
bool is_reduced_kernel_good =
convolver_.ConvolutionKernelSize() == kDefaultKernelSize / 2;
DCHECK(is_reduced_kernel_good);
if (!is_reduced_kernel_good)
return;
DCHECK_EQ(dest_frames_to_process, temp_buffer_.size());
DCHECK_EQ(convolver_.ConvolutionKernelSize(),
static_cast<unsigned>(kDefaultKernelSize / 2));
size_t half_size = kDefaultKernelSize / 2;
// Copy source samples to 2nd half of input buffer.
bool is_input_buffer_good =
input_buffer_.size() == source_frames_to_process * 2 &&
half_size <= source_frames_to_process;
DCHECK(is_input_buffer_good);
if (!is_input_buffer_good)
return;
DCHECK_EQ(input_buffer_.size(), source_frames_to_process * 2);
DCHECK_LE(half_size, source_frames_to_process);
float* input_p = input_buffer_.Data() + source_frames_to_process;
memcpy(input_p, source_p, sizeof(float) * source_frames_to_process);
......
......@@ -51,8 +51,7 @@ DynamicsCompressor::DynamicsCompressor(float sample_rate,
void DynamicsCompressor::SetParameterValue(unsigned parameter_id, float value) {
DCHECK_LT(parameter_id, static_cast<unsigned>(kParamLast));
if (parameter_id < kParamLast)
parameters_[parameter_id] = value;
parameters_[parameter_id] = value;
}
void DynamicsCompressor::InitializeParameters() {
......@@ -102,11 +101,6 @@ void DynamicsCompressor::Process(const AudioBus* source_bus,
DCHECK_EQ(number_of_channels, number_of_channels_);
DCHECK(number_of_source_channels);
if (number_of_channels != number_of_channels_ || !number_of_source_channels) {
destination_bus->Zero();
return;
}
switch (number_of_channels) {
case 2: // stereo
source_channels_[0] = source_bus->Channel(0)->Data();
......
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