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

Can't switch panning type (3d/stereo) on play #40

Closed
alexmooch opened this issue Jun 14, 2015 · 2 comments
Closed

Can't switch panning type (3d/stereo) on play #40

alexmooch opened this issue Jun 14, 2015 · 2 comments

Comments

@alexmooch
Copy link

Hi @rserota, great work on this script! It works like a charm, just one thing is not clear to me.

With code just like

var saw = new Wad({source: 'sine'});

stereo panning seems to be used by default. So following line:

saw.play({panning: [10, 0, 10]});

throws an exception Uncaught TypeError: Failed to set the 'value' property on 'AudioParam': The provided float value is non-finite. at line 473 in wad.js.
Setting up 3d panning manually:

var saw = new Wad({source: 'sine', panning: [0, 0, 0]}); // or 'panning: []'

fixes the thing.
And as I just figured out, this code:

var saw = new Wad({source: 'sine', panning: [0, 0, 0]});
saw.play({panning: 0.5});

gives again an error: Uncaught TypeError: Failed to execute 'setPosition' on 'PannerNode': The provided float value is non-finite. (line 468).

So, the question is if it's possible to change panning type after Wad is created? And can it be made automatically?

P.S. Should be in setUpPanningOnPlay not current Wad's but arg's panning type checked? Like

var setUpPanningOnPlay = function(that, arg) {
    var panning = arg && arg.panning; // can be zero provided as argument
    if (typeof(panning) === 'undefined') panning = that.panning.location;

    if (typeof(panning) === 'number') {
        that.panning.node = context.createStereoPanner();
        that.panning.node.pan.value = panning;
    }
    else {
        that.panning.node = context.createPanner();
        that.panning.node.setPosition(panning[0], panning[1], panning[2]);
    }

    that.nodes.push(that.panning.node);
};

or similar, I guess?

@rserota
Copy link
Owner

rserota commented Jun 14, 2015

My original intention was that once you initialize a Wad with one panner, you couldn't switch it to the other type on the fly. I just didn't think it really made sense, though I guess if you know what you're doing, there isn't really any harm.

Would you like to test your suggested code and submit it as a pull request? You'd also need to modify the setPanning method to be more dynamic, similarly to what you did with setUpPanningOnPlay.

@rserota
Copy link
Owner

rserota commented Jun 18, 2015

I implemented the change you suggested (and updated other relevant code). If you pull down fresh code, it should work the way you want. You can now switch between 3d and stereo panning on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants