Also guard against overflow when subtracting from unsigned.
Unified · Split
| @@ -762,7 +762,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) · 761 unmodified lines | ||
| 762 | 762 | |
| 763 | 763 | /* get lower loudness to consider */ |
| 764 | 764 | n = 0; |
| 765 | − nb_pow = LRA_LOWER_PRC * nb_powers / 100. + 0.5; | |
| 765 | + nb_pow = LRA_LOWER_PRC * 0.01 * nb_powers + 0.5; | |
| 766 | 766 | for (i = gate_hist_pos; i < HIST_SIZE; i++) { |
| 767 | 767 | n += ebur128->i3000.histogram[i].count; |
| 768 | 768 | if (n >= nb_pow) { |
| @@ -773,9 +773,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) · 4 unmodified lines | ||
| 773 | 773 | |
| 774 | 774 | /* get higher loudness to consider */ |
| 775 | 775 | n = nb_powers; |
| 776 | − nb_pow = LRA_HIGHER_PRC * nb_powers / 100. + 0.5; | |
| 776 | + nb_pow = LRA_HIGHER_PRC * 0.01 * nb_powers + 0.5; | |
| 777 | 777 | for (i = HIST_SIZE - 1; i >= 0; i--) { |
| 778 | − n -= ebur128->i3000.histogram[i].count; | |
| 778 | + n -= FFMIN(n, ebur128->i3000.histogram[i].count); | |
| 779 | 779 | if (n < nb_pow) { |
| 780 | 780 | ebur128->lra_high = ebur128->i3000.histogram[i].loudness; |
| 781 | 781 | break; |