| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License along | ||
| 15 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "libavutil/avassert.h" | ||
| 20 | #include "libavutil/mem_internal.h" | ||
| 21 | |||
| 22 | #include "libavcodec/lpc.h" | ||
| 23 | |||
| 24 | #include "checkasm.h" | ||
| 25 | |||
| 26 | #define randomize_int32(buf, len) \ | ||
| 27 | do { \ | ||
| 28 | for (int i = 0; i < len; i++) { \ | ||
| 29 | int32_t f = ((int)(UINT32_MAX >> 17)) - ((int)(rnd() >> 16)); \ | ||
| 30 | buf[i] = f; \ | ||
| 31 | } \ | ||
| 32 | } while (0) | ||
| 33 | |||
| 34 | #define EPS 0.005 | ||
| 35 | |||
| 36 | 6 | static void test_window(int len) | |
| 37 | { | ||
| 38 | 6 | LOCAL_ALIGNED(16, int32_t, src, [5000]); | |
| 39 | 6 | LOCAL_ALIGNED(16, double, dst0, [5000]); | |
| 40 | 6 | LOCAL_ALIGNED(16, double, dst1, [5000]); | |
| 41 | |||
| 42 | 6 | declare_func(void, const int32_t *in, ptrdiff_t len, double *out); | |
| 43 | |||
| 44 |
2/2✓ Branch 1 taken 23579 times.
✓ Branch 2 taken 6 times.
|
23585 | randomize_int32(src, len); |
| 45 | |||
| 46 | 6 | call_ref(src, len, dst0); | |
| 47 | 6 | call_new(src, len, dst1); | |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 23579 times.
✓ Branch 1 taken 6 times.
|
23585 | for (int i = 0; i < len; i++) { |
| 50 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23579 times.
|
23579 | if (!double_near_abs_eps(dst0[i], dst1[i], EPS)) { |
| 51 | ✗ | fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", | |
| 52 | ✗ | i, dst0[i], dst1[i], dst0[i] - dst1[i]); | |
| 53 | ✗ | fail(); | |
| 54 | ✗ | break; | |
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
6 | bench_new(src, 4608 + (len & 1), dst1); |
| 59 | 6 | } | |
| 60 | |||
| 61 | 4 | static void test_compute_autocorr(ptrdiff_t len, int lag) | |
| 62 | { | ||
| 63 | 4 | const double eps = EPS * (double)len; | |
| 64 | 4 | LOCAL_ALIGNED(32, double, src, [5000 + 2 + MAX_LPC_ORDER]); | |
| 65 | 4 | LOCAL_ALIGNED(16, double, dst0, [MAX_LPC_ORDER + 1]); | |
| 66 | 4 | LOCAL_ALIGNED(16, double, dst1, [MAX_LPC_ORDER + 1]); | |
| 67 | |||
| 68 | 4 | declare_func(void, const double *in, ptrdiff_t len, int lag, double *out); | |
| 69 | |||
| 70 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | av_assert0(lag >= 0 && lag <= MAX_LPC_ORDER); |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 4 times.
|
132 | for (int i = 0; i < MAX_LPC_ORDER; i++) |
| 73 | 128 | src[i] = 0.; | |
| 74 | |||
| 75 | 4 | src += MAX_LPC_ORDER; | |
| 76 | |||
| 77 |
2/2✓ Branch 0 taken 20008 times.
✓ Branch 1 taken 4 times.
|
20012 | for (int i = 0; i < 5000 + 2; i++) { |
| 78 | 20008 | src[i] = (double)rnd() / (double)UINT_MAX; | |
| 79 | } | ||
| 80 | |||
| 81 | 4 | call_ref(src, len, lag, dst0); | |
| 82 | 4 | call_new(src, len, lag, dst1); | |
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 4 times.
|
48 | for (size_t i = 0; i <= lag; i++) { |
| 85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
|
44 | if (!double_near_abs_eps(dst0[i], dst1[i], eps)) { |
| 86 | ✗ | fprintf(stderr, "%zu: %- .12f - %- .12f = % .12g\n", | |
| 87 | ✗ | i, dst0[i], dst1[i], dst0[i] - dst1[i]); | |
| 88 | ✗ | fail(); | |
| 89 | ✗ | break; | |
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
4 | bench_new(src, 4608 + (len & 1), lag, dst1); |
| 94 | 4 | } | |
| 95 | |||
| 96 | 14 | void checkasm_check_lpc(void) | |
| 97 | { | ||
| 98 | LPCContext ctx; | ||
| 99 | 14 | int len = 2000 + rnd() % 3000; | |
| 100 | static const int lags[] = { 8, 12, }; | ||
| 101 | |||
| 102 | 14 | ff_lpc_init(&ctx, 32, 16, FF_LPC_TYPE_DEFAULT); | |
| 103 | |||
| 104 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
|
14 | if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_even")) { |
| 105 | 3 | test_window(len & ~1); | |
| 106 | } | ||
| 107 | 14 | report("apply_welch_window_even"); | |
| 108 | |||
| 109 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
|
14 | if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_odd")) { |
| 110 | 3 | test_window(len | 1); | |
| 111 | } | ||
| 112 | 14 | report("apply_welch_window_odd"); | |
| 113 | 14 | ff_lpc_end(&ctx); | |
| 114 | |||
| 115 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (size_t i = 0; i < FF_ARRAY_ELEMS(lags); i++) { |
| 116 | 28 | ff_lpc_init(&ctx, len, lags[i], FF_LPC_TYPE_DEFAULT); | |
| 117 |
2/2✓ Branch 3 taken 4 times.
✓ Branch 4 taken 24 times.
|
28 | if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_even", lags[i])) |
| 118 | 4 | test_compute_autocorr(len & ~1, lags[i]); | |
| 119 | #if !ARCH_X86 | ||
| 120 | if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_odd", lags[i])) | ||
| 121 | test_compute_autocorr(len | 1, lags[i]); | ||
| 122 | #endif | ||
| 123 | 28 | ff_lpc_end(&ctx); | |
| 124 | } | ||
| 125 | 14 | report("compute_autocorr"); | |
| 126 | 14 | } | |
| 127 |