html5 - Web Audio Api working with Decibels -


i wish understand how work decibels in web audio api

here have audio buffer connected gain node

var mybuffer = context.createbuffersource()); mybuffer.buffer = buffer; //an audio buffer  var gainnode=context.creategain();  mybuffer.connect(gainnode); gainnode.connect(context.destination); 

gain volume range 0(silent) n 1 default volume know, audio not related such range, volume measured in decibels (db) , operations made in db too.

i have read interesting in answer it's far complete needs: is there way decibel levels audio file , transform information json array?

i wonder how determine decibel audio node, how edit volume using decibels

decibels interesting beast. decibels aren't measure of volume, per se - they're measure of gain or attentuation, described in http://en.wikipedia.org/wiki/decibel. number of decibels ten times logarithm base 10 of ratio of 2 power quantities.

you can decibels out of 1 critical place in web audio api - realtimeanalyser's getfloatfrequencydata returns float array of attenuation per frequency band, in decibels. it's not technically volume - it's attenuation unity (1), sine wave in frequency @ full volume (-1 1).

gain controls are, of course, commonly expressed in decibels, because they're measure of ratio - between unity , whatever volume knob set to. think of unity (0 db, gain=1) "as loud speakers go".

to express gain in decibels, remember gain of 1 (no attenuation, no gain) equal 0 decibels - because 10^0 = 1. (actually - it's because 10 ^ (0/10) = 1. obviously, 0 divided still 0 - remember, these deci-bels, there's factor of ten in there.) aforementioned wikipedia article explains in depth.

to convert between 2 - e.g., set gain.value when have decibels, , decibel gain gain.value - need use formula

decibel_level = 20 * log10( gain.value ); 

aka

gain.value = math.pow(10, (decibel_level / 20)); 

note base 10 log little more complex in javascript, due having access natural logarithm, not base 10 logarithm - can via

function log10(x) {     return math.log(x)/math.ln10; } 

(there's math.log10() method, it's experimental , not implemented across browsers.)


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -