Unified · Split
| @@ -248,7 +248,6 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 247 unmodified lines | ||
| 248 | 248 | double total_weight = 0.0; |
| 249 | 249 | const double sigma = (((s->filter_size / 2.0) - 1.0) / 3.0) + (1.0 / 3.0); |
| 250 | 250 | double adjust; |
| 251 | − int i; | |
| 252 | 251 | |
| 253 | 252 | // Pre-compute constants |
| 254 | 253 | const int offset = s->filter_size / 2; |
| @@ -256,7 +255,7 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 1 unmodified line | ||
| 256 | 255 | const double c2 = 2.0 * sigma * sigma; |
| 257 | 256 | |
| 258 | 257 | // Compute weights |
| 259 | − for (i = 0; i < s->filter_size; i++) { | |
| 258 | + for (int i = 0; i < s->filter_size; i++) { | |
| 260 | 259 | const int x = i - offset; |
| 261 | 260 | |
| 262 | 261 | s->weights[i] = c1 * exp(-x * x / c2); |
| @@ -265,7 +264,7 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 2 unmodified lines | ||
| 265 | 264 | |
| 266 | 265 | // Adjust weights |
| 267 | 266 | adjust = 1.0 / total_weight; |
| 268 | − for (i = 0; i < s->filter_size; i++) { | |
| 267 | + for (int i = 0; i < s->filter_size; i++) { | |
| 269 | 268 | s->weights[i] *= adjust; |
| 270 | 269 | } |
| 271 | 270 | } |
| @@ -273,13 +272,12 @@ static void init_gaussian_filter(DynamicAudioNormalizerContext *s) · 1 unmodified line | ||
| 273 | 272 | static av_cold void uninit(AVFilterContext *ctx) |
| 274 | 273 | { |
| 275 | 274 | DynamicAudioNormalizerContext *s = ctx->priv; |
| 276 | − int c; | |
| 277 | 275 | |
| 278 | 276 | av_freep(&s->prev_amplification_factor); |
| 279 | 277 | av_freep(&s->dc_correction_value); |
| 280 | 278 | av_freep(&s->compress_threshold); |
| 281 | 279 | |
| 282 | − for (c = 0; c < s->channels; c++) { | |
| 280 | + for (int c = 0; c < s->channels; c++) { | |
| 283 | 281 | if (s->gain_history_original) |
| 284 | 282 | cqueue_free(s->gain_history_original[c]); |
| 285 | 283 | if (s->gain_history_minimum) |
| @@ -309,7 +307,6 @@ static int config_input(AVFilterLink *inlink) · 23 unmodified lines | ||
| 309 | 307 | { |
| 310 | 308 | AVFilterContext *ctx = inlink->dst; |
| 311 | 309 | DynamicAudioNormalizerContext *s = ctx->priv; |
| 312 | − int c; | |
| 313 | 310 | |
| 314 | 311 | uninit(ctx); |
| 315 | 312 | |
| @@ -333,7 +330,7 @@ static int config_input(AVFilterLink *inlink) · 17 unmodified lines | ||
| 333 | 330 | !s->is_enabled || !s->weights) |
| 334 | 331 | return AVERROR(ENOMEM); |
| 335 | 332 | |
| 336 | − for (c = 0; c < inlink->channels; c++) { | |
| 333 | + for (int c = 0; c < inlink->channels; c++) { | |
| 337 | 334 | s->prev_amplification_factor[c] = 1.0; |
| 338 | 335 | |
| 339 | 336 | 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 | ||
| 378 | 375 | static double find_peak_magnitude(AVFrame *frame, int channel) |
| 379 | 376 | { |
| 380 | 377 | double max = DBL_EPSILON; |
| 381 | − int c, i; | |
| 382 | 378 | |
| 383 | 379 | if (channel == -1) { |
| 384 | − for (c = 0; c < frame->channels; c++) { | |
| 380 | + for (int c = 0; c < frame->channels; c++) { | |
| 385 | 381 | double *data_ptr = (double *)frame->extended_data[c]; |
| 386 | 382 | |
| 387 | − for (i = 0; i < frame->nb_samples; i++) | |
| 383 | + for (int i = 0; i < frame->nb_samples; i++) | |
| 388 | 384 | max = fmax(max, fabs(data_ptr[i])); |
| 389 | 385 | } |
| 390 | 386 | } else { |
| 391 | 387 | double *data_ptr = (double *)frame->extended_data[channel]; |
| 392 | 388 | |
| 393 | − for (i = 0; i < frame->nb_samples; i++) | |
| 389 | + for (int i = 0; i < frame->nb_samples; i++) | |
| 394 | 390 | max = fmax(max, fabs(data_ptr[i])); |
| 395 | 391 | } |
| 396 | 392 | |
| @@ -400,13 +396,12 @@ static double find_peak_magnitude(AVFrame *frame, int channel) · 3 unmodified lines | ||
| 400 | 396 | static double compute_frame_rms(AVFrame *frame, int channel) |
| 401 | 397 | { |
| 402 | 398 | double rms_value = 0.0; |
| 403 | − int c, i; | |
| 404 | 399 | |
| 405 | 400 | if (channel == -1) { |
| 406 | − for (c = 0; c < frame->channels; c++) { | |
| 401 | + for (int c = 0; c < frame->channels; c++) { | |
| 407 | 402 | const double *data_ptr = (double *)frame->extended_data[c]; |
| 408 | 403 | |
| 409 | − for (i = 0; i < frame->nb_samples; i++) { | |
| 404 | + for (int i = 0; i < frame->nb_samples; i++) { | |
| 410 | 405 | rms_value += pow_2(data_ptr[i]); |
| 411 | 406 | } |
| 412 | 407 | } |
| @@ -414,7 +409,7 @@ static double compute_frame_rms(AVFrame *frame, int channel) · 1 unmodified line | ||
| 414 | 409 | rms_value /= frame->nb_samples * frame->channels; |
| 415 | 410 | } else { |
| 416 | 411 | 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++) { | |
| 418 | 413 | rms_value += pow_2(data_ptr[i]); |
| 419 | 414 | } |
| 420 | 415 | |
| @@ -441,9 +436,8 @@ static local_gain get_max_local_gain(DynamicAudioNormalizerContext *s, AVFrame * · 20 unmodified lines | ||
| 441 | 436 | static double minimum_filter(cqueue *q) |
| 442 | 437 | { |
| 443 | 438 | double min = DBL_MAX; |
| 444 | − int i; | |
| 445 | 439 | |
| 446 | − for (i = 0; i < cqueue_size(q); i++) { | |
| 440 | + for (int i = 0; i < cqueue_size(q); i++) { | |
| 447 | 441 | min = fmin(min, cqueue_peek(q, i)); |
| 448 | 442 | } |
| 449 | 443 | |
| @@ -454,9 +448,8 @@ static double gaussian_filter(DynamicAudioNormalizerContext *s, cqueue *q, cqueu · 4 unmodified lines | ||
| 454 | 448 | { |
| 455 | 449 | const double *weights = s->weights; |
| 456 | 450 | double result = 0.0, tsum = 0.0; |
| 457 | − int i; | |
| 458 | 451 | |
| 459 | − for (i = 0; i < cqueue_size(q); i++) { | |
| 452 | + for (int i = 0; i < cqueue_size(q); i++) { | |
| 460 | 453 | double tq_item = cqueue_peek(tq, i); |
| 461 | 454 | double q_item = cqueue_peek(q, i); |
| 462 | 455 | |
| @@ -540,21 +533,20 @@ static void perform_dc_correction(DynamicAudioNormalizerContext *s, AVFrame *fra · 77 unmodified lines | ||
| 540 | 533 | { |
| 541 | 534 | const double diff = 1.0 / frame->nb_samples; |
| 542 | 535 | int is_first_frame = cqueue_empty(s->gain_history_original[0]); |
| 543 | − int c, i; | |
| 544 | 536 | |
| 545 | − for (c = 0; c < s->channels; c++) { | |
| 537 | + for (int c = 0; c < s->channels; c++) { | |
| 546 | 538 | const int bypass = bypass_channel(s, frame, c); |
| 547 | 539 | double *dst_ptr = (double *)frame->extended_data[c]; |
| 548 | 540 | double current_average_value = 0.0; |
| 549 | 541 | double prev_value; |
| 550 | 542 | |
| 551 | − for (i = 0; i < frame->nb_samples; i++) | |
| 543 | + for (int i = 0; i < frame->nb_samples; i++) | |
| 552 | 544 | current_average_value += dst_ptr[i] * diff; |
| 553 | 545 | |
| 554 | 546 | prev_value = is_first_frame ? current_average_value : s->dc_correction_value[c]; |
| 555 | 547 | s->dc_correction_value[c] = is_first_frame ? current_average_value : update_value(current_average_value, s->dc_correction_value[c], 0.1); |
| 556 | 548 | |
| 557 | − for (i = 0; i < frame->nb_samples && !bypass; i++) { | |
| 549 | + for (int i = 0; i < frame->nb_samples && !bypass; i++) { | |
| 558 | 550 | dst_ptr[i] -= fade(prev_value, s->dc_correction_value[c], i, frame->nb_samples); |
| 559 | 551 | } |
| 560 | 552 | } |
| @@ -586,13 +578,12 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 25 unmodified lines | ||
| 586 | 578 | AVFrame *frame, int channel) |
| 587 | 579 | { |
| 588 | 580 | double variance = 0.0; |
| 589 | − int i, c; | |
| 590 | 581 | |
| 591 | 582 | if (channel == -1) { |
| 592 | − for (c = 0; c < s->channels; c++) { | |
| 583 | + for (int c = 0; c < s->channels; c++) { | |
| 593 | 584 | const double *data_ptr = (double *)frame->extended_data[c]; |
| 594 | 585 | |
| 595 | − for (i = 0; i < frame->nb_samples; i++) { | |
| 586 | + for (int i = 0; i < frame->nb_samples; i++) { | |
| 596 | 587 | variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero* |
| 597 | 588 | } |
| 598 | 589 | } |
| @@ -600,7 +591,7 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 1 unmodified line | ||
| 600 | 591 | } else { |
| 601 | 592 | const double *data_ptr = (double *)frame->extended_data[channel]; |
| 602 | 593 | |
| 603 | − for (i = 0; i < frame->nb_samples; i++) { | |
| 594 | + for (int i = 0; i < frame->nb_samples; i++) { | |
| 604 | 595 | variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero* |
| 605 | 596 | } |
| 606 | 597 | variance /= frame->nb_samples - 1; |
| @@ -612,7 +603,6 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, · 5 unmodified lines | ||
| 612 | 603 | static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame) |
| 613 | 604 | { |
| 614 | 605 | int is_first_frame = cqueue_empty(s->gain_history_original[0]); |
| 615 | − int c, i; | |
| 616 | 606 | |
| 617 | 607 | if (s->channels_coupled) { |
| 618 | 608 | 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 | ||
| 625 | 615 | prev_actual_thresh = setup_compress_thresh(prev_value); |
| 626 | 616 | curr_actual_thresh = setup_compress_thresh(s->compress_threshold[0]); |
| 627 | 617 | |
| 628 | − for (c = 0; c < s->channels; c++) { | |
| 618 | + for (int c = 0; c < s->channels; c++) { | |
| 629 | 619 | double *const dst_ptr = (double *)frame->extended_data[c]; |
| 630 | 620 | const int bypass = bypass_channel(s, frame, c); |
| 631 | 621 | |
| 632 | 622 | if (bypass) |
| 633 | 623 | continue; |
| 634 | 624 | |
| 635 | − for (i = 0; i < frame->nb_samples; i++) { | |
| 625 | + for (int i = 0; i < frame->nb_samples; i++) { | |
| 636 | 626 | const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples); |
| 637 | 627 | dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]); |
| 638 | 628 | } |
| 639 | 629 | } |
| 640 | 630 | } else { |
| 641 | − for (c = 0; c < s->channels; c++) { | |
| 631 | + for (int c = 0; c < s->channels; c++) { | |
| 642 | 632 | const int bypass = bypass_channel(s, frame, c); |
| 643 | 633 | const double standard_deviation = compute_frame_std_dev(s, frame, c); |
| 644 | 634 | 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 | ||
| 652 | 642 | curr_actual_thresh = setup_compress_thresh(s->compress_threshold[c]); |
| 653 | 643 | |
| 654 | 644 | 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++) { | |
| 656 | 646 | const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples); |
| 657 | 647 | dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]); |
| 658 | 648 | } |
| @@ -718,14 +708,10 @@ static int analyze_frame(DynamicAudioNormalizerContext *s, AVFilterLink *outlink · 59 unmodified lines | ||
| 718 | 708 | |
| 719 | 709 | if (s->channels_coupled) { |
| 720 | 710 | 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++) | |
| 724 | 712 | update_gain_history(s, c, gain); |
| 725 | 713 | } else { |
| 726 | − int c; | |
| 727 | − | |
| 728 | − for (c = 0; c < s->channels; c++) | |
| 714 | + for (int c = 0; c < s->channels; c++) | |
| 729 | 715 | update_gain_history(s, c, get_max_local_gain(s, analyze_frame, c)); |
| 730 | 716 | } |
| 731 | 717 | |
| @@ -735,9 +721,7 @@ static int analyze_frame(DynamicAudioNormalizerContext *s, AVFilterLink *outlink · 3 unmodified lines | ||
| 735 | 721 | static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *in, |
| 736 | 722 | AVFrame *frame, int enabled) |
| 737 | 723 | { |
| 738 | − int c, i; | |
| 739 | − | |
| 740 | − for (c = 0; c < s->channels; c++) { | |
| 724 | + for (int c = 0; c < s->channels; c++) { | |
| 741 | 725 | const int bypass = bypass_channel(s, frame, c); |
| 742 | 726 | const double *src_ptr = (const double *)in->extended_data[c]; |
| 743 | 727 | double *dst_ptr = (double *)frame->extended_data[c]; |
| @@ -745,7 +729,7 @@ static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *in, · 1 unmodified line | ||
| 745 | 729 | |
| 746 | 730 | cqueue_dequeue(s->gain_history_smoothed[c], ¤t_amplification_factor); |
| 747 | 731 | |
| 748 | − for (i = 0; i < frame->nb_samples && enabled && !bypass; i++) { | |
| 732 | + for (int i = 0; i < frame->nb_samples && enabled && !bypass; i++) { | |
| 749 | 733 | const double amplification_factor = fade(s->prev_amplification_factor[c], |
| 750 | 734 | current_amplification_factor, i, |
| 751 | 735 | frame->nb_samples); |
| @@ -811,15 +795,14 @@ static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink, · 59 unmodified lines | ||
| 811 | 795 | AVFilterLink *outlink) |
| 812 | 796 | { |
| 813 | 797 | AVFrame *out = ff_get_audio_buffer(outlink, s->sample_advance); |
| 814 | − int c, i; | |
| 815 | 798 | |
| 816 | 799 | if (!out) |
| 817 | 800 | return AVERROR(ENOMEM); |
| 818 | 801 | |
| 819 | − for (c = 0; c < s->channels; c++) { | |
| 802 | + for (int c = 0; c < s->channels; c++) { | |
| 820 | 803 | double *dst_ptr = (double *)out->extended_data[c]; |
| 821 | 804 | |
| 822 | − for (i = 0; i < out->nb_samples; i++) { | |
| 805 | + for (int i = 0; i < out->nb_samples; i++) { | |
| 823 | 806 | dst_ptr[i] = s->alt_boundary_mode ? DBL_EPSILON : ((s->target_rms > DBL_EPSILON) ? fmin(s->peak_value, s->target_rms) : s->peak_value); |
| 824 | 807 | if (s->dc_correction) { |
| 825 | 808 | dst_ptr[i] *= ((i % 2) == 1) ? -1 : 1; |