Skip to content

Commit cd404bd

Browse files
DigiEggzjoshtynjala
authored andcommitted
Support pannerAttr for Howler sounds (#1788)
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()`.
1 parent c4cc642 commit cd404bd

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

src/lime/_internal/backend/html5/HTML5AudioSource.hx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@ class HTML5AudioSource
2626

2727
public function dispose():Void {}
2828

29-
public function init():Void {}
29+
public function init():Void
30+
{
31+
#if lime_howlerjs
32+
// Initialize the panner with default values
33+
parent.buffer.src.pannerAttr(
34+
{
35+
coneInnerAngle: 360,
36+
coneOuterAngle: 360,
37+
coneOuterGain: 0,
38+
distanceModel: "inverse",
39+
maxDistance: 10000,
40+
refDistance: 1,
41+
rolloffFactor: 1,
42+
panningModel: "equalpower" // Default to equalpower for better performance
43+
});
44+
#end
45+
}
3046

3147
public function play():Void
3248
{
@@ -218,10 +234,9 @@ class HTML5AudioSource
218234
#if lime_howlerjs
219235
parent.buffer.__srcHowl.rate(value);
220236
#end
221-
237+
222238
return getPitch();
223239
}
224-
225240

226241
public function getPosition():Vector4
227242
{

src/lime/media/howlerjs/Howl.hx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,40 @@ class Howl
216216
{
217217
return null;
218218
}
219+
220+
/**
221+
* Get/set the panner node's attributes for a sound or group of sounds. This method can optionally take 0, 1 or 2 arguments.
222+
* pannerAttr() -> Returns the group's values.
223+
* pannerAttr(id) -> Returns the sound id's values.
224+
* pannerAttr(o) -> Set's the values of all sounds in this Howl group.
225+
* pannerAttr(o, id) -> Set's the values of passed sound id.
226+
*
227+
* Attributes:
228+
* coneInnerAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
229+
* inside of which there will be no volume reduction.
230+
* coneOuterAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
231+
* outside of which the volume will be reduced to a constant value of coneOuterGain.
232+
* coneOuterGain - (0 by default) A parameter for directional audio sources, this is the gain outside of the
233+
* coneOuterAngle. It is a linear value in the range [0, 1].
234+
* distanceModel - ('inverse' by default) Determines algorithm used to reduce volume as audio moves away from
235+
* listener. Can be linear, inverse or `exponential.
236+
* maxDistance - (10000 by default) The maximum distance between source and listener, after which the volume
237+
* will not be reduced any further.
238+
* refDistance - (1 by default) A reference distance for reducing volume as source moves further from the listener.
239+
* This is simply a variable of the distance model and has a different effect depending on which model
240+
* is used and the scale of your coordinates. Generally, volume will be equal to 1 at this distance.
241+
* rolloffFactor - (1 by default) How quickly the volume reduces as source moves from listener. This is simply a
242+
* variable of the distance model and can be in the range of [0, 1] with linear and [0, ∞]
243+
* with inverse and exponential.
244+
* panningModel - ('HRTF' by default) Determines which spatialization algorithm is used to position audio.
245+
* Can be HRTF or equalpower.
246+
*
247+
* @return Returns self or current panner attributes.
248+
*/
249+
public function pannerAttr(args:PannerAttr, ?id:Int):Howl
250+
{
251+
return this;
252+
}
219253
}
220254
#else
221255
import haxe.Constraints.Function;
@@ -267,6 +301,7 @@ extern class Howl
267301
@:overload(function(x:Float, y:Float, z:Float):Howl {})
268302
@:overload(function(x:Float, y:Float, z:Float, id:Int):Howl {})
269303
public function pos():Array<Float>;
304+
public function pannerAttr(args:PannerAttr, ?id:Int):Howl;
270305
}
271306
#end
272307

@@ -295,4 +330,16 @@ typedef HowlOptions =
295330
?onseek:Function,
296331
?onfade:Function
297332
}
333+
334+
typedef PannerAttr =
335+
{
336+
?coneInnerAngle:Float,
337+
?coneOuterAngle:Float,
338+
?coneOuterGain:Float,
339+
?distanceModel:String,
340+
?maxDistance:Float,
341+
?refDistance:Float,
342+
?rolloffFactor:Float,
343+
?panningModel:String
344+
}
298345
#end

0 commit comments

Comments
 (0)