History

avfilter/af_dynaudnorm: reduce number of lines by using for (int ...

Paul B Mahol committed 4 years ago

Commit 178d8031 parent aa6b9061 file · +28 −45Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_dynaudnorm.c+28−45
@@ -248,7 +248,6 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 247 unmodified lines
248248 double total_weight = 0.0;
249249 const double sigma = (((s->filter_size / 2.0) - 1.0) / 3.0) + (1.0 / 3.0);
250250 double adjust;
251− int i;
252251
253252 // Pre-compute constants
254253 const int offset = s->filter_size / 2;
@@ -256,7 +255,7 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 1 unmodified line
256255 const double c2 = 2.0 * sigma * sigma;
257256
258257 // Compute weights
259− for (i = 0; i < s->filter_size; i++) {
258+ for (int i = 0; i < s->filter_size; i++) {
260259 const int x = i - offset;
261260
262261 s->weights[i] = c1 * exp(-x * x / c2);
@@ -265,7 +264,7 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 2 unmodified lines
265264
266265 // Adjust weights
267266 adjust = 1.0 / total_weight;
268− for (i = 0; i < s->filter_size; i++) {
267+ for (int i = 0; i < s->filter_size; i++) {
269268 s->weights[i] *= adjust;
270269 }
271270 }
@@ -273,13 +272,12 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 1 unmodified line
273272 static av_cold void uninit(AVFilterContext *ctx)
274273 {
275274 DynamicAudioNormalizerContext *s = ctx->priv;
276− int c;
277275
278276 av_freep(&s->prev_amplification_factor);
279277 av_freep(&s->dc_correction_value);
280278 av_freep(&s->compress_threshold);
281279
282− for (c = 0; c < s->channels; c++) {
280+ for (int c = 0; c < s->channels; c++) {
283281 if (s->gain_history_original)
284282 cqueue_free(s->gain_history_original[c]);
285283 if (s->gain_history_minimum)
@@ -309,7 +307,6 @@ static int config_input(AVFilterLink *inlink) · 23 unmodified lines
309307 {
310308 AVFilterContext *ctx = inlink->dst;
311309 DynamicAudioNormalizerContext *s = ctx->priv;
312− int c;
313310
314311 uninit(ctx);
315312
@@ -333,7 +330,7 @@ static int config_input(AVFilterLink *inlink) · 17 unmodified lines
333330 !s->is_enabled || !s->weights)
334331 return AVERROR(ENOMEM);
335332
336− for (c = 0; c < inlink->channels; c++) {
333+ for (int c = 0; c < inlink->channels; c++) {
337334 s->prev_amplification_factor[c] = 1.0;
338335
339336 s->gain_history_original[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE);
@@ -378,19 +375,18 @@ static inline double bound(const double threshold, const double val) · 38 unmodified lines
378375 static double find_peak_magnitude(AVFrame *frame, int channel)
379376 {
380377 double max = DBL_EPSILON;
381− int c, i;
382378
383379 if (channel == -1) {
384− for (c = 0; c < frame->channels; c++) {
380+ for (int c = 0; c < frame->channels; c++) {
385381 double *data_ptr = (double *)frame->extended_data[c];
386382
387− for (i = 0; i < frame->nb_samples; i++)
383+ for (int i = 0; i < frame->nb_samples; i++)
388384 max = fmax(max, fabs(data_ptr[i]));
389385 }
390386 } else {
391387 double *data_ptr = (double *)frame->extended_data[channel];
392388
393− for (i = 0; i < frame->nb_samples; i++)
389+ for (int i = 0; i < frame->nb_samples; i++)
394390 max = fmax(max, fabs(data_ptr[i]));
395391 }
396392
@@ -400,13 +396,12 @@ static double find_peak_magnitude(AVFrame *frame, int channel) · 3 unmodified lines
400396 static double compute_frame_rms(AVFrame *frame, int channel)
401397 {
402398 double rms_value = 0.0;
403− int c, i;
404399
405400 if (channel == -1) {
406− for (c = 0; c < frame->channels; c++) {
401+ for (int c = 0; c < frame->channels; c++) {
407402 const double *data_ptr = (double *)frame->extended_data[c];
408403
409− for (i = 0; i < frame->nb_samples; i++) {
404+ for (int i = 0; i < frame->nb_samples; i++) {
410405 rms_value += pow_2(data_ptr[i]);
411406 }
412407 }
@@ -414,7 +409,7 @@ static double compute_frame_rms(AVFrame *frame, int channel) · 1 unmodified line
414409 rms_value /= frame->nb_samples * frame->channels;
415410 } else {
416411 const double *data_ptr = (double *)frame->extended_data[channel];
417− for (i = 0; i < frame->nb_samples; i++) {
412+ for (int i = 0; i < frame->nb_samples; i++) {
418413 rms_value += pow_2(data_ptr[i]);
419414 }
420415
@@ -441,9 +436,8 @@ static local_gain get_max_local_gain(DynamicAudioNormalizerContext *s, AVFrame * · 20 unmodified lines
441436 static double minimum_filter(cqueue *q)
442437 {
443438 double min = DBL_MAX;
444− int i;
445439
446− for (i = 0; i < cqueue_size(q); i++) {
440+ for (int i = 0; i < cqueue_size(q); i++) {
447441 min = fmin(min, cqueue_peek(q, i));
448442 }
449443
@@ -454,9 +448,8 @@ static double gaussian_filter(DynamicAudioNormalizerContext *s, cqueue *q, cqueu · 4 unmodified lines
454448 {
455449 const double *weights = s->weights;
456450 double result = 0.0, tsum = 0.0;
457− int i;
458451
459− for (i = 0; i < cqueue_size(q); i++) {
452+ for (int i = 0; i < cqueue_size(q); i++) {
460453 double tq_item = cqueue_peek(tq, i);
461454 double q_item = cqueue_peek(q, i);
462455
@@ -540,21 +533,20 @@ static void perform_dc_correction(DynamicAudioNormalizerContext *s, AVFrame *fra · 77 unmodified lines
540533 {
541534 const double diff = 1.0 / frame->nb_samples;
542535 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
543− int c, i;
544536
545− for (c = 0; c < s->channels; c++) {
537+ for (int c = 0; c < s->channels; c++) {
546538 const int bypass = bypass_channel(s, frame, c);
547539 double *dst_ptr = (double *)frame->extended_data[c];
548540 double current_average_value = 0.0;
549541 double prev_value;
550542
551− for (i = 0; i < frame->nb_samples; i++)
543+ for (int i = 0; i < frame->nb_samples; i++)
552544 current_average_value += dst_ptr[i] * diff;
553545
554546 prev_value = is_first_frame ? current_average_value : s->dc_correction_value[c];
555547 s->dc_correction_value[c] = is_first_frame ? current_average_value : update_value(current_average_value, s->dc_correction_value[c], 0.1);
556548
557− for (i = 0; i < frame->nb_samples && !bypass; i++) {
549+ for (int i = 0; i < frame->nb_samples && !bypass; i++) {
558550 dst_ptr[i] -= fade(prev_value, s->dc_correction_value[c], i, frame->nb_samples);
559551 }
560552 }
@@ -586,13 +578,12 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 25 unmodified lines
586578 AVFrame *frame, int channel)
587579 {
588580 double variance = 0.0;
589− int i, c;
590581
591582 if (channel == -1) {
592− for (c = 0; c < s->channels; c++) {
583+ for (int c = 0; c < s->channels; c++) {
593584 const double *data_ptr = (double *)frame->extended_data[c];
594585
595− for (i = 0; i < frame->nb_samples; i++) {
586+ for (int i = 0; i < frame->nb_samples; i++) {
596587 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
597588 }
598589 }
@@ -600,7 +591,7 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 1 unmodified line
600591 } else {
601592 const double *data_ptr = (double *)frame->extended_data[channel];
602593
603− for (i = 0; i < frame->nb_samples; i++) {
594+ for (int i = 0; i < frame->nb_samples; i++) {
604595 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
605596 }
606597 variance /= frame->nb_samples - 1;
@@ -612,7 +603,6 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 5 unmodified lines
612603 static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame)
613604 {
614605 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
615− int c, i;
616606
617607 if (s->channels_coupled) {
618608 const double standard_deviation = compute_frame_std_dev(s, frame, -1);
@@ -625,20 +615,20 @@ static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame · 6 unmodified lines
625615 prev_actual_thresh = setup_compress_thresh(prev_value);
626616 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[0]);
627617
628− for (c = 0; c < s->channels; c++) {
618+ for (int c = 0; c < s->channels; c++) {
629619 double *const dst_ptr = (double *)frame->extended_data[c];
630620 const int bypass = bypass_channel(s, frame, c);
631621
632622 if (bypass)
633623 continue;
634624
635− for (i = 0; i < frame->nb_samples; i++) {
625+ for (int i = 0; i < frame->nb_samples; i++) {
636626 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples);
637627 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
638628 }
639629 }
640630 } else {
641− for (c = 0; c < s->channels; c++) {
631+ for (int c = 0; c < s->channels; c++) {
642632 const int bypass = bypass_channel(s, frame, c);
643633 const double standard_deviation = compute_frame_std_dev(s, frame, c);
644634 const double current_threshold = setup_compress_thresh(fmin(1.0, s->compress_factor * standard_deviation));
@@ -652,7 +642,7 @@ static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame · 7 unmodified lines
652642 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[c]);
653643
654644 dst_ptr = (double *)frame->extended_data[c];
655− for (i = 0; i < frame->nb_samples && !bypass; i++) {
645+ for (int i = 0; i < frame->nb_samples && !bypass; i++) {
656646 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples);
657647 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
658648 }
@@ -718,14 +708,10 @@ static int analyze_frame(DynamicAudioNormalizerContext *s, AVFilterLink *outlink · 59 unmodified lines
718708
719709 if (s->channels_coupled) {
720710 const local_gain gain = get_max_local_gain(s, analyze_frame, -1);
721− int c;
722−
723− for (c = 0; c < s->channels; c++)
711+ for (int c = 0; c < s->channels; c++)
724712 update_gain_history(s, c, gain);
725713 } else {
726− int c;
727−
728− for (c = 0; c < s->channels; c++)
714+ for (int c = 0; c < s->channels; c++)
729715 update_gain_history(s, c, get_max_local_gain(s, analyze_frame, c));
730716 }
731717
@@ -735,9 +721,7 @@ static int analyze_frame(DynamicAudioNormalizerContext *s, AVFilterLink *outlink · 3 unmodified lines
735721 static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *in,
736722 AVFrame *frame, int enabled)
737723 {
738− int c, i;
739−
740− for (c = 0; c < s->channels; c++) {
724+ for (int c = 0; c < s->channels; c++) {
741725 const int bypass = bypass_channel(s, frame, c);
742726 const double *src_ptr = (const double *)in->extended_data[c];
743727 double *dst_ptr = (double *)frame->extended_data[c];
@@ -745,7 +729,7 @@ static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *in, · 1 unmodified line
745729
746730 cqueue_dequeue(s->gain_history_smoothed[c], &current_amplification_factor);
747731
748− for (i = 0; i < frame->nb_samples && enabled && !bypass; i++) {
732+ for (int i = 0; i < frame->nb_samples && enabled && !bypass; i++) {
749733 const double amplification_factor = fade(s->prev_amplification_factor[c],
750734 current_amplification_factor, i,
751735 frame->nb_samples);
@@ -811,15 +795,14 @@ static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink, · 59 unmodified lines
811795 AVFilterLink *outlink)
812796 {
813797 AVFrame *out = ff_get_audio_buffer(outlink, s->sample_advance);
814− int c, i;
815798
816799 if (!out)
817800 return AVERROR(ENOMEM);
818801
819− for (c = 0; c < s->channels; c++) {
802+ for (int c = 0; c < s->channels; c++) {
820803 double *dst_ptr = (double *)out->extended_data[c];
821804
822− for (i = 0; i < out->nb_samples; i++) {
805+ for (int i = 0; i < out->nb_samples; i++) {
823806 dst_ptr[i] = s->alt_boundary_mode ? DBL_EPSILON : ((s->target_rms > DBL_EPSILON) ? fmin(s->peak_value, s->target_rms) : s->peak_value);
824807 if (s->dc_correction) {
825808 dst_ptr[i] *= ((i % 2) == 1) ? -1 : 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t