annotate pcm_tablegen.h @ 12295:bb7b7602b40e libavcodec

Map rc_buffer_size to and c_initial_buffer_occupancy to their libvpx counterparts. Patch by James Zern, jzern at google
author cehoyos
date Wed, 28 Jul 2010 08:02:35 +0000
parents 4b2300246240
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11571
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
1 /*
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
2 * Header file for hardcoded PCM tables
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
3 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
4 * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
5 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
6 * This file is part of FFmpeg.
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
7 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
12 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
16 * Lesser General Public License for more details.
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
17 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
21 */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
22
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
23 #ifndef PCM_TABLEGEN_H
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
24 #define PCM_TABLEGEN_H
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
25
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
26 #include <stdint.h>
11967
4b2300246240 Remove unnecessary ../ from include directives
mru
parents: 11571
diff changeset
27 #include "libavutil/attributes.h"
11571
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
28
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
29 /* from g711.c by SUN microsystems (unrestricted use) */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
30
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
31 #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
32 #define QUANT_MASK (0xf) /* Quantization field mask. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
33 #define NSEGS (8) /* Number of A-law segments. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
34 #define SEG_SHIFT (4) /* Left shift for segment number. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
35 #define SEG_MASK (0x70) /* Segment field mask. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
36
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
37 #define BIAS (0x84) /* Bias for linear code. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
38
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
39 /*
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
40 * alaw2linear() - Convert an A-law value to 16-bit linear PCM
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
41 *
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
42 */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
43 static av_cold int alaw2linear(unsigned char a_val)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
44 {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
45 int t;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
46 int seg;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
47
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
48 a_val ^= 0x55;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
49
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
50 t = a_val & QUANT_MASK;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
51 seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
52 if(seg) t= (t + t + 1 + 32) << (seg + 2);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
53 else t= (t + t + 1 ) << 3;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
54
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
55 return (a_val & SIGN_BIT) ? t : -t;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
56 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
57
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
58 static av_cold int ulaw2linear(unsigned char u_val)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
59 {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
60 int t;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
61
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
62 /* Complement to obtain normal u-law value. */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
63 u_val = ~u_val;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
64
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
65 /*
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
66 * Extract and bias the quantization bits. Then
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
67 * shift up by the segment number and subtract out the bias.
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
68 */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
69 t = ((u_val & QUANT_MASK) << 3) + BIAS;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
70 t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
71
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
72 return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
73 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
74
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
75 #if CONFIG_HARDCODED_TABLES
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
76 #define pcm_alaw_tableinit()
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
77 #define pcm_ulaw_tableinit()
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
78 #include "libavcodec/pcm_tables.h"
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
79 #else
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
80 /* 16384 entries per table */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
81 static uint8_t linear_to_alaw[16384];
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
82 static uint8_t linear_to_ulaw[16384];
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
83
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
84 static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
85 int (*xlaw2linear)(unsigned char),
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
86 int mask)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
87 {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
88 int i, j, v, v1, v2;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
89
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
90 j = 0;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
91 for(i=0;i<128;i++) {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
92 if (i != 127) {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
93 v1 = xlaw2linear(i ^ mask);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
94 v2 = xlaw2linear((i + 1) ^ mask);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
95 v = (v1 + v2 + 4) >> 3;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
96 } else {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
97 v = 8192;
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
98 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
99 for(;j<v;j++) {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
100 linear_to_xlaw[8192 + j] = (i ^ mask);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
101 if (j > 0)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
102 linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
103 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
104 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
105 linear_to_xlaw[0] = linear_to_xlaw[1];
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
106 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
107
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
108 static void pcm_alaw_tableinit(void)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
109 {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
110 build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
111 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
112
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
113 static void pcm_ulaw_tableinit(void)
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
114 {
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
115 build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
116 }
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
117 #endif /* CONFIG_HARDCODED_TABLES */
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
118
7d324b40c3d6 Allow hardcoding of ulaw and alaw tables.
reimar
parents:
diff changeset
119 #endif /* PCM_TABLEGEN_H */