-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathpanner.h
More file actions
344 lines (279 loc) · 12.8 KB
/
Copy pathpanner.h
File metadata and controls
344 lines (279 loc) · 12.8 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
* Copyright 2017-2018 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.
*/
/**
* @example panner.h
* @brief A frequency-dependent 3D panner based on the Vector-base Amplitude
* Panning (VBAP) method, with an optional spread control
*
* ### Files
* panner.h (include), panner_internal.h, panner.c, panner_internal.c
* ### Include Header
*/
/**
* @file panner.h
* @brief A frequency-dependent 3D panner based on the Vector-base Amplitude
* Panning (VBAP) method [1], with an optional spread control [2].
*
* Depending on the listening room, it may be beneficial to employ amplitude-
* normalised gains for low frequencies, and energy-normalised gains for high
* frequencies. Therefore, this VBAP implementation also uses the method
* described in [3], to do just that.
*
* @see [1] Pulkki, V. (1997). Virtual sound source positioning using vector
* base amplitude panning. Journal of the audio engineering society,
* 45(6), 456-466.
* @see [2] Pulkki, V. (1999). Uniform spreading of amplitude panned virtual
* sources. In Proceedings of the 1999 IEEE Workshop on Applications of
* Signal Processing to Audio and Acoustics. WASPAA'99 (Cat. No.
* 99TH8452) (pp. 187-190). IEEE.
* @see [3] Laitinen, M., Vilkamo, J., Jussila, K., Politis, A., Pulkki, V.
* (2014). Gain normalisation in amplitude panning as a function of
* frequency and room reverberance. 55th International Conference of
* the AES. Helsinki, Finland.
*
* @author Leo McCormack
* @date 25.09.2017
* @license ISC
*/
#ifndef __PANNER_H_INCLUDED__
#define __PANNER_H_INCLUDED__
#include "_common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* ========================================================================== */
/* Presets + Constants */
/* ========================================================================== */
/** Minimum supported spread angle, degrees */
#define PANNER_SPREAD_MIN_VALUE ( 0.0f )
/** Maximum supported spread angle, degrees */
#define PANNER_SPREAD_MAX_VALUE ( 90.0f )
/** Default number of Sources */
extern const int panner_defaultNumSources;
/** Default Loudspeaker directions */
extern const float panner_defaultSourceDirections[MAX_NUM_INPUTS][2];
/** Default number of Loudspeakers */
extern const int panner_defaultNumLoudspeakers;
/** Default Loudspeaker directions */
extern const float panner_defaultLoudspeakerDirections[MAX_NUM_OUTPUTS][2];
/* ========================================================================== */
/* Main Functions */
/* ========================================================================== */
/**
* Creates an instance of the panner
*
* @param[in] phPan (&) address of panner handle
*/
void panner_create(void** const phPan);
/**
* Destroys an instance of the panner
*
* @param[in] phPan (&) address of panner handle
*/
void panner_destroy(void** const phPan);
/**
* Initialises an instance of panner with default settings
*
* @warning This should not be called while _process() is on-going!
*
* @param[in] hPan panner handle
* @param[in] samplerate Host samplerate.
*/
void panner_init(void* const hPan,
int samplerate);
/**
* Intialises the codec variables, based on current global/user parameters
*
* @note This function is fully threadsafe. It can even be called periodically
* via a timer on one thread, while calling _process() on another thread.
* Since, if a set function is called (that warrants a re-init), then a
* flag is triggered internally and the next time this function is called,
* it will wait until the current process() function has completed before
* reinitialising the relevant parameters. If the _initCodec() takes
* longer than the time it takes for process() to be called again, then
* process() is simply bypassed until the codec is ready.
* @note This function does nothing if no re-initialisations are required.
*
* @param[in] hPan panner handle
*/
void panner_initCodec(void* const hPan);
/**
* Pans the input signals/sources to the loudspeaker channels using VBAP [1],
* and optional spreading [2] and frequency-dependent normalisation as a
* function of the room reverberation [3].
*
* @param[in] hPan panner 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
*
* @see [1] Pulkki, V. (1997). Virtual sound source positioning using vector
* base amplitude panning. Journal of the audio engineering society,
* 45(6), 456-466.
* @see [2] Pulkki, V. (1999). Uniform spreading of amplitude panned virtual
* sources. In Proceedings of the 1999 IEEE Workshop on Applications of
* Signal Processing to Audio and Acoustics. WASPAA'99 (Cat. No.
* 99TH8452) (pp. 187-190). IEEE.
* @see [3] Laitinen, M., Vilkamo, J., Jussila, K., Politis, A., Pulkki, V.
* (2014). Gain normalisation in amplitude panning as a function of
* frequency and room reverberance. 55th International Conference of
* the AES. Helsinki, Finland.
*/
void panner_process(void* const hPan,
const float *const * inputs,
float* const* outputs,
int nInputs,
int nOutputs,
int nSamples);
/* ========================================================================== */
/* Set Functions */
/* ========================================================================== */
/**
* Sets all intialisation flags to 1; re-initialising all settings/variables
* as panner is currently configured, at next available opportunity.
*/
void panner_refreshSettings(void* const hPan);
/** Sets the azimuth of a specific input/source index, in DEGREES */
void panner_setSourceAzi_deg(void* const hPan, int index, float newAzi_deg);
/** Sets the elevation of a specific input/source index, in DEGREES */
void panner_setSourceElev_deg(void* const hPan, int index, float newElev_deg);
/** Sets the number of inputs/sources to pan */
void panner_setNumSources(void* const hPan, int new_nSources);
/** Sets the azimuth of a specific loudspeaker index, in DEGREES */
void panner_setLoudspeakerAzi_deg(void* const hPan, int index, float newAzi_deg);
/** Sets the elevation of a specific loudspeaker index, in DEGREES */
void panner_setLoudspeakerElev_deg(void* const hPan, int index, float newElev_deg);
/** Sets the number of loudspeakers to pan to */
void panner_setNumLoudspeakers(void* const hPan, int new_nLoudspeakers);
/**
* Sets a preset for the output configuration (see #LOUDSPEAKER_ARRAY_PRESETS
* enum)
*/
void panner_setOutputConfigPreset(void* const hPan, int newPresetID);
/**
* Sets a preset for the input configuration (see #SOURCE_CONFIG_PRESETS enum)
*/
void panner_setInputConfigPreset(void* const hPan, int newPresetID);
/**
* Sets the room coefficient value 0..1 [1]; 0: normal room, 0.5: dry listening
* room, 1: anechoic
*
* @see [1] Laitinen, M., Vilkamo, J., Jussila, K., Politis, A., Pulkki, V.
* (2014). Gain normalisation in amplitude panning as a function of
* frequency and room reverberance. 55th International Conference of
* the AES. Helsinki, Finland.
*/
void panner_setDTT(void* const hPan, float newValue);
/** Sets the degree of spread, in DEGREES */
void panner_setSpread(void* const hPan, float newValue);
/** Sets the 'yaw' rotation angle, in DEGREES */
void panner_setYaw(void* const hPan, float newYaw);
/** Sets the 'pitch' rotation angle, in DEGREES */
void panner_setPitch(void* const hPan, float newPitch);
/** Sets the 'roll' rotation angle, in DEGREES */
void panner_setRoll(void* const hPan, float newRoll);
/**
* Sets a flag as to whether to "flip" the sign of the current 'yaw' angle
* (0: do not flip sign, 1: flip the sign)
*/
void panner_setFlipYaw(void* const hPan, int newState);
/**
* Sets a flag as to whether to "flip" the sign of the current 'pitch' angle
* (0: do not flip sign, 1: flip the sign)
*/
void panner_setFlipPitch(void* const hPan, int newState);
/**
* Sets a flag as to whether to "flip" the sign of the current 'roll' angle
* (0: do not flip sign, 1: flip the sign)
*/
void panner_setFlipRoll(void* const hPan, int newState);
/* ========================================================================== */
/* Get Functions */
/* ========================================================================== */
/**
* Returns the processing framesize (i.e., number of samples processed with
* every _process() call )
*/
int panner_getFrameSize(void);
/** Returns current codec status (see #CODEC_STATUS enum) */
CODEC_STATUS panner_getCodecStatus(void* const hPan);
/**
* (Optional) Returns current intialisation/processing progress, between 0..1
* - 0: intialisation/processing has started
* - 1: intialisation/processing has ended
*/
float panner_getProgressBar0_1(void* const hPan);
/**
* (Optional) Returns current intialisation/processing progress text
*
* @note "text" string should be (at least) of length:
* #PROGRESSBARTEXT_CHAR_LENGTH
*/
void panner_getProgressBarText(void* const hPan, char* text);
/** Returns the input/source azimuth for a given index, in DEGREES */
float panner_getSourceAzi_deg(void* const hPan, int index);
/** Returns the input/source elevation for a given index, in DEGREES */
float panner_getSourceElev_deg(void* const hPan, int index);
/** Returns the number of inputs/sources in the current layout */
int panner_getNumSources(void* const hPan);
/** Returns the maximum number of inputs/sources permitted by panner */
int panner_getMaxNumSources(void);
/** Returns the loudspeaker azimuth for a given index, in DEGREES */
float panner_getLoudspeakerAzi_deg(void* const hPan, int index);
/** Returns the loudspeaker elevation for a given index, in DEGREES */
float panner_getLoudspeakerElev_deg(void* const hPan, int index);
/** Returns the number of loudspeakers in the current layout */
int panner_getNumLoudspeakers(void* const hPan);
/** Returns the maximum number of loudspeakers permitted */
int panner_getMaxNumLoudspeakers(void);
/** Returns the DAW/Host sample rate */
int panner_getDAWsamplerate(void* const hPan);
/** Returns the room coefficient value 0..1 */
float panner_getDTT(void* const hPan);
/** Returns the spread value, in DEGREES */
float panner_getSpread(void* const hPan);
/** Returns the 'yaw' rotation angle, in DEGREES */
float panner_getYaw(void* const hPan);
/** Returns the 'pitch' rotation angle, in DEGREES */
float panner_getPitch(void* const hPan);
/** Returns the 'roll' rotation angle, in DEGREES */
float panner_getRoll(void* const hPan);
/**
* Returns a flag as to whether to "flip" the sign of the current 'yaw' angle
* (0: do not flip sign, 1: flip the sign)
*/
int panner_getFlipYaw(void* const hPan);
/**
* Returns a flag as to whether to "flip" the sign of the current 'pitch' angle
* (0: do not flip sign, 1: flip the sign)
*/
int panner_getFlipPitch(void* const hPan);
/**
* Returns a flag as to whether to "flip" the sign of the current 'roll' angle
* (0: do not flip sign, 1: flip the sign)
*/
int panner_getFlipRoll(void* const hPan);
/**
* Returns the processing delay in samples (may be used for delay compensation
* features)
*/
int panner_getProcessingDelay(void);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __PANNER_H_INCLUDED__ */