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

Go to the source code of this file.

Functions

int audio_spectrum_cartesian_f32_checked (const float *input, size_t input_elements, float *real, size_t real_elements, float *imag, size_t imag_elements, size_t frames, size_t bins, float magnitude_limit)

Function Documentation

◆ audio_spectrum_cartesian_f32_checked()

int audio_spectrum_cartesian_f32_checked ( const float * input,
size_t input_elements,
float * real,
size_t real_elements,
float * imag,
size_t imag_elements,
size_t frames,
size_t bins,
float magnitude_limit )

Definition at line 5 of file audio_spectrum_cartesian_checked.c.

9{
10 if (!frames || !bins || frames > SIZE_MAX / bins ||
11 frames * bins > SIZE_MAX / 2) return -2;
12 size_t n = frames * bins;
13 if (input_elements < 2*n || real_elements < n || imag_elements < n) return -2;
14 if (!(magnitude_limit > 0) || !isfinite(magnitude_limit) ||
15 !ck_checked_region(input, 2*n) || !ck_checked_region(real, n) ||
16 !ck_checked_region(imag, n) || ck_checked_overlap(input,2*n,real,n) ||
17 ck_checked_overlap(input,2*n,imag,n) || ck_checked_overlap(real,n,imag,n)) return -1;
18 if (!ck_checked_finite(input, 2*n)) return -3;
19 const float threshold = logf(magnitude_limit);
20 for (size_t row = 0; row < frames; ++row) {
21 for (size_t bin = 0; bin < bins; ++bin) {
22 float log_magnitude = input[row*2*bins+bin];
23 float phase = input[row*2*bins+bins+bin];
24 float magnitude = log_magnitude >= threshold ? magnitude_limit :
25 fminf(expf(log_magnitude), magnitude_limit);
26 real[row*bins+bin] = magnitude*cosf(phase);
27 imag[row*bins+bin] = magnitude*sinf(phase);
28 }
29 }
30 return 0;
31}
static int ck_checked_finite(const float *ptr, size_t n)
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_finite(), ck_checked_overlap(), and ck_checked_region().