xbmc/xbmc — pull request #3008 by herrnst (2013-07-25 17:20:43+00:00)
Title: paplayer: fix gain for mp3 files

This will make MP3 (and possibly MP1/MP2, don't have any files encoded as L1/L2 for testing) files played via paplayer reproduced with correct gain/loudness.

Some background:
I wondered for a long time why any of my mp3 files are replayed with reduced volume/gain, while any other format (FLAC, Vorbis et al) played back right, compared with any other audio player (e.g. Audacious, WinAMP or "lame --decode"), and wasn't able to improve by playing with ReplayGain settings or "audiophile=1". After looking at how libmad works and paplayer/MP3codec.cpp handles this, I found samples are bitshifted (converted) from mad's fixfloat (28bit) to AE_32bit_signed one bit off. While this saves some CPU cycles by not having to apply clipping, it results in reduced gain. Normally, the applied clipping shouldn't be neccessary at all or at least very seldom (the way mp3 works causes some clipping anyway at maxgain source files) and happens with any audio player, and the increased precision is still there with this commit.

Compiled and tested on linux with SoftAE in "analog" and "hdmi" mode (guess other engines and platforms will just work)

(Yes, the clipping is duplicated code, but I preferred this to be inline to save the cycles of function calling, and I didn't get this into a macro/#define...)