diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:41:43 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 21:57:34 +0200 |
commit | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch) | |
tree | 198d4ff7665d89307f6ca2469fa38620a9eb1672 /servers/audio | |
parent | 07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff) |
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
Diffstat (limited to 'servers/audio')
-rw-r--r-- | servers/audio/audio_driver_dummy.cpp | 9 | ||||
-rw-r--r-- | servers/audio/audio_filter_sw.cpp | 23 | ||||
-rw-r--r-- | servers/audio/audio_rb_resampler.cpp | 15 | ||||
-rw-r--r-- | servers/audio/audio_stream.cpp | 6 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_chorus.cpp | 3 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_compressor.cpp | 9 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_delay.cpp | 3 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_distortion.cpp | 5 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_filter.cpp | 18 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_filter.h | 9 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_pitch_shift.cpp | 26 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_spectrum_analyzer.cpp | 3 | ||||
-rw-r--r-- | servers/audio/effects/eq.cpp | 11 | ||||
-rw-r--r-- | servers/audio/effects/reverb.cpp | 53 |
14 files changed, 129 insertions, 64 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp index 5560385fd3..70d5ebbded 100644 --- a/servers/audio/audio_driver_dummy.cpp +++ b/servers/audio/audio_driver_dummy.cpp @@ -86,20 +86,23 @@ AudioDriver::SpeakerMode AudioDriverDummy::get_speaker_mode() const { }; void AudioDriverDummy::lock() { - if (!thread) + if (!thread) { return; + } mutex.lock(); }; void AudioDriverDummy::unlock() { - if (!thread) + if (!thread) { return; + } mutex.unlock(); }; void AudioDriverDummy::finish() { - if (!thread) + if (!thread) { return; + } exit_thread = true; Thread::wait_to_finish(thread); diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp index b6759649cc..f5eafb7e60 100644 --- a/servers/audio/audio_filter_sw.cpp +++ b/servers/audio/audio_filter_sw.cpp @@ -54,8 +54,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { int sr_limit = (sampling_rate / 2) + 512; double final_cutoff = (cutoff > sr_limit) ? sr_limit : cutoff; - if (final_cutoff < 1) + if (final_cutoff < 1) { final_cutoff = 1; //don't allow less than this + } double omega = 2.0 * Math_PI * final_cutoff / sampling_rate; @@ -67,15 +68,17 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { Q = 0.0001; } - if (mode == BANDPASS) + if (mode == BANDPASS) { Q *= 2.0; - else if (mode == PEAK) + } else if (mode == PEAK) { Q *= 3.0; + } double tmpgain = gain; - if (tmpgain < 0.001) + if (tmpgain < 0.001) { tmpgain = 0.001; + } if (stages > 1) { Q = (Q > 1.0 ? Math::pow(Q, 1.0 / stages) : Q); @@ -142,8 +145,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { } break; case LOWSHELF: { double tmpq = Math::sqrt(Q); - if (tmpq <= 0) + if (tmpq <= 0) { tmpq = 0.001; + } double beta = Math::sqrt(tmpgain) / tmpq; a0 = (tmpgain + 1.0) + (tmpgain - 1.0) * cos_v + beta * sin_v; @@ -156,8 +160,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { } break; case HIGHSHELF: { double tmpq = Math::sqrt(Q); - if (tmpq <= 0) + if (tmpq <= 0) { tmpq = 0.001; + } double beta = Math::sqrt(tmpgain) / tmpq; a0 = (tmpgain + 1.0) - (tmpgain - 1.0) * cos_v + beta * sin_v; @@ -235,8 +240,9 @@ void AudioFilterSW::Processor::set_filter(AudioFilterSW *p_filter, bool p_clear_ } void AudioFilterSW::Processor::update_coeffs(int p_interp_buffer_len) { - if (!filter) + if (!filter) { return; + } if (p_interp_buffer_len) { //interpolate Coeffs old_coeffs = coeffs; @@ -253,8 +259,9 @@ void AudioFilterSW::Processor::update_coeffs(int p_interp_buffer_len) { } void AudioFilterSW::Processor::process(float *p_samples, int p_amount, int p_stride, bool p_interpolate) { - if (!filter) + if (!filter) { return; + } if (p_interpolate) { for (int i = 0; i < p_amount; i++) { diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp index a7542fab03..7613e70e64 100644 --- a/servers/audio/audio_rb_resampler.cpp +++ b/servers/audio/audio_rb_resampler.cpp @@ -34,8 +34,9 @@ #include "servers/audio_server.h" int AudioRBResampler::get_channel_count() const { - if (!rb) + if (!rb) { return 0; + } return channels; } @@ -101,8 +102,9 @@ uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_i } bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) { - if (!rb) + if (!rb) { return false; + } int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate; int read_space = get_reader_space(); @@ -125,8 +127,9 @@ bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) { break; } - if (src_read > read_space) + if (src_read > read_space) { src_read = read_space; + } rb_read_pos = (rb_read_pos + src_read) & rb_mask; @@ -147,8 +150,9 @@ bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) { } int AudioRBResampler::get_num_of_ready_frames() { - if (!is_ready()) + if (!is_ready()) { return 0; + } int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate; int read_space = get_reader_space(); return (int64_t(read_space) << MIX_FRAC_BITS) / increment; @@ -192,8 +196,9 @@ Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_m } void AudioRBResampler::clear() { - if (!rb) + if (!rb) { return; + } //should be stopped at this point but just in case memdelete_arr(rb); diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 11b96edb8d..2cc2f5c291 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -244,8 +244,9 @@ Ref<AudioStream> AudioStreamRandomPitch::get_audio_stream() const { } void AudioStreamRandomPitch::set_random_pitch(float p_pitch) { - if (p_pitch < 1) + if (p_pitch < 1) { p_pitch = 1; + } random_pitch = p_pitch; } @@ -256,8 +257,9 @@ float AudioStreamRandomPitch::get_random_pitch() const { Ref<AudioStreamPlayback> AudioStreamRandomPitch::instance_playback() { Ref<AudioStreamPlaybackRandomPitch> playback; playback.instance(); - if (audio_stream.is_valid()) + if (audio_stream.is_valid()) { playback->playback = audio_stream->instance_playback(); + } playbacks.insert(playback.ptr()); playback->random_pitch = Ref<AudioStreamRandomPitch>((AudioStreamRandomPitch *)this); diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp index 48f050c5ab..2b530475f0 100644 --- a/servers/audio/effects/audio_effect_chorus.cpp +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -81,8 +81,9 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A } //low pass filter - if (v.cutoff == 0) + if (v.cutoff == 0) { continue; + } float auxlp = expf(-2.0 * Math_PI * v.cutoff / mix_rate); float c1 = 1.0 - auxlp; float c2 = auxlp; diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp index b0f829b679..4b0b4dabea 100644 --- a/servers/audio/effects/audio_effect_compressor.cpp +++ b/servers/audio/effects/audio_effect_compressor.cpp @@ -66,11 +66,13 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi float overdb = 2.08136898f * Math::linear2db(peak / threshold); - if (overdb < 0.0) //we only care about what goes over to compress + if (overdb < 0.0) { //we only care about what goes over to compress overdb = 0.0; + } - if (overdb - rundb > 5) // diffeence is too large + if (overdb - rundb > 5) { // diffeence is too large averatio = 4; + } if (overdb > rundb) { rundb = overdb + atcoef * (rundb - overdb); @@ -101,8 +103,9 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi gr_meter = grv; } else { gr_meter *= gr_meter_decay; - if (gr_meter > 1) + if (gr_meter > 1) { gr_meter = 1; + } } p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0 - mix); diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp index 00cf7a0e70..d6ab14be89 100644 --- a/servers/audio/effects/audio_effect_delay.cpp +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -105,8 +105,9 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au ring_buffer_pos++; - if ((++feedback_buffer_pos) >= feedback_delay_frames) + if ((++feedback_buffer_pos) >= feedback_delay_frames) { feedback_buffer_pos = 0; + } } } diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index da4c34ce82..dc5c2cc16f 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -59,10 +59,11 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi switch (base->mode) { case AudioEffectDistortion::MODE_CLIP: { a = powf(a, 1.0001 - drive_f); - if (a > 1.0) + if (a > 1.0) { a = 1.0; - else if (a < (-1.0)) + } else if (a < (-1.0)) { a = -1.0; + } } break; case AudioEffectDistortion::MODE_ATAN: { diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp index cf6d0fa896..a5135ee1a6 100644 --- a/servers/audio/effects/audio_effect_filter.cpp +++ b/servers/audio/effects/audio_effect_filter.cpp @@ -36,12 +36,15 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, for (int i = 0; i < p_frame_count; i++) { float f = p_src_frames[i].l; filter_process[0][0].process_one(f); - if (S > 1) + if (S > 1) { filter_process[0][1].process_one(f); - if (S > 2) + } + if (S > 2) { filter_process[0][2].process_one(f); - if (S > 3) + } + if (S > 3) { filter_process[0][3].process_one(f); + } p_dst_frames[i].l = f; } @@ -49,12 +52,15 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames, for (int i = 0; i < p_frame_count; i++) { float f = p_src_frames[i].r; filter_process[1][0].process_one(f); - if (S > 1) + if (S > 1) { filter_process[1][1].process_one(f); - if (S > 2) + } + if (S > 2) { filter_process[1][2].process_one(f); - if (S > 3) + } + if (S > 3) { filter_process[1][3].process_one(f); + } p_dst_frames[i].r = f; } diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h index c439c5a5b5..b11a4e3623 100644 --- a/servers/audio/effects/audio_effect_filter.h +++ b/servers/audio/effects/audio_effect_filter.h @@ -99,8 +99,9 @@ class AudioEffectLowPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectLowPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: @@ -111,8 +112,9 @@ public: class AudioEffectHighPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: @@ -123,8 +125,9 @@ public: class AudioEffectBandPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const { - if (property.name == "gain") + if (property.name == "gain") { property.usage = 0; + } } public: diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index a8f25ac325..fb6b56d984 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -94,7 +94,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff freqPerBin = sampleRate/(double)fftFrameSize; expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize; inFifoLatency = fftFrameSize-stepSize; - if (gRover == 0) gRover = inFifoLatency; + if (gRover == 0) { gRover = inFifoLatency; + +} /* initialize our static arrays */ @@ -142,8 +144,10 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* map delta phase into +/- Pi interval */ qpd = tmp/Math_PI; - if (qpd >= 0) qpd += qpd&1; - else qpd -= qpd&1; + if (qpd >= 0) { qpd += qpd&1; + } else { qpd -= qpd&1; + +} tmp -= Math_PI*(double)qpd; /* get deviation from bin frequency from the +/- Pi interval */ @@ -200,7 +204,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } /* zero negative frequencies */ - for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.; + for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) { gFFTworksp[k] = 0.; + +} /* do inverse transform */ smbFft(gFFTworksp, fftFrameSize, 1); @@ -210,13 +216,17 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp); } - for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k]; + for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k]; + +} /* shift accumulator */ memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); /* move input FIFO */ - for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize]; + for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize]; + +} } } @@ -245,7 +255,9 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) for (i = 2; i < 2*fftFrameSize-2; i += 2) { for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) { - if (i & bitm) j++; + if (i & bitm) { j++; + +} j <<= 1; } if (i < j) { diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index a3fd11c6c0..e744dbf9b0 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp @@ -50,8 +50,9 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign) for (i = 2; i < 2 * fftFrameSize - 2; i += 2) { for (bitm = 2, j = 0; bitm < 2 * fftFrameSize; bitm <<= 1) { - if (i & bitm) + if (i & bitm) { j++; + } j <<= 1; } if (i < j) { diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp index 59b3ba2d0b..08a6cf55fa 100644 --- a/servers/audio/effects/eq.cpp +++ b/servers/audio/effects/eq.cpp @@ -42,22 +42,25 @@ static int solve_quadratic(double a, double b, double c, double *r1, double *r2) //solves quadractic and returns number of roots double base = 2 * a; - if (base == 0.0f) + if (base == 0.0f) { return 0; + } double squared = b * b - 4 * a * c; - if (squared < 0.0) + if (squared < 0.0) { return 0; + } squared = sqrt(squared); *r1 = (-b + squared) / base; *r2 = (-b - squared) / base; - if (*r1 == *r2) + if (*r1 == *r2) { return 1; - else + } else { return 2; + } } EQ::BandProcess::BandProcess() { diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp index 99f60557e1..7c35d88ced 100644 --- a/servers/audio/effects/reverb.cpp +++ b/servers/audio/effects/reverb.cpp @@ -57,22 +57,27 @@ const float Reverb::allpass_tunings[MAX_ALLPASS] = { }; void Reverb::process(float *p_src, float *p_dst, int p_frames) { - if (p_frames > INPUT_BUFFER_MAX_SIZE) + if (p_frames > INPUT_BUFFER_MAX_SIZE) { p_frames = INPUT_BUFFER_MAX_SIZE; + } int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate); - if (predelay_frames < 10) + if (predelay_frames < 10) { predelay_frames = 10; - if (predelay_frames >= echo_buffer_size) + } + if (predelay_frames >= echo_buffer_size) { predelay_frames = echo_buffer_size - 1; + } for (int i = 0; i < p_frames; i++) { - if (echo_buffer_pos >= echo_buffer_size) + if (echo_buffer_pos >= echo_buffer_size) { echo_buffer_pos = 0; + } int read_pos = echo_buffer_pos - predelay_frames; - while (read_pos < 0) + while (read_pos < 0) { read_pos += echo_buffer_size; + } float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]); @@ -104,8 +109,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread)); for (int j = 0; j < p_frames; j++) { - if (c.pos >= size_limit) //reset this now just in case + if (c.pos >= size_limit) { //reset this now just in case c.pos = 0; + } float out = undenormalise(c.buffer[c.pos] * c.feedback); out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass @@ -156,8 +162,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { int size_limit = a.size - lrintf((float)a.extra_spread_frames * (1.0 - params.extra_spread)); for (int j = 0; j < p_frames; j++) { - if (a.pos >= size_limit) + if (a.pos >= size_limit) { a.pos = 0; + } float aux = a.buffer[a.pos]; a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]); @@ -200,10 +207,12 @@ void Reverb::set_predelay_feedback(float p_predelay_fb) { } void Reverb::set_highpass(float p_frq) { - if (p_frq > 1) + if (p_frq > 1) { p_frq = 1; - if (p_frq < 0) + } + if (p_frq < 0) { p_frq = 0; + } params.hpf = p_frq; } @@ -230,13 +239,15 @@ void Reverb::configure_buffers() { c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames; - if (len < 5) + if (len < 5) { len = 5; //may this happen? + } c.buffer = memnew_arr(float, len); c.pos = 0; - for (int j = 0; j < len; j++) + for (int j = 0; j < len; j++) { c.buffer[j] = 0; + } c.size = len; } @@ -246,13 +257,15 @@ void Reverb::configure_buffers() { a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames; - if (len < 5) + if (len < 5) { len = 5; //may this happen? + } a.buffer = memnew_arr(float, len); a.pos = 0; - for (int j = 0; j < len; j++) + for (int j = 0; j < len; j++) { a.buffer[j] = 0; + } a.size = len; } @@ -273,10 +286,11 @@ void Reverb::update_parameters() { for (int i = 0; i < MAX_COMBS; i++) { Comb &c = comb[i]; c.feedback = room_offset + params.room_size * room_scale; - if (c.feedback < room_offset) + if (c.feedback < room_offset) { c.feedback = room_offset; - else if (c.feedback > (room_offset + room_scale)) + } else if (c.feedback > (room_offset + room_scale)) { c.feedback = (room_offset + room_scale); + } float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough) auxdmp *= auxdmp; @@ -286,19 +300,22 @@ void Reverb::update_parameters() { } void Reverb::clear_buffers() { - if (echo_buffer) + if (echo_buffer) { memdelete_arr(echo_buffer); + } for (int i = 0; i < MAX_COMBS; i++) { - if (comb[i].buffer) + if (comb[i].buffer) { memdelete_arr(comb[i].buffer); + } comb[i].buffer = nullptr; } for (int i = 0; i < MAX_ALLPASS; i++) { - if (allpass[i].buffer) + if (allpass[i].buffer) { memdelete_arr(allpass[i].buffer); + } allpass[i].buffer = nullptr; } |