Skip to content

Commit 8381196

Browse files
added use of atomics in ambi_bin
1 parent eb66339 commit 8381196

File tree

4 files changed

+71
-34
lines changed

4 files changed

+71
-34
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ endif()
2929

3030
# Configure CMake
3131
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
32-
set(CMAKE_C_STANDARD 99)
33-
set(CMAKE_C_STANDARD_REQUIRED OFF)
32+
if(MSVC)
33+
set(CMAKE_C_STANDARD 99)
34+
else()
35+
set(CMAKE_C_STANDARD 11)
36+
endif()
37+
set(CMAKE_C_STANDARD_REQUIRED ON)
3438
set(CMAKE_CXX_STANDARD 14)
3539
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3640
set(CMAKE_CXX_EXTENSIONS OFF)

examples/include/_common.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@
3030
extern "C" {
3131
#endif /* __cplusplus */
3232

33+
#if defined(_MSC_VER)
34+
#if _MSC_VER >= 1936 && defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
35+
#pragma message("WARNING: The MSVC C compiler only has \"experimental\" Atomic support") /* although, seems to be fine... */
36+
#define STD_ATOMICS_SUPPORTED ( 1 )
37+
#else
38+
#pragma message("WARNING: Atomics require C11 and are not supported by the MSVC C compiler pre _MSC_VER=1936")
39+
#define STD_ATOMICS_SUPPORTED ( 0 )
40+
#endif
41+
#else
42+
#define STD_ATOMICS_SUPPORTED ( 1 )
43+
#include <stdatomic.h>
44+
#endif
45+
3346
/* ========================================================================== */
3447
/* Presets + Constants */
3548
/* ========================================================================== */
@@ -238,6 +251,24 @@ typedef enum {
238251
/** Maximum number of spherical harmonic components/signals supported */
239252
#define MAX_NUM_SH_SIGNALS ( MAX_NUM_CHANNELS )
240253

254+
#if STD_ATOMICS_SUPPORTED
255+
typedef _Atomic(float) _Atomic_FLOAT32;
256+
typedef _Atomic(int) _Atomic_INT32;
257+
258+
typedef _Atomic(CH_ORDER) _Atomic_CH_ORDER;
259+
typedef _Atomic(NORM_TYPES) _Atomic_NORM_TYPES;
260+
typedef _Atomic(CODEC_STATUS) _Atomic_CODEC_STATUS;
261+
typedef _Atomic(PROC_STATUS) _Atomic_PROC_STATUS;
262+
#else
263+
typedef float _Atomic_FLOAT32;
264+
typedef int _Atomic_INT32;
265+
266+
typedef CH_ORDER _Atomic_CH_ORDER;
267+
typedef NORM_TYPES _Atomic_NORM_TYPES;
268+
typedef CODEC_STATUS _Atomic_CODEC_STATUS;
269+
typedef PROC_STATUS _Atomic_PROC_STATUS;
270+
#endif
271+
241272

242273
#ifdef __cplusplus
243274
} /* extern "C" { */

examples/src/ambi_bin/ambi_bin.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ void ambi_bin_create
5454
{
5555
ambi_bin_data* pData = (ambi_bin_data*)malloc1d(sizeof(ambi_bin_data));
5656
*phAmbi = (void*)pData;
57-
int band;
5857

5958
/* default user parameters */
60-
for (band = 0; band<HYBRID_BANDS; band++)
61-
pData->EQ[band] = 1.0f;
6259
pData->useDefaultHRIRsFLAG = 1; /* pars->sofa_filepath must be valid to set this to 0 */
6360
pData->preProc = HRIR_PREPROC_EQ;
6461
pData->chOrdering = CH_ACN;

examples/src/ambi_bin/ambi_bin_internal.h

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ extern "C" {
7777
# error "AMBI_BIN_FRAME_SIZE must be an integer multiple of HOP_SIZE"
7878
#endif
7979

80+
#if STD_ATOMICS_SUPPORTED
81+
typedef _Atomic(AMBI_BIN_PREPROC) _Atomic_AMBI_BIN_PREPROC;
82+
#else
83+
typedef AMBI_BIN_PREPROC _Atomic_AMBI_BIN_PREPROC;
84+
#endif
85+
8086

8187
/* ========================================================================== */
8288
/* Structures */
@@ -93,9 +99,9 @@ typedef struct _ambi_bin_codecPars
9399
char* sofa_filepath; /**< absolute/relevative file path for a sofa file */
94100
float* hrirs; /**< time domain HRIRs; FLAT: N_hrir_dirs x 2 x hrir_len */
95101
float* hrir_dirs_deg; /**< directions of the HRIRs in degrees [azi elev]; FLAT: N_hrir_dirs x 2 */
96-
int N_hrir_dirs; /**< number of HRIR directions in the current sofa file */
97-
int hrir_len; /**< length of the HRIRs, this can be truncated, see "saf_sofa_reader.h" */
98-
int hrir_fs; /**< sampling rate of the HRIRs, should ideally match the host sampling rate, although not required */
102+
_Atomic_INT32 N_hrir_dirs; /**< number of HRIR directions in the current sofa file */
103+
_Atomic_INT32 hrir_len; /**< length of the HRIRs, this can be truncated, see "saf_sofa_reader.h" */
104+
_Atomic_INT32 hrir_fs; /**< sampling rate of the HRIRs, should ideally match the host sampling rate, although not required */
99105

100106
/* hrtf filterbank coefficients */
101107
float* itds_s; /**< interaural-time differences for each HRIR (in seconds); N_hrirs x 1 */
@@ -113,7 +119,7 @@ typedef struct _ambi_bin_codecPars
113119
typedef struct _ambi_bin
114120
{
115121
/* audio buffers + afSTFT time-frequency transform handle */
116-
int fs; /**< host sampling rate */
122+
_Atomic_INT32 fs; /**< host sampling rate */
117123
float** SHFrameTD; /**< Input spherical harmonic (SH) signals in the time-domain; #MAX_NUM_SH_SIGNALS x #AMBI_BIN_FRAME_SIZE */
118124
float** binFrameTD; /**< Output binaural signals in the time-domain; #NUM_EARS x #AMBI_BIN_FRAME_SIZE */
119125
float_complex*** SHframeTF; /**< Input spherical harmonic (SH) signals in the time-frequency domain; #HYBRID_BANDS x #MAX_NUM_SH_SIGNALS x #TIME_SLOTS */
@@ -123,40 +129,39 @@ typedef struct _ambi_bin
123129
float freqVector[HYBRID_BANDS]; /**< frequency vector for time-frequency transform, in Hz */
124130

125131
/* our codec configuration */
126-
CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
127-
float progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
132+
_Atomic_CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
133+
_Atomic_FLOAT32 progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
128134
char* progressBarText; /**< Current (re)initialisation step, string */
129135
ambi_bin_codecPars* pars; /**< Decoding specific data */
130136

131137
/* internal variables */
132-
PROC_STATUS procStatus; /**< see #PROC_STATUS */
138+
_Atomic_PROC_STATUS procStatus; /**< see #PROC_STATUS */
133139
float_complex M_rot[MAX_NUM_SH_SIGNALS][MAX_NUM_SH_SIGNALS]; /**< Current SH rotation matrix */
134-
int new_order; /**< new decoding order (current value will be replaced by this after next re-init) */
135-
int nSH; /**< number of spherical harmonic signals */
140+
_Atomic_INT32 new_order; /**< new decoding order (current value will be replaced by this after next re-init) */
141+
_Atomic_INT32 nSH; /**< number of spherical harmonic signals */
136142

137143
/* flags */
138-
int recalc_M_rotFLAG; /**< 0: no init required, 1: init required */
139-
int reinit_hrtfsFLAG; /**< 0: no init required, 1: init required */
144+
_Atomic_INT32 recalc_M_rotFLAG; /**< 0: no init required, 1: init required */
145+
_Atomic_INT32 reinit_hrtfsFLAG; /**< 0: no init required, 1: init required */
140146

141147
/* user parameters */
142-
int order; /**< current decoding order */
143-
int enableMaxRE; /**< 0: disabled, 1: enabled */
144-
int enableDiffuseMatching; /**< 0: disabled, 1: enabled */
145-
int enableTruncationEQ; /**< 0: disabled, 1: enabled */
146-
AMBI_BIN_DECODING_METHODS method; /**< current decoding method (see #AMBI_BIN_DECODING_METHODS) */
147-
float EQ[HYBRID_BANDS]; /**< EQ curve */
148-
int useDefaultHRIRsFLAG; /**< 1: use default HRIRs in database, 0: use those from SOFA file */
149-
AMBI_BIN_PREPROC preProc; /**< HRIR pre-processing strategy */
150-
CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
151-
NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
152-
int enableRotation; /**< Whether rotation should be enabled (1) or disabled (0) */
153-
float yaw; /**< yaw (Euler) rotation angle, in degrees */
154-
float roll; /**< roll (Euler) rotation angle, in degrees */
155-
float pitch; /**< pitch (Euler) rotation angle, in degrees */
156-
int bFlipYaw; /**< flag to flip the sign of the yaw rotation angle */
157-
int bFlipPitch; /**< flag to flip the sign of the pitch rotation angle */
158-
int bFlipRoll; /**< flag to flip the sign of the roll rotation angle */
159-
int useRollPitchYawFlag; /**< rotation order flag, 1: r-p-y, 0: y-p-r */
148+
_Atomic_INT32 order; /**< current decoding order */
149+
_Atomic_INT32 enableMaxRE; /**< 0: disabled, 1: enabled */
150+
_Atomic_INT32 enableDiffuseMatching; /**< 0: disabled, 1: enabled */
151+
_Atomic_INT32 enableTruncationEQ; /**< 0: disabled, 1: enabled */
152+
AMBI_BIN_DECODING_METHODS method; /**< current decoding method (see #AMBI_BIN_DECODING_METHODS) */
153+
_Atomic_INT32 useDefaultHRIRsFLAG; /**< 1: use default HRIRs in database, 0: use those from SOFA file */
154+
_Atomic_AMBI_BIN_PREPROC preProc; /**< HRIR pre-processing strategy */
155+
_Atomic_CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
156+
_Atomic_NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
157+
_Atomic_INT32 enableRotation; /**< Whether rotation should be enabled (1) or disabled (0) */
158+
_Atomic_FLOAT32 yaw; /**< yaw (Euler) rotation angle, in degrees */
159+
_Atomic_FLOAT32 roll; /**< roll (Euler) rotation angle, in degrees */
160+
_Atomic_FLOAT32 pitch; /**< pitch (Euler) rotation angle, in degrees */
161+
_Atomic_INT32 bFlipYaw; /**< flag to flip the sign of the yaw rotation angle */
162+
_Atomic_INT32 bFlipPitch; /**< flag to flip the sign of the pitch rotation angle */
163+
_Atomic_INT32 bFlipRoll; /**< flag to flip the sign of the roll rotation angle */
164+
_Atomic_INT32 useRollPitchYawFlag; /**< rotation order flag, 1: r-p-y, 0: y-p-r */
160165

161166
} ambi_bin_data;
162167

0 commit comments

Comments
 (0)