Coverage Report

Created: 2026-12-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/external/faac/libfaar/polyresample_wide.inc
Line
Count
Source
1
/*
2
 * FAAR - Freeware Advanced Audio Resampler
3
 * Copyright (C) 2026 Nils Schimmelmann
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 */
15
/* Mixed builds' High phase bank: double coefficients and accumulators over
16
 * float sample histories, where float builds use float2. */
17
#if !FAAR_RESAMPLER_FLOAT
18
static void filter_wide_phase(const faar_resampler *r, size_t base,
19
0
        size_t phase, double d, bool reverse, float *output) {
20
0
    const size_t len = r->filter_len, half_len = (len - 1) / 2;
21
0
    const double *c1 = r->polyphase_wide_table + (phase + 1) * len;
22
#if defined(_MSC_VER)
23
    __declspec(align(64)) double coeffs[POLYRESAMPLE_MAX_FILTER_LEN];
24
#else
25
0
    alignas(64) double coeffs[POLYRESAMPLE_MAX_FILTER_LEN];
26
0
#endif
27
0
    if ((len & 1) && phase == 0 && d < exact_phase_eps) {
28
0
        for (uint16_t c = 0; c < r->channels; ++c) {
29
0
            const float *h = r->hist[c] + base;
30
0
            double sum = c1[half_len] * h[half_len];
31
0
            for (size_t j = 0; j < half_len; ++j)
32
0
                sum += c1[j] * ((double)h[j] + h[len - 1 - j]);
33
0
            output[c] = (float)sum;
34
0
        }
35
0
        return;
36
0
    }
37
0
    const double *row = c1;
38
0
    if (d < exact_phase_eps) {
39
0
        if (reverse && r->polyphase_wide_reverse) {
40
0
            row = r->polyphase_wide_reverse + (phase + 1) * len;
41
0
        } else if (reverse) {
42
0
            for (size_t j = 0; j < len; ++j) coeffs[len - 1 - j] = c1[j];
43
0
            row = coeffs;
44
0
        }
45
0
    } else {
46
        /* Four-point Lagrange weights, as in the ordinary bank. */
47
0
        const double *c0 = c1 - len, *c2 = c1 + len, *c3 = c2 + len;
48
0
        double d2 = d * d, d3 = d2 * d;
49
0
        double w0 = (-d3 + 3 * d2 - 2 * d) / 6;
50
0
        double w1 = (d3 - 2 * d2 - d + 2) / 2;
51
0
        double w2 = (-d3 + d2 + 2 * d) / 2;
52
0
        double w3 = (d3 - d) / 6;
53
0
        for (size_t j = 0; j < len; ++j)
54
0
            coeffs[reverse ? len - 1 - j : j]
55
0
                = w0 * c0[j] + w1 * c1[j] + w2 * c2[j] + w3 * c3[j];
56
0
        row = coeffs;
57
0
    }
58
0
    for (uint16_t c = 0; c < r->channels; ++c) {
59
0
        const float *h = r->hist[c] + base;
60
0
        double a0 = 0, a1 = 0, a2 = 0, a3 = 0;
61
0
        size_t j = 0;
62
0
        for (; j + 3 < len; j += 4) {
63
0
            a0 += (double)h[j] * row[j];
64
0
            a1 += (double)h[j + 1] * row[j + 1];
65
0
            a2 += (double)h[j + 2] * row[j + 2];
66
0
            a3 += (double)h[j + 3] * row[j + 3];
67
0
        }
68
0
        double sum = a0 + a1 + a2 + a3;
69
0
        for (; j < len; ++j) sum += (double)h[j] * row[j];
70
0
        output[c] = (float)sum;
71
0
    }
72
0
}
73
#endif