Skip to content

Commit 8864a64

Browse files
Docs
1 parent c981b23 commit 8864a64

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# chowdsp_polyphase_fir
2+
3+
[![Test](https://github.com/Chowdhury-DSP/chowdsp_polyphase_fir/actions/workflows/test.yml/badge.svg)](https://github.com/Chowdhury-DSP/chowdsp_polyphase_fir/actions/workflows/test.yml)
4+
5+
This repository contains a minimal C/C++ library for computing [polyphase FIR filters](https://www.dsprelated.com/blogimages/JosefHoffmann/decim_interp_polyphase.pdf).
6+
7+
## Usage
8+
9+
First, determine your memory requirements:
10+
```cpp
11+
const auto persistent_bytes = persistent_bytes_required (n_channels, n_taps, interpolation_factor, max_block_size, alignment);
12+
const auto scratch_bytes = scratch_bytes_required (n_taps, interpolation_factor, max_block_size, alignment);
13+
```
14+
15+
Next, you can create a "state" object:
16+
```cpp
17+
auto* state = init (n_channels,
18+
n_taps,
19+
interpolation_factor,
20+
max_block_size,
21+
allocate_bytes (persistent_bytes, alignment),
22+
alignment);
23+
```
24+
25+
And load in our filter coefficients:
26+
```cpp
27+
load_coeffs (state, coeffs, n_taps);
28+
```
29+
30+
Now we're ready to do our processing! We can do polyphase interpolation:
31+
```cpp
32+
process_interpolate (state,
33+
input_buffer,
34+
output_buffer,
35+
n_channels,
36+
n_samples,
37+
scratch_data,
38+
use_avx);
39+
```
40+
41+
Or decimation:
42+
```cpp
43+
process_decimate (state,
44+
input_buffer,
45+
output_buffer,
46+
n_channels,
47+
n_samples,
48+
scratch_data,
49+
use_avx);
50+
```
51+
52+
## License
53+
54+
This code is licensed under the BSD 3-clause license. Enjoy!

chowdsp_polyphase_fir.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ namespace chowdsp::polyphase_fir
1010
#include <stddef.h>
1111
#endif
1212

13+
/**
14+
* Object to hold the filter's persistent state.
15+
*
16+
* Users should not instantiate this object directly,
17+
* it will be provided by the `init()` method.
18+
*/
1319
struct Polyphase_FIR_State
1420
{
1521
float* coeffs {};
@@ -21,16 +27,33 @@ struct Polyphase_FIR_State
2127
int factor {};
2228
};
2329

30+
/** Returns the number of bytes needed to construct the filter state. */
2431
size_t persistent_bytes_required (int n_channels, int n_taps, int factor, int max_samples_in, int alignment);
2532

33+
/*
34+
* Initializes the filter and returns a state object.
35+
*
36+
* Note that the number of taps must be greater than or equal to 16.
37+
*
38+
* The `max_samples_in` argument is relative to the "interpolation" mode of the filter.
39+
* For "decimation", the naximum input size if `max_samples_in * factor`.
40+
*
41+
* The returned pointer will be allocated into the provided block of persistent data.
42+
* This means that you should not free the pointer since it will be freed automatically
43+
* when you free the persistent data.
44+
*/
2645
struct Polyphase_FIR_State* init (int n_channels, int n_taps, int factor, int max_samples_in, void* persistent_data, int alignment);
2746

47+
/** Loads a set of filter coefficients into the filter */
2848
void load_coeffs (struct Polyphase_FIR_State* state, const float* coeffs, int n_taps);
2949

50+
/** Resets the filter state */
3051
void reset (struct Polyphase_FIR_State* state);
3152

53+
/** Returns the scratch memory required by the filter */
3254
size_t scratch_bytes_required (int n_taps, int factor, int max_samples_in, int alignment);
3355

56+
/** Process data through the "interpolation" mode of the filter */
3457
void process_interpolate (struct Polyphase_FIR_State* state,
3558
const float* const* in,
3659
float* const* out,
@@ -39,6 +62,7 @@ void process_interpolate (struct Polyphase_FIR_State* state,
3962
void* scratch_data,
4063
bool use_avx);
4164

65+
/** Process data through the "decimation" mode of the filter */
4266
void process_decimate (struct Polyphase_FIR_State* state,
4367
const float* const* in,
4468
float* const* out,

0 commit comments

Comments
 (0)