← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
audio_upsample_linear_checked.c File Reference

Go to the source code of this file.

Functions

int audio_upsample_linear_frames_f32_checked (const float *input, size_t input_elements, float *output, size_t output_elements, size_t frames, size_t channels, size_t factor)

Function Documentation

◆ audio_upsample_linear_frames_f32_checked()

int audio_upsample_linear_frames_f32_checked ( const float * input,
size_t input_elements,
float * output,
size_t output_elements,
size_t frames,
size_t channels,
size_t factor )

Definition at line 6 of file audio_upsample_linear_checked.c.

9{
10 size_t ni, no;
11 if (!factor || factor > 65536 || frames > 16777216 ||
12 !ck_checked_span(frames, channels, channels, &ni) ||
13 ni > SIZE_MAX / factor || input_elements < ni)
14 return -2;
15 no = ni * factor;
16 if (output_elements < no) return -2;
17 if (!ck_checked_region(input, ni) || !ck_checked_region(output, no) ||
18 ck_checked_overlap(input, ni, output, no)) return -1;
19 for (size_t i = 0; i < ni; ++i)
20 if (!isfinite(input[i])) return -3;
21 /* Preflight arithmetic too: a late invalid output cannot partially publish. */
22 for (int pass = 0; pass < 2; ++pass) {
23 for (size_t row = 0; row < frames * factor; ++row) {
24 /* Double coordinate avoids integer overflow and loss of half-pixels.
25 * Cast only the interpolation weight to the declared FP32 domain. */
26 double position = ((double)row + 0.5) / (double)factor - 0.5;
27 if (position < 0) position = 0;
28 size_t left = (size_t)position;
29 size_t right = left + 1 < frames ? left + 1 : left;
30 float weight = (float)(position - (double)left);
31 for (size_t c = 0; c < channels; ++c) {
32 float value = (1.0f - weight) * input[left * channels + c]
33 + weight * input[right * channels + c];
34 if (!isfinite(value)) return -3;
35 if (pass) output[row * channels + c] = value;
36 }
37 }
38 }
39 return 0;
40}
static int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span)
static int ck_checked_region(const float *ptr, size_t n)
static int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb)
const char * left
Definition true_bpe.h:140
const char const char * right
Definition true_bpe.h:141

References ck_checked_overlap(), ck_checked_region(), ck_checked_span(), left, and right.