What is involved when converting bitdepth?

Hello,

At the most basic level, what steps would be involved in converting bitdepth of sound data? Let´s say I have 16bit data and want to convert it to 12bit, would all it takes be, to rescale the values to a smaller range? Would this approach work?

12bitValue = (16bitValue / 0xffff * 0xfff);

Or is it more complicated than that?

Cheers,

At the most basic level, yes that’s it, though note that the audio samples are in the range of +1 to -1 (hence the vertical scale in Audacity).

In practice it is a little more complicated as you need to decide what to do with sample values that do not convert exactly. See here for more information about that: http://en.wikipedia.org/wiki/Dithering#Digital_audio