changeset 4956:ea7519d7649f libavcodec

Factorize usum
author ramiro
date Wed, 09 May 2007 23:08:01 +0000
parents bbe763044678
children 3fcb2f0d9ef1
files pcm.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pcm.c	Wed May 09 22:24:23 2007 +0000
+++ b/pcm.c	Wed May 09 23:08:01 2007 +0000
@@ -169,12 +169,13 @@
  */
 static inline void encode_from16(int bps, int le, int us,
                                short **samples, uint8_t **dst, int n) {
+    int usum = us ? 0x8000 : 0;
     if (bps > 2)
         memset(*dst, 0, n * bps);
     if (le) *dst += bps - 2;
     for(;n>0;n--) {
         register int v = *(*samples)++;
-        if (us) v += 0x8000;
+        v += usum;
         (*dst)[le] = v >> 8;
         (*dst)[1 - le] = v;
         *dst += bps;
@@ -361,10 +362,11 @@
 static inline void decode_to16(int bps, int le, int us,
                                uint8_t **src, short **samples, int src_len)
 {
+    int usum = us ? -0x8000 : 0;
     register int n = src_len / bps;
     if (le) *src += bps - 2;
     for(;n>0;n--) {
-        *(*samples)++ = ((*src)[le] << 8 | (*src)[1 - le]) - (us?0x8000:0);
+        *(*samples)++ = ((*src)[le] << 8 | (*src)[1 - le]) + usum;
         *src += bps;
     }
     if (le) *src -= bps - 2;