Skip to content

Commit 3b12e4e

Browse files
adopting atomics for more examples
1 parent 7d809bd commit 3b12e4e

File tree

11 files changed

+132
-101
lines changed

11 files changed

+132
-101
lines changed

examples/src/pitch_shifter/pitch_shifter_internal.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ extern "C" {
4646
# endif
4747
#endif
4848

49+
#ifndef __STDC_NO_ATOMICS__
50+
typedef _Atomic(PITCH_SHIFTER_FFTSIZE_OPTIONS) _Atomic_PITCH_SHIFTER_FFTSIZE_OPTIONS;
51+
typedef _Atomic(PITCH_SHIFTER_OSAMP_OPTIONS) _Atomic_PITCH_SHIFTER_OSAMP_OPTIONS;
52+
#else
53+
typedef PITCH_SHIFTER_FFTSIZE_OPTIONS _Atomic_PITCH_SHIFTER_FFTSIZE_OPTIONS;
54+
typedef PITCH_SHIFTER_OSAMP_OPTIONS _Atomic_PITCH_SHIFTER_OSAMP_OPTIONS;
55+
#endif
56+
4957
/* ========================================================================== */
5058
/* Structures */
5159
/* ========================================================================== */
@@ -60,22 +68,22 @@ typedef struct _pitch_shifter
6068

6169
/* internal */
6270
void* hSmb; /**< pitch-shifter handle */
63-
CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
64-
float progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
71+
_Atomic_CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
72+
_Atomic_FLOAT32 progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
6573
char* progressBarText; /**< Current (re)initialisation step, string */
66-
PROC_STATUS procStatus; /**< see #PROC_STATUS */
74+
_Atomic_PROC_STATUS procStatus; /**< see #PROC_STATUS */
6775
float sampleRate; /**< Host sampling rate, in Hz */
6876
float inputFrame[MAX_NUM_CHANNELS][PITCH_SHIFTER_FRAME_SIZE]; /**< Current input frame */
6977
float outputFrame[MAX_NUM_CHANNELS][PITCH_SHIFTER_FRAME_SIZE]; /**< Current output frame */
70-
int new_nChannels; /**< (current value will be replaced by this after next re-init) */
78+
_Atomic_INT32 new_nChannels; /**< (current value will be replaced by this after next re-init) */
7179
int fftFrameSize; /**< FFT size */
7280
int stepsize; /**< Hop size in samples*/
7381

7482
/* user parameters */
75-
int nChannels; /**< Current number of input/output channels */
76-
float pitchShift_factor; /**< 1: no shift, 0.5: down one octave, 2: up one octave */
77-
PITCH_SHIFTER_FFTSIZE_OPTIONS fftsize_option; /**< see #PITCH_SHIFTER_FFTSIZE_OPTIONS */
78-
PITCH_SHIFTER_OSAMP_OPTIONS osamp_option; /**< see #PITCH_SHIFTER_OSAMP_OPTIONS */
83+
_Atomic_INT32 nChannels; /**< Current number of input/output channels */
84+
_Atomic_FLOAT32 pitchShift_factor; /**< 1: no shift, 0.5: down one octave, 2: up one octave */
85+
_Atomic_PITCH_SHIFTER_FFTSIZE_OPTIONS fftsize_option; /**< see #PITCH_SHIFTER_FFTSIZE_OPTIONS */
86+
_Atomic_PITCH_SHIFTER_OSAMP_OPTIONS osamp_option; /**< see #PITCH_SHIFTER_OSAMP_OPTIONS */
7987

8088
} pitch_shifter_data;
8189

examples/src/powermap/powermap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void powermap_getPowermapEQHandle
642642
{
643643
powermap_data *pData = (powermap_data*)(hPm);
644644
(*pX_vector) = &(pData->freqVector[0]);
645-
(*pY_values) = &(pData->pmapEQ[0]);
645+
(*pY_values) = (float*)&(pData->pmapEQ[0]);
646646
(*pNpoints) = HYBRID_BANDS;
647647
}
648648

@@ -668,7 +668,7 @@ void powermap_getAnaOrderHandle
668668
{
669669
powermap_data *pData = (powermap_data*)(hPm);
670670
(*pX_vector) = &(pData->freqVector[0]);
671-
(*pY_values) = &(pData->analysisOrderPerBand[0]);
671+
(*pY_values) = (int*)&(pData->analysisOrderPerBand[0]);
672672
(*pNpoints) = HYBRID_BANDS;
673673
}
674674

examples/src/powermap/powermap_internal.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ extern "C" {
6161
#if (POWERMAP_FRAME_SIZE % HOP_SIZE != 0)
6262
# error "POWERMAP_FRAME_SIZE must be an integer multiple of HOP_SIZE"
6363
#endif
64-
64+
65+
#ifndef __STDC_NO_ATOMICS__
66+
typedef _Atomic(POWERMAP_MODES) _Atomic_POWERMAP_MODES;
67+
#else
68+
typedef POWERMAP_MODES _Atomic_POWERMAP_MODES;
69+
#endif
70+
6571
/* ========================================================================== */
6672
/* Structures */
6773
/* ========================================================================== */
@@ -100,38 +106,38 @@ typedef struct _powermap
100106
/* internal */
101107
int isFirstInit; /**< Flag */
102108
float_complex Cx[HYBRID_BANDS][MAX_NUM_SH_SIGNALS*MAX_NUM_SH_SIGNALS]; /**< covariance matrices per band */
103-
int new_masterOrder; /**< New maximum/master SH analysis order (current value will be replaced by this after next re-init) */
104-
int dispWidth; /**< Number of pixels on the horizontal in the 2D interpolated powermap image */
109+
_Atomic_INT32 new_masterOrder; /**< New maximum/master SH analysis order (current value will be replaced by this after next re-init) */
110+
_Atomic_INT32 dispWidth; /**< Number of pixels on the horizontal in the 2D interpolated powermap image */
105111

106112
/* ana configuration */
107-
CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
108-
PROC_STATUS procStatus; /**< see #PROC_STATUS */
109-
float progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
110-
char* progressBarText; /**< Current (re)initialisation step, string */
111-
powermap_codecPars* pars; /**< codec parameters */
113+
_Atomic_CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
114+
_Atomic_PROC_STATUS procStatus; /**< see #PROC_STATUS */
115+
_Atomic_FLOAT32 progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
116+
char* progressBarText; /**< Current (re)initialisation step, string */
117+
powermap_codecPars* pars; /**< codec parameters */
112118

113119
/* display */
114120
float* pmap; /**< grid_nDirs x 1 */
115121
float* prev_pmap; /**< grid_nDirs x 1 */
116122
float* pmap_grid[NUM_DISP_SLOTS]; /**< powermap interpolated to grid; interp_nDirs x 1 */
117-
int dispSlotIdx; /**< Current display slot */
123+
_Atomic_INT32 dispSlotIdx; /**< Current display slot */
118124
float pmap_grid_minVal; /**< Current minimum value in pmap (used to normalise [0..1]) */
119125
float pmap_grid_maxVal; /**< Current maximum value in pmap (used to normalise [0..1]) */
120-
int recalcPmap; /**< set this to 1 to generate a new powermap */
121-
int pmapReady; /**< 0: powermap not started yet, 1: powermap is ready for plotting*/
126+
_Atomic_INT32 recalcPmap; /**< set this to 1 to generate a new powermap */
127+
_Atomic_INT32 pmapReady; /**< 0: powermap not started yet, 1: powermap is ready for plotting*/
122128

123129
/* User parameters */
124-
int masterOrder; /**< Current maximum/master SH analysis order */
125-
int analysisOrderPerBand[HYBRID_BANDS]; /**< SH analysis order per frequency band */
126-
float pmapEQ[HYBRID_BANDS]; /**< Equalisation/weights per band */
127-
HFOV_OPTIONS HFOVoption; /**< see #HFOV_OPTIONS */
128-
ASPECT_RATIO_OPTIONS aspectRatioOption; /**< see #ASPECT_RATIO_OPTIONS */
129-
float covAvgCoeff; /**< Covariance matrix averaging coefficient, [0..1] */
130-
float pmapAvgCoeff; /**< Powermap averaging coefficient, [0..1] */
131-
int nSources; /**< Current number of sources (used for MUSIC) */
132-
POWERMAP_MODES pmap_mode; /**< see #POWERMAP_MODES*/
133-
CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
134-
NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
130+
_Atomic_INT32 masterOrder; /**< Current maximum/master SH analysis order */
131+
_Atomic_INT32 analysisOrderPerBand[HYBRID_BANDS]; /**< SH analysis order per frequency band */
132+
_Atomic_FLOAT32 pmapEQ[HYBRID_BANDS]; /**< Equalisation/weights per band */
133+
_Atomic_HFOV_OPTIONS HFOVoption; /**< see #HFOV_OPTIONS */
134+
_Atomic_ASPECT_RATIO_OPTIONS aspectRatioOption; /**< see #ASPECT_RATIO_OPTIONS */
135+
_Atomic_FLOAT32 covAvgCoeff; /**< Covariance matrix averaging coefficient, [0..1] */
136+
_Atomic_FLOAT32 pmapAvgCoeff; /**< Powermap averaging coefficient, [0..1] */
137+
_Atomic_INT32 nSources; /**< Current number of sources (used for MUSIC) */
138+
_Atomic_POWERMAP_MODES pmap_mode; /**< see #POWERMAP_MODES*/
139+
_Atomic_CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
140+
_Atomic_NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
135141

136142
} powermap_data;
137143

examples/src/rotator/rotator.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void rotator_process
109109
{
110110
rotator_data *pData = (rotator_data*)(hRot);
111111
int i, j, order, nSH, mixWithPreviousFLAG;
112-
float Rxyz[3][3];
112+
float Rxyz[3][3], yaw_temp, pitch_temp, roll_temp;
113113
float M_rot_tmp[MAX_NUM_SH_SIGNALS*MAX_NUM_SH_SIGNALS];
114114
CH_ORDER chOrdering;
115115

@@ -145,7 +145,10 @@ void rotator_process
145145
else {/* M_ROT_RECOMPUTE_QUATERNION */
146146
quaternion2rotationMatrix(&(pData->Q), Rxyz);
147147
quaternion2euler(&(pData->Q), 0, pData->useRollPitchYawFlag ? EULER_ROTATION_ROLL_PITCH_YAW : EULER_ROTATION_YAW_PITCH_ROLL,
148-
&(pData->yaw), &(pData->pitch), &(pData->roll));
148+
&yaw_temp, &pitch_temp, &roll_temp);
149+
pData->yaw = yaw_temp;
150+
pData->pitch = pitch_temp;
151+
pData->roll = roll_temp;
149152
}
150153
getSHrotMtxReal(Rxyz, (float*)M_rot_tmp, order);
151154
for(i=0; i<nSH; i++)

examples/src/rotator/rotator_internal.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ typedef enum {
6565
M_ROT_RECOMPUTE_QUATERNION /**< Use Quaternions to recompute M_rot */
6666
} M_ROT_STATUS;
6767

68+
#ifndef __STDC_NO_ATOMICS__
69+
typedef _Atomic(M_ROT_STATUS) _Atomic_M_ROT_STATUS;
70+
#else
71+
typedef M_ROT_STATUS _Atomic_M_ROT_STATUS;
72+
#endif
73+
6874
/** Main struct for the rotator */
6975
typedef struct _rotator
7076
{
@@ -80,22 +86,22 @@ typedef struct _rotator
8086
float interpolator_fadeOut[ROTATOR_FRAME_SIZE]; /**< Linear Interpolator (fade-out) */
8187
float M_rot[MAX_NUM_SH_SIGNALS][MAX_NUM_SH_SIGNALS]; /**< Current SH rotation matrix [1] */
8288
float prev_M_rot[MAX_NUM_SH_SIGNALS][MAX_NUM_SH_SIGNALS]; /**< Previous SH rotation matrix [1] */
83-
M_ROT_STATUS M_rot_status; /**< see #M_ROT_STATUS */
84-
int fs; /**< Host sampling rate, in Hz */
89+
_Atomic_M_ROT_STATUS M_rot_status; /**< see #M_ROT_STATUS */
90+
int fs; /**< Host sampling rate, in Hz */
8591

8692
/* user parameters */
87-
quaternion_data Q; /**< Quaternion used for rotation */
88-
int bFlipQuaternion; /**< 1: invert quaternion, 0: no inversion */
89-
float yaw; /**< yaw (Euler) rotation angle, in degrees */
90-
float roll; /**< roll (Euler) rotation angle, in degrees */
91-
float pitch; /**< pitch (Euler) rotation angle, in degrees */
92-
int bFlipYaw; /**< flag to flip the sign of the yaw rotation angle */
93-
int bFlipPitch; /**< flag to flip the sign of the pitch rotation angle */
94-
int bFlipRoll; /**< flag to flip the sign of the roll rotation angle */
95-
int useRollPitchYawFlag; /**< rotation order flag, 1: r-p-y, 0: y-p-r */
96-
CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
97-
NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
98-
SH_ORDERS inputOrder; /**< current input/output SH order */
93+
quaternion_data Q; /**< Quaternion used for rotation */
94+
_Atomic_INT32 bFlipQuaternion; /**< 1: invert quaternion, 0: no inversion */
95+
_Atomic_FLOAT32 yaw; /**< yaw (Euler) rotation angle, in degrees */
96+
_Atomic_FLOAT32 roll; /**< roll (Euler) rotation angle, in degrees */
97+
_Atomic_FLOAT32 pitch; /**< pitch (Euler) rotation angle, in degrees */
98+
_Atomic_INT32 bFlipYaw; /**< flag to flip the sign of the yaw rotation angle */
99+
_Atomic_INT32 bFlipPitch; /**< flag to flip the sign of the pitch rotation angle */
100+
_Atomic_INT32 bFlipRoll; /**< flag to flip the sign of the roll rotation angle */
101+
_Atomic_INT32 useRollPitchYawFlag; /**< rotation order flag, 1: r-p-y, 0: y-p-r */
102+
_Atomic_CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
103+
_Atomic_NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
104+
_Atomic_SH_ORDERS inputOrder; /**< current input/output SH order */
99105

100106
} rotator_data;
101107

examples/src/sldoa/sldoa_internal.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ typedef struct _sldoa
9696
float fs; /**< Host sampling rate, in Hz */
9797

9898
/* ana configuration */
99-
CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
100-
PROC_STATUS procStatus; /**< see #PROC_STATUS */
101-
float progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
99+
_Atomic_CODEC_STATUS codecStatus; /**< see #CODEC_STATUS */
100+
_Atomic_PROC_STATUS procStatus; /**< see #PROC_STATUS */
101+
_Atomic_FLOAT32 progressBar0_1; /**< Current (re)initialisation progress, between [0..1] */
102102
char* progressBarText; /**< Current (re)initialisation step, string */
103103

104104
/* internal */
@@ -110,23 +110,23 @@ typedef struct _sldoa
110110
float doa_rad[HYBRID_BANDS][MAX_NUM_SECTORS][2]; /**< Current DoA estimates per band and sector, in radians */
111111
float energy [HYBRID_BANDS][MAX_NUM_SECTORS]; /**< Current Sector energies */
112112
int nSectorsPerBand[HYBRID_BANDS]; /**< Number of sectors per band */
113-
int new_masterOrder; /**< New master/maximum analysis order (current value will be replaced by this after next re-init) */
113+
_Atomic_INT32 new_masterOrder; /**< New master/maximum analysis order (current value will be replaced by this after next re-init) */
114114

115115
/* display */
116116
float* azi_deg[NUM_DISP_SLOTS]; /**< DoA azimuths, in degrees */
117117
float* elev_deg[NUM_DISP_SLOTS]; /**< DoA elevations, in degrees */
118118
float* colourScale[NUM_DISP_SLOTS]; /**< Values dictating each DoA marker colour */
119119
float* alphaScale[NUM_DISP_SLOTS]; /**< Values dictating each DoA marker transparency */
120-
int current_disp_idx; /**< Current display slot */
120+
_Atomic_INT32 current_disp_idx; /**< Current display slot */
121121

122122
/* User parameters */
123-
int masterOrder; /**< Current master/maximum analysis order */
124-
int analysisOrderPerBand[HYBRID_BANDS]; /**< Analysis order MIN(anaPerBand, masterOrder) for each frequency band */
125-
float maxFreq; /**< Maximum display frequency, in Hz */
126-
float minFreq; /**< Minimum display frequency, in Hz */
127-
float avg_ms; /**< Temporal averaging, in ms */
128-
CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
129-
NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
123+
_Atomic_INT32 masterOrder; /**< Current master/maximum analysis order */
124+
int analysisOrderPerBand[HYBRID_BANDS]; /**< Analysis order MIN(anaPerBand, masterOrder) for each frequency band */
125+
_Atomic_FLOAT32 maxFreq; /**< Maximum display frequency, in Hz */
126+
_Atomic_FLOAT32 minFreq; /**< Minimum display frequency, in Hz */
127+
_Atomic_FLOAT32 avg_ms; /**< Temporal averaging, in ms */
128+
_Atomic_CH_ORDER chOrdering; /**< Ambisonic channel order convention (see #CH_ORDER) */
129+
_Atomic_NORM_TYPES norm; /**< Ambisonic normalisation convention (see #NORM_TYPES) */
130130

131131
} sldoa_data;
132132

examples/src/spreader/spreader.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,11 @@ void spreader_process
383383
procMode = pData->procMode;
384384
nSources = pData->nSources;
385385
Q = pData->Q;
386-
memcpy((float*)src_dirs_deg, pData->src_dirs_deg, nSources*2*sizeof(float));
387-
memcpy((float*)src_spread, pData->src_spread, nSources*sizeof(float));
386+
for(i=0; i<nSources; i++){
387+
src_dirs_deg[i][0] = pData->src_dirs_deg[i][0];
388+
src_dirs_deg[i][1] = pData->src_dirs_deg[i][1];
389+
src_spread[i] = pData->src_spread[i];
390+
}
388391

389392
/* apply binaural panner */
390393
if ((nSamples == SPREADER_FRAME_SIZE) && (pData->codecStatus==CODEC_STATUS_INITIALISED) ){
@@ -856,7 +859,7 @@ int spreader_getNDirs(void* const hSpr)
856859
float spreader_getIRAzi_deg(void* const hSpr, int index)
857860
{
858861
spreader_data *pData = (spreader_data*)(hSpr);
859-
if(pData->grid_dirs_deg!=NULL)
862+
if(pData->codecStatus == CODEC_STATUS_INITIALISED && pData->grid_dirs_deg!=NULL)
860863
return pData->grid_dirs_deg[index*2+0];
861864
else
862865
return 0.0f;
@@ -865,7 +868,7 @@ float spreader_getIRAzi_deg(void* const hSpr, int index)
865868
float spreader_getIRElev_deg(void* const hSpr, int index)
866869
{
867870
spreader_data *pData = (spreader_data*)(hSpr);
868-
if(pData->grid_dirs_deg!=NULL)
871+
if(pData->codecStatus == CODEC_STATUS_INITIALISED && pData->grid_dirs_deg!=NULL)
869872
return pData->grid_dirs_deg[index*2+1];
870873
else
871874
return 0.0f;

0 commit comments

Comments
 (0)