Developer World
Spresense Arduino Library v3.2.0-77d75a4
IIR.h
Go to the documentation of this file.
1/*
2 * IIR.h - IIR(biquad cascade) Library Header
3 * Copyright 2019, 2021 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef _IIR_H_
21#define _IIR_H_
22
29/*------------------------------------------------------------------*/
30/* For compatibility */
31/*------------------------------------------------------------------*/
32/* An execution sample of frame */
33/* For compatibility. Please do not use! */
34#define FRAMSIZE IIRClass::DEFAULT_FRAMESIZE
35
42/* Use CMSIS library */
43#define ARM_MATH_CM4
44#define __FPU_PRESENT 1U
45#include <cmsis/arm_math.h>
46
47#include "RingBuff.h"
48
49/*------------------------------------------------------------------*/
50/* Type Definition */
51/*------------------------------------------------------------------*/
56typedef enum e_filterType {
65} filterType_t;
66
67/*------------------------------------------------------------------*/
68/* IIR Class */
69/*------------------------------------------------------------------*/
76{
77public:
78
79 /*------------------------------------------------------------------*/
80 /* Configurations */
81 /*------------------------------------------------------------------*/
82
86 static const int BITLEN = 16;
87 //static const int BITLEN 32
88
92 static const int DEFAULT_FRAMESIZE = 768;
93
97 static const int MIN_FRAMESIZE = 240;
98
102 static const int MAX_CHANNEL_NUM = 8;
103
107 static const int INPUT_BUFFER_SIZE = 4; /* Times */
108
113 typedef enum e_format {
117 Planar
118 } format_t;
119
124 typedef enum e_error {
140 ERR_FS = -7
141 } error_t;
142
143 IIRClass() {
144 for (int i = 0; i < MAX_CHANNEL_NUM; i++) {
145 m_ringbuff[i] = NULL;
146 }
147 m_tmpInBuff = NULL;
148 m_tmpOutBuff = NULL;
149 m_InterleaveBuff = NULL;
150 }
151
159 bool begin(
160 filterType_t type,
161 int channel,
162 int cutoff,
163 float q,
164 int sample = DEFAULT_FRAMESIZE,
165 format_t output = Planar,
166 int fs = 48000
167 );
168
176 bool put(
177 q15_t* pSrc,
178 int size
179 );
180
188 int get(
189 q15_t* pDst,
190 int channel
191 );
192
200 int get(
201 q15_t* pDsts
202 );
203
210 void end();
211
219 bool empty(
220 int channel
221 );
222
230 error_t getErrorCause(){ return m_err; }
231
232
233private:
234
235 int m_channel;
236 int m_framesize;
237 format_t m_output;
238 error_t m_err;
239 int m_fs;
240
241 arm_biquad_cascade_df2T_instance_f32 S[MAX_CHANNEL_NUM];
242
243 float32_t m_coef[5];
244 float32_t m_buffer[MAX_CHANNEL_NUM][4];
245
246 RingBuff* m_ringbuff[MAX_CHANNEL_NUM];
247
248 /* Temporary buffer */
249 float* m_tmpInBuff;
250 float* m_tmpOutBuff;
251
252 q15_t* m_InterleaveBuff;
253
254 bool create_coef(filterType_t, int cutoff, float q);
255
256};
257
258#endif /*_IIR_H_*/
Biquad IIR filter class.
Definition: IIR.h:76
Definition: RingBuff.h:26
e_format
Definition: IIR.h:113
static const int BITLEN
Definition: IIR.h:86
void end()
Finalize the IIR library.
bool put(q15_t *pSrc, int size)
Put input data into the IIR library.
static const int INPUT_BUFFER_SIZE
Definition: IIR.h:107
int get(q15_t *pDsts)
Get the execution data of all channels.
e_error
Definition: IIR.h:124
error_t getErrorCause()
Get error information.
Definition: IIR.h:230
e_filterType
Definition: IIR.h:56
static const int MAX_CHANNEL_NUM
Definition: IIR.h:102
int get(q15_t *pDst, int channel)
Get the execution data of each channel.
bool empty(int channel)
Is the buffer empty or not of each channel.
bool begin(filterType_t type, int channel, int cutoff, float q, int sample=DEFAULT_FRAMESIZE, format_t output=Planar, int fs=48000)
Initialize the IIR library.
static const int MIN_FRAMESIZE
Definition: IIR.h:97
static const int DEFAULT_FRAMESIZE
Definition: IIR.h:92
@ Planar
the channel planar format
Definition: IIR.h:117
@ Interleave
the channel interleave format
Definition: IIR.h:115
@ ERR_FILTER_TYPE
Wrong filter type setting.
Definition: IIR.h:134
@ ERR_BUF_FULL
Failture of write as buffer is full.
Definition: IIR.h:138
@ ERR_MEMORY
Lack of memory area.
Definition: IIR.h:132
@ ERR_FORMAT
Wrong output format setting.
Definition: IIR.h:130
@ ERR_OK
No error.
Definition: IIR.h:126
@ ERR_FS
Wrong sampling rate.
Definition: IIR.h:140
@ ERR_CH_NUM
Wrong channel setting.
Definition: IIR.h:128
@ ERR_FRAME_SIZE
Wrong number of samples.
Definition: IIR.h:136
@ TYPE_BEF
Band Elimination Filter.
Definition: IIR.h:64
@ TYPE_BPF
Band Pass Filter.
Definition: IIR.h:62
@ TYPE_LPF
Low Pass Filter.
Definition: IIR.h:58
@ TYPE_HPF
High Pass Filter.
Definition: IIR.h:60