| << May >> | ||||||
| S | M | T | W | T | F | S |
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
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:
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
