Skip to content

Commit

Permalink
Support pannerAttr for Howler sounds (#1788)
Browse files Browse the repository at this point in the history
Exposes the pannerAttr field, which allows panner values to be set. By setting the panningModel to "equalpower", audio degradation is prevented and results in crisp by default, resolving the problem mentioned in goldfire/howler.js#112.

In the future, panner attributes can be passed (for example `parent.buffer.__srcHowl.pannerAttr({panningModel: "HRTF”});)` within the HTML5AudioSource `play()` function, after it has began playback via `parent.buffer.__srcHowl.play()`.
  • Loading branch information
DigiEggz authored and joshtynjala committed Feb 24, 2025
1 parent c4cc642 commit cd404bd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lime/_internal/backend/html5/HTML5AudioSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ class HTML5AudioSource

public function dispose():Void {}

public function init():Void {}
public function init():Void
{
#if lime_howlerjs
// Initialize the panner with default values
parent.buffer.src.pannerAttr(
{
coneInnerAngle: 360,
coneOuterAngle: 360,
coneOuterGain: 0,
distanceModel: "inverse",
maxDistance: 10000,
refDistance: 1,
rolloffFactor: 1,
panningModel: "equalpower" // Default to equalpower for better performance
});
#end
}

public function play():Void
{
Expand Down Expand Up @@ -218,10 +234,9 @@ class HTML5AudioSource
#if lime_howlerjs
parent.buffer.__srcHowl.rate(value);
#end

return getPitch();
}


public function getPosition():Vector4
{
Expand Down
47 changes: 47 additions & 0 deletions src/lime/media/howlerjs/Howl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ class Howl
{
return null;
}

/**
* Get/set the panner node's attributes for a sound or group of sounds. This method can optionally take 0, 1 or 2 arguments.
* pannerAttr() -> Returns the group's values.
* pannerAttr(id) -> Returns the sound id's values.
* pannerAttr(o) -> Set's the values of all sounds in this Howl group.
* pannerAttr(o, id) -> Set's the values of passed sound id.
*
* Attributes:
* coneInnerAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
* inside of which there will be no volume reduction.
* coneOuterAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
* outside of which the volume will be reduced to a constant value of coneOuterGain.
* coneOuterGain - (0 by default) A parameter for directional audio sources, this is the gain outside of the
* coneOuterAngle. It is a linear value in the range [0, 1].
* distanceModel - ('inverse' by default) Determines algorithm used to reduce volume as audio moves away from
* listener. Can be linear, inverse or `exponential.
* maxDistance - (10000 by default) The maximum distance between source and listener, after which the volume
* will not be reduced any further.
* refDistance - (1 by default) A reference distance for reducing volume as source moves further from the listener.
* This is simply a variable of the distance model and has a different effect depending on which model
* is used and the scale of your coordinates. Generally, volume will be equal to 1 at this distance.
* rolloffFactor - (1 by default) How quickly the volume reduces as source moves from listener. This is simply a
* variable of the distance model and can be in the range of [0, 1] with linear and [0, ∞]
* with inverse and exponential.
* panningModel - ('HRTF' by default) Determines which spatialization algorithm is used to position audio.
* Can be HRTF or equalpower.
*
* @return Returns self or current panner attributes.
*/
public function pannerAttr(args:PannerAttr, ?id:Int):Howl
{
return this;
}
}
#else
import haxe.Constraints.Function;
Expand Down Expand Up @@ -267,6 +301,7 @@ extern class Howl
@:overload(function(x:Float, y:Float, z:Float):Howl {})
@:overload(function(x:Float, y:Float, z:Float, id:Int):Howl {})
public function pos():Array<Float>;
public function pannerAttr(args:PannerAttr, ?id:Int):Howl;
}
#end

Expand Down Expand Up @@ -295,4 +330,16 @@ typedef HowlOptions =
?onseek:Function,
?onfade:Function
}

typedef PannerAttr =
{
?coneInnerAngle:Float,
?coneOuterAngle:Float,
?coneOuterGain:Float,
?distanceModel:String,
?maxDistance:Float,
?refDistance:Float,
?rolloffFactor:Float,
?panningModel:String
}
#end

0 comments on commit cd404bd

Please sign in to comment.