File: xtrxdsp_filters.h

package info (click to toggle)
libxtrxdsp 0.0.1%2Bgit20190830.eec2864-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268 kB
  • sloc: ansic: 2,538; makefile: 5
file content (118 lines) | stat: -rw-r--r-- 3,422 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Public xtrxdsp filters header file
 * Copyright (c) 2017 Sergey Kostanbaev <sergey.kostanbaev@fairwaves.co>
 * For more information, please visit: http://xtrx.io
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdint.h>
#include <xtrxdsp.h>

#define FILTER_TAPS_120 120
#define FILTER_TAPS_40  40

#define FILTER_TAPS_64  64

/*
 * 0    - 0.2     0.06 db
 * 0.25 - 1     -61.32 dB
 */
extern const int16_t g_filter_taps_120_4x[FILTER_TAPS_120];


/*
 *  0   - 0.25     0.00 db
 *  0.5 - 1      -84.04 db
 */
extern const int16_t g_filter_taps_40_long_2x_4x[FILTER_TAPS_40];


/*
 * 0    - 0.05    0.01 db
 * 0.25 - 1      -75.5 db
 */
extern const int16_t g_filter_taps_40_long_4x_16x[FILTER_TAPS_40];


/*
 * 0   - 0.4    0.37 db
 * 0.5 - 1       -46 db
 */
extern const int16_t g_filter_taps_40_2x[FILTER_TAPS_40];
extern const int16_t g_filter_taps_40_2x_q[FILTER_TAPS_40];


extern const int16_t g_filter_int16_taps_64_2x[FILTER_TAPS_64];
extern const float g_filter_float_taps_64_2x[FILTER_TAPS_64];


typedef struct xtrxdsp_filter_state {
	union {
		void* history_data;
		float* history_data_float;
		int16_t* history_data_int;
	};
	union {
		const void* filter_taps;
		const float* filter_taps_float;
		const int16_t* filter_taps_int;
	};
	unsigned history_size; // In floats
	unsigned decim;
	unsigned inter;
	union {
		func_xtrxdsp_sc32_conv64_t func;
		func_xtrxdsp_iq16_conv64_t func_int;
	};
	func_xtrxdsp_bx_expand_t expand_func;
} xtrxdsp_filter_state_t;

/**
 * @brief xtrxdsp_filter_init Initializes FIR filter and pushes zeros as history
 *                            data
 * @param taps Filter taps (doesn't have to be aligned to SMID vector size)
 * @param count Number of filter taps
 * @param decim Decimation rate at output (2^decim)
 * @param inter Interpolation rate before filtering (2^inter)
 * @param max_sps_block Max samples per block
 * @param out Structure to initialize
 * @return 0 - success, -errno on error
 */
int xtrxdsp_filter_init(const float* taps,
						unsigned count,
						unsigned decim,
						unsigned inter,
						unsigned max_sps_block,
						xtrxdsp_filter_state_t *out);

int xtrxdsp_filter_initi(const int16_t* taps,
						 unsigned count,
						 unsigned decim,
						 unsigned inter,
						 unsigned max_sps_block,
						 xtrxdsp_filter_state_t *out);

void xtrxdsp_filter_free(xtrxdsp_filter_state_t *out);

unsigned xtrxdsp_filter_work(xtrxdsp_filter_state_t* state,
							 const float *__restrict indata,
							 float *__restrict outdata,
							 unsigned num_insamples);

unsigned xtrxdsp_filter_worki(xtrxdsp_filter_state_t* state,
							  const int16_t *__restrict indata,
							  int16_t *__restrict outdata,
							  unsigned num_insamples);