← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_audio_snake_checked.h File Reference
#include <stddef.h>

Go to the source code of this file.

Functions

int audio_snake_strided_f32_checked (const float *input, size_t input_elements, size_t input_stride, const float *alpha, size_t alpha_elements, float *output, size_t output_elements, size_t output_stride, size_t channels, size_t frames)
 

Function Documentation

◆ audio_snake_strided_f32_checked()

int audio_snake_strided_f32_checked ( const float *  input,
size_t  input_elements,
size_t  input_stride,
const float *  alpha,
size_t  alpha_elements,
float *  output,
size_t  output_elements,
size_t  output_stride,
size_t  channels,
size_t  frames 
)

Definition at line 21 of file audio_snake_checked.c.

25 {
26 size_t input_span, output_span;
27 if (!channels || !frames || input_stride < frames || output_stride < frames)
28 return -1;
29 if (!ck_checked_span(channels, frames, input_stride, &input_span) ||
30 !ck_checked_span(channels, frames, output_stride, &output_span))
31 return -2;
32 if (input_elements < input_span || output_elements < output_span ||
33 alpha_elements < channels) return -2;
34 if (!ck_checked_region(input, input_span) ||
35 !ck_checked_region(alpha, channels) ||
36 !ck_checked_region(output, output_span) ||
37 ck_checked_overlap(input, input_span, output, output_span) ||
38 ck_checked_overlap(alpha, channels, input, input_span) ||
39 ck_checked_overlap(alpha, channels, output, output_span))
40 return -1;
41
42 /* A preflight pass preserves all output, including valid cells, when a
43 * late element overflows. No heap or variable-length stack storage. */
44 for (size_t channel = 0; channel < channels; ++channel) {
45 const float a = alpha[channel];
46 if (!isfinite(a) || a == 0.0f) return -3;
47 for (size_t frame = 0; frame < frames; ++frame) {
48 const float x = input[channel * input_stride + frame];
49 float result;
50 if (!isfinite(x) || !snake_value(x, a, &result)) return -3;
51 }
52 }
53 for (size_t channel = 0; channel < channels; ++channel)
54 for (size_t frame = 0; frame < frames; ++frame) {
55 float result = 0.0f;
56 /* Preflight established that this evaluation is finite. */
57 (void)snake_value(input[channel * input_stride + frame],
58 alpha[channel], &result);
59 output[channel * output_stride + frame] = result;
60 }
61 return 0;
62}
static int snake_value(float x, float alpha, float *value)
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)

References ck_checked_overlap(), ck_checked_region(), ck_checked_span(), and snake_value().