SAF
Loading...
Searching...
No Matches
ambi_dec_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2017-2018 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
45
46#ifndef __AMBI_DEC_INTERNAL_H_INCLUDED__
47#define __AMBI_DEC_INTERNAL_H_INCLUDED__
48
49#include "ambi_dec.h" /* Include header for this example */
50#include "saf.h" /* Main include header for SAF */
51#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
52
53#ifdef __cplusplus
54extern "C" {
55#endif /* __cplusplus */
56
57/* ========================================================================== */
58/* Internal Parameters */
59/* ========================================================================== */
60
61#if !defined(AMBI_DEC_FRAME_SIZE)
62# if defined(FRAME_SIZE) /* Use the global framesize if it is specified: */
63# define AMBI_DEC_FRAME_SIZE ( FRAME_SIZE )
64# else /* Otherwise, the default framesize for this example is: */
65# define AMBI_DEC_FRAME_SIZE ( 128 )
66# endif
67#endif
68#define HOP_SIZE ( 128 )
69#define HYBRID_BANDS ( HOP_SIZE + 5 )
70#define TIME_SLOTS ( AMBI_DEC_FRAME_SIZE / HOP_SIZE )
71#define MAX_NUM_LOUDSPEAKERS ( MAX_NUM_OUTPUTS )
72#define MIN_NUM_LOUDSPEAKERS ( 4 )
73#define NUM_DECODERS ( 2 )
74
75/* Checks: */
76#if (AMBI_DEC_FRAME_SIZE % HOP_SIZE != 0)
77# error "AMBI_DEC_FRAME_SIZE must be an integer multiple of HOP_SIZE"
78#endif
79
80#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
81 typedef _Atomic AMBI_DEC_DECODING_METHODS _Atomic_AMBI_DEC_DECODING_METHODS;
82 typedef _Atomic AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH _Atomic_AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH;
83#else
84 typedef AMBI_DEC_DECODING_METHODS _Atomic_AMBI_DEC_DECODING_METHODS;
85 typedef AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH _Atomic_AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH;
86#endif
87
88/* ========================================================================== */
89/* Structures */
90/* ========================================================================== */
91
96typedef struct _ambi_dec_codecPars
97{
98 /* decoders */
104
105 /* sofa file info */
107 float* hrirs;
109 _Atomic_INT32 N_hrir_dirs;
110 _Atomic_INT32 hrir_len;
111 _Atomic_INT32 hrir_fs;
112
113 /* vbap gain table for panning the HRIRs */
119
120 /* hrir filterbank coefficients */
121 float* itds_s;
122 float_complex* hrtf_fb;
123 float* hrtf_fb_mag;
125
126 /* integration weights */
127 float* weights;
128
130
135typedef struct _ambi_dec
136{
137 /* audio buffers + afSTFT time-frequency transform handle */
138 float** SHFrameTD;
140 float_complex*** SHframeTF;
141 float_complex*** outputframeTF;
142 float_complex*** binframeTF;
143 void* hSTFT;
145 _Atomic_INT32 fs;
147
148 /* our codec configuration */
149 _Atomic_CODEC_STATUS codecStatus;
150 _Atomic_FLOAT32 progressBar0_1;
153
154 /* internal variables */
156 _Atomic_INT32 new_nLoudpkrs;
157 _Atomic_INT32 new_binauraliseLS;
158 _Atomic_INT32 new_masterOrder;
159
160 /* flags */
161 _Atomic_PROC_STATUS procStatus;
162 _Atomic_INT32 reinit_hrtfsFLAG;
164
165 /* user parameters */
166 _Atomic_INT32 masterOrder;
167 _Atomic_INT32 orderPerBand[HYBRID_BANDS];
168 _Atomic_AMBI_DEC_DECODING_METHODS dec_method[NUM_DECODERS];
169 _Atomic_INT32 rE_WEIGHT[NUM_DECODERS];
170 _Atomic_AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH diffEQmode[NUM_DECODERS];
171 _Atomic_FLOAT32 transitionFreq;
172 _Atomic_INT32 nLoudpkrs;
174 _Atomic_INT32 useDefaultHRIRsFLAG;
175 _Atomic_INT32 enableHRIRsPreProc;
176 _Atomic_INT32 binauraliseLS;
177 _Atomic_CH_ORDER chOrdering;
178 _Atomic_NORM_TYPES norm;
179
181
182
183/* ========================================================================== */
184/* Internal Functions */
185/* ========================================================================== */
186
190void ambi_dec_setCodecStatus(void* const hCmp, CODEC_STATUS newStatus);
191
202void ambi_dec_interpHRTFs(void* const hAmbi,
203 float azimuth_deg,
204 float elevation_deg,
205 float_complex h_intrp[HYBRID_BANDS][NUM_EARS]);
206
227 _Atomic_FLOAT32 dirs_deg[MAX_NUM_LOUDSPEAKERS][2],
228 _Atomic_INT32* nCH,
229 int* nDims);
230
231
232#ifdef __cplusplus
233} /* extern "C" */
234#endif /* __cplusplus */
235
236#endif /* __AMBI_DEC_INTERNAL_H_INCLUDED__ */
#define MAX_SH_ORDER
Maximum supported Ambisonic order.
Definition _common.h:56
LOUDSPEAKER_ARRAY_PRESETS
Available loudspeaker array presets.
Definition _common.h:103
CODEC_STATUS
Current status of the codec.
Definition _common.h:205
#define HYBRID_BANDS
Number of frequency bands.
A frequency-dependent Ambisonic decoder for reproducing Ambisonic sound scenes over loudspeakers.
AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH
When using mixed order decoding (i.e.
Definition ambi_dec.h:92
AMBI_DEC_DECODING_METHODS
Available decoding methods.
Definition ambi_dec.h:73
void loadLoudspeakerArrayPreset(LOUDSPEAKER_ARRAY_PRESETS preset, _Atomic_FLOAT32 dirs_deg[MAX_NUM_LOUDSPEAKERS][2], _Atomic_INT32 *nCH, int *nDims)
Returns the loudspeaker directions for a specified loudspeaker array preset.
void ambi_dec_setCodecStatus(void *const hCmp, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
#define HYBRID_BANDS
Number of frequency bands.
void ambi_dec_interpHRTFs(void *const hAmbi, float azimuth_deg, float elevation_deg, float_complex h_intrp[HYBRID_BANDS][NUM_EARS])
Interpolates between the 3 nearest HRTFs using amplitude-preserving VBAP gains.
#define MAX_NUM_LOUDSPEAKERS
Maximum permitted output channels.
#define NUM_DECODERS
One for low-frequencies and another for high-frequencies.
#define NUM_EARS
2 (true for most humans)
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
Contains variables for sofa file loading, HRTF interpolation, and the loudspeaker decoders.
_Atomic_INT32 N_hrir_dirs
number of HRIR directions in the current sofa file
float_complex hrtf_interp[MAX_NUM_LOUDSPEAKERS][HYBRID_BANDS][NUM_EARS]
interpolated HRTFs
_Atomic_INT32 hrir_len
length of the HRIRs, this can be truncated, see "saf_sofa_reader.h"
char * sofa_filepath
absolute/relevative file path for a sofa file
float * M_dec_maxrE[NUM_DECODERS][MAX_SH_ORDER]
ambisonic decoding matrices with maxrE weighting ([0] for low-freq, [1] for high-freq); FLAT: nLoudsp...
float * M_dec[NUM_DECODERS][MAX_SH_ORDER]
ambisonic decoding matrices ([0] for low-freq, [1] for high-freq); FLAT: nLoudspeakers x nSH
int hrtf_nTriangles
number of triangle groups after triangulation
float * itds_s
interaural-time differences for each HRIR (in seconds); N_hrirs x 1
int * hrtf_vbap_gtableIdx
N_hrtf_vbap_gtable x 3.
int hrtf_vbapTableRes[2]
[azi elev] step sizes in degrees
float_complex * hrtf_fb
HRTF filterbank coefficients; nBands x nCH x N_hrirs.
float_complex * M_dec_cmplx_maxrE[NUM_DECODERS][MAX_SH_ORDER]
complex ambisonic decoding matrices with maxrE weighting ([0] for low-freq, [1] for high-freq); FLAT:...
_Atomic_INT32 hrir_fs
sampling rate of the HRIRs, should ideally match the host sampling rate, although not required
float * hrtf_fb_mag
magnitudes of the HRTF filterbank coefficients; nBands x nCH x N_hrirs
int N_hrtf_vbap_gtable
number of interpolation directions
float_complex * M_dec_cmplx[NUM_DECODERS][MAX_SH_ORDER]
complex ambisonic decoding matrices ([0] for low-freq, [1] for high-freq); FLAT: nLoudspeakers x nSH
float * weights
grid integration weights of hrirs; N_hrirs x 1
float * hrtf_vbap_gtableComp
N_hrtf_vbap_gtable x 3.
float * hrirs
time domain HRIRs; N_hrir_dirs x 2 x hrir_len
float M_norm[NUM_DECODERS][MAX_SH_ORDER][2]
norm coefficients to preserve omni energy/amplitude between different orders and decoders
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; N_hrir_dirs x 2
Main structure for ambi_dec.
_Atomic_AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH diffEQmode[NUM_DECODERS]
diffuse-field EQ approach; see AMBI_DEC_DIFFUSE_FIELD_EQ_APPROACH enum
_Atomic_INT32 masterOrder
Current maximum/master decoding order.
_Atomic_INT32 new_masterOrder
if new_masterOrder != masterOrder, ambi_dec is reinitialised (current value will be replaced by this ...
_Atomic_INT32 reinit_hrtfsFLAG
0: no init required, 1: init required
_Atomic_CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)
_Atomic_INT32 nLoudpkrs
number of loudspeakers/virtual loudspeakers
int afSTFTdelay
for host delay compensation
int loudpkrs_nDims
dimensionality of the current loudspeaker set-up
float ** SHFrameTD
Input spherical harmonic (SH) signals in the time-domain; MAX_NUM_SH_SIGNALS x AMBI_DEC_FRAME_SIZE.
_Atomic_FLOAT32 transitionFreq
transition frequency for the 2 decoders, in Hz
float_complex *** binframeTF
Output binaural signals in the time-frequency domain; HYBRID_BANDS x NUM_EARS x TIME_SLOTS.
_Atomic_INT32 recalc_hrtf_interpFLAG[MAX_NUM_LOUDSPEAKERS]
0: no init required, 1: init required
_Atomic_INT32 enableHRIRsPreProc
flag to apply pre-processing to the currently loaded HRTFs
_Atomic_NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
_Atomic_FLOAT32 loudpkrs_dirs_deg[MAX_NUM_LOUDSPEAKERS][2]
loudspeaker directions in degrees [azi, elev]
_Atomic_INT32 orderPerBand[HYBRID_BANDS]
Ambisonic decoding order per frequency band 1..SH_ORDER.
_Atomic_AMBI_DEC_DECODING_METHODS dec_method[NUM_DECODERS]
decoding methods for each decoder, see AMBI_DEC_DECODING_METHODS enum
void * hSTFT
afSTFT handle
_Atomic_INT32 useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
float_complex *** SHframeTF
Input spherical harmonic (SH) signals in the time-frequency domain; HYBRID_BANDS x MAX_NUM_SH_SIGNALS...
float ** outputFrameTD
Output loudspeaker or binaural signals in the time-domain; MAX_NUM_LOUDSPEAKERS x AMBI_DEC_FRAME_SIZE...
_Atomic_INT32 new_binauraliseLS
if new_binauraliseLS != binauraliseLS, ambi_dec is reinitialised (current value will be replaced by t...
_Atomic_PROC_STATUS procStatus
see PROC_STATUS
_Atomic_INT32 binauraliseLS
1: convolve loudspeaker signals with HRTFs, 0: output loudspeaker signals
_Atomic_INT32 fs
host sampling rate
_Atomic_CODEC_STATUS codecStatus
see CODEC_STATUS
_Atomic_INT32 rE_WEIGHT[NUM_DECODERS]
0:disabled, 1: enable max_rE weight
float freqVector[HYBRID_BANDS]
frequency vector for time-frequency transform, in Hz
char * progressBarText
Current (re)initialisation step, string.
_Atomic_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
ambi_dec_codecPars * pars
codec parameters
float_complex *** outputframeTF
Output loudspeaker signals in the time-frequency domain; HYBRID_BANDS x MAX_NUM_LOUDSPEAKERS x TIME_S...
_Atomic_INT32 new_nLoudpkrs
if new_nLoudpkrs != nLoudpkrs, afSTFT is reinitialised (current value will be replaced by this after ...