SAF
Loading...
Searching...
No Matches
ambi_bin_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 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
47
48#ifndef __AMBI_BIN_INTERNAL_H_INCLUDED__
49#define __AMBI_BIN_INTERNAL_H_INCLUDED__
50
51#include "ambi_bin.h" /* Include header for this example */
52#include "saf.h" /* Main include header for SAF */
53#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
54
55#ifdef __cplusplus
56extern "C" {
57#endif /* __cplusplus */
58
59/* ========================================================================== */
60/* Internal Parameters */
61/* ========================================================================== */
62
63#if !defined(AMBI_BIN_FRAME_SIZE)
64# if defined(FRAME_SIZE) /* Use the global framesize if it is specified: */
65# define AMBI_BIN_FRAME_SIZE ( FRAME_SIZE )
66# else /* Otherwise, the default framesize for this example is: */
67# define AMBI_BIN_FRAME_SIZE ( 128 )
68# endif
69#endif
70#define HOP_SIZE ( 128 )
71#define HYBRID_BANDS ( HOP_SIZE + 5 )
72#define TIME_SLOTS ( AMBI_BIN_FRAME_SIZE / HOP_SIZE )
73#define POST_GAIN ( -9.0f )
74
75/* Checks: */
76#if (AMBI_BIN_FRAME_SIZE % HOP_SIZE != 0)
77# error "AMBI_BIN_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_BIN_PREPROC _Atomic_AMBI_BIN_PREPROC;
82 typedef _Atomic AMBI_BIN_DECODING_METHODS _Atomic_AMBI_BIN_DECODING_METHODS;
83#else
84 typedef AMBI_BIN_PREPROC _Atomic_AMBI_BIN_PREPROC;
85 typedef AMBI_BIN_DECODING_METHODS _Atomic_AMBI_BIN_DECODING_METHODS;
86#endif
87
88
89/* ========================================================================== */
90/* Structures */
91/* ========================================================================== */
92
94typedef struct _ambi_bin_codecPars
95{
96 /* Decoder */
99
100 /* sofa file info */
102 float* hrirs;
104 _Atomic_INT32 N_hrir_dirs;
105 _Atomic_INT32 hrir_len;
106 _Atomic_INT32 hrir_fs;
107
108 /* hrtf filterbank coefficients */
109 float* itds_s;
110 float_complex* hrtf_fb;
111
112 /* integration weights */
113 float* weights;
114
116
121typedef struct _ambi_bin
122{
123 /* audio buffers + afSTFT time-frequency transform handle */
124 _Atomic_INT32 fs;
125 float** SHFrameTD;
126 float** binFrameTD;
127 float_complex*** SHframeTF;
128 float_complex*** binframeTF;
129 void* hSTFT;
132
133 /* our codec configuration */
134 _Atomic_CODEC_STATUS codecStatus;
135 _Atomic_FLOAT32 progressBar0_1;
138
139 /* internal variables */
140 _Atomic_PROC_STATUS procStatus;
142 _Atomic_INT32 new_order;
143 _Atomic_INT32 nSH;
144
145 /* flags */
146 _Atomic_INT32 recalc_M_rotFLAG;
147 _Atomic_INT32 reinit_hrtfsFLAG;
148
149 /* user parameters */
150 _Atomic_INT32 order;
151 _Atomic_INT32 enableMaxRE;
152 _Atomic_INT32 enableDiffuseMatching;
153 _Atomic_INT32 enableTruncationEQ;
154 _Atomic_AMBI_BIN_DECODING_METHODS method;
155 _Atomic_INT32 useDefaultHRIRsFLAG;
156 _Atomic_AMBI_BIN_PREPROC preProc;
157 _Atomic_CH_ORDER chOrdering;
158 _Atomic_NORM_TYPES norm;
159 _Atomic_INT32 enableRotation;
160 _Atomic_FLOAT32 yaw;
161 _Atomic_FLOAT32 roll;
162 _Atomic_FLOAT32 pitch;
163 _Atomic_INT32 bFlipYaw;
164 _Atomic_INT32 bFlipPitch;
165 _Atomic_INT32 bFlipRoll;
166 _Atomic_INT32 useRollPitchYawFlag;
167
169
170
171/* ========================================================================== */
172/* Internal Functions */
173/* ========================================================================== */
174
176void ambi_bin_setCodecStatus(void* const hAmbi,
177 CODEC_STATUS newStatus);
178
179
180#ifdef __cplusplus
181} /* extern "C" { */
182#endif /* __cplusplus */
183
184#endif /* __AMBI_BIN_INTERNAL_H_INCLUDED__ */
#define MAX_NUM_SH_SIGNALS
Maximum number of spherical harmonic components/signals supported.
Definition _common.h:243
CODEC_STATUS
Current status of the codec.
Definition _common.h:205
A binaural Ambisonic decoder for reproducing Ambisonic sound scenes over headphones.
AMBI_BIN_DECODING_METHODS
Available decoding methods for the ambi_bin example.
Definition ambi_bin.h:126
AMBI_BIN_PREPROC
Available HRIR pre-preprocessing options.
Definition ambi_bin.h:141
#define HYBRID_BANDS
Number of frequency bands.
void ambi_bin_setCodecStatus(void *const hAmbi, CODEC_STATUS newStatus)
Sets codec status.
#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, HRIRs, and the binaural decoder.
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; FLAT: N_hrir_dirs x 2
float * weights
grid integration weights of hrirs; N_hrirs x 1
_Atomic_INT32 N_hrir_dirs
number of HRIR directions in the current sofa file
float_complex * hrtf_fb
HRTF filterbank coeffs; FLAT: nBands x nCH x N_hrirs.
char * sofa_filepath
absolute/relevative file path for a sofa file
_Atomic_INT32 hrir_len
length of the HRIRs, this can be truncated, see "saf_sofa_reader.h"
float_complex M_dec_rot[HYBRID_BANDS][NUM_EARS][MAX_NUM_SH_SIGNALS]
Decording matrix per band, with sound-field rotation baked-in.
float * hrirs
time domain HRIRs; FLAT: N_hrir_dirs x 2 x hrir_len
float_complex M_dec[HYBRID_BANDS][NUM_EARS][MAX_NUM_SH_SIGNALS]
Decoding matrix per band.
float * itds_s
interaural-time differences for each HRIR (in seconds); N_hrirs x 1
_Atomic_INT32 hrir_fs
sampling rate of the HRIRs, should ideally match the host sampling rate, although not required
Main structure for ambi_bin.
_Atomic_INT32 fs
host sampling rate
float_complex *** binframeTF
Output binaural signals in the time-frequency domain; HYBRID_BANDS x NUM_EARS x TIME_SLOTS.
_Atomic_INT32 enableRotation
Whether rotation should be enabled (1) or disabled (0)
_Atomic_CODEC_STATUS codecStatus
see CODEC_STATUS
_Atomic_AMBI_BIN_PREPROC preProc
HRIR pre-processing strategy.
_Atomic_INT32 enableTruncationEQ
0: disabled, 1: enabled
int afSTFTdelay
for host delay compensation
_Atomic_INT32 reinit_hrtfsFLAG
0: no init required, 1: init required
float_complex M_rot[MAX_NUM_SH_SIGNALS][MAX_NUM_SH_SIGNALS]
Current SH rotation matrix.
_Atomic_FLOAT32 pitch
pitch (Euler) rotation angle, in degrees
_Atomic_NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
char * progressBarText
Current (re)initialisation step, string.
_Atomic_INT32 useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
_Atomic_FLOAT32 yaw
yaw (Euler) rotation angle, in degrees
_Atomic_INT32 enableDiffuseMatching
0: disabled, 1: enabled
_Atomic_FLOAT32 roll
roll (Euler) rotation angle, in degrees
_Atomic_INT32 new_order
new decoding order (current value will be replaced by this after next re-init)
_Atomic_INT32 enableMaxRE
0: disabled, 1: enabled
void * hSTFT
afSTFT handle
_Atomic_INT32 nSH
number of spherical harmonic signals
_Atomic_AMBI_BIN_DECODING_METHODS method
current decoding method (see AMBI_BIN_DECODING_METHODS)
_Atomic_INT32 useRollPitchYawFlag
rotation order flag, 1: r-p-y, 0: y-p-r
float_complex *** SHframeTF
Input spherical harmonic (SH) signals in the time-frequency domain; HYBRID_BANDS x MAX_NUM_SH_SIGNALS...
float freqVector[HYBRID_BANDS]
frequency vector for time-frequency transform, in Hz
_Atomic_PROC_STATUS procStatus
see PROC_STATUS
_Atomic_INT32 bFlipYaw
flag to flip the sign of the yaw rotation angle
_Atomic_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
_Atomic_INT32 recalc_M_rotFLAG
0: no init required, 1: init required
_Atomic_INT32 bFlipRoll
flag to flip the sign of the roll rotation angle
ambi_bin_codecPars * pars
Decoding specific data.
_Atomic_CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)
_Atomic_INT32 order
current decoding order
float ** SHFrameTD
Input spherical harmonic (SH) signals in the time-domain; MAX_NUM_SH_SIGNALS x AMBI_BIN_FRAME_SIZE.
_Atomic_INT32 bFlipPitch
flag to flip the sign of the pitch rotation angle
float ** binFrameTD
Output binaural signals in the time-domain; NUM_EARS x AMBI_BIN_FRAME_SIZE.