changeset 4959:e00e16be833a libavcodec

Use bytestream
author ramiro
date Wed, 09 May 2007 23:21:07 +0000
parents 842b30b88d9a
children 1745d0452e87
files pcm.c
diffstat 1 files changed, 11 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/pcm.c	Wed May 09 23:15:19 2007 +0000
+++ b/pcm.c	Wed May 09 23:21:07 2007 +0000
@@ -26,6 +26,7 @@
 
 #include "avcodec.h"
 #include "bitstream.h" // for ff_reverse
+#include "bytestream.h"
 
 /* from g711.c by SUN microsystems (unrestricted use) */
 
@@ -248,46 +249,34 @@
             uint32_t tmp = ff_reverse[*samples >> 8] +
                            (ff_reverse[*samples & 0xff] << 8);
             tmp <<= 4; // sync flags would go here
-            dst[2] = tmp & 0xff;
-            tmp >>= 8;
-            dst[1] = tmp & 0xff;
-            dst[0] = tmp >> 8;
+            bytestream_put_be24(&dst, tmp);
             samples++;
-            dst += 3;
         }
         break;
     case CODEC_ID_PCM_S16LE:
         for(;n>0;n--) {
             v = *samples++;
-            dst[0] = v & 0xff;
-            dst[1] = v >> 8;
-            dst += 2;
+            bytestream_put_le16(&dst, v);
         }
         break;
     case CODEC_ID_PCM_S16BE:
         for(;n>0;n--) {
             v = *samples++;
-            dst[0] = v >> 8;
-            dst[1] = v;
-            dst += 2;
+            bytestream_put_be16(&dst, v);
         }
         break;
     case CODEC_ID_PCM_U16LE:
         for(;n>0;n--) {
             v = *samples++;
             v += 0x8000;
-            dst[0] = v & 0xff;
-            dst[1] = v >> 8;
-            dst += 2;
+            bytestream_put_le16(&dst, v);
         }
         break;
     case CODEC_ID_PCM_U16BE:
         for(;n>0;n--) {
             v = *samples++;
             v += 0x8000;
-            dst[0] = v >> 8;
-            dst[1] = v;
-            dst += 2;
+            bytestream_put_be16(&dst, v);
         }
         break;
     case CODEC_ID_PCM_S8:
@@ -425,39 +414,34 @@
     case CODEC_ID_PCM_S24DAUD:
         n = buf_size / 3;
         for(;n>0;n--) {
-          uint32_t v = src[0] << 16 | src[1] << 8 | src[2];
+          uint32_t v = bytestream_get_be24(&src);
           v >>= 4; // sync flags are here
           *samples++ = ff_reverse[(v >> 8) & 0xff] +
                        (ff_reverse[v & 0xff] << 8);
-          src += 3;
         }
         break;
     case CODEC_ID_PCM_S16LE:
         n = buf_size >> 1;
         for(;n>0;n--) {
-            *samples++ = src[0] | (src[1] << 8);
-            src += 2;
+            *samples++ = bytestream_get_le16(&src);
         }
         break;
     case CODEC_ID_PCM_S16BE:
         n = buf_size >> 1;
         for(;n>0;n--) {
-            *samples++ = (src[0] << 8) | src[1];
-            src += 2;
+            *samples++ = bytestream_get_be16(&src);
         }
         break;
     case CODEC_ID_PCM_U16LE:
         n = buf_size >> 1;
         for(;n>0;n--) {
-            *samples++ = (src[0] | (src[1] << 8)) - 0x8000;
-            src += 2;
+            *samples++ = bytestream_get_le16(&src) - 0x8000;
         }
         break;
     case CODEC_ID_PCM_U16BE:
         n = buf_size >> 1;
         for(;n>0;n--) {
-            *samples++ = ((src[0] << 8) | src[1]) - 0x8000;
-            src += 2;
+            *samples++ = bytestream_get_be16(&src) - 0x8000;
         }
         break;
     case CODEC_ID_PCM_S8: