]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcm.c
GCC4 fix by (Keenan Pepper (keenanpepper gmail com)
[ffmpeg] / libavcodec / pcm.c
index 48adccf2d2ab4935cab1421da68ddabebad07d36..8e57d11a1c50db07590a5197544e80c7a5946d6d 100644 (file)
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/**
+ * @file pcm.c
+ * PCM codecs
+ */
 #include "avcodec.h"
 
 /* from g711.c by SUN microsystems (unrestricted use) */
@@ -39,19 +45,11 @@ static int alaw2linear(unsigned char        a_val)
 
        a_val ^= 0x55;
 
-       t = (a_val & QUANT_MASK) << 4;
+       t = a_val & QUANT_MASK;
        seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
-       switch (seg) {
-       case 0:
-               t += 8;
-               break;
-       case 1:
-               t += 0x108;
-               break;
-       default:
-               t += 0x108;
-               t <<= seg - 1;
-       }
+       if(seg) t= (t + t + 1 + 32) << (seg + 2);
+       else    t= (t + t + 1     ) << 3;
+
        return ((a_val & SIGN_BIT) ? t : -t);
 }
 
@@ -73,13 +71,13 @@ static int ulaw2linear(unsigned char        u_val)
 }
 
 /* 16384 entries per table */
-static UINT8 *linear_to_alaw = NULL;
+static uint8_t *linear_to_alaw = NULL;
 static int linear_to_alaw_ref = 0;
 
-static UINT8 *linear_to_ulaw = NULL;
+static uint8_t *linear_to_ulaw = NULL;
 static int linear_to_ulaw_ref = 0;
 
-static void build_xlaw_table(UINT8 *linear_to_xlaw, 
+static void build_xlaw_table(uint8_t *linear_to_xlaw, 
                              int (*xlaw2linear)(unsigned char),
                              int mask) 
 {
@@ -129,6 +127,23 @@ static int pcm_encode_init(AVCodecContext *avctx)
         break;
     }
     
+    switch(avctx->codec->id) {
+    case CODEC_ID_PCM_S16LE:
+    case CODEC_ID_PCM_S16BE:
+    case CODEC_ID_PCM_U16LE:
+    case CODEC_ID_PCM_U16BE:
+        avctx->block_align = 2 * avctx->channels;
+        break;
+    case CODEC_ID_PCM_S8:
+    case CODEC_ID_PCM_U8:
+    case CODEC_ID_PCM_MULAW:
+    case CODEC_ID_PCM_ALAW:
+        avctx->block_align = avctx->channels;
+        break;
+    default:
+        break;
+    }
+
     avctx->coded_frame= avcodec_alloc_frame();
     avctx->coded_frame->key_frame= 1;
     
@@ -274,16 +289,19 @@ static int pcm_decode_init(AVCodecContext * avctx)
 
 static int pcm_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
-                           UINT8 *buf, int buf_size)
+                           uint8_t *buf, int buf_size)
 {
     PCMDecode *s = avctx->priv_data;
     int n;
     short *samples;
-    UINT8 *src;
+    uint8_t *src;
 
     samples = data;
     src = buf;
 
+    if(buf_size > AVCODEC_MAX_AUDIO_FRAME_SIZE/2)
+        buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE/2;
+
     switch(avctx->codec->id) {
     case CODEC_ID_PCM_S16LE:
         n = buf_size >> 1;
@@ -336,10 +354,9 @@ static int pcm_decode_frame(AVCodecContext *avctx,
         }
         break;
     default:
-        *data_size = 0;
         return -1;
     }
-    *data_size = (UINT8 *)samples - (UINT8 *)data;
+    *data_size = (uint8_t *)samples - (uint8_t *)data;
     return src - buf;
 }