-
Notifications
You must be signed in to change notification settings - Fork 1
/
convolver.h
154 lines (127 loc) · 4.08 KB
/
convolver.h
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* (c) Copyright 2001, 2002, 2004, 2006 -- Anders Torger
*
* This program is open source. For license terms, see the LICENSE file.
*
*/
#ifndef _CONVOLVER_H_
#define _CONVOLVER_H_
#include <inttypes.h>
#include "defs.h"
#include "bfmod.h"
#include "dai.h"
/* Convert from raw sample format to the convolver's own time-domain format. */
void
convolver_raw2cbuf(void *rawbuf,
void *cbuf,
void *next_cbuf,
struct buffer_format *bf,
void (*postprocess)(void *realbuf,
int n_samples,
void *arg),
void *pp_arg);
/* Transform from time-domain to frequency-domain. */
void
convolver_time2freq(void *input_cbuf,
void *output_cbuf);
/* Scale and mix in the frequency-domain. The 'mixmode' parameter may be used
internally for possible reordering of data prior to or after convolution. */
void
convolver_mixnscale(void *input_cbufs[],
void *output_cbuf,
double scales[],
int n_bufs,
#define CONVOLVER_MIXMODE_INPUT 1
#define CONVOLVER_MIXMODE_INPUT_ADD 2
#define CONVOLVER_MIXMODE_OUTPUT 3
int mixmode);
/* Convolution in the frequency-domain, done in-place. */
void
convolver_convolve_inplace(void *cbuf,
void *coeffs);
/* Convolution in the frequency-domain. */
void
convolver_convolve(void *input_cbuf,
void *coeffs,
void *output_cbuf);
void
convolver_crossfade_inplace(void *input_cbuf,
void *crossfade_cbuf,
void *buffer_cbuf);
/* Convolution in the frequency-domain, with the result added to the output. */
void
convolver_convolve_add(void *input_cbuf,
void *coeffs,
void *output_cbuf);
/* Convolve with dirac pulse. */
void
convolver_dirac_convolve(void *input_cbuf,
void *output_cbuf);
void
convolver_dirac_convolve_inplace(void *cbuf);
/* Transform from frequency-domain to time-domain. */
void
convolver_freq2time(void *input_cbuf,
void *output_cbuf);
/* Evaluate convolution output by transforming it back to time-domain, do
overlap-save and transform back to frequency-domain again. Used when filters
are put in series. The 'buffer_cbuf' must be 1.5 times the cbufsize and must
be cleared the first call, and be kept the following calls. Input and output
buffers may be the same. */
void
convolver_convolve_eval(void *input_cbuf,
void *buffer_cbuf,
void *output_cbuf);
/* Convert from the convolver's own time-domain format to raw sample format. */
void
convolver_cbuf2raw(void *cbuf,
void *outbuf,
struct buffer_format *bf,
bool_t apply_dither,
void *dither_state,
struct bfoverflow *overflow);
/* Return the size of the convolver's internal format corresponding to the
given number of samples. */
int
convolver_cbufsize(void);
/* Convert a set of coefficients to the convolver's internal frequency domain
format. */
void *
convolver_coeffs2cbuf(void *coeffs,
int n_coeffs,
double scale,
void *optional_dest);
/* Fast version of the above to be used in runtime */
void
convolver_runtime_coeffs2cbuf(void *src,
void *dest);
/* Make a quick sanity check */
bool_t
convolver_verify_cbuf(void *cbufs[],
int n_cbufs);
/* Dump the contents of a cbuf to a text-file (after conversion back to
coefficient list) */
void
convolver_debug_dump_cbuf(const char filename[],
void *cbufs[],
int n_cbufs);
/* Get a plan for the FFT lib used. Do not free it. */
void *
convolver_fftplan(int order,
int invert,
int inplace);
typedef struct _td_conv_t_ td_conv_t;
int
convolver_td_block_length(int n_coeffs);
td_conv_t *
convolver_td_new(void *coeffs,
int n_coeffs);
void
convolver_td_convolve(td_conv_t *tdc,
void *overlap_block);
/* Initialise convolver. Some convolvers may ignore 'config_filename' */
bool_t
convolver_init(const char config_filename[],
int length,
int realsize);
#endif