Skip to content

Commit 996133f

Browse files
committed
Add support for setting Doppler factor and speed of sound.
1 parent 3cb431c commit 996133f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ The following methods are used to modify all sounds globally, and are called fro
160160
* *x*: `Number` The x-velocity of the listener.
161161
* *y*: `Number` The y-velocity of the listener.
162162
* *z*: `Number` The z-velocity of the listener.
163+
* **dopplerFactor**: Get/set the Doppler factor. **This only works with Web Audio API.**
164+
* *factor*: `Number` The Doppler factor.
165+
* **speedOfSound**: Get/set the speed of sound. **This only works with Web Audio API.**
166+
* *speed*: `Number` The speed of sound.
163167

164168
## License
165169

howler.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,46 @@
164164

165165
return Howler;
166166
},
167+
168+
/**
169+
* Get/set the Doppler factor.
170+
* NOTE: This only works with Web Audio API, HTML5 Audio playback
171+
* will not be affected.
172+
* @param {Float} factor Doppler factor to use
173+
* @return {Float} Returns {Howler} or the current Doppler factor
174+
*/
175+
dopplerFactor: function(factor) {
176+
177+
if (factor >= 0 || factor < 0) {
178+
if (usingWebAudio) {
179+
ctx.listener.dopplerFactor = factor;
180+
}
181+
} else {
182+
return ctx.listener.dopplerFactor;
183+
}
184+
185+
return Howler;
186+
},
187+
188+
/**
189+
* Get/set the speed of sound.
190+
* NOTE: This only works with Web Audio API, HTML5 Audio playback
191+
* will not be affected.
192+
* @param {Float} speed Speed of sound to use
193+
* @return {Float} Returns {Howler} or the current speed of sound
194+
*/
195+
speedOfSound: function(speed) {
196+
197+
if (speed >= 0 || speed < 0) {
198+
if (usingWebAudio) {
199+
ctx.listener.speedOfSound = speed;
200+
}
201+
} else {
202+
return ctx.listener.speedOfSound;
203+
}
204+
205+
return Howler;
206+
},
167207
};
168208

169209
// allow access to the global audio controls

0 commit comments

Comments
 (0)