SAF
Loading...
Searching...
No Matches
ambi_bin.h

A binaural Ambisonic decoder for reproducing Ambisonic sound scenes over headphones.

A binaural Ambisonic decoder for reproducing Ambisonic sound scenes over headphones

Files

ambi_bin.h (include), ambi_bin_internal.h, ambi_bin.c, ambi_bin_internal.c

Example Usage

int main(void) {
void* hAmbi;
int frameSize;
// Create an instance of ambi_bin
ambi_bin_create(&hAmbi);
// Call any set functions, e.g.:
ambi_bin_setYaw(hAmbi, 180.0f); // turn the listener around
// Note that many set functions, for example ambi_bin_setYaw(), will
// update their value immediately. Whereas, others, for example
// ambi_bin_setInputOrderPreset(), which could cause clicks/hangs with
// the main processing loop, will only trigger a flag that indicates that
// a re-initisation is required. Therefore, ambi_bin_initCodec() should
// be called after calling these particular set functions in order to
// update the run-time settings accordingly.
//
// This function is fully thread-safe, and actually calling this on a
// separate thread is actively encouraged, in order to avoid the
// aforementioned run-time clicks/hangs. ambi_bin_process() is muted
// if the initialisations are still on-going, and initialisations are
// paused until the current ambi_bin_process() call has completed.
// ambi_bin_init() should be called once before calling
// ambi_bin_process() in order to inform the example of the host sample
// rate and flush run-time buffers with zeros. It is not safe to call
// this during ambi_bin_process()!
ambi_bin_init(hAmbi, hostSamplingRate);
// The framesize of this example is fixed, and can be found with
frameSize = ambi_bin_getFrameSize();
// Processing frame-by-frame
...
// Load signals into inputSignalBuffer (numberOfInputs x frameSize)
ambi_bin_process(hAmbi, inputSignalBuffer, outputSignalBuffer,
numberOfInputs, numberOfOutputs, frameSize);
// Copy signals from outputSignalBuffer (numberOfOutputs x frameSize)
...
// Destroy this instance of ambi_bin
}
@ NORM_N3D
orthonormalised (N3D)
Definition _common.h:75
@ SH_ORDER_FIRST
First-order (4 channels)
Definition _common.h:39
void ambi_bin_setInputOrderPreset(void *const hAmbi, SH_ORDERS newPreset)
Sets the decoding order (see SH_ORDERS enum)
Definition ambi_bin.c:534
void ambi_bin_create(void **const phAmbi)
Creates an instance of ambi_bin.
Definition ambi_bin.c:51
void ambi_bin_initCodec(void *const hAmbi)
Intialises the codec variables, based on current global/user parameters.
Definition ambi_bin.c:169
void ambi_bin_process(void *const hAmbi, const float *const *inputs, float *const *const outputs, int nInputs, int nOutputs, int nSamples)
Decodes input spherical harmonic signals to the binaural channels.
Definition ambi_bin.c:403
void ambi_bin_setNormType(void *const hAmbi, int newType)
Sets the Ambisonic normalisation convention to decode with, in order to match with the convention emp...
Definition ambi_bin.c:562
void ambi_bin_setEnableRotation(void *const hAmbi, int newState)
Sets the flag to enable/disable (1 or 0) sound-field rotation.
Definition ambi_bin.c:605
void ambi_bin_setYaw(void *const hAmbi, float newYaw_deg)
Sets the 'yaw' rotation angle, in degrees.
Definition ambi_bin.c:611
int ambi_bin_getFrameSize(void)
Returns the processing framesize (i.e., number of samples processed with every _process() call )
Definition ambi_bin.c:668
void ambi_bin_destroy(void **const phAmbi)
Destroys an instance of ambi_bin.
Definition ambi_bin.c:111
void ambi_bin_init(void *const hAmbi, int samplerate)
Initialises ambi_bin with default settings, and samplerate.
Definition ambi_bin.c:149
#define SAF_TRUE
Boolean true.

Include Header

/*
* Copyright 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 __AMBI_BIN_H_INCLUDED__
#define __AMBI_BIN_H_INCLUDED__
#include "_common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* ========================================================================== */
/* Presets + Constants */
/* ========================================================================== */
typedef enum {
#define AMBI_BIN_NUM_DECODING_METHODS ( 5 )
typedef enum {
#define AMBI_BIN_NUM_HRIR_PREPROC_OPTIONS ( 4 )
/* ========================================================================== */
/* Main Functions */
/* ========================================================================== */
void ambi_bin_create(void** const phAmbi);
void ambi_bin_destroy(void** const phAmbi);
void ambi_bin_init(void* const hAmbi,
int samplerate);
void ambi_bin_initCodec(void* const hAmbi);
void ambi_bin_process(void* const hAmbi,
const float *const * inputs,
float* const* const outputs,
int nInputs,
int nOutputs,
int nSamples);
/* ========================================================================== */
/* Set Functions */
/* ========================================================================== */
void ambi_bin_refreshParams(void* const hAmbi);
void ambi_bin_setUseDefaultHRIRsflag(void* const hAmbi, int newState);
void ambi_bin_setSofaFilePath(void* const hAmbi, const char* path);
void ambi_bin_setInputOrderPreset(void* const hAmbi,
SH_ORDERS newPreset);
void ambi_bin_setDecodingMethod(void* const hAmbi,
void ambi_bin_setChOrder(void* const hAmbi, int newOrder);
void ambi_bin_setNormType(void* const hAmbi, int newType);
void ambi_bin_setEnableMaxRE(void* const hAmbi, int newState);
void ambi_bin_setEnableDiffuseMatching(void* const hAmbi, int newState);
void ambi_bin_setEnableTruncationEQ(void* const hAmbi, int newState);
void ambi_bin_setHRIRsPreProc(void* const hAmbi, AMBI_BIN_PREPROC newType);
void ambi_bin_setEnableRotation(void* const hAmbi, int newState);
void ambi_bin_setYaw(void* const hAmbi, float newYaw_deg);
void ambi_bin_setPitch(void* const hAmbi, float newPitch);
void ambi_bin_setRoll(void* const hAmbi, float newRoll);
void ambi_bin_setFlipYaw(void* const hAmbi, int newState);
void ambi_bin_setFlipPitch(void* const hAmbi, int newState);
void ambi_bin_setFlipRoll(void* const hAmbi, int newState);
void ambi_bin_setRPYflag(void* const hAmbi, int newState);
/* ========================================================================== */
/* Get Functions */
/* ========================================================================== */
float ambi_bin_getProgressBar0_1(void* const hAmbi);
void ambi_bin_getProgressBarText(void* const hAmbi, char* text);
int ambi_bin_getUseDefaultHRIRsflag(void* const hAmbi);
int ambi_bin_getInputOrderPreset(void* const hAmbi);
char* ambi_bin_getSofaFilePath(void* const hAmbi);
int ambi_bin_getChOrder(void* const hAmbi);
int ambi_bin_getNormType(void* const hAmbi);
int ambi_bin_getNSHrequired(void* const hAmbi);
int ambi_bin_getEnableMaxRE(void* const hAmbi);
int ambi_bin_getEnableDiffuseMatching(void* const hAmbi);
int ambi_bin_getEnableTruncationEQ(void* const hAmbi);
int ambi_bin_getEnableRotation(void* const hAmbi);
float ambi_bin_getYaw(void* const hAmbi);
float ambi_bin_getPitch(void* const hAmbi);
float ambi_bin_getRoll(void* const hAmbi);
int ambi_bin_getFlipYaw(void* const hAmbi);
int ambi_bin_getFlipPitch(void* const hAmbi);
int ambi_bin_getFlipRoll(void* const hAmbi);
int ambi_bin_getRPYflag(void* const hAmbi);
int ambi_bin_getNDirs(void* const hAmbi);
int ambi_bin_getHRIRlength(void* const hAmbi);
int ambi_bin_getHRIRsamplerate(void* const hAmbi);
int ambi_bin_getDAWsamplerate(void* const hAmbi);
#ifdef __cplusplus
} /* extern "C" { */
#endif /* __cplusplus */
#endif /* __AMBI_BIN_H_INCLUDED__ */
A bunch of things that are common to many of the saf examples.
SH_ORDERS
Available spherical harmonic (SH) input/output order options.
Definition _common.h:38
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
void ambi_bin_setChOrder(void *const hAmbi, int newOrder)
Sets the Ambisonic channel ordering convention to decode with, in order to match the convention emplo...
Definition ambi_bin.c:555
int ambi_bin_getNSHrequired(void *const hAmbi)
Returns the number of spherical harmonic signals required by the current decoding order: (current_ord...
Definition ambi_bin.c:760
int ambi_bin_getEnableMaxRE(void *const hAmbi)
Returns the flag value which dictates whether to enable/disable maxrE weighting ('0' disabled,...
Definition ambi_bin.c:737
int ambi_bin_getHRIRsamplerate(void *const hAmbi)
Returns the HRIR sample rate.
Definition ambi_bin.c:828
int ambi_bin_getNormType(void *const hAmbi)
Returns the Ambisonic normalisation convention currently being usedto decode with,...
Definition ambi_bin.c:731
void ambi_bin_setFlipRoll(void *const hAmbi, int newState)
Sets a flag as to whether to "flip" the sign of the current 'roll' angle.
Definition ambi_bin.c:650
void ambi_bin_setPitch(void *const hAmbi, float newPitch)
Sets the 'pitch' rotation angle, in degrees.
Definition ambi_bin.c:618
int ambi_bin_getProcessingDelay(void)
Returns the processing delay in samples (may be used for delay compensation features)
Definition ambi_bin.c:841
int ambi_bin_getEnableTruncationEQ(void *const hAmbi)
Returns the flag value which dictates whether the truncation EQ is currently enabled ('0' disabled,...
Definition ambi_bin.c:749
int ambi_bin_getEnableDiffuseMatching(void *const hAmbi)
Returns the flag value which dictates whether the diffuse covariance contraint is currently enabled (...
Definition ambi_bin.c:743
AMBI_BIN_PREPROC ambi_bin_getHRIRsPreProc(void *const hAmbi)
Returns HRIR pre-processing strategy.
Definition ambi_bin.c:697
AMBI_BIN_DECODING_METHODS ambi_bin_getDecodingMethod(void *const hAmbi)
Returns the currently selected decoding method (see AMBI_BIN_DECODING_METHODS enum)
Definition ambi_bin.c:709
int ambi_bin_getDAWsamplerate(void *const hAmbi)
Returns the DAW/Host sample rate.
Definition ambi_bin.c:835
void ambi_bin_setHRIRsPreProc(void *const hAmbi, AMBI_BIN_PREPROC newType)
Sets HRIR pre-processing strategy (see AMBI_BIN_PREPROC enum)
Definition ambi_bin.c:596
void ambi_bin_setFlipYaw(void *const hAmbi, int newState)
Sets a flag as to whether to "flip" the sign of the current 'yaw' angle.
Definition ambi_bin.c:632
AMBI_BIN_DECODING_METHODS
Available decoding methods for the ambi_bin example.
Definition ambi_bin.h:126
@ DECODING_METHOD_LSDIFFEQ
Least-squares (LS) decoder with diffuse-field spectral equalisation.
Definition ambi_bin.h:128
@ DECODING_METHOD_LS
Least-squares (LS) decoder.
Definition ambi_bin.h:127
@ DECODING_METHOD_SPR
Spatial resampling decoder (on the same lines as the virtual loudspeaker approach)
Definition ambi_bin.h:130
@ DECODING_METHOD_TA
Time-alignment (TA)
Definition ambi_bin.h:132
@ DECODING_METHOD_MAGLS
Magnitude least-squares decoder (MagLS)
Definition ambi_bin.h:133
void ambi_bin_setEnableMaxRE(void *const hAmbi, int newState)
Sets a flag to enable/disable the max_rE weighting.
Definition ambi_bin.c:569
void ambi_bin_setSofaFilePath(void *const hAmbi, const char *path)
Sets the file path for a .sofa file, in order to employ a custom HRIR set for the decoding.
Definition ambi_bin.c:522
int ambi_bin_getEnableRotation(void *const hAmbi)
Returns the flag value which dictates whether to enable/disable sound-field rotation ('0' disabled,...
Definition ambi_bin.c:766
int ambi_bin_getChOrder(void *const hAmbi)
Returns the Ambisonic channel ordering convention currently being used to decode with,...
Definition ambi_bin.c:725
int ambi_bin_getNumEars(void)
Returns the number of ears possessed by the average homo sapien (2)
Definition ambi_bin.c:755
float ambi_bin_getPitch(void *const hAmbi)
Returns the 'pitch' rotation angle, in degrees.
Definition ambi_bin.c:778
void ambi_bin_setFlipPitch(void *const hAmbi, int newState)
Sets a flag as to whether to "flip" the sign of the current 'pitch' angle.
Definition ambi_bin.c:641
int ambi_bin_getHRIRlength(void *const hAmbi)
Returns the length of HRIRs in time-domain samples.
Definition ambi_bin.c:821
float ambi_bin_getRoll(void *const hAmbi)
Returns the 'roll' rotation angle, in degrees.
Definition ambi_bin.c:784
void ambi_bin_setRPYflag(void *const hAmbi, int newState)
Sets a flag as to whether to use "yaw-pitch-roll" (0) or "roll-pitch-yaw" (1) rotation order.
Definition ambi_bin.c:659
int ambi_bin_getFlipPitch(void *const hAmbi)
Returns a flag as to whether to "flip" the sign of the current 'pitch' angle ('0' do not flip sign,...
Definition ambi_bin.c:796
int ambi_bin_getFlipRoll(void *const hAmbi)
Returns a flag as to whether to "flip" the sign of the current 'roll' angle ('0' do not flip sign,...
Definition ambi_bin.c:802
char * ambi_bin_getSofaFilePath(void *const hAmbi)
Returns the file path for a .sofa file.
Definition ambi_bin.c:715
float ambi_bin_getProgressBar0_1(void *const hAmbi)
(Optional) Returns current intialisation/processing progress, between 0..1
Definition ambi_bin.c:679
void ambi_bin_setUseDefaultHRIRsflag(void *const hAmbi, int newState)
Sets flag to dictate whether the default HRIRs in the Spatial_Audio_Framework should be used,...
Definition ambi_bin.c:512
AMBI_BIN_PREPROC
Available HRIR pre-preprocessing options.
Definition ambi_bin.h:141
@ HRIR_PREPROC_PHASE
Phase simplification based on ITD.
Definition ambi_bin.h:144
@ HRIR_PREPROC_EQ
Diffuse-field EQ (compensates CTF)
Definition ambi_bin.h:143
@ HRIR_PREPROC_OFF
No pre-processing active.
Definition ambi_bin.h:142
@ HRIR_PREPROC_ALL
Diffuse-field EQ AND phase-simplification.
Definition ambi_bin.h:145
void ambi_bin_setEnableTruncationEQ(void *const hAmbi, int newState)
Sets a flag to enable/disable (1 or 0) truncation EQ.
Definition ambi_bin.c:587
int ambi_bin_getRPYflag(void *const hAmbi)
Returns a flag as to whether to use "yaw-pitch-roll" (0) or "roll-pitch-yaw" (1) rotation order.
Definition ambi_bin.c:808
int ambi_bin_getFlipYaw(void *const hAmbi)
Returns a flag as to whether to "flip" the sign of the current 'yaw' angle ('0' do not flip sign,...
Definition ambi_bin.c:790
int ambi_bin_getInputOrderPreset(void *const hAmbi)
Returns the decoding order.
Definition ambi_bin.c:703
void ambi_bin_setDecodingMethod(void *const hAmbi, AMBI_BIN_DECODING_METHODS newMethod)
Sets the decoding method (see AMBI_BIN_DECODING_METHODS enum)
Definition ambi_bin.c:548
void ambi_bin_setEnableDiffuseMatching(void *const hAmbi, int newState)
Sets a flag to enable/disable (1 or 0) the diffuse-covariance constraint.
Definition ambi_bin.c:578
CODEC_STATUS ambi_bin_getCodecStatus(void *const hAmbi)
Returns current codec status, see CODEC_STATUS enum.
Definition ambi_bin.c:673
int ambi_bin_getUseDefaultHRIRsflag(void *const hAmbi)
Returns the value of a flag used to dictate whether the default HRIRs in the Spatial_Audio_Framework ...
Definition ambi_bin.c:691
float ambi_bin_getYaw(void *const hAmbi)
Returns the 'yaw' rotation angle, in degree.
Definition ambi_bin.c:772
int ambi_bin_getNDirs(void *const hAmbi)
Returns the number of directions in the currently used HRIR set.
Definition ambi_bin.c:814
void ambi_bin_getProgressBarText(void *const hAmbi, char *text)
(Optional) Returns current intialisation/processing progress text
Definition ambi_bin.c:685
void ambi_bin_setRoll(void *const hAmbi, float newRoll)
Sets the 'roll' rotation angle, in degrees.
Definition ambi_bin.c:625
void ambi_bin_refreshParams(void *const hAmbi)
Sets intialisation flags to 1, so as to re-initialise all settings/variables (as ambi_bin is currentl...
Definition ambi_bin.c:505