SAF
Loading...
Searching...
No Matches
binauraliser_nf_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Michael McCrea, Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
38
39#ifndef __BINAURALISER_NF_INTERNAL_H_INCLUDED__
40#define __BINAURALISER_NF_INTERNAL_H_INCLUDED__
41
43#include "binauraliser_nf.h" /* Include header for this example */
44#include "saf.h" /* Main include header for SAF */
45#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
46
47#ifdef __cplusplus
48extern "C" {
49#endif /* __cplusplus */
50
51/* ========================================================================== */
52/* Structures */
53/* ========================================================================== */
54
61typedef struct _binauraliserNF {
62 //struct _binauraliser; /**< "inherit" member vars of binauraliser struct - requires -fms-extensions compile flag */
63
64 /* The following variables MUST match those of the _binauraliser struct */
65
66 /* audio buffers */
67 float** inputFrameTD;
68 float** outframeTD;
69 float_complex*** inputframeTF;
70 float_complex*** outputframeTF;
71 int fs;
73 void* hSTFT;
74
75 /* sofa file info */
77 float* hrirs;
79 _Atomic_INT32 N_hrir_dirs;
80 _Atomic_INT32 hrir_loaded_len;
81 _Atomic_INT32 hrir_runtime_len;
82 _Atomic_INT32 hrir_loaded_fs;
83 _Atomic_INT32 hrir_runtime_fs;
84 float* weights;
85
86 /* vbap gain table */
91
92 /* hrir filterbank coefficients */
93 float* itds_s;
94 float_complex* hrtf_fb;
95 float* hrtf_fb_mag;
97
98 /* flags/status */
99 _Atomic_CODEC_STATUS codecStatus;
100 _Atomic_FLOAT32 progressBar0_1;
102 _Atomic_PROC_STATUS procStatus;
105 _Atomic_INT32 recalc_M_rotFLAG;
106
107 /* misc. */
112 _Atomic_INT32 new_nSources;
113
114 /* user parameters */
115 _Atomic_INT32 nSources;
116 _Atomic_FLOAT32 src_dirs_deg[MAX_NUM_INPUTS][2];
117 _Atomic_INTERP_MODES interpMode;
118 _Atomic_INT32 useDefaultHRIRsFLAG;
119 _Atomic_INT32 enableHRIRsDiffuseEQ;
120 _Atomic_INT32 enableRotation;
121 _Atomic_FLOAT32 yaw;
122 _Atomic_FLOAT32 roll;
123 _Atomic_FLOAT32 pitch;
124 _Atomic_INT32 bFlipYaw;
125 _Atomic_INT32 bFlipPitch;
126 _Atomic_INT32 bFlipRoll;
127 _Atomic_INT32 useRollPitchYawFlag;
128 _Atomic_FLOAT32 src_gains[MAX_NUM_INPUTS];
129
130
131 /* End copied _binauraliser struct members. The following are unique to the _binauraliserNF struct */
132
137
138 /* misc. */
139 _Atomic_FLOAT32 src_dists_m[MAX_NUM_INPUTS];
146
147 /* flags/status */
149
151
152
153/* ========================================================================== */
154/* Internal Functions */
155/* ========================================================================== */
156
162void binauraliserNF_initTFT(void* const hBin);
163
167void binauraliserNF_resetSourceDistances(void* const hBin);
168
169
170#ifdef __cplusplus
171} /* extern "C" { */
172#endif /* __cplusplus */
173
174#endif /* __BINAURALISER_INTERNAL_NF_H_INCLUDED__ */
#define MAX_NUM_INPUTS
Maximum number of input channels supported.
Definition _common.h:237
#define HYBRID_BANDS
Number of frequency bands.
Convolves input audio (up to 64 channels) with interpolated HRTFs in the time-frequency domain.
Convolves input audio (up to 64 channels) with interpolated HRTFs in the time-frequency domain,...
void binauraliserNF_initTFT(void *const hBin)
Initialise the filterbank used by binauraliserNF.
void binauraliserNF_resetSourceDistances(void *const hBin)
Resets the source distances to the default far field distance.
#define NUM_EARS
2 (true for most humans)
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
Main structure for binauraliserNF.
_Atomic_INT32 recalc_dvfCoeffFLAG[MAX_NUM_INPUTS]
1: re-calculate the DVF coefficients on change in distance, 0: do not.
_Atomic_INT32 useRollPitchYawFlag
rotation order flag, 1: r-p-y, 0: y-p-r
float * itds_s
interaural-time differences for each HRIR (in seconds); nBands x 1
char * sofa_filepath
absolute/relevative file path for a sofa file
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; FLAT: N_hrir_dirs x 2
_Atomic_INT32 bFlipPitch
flag to flip the sign of the pitch rotation angle
float_complex *** outputframeTF
time-frequency domain input frame; HYBRID_BANDS x NUM_EARS x TIME_SLOTS
_Atomic_FLOAT32 src_dists_m[MAX_NUM_INPUTS]
Source distance, meters.
float_complex * hrtf_fb
hrtf filterbank coefficients; nBands x nCH x N_hrirs
_Atomic_INT32 enableRotation
1: enable rotation, 0: disable
_Atomic_PROC_STATUS procStatus
see PROC_STATUS
int N_hrtf_vbap_gtable
Number of interpolation weights/directions.
_Atomic_INT32 N_hrir_dirs
number of HRIR directions in the current sofa file
float src_dirs_rot_deg[MAX_NUM_INPUTS][2]
Intermediate rotated source directions, in degrees.
_Atomic_FLOAT32 pitch
pitch (Euler) rotation angle, in degrees
_Atomic_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
float * hrirs
time domain HRIRs; FLAT: N_hrir_dirs x NUM_EARS x hrir_len
_Atomic_INTERP_MODES interpMode
see INTERP_MODES
int nTriangles
Number of triangles in the convex hull of the spherical arrangement of HRIR directions/points.
_Atomic_FLOAT32 yaw
yaw (Euler) rotation angle, in degrees
float ** inputFrameTD
time-domain input frame; MAX_NUM_INPUTS x BINAURALISER_FRAME_SIZE
char * progressBarText
Current (re)initialisation step, string.
float head_radius_recip
Reciprocal of head radius.
float dvfphases[MAX_NUM_INPUTS][NUM_EARS][HYBRID_BANDS]
DVF filter frequency band phases.
float a_dvf[MAX_NUM_INPUTS][NUM_EARS][2]
shelf IIR denominator coefficients for each input, left and right.
_Atomic_INT32 useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
float * hrtf_fb_mag
magnitudes of the hrtf filterbank coefficients; nBands x nCH x N_hrirs
float * weights
Integration weights for the HRIR measurement grid; N_hrir_dirs x 1.
_Atomic_INT32 bFlipYaw
flag to flip the sign of the yaw rotation angle
float farfield_thresh_m
Distance considered to be far field (no near field filtering), meters.
int hrtf_vbapTableRes[2]
[0] azimuth, and [1] elevation grid resolution, in degrees
float freqVector[HYBRID_BANDS]
Frequency vector (filterbank centre frequencies)
float_complex *** inputframeTF
time-frequency domain input frame; HYBRID_BANDS x MAX_NUM_INPUTS x TIME_SLOTS
_Atomic_INT32 hrir_loaded_fs
sampling rate of the loaded HRIRs
int fs
Host sampling rate, in Hz.
int * hrtf_vbap_gtableIdx
N_hrtf_vbap_gtable x 3.
_Atomic_FLOAT32 src_gains[MAX_NUM_INPUTS]
Gains applied per source.
float src_dirs_cur[MAX_NUM_INPUTS][2]
Pointer to assign to the current HRTF directions being operated on (non/rotated directions switch).
_Atomic_INT32 hrir_loaded_len
length of the loaded HRIRs, in samples
_Atomic_INT32 nSources
Current number of input/source signals.
_Atomic_INT32 hrir_runtime_len
length of the HRIRs being used for processing (after any resampling), in samples
float src_dirs_rot_xyz[MAX_NUM_INPUTS][3]
Intermediate rotated source directions, as unit-length Cartesian coordinates.
float dvfmags[MAX_NUM_INPUTS][NUM_EARS][HYBRID_BANDS]
DVF filter frequency band magnitudes.
float_complex hrtf_interp[MAX_NUM_INPUTS][HYBRID_BANDS][NUM_EARS]
Interpolated HRTFs.
float farfield_headroom
Scale factor applied to farfield_thresh_m when resetting to the far field, and for UI range,...
float head_radius
Head radius, used calculate normalized source distance meters, def.
_Atomic_INT32 reInitHRTFsAndGainTables
1: reinitialise the HRTFs and interpolation tables, 0: do not
_Atomic_INT32 hrir_runtime_fs
sampling rate of the HRIRs being used for processing (after any resampling)
_Atomic_INT32 recalc_hrtf_interpFLAG[MAX_NUM_INPUTS]
1: re-calculate/interpolate the HRTF, 0: do not
float b_dvf[MAX_NUM_INPUTS][NUM_EARS][2]
shelf IIR numerator coefficients for each input, left and right.
_Atomic_CODEC_STATUS codecStatus
see CODEC_STATUS
_Atomic_INT32 bFlipRoll
flag to flip the sign of the roll rotation angle
float ** outframeTD
time-domain output frame; NUM_EARS x BINAURALISER_FRAME_SIZE
float nearfield_limit_m
Minimum distance allowed for near-field filtering, from head center, meters, def.
float src_dirs_xyz[MAX_NUM_INPUTS][3]
Intermediate source directions, as unit-length Cartesian coordinates.
_Atomic_INT32 enableHRIRsDiffuseEQ
flag to diffuse-field equalisation to the currently loaded HRTFs
float * hrtf_vbap_gtableComp
N_hrtf_vbap_gtable x 3.
_Atomic_INT32 new_nSources
New number of input/source signals (current value will be replaced by this after next re-init)
_Atomic_INT32 recalc_M_rotFLAG
1: re-calculate the rotation matrix, 0: do not
_Atomic_FLOAT32 src_dirs_deg[MAX_NUM_INPUTS][2]
Current source/panning directions, in degrees.
_Atomic_FLOAT32 roll
roll (Euler) rotation angle, in degrees