Comments (12)
We are currently using pos3d extensively in our newest game and haven't run into any issues. Are you still seeing this in 1.1.4, and if so, can you post some sample code?
from howler.js.
Hi James,
I have yet to download 1.1.4 and I am about to go to work. So, later tonight I will test it and post code if there is still a problem. I've been recently suspecting that it has less to do with pos3d and more to do with fast repeated sounds. I might have to learn from you the correct way to play stuff like machine gun fire (lots of the same sounds in a row without cutting the previous one off). I will check back in soon. Thanks!
from howler.js.
Hi again,
Yes unfortunately it is still echoing/delaying repeated sounds in v1.1.4. If I play a sound to the left (comes to my left ear), then move slider to the right and play the sound again, it still plays out of the old left ear position, but fainter. And now I end up with two sounds, one coming out of the left position (incorrectly) and a louder one coming out of the right position (correct). Howler is somehow retaining that older position even though I have long since moved away from there. It will continue to play it there for about 4 times, so I end up eventually with a history trail of sounds - heh heh, sort of like quantum parallel "many universes" theory! Cool, but not what I'm expecting.
I got it to work correctly with my hack above, but I don't really want to have to do this.
I will post back with the source code. Must go to bed. :-)
from howler.js.
Here's some sample code. I only included the relevant parts for playing a sound that repeats quickly:
//use jQuery to listen for a Key pressed down
$(document).keydown(function(e) {
//this keys[] array will hold all keys that are being pressed
keys[e.which] = true; //[e.which] returns the key code and
//thus that element of the keys[] array will be 'true'
});
//when user releases a key upwards, it is no longer needed so delete it
$(document).keyup(function(e) {
delete keys[e.which];
});
//for a real game, requestAnimationFrame() should be used, but for this demo,
//the setInterval() function will do. Every 100 milliseconds (1000 / 100 =
// about 10 times a second), it fires the callback function scanKeyboard()
setInterval(scanKeyboard, 100); //(could change the '100' to '17' for around 60 times a second)
//this function is called every 100 milliseconds in the setInterval() function above
function scanKeyboard() {
//iterate through the keys[] array
for (var i in keys) {
if (!keys.hasOwnProperty(i))
continue; //didn't have a property, so continue on to the next 'i' index.
// otherwise, test if the SPACE bar is pressed (key code is 32)
if (i == 32) {
posValueX = $("#sliderX").slider("value"); //set posValueX to sliderX value
posValueY = $("#sliderY").slider("value"); //set posValueY to sliderY value
posValueZ = $("#sliderZ").slider("value") * -1.0; //set posValueZ to -(sliderZ) value
powerupSound.pos3d(posValueX, posValueY, posValueZ);
powerupSound.play();
}
}
}
I suspect that this whole problem of echoing sounds has to do with how sounds are supposed to be rapidly repeated in Howler. Lets say I code something like this:
for(i=0; i<shotsFired; i++){
machineGunSound.play();
}
Is this the correct way to use fast repeating sounds in Howler? Or should I say for i<shotsFired machineGunSound[i] = new Howl(...) , and just create a separate Howler sound object for each bullet?
Thanks for taking a look at this.
from howler.js.
What happens if you change this:
powerupSound.pos3d(posValueX, posValueY, posValueZ);
powerupSound.play();
to this:
powerupSound.play(function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});
from howler.js.
Hi James, thanks for the suggestion. I will try it tonight - I have to work right now but I will be at my computer later. I will post soon with the results.
from howler.js.
It still doesn't work for me. It doesn't play any sound at all.
Do I have to replace the word (soundId) with something of my own or can I use what you provided as-is? Does soundId somehow have to change each iteration?
Thanks for your help.
from howler.js.
Can you post the code that defines powerupSound
?
from howler.js.
Yes, here it is:
var powerupSound = new Howl({
urls : ['powerup.mp3']
});
And here is my updated pos3d function call, using your earlier suggestion:
setInterval(scanKeyboard, 100);
//this function is called every 100 milliseconds in the setInterval() function above
function scanKeyboard() {
//iterate through the keys[] array
for (var i in keys) {
if (!keys.hasOwnProperty(i))
continue;//didn't have a property, so continue on to the next 'i' index.
// otherwise, test if the SPACE bar is pressed (key code is 32)
if (i == 32) {
posValueX = $("#sliderX").slider("value"); //set posValueX to sliderX value
posValueY = $("#sliderY").slider("value"); //set posValueY to sliderY value
posValueZ = $("#sliderZ").slider("value") * -1.0; //set posValueZ to -(sliderZ) value
powerupSound.play(function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});
}
}
}
I would eventually like this to trigger a machine-gun effect so when the player holds down SPACE or 'fire' button, multiple shot sounds will play rapid-fire over one another without cutting the earlier ones off. So I guess what I'm looking for is a way to have multiples of the same sound with a unique 3D position and start/stop time for each (which I'm guessing requires a unique identifier for each?). Thanks for any help you can give me.
from howler.js.
Sorry, that is my mistake, I typed up my example wrong. Try this:
powerupSound.play(null, function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});
from howler.js.
Yes! It works! That did the trick like magic. I guess what my demo needed was a unique id for each sound that was triggered rapid-fire by holding down the SPACE key.
If you like, I can now post the source code for this little demo as it works the way I intended.
Thanks so much for your patience and help James!
-Erich
from howler.js.
Please post, I'm sure others would find it useful. Thanks!
from howler.js.
Related Issues (20)
- Why callback not be cleared automaticlly after sound stopped
- When looping, playback position value is sometimes beyond the audio file's duration
- Turn media session on and off
- ALAC encoded files not playing
- Failure to load audio on latest Opera HOT 3
- Howler gets in interrupted state after minimized and opened again iOS
- Howler Sprite Visual example does not work on iphone
- Seamlessly play multiple sprites one after another with the howler.js library
- gap when audio is in loop using html5
- How to differentiate between a sound already played or about to be played based on soundID params?
- Some live streams (html5) buffer forever on Safari iOS 17.4 HOT 16
- On Safari, no error is triggered in case of a corrupted file
- keep crash on Safari 17.5 beta HOT 3
- Duration returns Infinity in chrome
- Audio is not playing when I phone goes to sleep mode. HOT 1
- Howler not working in background for iphone
- iOS 17.4 playback issue HOT 2
- Opera GX LVL5 (core: 109.0.5097.62) not working but Chrome, Firefox, Edge and Safari are all okay. HOT 1
- Audio doesnt play if i set html5 to true and audio doesnt play on background if i set html5 to false, Iphone latest ios version HOT 9
- seeking help re: Perf on iPad mobile Safari HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from howler.js.