diff options
| author | Dave Chapman <dave@dchapman.com> | 2007-03-22 22:47:04 +0000 |
|---|---|---|
| committer | Dave Chapman <dave@dchapman.com> | 2007-03-22 22:47:04 +0000 |
| commit | 8b4076955451df160593f7d3a345801015aec039 (patch) | |
| tree | d048afbff22c2794aec525532209f7abe05a62de /apps/plugins | |
| parent | 176cd65e4ced87affdd9d32ed0e21c44156a57f8 (diff) | |
| download | rockbox-8b4076955451df160593f7d3a345801015aec039.zip rockbox-8b4076955451df160593f7d3a345801015aec039.tar.gz rockbox-8b4076955451df160593f7d3a345801015aec039.tar.bz2 rockbox-8b4076955451df160593f7d3a345801015aec039.tar.xz | |
Clamp output when converting from libmad's s3.28 format to 16-bit integers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12894 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
| -rw-r--r-- | apps/plugins/mpegplayer/mpegplayer.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c index d4f40ac..aa5f162 100644 --- a/apps/plugins/mpegplayer/mpegplayer.c +++ b/apps/plugins/mpegplayer/mpegplayer.c @@ -555,6 +555,7 @@ static void audio_thread(void) { int32_t* left; int32_t* right; + int32_t sample; int i; size_t n = 0; size_t len; @@ -655,15 +656,33 @@ static void audio_thread(void) left = &synth.pcm.samples[0][0]; right = &synth.pcm.samples[1][0]; for (i = 0 ; i < framelength; i++) { - *(pcmbuf_head++) = *(left++) >> 13; - *(pcmbuf_head++) = *(right++) >> 13; + /* libmad outputs s3.28 */ + sample = *(left++) >> 13; + if (sample > 32767) + sample = 32767; + else if (sample < -32768) + sample = -32768; + *(pcmbuf_head++) = sample; + + sample = *(right++) >> 13; + if (sample > 32767) + sample = 32767; + else if (sample < -32768) + sample = -32768; + *(pcmbuf_head++) = sample; + if (pcmbuf_head >= pcmbuf_end) { pcmbuf_head = pcm_buffer; } } } else { /* mono */ - int16_t sample; left = &synth.pcm.samples[0][0]; for (i = 0 ; i < framelength; i++) { sample = *(left++) >> 13; + + if (sample > 32767) + sample = 32767; + else if (sample < -32768) + sample = -32768; + *(pcmbuf_head++) = sample; *(pcmbuf_head++) = sample; if (pcmbuf_head >= pcmbuf_end) { pcmbuf_head = pcm_buffer; } |