Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -105,73 +105,76 @@ static void fn(queue_sample)(AVFilterContext *ctx, · 104 unmodified lines | ||
| 105 | 105 | *window_pos = 0; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | −static ftype fn(compute_avg)(ftype *cache, ftype sample, ftype wsample, | |
| 108 | +static ftype fn(compute_avg)(ftype *cache, ftype x, ftype px, | |
| 109 | 109 | int window_size, int *unused, int *unused2) |
| 110 | 110 | { |
| 111 | 111 | ftype r; |
| 112 | 112 | |
| 113 | − cache[0] += FABS(sample); | |
| 114 | − cache[0] -= FABS(wsample); | |
| 113 | + cache[0] += FABS(x); | |
| 114 | + cache[0] -= FABS(px); | |
| 115 | 115 | cache[0] = r = FMAX(cache[0], ZERO); |
| 116 | 116 | |
| 117 | 117 | return r / window_size; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | −static ftype fn(compute_median)(ftype *peak, ftype sample, ftype wsample, | |
| 121 | − int size, int *ffront, int *bback) | |
| 120 | +#define PEAKS(empty_value,op,sample, psample)\ | |
| 121 | + if (!empty && psample == ss[front]) { \ | |
| 122 | + ss[front] = empty_value; \ | |
| 123 | + if (back != front) { \ | |
| 124 | + front--; \ | |
| 125 | + if (front < 0) \ | |
| 126 | + front = n - 1; \ | |
| 127 | + } \ | |
| 128 | + empty = front == back; \ | |
| 129 | + } \ | |
| 130 | + \ | |
| 131 | + if (!empty && sample op ss[front]) { \ | |
| 132 | + while (1) { \ | |
| 133 | + ss[front] = empty_value; \ | |
| 134 | + if (back == front) { \ | |
| 135 | + empty = 1; \ | |
| 136 | + break; \ | |
| 137 | + } \ | |
| 138 | + front--; \ | |
| 139 | + if (front < 0) \ | |
| 140 | + front = n - 1; \ | |
| 141 | + } \ | |
| 142 | + } \ | |
| 143 | + \ | |
| 144 | + while (!empty && sample op ss[back]) { \ | |
| 145 | + ss[back] = empty_value; \ | |
| 146 | + if (back == front) { \ | |
| 147 | + empty = 1; \ | |
| 148 | + break; \ | |
| 149 | + } \ | |
| 150 | + back++; \ | |
| 151 | + if (back >= n) \ | |
| 152 | + back = 0; \ | |
| 153 | + } \ | |
| 154 | + \ | |
| 155 | + if (!empty) { \ | |
| 156 | + back--; \ | |
| 157 | + if (back < 0) \ | |
| 158 | + back = n - 1; \ | |
| 159 | + } | |
| 160 | + | |
| 161 | +static ftype fn(compute_median)(ftype *ss, ftype x, ftype px, | |
| 162 | + int n, int *ffront, int *bback) | |
| 122 | 163 | { |
| 123 | − ftype r, abs_sample = FABS(sample); | |
| 164 | + ftype r, ax = FABS(x); | |
| 124 | 165 | int front = *ffront; |
| 125 | 166 | int back = *bback; |
| 126 | − int empty = front == back && peak[front] == -ONE; | |
| 167 | + int empty = front == back && ss[front] == -ONE; | |
| 127 | 168 | int idx; |
| 128 | 169 | |
| 129 | − if (!empty && FABS(wsample) == peak[front]) { | |
| 130 | − peak[front] = -ONE; | |
| 131 | − if (back != front) { | |
| 132 | − front--; | |
| 133 | − if (front < 0) | |
| 134 | − front = size - 1; | |
| 135 | − } | |
| 136 | − empty = front == back; | |
| 137 | − } | |
| 138 | − | |
| 139 | − if (!empty && abs_sample > peak[front]) { | |
| 140 | − while (1) { | |
| 141 | − peak[front] = -ONE; | |
| 142 | − if (back == front) { | |
| 143 | − empty = 1; | |
| 144 | − break; | |
| 145 | − } | |
| 146 | − front--; | |
| 147 | − if (front < 0) | |
| 148 | − front = size - 1; | |
| 149 | − } | |
| 150 | − } | |
| 151 | − | |
| 152 | − while (!empty && abs_sample > peak[back]) { | |
| 153 | − peak[back] = -ONE; | |
| 154 | − if (back == front) { | |
| 155 | − empty = 1; | |
| 156 | − break; | |
| 157 | − } | |
| 158 | − back++; | |
| 159 | − if (back >= size) | |
| 160 | − back = 0; | |
| 161 | − } | |
| 162 | − | |
| 163 | − if (!empty) { | |
| 164 | − back--; | |
| 165 | − if (back < 0) | |
| 166 | − back = size - 1; | |
| 167 | − } | |
| 170 | + PEAKS(-ONE, >, ax, FABS(px)) | |
| 168 | 171 | |
| 169 | − peak[back] = abs_sample; | |
| 170 | − idx = (back <= front) ? back + (front - back + 1) / 2 : back + (size + front - back + 1) / 2; | |
| 171 | − if (idx >= size) | |
| 172 | − idx -= size; | |
| 173 | − av_assert2(idx >= 0 && idx < size); | |
| 174 | − r = peak[idx]; | |
| 172 | + ss[back] = ax; | |
| 173 | + idx = (back <= front) ? back + (front - back + 1) / 2 : back + (n + front - back + 1) / 2; | |
| 174 | + if (idx >= n) | |
| 175 | + idx -= n; | |
| 176 | + av_assert2(idx >= 0 && idx < n); | |
| 177 | + r = ss[idx]; | |
| 175 | 178 | |
| 176 | 179 | *ffront = front; |
| 177 | 180 | *bback = back; |
| @@ -179,56 +182,18 @@ static ftype fn(compute_median)(ftype *peak, ftype sample, ftype wsample, · 1 unmodified line | ||
| 179 | 182 | return r; |
| 180 | 183 | } |
| 181 | 184 | |
| 182 | −static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample, | |
| 183 | − int size, int *ffront, int *bback) | |
| 185 | +static ftype fn(compute_peak)(ftype *ss, ftype x, ftype px, | |
| 186 | + int n, int *ffront, int *bback) | |
| 184 | 187 | { |
| 185 | − ftype r, abs_sample = FABS(sample); | |
| 188 | + ftype r, ax = FABS(x); | |
| 186 | 189 | int front = *ffront; |
| 187 | 190 | int back = *bback; |
| 188 | − int empty = front == back && peak[front] == ZERO; | |
| 189 | − | |
| 190 | − if (!empty && FABS(wsample) == peak[front]) { | |
| 191 | − peak[front] = ZERO; | |
| 192 | − if (back != front) { | |
| 193 | − front--; | |
| 194 | − if (front < 0) | |
| 195 | − front = size - 1; | |
| 196 | − } | |
| 197 | − empty = front == back; | |
| 198 | − } | |
| 191 | + int empty = front == back && ss[front] == ZERO; | |
| 199 | 192 | |
| 200 | − if (!empty && abs_sample >= peak[front]) { | |
| 201 | − while (1) { | |
| 202 | − peak[front] = ZERO; | |
| 203 | − if (back == front) { | |
| 204 | − empty = 1; | |
| 205 | − break; | |
| 206 | − } | |
| 207 | − front--; | |
| 208 | − if (front < 0) | |
| 209 | − front = size - 1; | |
| 210 | − } | |
| 211 | − } | |
| 193 | + PEAKS(ZERO, >=, ax, FABS(px)) | |
| 212 | 194 | |
| 213 | − while (!empty && abs_sample >= peak[back]) { | |
| 214 | − peak[back] = ZERO; | |
| 215 | − if (back == front) { | |
| 216 | − empty = 1; | |
| 217 | − break; | |
| 218 | − } | |
| 219 | − back++; | |
| 220 | − if (back >= size) | |
| 221 | − back = 0; | |
| 222 | − } | |
| 223 | − | |
| 224 | − if (!empty) { | |
| 225 | − back--; | |
| 226 | − if (back < 0) | |
| 227 | − back = size - 1; | |
| 228 | − } | |
| 229 | − | |
| 230 | − peak[back] = abs_sample; | |
| 231 | − r = peak[front]; | |
| 195 | + ss[back] = ax; | |
| 196 | + r = ss[front]; | |
| 232 | 197 | |
| 233 | 198 | *ffront = front; |
| 234 | 199 | *bback = back; |
| @@ -236,57 +201,19 @@ static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample, · 1 unmodified line | ||
| 236 | 201 | return r; |
| 237 | 202 | } |
| 238 | 203 | |
| 239 | −static ftype fn(compute_ptp)(ftype *peak, ftype sample, ftype wsample, | |
| 240 | − int size, int *ffront, int *bback) | |
| 204 | +static ftype fn(compute_ptp)(ftype *ss, ftype x, ftype px, | |
| 205 | + int n, int *ffront, int *bback) | |
| 241 | 206 | { |
| 242 | 207 | int front = *ffront; |
| 243 | 208 | int back = *bback; |
| 244 | − int empty = front == back && peak[front] == TMIN; | |
| 209 | + int empty = front == back && ss[front] == TMIN; | |
| 245 | 210 | ftype r, max, min; |
| 246 | 211 | |
| 247 | − if (!empty && wsample == peak[front]) { | |
| 248 | − peak[front] = TMIN; | |
| 249 | − if (back != front) { | |
| 250 | − front--; | |
| 251 | − if (front < 0) | |
| 252 | − front = size - 1; | |
| 253 | − } | |
| 254 | − empty = front == back; | |
| 255 | − } | |
| 256 | − | |
| 257 | − if (!empty && sample >= peak[front]) { | |
| 258 | − while (1) { | |
| 259 | − peak[front] = TMIN; | |
| 260 | − if (back == front) { | |
| 261 | − empty = 1; | |
| 262 | − break; | |
| 263 | − } | |
| 264 | − front--; | |
| 265 | − if (front < 0) | |
| 266 | − front = size - 1; | |
| 267 | − } | |
| 268 | − } | |
| 269 | − | |
| 270 | − while (!empty && sample >= peak[back]) { | |
| 271 | − peak[back] = TMIN; | |
| 272 | − if (back == front) { | |
| 273 | − empty = 1; | |
| 274 | − break; | |
| 275 | − } | |
| 276 | − back++; | |
| 277 | − if (back >= size) | |
| 278 | − back = 0; | |
| 279 | − } | |
| 280 | − | |
| 281 | − if (!empty) { | |
| 282 | − back--; | |
| 283 | − if (back < 0) | |
| 284 | − back = size - 1; | |
| 285 | − } | |
| 212 | + PEAKS(TMIN, >=, x, px) | |
| 286 | 213 | |
| 287 | − peak[back] = sample; | |
| 288 | − max = peak[front]; | |
| 289 | − min = sample; | |
| 214 | + ss[back] = x; | |
| 215 | + max = ss[front]; | |
| 216 | + min = x; | |
| 290 | 217 | r = FABS(min) + FABS(max - min); |
| 291 | 218 | |
| 292 | 219 | *ffront = front; |
| @@ -295,13 +222,13 @@ static ftype fn(compute_ptp)(ftype *peak, ftype sample, ftype wsample, · 2 unmodified lines | ||
| 295 | 222 | return r; |
| 296 | 223 | } |
| 297 | 224 | |
| 298 | −static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample, | |
| 225 | +static ftype fn(compute_rms)(ftype *cache, ftype x, ftype px, | |
| 299 | 226 | int window_size, int *unused, int *unused2) |
| 300 | 227 | { |
| 301 | 228 | ftype r; |
| 302 | 229 | |
| 303 | − cache[0] += sample * sample; | |
| 304 | − cache[0] -= wsample * wsample; | |
| 230 | + cache[0] += x * x; | |
| 231 | + cache[0] -= px * px; | |
| 305 | 232 | cache[0] = r = FMAX(cache[0], ZERO); |
| 306 | 233 | |
| 307 | 234 | return SQRT(r / window_size); |