ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_firmr_init_s16.c File Reference
#include "dsps_fir.h"
#include "malloc.h"
#include <string.h>
#include "dsp_tests.h"
#include "dsp_common.h"
Include dependency graph for dsps_firmr_init_s16.c:

Go to the source code of this file.

Macros

#define ROUNDING_VALUE   0x7fff

Functions

esp_err_t dsps_firmr_init_s16 (fir_s16_t *fir, int16_t *coeffs, int16_t *delay, int16_t coeffs_len, int16_t interp, int16_t decim, int16_t start_pos, int16_t shift)
 initialize structure for multi-rate FIR filter Function initialize structure for 16 bit signed fixed point multi-rate FIR filter The implementation use ANSI C and could be compiled and run on any platform

Macro Definition Documentation

◆ ROUNDING_VALUE

#define ROUNDING_VALUE   0x7fff

Definition at line 13 of file dsps_firmr_init_s16.c.

Function Documentation

◆ dsps_firmr_init_s16()

esp_err_t dsps_firmr_init_s16 ( fir_s16_t * fir,
int16_t * coeffs,
int16_t * delay,
int16_t length,
int16_t interp,
int16_t decim,
int16_t start_pos,
int16_t shift )

initialize structure for multi-rate FIR filter Function initialize structure for 16 bit signed fixed point multi-rate 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 be length N
lengthFIR filter length. Length of coeffs and delay arrays.
interpinterpolation factor.
decimdecimation factor.
start_posinitial value of decimation counter. Must be [0..decim)
shiftshift of accumulator value to store in the output array.
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 15 of file dsps_firmr_init_s16.c.

16{
17 fir->coeffs = coeffs;
18 fir->delay = delay;
19
20
21 fir->coeffs_len = coeffs_len;
22 fir->pos = 0;
23 fir->decim = decim;
24 fir->d_pos = start_pos;
25 fir->shift = shift;
26 fir->rounding_val = (int16_t)(ROUNDING_VALUE);
27 fir->free_status = 0;
28
29 if (delay == NULL) {
30#ifdef CONFIG_IDF_TARGET_ESP32S3
31 fir->delay = (int16_t *)memalign(16, (fir->delay_size + 4) * sizeof(int16_t));
32#else
33 fir->delay = (int16_t *)malloc((fir->delay_size + 4) * sizeof(int16_t));
34#endif // CONFIG_IDF_TARGET_ESP32S3
35 fir->free_status = 1;
36 } else {
37 fir->free_status = 0;
38 }
39
40
41 fir->interp = interp;
42 fir->interp_pos = 0;
43 fir->start_pos = start_pos;
44 fir->delay_size = coeffs_len / interp;
45
46
47 if (fir->coeffs_len < 2) { // number of coeffcients must be higer than 1
49 }
50
51 if ((fir->shift > 40) || (fir->shift < -40)) { // shift amount must be within a range from -40 to 40
53 }
54
55 if (fir->d_pos >= fir->decim) { // start position must be lower than decimation
57 }
58
59 for (int i = 0; i < fir->delay_size; i++) { // Initialize the delay line to zero
60 fir->delay[i] = 0;
61 }
62
63 return ESP_OK;
64}
#define ESP_ERR_DSP_PARAM_OUTOFRANGE
#define ESP_ERR_DSP_INVALID_LENGTH
#define memalign(align_, size_)
Definition dsp_tests.h:35
#define ROUNDING_VALUE
#define ESP_OK
Definition esp_err.h:23
int16_t delay_size
Interpolation parameters.
Definition dsps_fir.h:71
int16_t shift
Definition dsps_fir.h:61
int16_t * coeffs
Definition dsps_fir.h:55
int32_t rounding_val
Definition dsps_fir.h:63
int16_t * delay
Definition dsps_fir.h:56
int16_t decim
Definition dsps_fir.h:59
int16_t pos
Definition dsps_fir.h:58
int16_t start_pos
Definition dsps_fir.h:74
int16_t interp_pos
Definition dsps_fir.h:73
int16_t interp
Definition dsps_fir.h:72
int16_t d_pos
Definition dsps_fir.h:60
int16_t coeffs_len
Definition dsps_fir.h:57
int16_t free_status
Definition dsps_fir.h:64
float delay[256]
Definition test_fir.c:15
float coeffs[256]
Definition test_fir.c:14

References coeffs, fir_s16_s::coeffs, fir_s16_s::coeffs_len, fir_s16_s::d_pos, fir_s16_s::decim, delay, fir_s16_s::delay, fir_s16_s::delay_size, ESP_ERR_DSP_INVALID_LENGTH, ESP_ERR_DSP_PARAM_OUTOFRANGE, ESP_OK, fir_s16_s::free_status, fir_s16_s::interp, fir_s16_s::interp_pos, memalign, fir_s16_s::pos, fir_s16_s::rounding_val, ROUNDING_VALUE, fir_s16_s::shift, and fir_s16_s::start_pos.

Referenced by dsps_resampler_mr_init().

Here is the caller graph for this function: