/src/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 | 151k | size_t phase, double d, bool reverse, float *output) { |
20 | 151k | const size_t len = r->filter_len, half_len = (len - 1) / 2; |
21 | 151k | 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 | 151k | alignas(64) double coeffs[POLYRESAMPLE_MAX_FILTER_LEN]; |
26 | 151k | #endif |
27 | 151k | if ((len & 1) && phase == 0 && d < exact_phase_eps) { |
28 | 8.93k | for (uint16_t c = 0; c < r->channels; ++c) { |
29 | 5.76k | const float *h = r->hist[c] + base; |
30 | 5.76k | double sum = c1[half_len] * h[half_len]; |
31 | 646k | for (size_t j = 0; j < half_len; ++j) |
32 | 640k | sum += c1[j] * ((double)h[j] + h[len - 1 - j]); |
33 | 5.76k | output[c] = (float)sum; |
34 | 5.76k | } |
35 | 3.16k | return; |
36 | 3.16k | } |
37 | 148k | const double *row = c1; |
38 | 148k | if (d < exact_phase_eps) { |
39 | 90.9k | if (reverse && r->polyphase_wide_reverse) { |
40 | 32.1k | row = r->polyphase_wide_reverse + (phase + 1) * len; |
41 | 58.8k | } else if (reverse) { |
42 | 6.70M | for (size_t j = 0; j < len; ++j) coeffs[len - 1 - j] = c1[j]; |
43 | 13.3k | row = coeffs; |
44 | 13.3k | } |
45 | 90.9k | } else { |
46 | | /* Four-point Lagrange weights, as in the ordinary bank. */ |
47 | 57.7k | const double *c0 = c1 - len, *c2 = c1 + len, *c3 = c2 + len; |
48 | 57.7k | double d2 = d * d, d3 = d2 * d; |
49 | 57.7k | double w0 = (-d3 + 3 * d2 - 2 * d) / 6; |
50 | 57.7k | double w1 = (d3 - 2 * d2 - d + 2) / 2; |
51 | 57.7k | double w2 = (-d3 + d2 + 2 * d) / 2; |
52 | 57.7k | double w3 = (d3 - d) / 6; |
53 | 26.3M | for (size_t j = 0; j < len; ++j) |
54 | 26.2M | coeffs[reverse ? len - 1 - j : j] |
55 | 26.2M | = w0 * c0[j] + w1 * c1[j] + w2 * c2[j] + w3 * c3[j]; |
56 | 57.7k | row = coeffs; |
57 | 57.7k | } |
58 | 355k | for (uint16_t c = 0; c < r->channels; ++c) { |
59 | 207k | const float *h = r->hist[c] + base; |
60 | 207k | double a0 = 0, a1 = 0, a2 = 0, a3 = 0; |
61 | 207k | size_t j = 0; |
62 | 11.3M | for (; j + 3 < len; j += 4) { |
63 | 11.1M | a0 += (double)h[j] * row[j]; |
64 | 11.1M | a1 += (double)h[j + 1] * row[j + 1]; |
65 | 11.1M | a2 += (double)h[j + 2] * row[j + 2]; |
66 | 11.1M | a3 += (double)h[j + 3] * row[j + 3]; |
67 | 11.1M | } |
68 | 207k | double sum = a0 + a1 + a2 + a3; |
69 | 568k | for (; j < len; ++j) sum += (double)h[j] * row[j]; |
70 | 207k | output[c] = (float)sum; |
71 | 207k | } |
72 | 148k | } |
73 | | #endif |