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
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 )
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
81/* ========================================================================== */
82/* Structures */
83/* ========================================================================== */
84
86typedef struct _ambi_bin_codecPars
87{
88 /* Decoder */
89 float_complex M_dec[HYBRID_BANDS][NUM_EARS][MAX_NUM_SH_SIGNALS];
90 float_complex M_dec_rot[HYBRID_BANDS][NUM_EARS][MAX_NUM_SH_SIGNALS];
92 /* sofa file info */
94 float* hrirs;
98 int hrir_fs;
100 /* hrtf filterbank coefficients */
101 float* itds_s;
102 float_complex* hrtf_fb;
104 /* integration weights */
105 float* weights;
108
113typedef struct _ambi_bin
114{
115 /* audio buffers + afSTFT time-frequency transform handle */
116 int fs;
117 float** SHFrameTD;
118 float** binFrameTD;
119 float_complex*** SHframeTF;
120 float_complex*** binframeTF;
121 void* hSTFT;
123 float freqVector[HYBRID_BANDS];
125 /* our codec configuration */
131 /* internal variables */
135 int nSH;
137 /* flags */
141 /* user parameters */
142 int order;
147 float EQ[HYBRID_BANDS];
153 float yaw;
154 float roll;
155 float pitch;
162
163
164/* ========================================================================== */
165/* Internal Functions */
166/* ========================================================================== */
167
169void ambi_bin_setCodecStatus(void* const hAmbi,
170 CODEC_STATUS newStatus);
171
172
173#ifdef __cplusplus
174} /* extern "C" { */
175#endif /* __cplusplus */
176
177#endif /* __AMBI_BIN_INTERNAL_H_INCLUDED__ */
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
#define MAX_NUM_SH_SIGNALS
Maximum number of spherical harmonic components/signals supported.
Definition _common.h:239
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
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.
int N_hrir_dirs
number of HRIR directions in the current sofa file
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
int hrir_len
length of the HRIRs, this can be truncated, see "saf_sofa_reader.h"
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
int hrir_fs
sampling rate of the HRIRs, should ideally match the host sampling rate, although not required
float * hrirs
time domain HRIRs; FLAT: N_hrir_dirs x 2 x hrir_len
float * itds_s
interaural-time differences for each HRIR (in seconds); N_hrirs x 1
Main structure for ambi_bin.
CODEC_STATUS codecStatus
see CODEC_STATUS
float_complex *** binframeTF
Output binaural signals in the time-frequency domain; HYBRID_BANDS x NUM_EARS x TIME_SLOTS.
float pitch
pitch (Euler) rotation angle, in degrees
CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)
int bFlipRoll
flag to flip the sign of the roll rotation angle
int enableDiffuseMatching
0: disabled, 1: enabled
int afSTFTdelay
for host delay compensation
int bFlipPitch
flag to flip the sign of the pitch rotation angle
int enableTruncationEQ
0: disabled, 1: enabled
AMBI_BIN_DECODING_METHODS method
current decoding method (see AMBI_BIN_DECODING_METHODS)
int useRollPitchYawFlag
rotation order flag, 1: r-p-y, 0: y-p-r
int enableMaxRE
0: disabled, 1: enabled
PROC_STATUS procStatus
see PROC_STATUS
char * progressBarText
Current (re)initialisation step, string.
int useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
int bFlipYaw
flag to flip the sign of the yaw rotation angle
int new_order
new decoding order (current value will be replaced by this after next re-init)
void * hSTFT
afSTFT handle
NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
AMBI_BIN_PREPROC preProc
HRIR pre-processing strategy.
float_complex *** SHframeTF
Input spherical harmonic (SH) signals in the time-frequency domain; HYBRID_BANDS x MAX_NUM_SH_SIGNALS...
float progressBar0_1
Current (re)initialisation progress, between [0..1].
float roll
roll (Euler) rotation angle, in degrees
int recalc_M_rotFLAG
0: no init required, 1: init required
int nSH
number of spherical harmonic signals
ambi_bin_codecPars * pars
Decoding specific data.
float yaw
yaw (Euler) rotation angle, in degrees
int order
current decoding order
int reinit_hrtfsFLAG
0: no init required, 1: init required
float ** SHFrameTD
Input spherical harmonic (SH) signals in the time-domain; MAX_NUM_SH_SIGNALS x AMBI_BIN_FRAME_SIZE.
int fs
host sampling rate
float ** binFrameTD
Output binaural signals in the time-domain; NUM_EARS x AMBI_BIN_FRAME_SIZE.
int enableRotation
Whether rotation should be enabled (1) or disabled (0)