Binaural (w Sofa support)

Aspic Audiostack Binaural module provides effects for binaural spatialization.

  1. Effects
  2. Helpers
  3. Code samples

Effects

Binaural Spatialization Aspic

Provides HRTF-based spatialization for binaural rendering. Also supports SOFA for individualized binaural rendering.

Each input channel is spatialized independently (no mixing), which enables you to add more “per-channel” effects after this spatialization.

I/O Channel count Sub channel count  
in N 1 (MONO)  
out N 2 (STEREO)  

Construction

No arguments

Usage :

context.createEffect(EFFECT_ID, BUS_ID, BinauralSpatializationAspic); 

Parameters

Instanciation
  • subject_name (const char*) : name of HRTF to use

    If you have registered custom HRTF in the context, use this parameter to bind hrtfs to listeners

    Parameter is mapped by default to listener/%list_id/subject_name

    Usage with default vars and patterns:

    context.setParameter("listener/6/subject_name", "myHRTF");
    

To load and register custom HRTF, see HRTF loading below.

Runtime
  • src_position (vec3, multivalued) : position of audio source

    This parameter will contain N values, with N equal to the number of channels reaching effect’s input.

    Parameter is mapped by default to source/%src_id/position

    Usage with default vars and patterns:

    float sourcePos[] = {1.0, 2.0, 3.0};
    context.setParameter("source/9/position", sourcePos);
    
  • listener_position (vec3, multivalued) : position of audio listener

    This parameter will contain N values, with N equal to the number of listeners.

    Parameter is mapped by default to listener/%list_id/position

    Usage with default vars and patterns:

    float playerPos[] = {1.0, 2.0, 3.0};
    context.setParameter("listener/1/position", playerPos);
    
  • listener_rotation (vec3, multivalued) : rotation of audio listener

    This parameter will contain N values, with N equal to the number of listeners.

    Parameter is mapped by default to listener/%list_id/rotation

    Usage with default vars and patterns:

    float playerRot[] = {1.0, 2.0, 3.0};
    context.setParameter("listener/1/rotation", playerRot);
    

Note : coordinates in Aspic Audiostack are specified using right-hand axes (X right, Y up, Z backward).

We will add a convenient interface to help you transform various coordinates systems.



Helpers

Loading custom HRTF

In order to use custom HRTF, this extension allows you to laod .SOFA files.

First you have to register a new asset of type SofaAsset:

Usage:

context.registerAsset("my_hrtf", 4 /* SofaAsset */);

The first parameter is the name you want to give to this asset; the second parameter identifies SofaAssets.

Then, you can load a file into this assets using:

context.loadAssetFromFile("my_hrtf", "path/to/myHrtf.SOFA");

If your SOFA file is properly formated, the asset is successfully loaded, and you can bind these HRTFs to one listener. Please check Binaural samples!




Code samples

For more code samples, see Binaural samples

Binaural spatialization sample

This sample spatialize audio for one listener.

For multilistener samples, please see Asio Extension samples, since they enable multi-output rendering.

[...]

enum:int{helloId = 0, outputId = 1, busId, spatId};

AudiostackContext context;
context.setLicenseKeyFromFile("LICENSE.aslc");

context.createInput(helloId, HelloInput);
context.createOutput(outputId, WindowsCoreAudioOutput,true);                 
// Output is stereo, because binaural effect produces a stereo output.

context.createBus(busId);                                       
context.createEffect(spatId,busId,BinauralSpatializationAspic);

context.connect(helloId,busId);
context.connect(busId,outputId);

context.play();

float sourcePos[]   =   {0.0, 0.0, -1.0};
float listenerPos[] =   {0.0, 0.0, 1.0};
float listenerRot[] =   {0.0, 0.0, 0.0};

context.setParameter("listener/1/position",listenerPos);

char c;
do{

	std::cout<<"Press r or l to rotate the listener, press q to exit"<<std::endl;
	std::cin>>c;

	switch(c){
	case 'l':
		listenerRot[1]-=10;	// Rotate around Y axis (=> azimuth)
		context.setParameter("listener/1/rotation",listenerRot);
		err(context);
		break;
	case 'r':
		listenerRot[1]+=10;
		context.setParameter("listener/1/rotation",listenerRot);
		err(context);
		break;
	}
}while(c!='q');


context.stop();

[...]

For more code samples, see Binaural samples