ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_fir_init_f32.c File Reference
#include "dsps_fir.h"
#include "malloc.h"
Include dependency graph for dsps_fir_init_f32.c:

Go to the source code of this file.

Functions

esp_err_t dsps_fir_init_f32 (fir_f32_t *fir, float *coeffs, float *delay, int coeffs_len)
 initialize structure for 32 bit FIR filter
esp_err_t dsps_fir_f32_free (fir_f32_t *fir)
 support arrays freeing function

Function Documentation

◆ dsps_fir_f32_free()

esp_err_t dsps_fir_f32_free ( fir_f32_t * fir)

support arrays freeing function

Function frees the delay line arrays, if it was allocated by the init functions.

Parameters
firpointer to fir filter structure, that must be initialized before
Returns
  • ESP_OK on success

Definition at line 60 of file dsps_fir_init_f32.c.

61{
62 if (fir->use_delay != 0) {
63 fir->use_delay = 0;
64 free(fir->delay);
65 }
66 return ESP_OK;
67}
#define ESP_OK
Definition esp_err.h:23
float * delay
Definition dsps_fir.h:31
int16_t use_delay
Definition dsps_fir.h:35

References fir_f32_s::delay, ESP_OK, and fir_f32_s::use_delay.

Referenced by dsps_resampler_mr_free().

Here is the caller graph for this function:

◆ dsps_fir_init_f32()

esp_err_t dsps_fir_init_f32 ( fir_f32_t * fir,
float * coeffs,
float * delay,
int coeffs_len )

initialize structure for 32 bit FIR filter

Function initialize structure for 32 bit floating point FIR filter The implementation use ANSI C and could be compiled and run on any platform

Parameters
firpointer to fir filter structure, that must be preallocated
coeffsarray with FIR filter coefficients. Must be length N
delayarray for FIR filter delay line. Must have a length = coeffs_len + 4
coeffs_lenFIR filter length. Length of coeffs array. For esp32s3 length should be divided by 4 and aligned to 16.
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 19 of file dsps_fir_init_f32.c.

20{
21 // Allocate delay line in case if it's NULL
22 if (delay == NULL) {
23#ifdef CONFIG_IDF_TARGET_ESP32S3
24 delay = (float *)memalign(16, (coeffs_len + 4) * sizeof(float));
25#else
26 delay = (float *)malloc((coeffs_len + 4) * sizeof(float));
27#endif // CONFIG_IDF_TARGET_ESP32S3
28 fir->use_delay = 1;
29 } else {
30 fir->use_delay = 0;
31 }
32 for (int i = 0; i < (coeffs_len + 4); i++) {
33 delay[i] = 0;
34 }
35 fir->coeffs = coeffs;
36 fir->delay = delay;
37 fir->N = coeffs_len;
38 fir->pos = 0;
39
40#ifdef CONFIG_IDF_TARGET_ESP32S3
41 if (fir->N % 4 != 0) {
43 }
44 // The coeffs array should be aligned to 16
45 if (((uint32_t)coeffs) & 0x0f) {
47 }
48 // The delay array should be aligned to 16
49 if (((uint32_t)delay) & 0x0f) {
51 }
52#endif // CONFIG_IDF_TARGET_ESP32S3
53
54 for (int i = 0 ; i < coeffs_len; i++) {
55 fir->delay[i] = 0;
56 }
57 return ESP_OK;
58}
#define ESP_ERR_DSP_INVALID_LENGTH
#define ESP_ERR_DSP_ARRAY_NOT_ALIGNED
#define memalign(align_, size_)
Definition dsp_tests.h:35
float * coeffs
Definition dsps_fir.h:30
int pos
Definition dsps_fir.h:33
float delay[256]
Definition test_fir.c:15
float coeffs[256]
Definition test_fir.c:14

References coeffs, fir_f32_s::coeffs, delay, fir_f32_s::delay, ESP_ERR_DSP_ARRAY_NOT_ALIGNED, ESP_ERR_DSP_INVALID_LENGTH, ESP_OK, memalign, fir_f32_s::N, fir_f32_s::pos, and fir_f32_s::use_delay.

Referenced by test_fir().

Here is the caller graph for this function: