Home Reference Source Repository
import {BinauralPanner} from 'binaural/src/audio/BinauralPanner.js'
public class | source

BinauralPanner

Binaural panner with multiple sources and a listener.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Constructs an HRTF set.

Member Summary

Public Members
public set

Set coordinate system.

public get

Get coordinate system.

public set

Set post-filtering flag.

public get

Get post-filtering flag.

public get

Get coordinate system for filter positions.

public set

Set coordinate system for filter positions.

public set

Set the filter positions of the HRTF set.

public get

Get the filter positions of the HRTF set.

public get

Get the HrtfSet.

public set

hrtfSet(hrtfSet: HrtfSet): *

Refer an external HRTF set, and update sources.

public set

listener(listener: Listener): *

Refer an external listener, and update sources.

public set

Set coordinate system for listener.

public get

Get coordinate system for listener.

public set

listenerPosition(positionRequest: Coordinates): *

Set listener position.

public get

Get listener position.

public set

listenerUp(upRequest: Coordinates): *

Set listener up direction (not an absolute position).

public get

Get listener up direction.

public set

listenerView(viewRequest: Coordinates): *

Set listener view, as an aiming position or a relative direction, if viewIsRelative is respectively false or true.

public get

Get listener view.

public set

Set the type of view: absolute to an aiming position (when false), or a relative direction (when true).

public get

Get the type of view.

public set

sourcePositions(positionsRequest: Array<Coordinates>): *

Set the sources positions.

public get

Get the source positions.

Method Summary

Public Methods
public

connectInputByIndex(index: Number, nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this

Connect the input of a source.

public

connectOutputByIndex(index: Number, nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this

Connect the output of a source.

public

connectOutputs(nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this

Connect the output of each source.

public

disconnectInputByIndex(index: Number, nodesToDisconnect: AudioNode | Array<AudioNode>): this

Disconnect the input of one source.

public

disconnectInputs(nodesToDisconnect: AudioNode | Array<AudioNode>): this

Disconnect the input of each source.

public

disconnectOutputByIndex(index: Number, nodesToDisconnect: AudioNode | Array<AudioNode>): this

Disconnect the output of a source.

public

disconnectOutputs(nodesToDisconnect: AudioNode | Array<AudioNode>): this

Disconnect the output of each source.

public

Get the position of one source.

public

loadHrtfSet(sourceUrl: String): Promise.<this | Error>

Load an HRTF set form an URL, and update sources.

public

setSourcePositionByIndex(index: Number, positionRequest: Coordinates): this

Set the position of one source.

public

Update the sources filters, according to pending changes in listener, and source positions.

Public Constructors

public constructor(options: Object) source

Constructs an HRTF set. Note that the filter positions are applied during the load of an HRTF URL.

Params:

NameTypeAttributeDescription
options Object
options.audioContext AudioContext

mandatory for the creation of FIR audio buffers

options.coordinateSystem CoordinateSystem
  • optional
  • default: 'gl'

BinauralPanner#coordinateSystem

options.sourceCount Number
  • optional
  • default: 1
options.sourcePositions Array<coordinates>
  • optional
  • default: undefined

must be of length options.sourceCount BinauralPanner#sourcePositions

options.crossfadeDuration Number
  • optional

in seconds.

options.hrtfSet HrtfSet
  • optional

refer an external HRTF set. BinauralPanner#hrtfSet

options.filterCoordinateSystem CoordinateSystem
  • optional
  • default: options.coordinateSystem

BinauralPanner#filterCoordinateSystem

options.filterPositions Array<coordinates>
  • optional
  • default: undefined

array of positions to filter. Use undefined to use all positions from the HRTF set. BinauralPanner#filterPositions

options.filterAfterLoad Boolean
  • optional
  • default: false

true to filter after full load of SOFA file

options.listener Listener
  • optional

refer an external listener. BinauralPanner#listener

options.listenerCoordinateSystem CoordinateSystem
  • optional
  • default: options.coordinateSystem

BinauralPanner#listenerCoordinateSystem

options.listenerPosition Coordinates
  • optional
  • default: [0,0,0]

BinauralPanner#listenerPosition

options.listenerUp Coordinates
  • optional
  • default: [0,1,0]

BinauralPanner#listenerUp

options.listenerView Coordinates
  • optional
  • default: [0,0,-1]

BinauralPanner#listenerView

options.listenerViewIsRelative Boolean
  • optional
  • default: false

Listener#viewIsRelative

See:

Public Members

public set coordinateSystem(system: CoordinateSystem): * source

Set coordinate system.

public get coordinateSystem: CoordinateSystem: * source

Get coordinate system.

public set filterAfterLoad(post: Boolean): * source

Set post-filtering flag. When false, try to load a partial set of HRTF.

public get filterAfterLoad: Boolean: * source

Get post-filtering flag. When false, try to load a partial set of HRTF.

Return:

Boolean

public get filterCoordinateSystem: CoordinateSystem: * source

Get coordinate system for filter positions.

public set filterCoordinateSystem(system: CoordinateSystem): * source

Set coordinate system for filter positions.

public set filterPositions(positions: Array<Coordinates>): * source

Set the filter positions of the HRTF set.

See:

public get filterPositions: Array<Coordinates>: * source

Get the filter positions of the HRTF set.

Return:

Array<Coordinates>

positions

See:

public get hrtfSet: HrtfSet: * source

Get the HrtfSet.

Return:

HrtfSet

public set hrtfSet(hrtfSet: HrtfSet): * source

Refer an external HRTF set, and update sources. Its positions coordinate system must be 'gl'.

Throw:

Error

when hrtfSet in undefined or hrtfSet.coordinateSystem is not 'gl'.

See:

public set listener(listener: Listener): * source

Refer an external listener, and update sources.

Throw:

Error

when listener in undefined.

See:

public set listenerCoordinateSystem(system: CoordinateSystem): * source

Set coordinate system for listener.

See:

public get listenerCoordinateSystem: CoordinateSystem: * source

Get coordinate system for listener.

public set listenerPosition(positionRequest: Coordinates): * source

Set listener position. It will update the relative positions of the sources after a call to the update method.

Default value is [0, 0, 0] in 'gl' coordinates.

See:

public get listenerPosition: Coordinates: * source

Get listener position.

Return:

Coordinates

public set listenerUp(upRequest: Coordinates): * source

Set listener up direction (not an absolute position). It will update the relative positions of the sources after a call to the update method.

Default value is [0, 1, 0] in 'gl' coordinates.

See:

public get listenerUp: Coordinates: * source

Get listener up direction.

Return:

Coordinates

public set listenerView(viewRequest: Coordinates): * source

Set listener view, as an aiming position or a relative direction, if viewIsRelative is respectively false or true. It will update the relative positions of the sources after a call to the update method.

Default value is [0, 0, -1] in 'gl' coordinates.

See:

public get listenerView: Coordinates: * source

Get listener view.

Return:

Coordinates

public set listenerViewIsRelative(relative: Boolean): * source

Set the type of view: absolute to an aiming position (when false), or a relative direction (when true). It will update the relative positions after a call to the update method.

See:

public get listenerViewIsRelative: Boolean: * source

Get the type of view.

Return:

Boolean

public set sourcePositions(positionsRequest: Array<Coordinates>): * source

Set the sources positions. It will update the relative positions after a call to the update method.

Throw:

Error

if the length of positionsRequest is not the same as the number of sources

See:

  • BinauralPanner#update
  • BinauralPanner#setSourcePositionByIndex

public get sourcePositions: Array<Coordinates>: * source

Get the source positions.

Return:

Array<Coordinates>

Public Methods

public connectInputByIndex(index: Number, nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this source

Connect the input of a source.

Params:

NameTypeAttributeDescription
index Number
nodesToConnect AudioNode | Array<AudioNode>
output Number
  • optional
  • default: 0

output to connect from

input Number
  • optional
  • default: 0

input to connect to

Return:

this

public connectOutputByIndex(index: Number, nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this source

Connect the output of a source.

Params:

NameTypeAttributeDescription
index Number
nodesToConnect AudioNode | Array<AudioNode>
output Number
  • optional
  • default: 0

output to connect from

input Number
  • optional
  • default: 0

input to connect to

Return:

this

public connectOutputs(nodesToConnect: AudioNode | Array<AudioNode>, output: Number, input: Number): this source

Connect the output of each source.

Params:

NameTypeAttributeDescription
nodesToConnect AudioNode | Array<AudioNode>
output Number
  • optional
  • default: 0

output to connect from

input Number
  • optional
  • default: 0

input to connect to

Return:

this

See:

  • BinauralPanner#connectOutputByIndex

public disconnectInputByIndex(index: Number, nodesToDisconnect: AudioNode | Array<AudioNode>): this source

Disconnect the input of one source.

Params:

NameTypeAttributeDescription
index Number
nodesToDisconnect AudioNode | Array<AudioNode>

disconnect all when undefined.

Return:

this

public disconnectInputs(nodesToDisconnect: AudioNode | Array<AudioNode>): this source

Disconnect the input of each source.

Params:

NameTypeAttributeDescription
nodesToDisconnect AudioNode | Array<AudioNode>

disconnect all when undefined.

Return:

this

public disconnectOutputByIndex(index: Number, nodesToDisconnect: AudioNode | Array<AudioNode>): this source

Disconnect the output of a source.

Params:

NameTypeAttributeDescription
index Number
nodesToDisconnect AudioNode | Array<AudioNode>

disconnect all when undefined.

Return:

this

public disconnectOutputs(nodesToDisconnect: AudioNode | Array<AudioNode>): this source

Disconnect the output of each source.

Params:

NameTypeAttributeDescription
nodesToDisconnect AudioNode | Array<AudioNode>

Return:

this

public getSourcePositionByIndex(index: Number): Coordinates source

Get the position of one source.

Params:

NameTypeAttributeDescription
index Number

Return:

Coordinates

public loadHrtfSet(sourceUrl: String): Promise.<this | Error> source

Load an HRTF set form an URL, and update sources.

Params:

NameTypeAttributeDescription
sourceUrl String

Return:

Promise.<this | Error>

resolve when URL successfully loaded.

See:

public setSourcePositionByIndex(index: Number, positionRequest: Coordinates): this source

Set the position of one source. It will update the corresponding relative position after a call to the update method.

Params:

NameTypeAttributeDescription
index Number
positionRequest Coordinates

Return:

this

See:

  • BinauralPanner#update

public update(): Boolean source

Update the sources filters, according to pending changes in listener, and source positions.

Return:

Boolean

true when at least a change occurred.