annotate ffmpeg/libavcodec/pcm_tablegen.h @ 13:844d341cf643 tip

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