Finding the gain of an AudioBuffer channel


Hi all,

Forgive me if this is a silly question. How do I find the gain of an AudioBuffer channel, relative to 0dB? The lack of an obvious function would lead me to believe that gain can be easily deduced from the samples themselves but I am not sure how. I’m asking because I’m looking to adjust gain relative to an existing level.

Any help would be much appreciated. Thanks!





This is what you’re looking for. Feed it a processor’s floating point value, get dBFS back (and vice versa).

EDIT: You can combine this with @Rail_Jon_Rogut’s answer to do pretty much exactly what you want (hopefully).

Just keep in mind that if you base your calculations off the raw buffers, the behavior will likely change with different sample rates and buffer sizes.


Thank you @Rail_Jon_Rogut & @jonathonracz! Exactly the help I was looking for.