meenie / 8bit.js

8Bit.js Audio Library - Write music using 8bit oscillation sounds.
778 stars 37 forks source link

Should fade() use AudioParam automation methods instead? #2

Closed olivierthereaux closed 11 years ago

olivierthereaux commented 11 years ago

I was wondering how your fade (in/out) worked, and noticed that you are using:

                    if (i > 0) {
                        i = i - 2;
                        i = i < 0 ? 0 : i;
                        var gain = 'up' === direction ? masterVolumeLevel * 100 - i : i;
                        masterVolume.gain.value = gain / 100;
                   ...

Would it be less verbose/painful and probably more efficient to use one of the specified audioparam automation methods from http://www.w3.org/TR/webaudio/#methodsandparams-AudioParam ?

I think linearRampToValueAtTime() would do pretty much the same thing you are doing here.

Have you tried the methods and found them to not be usable, or did you not know about them? This could be interesting feedback to us in the W3C Audio WG.

meenie commented 11 years ago

To be honest I didn't know about them. I pieced this library together over the weekend and I fully consumed the API into my brain yet :). I'll be switching it out to use that though as it's exactly what I should have used in the first place. Is there anything else in that I've done wrong? Also, I wasn't sure how know when all the oscillators were done playing so I had to use a setTimeout() to keep checking.

olivierthereaux commented 11 years ago

Ah, thanks. Good to know that it was not because the method is broken or not usable. I don't think I'm really qualify to critique the rest of it, but I'll keep looking.

That said, there is a W3C community group which we've created, where questions such as "am I using this right" are very much in scope. http://www.w3.org/community/audio-dev/

meenie commented 11 years ago

Great, thanks for that! I didn't realise that this would blow up so quickly. I just pushed this afternoon and it's already trending on Github. I'm a newbie when it comes to AudioContext since I only learned about it over the weekend. I have some big plans with what I want to do though :+1:.

meenie commented 11 years ago

I'm trying to use linearRampToValueAtTime() but it doesn't seem to work on the first time I try and fade it down, but then does work the subsequent tries. Also the fade up starts around the 50% mark and then goes up from there. I'd like if it worked closer to how my library currently does it as it seems much smoother. I also tried exponentialRampToValueAtTime() but that didn't work at all. No errors, but also no volume change.

olivierthereaux commented 11 years ago

Not sure why it's not working. Have you looked at e.g. https://github.com/sourcefabric/Airtime/blob/6bdc2caaec274b6814c15c503d97dc5e3e00bba5/airtime_mvc/public/js/waveformplaylist/fades.js ?

meenie commented 11 years ago

Thanks for the link, I'll implement what they have there and see how I go. At the moment it's close to midnight and I have work tomorrow :). Have a good day/night!

meenie commented 10 years ago

@olivierthereaux - I've implemented this finally, only took 11 months :). When I tried it last time, there may have been some bugs in my code or Chrome itself. In any case, it was rather straight forward this time. Thanks again!