/proc/self/cwd/external/faac/libfaar/libfaar_internal.h
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 | | #ifndef LIBFAAR_INTERNAL_H |
16 | | #define LIBFAAR_INTERNAL_H |
17 | | |
18 | | #include "faar.h" |
19 | | #include "../common/build_defaults.h" |
20 | | |
21 | | /* resampler-float is off by default. */ |
22 | | #ifndef FAAR_RESAMPLER_FLOAT |
23 | | #define FAAR_RESAMPLER_FLOAT 0 |
24 | | #endif |
25 | | |
26 | | #include <stdlib.h> |
27 | | #include <string.h> |
28 | | #include <math.h> |
29 | | #include <stdbool.h> |
30 | | #include <assert.h> |
31 | | |
32 | | /* Ports override both hooks with -D or a force-included header. Detect the |
33 | | * overrides first: libc realloc must never see a custom allocator's block. */ |
34 | | #if defined(AllocMemory) != defined(FreeMemory) |
35 | | #error "Override AllocMemory and FreeMemory together" |
36 | | #endif |
37 | | #if defined(AllocMemory) |
38 | | #define FAAR_CUSTOM_ALLOCATOR 1 |
39 | | #else |
40 | 7.98k | #define AllocMemory(size) malloc(size) |
41 | 10.0k | #define FreeMemory(block) free(block) |
42 | | #endif |
43 | | |
44 | | /* Zeroed array allocation; AllocMemory need not clear, and calloc's overflow |
45 | | * check must survive the conversion. */ |
46 | | static inline void *faar_alloc_zeroed(size_t count, size_t size) |
47 | 2.08k | { |
48 | 2.08k | void *block; |
49 | 2.08k | if (size && count > SIZE_MAX / size) return NULL; |
50 | 2.08k | block = AllocMemory(count * size); |
51 | 2.08k | if (block) memset(block, 0, count * size); |
52 | 2.08k | return block; |
53 | 2.08k | } polyresample.c:faar_alloc_zeroed Line | Count | Source | 47 | 2.08k | { | 48 | 2.08k | void *block; | 49 | 2.08k | if (size && count > SIZE_MAX / size) return NULL; | 50 | 2.08k | block = AllocMemory(count * size); | 51 | 2.08k | if (block) memset(block, 0, count * size); | 52 | 2.08k | return block; | 53 | 2.08k | } |
Unexecuted instantiation: dft_prefilter.c:faar_alloc_zeroed Unexecuted instantiation: dft_fir.c:faar_alloc_zeroed Unexecuted instantiation: fft.c:faar_alloc_zeroed |
54 | | |
55 | | /* Grow a block, preserving only initialized bytes. On failure the old block |
56 | | * remains owned by the caller. Standard builds retain in-place libc growth. */ |
57 | | static inline void *faar_grow_memory(void *block, size_t used, size_t bytes) |
58 | 0 | { |
59 | | #ifdef FAAR_CUSTOM_ALLOCATOR |
60 | | void *grown = AllocMemory(bytes); |
61 | | if (!grown) return NULL; |
62 | | if (used) memcpy(grown, block, used); |
63 | | FreeMemory(block); |
64 | | return grown; |
65 | | #else |
66 | 0 | (void)used; |
67 | 0 | return realloc(block, bytes); |
68 | 0 | #endif |
69 | 0 | } Unexecuted instantiation: polyresample.c:faar_grow_memory Unexecuted instantiation: dft_prefilter.c:faar_grow_memory Unexecuted instantiation: dft_fir.c:faar_grow_memory Unexecuted instantiation: fft.c:faar_grow_memory |
70 | | |
71 | | /* High's sensitive kernels need more than float precision. By default they |
72 | | * run in native double, which is ten times faster; with FAAR_RESAMPLER_FLOAT |
73 | | * float builds emulate the precision with float2 so targets without a double |
74 | | * FPU still run High. */ |
75 | | |
76 | | /* Sample planes; distinct from the API's float so storage stays greppable. */ |
77 | | typedef float faar_sample_t; |
78 | | |
79 | | #include "fft.h" |
80 | | #define faar_fft_plan faar_fftf_plan |
81 | 0 | #define faar_fft_cinit faar_fftf_cinit |
82 | 0 | #define faar_fft_cinit_shared_single faar_fftf_cinit_shared_single |
83 | 0 | #define faar_fft_cinit_filter_shared faar_fftf_cinit_filter_shared |
84 | 0 | #define faar_fft_cbuffer faar_fftf_cbuffer |
85 | 0 | #define faar_fft_cforward faar_fftf_cforward |
86 | 0 | #define faar_fft_clear faar_fftf_clear |
87 | 0 | #define faar_fft_prepare faar_fftf_prepare |
88 | | |
89 | | #endif /* LIBFAAR_INTERNAL_H */ |