diff options
author | James Courtier-Dutton <jcdutton@users.sourceforge.net> | 2004-03-08 18:33:54 +0000 |
---|---|---|
committer | James Courtier-Dutton <jcdutton@users.sourceforge.net> | 2004-03-08 18:33:54 +0000 |
commit | 80d3b5784ab6ed42a49974a71c4a21e01b9b9f1d (patch) | |
tree | bdd4301ea4a9903975457c7cc9f6f199e40a60f0 | |
parent | 9546d76f10064826572f56bd7ea2b2bc78ce8806 (diff) | |
download | xine-lib-80d3b5784ab6ed42a49974a71c4a21e01b9b9f1d.tar.gz xine-lib-80d3b5784ab6ed42a49974a71c4a21e01b9b9f1d.tar.bz2 |
Limit software amp so that audio is not clipped.
CVS patchset: 6234
CVS date: 2004/03/08 18:33:54
-rw-r--r-- | src/xine-engine/audio_out.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 3273d3f55..4e66b4ad8 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -17,7 +17,7 @@ * along with self program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: audio_out.c,v 1.164 2004/03/03 20:09:16 mroi Exp $ + * $Id: audio_out.c,v 1.165 2004/03/08 18:33:54 jcdutton Exp $ * * 22-8-2001 James imported some useful AC3 sections from the previous alsa driver. * (c) 2001 Andy Lo A Foe <andy@alsaplayer.org> @@ -540,6 +540,7 @@ static void audio_filter_amp (aos_t *this, int16_t *mem, int num_frames) { int i; int num_channels; double amp_factor; + int32_t test; num_channels = _x_ao_mode2channels (this->input.mode); if (!num_channels) @@ -549,7 +550,18 @@ static void audio_filter_amp (aos_t *this, int16_t *mem, int num_frames) { if (this->amp_mute) amp_factor=0.0; for (i=0; i<num_frames*num_channels; i++) { - mem[i] = mem[i] * amp_factor; + test = mem[i] * amp_factor; +/* Force limit on amp_factor to prevent clipping */ + if (test < INT16_MIN) { + this->amp_factor = amp_factor = amp_factor * INT16_MIN / test; + test=INT16_MIN; + } + if (test > INT16_MAX) { + this->amp_factor = amp_factor = amp_factor * INT16_MIN / test; + test=INT16_MAX; + } + mem[i] = test; + } } |