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
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 )
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/* ========================================================================== */
81/* Structures */
82/* ========================================================================== */
83
88typedef struct _ambi_dec_codecPars
89{
90 /* decoders */
91 float* M_dec[NUM_DECODERS][MAX_SH_ORDER];
92 float_complex* M_dec_cmplx[NUM_DECODERS][MAX_SH_ORDER];
93 float* M_dec_maxrE[NUM_DECODERS][MAX_SH_ORDER];
94 float_complex* M_dec_cmplx_maxrE[NUM_DECODERS][MAX_SH_ORDER];
95 float M_norm[NUM_DECODERS][MAX_SH_ORDER][2];
97 /* sofa file info */
99 float* hrirs;
105 /* vbap gain table for panning the HRIRs */
106 int hrtf_vbapTableRes[2];
112 /* hrir filterbank coefficients */
113 float* itds_s;
114 float_complex* hrtf_fb;
115 float* hrtf_fb_mag;
116 float_complex hrtf_interp[MAX_NUM_LOUDSPEAKERS][HYBRID_BANDS][NUM_EARS];
118 /* integration weights */
119 float* weights;
122
127typedef struct _ambi_dec
128{
129 /* audio buffers + afSTFT time-frequency transform handle */
130 float** SHFrameTD;
132 float_complex*** SHframeTF;
133 float_complex*** outputframeTF;
134 float_complex*** binframeTF;
135 void* hSTFT;
137 int fs;
138 float freqVector[HYBRID_BANDS];
140 /* our codec configuration */
146 /* internal variables */
152 /* flags */
155 int recalc_hrtf_interpFLAG[MAX_NUM_LOUDSPEAKERS];
157 /* user parameters */
159 int orderPerBand[HYBRID_BANDS];
161 int rE_WEIGHT[NUM_DECODERS];
165 float loudpkrs_dirs_deg[MAX_NUM_LOUDSPEAKERS][NUM_DECODERS];
173
174
175/* ========================================================================== */
176/* Internal Functions */
177/* ========================================================================== */
178
182void ambi_dec_setCodecStatus(void* const hCmp, CODEC_STATUS newStatus);
183
194void ambi_dec_interpHRTFs(void* const hAmbi,
195 float azimuth_deg,
196 float elevation_deg,
197 float_complex h_intrp[HYBRID_BANDS][NUM_EARS]);
198
219 float dirs_deg[MAX_NUM_LOUDSPEAKERS][2],
220 int* nCH,
221 int* nDims);
222
223
224#ifdef __cplusplus
225} /* extern "C" */
226#endif /* __cplusplus */
227
228#endif /* __AMBI_DEC_INTERNAL_H_INCLUDED__ */
#define MAX_SH_ORDER
Maximum supported Ambisonic order.
Definition _common.h:52
LOUDSPEAKER_ARRAY_PRESETS
Available loudspeaker array presets.
Definition _common.h:99
PROC_STATUS
Current status of the processing loop.
Definition _common.h:219
NORM_TYPES
Available Ambisonic normalisation conventions.
Definition _common.h:74
CH_ORDER
Available Ambisonic channel ordering conventions.
Definition _common.h:59
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
#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, float dirs_deg[MAX_NUM_LOUDSPEAKERS][2], int *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.
char * sofa_filepath
absolute/relevative file path for a sofa file
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 hrir_len
length of the HRIRs, this can be truncated, see "saf_sofa_reader.h"
float_complex * hrtf_fb
HRTF filterbank coefficients; nBands x nCH x N_hrirs.
int 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 * weights
grid integration weights of hrirs; N_hrirs x 1
int N_hrir_dirs
number of HRIR directions in the current sofa file
float * hrtf_vbap_gtableComp
N_hrtf_vbap_gtable x 3.
float * hrirs
time domain HRIRs; N_hrir_dirs x 2 x hrir_len
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; N_hrir_dirs x 2
Main structure for ambi_dec.
CODEC_STATUS codecStatus
see CODEC_STATUS
int new_nLoudpkrs
if new_nLoudpkrs != nLoudpkrs, afSTFT is reinitialised (current value will be replaced by this after ...
int new_masterOrder
if new_masterOrder != masterOrder, ambi_dec is reinitialised (current value will be replaced by this ...
CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)
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.
float_complex *** binframeTF
Output binaural signals in the time-frequency domain; HYBRID_BANDS x NUM_EARS x TIME_SLOTS.
int useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
float transitionFreq
transition frequency for the 2 decoders, in Hz
void * hSTFT
afSTFT handle
float_complex *** SHframeTF
Input spherical harmonic (SH) signals in the time-frequency domain; HYBRID_BANDS x MAX_NUM_SH_SIGNALS...
int enableHRIRsPreProc
flag to apply pre-processing to the currently loaded HRTFs
float progressBar0_1
Current (re)initialisation progress, between [0..1].
int masterOrder
Current maximum/master decoding order.
NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
float ** outputFrameTD
Output loudspeaker or binaural signals in the time-domain; MAX_NUM_LOUDSPEAKERS x AMBI_DEC_FRAME_SIZE...
int fs
host sampling rate
int nLoudpkrs
number of loudspeakers/virtual loudspeakers
PROC_STATUS procStatus
see PROC_STATUS
char * progressBarText
Current (re)initialisation step, string.
int binauraliseLS
1: convolve loudspeaker signals with HRTFs, 0: output loudspeaker signals
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...
int new_binauraliseLS
if new_binauraliseLS != binauraliseLS, ambi_dec is reinitialised (current value will be replaced by t...
int reinit_hrtfsFLAG
0: no init required, 1: init required