SAF
Loading...
Searching...
No Matches
array2sh.h

Spatially encodes spherical microphone array signals into spherical harmonic signals (aka: Ambisonic signals) utilising theoretical encoding filters.

Spatially encodes spherical microphone array signals into spherical harmonic signals (aka: Ambisonic signals) utilising theoretical encoding filters.

Files

array2sh.h (include), array2sh_internal.h, array2sh.c, array2sh_internal.c

Example Usage

int main(void) {
void* hA2sh;
int frameSize;
// Create and initialise an instance of array2sh
array2sh_create(&hA2sh);
array2sh_init(hA2sh, hostSamplingRate);
// Call any set functions, e.g.:
array2sh_setPreset(hA2sh, MICROPHONE_ARRAY_PRESET_EIGENMIKE32);
array2sh_setGain(hA2sh, 6.0f);
// The framesize of this example is fixed, and can be found with
frameSize = array2sh_getFrameSize();
// Processing frame-by-frame
...
// Load signals into inputSignalBuffer (numberOfInputs x frameSize)
array2sh_process(hA2sh, inputSignalBuffer, outputSignalBuffer,
numberOfInputs, numberOfOutputs, frameSize);
// Copy signals from outputSignalBuffer (numberOfOutputs x frameSize)
...
// Destroy this instance of array2sh
}
@ NORM_N3D
orthonormalised (N3D)
Definition _common.h:75
void array2sh_setNormType(void *const hA2sh, int newType)
Sets the Ambisonic normalisation convention to encode with, in order to match with the convention emp...
Definition array2sh.c:489
void array2sh_destroy(void **const phA2sh)
Destroys an instance of array2sh.
Definition array2sh.c:105
void array2sh_setGain(void *const hA2sh, float newGain)
Sets the amount of post gain to apply after the encoding, in DECIBELS.
Definition array2sh.c:507
void array2sh_create(void **const phA2sh)
Creates an instance of array2sh.
Definition array2sh.c:53
void array2sh_setPreset(void *const hA2sh, ARRAY2SH_MICROPHONE_ARRAY_PRESETS preset)
Sets a pre-defined microphone/hydrophone array preset (See ARRAY2SH_MICROPHONE_ARRAY_PRESETS enum)
Definition array2sh.c:327
void array2sh_init(void *const hA2sh, int samplerate)
Initialises an instance of array2sh with default settings.
Definition array2sh.c:149
void array2sh_process(void *const hA2sh, const float *const *inputs, float *const *outputs, int nInputs, int nOutputs, int nSamples)
Spatially encode microphone/hydrophone array signals into spherical harmonic signals.
Definition array2sh.c:186
int array2sh_getFrameSize(void)
Returns the processing framesize (i.e., number of samples processed with every _process() call )
Definition array2sh.c:516

Include Header

/*
* Copyright 2017-2018 Leo McCormack
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __ARRAY2SH_H_INCLUDED__
#define __ARRAY2SH_H_INCLUDED__
#include "_common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* ========================================================================== */
/* Presets + Constants */
/* ========================================================================== */
typedef enum {
MICROPHONE_ARRAY_PRESET_DEFAULT = 1,
MICROPHONE_ARRAY_PRESET_AALTO_HYDROPHONE,
MICROPHONE_ARRAY_PRESET_SENNHEISER_AMBEO,
MICROPHONE_ARRAY_PRESET_CORE_SOUND_TETRAMIC,
MICROPHONE_ARRAY_PRESET_ZOOM_H3VR_PRESET,
MICROPHONE_ARRAY_PRESET_SOUND_FIELD_SPS200,
MICROPHONE_ARRAY_PRESET_ZYLIA_1D,
MICROPHONE_ARRAY_PRESET_EIGENMIKE32,
MICROPHONE_ARRAY_PRESET_EIGENMIKE64,
MICROPHONE_ARRAY_PRESET_DTU_MIC
typedef enum {
#define ARRAY2SH_NUM_FILTER_TYPES ( 4 )
typedef enum {
#define ARRAY2SH_NUM_ARRAY_TYPES ( 2 )
typedef enum {
#define ARRAY2SH_NUM_WEIGHT_TYPES ( 6 )
typedef enum {
#define ARRAY2SH_MAX_NUM_SENSORS ( MAX_NUM_CHANNELS )
#define ARRAY2SH_MAX_GAIN_MIN_VALUE ( 0.0f )
#define ARRAY2SH_MAX_GAIN_MAX_VALUE ( 80.0f )
#define ARRAY2SH_POST_GAIN_MIN_VALUE ( -60.0f )
#define ARRAY2SH_POST_GAIN_MAX_VALUE ( 12.0f )
#define ARRAY2SH_SPEED_OF_SOUND_MIN_VALUE ( 200.0f )
#define ARRAY2SH_SPEED_OF_SOUND_MAX_VALUE ( 2000.0f )
#define ARRAY2SH_ARRAY_RADIUS_MIN_VALUE ( 1.0f )
#define ARRAY2SH_ARRAY_RADIUS_MAX_VALUE ( 400.0f )
#define ARRAY2SH_BAFFLE_RADIUS_MIN_VALUE ( 1.0f )
#define ARRAY2SH_BAFFLE_RADIUS_MAX_VALUE ( 400.0f )
/* ========================================================================== */
/* Main Functions */
/* ========================================================================== */
void array2sh_create(void** const phA2sh);
void array2sh_destroy(void** const phA2sh);
void array2sh_init(void* const hA2sh,
int samplerate);
void array2sh_evalEncoder(void* const hA2sh);
void array2sh_process(void* const hA2sh,
const float *const * inputs,
float* const* outputs,
int nInputs,
int nOutputs,
int nSamples);
/* ========================================================================== */
/* Set Functions */
/* ========================================================================== */
void array2sh_refreshSettings(void* const hA2sh);
void array2sh_setEncodingOrder(void* const hA2sh, int newOrder);
void array2sh_setRequestEncoderEvalFLAG(void* const hA2sh, int newState);
void array2sh_setEvalStatus(void* const hA2sh, ARRAY2SH_EVAL_STATUS evalStatus);
void array2sh_setDiffEQpastAliasing(void* const hA2sh, int newState);
void array2sh_setPreset(void* const hA2sh,
void array2sh_setSensorAzi_rad(void* const hA2sh, int index, float newAzi_rad);
void array2sh_setSensorElev_rad(void* const hA2sh, int index, float newElev_rad);
void array2sh_setSensorAzi_deg(void* const hA2sh, int index, float newAzi_deg);
void array2sh_setSensorElev_deg(void* const hA2sh, int index, float newElev_deg);
void array2sh_setNumSensors(void* const hA2sh, int newQ);
void array2sh_setr(void* const hA2sh, float newr);
void array2sh_setR(void* const hA2sh, float newR);
void array2sh_setArrayType(void* const hA2sh, int newType);
void array2sh_setWeightType(void* const hA2sh, int newType);
void array2sh_setFilterType(void* const hA2sh, int newType);
void array2sh_setRegPar(void* const hA2sh, float newVal);
void array2sh_setChOrder(void* const hA2sh, int newOrder);
void array2sh_setNormType(void* const hA2sh, int newType);
void array2sh_setc(void* const hA2sh, float newc);
void array2sh_setGain(void* const hA2sh, float newGain);
/* ========================================================================== */
/* Get Functions */
/* ========================================================================== */
int array2sh_getReinitSHTmatrixFLAG(void* const hA2sh);
float array2sh_getProgressBar0_1(void* const hA2sh);
void array2sh_getProgressBarText(void* const hA2sh, char* text);
int array2sh_getDiffEQpastAliasing(void* const hA2sh);
int array2sh_getRequestEncoderEvalFLAG(void* const hA2sh);
int array2sh_getEncodingOrder(void* const hA2sh);
float array2sh_getSensorAzi_rad(void* const hA2sh, int index);
float array2sh_getSensorElev_rad(void* const hA2sh, int index);
float array2sh_getSensorAzi_deg(void* const hA2sh, int index);
float array2sh_getSensorElev_deg(void* const hA2sh, int index);
int array2sh_getNumSensors(void* const hA2sh);
int array2sh_getMinNumSensors(void* const hA2sh);
int array2sh_getNSHrequired(void* const hA2sh);
float array2sh_getr(void* const hA2sh);
float array2sh_getR(void* const hA2sh);
int array2sh_getArrayType(void* const hA2sh);
int array2sh_getWeightType(void* const hA2sh);
int array2sh_getFilterType(void* const hA2sh);
float array2sh_getRegPar(void* const hA2sh);
int array2sh_getChOrder(void* const hA2sh);
int array2sh_getNormType(void* const hA2sh);
float array2sh_getc(void* const hA2sh);
float array2sh_getGain(void* const hA2sh);
float* array2sh_getFreqVector(void* const hA2sh, int* nFreqPoints);
float** array2sh_getbN_inv(void* const hA2sh, int* nCurves, int* nFreqPoints);
float** array2sh_getbN_modal(void* const hA2sh, int* nCurves, int* nFreqPoints);
float* array2sh_getSpatialCorrelation_Handle(void* const hA2sh,
int* nCurves,
int* nFreqPoints);
float* array2sh_getLevelDifference_Handle(void* const hA2sh, int* nCurves, int* nFreqPoints);
int array2sh_getSamplingRate(void* const hA2sh);
#ifdef __cplusplus
} /* extern "C" { */
#endif /* __cplusplus */
#endif /* __ARRAY2SH_H_INCLUDED__ */
A bunch of things that are common to many of the saf examples.
float array2sh_getR(void *const hA2sh)
Returns the radius of the scatterer, in meters.
Definition array2sh.c:623
float * array2sh_getSpatialCorrelation_Handle(void *const hA2sh, int *nCurves, int *nFreqPoints)
Returns a pointer to the spatial correlation [1] data.
Definition array2sh.c:703
float array2sh_getSensorElev_deg(void *const hA2sh, int index)
Returns a particular sensor's elevation w.r.t to the origin of the array, in DEGREES.
Definition array2sh.c:584
float array2sh_getr(void *const hA2sh)
Returns the radius of the array, in meters.
Definition array2sh.c:616
ARRAY2SH_MICROPHONE_ARRAY_PRESETS
Available microphone array presets.
Definition array2sh.h:105
void array2sh_setNumSensors(void *const hA2sh, int newQ)
Sets the number of sensors in the array.
Definition array2sh.c:391
float ** array2sh_getbN_inv(void *const hA2sh, int *nCurves, int *nFreqPoints)
Returns the regularised inversion of the modal coefficients per frequency (may be used for optional p...
Definition array2sh.c:687
void array2sh_setSensorElev_rad(void *const hA2sh, int index, float newElev_rad)
Sets a particular sensor's elevation (radians) w.r.t to the origin of the array.
Definition array2sh.c:351
void array2sh_setR(void *const hA2sh, float newR)
Sets the radius (in meters) of the scatterer (only for Rigid arrays).
Definition array2sh.c:423
void array2sh_setEvalStatus(void *const hA2sh, ARRAY2SH_EVAL_STATUS evalStatus)
Sets current eval status (see ARRAY2SH_EVAL_STATUS enum)
Definition array2sh.c:306
float array2sh_getSensorAzi_deg(void *const hA2sh, int index)
Returns a particular sensor's azimuth w.r.t to the origin of the array, in DEGREES.
Definition array2sh.c:577
float * array2sh_getFreqVector(void *const hA2sh, int *nFreqPoints)
Returns a pointer to the frequency vector.
Definition array2sh.c:680
ARRAY2SH_FILTER_TYPES
Available encoding filter approaches.
Definition array2sh.h:134
@ FILTER_Z_STYLE
Encoding filters based on a linear-phase filter- bank approach [3].
Definition array2sh.h:140
@ FILTER_SOFT_LIM
Encoding filters based on a 'soft-limiting' regularised inversion of the modal responses [1].
Definition array2sh.h:135
@ FILTER_Z_STYLE_MAXRE
Same as FILTER_Z_STYLE, only it also has max_rE weights baked in.
Definition array2sh.h:142
@ FILTER_TIKHONOV
Encoding filters based on a 'Tikhonov' regularised inversion of the modal responses [2].
Definition array2sh.h:138
void array2sh_setRegPar(void *const hA2sh, float newVal)
Sets the value of the regularisation parameter (the maximum permitted gain of the filters),...
Definition array2sh.c:471
int array2sh_getRequestEncoderEvalFLAG(void *const hA2sh)
Returns a flag, which is '1' if there has been a recent request to evaluate the current encoding perf...
Definition array2sh.c:545
int array2sh_getMaxNumSensors(void)
Returns the maximum supported number of sensors which can be in the array.
Definition array2sh.c:599
void array2sh_setArrayType(void *const hA2sh, int newType)
Sets the type of array (see ARRAY2SH_ARRAY_TYPES enum)
Definition array2sh.c:436
int array2sh_getEncodingOrder(void *const hA2sh)
Returns the current encoding order (see SH_ORDERS enum)
Definition array2sh.c:557
float array2sh_getProgressBar0_1(void *const hA2sh)
(Optional) Returns current intialisation/processing progress, between 0..1
Definition array2sh.c:533
void array2sh_refreshSettings(void *const hA2sh)
Sets all intialisation flags to 1; re-initialising all settings/variables as array2sh is currently co...
Definition array2sh.c:277
void array2sh_setEncodingOrder(void *const hA2sh, int newOrder)
Sets the encoding order (see SH_ORDERS enum)
Definition array2sh.c:284
void array2sh_setFilterType(void *const hA2sh, int newType)
Sets the type filter design to employ for computing the encoding matrices (see ARRAY2SH_FILTER_TYPES ...
Definition array2sh.c:460
int array2sh_getSamplingRate(void *const hA2sh)
Returns the DAW/Host sample rate.
Definition array2sh.c:719
void array2sh_setSensorElev_deg(void *const hA2sh, int index, float newElev_deg)
Sets a particular sensor's elevation (degrees) w.r.t to the origin of the array.
Definition array2sh.c:378
float array2sh_getRegPar(void *const hA2sh)
Returns the value of the regurlisation parameter; the maximum permitted gain provided by the filters,...
Definition array2sh.c:650
float * array2sh_getLevelDifference_Handle(void *const hA2sh, int *nCurves, int *nFreqPoints)
Returns a pointer to the level-difference [1] data.
Definition array2sh.c:711
int array2sh_getArrayType(void *const hA2sh)
Returns the type of array.
Definition array2sh.c:630
int array2sh_getNormType(void *const hA2sh)
Returns the Ambisonic normalisation convention currently being usedto decode with,...
Definition array2sh.c:662
int array2sh_getDiffEQpastAliasing(void *const hA2sh)
Flag to enabled/disable diffuse equalisation above the spatial aliasing limit of the array (0: disabl...
Definition array2sh.c:551
float ** array2sh_getbN_modal(void *const hA2sh, int *nCurves, int *nFreqPoints)
Returns the direct inversion of the modal coefficients per frequency (may be used for optional plotti...
Definition array2sh.c:695
ARRAY2SH_WEIGHT_TYPES
List of supported sensor directivities and array construction types.
Definition array2sh.h:166
@ WEIGHT_RIGID_OMNI
Rigid baffle construction with omni sensors.
Definition array2sh.h:167
@ WEIGHT_OPEN_OMNI
Open array construction with omni sensors.
Definition array2sh.h:171
@ WEIGHT_OPEN_DIPOLE
Open array construction with dipole sensors.
Definition array2sh.h:173
@ WEIGHT_RIGID_CARD
Rigid baffle construction with cardioid sensors.
Definition array2sh.h:168
@ WEIGHT_RIGID_DIPOLE
Rigid baffle construction with dipole sensors.
Definition array2sh.h:170
@ WEIGHT_OPEN_CARD
Open array construction with cardioid sensors.
Definition array2sh.h:172
int array2sh_getMinNumSensors(void *const hA2sh)
Returns the minimum number of sensors which can be in the array [(current_order+1)^2].
Definition array2sh.c:604
float array2sh_getc(void *const hA2sh)
Returns the speed of sound of the medium (~343m/s air, ~1480m/s water), in m/s.
Definition array2sh.c:668
void array2sh_getProgressBarText(void *const hA2sh, char *text)
(Optional) Returns current intialisation/processing progress text
Definition array2sh.c:539
void array2sh_setc(void *const hA2sh, float newc)
Sets the speed of sound of the medium (~343m/s air, ~1480m/s water), in m/s.
Definition array2sh.c:496
void array2sh_evalEncoder(void *const hA2sh)
Evaluates the encoder, based on current global/user parameters.
Definition array2sh.c:162
void array2sh_setr(void *const hA2sh, float newr)
Sets the radius of the array.
Definition array2sh.c:410
void array2sh_setSensorAzi_rad(void *const hA2sh, int index, float newAzi_rad)
Sets a particular sensor's azimuth (radians) w.r.t to the origin of the array.
Definition array2sh.c:338
void array2sh_setSensorAzi_deg(void *const hA2sh, int index, float newAzi_deg)
Sets a particular sensor's azimuth (degrees) w.r.t to the origin of the array.
Definition array2sh.c:364
int array2sh_getNSHrequired(void *const hA2sh)
Returns the number of spherical harmonic signals required by the current encoding order: (current_ord...
Definition array2sh.c:610
void array2sh_setWeightType(void *const hA2sh, int newType)
Sets the type of weights to use (see ARRAY2SH_WEIGHT_TYPES enum)
Definition array2sh.c:448
void array2sh_setDiffEQpastAliasing(void *const hA2sh, int newState)
Analyses what the theoretical spatial aliasing frequency is, and conducts diffuse-field equalisation ...
Definition array2sh.c:317
float array2sh_getGain(void *const hA2sh)
Returns the amount of post gain to apply after the encoding, in DECIBELS.
Definition array2sh.c:674
void array2sh_setChOrder(void *const hA2sh, int newOrder)
Sets the Ambisonic channel ordering convention to encode with, in order to match the convention emplo...
Definition array2sh.c:482
float array2sh_getSensorAzi_rad(void *const hA2sh, int index)
Returns a particular sensor's azimuth w.r.t to the origin of the array, in RADIANS.
Definition array2sh.c:563
float array2sh_getSensorElev_rad(void *const hA2sh, int index)
Returns a particular sensor's elevation w.r.t to the origin of the array, in RADIANS.
Definition array2sh.c:570
ARRAY2SH_ARRAY_TYPES
List of supported array types.
Definition array2sh.h:156
@ ARRAY_CYLINDRICAL
Cylindrial arrangement of sensors (open/rigid)
Definition array2sh.h:158
@ ARRAY_SPHERICAL
Spherical arrangement of sensors (open/rigid)
Definition array2sh.h:157
int array2sh_getChOrder(void *const hA2sh)
Returns the Ambisonic channel ordering convention currently being used to decode with,...
Definition array2sh.c:656
int array2sh_getFilterType(void *const hA2sh)
Returns the type filter design to employ for computing the encoding matrices (see ARRAY2SH_FILTER_TYP...
Definition array2sh.c:644
int array2sh_getWeightType(void *const hA2sh)
Returns the type of weights to use see ARRAY2SH_WEIGHT_TYPES enum.
Definition array2sh.c:637
int array2sh_getReinitSHTmatrixFLAG(void *const hA2sh)
Returns 0 if SHT is not be reinitialised, 1: if it is.
Definition array2sh.c:527
int array2sh_getProcessingDelay(void)
Returns the processing delay in samples (may be used for delay compensation features)
Definition array2sh.c:725
int array2sh_getNumSensors(void *const hA2sh)
Returns the number of sensors in the array.
Definition array2sh.c:591
void array2sh_setRequestEncoderEvalFLAG(void *const hA2sh, int newState)
Evaluates the performance of the current encoding filters when applied to a theoretical model of the ...
Definition array2sh.c:300
ARRAY2SH_EVAL_STATUS array2sh_getEvalStatus(void *const hA2sh)
Returns current eval status (see ARRAY2SH_EVAL_STATUS enum)
Definition array2sh.c:521
ARRAY2SH_EVAL_STATUS
Current status of the encoder evaluation output data.
Definition array2sh.h:186
@ EVAL_STATUS_RECENTLY_EVALUATED
Encoder has recently been evaluated.
Definition array2sh.h:188
@ EVAL_STATUS_EVALUATING
Encoder is being evaluated.
Definition array2sh.h:190
@ EVAL_STATUS_EVALUATED
Encoder has been evaluated.
Definition array2sh.h:187
@ EVAL_STATUS_NOT_EVALUATED
Encoder has not been evaluated.
Definition array2sh.h:189