ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_fir_init_f32.c
Go to the documentation of this file.
1// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "dsps_fir.h"
16#include "malloc.h"
17
18
19esp_err_t dsps_fir_init_f32(fir_f32_t *fir, float *coeffs, float *delay, int coeffs_len)
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}
59
61{
62 if (fir->use_delay != 0) {
63 fir->use_delay = 0;
64 free(fir->delay);
65 }
66 return ESP_OK;
67}
#define ESP_ERR_DSP_INVALID_LENGTH
#define ESP_ERR_DSP_ARRAY_NOT_ALIGNED
#define memalign(align_, size_)
Definition dsp_tests.h:35
struct fir_f32_s fir_f32_t
Data struct of f32 fir filter.
esp_err_t dsps_fir_f32_free(fir_f32_t *fir)
support arrays freeing function
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
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
float * coeffs
Definition dsps_fir.h:30
int pos
Definition dsps_fir.h:33
float * delay
Definition dsps_fir.h:31
int16_t use_delay
Definition dsps_fir.h:35
float delay[256]
Definition test_fir.c:15
float coeffs[256]
Definition test_fir.c:14