forked from leomccormack/Spatial_Audio_Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvconv.h
206 lines (163 loc) · 6.83 KB
/
tvconv.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright 2020 Leo McCormack
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file tvconv.h
* @brief A time-varying multi-channel convolver
* @author Rapolas Daugintis
* @date 13.07.2021
*/
#ifndef __TVCONV_H_INCLUDED__
#define __TVCONV_H_INCLUDED__
#include "_common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** SOFA loader error codes */
typedef enum {
/** Not initialized */
SAF_TVCONV_NOT_INIT,
/** Loading file */
SAF_TVCONV_SOFA_LOADING,
/** None of the error checks failed */
SAF_TVCONV_SOFA_OK,
/** Not a SOFA file, or no such file was found in the specified location */
SAF_TVCONV_SOFA_ERROR_INVALID_FILE_OR_FILE_PATH,
/** Dimensions of the SOFA data were not as expected */
SAF_TVCONV_SOFA_ERROR_DIMENSIONS_UNEXPECTED,
/** The data-type of the SOFA data was not as expected */
SAF_TVCONV_SOFA_ERROR_FORMAT_UNEXPECTED,
/** NetCDF is not thread safe! */
SAF_TVCONV_SOFA_ERROR_NETCDF_IN_USE
} SAF_TVCONV_ERROR_CODES;
/* ========================================================================== */
/* Main Functions */
/* ========================================================================== */
/**
* Creates an instance of tvconv
*
* @param[in] phTVCnv (&) address of tvconv handle
*/
void tvconv_create(void** const phTVCnv);
/**
* Destroys an instance of tvconv
*
* @param[in] phTVCnv (&) address of tvconv handle
*/
void tvconv_destroy(void** const phTVCnv);
/**
* Initialises an instance of tvconv with default settings
*
* @param[in] hTVCnv tvconv handle
* @param[in] samplerate Host samplerate.
* @param[in] hostBlockSize Host frame/block size
*/
void tvconv_init(void* const hTVCnv,
int samplerate,
int hostBlockSize);
/**
* Performs the time-varying convolution processing
*
* @param[in] hTVCnv tvconv handle
* @param[in] inputs Input channel buffers; 2-D array: nInputs x nSamples
* @param[in] outputs Output channel buffers; 2-D array: nOutputs x nSamples
* @param[in] nInputs Number of input channels
* @param[in] nOutputs Number of output channels
* @param[in] nSamples Number of samples in 'inputs'/'output' matrices (block size)
*/
void tvconv_process(void* const hTVCnv,
float* const* const inputs,
float* const* const outputs,
int nInputs,
int nOutputs,
int nSamples);
/* ========================================================================== */
/* Set Functions */
/* ========================================================================== */
/**
* Sets all intialisation flags to 1. Re-initialising all settings/variables,
* as tvconv is currently configured, at next available opportunity.
*/
void tvconv_refreshParams(void* const hTVCnv);
/**
* Checks whether things have to be reinitialised, and does so if it is needed
*/
void tvconv_checkReInit(void* const hTVCnv);
/** Reads IRs and positions from the current sofa file path. */
void tvconv_setFiltersAndPositions(void* const hTVCnv);
/** Sets current sofa file path. */
void tvconv_setSofaFilePath(void* const hTVCnv, const char* path);
/**
* Sets the target listener position.
*
* @param[in] dim dimension of the coordinate to be set (0 is x, 1 is y,
* * and 2 is z).
* @param[in] position new position to be set.
*/
void tvconv_setTargetPosition(void* const hTVCnv, float position, int dim);
/* ========================================================================== */
/* Get Functions */
/* ========================================================================== */
/**
* Returns the processing framesize (i.e., number of samples processed with
* every _process() call )
*/
int tvconv_getFrameSize(void);
/** Returns the number input channels */
int tvconv_getNumInputChannels(void* const hTVCnv);
/**
* Returns the number of output channels (the same as the number of channels in
* the loaded sofa file)
*/
int tvconv_getNumOutputChannels(void* const hTVCnv);
/** Returns the currect host block size */
int tvconv_getHostBlockSize(void* const hTVCnv);
/** Returns the number of IR channels in the loaded sofa file */
int tvconv_getNumIRs(void* const hTVCnv);
/** Returns the number of listener positions in the loaded sofa file */
int tvconv_getNumListenerPositions(void* const hTVCnv);
/** Returns the current coordinate of dimension dim (0 ... NUM_DIMENSIONS-1) */
float tvconv_getListenerPosition(void* const hTVCnv, int index, int dim);
/** Returns the index of the current IR position */
int tvconv_getListenerPositionIdx(void* const hTVCnv);
/** Returns the current coordinate of dimension dim (0 ... NUM_DIMENSIONS-1) */
float tvconv_getTargetPosition(void* const hTVCnv, int dim);
/** Returns the source coordinate of dimension dim (0 ... NUM_DIMENSIONS-1) */
float tvconv_getSourcePosition(void* const hTVCnv, int dim);
/** Returns minimum cooridinate of dimension dim (0 ... NUM_DIMENSIONS-1) */
float tvconv_getMinDimension(void* const hTVCnv, int dim);
/** Returns minimum cooridinate of dimension dim (0 ... NUM_DIMENSIONS-1) */
float tvconv_getMaxDimension(void* const hTVCnv, int dim);
/** Returns the current filter length, in samples */
int tvconv_getIRLength(void* const hTVCnv);
/** Returns the samplerate of the loaded filters */
int tvconv_getIRFs(void* const hTVCnv);
/** Returns the samperate of the host */
int tvconv_getHostFs(void* const hTVCnv);
/**
* Returns the processing delay in samples (may be used for delay compensation
* features)
*/
int tvconv_getProcessingDelay(void* const hTVCnv);
/** Returns the current Sofa file path */
char* tvconv_getSofaFilePath(void* const hTVCnv);
/** Returns the current Sofa file error state */
SAF_TVCONV_ERROR_CODES tvconv_getSofaErrorState(void* const hTVCnv);
/** Returns current codec status (see #CODEC_STATUS enum) */
CODEC_STATUS tvconv_getCodecStatus(void* const hTVCnv);
#ifdef __cplusplus
} /* extern "C" { */
#endif /* __cplusplus */
#endif /* __TVCONV_H_INCLUDED__ */