]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcm.c
Another PIX_FMT_ ---> IMGFMT_ conversion
[ffmpeg] / libavcodec / pcm.c
index 5a92bd060bcda1d9463e2ca71ad9e2f6d3d862c5..0b4dd1c86bc3d4f5876683d17dd101fd412c5898 100644 (file)
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
 /**
  * @file pcm.c
  * PCM codecs
  */
+
 #include "avcodec.h"
 #include "bitstream.h" // for ff_reverse
 
 /* from g711.c by SUN microsystems (unrestricted use) */
 
-#define        SIGN_BIT        (0x80)          /* Sign bit for a A-law byte. */
-#define        QUANT_MASK      (0xf)           /* Quantization field mask. */
-#define        NSEGS           (8)             /* Number of A-law segments. */
-#define        SEG_SHIFT       (4)             /* Left shift for segment number. */
-#define        SEG_MASK        (0x70)          /* Segment field mask. */
+#define         SIGN_BIT        (0x80)      /* Sign bit for a A-law byte. */
+#define         QUANT_MASK      (0xf)       /* Quantization field mask. */
+#define         NSEGS           (8)         /* Number of A-law segments. */
+#define         SEG_SHIFT       (4)         /* Left shift for segment number. */
+#define         SEG_MASK        (0x70)      /* Segment field mask. */
 
-#define        BIAS            (0x84)          /* Bias for linear code. */
+#define         BIAS            (0x84)      /* Bias for linear code. */
 
 /*
  * alaw2linear() - Convert an A-law value to 16-bit linear PCM
  *
  */
-static int alaw2linear(unsigned char   a_val)
+static int alaw2linear(unsigned char a_val)
 {
-       int             t;
-       int             seg;
+        int t;
+        int seg;
 
-       a_val ^= 0x55;
+        a_val ^= 0x55;
 
-       t = a_val & QUANT_MASK;
-       seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
-       if(seg) t= (t + t + 1 + 32) << (seg + 2);
-       else    t= (t + t + 1     ) << 3;
+        t = a_val & QUANT_MASK;
+        seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
+        if(seg) t= (t + t + 1 + 32) << (seg + 2);
+        else    t= (t + t + 1     ) << 3;
 
-       return ((a_val & SIGN_BIT) ? t : -t);
+        return ((a_val & SIGN_BIT) ? t : -t);
 }
 
-static int ulaw2linear(unsigned char   u_val)
+static int ulaw2linear(unsigned char u_val)
 {
-       int             t;
+        int t;
 
-       /* Complement to obtain normal u-law value. */
-       u_val = ~u_val;
+        /* Complement to obtain normal u-law value. */
+        u_val = ~u_val;
 
-       /*
-        * Extract and bias the quantization bits. Then
-        * shift up by the segment number and subtract out the bias.
-        */
-       t = ((u_val & QUANT_MASK) << 3) + BIAS;
-       t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
+        /*
+         * Extract and bias the quantization bits. Then
+         * shift up by the segment number and subtract out the bias.
+         */
+        t = ((u_val & QUANT_MASK) << 3) + BIAS;
+        t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
 
-       return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
+        return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
 }
 
 /* 16384 entries per table */
@@ -78,9 +78,9 @@ static int linear_to_alaw_ref = 0;
 static uint8_t *linear_to_ulaw = NULL;
 static int linear_to_ulaw_ref = 0;
 
-static void build_xlaw_table(uint8_t *linear_to_xlaw, 
+static void build_xlaw_table(uint8_t *linear_to_xlaw,
                              int (*xlaw2linear)(unsigned char),
-                             int mask) 
+                             int mask)
 {
     int i, j, v, v1, v2;
 
@@ -127,7 +127,7 @@ static int pcm_encode_init(AVCodecContext *avctx)
     default:
         break;
     }
-    
+
     switch(avctx->codec->id) {
     case CODEC_ID_PCM_S32LE:
     case CODEC_ID_PCM_S32BE:
@@ -160,7 +160,7 @@ static int pcm_encode_init(AVCodecContext *avctx)
 
     avctx->coded_frame= avcodec_alloc_frame();
     avctx->coded_frame->key_frame= 1;
-    
+
     return 0;
 }
 
@@ -188,6 +188,7 @@ static int pcm_encode_close(AVCodecContext *avctx)
  * \brief convert samples from 16 bit
  * \param bps byte per sample for the destination format, must be >= 2
  * \param le 0 for big-, 1 for little-endian
+ * \param us 0 for signed, 1 for unsigned output
  * \param samples input samples
  * \param dst output samples
  * \param n number of samples in samples buffer.
@@ -208,7 +209,7 @@ static inline void encode_from16(int bps, int le, int us,
 }
 
 static int pcm_encode_frame(AVCodecContext *avctx,
-                           unsigned char *frame, int buf_size, void *data)
+                            unsigned char *frame, int buf_size, void *data)
 {
     int n, sample_size, v;
     short *samples;
@@ -378,6 +379,7 @@ static int pcm_decode_init(AVCodecContext * avctx)
  * \brief convert samples to 16 bit
  * \param bps byte per sample for the source format, must be >= 2
  * \param le 0 for big-, 1 for little-endian
+ * \param us 0 for signed, 1 for unsigned input
  * \param src input samples
  * \param samples output samples
  * \param src_len number of bytes in src
@@ -395,8 +397,8 @@ static inline void decode_to16(int bps, int le, int us,
 }
 
 static int pcm_decode_frame(AVCodecContext *avctx,
-                           void *data, int *data_size,
-                           uint8_t *buf, int buf_size)
+                            void *data, int *data_size,
+                            uint8_t *buf, int buf_size)
 {
     PCMDecode *s = avctx->priv_data;
     int n;
@@ -507,9 +509,9 @@ AVCodec name ## _encoder = {                    \
     CODEC_TYPE_AUDIO,                           \
     id,                                         \
     0,                                          \
-    pcm_encode_init,                           \
-    pcm_encode_frame,                          \
-    pcm_encode_close,                          \
+    pcm_encode_init,                            \
+    pcm_encode_frame,                           \
+    pcm_encode_close,                           \
     NULL,                                       \
 };                                              \
 AVCodec name ## _decoder = {                    \
@@ -517,7 +519,7 @@ AVCodec name ## _decoder = {                    \
     CODEC_TYPE_AUDIO,                           \
     id,                                         \
     sizeof(PCMDecode),                          \
-    pcm_decode_init,                           \
+    pcm_decode_init,                            \
     NULL,                                       \
     NULL,                                       \
     pcm_decode_frame,                           \