2010-04-01 20:54:15 +03:00
|
|
|
/*
|
|
|
|
* Header file for hardcoded PCM tables
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2011-05-17 17:58:04 +03:00
|
|
|
#ifndef AVCODEC_PCM_TABLEGEN_H
|
|
|
|
#define AVCODEC_PCM_TABLEGEN_H
|
2010-04-01 20:54:15 +03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2010-06-26 23:28:44 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2010-04-01 20:54:15 +03:00
|
|
|
|
|
|
|
/* from g711.c by SUN microsystems (unrestricted use) */
|
|
|
|
|
|
|
|
#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
|
|
|
|
#define QUANT_MASK (0xf) /* Quantization field mask. */
|
|
|
|
#define NSEGS (8) /* Number of A-law segments. */
|
|
|
|
#define SEG_SHIFT (4) /* Left shift for segment number. */
|
|
|
|
#define SEG_MASK (0x70) /* Segment field mask. */
|
|
|
|
|
|
|
|
#define BIAS (0x84) /* Bias for linear code. */
|
|
|
|
|
2018-10-13 01:06:39 +02:00
|
|
|
#define VIDC_SIGN_BIT (1)
|
|
|
|
#define VIDC_QUANT_MASK (0x1E)
|
|
|
|
#define VIDC_QUANT_SHIFT (1)
|
|
|
|
#define VIDC_SEG_SHIFT (5)
|
|
|
|
#define VIDC_SEG_MASK (0xE0)
|
|
|
|
|
2016-02-16 19:01:29 +02:00
|
|
|
/* alaw2linear() - Convert an A-law value to 16-bit linear PCM */
|
2010-04-01 20:54:15 +03:00
|
|
|
static av_cold int alaw2linear(unsigned char a_val)
|
|
|
|
{
|
2020-02-14 22:22:08 +02:00
|
|
|
int t;
|
|
|
|
int seg;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
a_val ^= 0x55;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
t = a_val & QUANT_MASK;
|
|
|
|
seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
|
|
|
|
if(seg) t= (t + t + 1 + 32) << (seg + 2);
|
|
|
|
else t= (t + t + 1 ) << 3;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
return (a_val & SIGN_BIT) ? t : -t;
|
2010-04-01 20:54:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int ulaw2linear(unsigned char u_val)
|
|
|
|
{
|
2020-02-14 22:22:08 +02:00
|
|
|
int t;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
/* Complement to obtain normal u-law value. */
|
|
|
|
u_val = ~u_val;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
/*
|
|
|
|
* Extract and bias the quantization bits. Then
|
|
|
|
* shift up by the segment number and subtract out the bias.
|
|
|
|
*/
|
|
|
|
t = ((u_val & QUANT_MASK) << 3) + BIAS;
|
|
|
|
t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
|
2010-04-01 20:54:15 +03:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
|
2010-04-01 20:54:15 +03:00
|
|
|
}
|
|
|
|
|
2018-10-13 01:06:39 +02:00
|
|
|
static av_cold int vidc2linear(unsigned char u_val)
|
|
|
|
{
|
2020-02-14 22:22:08 +02:00
|
|
|
int t;
|
2018-10-13 01:06:39 +02:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
/*
|
|
|
|
* Extract and bias the quantization bits. Then
|
|
|
|
* shift up by the segment number and subtract out the bias.
|
|
|
|
*/
|
|
|
|
t = (((u_val & VIDC_QUANT_MASK) >> VIDC_QUANT_SHIFT) << 3) + BIAS;
|
|
|
|
t <<= ((unsigned)u_val & VIDC_SEG_MASK) >> VIDC_SEG_SHIFT;
|
2018-10-13 01:06:39 +02:00
|
|
|
|
2020-02-14 22:22:08 +02:00
|
|
|
return (u_val & VIDC_SIGN_BIT) ? (BIAS - t) : (t - BIAS);
|
2018-10-13 01:06:39 +02:00
|
|
|
}
|
|
|
|
|
2010-04-01 20:54:15 +03:00
|
|
|
#if CONFIG_HARDCODED_TABLES
|
|
|
|
#define pcm_alaw_tableinit()
|
|
|
|
#define pcm_ulaw_tableinit()
|
2018-10-13 01:06:39 +02:00
|
|
|
#define pcm_vidc_tableinit()
|
2010-04-01 20:54:15 +03:00
|
|
|
#include "libavcodec/pcm_tables.h"
|
|
|
|
#else
|
|
|
|
/* 16384 entries per table */
|
|
|
|
static uint8_t linear_to_alaw[16384];
|
|
|
|
static uint8_t linear_to_ulaw[16384];
|
2018-10-13 01:06:39 +02:00
|
|
|
static uint8_t linear_to_vidc[16384];
|
2010-04-01 20:54:15 +03:00
|
|
|
|
|
|
|
static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
|
|
|
|
int (*xlaw2linear)(unsigned char),
|
|
|
|
int mask)
|
|
|
|
{
|
|
|
|
int i, j, v, v1, v2;
|
|
|
|
|
lavc/pcm_tablegen: slight speedup of table generation
This gets rid of some branches to speed up table generation slightly
(impact higher on mulaw than alaw). Tables are identical to before,
tested with FATE.
Sample benchmark (Haswell, GNU/Linux+gcc):
old:
313494 decicycles in build_alaw_table, 4094 runs, 2 skips
315959 decicycles in build_alaw_table, 8190 runs, 2 skips
323599 decicycles in build_ulaw_table, 4095 runs, 1 skips
318849 decicycles in build_ulaw_table, 8188 runs, 4 skips
new:
261902 decicycles in build_alaw_table, 4096 runs, 0 skips
266519 decicycles in build_alaw_table, 8192 runs, 0 skips
209657 decicycles in build_ulaw_table, 4096 runs, 0 skips
232656 decicycles in build_ulaw_table, 8192 runs, 0 skips
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-31 06:02:11 +02:00
|
|
|
j = 1;
|
|
|
|
linear_to_xlaw[8192] = mask;
|
|
|
|
for(i=0;i<127;i++) {
|
|
|
|
v1 = xlaw2linear(i ^ mask);
|
|
|
|
v2 = xlaw2linear((i + 1) ^ mask);
|
|
|
|
v = (v1 + v2 + 4) >> 3;
|
|
|
|
for(;j<v;j+=1) {
|
|
|
|
linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
|
2010-04-01 20:54:15 +03:00
|
|
|
linear_to_xlaw[8192 + j] = (i ^ mask);
|
|
|
|
}
|
|
|
|
}
|
lavc/pcm_tablegen: slight speedup of table generation
This gets rid of some branches to speed up table generation slightly
(impact higher on mulaw than alaw). Tables are identical to before,
tested with FATE.
Sample benchmark (Haswell, GNU/Linux+gcc):
old:
313494 decicycles in build_alaw_table, 4094 runs, 2 skips
315959 decicycles in build_alaw_table, 8190 runs, 2 skips
323599 decicycles in build_ulaw_table, 4095 runs, 1 skips
318849 decicycles in build_ulaw_table, 8188 runs, 4 skips
new:
261902 decicycles in build_alaw_table, 4096 runs, 0 skips
266519 decicycles in build_alaw_table, 8192 runs, 0 skips
209657 decicycles in build_ulaw_table, 4096 runs, 0 skips
232656 decicycles in build_ulaw_table, 8192 runs, 0 skips
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-31 06:02:11 +02:00
|
|
|
for(;j<8192;j++) {
|
|
|
|
linear_to_xlaw[8192 - j] = (127 ^ (mask ^ 0x80));
|
|
|
|
linear_to_xlaw[8192 + j] = (127 ^ mask);
|
|
|
|
}
|
2010-04-01 20:54:15 +03:00
|
|
|
linear_to_xlaw[0] = linear_to_xlaw[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcm_alaw_tableinit(void)
|
|
|
|
{
|
|
|
|
build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcm_ulaw_tableinit(void)
|
|
|
|
{
|
|
|
|
build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
|
|
|
|
}
|
2018-10-13 01:06:39 +02:00
|
|
|
|
|
|
|
static void pcm_vidc_tableinit(void)
|
|
|
|
{
|
|
|
|
build_xlaw_table(linear_to_vidc, vidc2linear, 0xff);
|
|
|
|
}
|
2010-04-01 20:54:15 +03:00
|
|
|
#endif /* CONFIG_HARDCODED_TABLES */
|
|
|
|
|
2011-05-17 17:58:04 +03:00
|
|
|
#endif /* AVCODEC_PCM_TABLEGEN_H */
|