← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
audio_scaled_sum_strided.c
Go to the documentation of this file.
2
3/* Output[c, t] = (left[c, t] + right[c, t]) * scale.
4 * The three physical row strides may differ. Only the valid columns are read
5 * and written; capacities describe reserved storage, not valid extents.
6 */
8 const float *left, size_t left_elements, size_t left_stride,
9 const float *right, size_t right_elements, size_t right_stride,
10 float *output, size_t output_elements, size_t output_stride,
11 size_t rows, size_t columns, float scale)
12{
13 size_t nl, nr, no;
14 if (!ck_checked_span(rows, columns, left_stride, &nl) ||
15 !ck_checked_span(rows, columns, right_stride, &nr) ||
16 !ck_checked_span(rows, columns, output_stride, &no) ||
17 left_elements < nl || right_elements < nr || output_elements < no)
18 return -2;
19 if (!isfinite(scale) ||
21 !ck_checked_region(output, no) ||
22 ck_checked_overlap(left, nl, output, no) ||
23 ck_checked_overlap(right, nr, output, no))
24 return -1;
25 /* Preflight every element so failure never publishes a partial output. */
26 for (size_t row = 0; row < rows; ++row) {
27 for (size_t column = 0; column < columns; ++column) {
28 const float a = left[row * left_stride + column];
29 const float b = right[row * right_stride + column];
30 const float sum = a + b;
31 if (!isfinite(a) || !isfinite(b) || !isfinite(sum) ||
32 !isfinite(sum * scale))
33 return -3;
34 }
35 }
36 for (size_t row = 0; row < rows; ++row)
37 for (size_t column = 0; column < columns; ++column)
38 output[row * output_stride + column] =
39 (left[row * left_stride + column] +
40 right[row * right_stride + column]) * scale;
41 return 0;
42}
int audio_scaled_sum_strided_f32_checked(const float *left, size_t left_elements, size_t left_stride, const float *right, size_t right_elements, size_t right_stride, float *output, size_t output_elements, size_t output_stride, size_t rows, size_t columns, float scale)
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:138
const char const char * right
Definition true_bpe.h:139