Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Header file for hardcoded PCM tables | ||
3 | * | ||
4 | * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de> | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #ifndef AVCODEC_PCM_TABLEGEN_H | ||
24 | #define AVCODEC_PCM_TABLEGEN_H | ||
25 | |||
26 | #include <stdint.h> | ||
27 | #include "libavutil/attributes.h" | ||
28 | |||
29 | /* from g711.c by SUN microsystems (unrestricted use) */ | ||
30 | |||
31 | #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ | ||
32 | #define QUANT_MASK (0xf) /* Quantization field mask. */ | ||
33 | #define NSEGS (8) /* Number of A-law segments. */ | ||
34 | #define SEG_SHIFT (4) /* Left shift for segment number. */ | ||
35 | #define SEG_MASK (0x70) /* Segment field mask. */ | ||
36 | |||
37 | #define BIAS (0x84) /* Bias for linear code. */ | ||
38 | |||
39 | #define VIDC_SIGN_BIT (1) | ||
40 | #define VIDC_QUANT_MASK (0x1E) | ||
41 | #define VIDC_QUANT_SHIFT (1) | ||
42 | #define VIDC_SEG_SHIFT (5) | ||
43 | #define VIDC_SEG_MASK (0xE0) | ||
44 | |||
45 | #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER | ||
46 | /* alaw2linear() - Convert an A-law value to 16-bit linear PCM */ | ||
47 | 8434 | static av_cold int alaw2linear(unsigned char a_val) | |
48 | { | ||
49 | int t; | ||
50 | int seg; | ||
51 | |||
52 | 8434 | a_val ^= 0x55; | |
53 | |||
54 | 8434 | t = a_val & QUANT_MASK; | |
55 | 8434 | seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; | |
56 |
2/2✓ Branch 0 taken 7385 times.
✓ Branch 1 taken 1049 times.
|
8434 | if(seg) t= (t + t + 1 + 32) << (seg + 2); |
57 | 1049 | else t= (t + t + 1 ) << 3; | |
58 | |||
59 |
2/2✓ Branch 0 taken 3328 times.
✓ Branch 1 taken 5106 times.
|
8434 | return (a_val & SIGN_BIT) ? t : -t; |
60 | } | ||
61 | #endif | ||
62 | |||
63 | #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER | ||
64 | 4092 | static av_cold int ulaw2linear(unsigned char u_val) | |
65 | { | ||
66 | int t; | ||
67 | |||
68 | /* Complement to obtain normal u-law value. */ | ||
69 | 4092 | u_val = ~u_val; | |
70 | |||
71 | /* | ||
72 | * Extract and bias the quantization bits. Then | ||
73 | * shift up by the segment number and subtract out the bias. | ||
74 | */ | ||
75 | 4092 | t = ((u_val & QUANT_MASK) << 3) + BIAS; | |
76 | 4092 | t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; | |
77 | |||
78 |
2/2✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 2300 times.
|
4092 | return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS); |
79 | } | ||
80 | #endif | ||
81 | |||
82 | #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER | ||
83 | ✗ | static av_cold int vidc2linear(unsigned char u_val) | |
84 | { | ||
85 | int t; | ||
86 | |||
87 | /* | ||
88 | * Extract and bias the quantization bits. Then | ||
89 | * shift up by the segment number and subtract out the bias. | ||
90 | */ | ||
91 | ✗ | t = (((u_val & VIDC_QUANT_MASK) >> VIDC_QUANT_SHIFT) << 3) + BIAS; | |
92 | ✗ | t <<= ((unsigned)u_val & VIDC_SEG_MASK) >> VIDC_SEG_SHIFT; | |
93 | |||
94 | ✗ | return (u_val & VIDC_SIGN_BIT) ? (BIAS - t) : (t - BIAS); | |
95 | } | ||
96 | #endif | ||
97 | |||
98 | #if CONFIG_HARDCODED_TABLES | ||
99 | #define pcm_alaw_tableinit() | ||
100 | #define pcm_ulaw_tableinit() | ||
101 | #define pcm_vidc_tableinit() | ||
102 | #include "libavcodec/pcm_tables.h" | ||
103 | #else | ||
104 | /* 16384 entries per table */ | ||
105 | #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER | ||
106 | static uint8_t linear_to_alaw[16384]; | ||
107 | #endif | ||
108 | #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER | ||
109 | static uint8_t linear_to_ulaw[16384]; | ||
110 | #endif | ||
111 | #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER | ||
112 | static uint8_t linear_to_vidc[16384]; | ||
113 | #endif | ||
114 | |||
115 | #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER || \ | ||
116 | CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \ | ||
117 | CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER | ||
118 | 9 | static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw, | |
119 | int (*xlaw2linear)(unsigned char), | ||
120 | int mask) | ||
121 | { | ||
122 | int i, j, v, v1, v2; | ||
123 | |||
124 | 9 | j = 1; | |
125 | 9 | linear_to_xlaw[8192] = mask; | |
126 |
2/2✓ Branch 0 taken 1143 times.
✓ Branch 1 taken 9 times.
|
1152 | for(i=0;i<127;i++) { |
127 | 1143 | v1 = xlaw2linear(i ^ mask); | |
128 | 1143 | v2 = xlaw2linear((i + 1) ^ mask); | |
129 | 1143 | v = (v1 + v2 + 4) >> 3; | |
130 |
2/2✓ Branch 0 taken 71349 times.
✓ Branch 1 taken 1143 times.
|
72492 | for(;j<v;j+=1) { |
131 | 71349 | linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80)); | |
132 | 71349 | linear_to_xlaw[8192 + j] = (i ^ mask); | |
133 | } | ||
134 | } | ||
135 |
2/2✓ Branch 0 taken 2370 times.
✓ Branch 1 taken 9 times.
|
2379 | for(;j<8192;j++) { |
136 | 2370 | linear_to_xlaw[8192 - j] = (127 ^ (mask ^ 0x80)); | |
137 | 2370 | linear_to_xlaw[8192 + j] = (127 ^ mask); | |
138 | } | ||
139 | 9 | linear_to_xlaw[0] = linear_to_xlaw[1]; | |
140 | 9 | } | |
141 | #endif | ||
142 | |||
143 | #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER | ||
144 | 7 | static void pcm_alaw_tableinit(void) | |
145 | { | ||
146 | 7 | build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5); | |
147 | 7 | } | |
148 | #endif | ||
149 | |||
150 | #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER | ||
151 | 2 | static void pcm_ulaw_tableinit(void) | |
152 | { | ||
153 | 2 | build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff); | |
154 | 2 | } | |
155 | #endif | ||
156 | |||
157 | #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER | ||
158 | ✗ | static void pcm_vidc_tableinit(void) | |
159 | { | ||
160 | ✗ | build_xlaw_table(linear_to_vidc, vidc2linear, 0xff); | |
161 | ✗ | } | |
162 | #endif | ||
163 | #endif /* CONFIG_HARDCODED_TABLES */ | ||
164 | |||
165 | #endif /* AVCODEC_PCM_TABLEGEN_H */ | ||
166 |