Skip to content

Instantly share code, notes, and snippets.

@merryhime
Created April 1, 2017 19:55
Show Gist options
  • Save merryhime/ba6b5f78b8f57066dcd544b9a2d5fd62 to your computer and use it in GitHub Desktop.
Save merryhime/ba6b5f78b8f57066dcd544b9a2d5fd62 to your computer and use it in GitHub Desktop.
// Note that our hearing is logarithmic.
// 0 dB = 1.0
// For the below equations, ratio refers to the amplitude ratio.
// 0 dB = same power = same amplitude = same psycho-acoustic volume
// -3 dB = half power
// -6 dB = half amplitude
// -10 dB = half psycho-acoustic volume = 32% amplitude
double dB_to_ratio(double dB) {
return exp(10.0, dB / 20.0);
}
double ratio_to_dB(double ratio) {
return 20.0 * log10(ratio);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment