[FFmpeg-devel] [PATCH] hardcoding for pcm alaw/ulaw tables
Michael Niedermayer
michaelni
Sun Mar 21 19:24:46 CET 2010
On Sun, Mar 21, 2010 at 06:43:38PM +0100, Reimar D?ffinger wrote:
> Hello,
> this allows hard-coding the linear-to-alaw and linear-to-ulaw tables,
> which have a size of 32 kB overall.
not specific to this patch but id like to point out that the table generation
is messy and it lacks documentation.
> Makefile | 1
> pcm.c | 79 +-------------------------------------
> pcm_tablegen.c | 51 ++++++++++++++++++++++++
> pcm_tablegen.h | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 173 insertions(+), 76 deletions(-)
> e47b001605eda9746a6afec01520084951af5157 pcmtables.diff
> Index: libavcodec/pcm_tablegen.c
> ===================================================================
> --- libavcodec/pcm_tablegen.c (revision 0)
> +++ libavcodec/pcm_tablegen.c (revision 0)
> @@ -0,0 +1,51 @@
> +/*
> + * Generate a header file for hardcoded PCM tables
> + *
> + * Copyright (c) 2010 Reimar D?ffinger <Reimar.Doeffinger at 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
> + */
> +
> +#include <stdlib.h>
> +#define av_cold
> +#define CONFIG_HARDCODED_TABLES 0
ugly
> +#include "pcm_tablegen.h"
> +#include "tableprint.h"
> +
> +void tableinit(void)
> +{
> + pcm_alaw_tableinit();
> + pcm_ulaw_tableinit();
> +}
> +
> +const struct tabledef tables[] = {
> + {
> + "static const uint8_t linear_to_alaw[1 << 14]",
> + write_uint8_array,
> + linear_to_alaw,
> + 1 << 14,
> + 0
> + },
> + {
> + "static const uint8_t linear_to_ulaw[1 << 14]",
> + write_uint8_array,
> + linear_to_ulaw,
> + 1 << 14,
> + 0
> + },
cleaner and with half the code:
printf("static const uint8_t linear_to_ulaw[1 << 14]= {\n");
for(i=0; i < 1<<14; i++)
printf("%d,", linear_to_ulaw[i]);
printf("};\n");
[...]
> +static av_cold int ulaw2linear(unsigned char u_val)
> +{
> + int t;
> +
> + /* Complement to obtain normal u-law value. */
> + u_val = ~u_val;
> +
> + /*
> + * 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;
> +
> + return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
> +}
> +
> +#if CONFIG_HARDCODED_TABLES
> +#define pcm_alaw_tableinit()
> +#define pcm_ulaw_tableinit()
ugly
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100321/13457446/attachment.pgp>
More information about the ffmpeg-devel
mailing list