Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pausing issue in v1.1.1 #37

Closed
erichlof opened this issue Apr 18, 2013 · 12 comments
Closed

Pausing issue in v1.1.1 #37

erichlof opened this issue Apr 18, 2013 · 12 comments
Labels

Comments

@erichlof
Copy link

Hi James,
I opened this issue in relation to the recently closed issue that I had started. I feel this is still a relevant issue. There is a pausing problem while trying to use the new .pos3d() method to pan a sound, then playing a sound once, twice, or repeating the sound rapid-fire (like a machine-gun effect in a game).

I found the problem magically goes away when I make a simple boolean change to your howler.js code:

       // set web audio node to paused at end
        if (self._webAudio && !loop) {
          self._nodeById(data.id).paused = false; //changed to 'false' by erichlof
        }  

This came from the play: function . I'm sorry this is kind of a hack and I don't really understand the inner workings of howler well enough to know why this works, but it does.

Can you safely work it in to the next version so we can use the .pos3d() method with the intended results?

Thanks James. Howler 1.1.1 rocks!

@goldfire
Copy link
Owner

goldfire commented May 3, 2013

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?

@erichlof
Copy link
Author

erichlof commented May 3, 2013

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!

@erichlof
Copy link
Author

erichlof commented May 4, 2013

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. :-)

@erichlof
Copy link
Author

erichlof commented May 6, 2013

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.

@goldfire
Copy link
Owner

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);
});

@erichlof
Copy link
Author

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.

@erichlof
Copy link
Author

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.

@goldfire
Copy link
Owner

Can you post the code that defines powerupSound?

@erichlof
Copy link
Author

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.

@goldfire
Copy link
Owner

Sorry, that is my mistake, I typed up my example wrong. Try this:

powerupSound.play(null, function(soundId){
    powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});

@erichlof
Copy link
Author

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

@goldfire
Copy link
Owner

goldfire commented Jun 9, 2013

Please post, I'm sure others would find it useful. Thanks!

@goldfire goldfire closed this as completed Jun 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants