• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/pcm_tablegen.h

Go to the documentation of this file.
00001 /*
00002  * Header file for hardcoded PCM tables
00003  *
00004  * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #ifndef PCM_TABLEGEN_H
00024 #define PCM_TABLEGEN_H
00025 
00026 #include <stdint.h>
00027 #include "../libavutil/attributes.h"
00028 
00029 /* from g711.c by SUN microsystems (unrestricted use) */
00030 
00031 #define         SIGN_BIT        (0x80)      /* Sign bit for a A-law byte. */
00032 #define         QUANT_MASK      (0xf)       /* Quantization field mask. */
00033 #define         NSEGS           (8)         /* Number of A-law segments. */
00034 #define         SEG_SHIFT       (4)         /* Left shift for segment number. */
00035 #define         SEG_MASK        (0x70)      /* Segment field mask. */
00036 
00037 #define         BIAS            (0x84)      /* Bias for linear code. */
00038 
00039 /*
00040  * alaw2linear() - Convert an A-law value to 16-bit linear PCM
00041  *
00042  */
00043 static av_cold int alaw2linear(unsigned char a_val)
00044 {
00045         int t;
00046         int seg;
00047 
00048         a_val ^= 0x55;
00049 
00050         t = a_val & QUANT_MASK;
00051         seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
00052         if(seg) t= (t + t + 1 + 32) << (seg + 2);
00053         else    t= (t + t + 1     ) << 3;
00054 
00055         return (a_val & SIGN_BIT) ? t : -t;
00056 }
00057 
00058 static av_cold int ulaw2linear(unsigned char u_val)
00059 {
00060         int t;
00061 
00062         /* Complement to obtain normal u-law value. */
00063         u_val = ~u_val;
00064 
00065         /*
00066          * Extract and bias the quantization bits. Then
00067          * shift up by the segment number and subtract out the bias.
00068          */
00069         t = ((u_val & QUANT_MASK) << 3) + BIAS;
00070         t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
00071 
00072         return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
00073 }
00074 
00075 #if CONFIG_HARDCODED_TABLES
00076 #define pcm_alaw_tableinit()
00077 #define pcm_ulaw_tableinit()
00078 #include "libavcodec/pcm_tables.h"
00079 #else
00080 /* 16384 entries per table */
00081 static uint8_t linear_to_alaw[16384];
00082 static uint8_t linear_to_ulaw[16384];
00083 
00084 static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
00085                              int (*xlaw2linear)(unsigned char),
00086                              int mask)
00087 {
00088     int i, j, v, v1, v2;
00089 
00090     j = 0;
00091     for(i=0;i<128;i++) {
00092         if (i != 127) {
00093             v1 = xlaw2linear(i ^ mask);
00094             v2 = xlaw2linear((i + 1) ^ mask);
00095             v = (v1 + v2 + 4) >> 3;
00096         } else {
00097             v = 8192;
00098         }
00099         for(;j<v;j++) {
00100             linear_to_xlaw[8192 + j] = (i ^ mask);
00101             if (j > 0)
00102                 linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
00103         }
00104     }
00105     linear_to_xlaw[0] = linear_to_xlaw[1];
00106 }
00107 
00108 static void pcm_alaw_tableinit(void)
00109 {
00110     build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
00111 }
00112 
00113 static void pcm_ulaw_tableinit(void)
00114 {
00115     build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
00116 }
00117 #endif /* CONFIG_HARDCODED_TABLES */
00118 
00119 #endif /* PCM_TABLEGEN_H */

Generated on Fri Sep 16 2011 17:17:41 for FFmpeg by  doxygen 1.7.1