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

setVolume does not effect #38

Closed
timotoots opened this issue Jun 2, 2015 · 4 comments
Closed

setVolume does not effect #38

timotoots opened this issue Jun 2, 2015 · 4 comments

Comments

@timotoots
Copy link

Hello @rserota! Thanks for the great work, I really like the script!

I do have one problem. I try to get setVolume working at later times after loading, but it seems not to have effect. I am using latest Chrome. Here is a demo, bell.setVolume(0.5) works, but the one inside of the setTimeout does not. Also it does not work from any other function. Or am I missing anything here?

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="wad/build/wad.js"></script>
</head>
<body>
  <script>

var bell = new Wad({source : 'test.wav', volume : 1})
bell.play()
bell.setVolume(0.5);
setTimeout('bell.setVolume(0.1);console.log("voldown")',1000);

</script>
</body>
</html>
@rserota
Copy link
Owner

rserota commented Jun 2, 2015

Hey @timotoots, thanks for using wad.js.

According to the Web Audio spec, gain nodes will ignore changes to their value if there is currently automation scheduled. All basic wads have automation scheduled to implement their envelopes, so this would prevent setVolume from changing the volume while a note is playing. I don't think it has anything to do with setTimeout specifically. I'm not sure if the web audio API always worked this way, because I could swear this feature used to work.

You can work around this issue by wrapping the bell in a polywad, because polywads have their own gain nodes, but they have no automation.

var bell = new Wad({source : 'test.wav', volume : 1});
var wrapper = new Wad.Poly();
wrapper.add(bell)
bell.play()
setTimeout('wrapper.setVolume(0.1);console.log("voldown")',1000);

@notthetup
Copy link

As per the current implementation of WebAudio (the spec has some upcoming changes about this) if the AudioParam is in 'automation mode' then the setters/getters are disabled. The setter doesn't change anything, and the getter returns a 'last stable value'.

WebAudio/web-audio-api#503

@rserota
Copy link
Owner

rserota commented Jun 3, 2015

@notthetup Thanks for the link. That adds some clarity to this issue for me.

I don't think I'll be able to find a better solution to this issue than the workaround I posted above, due to how web audio handles automation. In that case, I will close this issue.

@rserota rserota closed this as completed Jun 3, 2015
@timotoots
Copy link
Author

I got it working that way!
Thanks for the workaround @rserota and also the extra info @notthetup!

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

3 participants