35 *phAmbi = (
void*)pData;
77 pData->
fs = (float)sampleRate;
91 const float *
const * inputs,
92 float*
const*
const outputs,
99 int i, j, ch, nSources, nSH, mixWithPreviousFLAG;
117 for(i=0; i <
SAF_MIN(nSources,nInputs); i++)
123 mixWithPreviousFLAG = 0;
124 for(ch=0; ch<nSources; ch++){
128 pData->
Y[j][ch] = Y_src[j];
130 pData->
Y[j][ch] = 0.0f;
134 mixWithPreviousFLAG = 1;
137 if(fabsf(pData->
src_gains[ch] - 1.f) > 1e-6f)
142 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, nSH,
AMBI_ENC_FRAME_SIZE, nSources, 1.0f,
148 if(mixWithPreviousFLAG){
149 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, nSH,
AMBI_ENC_FRAME_SIZE, nSources, 1.0f,
155 for (i=0; i < nSH; i++){
171 scale = 1.0f/sqrtf((
float)nSources);
189 for(i = 0; i <
SAF_MIN(nSH,nOutputs); i++)
191 for(; i < nOutputs; i++)
195 for (ch=0; ch < nOutputs; ch++)
234 if(newAzi_deg>180.0f)
235 newAzi_deg = -360.0f + newAzi_deg;
236 newAzi_deg =
SAF_MAX(newAzi_deg, -180.0f);
237 newAzi_deg =
SAF_MIN(newAzi_deg, 180.0f);
245 newElev_deg =
SAF_MAX(newElev_deg, -90.0f);
246 newElev_deg =
SAF_MIN(newElev_deg, 90.0f);
312 for(
int i=0; i<pData->
nSources; i++)
321 return (
int)pData->
order;
362 return (
int)pData->
norm;
#define MAX_SH_ORDER
Maximum supported Ambisonic order.
#define MAX_NUM_INPUTS
Maximum number of input channels supported.
NORM_TYPES
Available Ambisonic normalisation conventions.
@ NORM_SN3D
Schmidt semi-normalisation (SN3D)
@ NORM_FUMA
(Legacy) Furse-Malham scaling
@ NORM_N3D
orthonormalised (N3D)
CH_ORDER
Available Ambisonic channel ordering conventions.
@ CH_ACN
Ambisonic Channel Numbering (ACN)
@ CH_FUMA
(Legacy) Furse-Malham/B-format (WXYZ)
#define MAX_NUM_SH_SIGNALS
Maximum number of spherical harmonic components/signals supported.
SH_ORDERS
Available spherical harmonic (SH) input/output order options.
@ SH_ORDER_FIRST
First-order (4 channels)
void ambi_enc_setEnablePostScaling(void *const hAmbi, int newStatus)
By default, ambi_enc will scale the output signals by the number of input signals.
int ambi_enc_getFrameSize(void)
Returns the processing framesize (i.e., number of samples processed with every _process() call )
void ambi_enc_refreshParams(void *const hAmbi)
Sets all intialisation flags to 1; re-initialising all settings/variables as ambi_enc is currently co...
int ambi_enc_getEnablePostScaling(void *const hAmbi)
Returns 0: if post scaling is disabled, 1: if post scaling is enabled.
void ambi_enc_setSourceGain(void *const hAmbi, int srcIdx, float newGain)
Sets gain factor for an input source.
void ambi_enc_setSourceElev_deg(void *const hAmbi, int index, float newElev_deg)
Sets the elevation for a specific source index.
void ambi_enc_setNormType(void *const hAmbi, int newType)
Sets the Ambisonic normalisation convention to encode with (see NORM_TYPES enum)
void ambi_enc_setSourceSolo(void *const hAmbi, int srcIdx)
Set a source to solo.
int ambi_enc_getMaxNumSources()
Returns the maximum number of input signals/sources that can be encoded.
int ambi_enc_getChOrder(void *const hAmbi)
Returns the Ambisonic channel ordering convention currently being used to encode with (see CH_ORDER e...
int ambi_enc_getProcessingDelay()
Returns the processing delay in samples (may be used for delay compensation features)
void ambi_enc_setUnSolo(void *const hAmbi)
Unsolo / unmute all sources.
void ambi_enc_setNumSources(void *const hAmbi, int new_nSources)
Sets the number of input signals/sources to encode.
void ambi_enc_setInputConfigPreset(void *const hAmbi, int newPresetID)
Sets the input configuration preset (see SOURCE_CONFIG_PRESETS enum)
void ambi_enc_setSourceAzi_deg(void *const hAmbi, int index, float newAzi_deg)
Sets the azimuth for a specific source index.
int ambi_enc_getNormType(void *const hAmbi)
Returns the Ambisonic normalisation convention currently being used to encode with (see NORM_TYPES en...
void ambi_enc_destroy(void **const phAmbi)
Destroys an instance of ambi_enc.
void ambi_enc_create(void **const phAmbi)
Creates an instance of ambi_enc.
void ambi_enc_setOutputOrder(void *const hAmbi, int newOrder)
Sets the encoding order (see SH_ORDERS enum)
void ambi_enc_process(void *const hAmbi, const float *const *inputs, float *const *const outputs, int nInputs, int nOutputs, int nSamples)
Encodes input signals into spherical harmonic signals, at the specified encoding directions.
int ambi_enc_getNSHrequired(void *const hAmbi)
Returns the number of spherical harmonic signals required by the current decoding order: (current_ord...
float ambi_enc_getSourceElev_deg(void *const hAmbi, int index)
Returns the elevation for a specific source, in DEGREES.
float ambi_enc_getSourceAzi_deg(void *const hAmbi, int index)
Returns the azimuth for a specific source, in DEGREES.
void ambi_enc_setChOrder(void *const hAmbi, int newOrder)
Sets the Ambisonic channel ordering convention to encode with (see CH_ORDER enum)
int ambi_enc_getNumSources(void *const hAmbi)
Returns the number of input signals/sources to encode.
int ambi_enc_getOutputOrder(void *const hAmbi)
Returns the decoding order (see SH_ORDERS enum)
void ambi_enc_init(void *const hAmbi, int sampleRate)
Initialises an instance of ambi_enc with default settings.
A basic Ambisonic encoder.
void loadSourceConfigPreset(SOURCE_CONFIG_PRESETS preset, float dirs_deg[MAX_NUM_INPUTS][2], int *newNCH)
Returns the source directions for a specified source config preset.
A basic Ambisonic encoder.
#define AMBI_ENC_FRAME_SIZE
Framesize, in time-domain samples.
void convertHOAChannelConvention(float *insig, int order, int signalLength, HOA_CH_ORDER inConvention, HOA_CH_ORDER outConvention)
Converts an Ambisonic signal from one channel ordering convention to another.
void convertHOANormConvention(float *insig, int order, int signalLength, HOA_NORM inConvention, HOA_NORM outConvention)
Converts an Ambisonic signal from one normalisation convention to another.
void getRSH_recur(int N, float *dirs_deg, int nDirs, float *Y)
Computes real-valued spherical harmonics [1] for each given direction on the unit sphere.
@ HOA_CH_ORDER_FUMA
Furse-Malham (FuMa) convention, often used by older recordings.
@ HOA_CH_ORDER_ACN
Ambisonic Channel numbering (ACN) convention, which is employed by all spherical harmonic related fun...
@ HOA_NORM_FUMA
Furse-Malham (FuMa) convention.
@ HOA_NORM_SN3D
Schmidt semi-normalisation (SN3D) convention, as used by the AmbiX standard.
@ HOA_NORM_N3D
Orthonormalised (N3D) convention, which is the default convention used by SAF.
#define ORDER2NSH(order)
Converts spherical harmonic order to number of spherical harmonic components i.e: (order+1)^2.
#define SAF_CLAMP(a, min, max)
Ensures value "a" is clamped between the "min" and "max" values.
void utility_svvmul(const float *a, const float *b, const int len, float *c)
Single-precision, element-wise vector-vector multiplication i.e.
#define SAF_MAX(a, b)
Returns the maximum of the two values.
void utility_svvcopy(const float *a, const int len, float *c)
Single-precision, vector-vector copy, i.e.
#define SAF_MIN(a, b)
Returns the minimum of the two values.
void utility_svsmul(float *a, const float *s, const int len, float *c)
Single-precision, multiplies each element in vector 'a' with a scalar 's', i.e.
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
Main structure for ambi_enc.
float tempFrame[MAX_NUM_SH_SIGNALS][AMBI_ENC_FRAME_SIZE]
Temporary frame.
float Y[MAX_NUM_SH_SIGNALS][MAX_NUM_INPUTS]
SH weights.
int enablePostScaling
Flag 1: output signals scaled by 1/sqrt(nSources), 0: disabled.
int new_nSources
New number of input signals (current value will be replaced by this after next re-init)
float interpolator_fadeIn[AMBI_ENC_FRAME_SIZE]
Linear Interpolator (fade-in)
float inputFrameTD[MAX_NUM_INPUTS][AMBI_ENC_FRAME_SIZE]
Input frame of signals.
CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)
float tempFrame_fadeOut[MAX_NUM_SH_SIGNALS][AMBI_ENC_FRAME_SIZE]
Temporary frame with linear interpolation (fade-out) applied.
float outputFrameTD[MAX_NUM_SH_SIGNALS][AMBI_ENC_FRAME_SIZE]
Output frame of SH signals.
float prev_Y[MAX_NUM_SH_SIGNALS][MAX_NUM_INPUTS]
Previous SH weights.
int nSources
Current number of input signals.
float prev_inputFrameTD[MAX_NUM_INPUTS][AMBI_ENC_FRAME_SIZE]
Previous frame of signals.
NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
float src_gains[MAX_NUM_INPUTS]
Gains applied per source.
float fs
Host sampling rate.
SH_ORDERS order
Current SH encoding order.
int recalc_SH_FLAG[MAX_NUM_INPUTS]
Flags, 1: recalc SH weights, 0: do not.
float outputFrameTD_fadeIn[MAX_NUM_SH_SIGNALS][AMBI_ENC_FRAME_SIZE]
Output frame of SH signals with linear interpolation (fade-in) applied.
float src_dirs_deg[MAX_NUM_INPUTS][2]
Source directions, in degrees.
float interpolator_fadeOut[AMBI_ENC_FRAME_SIZE]
Linear Interpolator (fade-out)