Converting audio samples to dB and back
26/4/2012
I've been writing a tool to normalize lots of audio files at once, as well as convert between various loss-less formats (particularly FLAC and WAV). In doing that I needed a way of converting between the raw audio sample maximum and dB. So I present to you my C functions for doing so:
double LinearToDb(int32 linear, int bitDepth)
{
    uint32 MaxLinear = (1 << (bitDepth - 1)) - 1;
    uint32 ab = linear >= 0 ? linear : -linear;
    return log10((double)ab / MaxLinear) * 20.0;
}

int32 DbToLinear(double dB, int bitDepth)
{
    uint32 MaxLinear = (1 << (bitDepth - 1)) - 1;
    double d = pow(10, dB / 20);
    return d * MaxLinear;
}
Another code snippit for Google to index.

Tags: audio

From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]
Post