comparison pcm.c @ 2979:bfabfdf9ce55 libavcodec

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents ef2149182f1c
children 0b546eab515d
comparison
equal deleted inserted replaced
2978:403183bbb505 2979:bfabfdf9ce55
25 #include "avcodec.h" 25 #include "avcodec.h"
26 #include "bitstream.h" // for ff_reverse 26 #include "bitstream.h" // for ff_reverse
27 27
28 /* from g711.c by SUN microsystems (unrestricted use) */ 28 /* from g711.c by SUN microsystems (unrestricted use) */
29 29
30 #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ 30 #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
31 #define QUANT_MASK (0xf) /* Quantization field mask. */ 31 #define QUANT_MASK (0xf) /* Quantization field mask. */
32 #define NSEGS (8) /* Number of A-law segments. */ 32 #define NSEGS (8) /* Number of A-law segments. */
33 #define SEG_SHIFT (4) /* Left shift for segment number. */ 33 #define SEG_SHIFT (4) /* Left shift for segment number. */
34 #define SEG_MASK (0x70) /* Segment field mask. */ 34 #define SEG_MASK (0x70) /* Segment field mask. */
35 35
36 #define BIAS (0x84) /* Bias for linear code. */ 36 #define BIAS (0x84) /* Bias for linear code. */
37 37
38 /* 38 /*
39 * alaw2linear() - Convert an A-law value to 16-bit linear PCM 39 * alaw2linear() - Convert an A-law value to 16-bit linear PCM
40 * 40 *
41 */ 41 */
42 static int alaw2linear(unsigned char a_val) 42 static int alaw2linear(unsigned char a_val)
43 { 43 {
44 int t; 44 int t;
45 int seg; 45 int seg;
46 46
47 a_val ^= 0x55; 47 a_val ^= 0x55;
48 48
49 t = a_val & QUANT_MASK; 49 t = a_val & QUANT_MASK;
50 seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; 50 seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
51 if(seg) t= (t + t + 1 + 32) << (seg + 2); 51 if(seg) t= (t + t + 1 + 32) << (seg + 2);
52 else t= (t + t + 1 ) << 3; 52 else t= (t + t + 1 ) << 3;
53 53
54 return ((a_val & SIGN_BIT) ? t : -t); 54 return ((a_val & SIGN_BIT) ? t : -t);
55 } 55 }
56 56
57 static int ulaw2linear(unsigned char u_val) 57 static int ulaw2linear(unsigned char u_val)
58 { 58 {
59 int t; 59 int t;
60 60
61 /* Complement to obtain normal u-law value. */ 61 /* Complement to obtain normal u-law value. */
62 u_val = ~u_val; 62 u_val = ~u_val;
63 63
64 /* 64 /*
65 * Extract and bias the quantization bits. Then 65 * Extract and bias the quantization bits. Then
66 * shift up by the segment number and subtract out the bias. 66 * shift up by the segment number and subtract out the bias.
67 */ 67 */
68 t = ((u_val & QUANT_MASK) << 3) + BIAS; 68 t = ((u_val & QUANT_MASK) << 3) + BIAS;
69 t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; 69 t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
70 70
71 return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); 71 return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
72 } 72 }
73 73
74 /* 16384 entries per table */ 74 /* 16384 entries per table */
75 static uint8_t *linear_to_alaw = NULL; 75 static uint8_t *linear_to_alaw = NULL;
76 static int linear_to_alaw_ref = 0; 76 static int linear_to_alaw_ref = 0;
207 } 207 }
208 if (le) *dst -= bps - 2; 208 if (le) *dst -= bps - 2;
209 } 209 }
210 210
211 static int pcm_encode_frame(AVCodecContext *avctx, 211 static int pcm_encode_frame(AVCodecContext *avctx,
212 unsigned char *frame, int buf_size, void *data) 212 unsigned char *frame, int buf_size, void *data)
213 { 213 {
214 int n, sample_size, v; 214 int n, sample_size, v;
215 short *samples; 215 short *samples;
216 unsigned char *dst; 216 unsigned char *dst;
217 217
395 } 395 }
396 if (le) *src -= bps - 2; 396 if (le) *src -= bps - 2;
397 } 397 }
398 398
399 static int pcm_decode_frame(AVCodecContext *avctx, 399 static int pcm_decode_frame(AVCodecContext *avctx,
400 void *data, int *data_size, 400 void *data, int *data_size,
401 uint8_t *buf, int buf_size) 401 uint8_t *buf, int buf_size)
402 { 402 {
403 PCMDecode *s = avctx->priv_data; 403 PCMDecode *s = avctx->priv_data;
404 int n; 404 int n;
405 short *samples; 405 short *samples;
406 uint8_t *src; 406 uint8_t *src;
507 AVCodec name ## _encoder = { \ 507 AVCodec name ## _encoder = { \
508 #name, \ 508 #name, \
509 CODEC_TYPE_AUDIO, \ 509 CODEC_TYPE_AUDIO, \
510 id, \ 510 id, \
511 0, \ 511 0, \
512 pcm_encode_init, \ 512 pcm_encode_init, \
513 pcm_encode_frame, \ 513 pcm_encode_frame, \
514 pcm_encode_close, \ 514 pcm_encode_close, \
515 NULL, \ 515 NULL, \
516 }; \ 516 }; \
517 AVCodec name ## _decoder = { \ 517 AVCodec name ## _decoder = { \
518 #name, \ 518 #name, \
519 CODEC_TYPE_AUDIO, \ 519 CODEC_TYPE_AUDIO, \
520 id, \ 520 id, \
521 sizeof(PCMDecode), \ 521 sizeof(PCMDecode), \
522 pcm_decode_init, \ 522 pcm_decode_init, \
523 NULL, \ 523 NULL, \
524 NULL, \ 524 NULL, \
525 pcm_decode_frame, \ 525 pcm_decode_frame, \
526 } 526 }
527 527