pcm_tablegen.h
Go to the documentation of this file.
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 /*
40  * alaw2linear() - Convert an A-law value to 16-bit linear PCM
41  *
42  */
43 static av_cold int alaw2linear(unsigned char a_val)
44 {
45  int t;
46  int seg;
47 
48  a_val ^= 0x55;
49 
50  t = a_val & QUANT_MASK;
51  seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
52  if(seg) t= (t + t + 1 + 32) << (seg + 2);
53  else t= (t + t + 1 ) << 3;
54 
55  return (a_val & SIGN_BIT) ? t : -t;
56 }
57 
58 static av_cold int ulaw2linear(unsigned char u_val)
59 {
60  int t;
61 
62  /* Complement to obtain normal u-law value. */
63  u_val = ~u_val;
64 
65  /*
66  * Extract and bias the quantization bits. Then
67  * shift up by the segment number and subtract out the bias.
68  */
69  t = ((u_val & QUANT_MASK) << 3) + BIAS;
70  t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
71 
72  return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
73 }
74 
75 #if CONFIG_HARDCODED_TABLES
76 #define pcm_alaw_tableinit()
77 #define pcm_ulaw_tableinit()
78 #include "libavcodec/pcm_tables.h"
79 #else
80 /* 16384 entries per table */
81 static uint8_t linear_to_alaw[16384];
82 static uint8_t linear_to_ulaw[16384];
83 
84 static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
85  int (*xlaw2linear)(unsigned char),
86  int mask)
87 {
88  int i, j, v, v1, v2;
89 
90  j = 0;
91  for(i=0;i<128;i++) {
92  if (i != 127) {
93  v1 = xlaw2linear(i ^ mask);
94  v2 = xlaw2linear((i + 1) ^ mask);
95  v = (v1 + v2 + 4) >> 3;
96  } else {
97  v = 8192;
98  }
99  for(;j<v;j++) {
100  linear_to_xlaw[8192 + j] = (i ^ mask);
101  if (j > 0)
102  linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
103  }
104  }
105  linear_to_xlaw[0] = linear_to_xlaw[1];
106 }
107 
108 static void pcm_alaw_tableinit(void)
109 {
111 }
112 
113 static void pcm_ulaw_tableinit(void)
114 {
116 }
117 #endif /* CONFIG_HARDCODED_TABLES */
118 
119 #endif /* AVCODEC_PCM_TABLEGEN_H */
float v
static void pcm_alaw_tableinit(void)
Definition: pcm_tablegen.h:108
static void pcm_ulaw_tableinit(void)
Definition: pcm_tablegen.h:113
static av_cold int ulaw2linear(unsigned char u_val)
Definition: pcm_tablegen.h:58
Macro definitions for various function/variable attributes.
uint8_t
#define av_cold
Definition: attributes.h:78
#define SEG_SHIFT
Definition: pcm_tablegen.h:34
static uint8_t linear_to_ulaw[16384]
Definition: pcm_tablegen.h:82
#define SEG_MASK
Definition: pcm_tablegen.h:35
static const uint16_t mask[17]
Definition: lzw.c:37
static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw, int(*xlaw2linear)(unsigned char), int mask)
Definition: pcm_tablegen.h:84
#define BIAS
Definition: pcm_tablegen.h:37
static av_cold int alaw2linear(unsigned char a_val)
Definition: pcm_tablegen.h:43
#define SIGN_BIT
Definition: pcm_tablegen.h:31
t
Definition: genspecsines3.m:6
synthesis window for stochastic i
#define QUANT_MASK
Definition: pcm_tablegen.h:32
static uint8_t linear_to_alaw[16384]
Definition: pcm_tablegen.h:81