LCOV - code coverage report
Current view: top level - libavcodec - pcm_tablegen.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 33 100.0 %
Date: 2017-12-12 03:56:30 Functions: 5 5 100.0 %

          Line data    Source code
       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             : /* alaw2linear() - Convert an A-law value to 16-bit linear PCM */
      40        7668 : static av_cold int alaw2linear(unsigned char a_val)
      41             : {
      42             :         int t;
      43             :         int seg;
      44             : 
      45        7668 :         a_val ^= 0x55;
      46             : 
      47        7668 :         t = a_val & QUANT_MASK;
      48        7668 :         seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
      49        7668 :         if(seg) t= (t + t + 1 + 32) << (seg + 2);
      50         954 :         else    t= (t + t + 1     ) << 3;
      51             : 
      52        7668 :         return (a_val & SIGN_BIT) ? t : -t;
      53             : }
      54             : 
      55        4092 : static av_cold int ulaw2linear(unsigned char u_val)
      56             : {
      57             :         int t;
      58             : 
      59             :         /* Complement to obtain normal u-law value. */
      60        4092 :         u_val = ~u_val;
      61             : 
      62             :         /*
      63             :          * Extract and bias the quantization bits. Then
      64             :          * shift up by the segment number and subtract out the bias.
      65             :          */
      66        4092 :         t = ((u_val & QUANT_MASK) << 3) + BIAS;
      67        4092 :         t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
      68             : 
      69        4092 :         return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
      70             : }
      71             : 
      72             : #if CONFIG_HARDCODED_TABLES
      73             : #define pcm_alaw_tableinit()
      74             : #define pcm_ulaw_tableinit()
      75             : #include "libavcodec/pcm_tables.h"
      76             : #else
      77             : /* 16384 entries per table */
      78             : static uint8_t linear_to_alaw[16384];
      79             : static uint8_t linear_to_ulaw[16384];
      80             : 
      81           8 : static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
      82             :                              int (*xlaw2linear)(unsigned char),
      83             :                              int mask)
      84             : {
      85             :     int i, j, v, v1, v2;
      86             : 
      87           8 :     j = 1;
      88           8 :     linear_to_xlaw[8192] = mask;
      89        1024 :     for(i=0;i<127;i++) {
      90        1016 :         v1 = xlaw2linear(i ^ mask);
      91        1016 :         v2 = xlaw2linear((i + 1) ^ mask);
      92        1016 :         v = (v1 + v2 + 4) >> 3;
      93       64430 :         for(;j<v;j+=1) {
      94       63414 :             linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
      95       63414 :             linear_to_xlaw[8192 + j] = (i ^ mask);
      96             :         }
      97             :     }
      98        2122 :     for(;j<8192;j++) {
      99        2114 :         linear_to_xlaw[8192 - j] = (127 ^ (mask ^ 0x80));
     100        2114 :         linear_to_xlaw[8192 + j] = (127 ^ mask);
     101             :     }
     102           8 :     linear_to_xlaw[0] = linear_to_xlaw[1];
     103           8 : }
     104             : 
     105           6 : static void pcm_alaw_tableinit(void)
     106             : {
     107           6 :     build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
     108           6 : }
     109             : 
     110           2 : static void pcm_ulaw_tableinit(void)
     111             : {
     112           2 :     build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
     113           2 : }
     114             : #endif /* CONFIG_HARDCODED_TABLES */
     115             : 
     116             : #endif /* AVCODEC_PCM_TABLEGEN_H */

Generated by: LCOV version 1.13