Created
February 12, 2013 11:22
-
-
Save mrmikejones/4761676 to your computer and use it in GitHub Desktop.
Conversion between decibel and linear scales
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
static double ConvertDecibelsToLinear(double dB) | |
{ | |
if(dB <= -60.0) | |
{ | |
return 0.0; | |
} | |
return pow(10.0, dB/20.0); | |
} | |
static double ConvertLinearToDecibels(double linear) | |
{ | |
if(linear <= 0.0) | |
{ | |
return -60.0; | |
} | |
return 20.0 * log10(linear); | |
} | |
int main(int argc, char* argv[]) | |
{ | |
printf("-6dB in linear is %.2f\n", ConvertDecibelsToLinear(-6.0)); | |
printf("0.25 in decibels is %.2f\n", ConvertLinearToDecibels(0.25)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment