kittykatattack / sound.js

A micro-library to load, play and generate sound effects and music for games and interactive applications
300 stars 44 forks source link

Sound instances and volume #11

Closed sashamirkovic closed 7 years ago

sashamirkovic commented 7 years ago

Hello,

I use this library as described however I have following problems with it. First once I write sndA = sounds[sndApathj] whenever I use in the code sndA.play() it starts another instance. Then I noticed that adjusting sndA.volume does not affect volume level at all. Also, with example code I get a errors for synth sound like:

sound.js:838 Oscillator.frequency.linearRampToValueAtTime value -1 outside nominal range [0, 24000]; value will be clamped.

Also I noticed that other functions like fade, fadeIn, fadeOut act strange (for example fadeIn is not fading in in linear fashion). Also, when one sound is playing and another sound is started overall volume is affected.

Could you please check the sound.js?

kittykatattack commented 7 years ago

Hi,

Please let me know on which browser you received this error message:

sound.js:838 Oscillator.frequency.linearRampToValueAtTime value -1 outside nominal range [0, 24000]; value will be clamped.

Did you receive this message while testing the "index.html" example file?

Qriva commented 7 years ago

Hello, I have also problems with changing volume but I made some research:

Bug appear for Firefox (I did not check Safari) and you can observe it even in your own demo @kittykatattack when trying to fadeOutfade is cuted off. I checked how it works in library and it stops working after using anyvolume.gain method like linearRampToValueAtTime. After using methods, property value(of gain) stops working. Methods don't set value property to new one, it just stuck in original one.

Im not an expert in audio but possible fix can be change all volume.gain.value to method gain.setValueAtTime. Also its probably related to Bug 893020 and this implementation

kittykatattack commented 7 years ago

@Qriva Thanks so much for those details! Can anyone suggest a fix?

Qriva commented 7 years ago

I needed sound library so I checked others likehowler.js but it seems that problem exists in all libraries.

I think that easy fix is not possible. Only thing I thought was to use everywhere gain.setValueAtTime instead of value but this way it's still not possible to get current value so only way to fix that is to store type used function and if value is needed - manually "predict", calculate current value from formula (in W3). But this is very complex solution... Paul Adenot said it's not going to be fixed in near future so the only solution for that is to rebuild library.