libs: Import upstream code from mpg123 1.29.1.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-10-21 11:39:48 +02:00
parent eb0180e7b4
commit bafb747d2d
70 changed files with 32193 additions and 0 deletions

26
configure vendored
View File

@ -703,6 +703,8 @@ TIFF_PE_LIBS
TIFF_PE_CFLAGS
PNG_PE_LIBS
PNG_PE_CFLAGS
MPG123_PE_LIBS
MPG123_PE_CFLAGS
LCMS2_PE_LIBS
LCMS2_PE_CFLAGS
JXR_PE_LIBS
@ -1786,6 +1788,7 @@ enable_jpeg
enable_jxr
enable_lcms2
enable_mfuuid
enable_mpg123
enable_png
enable_strmiids
enable_tiff
@ -1934,6 +1937,8 @@ JXR_PE_CFLAGS
JXR_PE_LIBS
LCMS2_PE_CFLAGS
LCMS2_PE_LIBS
MPG123_PE_CFLAGS
MPG123_PE_LIBS
PNG_PE_CFLAGS
PNG_PE_LIBS
TIFF_PE_CFLAGS
@ -2724,6 +2729,11 @@ Some influential environment variables:
version
LCMS2_PE_LIBS
Linker flags for the PE lcms2, overriding the bundled version
MPG123_PE_CFLAGS
C compiler flags for the PE mpg123, overriding the bundled
version
MPG123_PE_LIBS
Linker flags for the PE mpg123, overriding the bundled version
PNG_PE_CFLAGS
C compiler flags for the PE png, overriding the bundled version
PNG_PE_LIBS Linker flags for the PE png, overriding the bundled version
@ -10737,6 +10747,19 @@ fi
$as_echo "$as_me:${as_lineno-$LINENO}: lcms2 cflags: $LCMS2_PE_CFLAGS" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: lcms2 libs: $LCMS2_PE_LIBS" >&5
if ${MPG123_PE_CFLAGS:+false} :; then :
MPG123_PE_CFLAGS="-I\$(top_srcdir)/libs/mpg123/src/libmpg123"
else
enable_mpg123=no
fi
if ${MPG123_PE_LIBS:+false} :; then :
MPG123_PE_LIBS=mpg123
else
enable_mpg123=no
fi
$as_echo "$as_me:${as_lineno-$LINENO}: mpg123 cflags: $MPG123_PE_CFLAGS" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: mpg123 libs: $MPG123_PE_LIBS" >&5
if ${PNG_PE_CFLAGS:+false} :; then :
PNG_PE_CFLAGS="-I\$(top_srcdir)/libs/png"
else
@ -18847,6 +18870,8 @@ JXR_PE_CFLAGS = $JXR_PE_CFLAGS
JXR_PE_LIBS = $JXR_PE_LIBS
LCMS2_PE_CFLAGS = $LCMS2_PE_CFLAGS
LCMS2_PE_LIBS = $LCMS2_PE_LIBS
MPG123_PE_CFLAGS = $MPG123_PE_CFLAGS
MPG123_PE_LIBS = $MPG123_PE_LIBS
PNG_PE_CFLAGS = $PNG_PE_CFLAGS
PNG_PE_LIBS = $PNG_PE_LIBS
TIFF_PE_CFLAGS = $TIFF_PE_CFLAGS
@ -20142,6 +20167,7 @@ wine_fn_config_makefile libs/jpeg enable_jpeg
wine_fn_config_makefile libs/jxr enable_jxr
wine_fn_config_makefile libs/lcms2 enable_lcms2
wine_fn_config_makefile libs/mfuuid enable_mfuuid
wine_fn_config_makefile libs/mpg123 enable_mpg123
wine_fn_config_makefile libs/png enable_png
wine_fn_config_makefile libs/strmiids enable_strmiids
wine_fn_config_makefile libs/tiff enable_tiff

View File

@ -1057,6 +1057,7 @@ WINE_EXTLIB_FLAGS(GSM, gsm, gsm, "-I\$(top_srcdir)/libs/gsm/inc")
WINE_EXTLIB_FLAGS(JPEG, jpeg, jpeg, "-I\$(top_srcdir)/libs/jpeg")
WINE_EXTLIB_FLAGS(JXR, jxr, jxr, "-I\$(top_srcdir)/libs/jxr/jxrgluelib -I\$(top_srcdir)/libs/jxr/image/sys")
WINE_EXTLIB_FLAGS(LCMS2, lcms2, lcms2, "-I\$(top_srcdir)/libs/lcms2/include")
WINE_EXTLIB_FLAGS(MPG123, mpg123, mpg123, "-I\$(top_srcdir)/libs/mpg123/src/libmpg123")
WINE_EXTLIB_FLAGS(PNG, png, "png \$(ZLIB_PE_LIBS)", "-I\$(top_srcdir)/libs/png")
WINE_EXTLIB_FLAGS(TIFF, tiff, tiff, "-I\$(top_srcdir)/libs/tiff/libtiff")
WINE_EXTLIB_FLAGS(XML2, libxml2, xml2, "-I\$(top_srcdir)/libs/xml2/include -DLIBXML_STATIC")
@ -3693,6 +3694,7 @@ WINE_CONFIG_MAKEFILE(libs/jpeg)
WINE_CONFIG_MAKEFILE(libs/jxr)
WINE_CONFIG_MAKEFILE(libs/lcms2)
WINE_CONFIG_MAKEFILE(libs/mfuuid)
WINE_CONFIG_MAKEFILE(libs/mpg123)
WINE_CONFIG_MAKEFILE(libs/png)
WINE_CONFIG_MAKEFILE(libs/strmiids)
WINE_CONFIG_MAKEFILE(libs/tiff)

176
libs/mpg123/AUTHORS Normal file
View File

@ -0,0 +1,176 @@
This is an attempt to give credit to the people who contributed in some way to the mpg123 project.
There are names and email addresses listed. Please use these addresses only to contact contributors with some question about their mpg123 contribution.
You are explicitly not allowed to send them unwanted business offers or to question the quality of their sex life.
--------------------
Being on the list of contributing authors not necessarily means that there
is significant copyright in parts of the source code. There are obviously
contributions of differing complexity. I try to mention people who motivated
changes at least by suggesting some definite code changes, even if their
code did not enter the mpg123 source verbatim. Trivial changes like pointing
out ovbious syntax errors that make compilers cry do not land here.
--------------------
Current maintainers with various sorts of contributions:
Thomas Orgis <thomas@orgis.org>
Patrick Dehne <patrick@steidle.net>
Jonathan Yong <10walls@gmail.com>
Taihei Momma <tmkk@mac.com>
Co-initiator of the revived mpg123 project, but not that involved anymore:
Nicholas J Humfrey <njh@ecs.soton.ac.uk>
Special thanks go to Taihei, the person who keeps the assembly optimisations alive
and takes care of portability to OSX/iOS platforms.
Generic address pointing to the current maintainer (hopefully still works in future in case maintainership will change again): <maintainer@mpg123.org>
The creator: Michael Hipp (email: hippm@informatik.uni-tuebingen.de - please bother maintainers first)
Contributions/ideas Thomas Orgis era (includes backports from mhipp trunk):
Vitaly Kirsanov <krokoziabla@gmail.com>: ports/cmake (optional CMake build)
Won-Kyu Park <wkpark@gmail.com>: patch to get rid of asm textrels (x86 PIC)
Michael Weiser <michaelweiser@users.sf.net>: update of coreaudio output to AudioComponents API
Bent Bisballe Nyeng <bbn@dynastrom.com>: patch for MPG123_NO_PEEK_END and MPG123_FORCE_SEEKABLE
Eric S. Raymond <esr@thyrsus.com>: man page fixes
Tobias Weber <tobiw@suprafluid.com>: patch for --disable-equalizer
Hans de Goede <j.w.r.degoede@gmail.com>: patch to skip APE tags
Stephan Vedder <stephan.vedder@gmail.com>: MSVC++ 2013 port update
Rajeev V. Pillai <rajeevvp@users.sf.net>: pointing out/patching issues in HTTP code and behaviour of mpg123 remote/terminal control
Jarno Lehtinen <lehtinen@sci.fi>: tinyalsa output
Anthony Wells <borgboyone@yahoo.com>: initial version of ID3v2 APIC patch
David Wohlferd <limegreensocks@yahoo.com>: Win32 WaveOut buffer destructor fix.
Mike Gorchak <mike.gorchak.qnx@gmail.com>: QNX native audio output (QSA)
Dan McGee <dpmcgee@gmail.com>: various patches (also for test suite)
Jonathan Yong (jon_y) <10walls@gmail.com>: win32 hacking, win32 wasapi audio.
Malcolm Boczek <MBoczek@terraindustries.com>: Common language runtime wrapper
Elbert Pol (TeLLie) <elbert.pol@gmail.com>: OS/2 port fixup
Jeroen Valkonet <jvalkon@xs4all.nl>: motivate pitch control, suggestive patch for pitch command in generic control interface
Andy Hefner <ahefner@gmail.com>: patch for that second UTF16 issue
Taihei Monma <tmkk@mac.com>: A whole lot of new/improved assembler code, including Altivec!
Christian Weisgerber <naddy@openbsd.org>, Brad Smith: sndio output
Patrick Dehne (P4tr3ck) <patrick@steidle.net>: more MSVC++ porting, patch to handle missing bit reservoirs
Thorsten Glaser <tg@mirbsd.de>: icy2utf8, suggest utf8 locale stuff
Dan Smith <dan@algenta.com>: ABI fixes for ensuring stack alignment (esp. for MinGW-built DLL with MSVC)
Michael Ryzhykh <mclroy@gmail.com>: mpg123.spec.in
Stefan Lenselink <Stefan@lenselink.org>: initial aRts output
Sergej Kvachonok <ravenexp@gmail.com>: win32 audio rewrite
Winston: SunOS-4.1.4/gcc-2.7.0 testing and suggestions for fixes (legacy Makefile, integer type headers)
Mika Tiainen: pointing out the fix for the UTF to ASCII filtering of tags to actually work
Nick Kurshev <nickols_k@mail.ru>: extended 3dnow (from mplayer)
Zuxy Meng <zuxy.meng@gmail.com>: SSE (from mplayer)
Honza <cundrak@quick.cz>: idea and prototype patch for ICY meta data support
Petr Baudis <pasky@ucw.cz>: patches: term sigcont, id3 display unicode fallback and condensed output
Petr Salinger <Petr.Salinger@seznam.cz>: i486 enhancement
mpdavig@users.sourceforge.net: linux-ppc-nas Makefile.legacy entry
Adrian Bacon <adrian.bacon@xs4all.nl>: patched decode_i586_dither (noise shaped float/int rounding)
Cool Feet Audio project <nutcase@dtfm.org>: realtime equalizer control
Steve Grundell <www@grundell.u-net.com>: clean stdout in control mode with stdout decoding
Romain Dolbeau <romain@dolbeau.org>: Altivec support (taken from mplayer)
higway <higway@mednet.md>: MMX Patch
Clemens Ladisch <clemens@ladisch.de>: ALSA 0.9/1.0 support
Debian Daniel Kobras <kobras@debian.org> era:
Steve Kemp <skx@debian.org>
Dan Olson <theoddone33@icculus.org>
Syuuhei Kashiyama <squash@mb.kcom.ne.jp>
Rupert Levene <rupert.debian@hotpop.com>
Andreas Dilger <adilger@turbolinux.com>
Erik B. Andersen <andersee@debian.org>
Chris Butler <chrisb@debian.org>
Martin Sjogren <md9ms@mdstud.chalmers.se>
Chet Hosey <chosey@budapress.com>
Roland Rosenfeld <roland@spinnaker.de>
Debian Colin Watson <cjwatson@debian.org> era:
Helge Deller <deller@gmx.de>
Chet Hosey <chosey@budapress.com>
Christopher C. Chimelis <chris@debian.org>
Roland Rosenfeld <roland@spinnaker.de>
Marcelo E. Magallon <mmagallo@debian.org>
Initial Debianers:
Tommi Virtanen <tv@debian.org>
Paul Haggart <phaggart@debian.org>
Contributions/ideas Michael Hipp era:
Mikko Tommila: DCT9
Oliver Fromme <oliver.fromme@heim3.tu-clausthal.de>
MPEG Software Simulation Group: reference decoder package
Tobias Bading: idea for DCT64 in subband synthesis from maplay package
Jeff Tsay and Mikko Tommila: MDCT36 from maplay package
Philipp Knirsch <phil@mpik-tueb.mpg.de>: DCT36/manual unroll idea
Thomas Woerner: SGI Audio
Damien Clermonte: HP-UX audio fixes
Niclas Lindstrom <nil@wineasy.se>: OS2 port
Stefan Bieschewski <stb@acm.org>: Pentium optimizations, decode_i586.s
Martin Denn <mdenn@unix-ag.uni-kl.de>: NAS port
Niklas Beisert <nbeisert@physik.tu-muenchen.de>: MPEG 2.5 tables
<mycroft@NetBSD.ORG> and <augustss@cs.chalmers.se>: NetBSD Patch(es)
Kevin Brintnall <kbrint@visi.com>: BSD patch
Tony Million: win32 port
Steven Tiger Lang: advanced shuffle
Eric B. Mitchell: esd port
Ryan R. Prosser <prosser@geocities.com>: esd port for Solaris
Andreas Neuhaus: initial generic control interface
(additionally fetched from changelog:)
Ralf Hildebrandt <R.Hildebrandt@TU-BS.DE>: audio_alib changes
<sms@moe.2bsd.com>: BSDOS 4.0 with gcc added to Makefile
Bertrand Petit <elrond@phoe.netdev.net>: frontend changes
Erik Mouw <J.A.K.Mouw@its.tudelft.nl>: SGI audio fix for non RAD machines
Daniel O'Connor <darius@guppy.dons.net.au>: freebsd-esd make-entry
D. Skarda <0rfelyus@atrey.karlin.mff.cuni.cz>: enhanced head_check
Wilson, Jeff D <jeff.wilson@wilcom.com>: xterm-title
Robert Bihlmeyer <robbe@orcus.priv.at>: esd changes
Hannu Napari's <Hannu.Napari@hut.fi>: SGI audio patches
<Juergen.Schoew@unix-ag.uni-siegen.de>: native AIX support
<psst@euskalnet.net>: playlist patch
Gilles Zunino <Gilles.Zunino@hei.fupl.asso.fr>: SGI audio patches
Matthew Parslow <roy@alpha.alphalink.com.au>: esdserver patch
<dlux@dlux.sch.bme.hu>: equalizer patch (equalfile setting)
Ducroquet Erwan <ducroque@ufr-info-p7.ibp.fr>: HPUX/ALib support
Shane Wegner <shane@CM.NU>: genrepatch
Samuel Audet <guardia@step.polymtl.ca>: wav-File patch
"J. Dean Brederson" <jdb@cs.utah.edu>: SGI-RAD support
Chou Ye-chi <is84002@cis.nctu.edu.tw>: sajberplay/FreeBSD patch
Fabrice Bellard <bellard@email.enst.fr>: 486 optimizations
A. Hermansen <ahermans@vf.telia.no> and J. Kysela <perex@jcu.cz>: ALSA output
KIMURA Takuhiro <kim@hannah.ipc.miyakyo-u.ac.jp>: K6-3DNow
Petr Stehlik <stehlik@cas3.zlin.vutbr.cz>: MINT
Andy <andy@snoogie.demon.co.uk>: float2int speed up proposal
Brian Foutz <foutz@anise.ee.cornell.edu>: TK3Play
Thomas Niederreiter <tn@tarantel.rz.fh-muenchen.de>: RIFF header fix
Stefan Gybas <cab@studbox.uni-stuttgart.de>: m68k patch
Grant Erickson <eric0139@tc.umn.edu>: Linux PPC patch
Peter Berger <peterb@hoopoe.psc.edu>: BSDi patch
Henrik P Johnson <king@one.se>: HTTP auth
Steven Tiger Lang <tiger@tyger.org>: advanced shuffle
"Brian J. Swetland" <swetland@uiuc.edu>: front-end (remote) patch
<leo@zycad.com>
Tillmann Steinbrecher <tst@gmx.de>: shuffle patch
M.Stekelenburg <m.stekelenburg@student.utwente.nl>: i386-getbits
Antti Andreimann <anttix@cyberix.edu.ee>: outburst patch
Hur TaeSung <saturn@arari.snu.ac.kr>: 'http accept' patch
(from post-0.59 changes that yet have to go into new trunk:)
Hans Schwengeler <schweng@astro.unibas.ch>: audio_dec additions
Wojciech Barañski's Mp3Play (check the tools folder): Mp3Play frontend
Daniel Koukola: audio_oss.c patch
Munechika SUMIKAWA <sumikawa@ebina.hitachi.co.jp>: IPv6
TEMNOTA <temnota@kmv.ru>: HTTP,FTP patch/playlist fix
Peter Surda <shurdeek@panorama.sth.ac.at>: VBR patch
Ben <ben@blaukopf.com>: ARM startup time improvements
Dave MacKenzie <djm@pix.net>: init_output() patch
pasky's <pasky@ju.cz>: close-on-stop patch

19
libs/mpg123/LICENSE Normal file
View File

@ -0,0 +1,19 @@
This is the file that contains the terms of use, copying, etc. for the mpg123 distribution package.
Main message, to include in "About ..." boxes, etc:
Copyright (c) 1995-2020 by Michael Hipp and others,
free software under the terms of the LGPL v2.1
There is an attempt to cover the actual list of authors in the AUTHORS file.
Project maintainer since 2006 is Thomas Orgis and many people have contributed
since the Michael Hipp era, but he stays the initial source and it would
be impractical to count them all individually, so it's "and others".
Source files contain the phrase "the mpg123 project" to the same effect
in their license boilerplate; especially those that were added after
maintainership changed. The person mainly responsible for the first version
is usually named in the phrase "initially written by ...".
All files in the distribution that don't carry a license note on their own are
licensed under the terms of the LGPL 2.1; exceptions may apply, especially to
files not in the official distribution but in the revision control repository.

31
libs/mpg123/Makefile.in Normal file
View File

@ -0,0 +1,31 @@
EXTLIB = libmpg123.a
EXTRAINCL = -I$(srcdir)/src -I$(srcdir)/src/compat -I$(srcdir)/src/libmpg123
EXTRADEFS = -DOPT_GENERIC_DITHER -DREAL_IS_FLOAT -DNO_CATCHSIGNAL
C_SRCS = \
src/compat/compat.c \
src/compat/compat_str.c \
src/libmpg123/dct64.c \
src/libmpg123/dither.c \
src/libmpg123/equalizer.c \
src/libmpg123/format.c \
src/libmpg123/frame.c \
src/libmpg123/icy.c \
src/libmpg123/icy2utf8.c \
src/libmpg123/id3.c \
src/libmpg123/index.c \
src/libmpg123/layer1.c \
src/libmpg123/layer2.c \
src/libmpg123/layer3.c \
src/libmpg123/lfs_wrap.c \
src/libmpg123/libmpg123.c \
src/libmpg123/ntom.c \
src/libmpg123/optimize.c \
src/libmpg123/parse.c \
src/libmpg123/readers.c \
src/libmpg123/stringbuf.c \
src/libmpg123/synth.c \
src/libmpg123/synth_8bit.c \
src/libmpg123/synth_real.c \
src/libmpg123/synth_s32.c \
src/libmpg123/tabinit.c

529
libs/mpg123/config.h Normal file
View File

@ -0,0 +1,529 @@
/* src/config.h. Generated from config.h.in by configure. */
/* src/config.h.in. Generated from configure.ac by autoheader. */
/* Define if your architecture wants/needs/can use attribute_align_arg and
alignment checks. It is for 32bit x86... */
/* #undef ABI_ALIGN_FUN */
/* Define to use proper rounding. */
#define ACCURATE_ROUNDING 1
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
/* Define if .balign is present. */
#define ASMALIGN_BALIGN 1
/* Define if .align just takes byte count. */
/* #undef ASMALIGN_BYTE */
/* Define if .align takes 3 for alignment of 2^3=8 bytes instead of 8. */
/* #undef ASMALIGN_EXP */
/* Define if __attribute__((aligned(16))) shall be used */
#define CCALIGN 1
/* Define if debugging is enabled. */
/* #undef DEBUG */
/* The default audio output module(s) to use */
#define DEFAULT_OUTPUT_MODULE "pulse,win32,win32_wasapi,sdl"
/* Define if building with dynamcally linked libmpg123 */
/* #undef DYNAMIC_BUILD */
/* Use EFBIG as substitude for EOVERFLOW, mingw.org may lack the latter */
/* #undef EOVERFLOW */
/* Define if FIFO support is enabled. */
#define FIFO 1
/* Define if frame index should be used. */
#define FRAME_INDEX 1
/* Define if gapless is enabled. */
#define GAPLESS 1
/* Define to 1 if you have the <alc.h> header file. */
/* #undef HAVE_ALC_H */
/* Define to 1 if you have the <Alib.h> header file. */
/* #undef HAVE_ALIB_H */
/* Define to 1 if you have the <AL/alc.h> header file. */
/* #undef HAVE_AL_ALC_H */
/* Define to 1 if you have the <AL/al.h> header file. */
/* #undef HAVE_AL_AL_H */
/* Define to 1 if you have the <al.h> header file. */
/* #undef HAVE_AL_H */
/* Define to 1 if you have the <arpa/inet.h> header file. */
/* #undef HAVE_ARPA_INET_H */
/* Define to 1 if you have the <asm/audioio.h> header file. */
/* #undef HAVE_ASM_AUDIOIO_H */
/* Define to 1 if you have the `atoll' function. */
#define HAVE_ATOLL 1
/* Define to 1 if you have the <audios.h> header file. */
/* #undef HAVE_AUDIOS_H */
/* Define to 1 if you have the <AudioToolbox/AudioToolbox.h> header file. */
/* #undef HAVE_AUDIOTOOLBOX_AUDIOTOOLBOX_H */
/* Define to 1 if you have the <AudioUnit/AudioUnit.h> header file. */
/* #undef HAVE_AUDIOUNIT_AUDIOUNIT_H */
/* Define to 1 if you have the <byteswap.h> header file. */
/* #undef HAVE_BYTESWAP_H */
/* Define to 1 if you have the <CoreServices/CoreServices.h> header file. */
/* #undef HAVE_CORESERVICES_CORESERVICES_H */
/* Define to 1 if you have the <CUlib.h> header file. */
/* #undef HAVE_CULIB_H */
/* Define to 1 if you have the <dirent.h> header file. */
#define HAVE_DIRENT_H 1
/* Define to 1 if you have the `dlclose' function. */
/* #undef HAVE_DLCLOSE */
/* Define to 1 if you have the <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
/* Define to 1 if you have the `dlopen' function. */
/* #undef HAVE_DLOPEN */
/* Define to 1 if you have the `dlsym' function. */
/* #undef HAVE_DLSYM */
/* Define to 1 if you have the `getaddrinfo' function. */
/* #undef HAVE_GETADDRINFO */
/* Define to 1 if you have the `getuid' function. */
/* #undef HAVE_GETUID */
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `iswprint' function. */
#define HAVE_ISWPRINT 1
/* Define to 1 if you have the <langinfo.h> header file. */
/* #undef HAVE_LANGINFO_H */
/* Define to 1 if you have the `m' library (-lm). */
#define HAVE_LIBM 1
/* Define to 1 if you have the `mx' library (-lmx). */
/* #undef HAVE_LIBMX */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <linux/soundcard.h> header file. */
/* #undef HAVE_LINUX_SOUNDCARD_H */
/* Define to 1 if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
/* Define to 1 if you have the <machine/soundcard.h> header file. */
/* #undef HAVE_MACHINE_SOUNDCARD_H */
/* Define to 1 if you have the `mbstowcs' function. */
#define HAVE_MBSTOWCS 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `mkfifo' function. */
/* #undef HAVE_MKFIFO */
/* Define to 1 if you have the `mmap' function. */
/* #undef HAVE_MMAP */
/* Define to 1 if you have the <netdb.h> header file. */
/* #undef HAVE_NETDB_H */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if you have the <netinet/tcp.h> header file. */
/* #undef HAVE_NETINET_TCP_H */
/* Define to 1 if you have the `nl_langinfo' function. */
/* #undef HAVE_NL_LANGINFO */
/* Define to 1 if you have the <OpenAL/alc.h> header file. */
/* #undef HAVE_OPENAL_ALC_H */
/* Define to 1 if you have the <OpenAL/al.h> header file. */
/* #undef HAVE_OPENAL_AL_H */
/* Define to 1 if you have the <os2me.h> header file. */
/* #undef HAVE_OS2ME_H */
/* Define to 1 if you have the <os2.h> header file. */
/* #undef HAVE_OS2_H */
/* Define to 1 if you have the `random' function. */
/* #undef HAVE_RANDOM */
/* Define to 1 if you have the <sched.h> header file. */
#define HAVE_SCHED_H 1
/* Define to 1 if you have the `sched_setscheduler' function. */
/* #undef HAVE_SCHED_SETSCHEDULER */
/* Define to 1 if you have the `setlocale' function. */
#define HAVE_SETLOCALE 1
/* Define to 1 if you have the `setpriority' function. */
/* #undef HAVE_SETPRIORITY */
/* Define to 1 if you have the `setuid' function. */
/* #undef HAVE_SETUID */
/* Define to 1 if you have the `shmat' function. */
/* #undef HAVE_SHMAT */
/* Define to 1 if you have the `shmctl' function. */
/* #undef HAVE_SHMCTL */
/* Define to 1 if you have the `shmdt' function. */
/* #undef HAVE_SHMDT */
/* Define to 1 if you have the `shmget' function. */
/* #undef HAVE_SHMGET */
/* Define to 1 if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define to 1 if you have the <sndio.h> header file. */
/* #undef HAVE_SNDIO_H */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sun/audioio.h> header file. */
/* #undef HAVE_SUN_AUDIOIO_H */
/* Define to 1 if you have the <sys/audioio.h> header file. */
/* #undef HAVE_SYS_AUDIOIO_H */
/* Define to 1 if you have the <sys/audio.h> header file. */
/* #undef HAVE_SYS_AUDIO_H */
/* Define to 1 if you have the <sys/ioctl.h> header file. */
/* #undef HAVE_SYS_IOCTL_H */
/* Define to 1 if you have the <sys/ipc.h> header file. */
/* #undef HAVE_SYS_IPC_H */
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define to 1 if you have the <sys/resource.h> header file. */
/* #undef HAVE_SYS_RESOURCE_H */
/* Define to 1 if you have the <sys/select.h> header file. */
/* #undef HAVE_SYS_SELECT_H */
/* Define to 1 if you have the <sys/shm.h> header file. */
/* #undef HAVE_SYS_SHM_H */
/* Define to 1 if you have the <sys/signal.h> header file. */
/* #undef HAVE_SYS_SIGNAL_H */
/* Define to 1 if you have the <sys/socket.h> header file. */
/* #undef HAVE_SYS_SOCKET_H */
/* Define to 1 if you have the <sys/soundcard.h> header file. */
/* #undef HAVE_SYS_SOUNDCARD_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
/* #undef HAVE_SYS_TIME_H 1 */
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/wait.h> header file. */
/* #undef HAVE_SYS_WAIT_H */
/* Define this if you have the POSIX termios library */
/* #undef HAVE_TERMIOS */
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the <wchar.h> header file. */
#define HAVE_WCHAR_H 1
/* Define to 1 if you have the `wcstombs' function. */
#define HAVE_WCSTOMBS 1
/* Define to 1 if you have the `wcswidth' function. */
/* #undef HAVE_WCSWIDTH */
/* Define to 1 if you have the <wctype.h> header file. */
#define HAVE_WCTYPE_H 1
/* Define to 1 if you have the <windows.h> header file. */
#define HAVE_WINDOWS_H 1
/* Define to 1 if you have the <ws2tcpip.h> header file. */
#define HAVE_WS2TCPIP_H 1
/* Define to indicate that float storage follows IEEE754. */
#define IEEE_FLOAT 1
/* size of the frame index seek table */
#define INDEX_SIZE 1000
/* Define if IPV6 support is enabled. */
#define IPV6 1
/* Define this to the size of native offset type in bits, used for LFS alias
functions. */
#define LFS_ALIAS_BITS 32
/* Define to the extension used for runtime loadable modules, say, ".so". */
#define LT_MODULE_EXT ".dll"
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
/* Define to the shared library suffix, say, ".dylib". */
/* #undef LT_SHARED_EXT */
/* Define to the shared archive member specification, say "(shr.o)". */
/* #undef LT_SHARED_LIB_MEMBER */
/* Define if network support is enabled. */
/* #undef NETWORK */
/* Define to disable 16 bit integer output. */
/* #undef NO_16BIT */
/* Define to disable 32 bit and 24 bit integer output. */
/* #undef NO_32BIT */
/* Define to disable 8 bit integer output. */
/* #undef NO_8BIT */
/* Define to disable downsampled decoding. */
/* #undef NO_DOWNSAMPLE */
/* Define to disable equalizer. */
/* #undef NO_EQUALIZER */
/* Define to disable error messages in combination with a return value (the
return is left intact). */
/* #undef NO_ERETURN */
/* Define to disable error messages. */
/* #undef NO_ERRORMSG */
/* Define to disable feeder and buffered readers. */
/* #undef NO_FEEDER */
/* Define to disable ICY handling. */
/* #undef NO_ICY */
/* Define to disable ID3v2 parsing. */
/* #undef NO_ID3V2 */
/* Define to disable layer I. */
/* #undef NO_LAYER1 */
/* Define to disable layer II. */
/* #undef NO_LAYER2 */
/* Define to disable layer III. */
/* #undef NO_LAYER3 */
/* Define to disable analyzer info. */
/* #undef NO_MOREINFO */
/* Define to disable ntom resampling. */
/* #undef NO_NTOM */
/* Define to disable real output. */
/* #undef NO_REAL */
/* Define to disable string functions. */
/* #undef NO_STRING */
/* Define for post-processed 32 bit formats. */
/* #undef NO_SYNTH32 */
/* Define to disable warning messages. */
/* #undef NO_WARNING */
/* Name of package */
#define PACKAGE "mpg123"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "maintainer@mpg123.org"
/* Define to the full name of this package. */
#define PACKAGE_NAME "mpg123"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "mpg123 1.29.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "mpg123"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.29.1"
/* Define if portaudio v18 API is wanted. */
/* #undef PORTAUDIO18 */
/* Define for calculating tables at runtime. */
/* #undef RUNTIME_TABLES */
/* The size of `int32_t', as computed by sizeof. */
#define SIZEOF_INT32_T 4
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4
/* The size of `off64_t', as computed by sizeof. */
#define SIZEOF_OFF64_T 8
/* The size of `off_t', as computed by sizeof. */
#define SIZEOF_OFF_T 8
/* The size of `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T 4
/* The size of `ssize_t', as computed by sizeof. */
#define SIZEOF_SSIZE_T 4
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to not duplicate some code for likely cases in libsyn123. */
/* #undef SYN123_NO_CASES */
/* Define if modules are enabled */
#define USE_MODULES 1
/* Define for new Huffman decoding scheme. */
#define USE_NEW_HUFFTABLE 1
/* Define to use yasm for assemble AVX sources. */
/* #undef USE_YASM_FOR_AVX */
/* Version number of package */
#define VERSION "1.29.1"
/* Define to use Win32 named pipes */
#define WANT_WIN32_FIFO 1
/* Define to use Win32 sockets */
#define WANT_WIN32_SOCKETS 1
/* Define to use Unicode for Windows */
#define WANT_WIN32_UNICODE 1
/* Windows UWP build */
/* #undef WINDOWS_UWP */
/* Windows Vista and later APIs */
/* #undef WINVER */
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
/* Define for extreme debugging. */
/* #undef XDEBUG */
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
/* Windows Vista and later APIs */
/* #undef _WIN32_WINNT */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `short' if <sys/types.h> does not define. */
/* #undef int16_t */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef int32_t */
/* Define to `long long' if <sys/types.h> does not define. */
/* #undef int64_t */
/* Define to the native offset type (long or actually off_t). */
#define lfs_alias_t long
/* Define to `long int' if <sys/types.h> does not define. */
/* #undef off_t */
/* Define to `unsigned long' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define to `long' if <sys/types.h> does not define. */
/* #undef ssize_t */
/* Define to `unsigned short' if <sys/types.h> does not define. */
/* #undef uint16_t */
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef uint32_t */
/* Define to `unsigned long' if <sys/types.h> does not define. */
/* #undef uintptr_t */

View File

@ -0,0 +1,508 @@
/*
compat: Some compatibility functions (basic memory & string stuff in separate file)
The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX.
So anything possibly somewhat advanced should be considered to be put here, with proper #ifdef;-)
copyright 2007-2020 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, Windows Unicode stuff by JonY.
*/
#include "config.h"
/* This source file does need _POSIX_SOURCE to get some sigaction. */
#define _POSIX_SOURCE
#include "compat.h"
#ifdef _MSC_VER
#include <io.h>
#if(defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_APP))
#define WINDOWS_UWP
#endif
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
/* Win32 is only supported with unicode now. These headers also cover
module stuff. The WANT_WIN32_UNICODE macro is synonymous with
"want windows-specific API, and only the unicode variants of which". */
#ifdef WANT_WIN32_UNICODE
#include <wchar.h>
#include <windows.h>
#include <winnls.h>
#include <shlwapi.h>
#endif
#include "debug.h"
#ifndef WINDOWS_UWP
char *compat_getenv(const char* name)
{
char *ret = NULL;
#ifdef WANT_WIN32_UNICODE
wchar_t *env;
wchar_t *wname = NULL;
if(win32_utf8_wide(name, &wname, NULL) > 0)
{
env = _wgetenv(wname);
free(wname);
if(env)
win32_wide_utf8(env, &ret, NULL);
}
#else
ret = getenv(name);
if(ret)
ret = compat_strdup(ret);
#endif
return ret;
}
#endif
#include "wpathconv.h"
/* Always add a default permission mask in case of flags|O_CREAT. */
int compat_open(const char *filename, int flags)
{
int ret;
#if defined (WANT_WIN32_UNICODE)
wchar_t *frag = NULL;
frag = u2wlongpath(filename);
/* Fallback to plain open when ucs-2 conversion fails */
if(!frag)
goto open_fallback;
/*Try _wopen */
ret = _wopen(frag, flags|_O_BINARY, _S_IREAD | _S_IWRITE);
if(ret != -1 )
goto open_ok; /* msdn says -1 means failure */
open_fallback:
#endif
#if (defined(WIN32) && !defined (__CYGWIN__))
/* MSDN says POSIX function is deprecated beginning in Visual C++ 2005 */
/* Try plain old _open(), if it fails, do nothing */
ret = _open(filename, flags|_O_BINARY, _S_IREAD | _S_IWRITE);
#else
ret = open(filename, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
#endif
#if defined (WANT_WIN32_UNICODE)
open_ok:
free(frag);
#endif
return ret;
}
/* Moved over from wav.c, logic with fallbacks added from the
example of compat_open(). */
FILE* compat_fopen(const char *filename, const char *mode)
{
FILE* stream = NULL;
#ifdef WANT_WIN32_UNICODE
int cnt = 0;
wchar_t *wname = NULL;
wchar_t *wmode = NULL;
wname = u2wlongpath(filename);
if(!wname)
goto fopen_fallback;
cnt = win32_utf8_wide(mode, &wmode, NULL);
if( (wmode == NULL) || (cnt == 0))
goto fopen_fallback;
stream = _wfopen(wname, wmode);
if(stream) goto fopen_ok;
fopen_fallback:
#endif
stream = fopen(filename, mode);
#ifdef WANT_WIN32_UNICODE
fopen_ok:
free(wmode);
free(wname);
#endif
return stream;
}
FILE* compat_fdopen(int fd, const char *mode)
{
return fdopen(fd, mode);
}
int compat_close(int infd)
{
#if (defined(WIN32) && !defined (__CYGWIN__)) /* MSDN says POSIX function is deprecated beginning in Visual C++ 2005 */
return _close(infd);
#else
return close(infd);
#endif
}
int compat_fclose(FILE *stream)
{
return fclose(stream);
}
#ifndef WINDOWS_UWP
/*
The Windows file and path stuff is an extract of jon_y's win32 loader
prototype from the loader_rework branch. It's been divided in to
reusable functons by ThOr in the hope to work out some generic-looking
loader code for both POSIX and Windows. The routines might be
helpful for consistent path work in other parts of mpg123, too.
This all is about getting some working code on a wide range of
systems while staying somewhat sane. If it does ridiculously inefficient
things with extraneous copies and grabbing of functions that made
it late to some official APIs, that's still fine with us.
*/
char* compat_catpath(const char *prefix, const char* path)
{
char *ret = NULL;
#ifdef WANT_WIN32_UNICODE
wchar_t *wprefix = NULL; /* Wide windows versions of */
wchar_t *wpath = NULL; /* input arguments. */
wchar_t *locwret = NULL; /* Tmp return value from LocalAlloc */
/*
This variation of combinepath can work with long and UNC paths, but
is not officially exposed in any DLLs, It also allocates all its buffers
internally via LocalAlloc, avoiding buffer overflow problems.
ThOr: I presume this hack is for supporting pre-8 Windows, as
from Windows 8 on, this is documented in the API.
*/
HRESULT (__stdcall *mypac)( const wchar_t *in, const wchar_t* more
, unsigned long flags, wchar_t **out ) = NULL;
HMODULE pathcch = NULL;
if(!prefix && !path)
goto catpath_end;
wprefix = u2wpath(prefix);
wpath = u2wpath(path);
if((prefix && !wprefix) || (path && !wpath))
goto catpath_end;
/* Again: I presume this whole fun is to get at PathAllocCombine
even when pathcch.h is not available (like in MinGW32). */
if( (pathcch = GetModuleHandleA("kernelbase")) )
mypac = (void *)GetProcAddress(pathcch, "PathAllocCombine");
if(mypac) /* PATHCCH_ALLOW_LONG_PATH = 1 per API docs */
{
debug("Actually calling PathAllocCombine!");
mypac(wprefix, wpath, 1, &locwret);
}
else
{
/* Playing safe, if we'd care much about performance, this would be on
the stack. */
locwret = LocalAlloc(LPTR, sizeof(wchar_t)*MAX_PATH);
if(locwret)
PathCombineW(locwret, wprefix, wpath);
}
ret = w2upath(locwret);
catpath_end:
LocalFree(locwret);
free(wprefix);
free(wpath);
#else
size_t len, prelen, patlen;
if(path && path[0] == '/')
prefix = NULL; /* Absolute path stays as it is. */
prelen = prefix ? strlen(prefix) : 0;
patlen = path ? strlen(path) : 0;
/* Concatenate the two, put a / in between if both present. */
len = ((prefix && path) ? 1 : 0) + prelen + patlen;
ret = malloc(len+1);
if(ret)
{
size_t off=0;
memcpy(ret, prefix, prelen);
if(prefix && path)
ret[prelen+(off++)] = '/';
memcpy(ret+prelen+off, path, patlen);
ret[len] = 0;
}
#endif
return ret;
}
int compat_isdir(const char *path)
{
int ret = 0;
#ifdef WANT_WIN32_UNICODE
wchar_t *wpath;
wpath = u2wlongpath(path);
if(wpath)
{
DWORD attr = GetFileAttributesW(wpath);
if(attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
ret=1;
free(wpath);
}
#else
struct stat sb;
if(path && !stat(path, &sb))
{
if(S_ISDIR(sb.st_mode))
ret=1;
}
#endif
return ret;
}
struct compat_dir
{
char *path;
#ifdef WANT_WIN32_UNICODE
int gotone; /* Got a result stored from FindFirstFileW. */
WIN32_FIND_DATAW d;
HANDLE ffn;
#else
DIR* dir;
#endif
};
struct compat_dir* compat_diropen(char *path)
{
struct compat_dir *cd;
if(!path)
return NULL;
cd = malloc(sizeof(*cd));
if(!cd)
return NULL;
#ifdef WANT_WIN32_UNICODE
cd->gotone = 0;
{
char *pattern;
wchar_t *wpattern;
pattern = compat_catpath(path, "*");
wpattern = u2wlongpath(pattern);
if(wpattern)
{
cd->ffn = FindFirstFileW(wpattern, &(cd->d));
if(cd->ffn == INVALID_HANDLE_VALUE)
{
/* FindClose() only needed after successful first find, right? */
free(cd);
cd = NULL;
}
else
cd->gotone = 1;
}
free(wpattern);
free(pattern);
}
#else
cd->dir = opendir(path);
if(!cd->dir)
{
free(cd);
cd = NULL;
}
#endif
if(cd)
{
cd->path = compat_strdup(path);
if(!cd->path)
{
compat_dirclose(cd);
cd = NULL;
}
}
return cd;
}
void compat_dirclose(struct compat_dir *cd)
{
if(cd)
{
free(cd->path);
#ifdef WANT_WIN32_UNICODE
FindClose(cd->ffn);
#else
closedir(cd->dir);
#endif
free(cd);
}
}
char* compat_nextfile(struct compat_dir *cd)
{
if(!cd)
return NULL;
#ifdef WANT_WIN32_UNICODE
while(cd->gotone || FindNextFileW(cd->ffn, &(cd->d)))
{
cd->gotone = 0;
if(!(cd->d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
char *ret;
win32_wide_utf8(cd->d.cFileName, &ret, NULL);
return ret;
}
}
#else
{
struct dirent *dp;
while((dp = readdir(cd->dir)))
{
struct stat fst;
char *fullpath = compat_catpath(cd->path, dp->d_name);
if(fullpath && !stat(fullpath, &fst) && S_ISREG(fst.st_mode))
{
free(fullpath);
return compat_strdup(dp->d_name);
}
free(fullpath);
}
}
#endif
return NULL;
}
char* compat_nextdir(struct compat_dir *cd)
{
if(!cd)
return NULL;
#ifdef WANT_WIN32_UNICODE
while(cd->gotone || FindNextFileW(cd->ffn, &(cd->d)))
{
cd->gotone = 0;
if(cd->d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char *ret;
win32_wide_utf8(cd->d.cFileName, &ret, NULL);
return ret;
}
}
#else
{
struct dirent *dp;
while((dp = readdir(cd->dir)))
{
struct stat fst;
char *fullpath = compat_catpath(cd->path, dp->d_name);
if(fullpath && !stat(fullpath, &fst) && S_ISDIR(fst.st_mode))
{
free(fullpath);
return compat_strdup(dp->d_name);
}
free(fullpath);
}
}
#endif
return NULL;
}
#endif
// Revisit logic of write():
// Return -1 if interrupted before any data was written,
// set errno to EINTR. Any other error value is serious
// for blocking I/O, which we assume here. EAGAIN should be
// handed through.
// Reaction to zero-sized write attempts could also be funky, so avoid that.
// May return short count for various reasons. I assume that
// any serious condition will show itself as return value -1
// eventually.
// These uninterruptible write/read functions shall persist as long as
// possible to finish the desired operation. A short byte count is short
// because of a serious reason (maybe EOF, maybe out of disk space). You
// can inspect errno.
size_t unintr_write(int fd, void const *buffer, size_t bytes)
{
size_t written = 0;
errno = 0;
while(bytes)
{
errno = 0;
ssize_t part = write(fd, (char*)buffer+written, bytes);
// Just on short writes, we do not abort. Only when
// there was no successful operation (even zero write) at all.
// Any other error than EINTR ends things here.
if(part >= 0)
{
bytes -= part;
written += part;
} else if(errno != EINTR)
break;
}
return written;
}
/* Same for reading the data. */
size_t unintr_read(int fd, void *buffer, size_t bytes)
{
size_t got = 0;
errno = 0;
while(bytes)
{
errno = 0;
ssize_t part = read(fd, (char*)buffer+got, bytes);
if(part >= 0)
{
bytes -= part;
got += part;
} else if(errno != EINTR)
break;
}
return got;
}
// and again for streams
size_t unintr_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t written = 0;
errno = 0;
while(size && nmemb)
{
errno = 0;
size_t part = fwrite((char*)ptr+written*size, size, nmemb, stream);
if(part > 0)
{
nmemb -= part;
written += part;
} else if(errno != EINTR)
break;
}
return written;
}
#ifndef NO_CATCHSIGNAL
#if (!defined(WIN32) || defined (__CYGWIN__)) && defined(HAVE_SIGNAL_H)
void (*catchsignal(int signum, void(*handler)()))()
{
struct sigaction new_sa;
struct sigaction old_sa;
#ifdef DONT_CATCH_SIGNALS
fprintf (stderr, "Not catching any signals.\n");
return ((void (*)()) -1);
#endif
new_sa.sa_handler = handler;
sigemptyset(&new_sa.sa_mask);
new_sa.sa_flags = 0;
if(sigaction(signum, &new_sa, &old_sa) == -1)
return ((void (*)()) -1);
return (old_sa.sa_handler);
}
#endif
#endif

View File

@ -0,0 +1,301 @@
/*
compat: Some compatibility functions and header inclusions.
Basic standard C stuff, that may barely be above/around C89.
The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX.
It is envisioned to include this compat header instead of any of the "standard" headers, to catch compatibility issues.
So, don't include stdlib.h or string.h ... include compat.h.
copyright 2007-21 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#ifndef MPG123_COMPAT_H
#define MPG123_COMPAT_H
#include "config.h"
// We are using C99 now, including possibly single-precision math.
#define _ISO_C99_SOURCE
#include <errno.h>
#ifdef HAVE_STDLIB_H
/* realloc, size_t */
#include <stdlib.h>
#endif
#include <stdio.h>
#include <math.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#else
#ifdef HAVE_SYS_SIGNAL_H
#include <sys/signal.h>
#endif
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* Types, types, types. */
/* Do we actually need these two in addition to sys/types.h? As replacement? */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
/* We want SIZE_MAX, etc. */
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)-1)
#endif
#ifndef SSIZE_MAX
#define SSIZE_MAX ((size_t)-1/2)
#endif
#ifndef ULONG_MAX
#define ULONG_MAX ((unsigned long)-1)
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef OS2
#include <float.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
/* For select(), I need select.h according to POSIX 2001, else: sys/time.h sys/types.h unistd.h */
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
/* compat_open makes little sense without */
#include <fcntl.h>
/* To parse big numbers... */
#ifdef HAVE_ATOLL
#define atobigint atoll
#else
#define atobigint atol
#endif
typedef unsigned char byte;
#if defined(_MSC_VER)
// For _setmode(), at least.
#include <io.h>
#if !defined(MPG123_DEF_SSIZE_T)
#define MPG123_DEF_SSIZE_T
#include <stddef.h>
typedef ptrdiff_t ssize_t;
#endif
#endif
// Not too early, leave system headers alone (strerror).
#include "intsym.h"
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
void *safe_realloc(void *ptr, size_t size);
// Also freeing ptr if result is NULL. You can do
// ptr = safer_realloc(ptr, size)
// Also, ptr = safer_realloc(ptr, 0) will do free(ptr); ptr=NULL;.
void *safer_realloc(void *ptr, size_t size);
#ifndef HAVE_STRERROR
const char *strerror(int errnum);
#endif
/* Roll our own strdup() that does not depend on libc feature test macros
and returns NULL on NULL input instead of crashing. */
char* compat_strdup(const char *s);
/* If we have the size checks enabled, try to derive some sane printfs.
Simple start: Use max integer type and format if long is not big enough.
I am hesitating to use %ll without making sure that it's there... */
#if (defined SIZEOF_OFF_T) && (SIZEOF_OFF_T > SIZEOF_LONG) && (defined PRIiMAX)
# define OFF_P PRIiMAX
typedef intmax_t off_p;
#else
# define OFF_P "li"
typedef long off_p;
#endif
#if (defined SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > SIZEOF_LONG) && (defined PRIuMAX)
# define SIZE_P PRIuMAX
typedef uintmax_t size_p;
#else
# define SIZE_P "lu"
typedef unsigned long size_p;
#endif
#if (defined SIZEOF_SSIZE_T) && (SIZEOF_SSIZE_T > SIZEOF_LONG) && (defined PRIiMAX)
# define SSIZE_P PRIuMAX
typedef intmax_t ssize_p;
#else
# define SSIZE_P "li"
typedef long ssize_p;
#endif
/* Get an environment variable, possibly converted to UTF-8 from wide string.
The return value is a copy that you shall free. */
char *compat_getenv(const char* name);
/**
* Opening a file handle can be different.
* This function here is defined to take a path in native encoding (ISO8859 / UTF-8 / ...), or, when MS Windows Unicode support is enabled, an UTF-8 string that will be converted back to native UCS-2 (wide character) before calling the system's open function.
* @param[in] wptr Pointer to wide string.
* @param[in] mbptr Pointer to multibyte string.
* @return file descriptor (>=0) or error code.
*/
int compat_open(const char *filename, int flags);
FILE* compat_fopen(const char *filename, const char *mode);
/**
* Also fdopen to avoid having to define POSIX macros in various source files.
*/
FILE* compat_fdopen(int fd, const char *mode);
/**
* Closing a file handle can be platform specific.
* This function takes a file descriptor that is to be closed.
* @param[in] infd File descriptor to be closed.
* @return 0 if the file was successfully closed. A return value of -1 indicates an error.
*/
int compat_close(int infd);
int compat_fclose(FILE* stream);
/* Those do make sense in a separate file, but I chose to include them in compat.c because that's the one source whose object is shared between mpg123 and libmpg123 -- and both need the functionality internally. */
#ifdef WANT_WIN32_UNICODE
/**
* win32_uni2mbc
* Converts a null terminated UCS-2 string to a multibyte (UTF-8) equivalent.
* Caller is supposed to free allocated buffer.
* @param[in] wptr Pointer to wide string.
* @param[out] mbptr Pointer to multibyte string.
* @param[out] buflen Optional parameter for length of allocated buffer.
* @return status of WideCharToMultiByte conversion.
*
* WideCharToMultiByte - http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx
*/
int win32_wide_utf8(const wchar_t * const wptr, char **mbptr, size_t * buflen);
/**
* win32_mbc2uni
* Converts a null terminated UTF-8 string to a UCS-2 equivalent.
* Caller is supposed to free allocated buffer.
* @param[in] mbptr Pointer to multibyte string.
* @param[out] wptr Pointer to wide string.
* @param[out] buflen Optional parameter for length of allocated buffer.
* @return status of WideCharToMultiByte conversion.
*
* MultiByteToWideChar - http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx
*/
int win32_utf8_wide(const char *const mbptr, wchar_t **wptr, size_t *buflen);
#endif
/*
A little bit of path abstraction: We always work with plain char strings
that usually represent POSIX-ish UTF-8 paths (something like c:/some/file
might appear). For Windows, those are converted to wide strings with \
instead of / and possible fun is had with prefixes to get around the old
path length limit. Outside of the compat library, that stuff should not
matter, although something like //?/UNC/server/some/file could be thrown
around as UTF-8 string, to be converted to a wide \\?\UNC\server\some\file
just before handing it to Windows API.
There is a lot of unnecessary memory allocation and string copying because
of this, but this filesystem stuff is not really relevant to mpg123
performance, so the goal is to keep the code outside the compatibility layer
simple.
*/
/*
Concatenate a prefix and a path, one of them alowed to be NULL.
If the path is already absolute, the prefix is ignored. Relative
parts (like /..) are resolved if this is sensible for the platform
(meaning: for Windows), else they are preserved (on POSIX, actual
file system access would be needed because of symlinks).
*/
char* compat_catpath(const char *prefix, const char* path);
/* Return 1 if the given path indicates an existing directory,
0 otherwise. */
int compat_isdir(const char *path);
/*
Directory traversal. This talks ASCII/UTF-8 paths externally, converts
to/from wchar_t internally if the platform wants that. Returning NULL
means failure to open/end of listing.
There is no promise about sorting entries.
*/
struct compat_dir;
/* Returns NULL if either directory failed to open or listing is empty.
Listing can still be empty even if non-NULL, so always rely on the
nextfile/nextdir functions. */
struct compat_dir* compat_diropen(char *path);
void compat_dirclose(struct compat_dir*);
/* Get the next entry that is a file (or symlink to one).
The returned string is a copy that needs to be freed after use. */
char* compat_nextfile(struct compat_dir*);
/* Get the next entry that is a directory (or symlink to one).
The returned string is a copy that needs to be freed after use. */
char* compat_nextdir (struct compat_dir*);
#ifdef USE_MODULES
/*
For keeping the path mess local, a system-specific dlopen() variant
is contained in here, too. This is very thin wrapping, even sparing
definition of a handle type, just using void pointers.
Use of absolute paths is a good idea if you want to be sure which
file is openend, as default search paths vary.
*/
void *compat_dlopen (const char *path);
void *compat_dlsym (void *handle, const char* name);
void compat_dlclose(void *handle);
#endif
/* Blocking write/read of data with signal resilience.
They continue after being interrupted by signals and always return the
amount of processed data (shortage indicating actual problem or EOF). */
size_t unintr_write(int fd, void const *buffer, size_t bytes);
size_t unintr_read (int fd, void *buffer, size_t bytes);
size_t unintr_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
/* That one comes from Tellie on OS/2, needed in resolver. */
#ifdef __KLIBC__
typedef int socklen_t;
#endif
/* OSX SDK defines an enum with "normal" as value. That clashes with
optimize.h */
#ifdef __APPLE__
#define normal mpg123_normal
#endif
#include "true.h"
#if (!defined(WIN32) || defined (__CYGWIN__)) && defined(HAVE_SIGNAL_H)
void (*catchsignal(int signum, void(*handler)()))();
#endif
#endif

View File

@ -0,0 +1,105 @@
/*
compat: Some compatibility functions (basic memory and string stuff)
The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX.
So anything possibly somewhat advanced should be considered to be put here, with proper #ifdef;-)
copyright 2007-2016 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, Windows Unicode stuff by JonY.
*/
#include "compat.h"
/* Win32 is only supported with unicode now. These headers also cover
module stuff. The WANT_WIN32_UNICODE macro is synonymous with
"want windows-specific API, and only the unicode variants of which". */
#ifdef WANT_WIN32_UNICODE
#include <wchar.h>
#include <windows.h>
#include <winnls.h>
#endif
#include "debug.h"
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
void *safe_realloc(void *ptr, size_t size)
{
if(ptr == NULL) return malloc(size);
else return realloc(ptr, size);
}
// A more sensible variant of realloc: It deallocates the original memory if
// realloc fails or if size zero was requested.
void *safer_realloc(void *ptr, size_t size)
{
void *nptr = size ? safe_realloc(ptr, size) : NULL;
if(!nptr && ptr)
free(ptr);
return nptr;
}
#ifndef HAVE_STRERROR
const char *strerror(int errnum)
{
extern int sys_nerr;
extern char *sys_errlist[];
return (errnum < sys_nerr) ? sys_errlist[errnum] : "";
}
#endif
char* compat_strdup(const char *src)
{
char *dest = NULL;
if(src)
{
size_t len;
len = strlen(src)+1;
if((dest = malloc(len)))
memcpy(dest, src, len);
}
return dest;
}
/* Windows Unicode stuff */
#ifdef WANT_WIN32_UNICODE
int win32_wide_utf8(const wchar_t * const wptr, char **mbptr, size_t * buflen)
{
size_t len;
char *buf;
int ret = 0;
len = WideCharToMultiByte(CP_UTF8, 0, wptr, -1, NULL, 0, NULL, NULL); /* Get utf-8 string length */
buf = calloc(len + 1, sizeof (char)); /* Can we assume sizeof char always = 1? */
if(!buf) len = 0;
else {
if (len != 0) ret = WideCharToMultiByte(CP_UTF8, 0, wptr, -1, buf, len, NULL, NULL); /*Do actual conversion*/
buf[len] = '0'; /* Must terminate */
}
*mbptr = buf; /* Set string pointer to allocated buffer */
if(buflen != NULL) *buflen = (len) * sizeof (char); /* Give length of allocated memory if needed. */
return ret;
}
int win32_utf8_wide(const char *const mbptr, wchar_t **wptr, size_t *buflen)
{
size_t len;
wchar_t *buf;
int ret = 0;
len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mbptr, -1, NULL, 0); /* Get converted size */
buf = calloc(len + 1, sizeof (wchar_t)); /* Allocate memory accordingly */
if(!buf) len = 0;
else {
if (len != 0) ret = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, mbptr, -1, buf, len); /* Do conversion */
buf[len] = L'0'; /* Must terminate */
}
*wptr = buf; /* Set string pointer to allocated buffer */
if (buflen != NULL) *buflen = len * sizeof (wchar_t); /* Give length of allocated memory if needed. */
return ret; /* Number of characters written */
}
#endif

View File

@ -0,0 +1,120 @@
/*
wpathconv: static functions for windows file path conversions
This file is intended to be included in libcompat sources for internal use.
It is separated out to be able to split off the dlopen functions into a
separate libcompat. It is just a code fragment.
copyright 2007-2019 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by JonY
*/
#ifndef WINDOWS_UWP
#ifdef WANT_WIN32_UNICODE
/* Convert unix UTF-8 (or ASCII) paths to Windows wide character paths. */
static wchar_t* u2wpath(const char *upath)
{
wchar_t* wpath, *p;
if(!upath || win32_utf8_wide(upath, &wpath, NULL) < 1)
return NULL;
for(p=wpath; *p; ++p)
if(*p == L'/')
*p = L'\\';
return wpath;
}
/* Convert Windows wide character paths to unix UTF-8. */
static char* w2upath(const wchar_t *wpath)
{
char* upath, *p;
if(!wpath || win32_wide_utf8(wpath, &upath, NULL) < 1)
return NULL;
for(p=upath; *p; ++p)
if(*p == '\\')
*p = '/';
return upath;
}
/* An absolute path that is too long and not already marked with
\\?\ can be marked as a long one and still work. */
static int wpath_need_elongation(wchar_t *wpath)
{
if( wpath && !PathIsRelativeW(wpath)
&& wcslen(wpath) > MAX_PATH-1
&& wcsncmp(L"\\\\?\\", wpath, 4) )
return 1;
else
return 0;
}
/* Take any wide windows path and turn it into a path that is allowed
to be longer than MAX_PATH, if it is not already. */
static wchar_t* wlongpath(wchar_t *wpath)
{
size_t len, plen;
const wchar_t *prefix = L"";
wchar_t *wlpath = NULL;
if(!wpath)
return NULL;
/* Absolute paths that do not start with \\?\ get that prepended
to allow them being long. */
if(!PathIsRelativeW(wpath) && wcsncmp(L"\\\\?\\", wpath, 4))
{
if(wcslen(wpath) >= 2 && PathIsUNCW(wpath))
{
/* \\server\path -> \\?\UNC\server\path */
prefix = L"\\\\?\\UNC";
++wpath; /* Skip the first \. */
}
else /* c:\some/path -> \\?\c:\some\path */
prefix = L"\\\\?\\";
}
plen = wcslen(prefix);
len = plen + wcslen(wpath);
wlpath = malloc(len+1*sizeof(wchar_t));
if(wlpath)
{
/* Brute force memory copying, swprintf is too dandy. */
memcpy(wlpath, prefix, sizeof(wchar_t)*plen);
memcpy(wlpath+plen, wpath, sizeof(wchar_t)*(len-plen));
wlpath[len] = 0;
}
return wlpath;
}
/* Convert unix path to wide windows path, optionally marking
it as long path if necessary. */
static wchar_t* u2wlongpath(const char *upath)
{
wchar_t *wpath = NULL;
wchar_t *wlpath = NULL;
wpath = u2wpath(upath);
if(wpath_need_elongation(wpath))
{
wlpath = wlongpath(wpath);
free(wpath);
wpath = wlpath;
}
return wpath;
}
#endif
#else
static wchar_t* u2wlongpath(const char *upath)
{
wchar_t* wpath, *p;
if (!upath || win32_utf8_wide(upath, &wpath, NULL) < 1)
return NULL;
for (p = wpath; *p; ++p)
if (*p == L'/')
*p = L'\\';
return wpath;
}
#endif

370
libs/mpg123/src/intsym.h Normal file
View File

@ -0,0 +1,370 @@
#ifndef MPG123_INTSYM_H
#define MPG123_INTSYM_H
/* Mapping of internal mpg123 symbols to something that is less likely to
conflict in case of static linking. */
#include "config.h"
#define COS9 INT123_COS9
#define tfcos36 INT123_tfcos36
#define pnts INT123_pnts
#define catchsignal INT123_catchsignal
#define safe_realloc INT123_safe_realloc
#define safer_realloc INT123_safer_realloc
#define compat_strdup INT123_compat_strdup
#define compat_getenv INT123_compat_getenv
#define compat_open INT123_compat_open
#define compat_fopen INT123_compat_fopen
#define compat_fdopen INT123_compat_fdopen
#define compat_close INT123_compat_close
#define compat_fclose INT123_compat_fclose
#define win32_wide_utf8 INT123_win32_wide_utf8
#define win32_utf8_wide INT123_win32_utf8_wide
#define compat_catpath INT123_compat_catpath
#define compat_isdir INT123_compat_isdir
#define compat_diropen INT123_compat_diropen
#define compat_dirclose INT123_compat_dirclose
#define compat_nextfile INT123_compat_nextfile
#define compat_nextdir INT123_compat_nextdir
#define compat_dlopen INT123_compat_dlopen
#define compat_dlsym INT123_compat_dlsym
#define compat_dlclose INT123_compat_dlclose
#define unintr_write INT123_unintr_write
#define unintr_read INT123_unintr_read
#define unintr_fwrite INT123_unintr_fwrite
#define ntom_set_ntom INT123_ntom_set_ntom
#define synth_1to1 INT123_synth_1to1
#define synth_1to1_dither INT123_synth_1to1_dither
#define synth_1to1_i386 INT123_synth_1to1_i386
#define synth_1to1_i586 INT123_synth_1to1_i586
#define synth_1to1_i586_dither INT123_synth_1to1_i586_dither
#define synth_1to1_mmx INT123_synth_1to1_mmx
#define synth_1to1_3dnow INT123_synth_1to1_3dnow
#define synth_1to1_sse INT123_synth_1to1_sse
#define synth_1to1_stereo_sse INT123_synth_1to1_stereo_sse
#define synth_1to1_3dnowext INT123_synth_1to1_3dnowext
#define synth_1to1_altivec INT123_synth_1to1_altivec
#define synth_1to1_stereo_altivec INT123_synth_1to1_stereo_altivec
#define synth_1to1_x86_64 INT123_synth_1to1_x86_64
#define synth_1to1_stereo_x86_64 INT123_synth_1to1_stereo_x86_64
#define synth_1to1_avx INT123_synth_1to1_avx
#define synth_1to1_stereo_avx INT123_synth_1to1_stereo_avx
#define synth_1to1_arm INT123_synth_1to1_arm
#define synth_1to1_neon INT123_synth_1to1_neon
#define synth_1to1_stereo_neon INT123_synth_1to1_stereo_neon
#define synth_1to1_neon64 INT123_synth_1to1_neon64
#define synth_1to1_stereo_neon64 INT123_synth_1to1_stereo_neon64
#define absynth_1to1_i486 INT123_absynth_1to1_i486
#define synth_1to1_mono INT123_synth_1to1_mono
#define synth_1to1_m2s INT123_synth_1to1_m2s
#define synth_2to1 INT123_synth_2to1
#define synth_2to1_dither INT123_synth_2to1_dither
#define synth_2to1_i386 INT123_synth_2to1_i386
#define synth_2to1_mono INT123_synth_2to1_mono
#define synth_2to1_m2s INT123_synth_2to1_m2s
#define synth_4to1 INT123_synth_4to1
#define synth_4to1_dither INT123_synth_4to1_dither
#define synth_4to1_i386 INT123_synth_4to1_i386
#define synth_4to1_mono INT123_synth_4to1_mono
#define synth_4to1_m2s INT123_synth_4to1_m2s
#define synth_ntom INT123_synth_ntom
#define synth_ntom_mono INT123_synth_ntom_mono
#define synth_ntom_m2s INT123_synth_ntom_m2s
#define synth_1to1_8bit INT123_synth_1to1_8bit
#define synth_1to1_8bit_i386 INT123_synth_1to1_8bit_i386
#define synth_1to1_8bit_wrap INT123_synth_1to1_8bit_wrap
#define synth_1to1_8bit_mono INT123_synth_1to1_8bit_mono
#define synth_1to1_8bit_m2s INT123_synth_1to1_8bit_m2s
#define synth_1to1_8bit_wrap_mono INT123_synth_1to1_8bit_wrap_mono
#define synth_1to1_8bit_wrap_m2s INT123_synth_1to1_8bit_wrap_m2s
#define synth_2to1_8bit INT123_synth_2to1_8bit
#define synth_2to1_8bit_i386 INT123_synth_2to1_8bit_i386
#define synth_2to1_8bit_mono INT123_synth_2to1_8bit_mono
#define synth_2to1_8bit_m2s INT123_synth_2to1_8bit_m2s
#define synth_4to1_8bit INT123_synth_4to1_8bit
#define synth_4to1_8bit_i386 INT123_synth_4to1_8bit_i386
#define synth_4to1_8bit_mono INT123_synth_4to1_8bit_mono
#define synth_4to1_8bit_m2s INT123_synth_4to1_8bit_m2s
#define synth_ntom_8bit INT123_synth_ntom_8bit
#define synth_ntom_8bit_mono INT123_synth_ntom_8bit_mono
#define synth_ntom_8bit_m2s INT123_synth_ntom_8bit_m2s
#define synth_1to1_real INT123_synth_1to1_real
#define synth_1to1_real_i386 INT123_synth_1to1_real_i386
#define synth_1to1_real_sse INT123_synth_1to1_real_sse
#define synth_1to1_real_stereo_sse INT123_synth_1to1_real_stereo_sse
#define synth_1to1_real_x86_64 INT123_synth_1to1_real_x86_64
#define synth_1to1_real_stereo_x86_64 INT123_synth_1to1_real_stereo_x86_64
#define synth_1to1_real_avx INT123_synth_1to1_real_avx
#define synth_1to1_fltst_avx INT123_synth_1to1_fltst_avx
#define synth_1to1_real_altivec INT123_synth_1to1_real_altivec
#define synth_1to1_fltst_altivec INT123_synth_1to1_fltst_altivec
#define synth_1to1_real_neon INT123_synth_1to1_real_neon
#define synth_1to1_real_stereo_neon INT123_synth_1to1_real_stereo_neon
#define synth_1to1_real_neon64 INT123_synth_1to1_real_neon64
#define synth_1to1_fltst_neon64 INT123_synth_1to1_fltst_neon64
#define synth_1to1_real_mono INT123_synth_1to1_real_mono
#define synth_1to1_real_m2s INT123_synth_1to1_real_m2s
#define synth_2to1_real INT123_synth_2to1_real
#define synth_2to1_real_i386 INT123_synth_2to1_real_i386
#define synth_2to1_real_mono INT123_synth_2to1_real_mono
#define synth_2to1_real_m2s INT123_synth_2to1_real_m2s
#define synth_4to1_real INT123_synth_4to1_real
#define synth_4to1_real_i386 INT123_synth_4to1_real_i386
#define synth_4to1_real_mono INT123_synth_4to1_real_mono
#define synth_4to1_real_m2s INT123_synth_4to1_real_m2s
#define synth_ntom_real INT123_synth_ntom_real
#define synth_ntom_real_mono INT123_synth_ntom_real_mono
#define synth_ntom_real_m2s INT123_synth_ntom_real_m2s
#define synth_1to1_s32 INT123_synth_1to1_s32
#define synth_1to1_s32_i386 INT123_synth_1to1_s32_i386
#define synth_1to1_s32_sse INT123_synth_1to1_s32_sse
#define synth_1to1_s32_stereo_sse INT123_synth_1to1_s32_stereo_sse
#define synth_1to1_s32_x86_64 INT123_synth_1to1_s32_x86_64
#define synth_1to1_s32_stereo_x86_64 INT123_synth_1to1_s32_stereo_x86_64
#define synth_1to1_s32_avx INT123_synth_1to1_s32_avx
#define synth_1to1_s32_stereo_avx INT123_synth_1to1_s32_stereo_avx
#define synth_1to1_s32_altivec INT123_synth_1to1_s32_altivec
#define synth_1to1_s32_stereo_altivec INT123_synth_1to1_s32_stereo_altivec
#define synth_1to1_s32_neon INT123_synth_1to1_s32_neon
#define synth_1to1_s32_stereo_neon INT123_synth_1to1_s32_stereo_neon
#define synth_1to1_s32_neon64 INT123_synth_1to1_s32_neon64
#define synth_1to1_s32st_neon64 INT123_synth_1to1_s32st_neon64
#define synth_1to1_s32_mono INT123_synth_1to1_s32_mono
#define synth_1to1_s32_m2s INT123_synth_1to1_s32_m2s
#define synth_2to1_s32 INT123_synth_2to1_s32
#define synth_2to1_s32_i386 INT123_synth_2to1_s32_i386
#define synth_2to1_s32_mono INT123_synth_2to1_s32_mono
#define synth_2to1_s32_m2s INT123_synth_2to1_s32_m2s
#define synth_4to1_s32 INT123_synth_4to1_s32
#define synth_4to1_s32_i386 INT123_synth_4to1_s32_i386
#define synth_4to1_s32_mono INT123_synth_4to1_s32_mono
#define synth_4to1_s32_m2s INT123_synth_4to1_s32_m2s
#define synth_ntom_s32 INT123_synth_ntom_s32
#define synth_ntom_s32_mono INT123_synth_ntom_s32_mono
#define synth_ntom_s32_m2s INT123_synth_ntom_s32_m2s
#define dct64 INT123_dct64
#define dct64_i386 INT123_dct64_i386
#define dct64_altivec INT123_dct64_altivec
#define dct64_i486 INT123_dct64_i486
#define dct36 INT123_dct36
#define dct36_3dnow INT123_dct36_3dnow
#define dct36_3dnowext INT123_dct36_3dnowext
#define dct36_x86_64 INT123_dct36_x86_64
#define dct36_sse INT123_dct36_sse
#define dct36_avx INT123_dct36_avx
#define dct36_neon INT123_dct36_neon
#define dct36_neon64 INT123_dct36_neon64
#define synth_ntom_set_step INT123_synth_ntom_set_step
#define ntom_val INT123_ntom_val
#define ntom_frame_outsamples INT123_ntom_frame_outsamples
#define ntom_frmouts INT123_ntom_frmouts
#define ntom_ins2outs INT123_ntom_ins2outs
#define ntom_frameoff INT123_ntom_frameoff
#define init_layer3 INT123_init_layer3
#define init_layer3_gainpow2 INT123_init_layer3_gainpow2
#define init_layer3_stuff INT123_init_layer3_stuff
#define init_layer12 INT123_init_layer12
#define init_layer12_table INT123_init_layer12_table
#define init_layer12_stuff INT123_init_layer12_stuff
#define init_costabs INT123_init_costabs
#define make_decode_tables INT123_make_decode_tables
#define make_decode_tables_mmx INT123_make_decode_tables_mmx
#define init_layer3_gainpow2_mmx INT123_init_layer3_gainpow2_mmx
#define init_layer12_table_mmx INT123_init_layer12_table_mmx
#define make_conv16to8_table INT123_make_conv16to8_table
#define do_layer3 INT123_do_layer3
#define do_layer2 INT123_do_layer2
#define do_layer1 INT123_do_layer1
#define do_equalizer INT123_do_equalizer
#define dither_table_init INT123_dither_table_init
#define frame_dither_init INT123_frame_dither_init
#define invalidate_format INT123_invalidate_format
#define frame_init INT123_frame_init
#define frame_init_par INT123_frame_init_par
#define frame_outbuffer INT123_frame_outbuffer
#define frame_output_format INT123_frame_output_format
#define frame_buffers INT123_frame_buffers
#define frame_reset INT123_frame_reset
#define frame_buffers_reset INT123_frame_buffers_reset
#define frame_exit INT123_frame_exit
#define frame_index_find INT123_frame_index_find
#define frame_index_setup INT123_frame_index_setup
#define do_volume INT123_do_volume
#define do_rva INT123_do_rva
#define frame_gapless_init INT123_frame_gapless_init
#define frame_gapless_realinit INT123_frame_gapless_realinit
#define frame_gapless_update INT123_frame_gapless_update
#define frame_gapless_bytify INT123_frame_gapless_bytify
#define frame_gapless_ignore INT123_frame_gapless_ignore
#define frame_expect_outsamples INT123_frame_expect_outsamples
#define frame_skip INT123_frame_skip
#define frame_ins2outs INT123_frame_ins2outs
#define frame_outs INT123_frame_outs
#define frame_expect_outsampels INT123_frame_expect_outsampels
#define frame_offset INT123_frame_offset
#define frame_set_frameseek INT123_frame_set_frameseek
#define frame_set_seek INT123_frame_set_seek
#define frame_tell_seek INT123_frame_tell_seek
#define frame_fill_toc INT123_frame_fill_toc
#define getcpuflags INT123_getcpuflags
#define icy2utf8 INT123_icy2utf8
#define init_icy INT123_init_icy
#define clear_icy INT123_clear_icy
#define reset_icy INT123_reset_icy
#define init_id3 INT123_init_id3
#define exit_id3 INT123_exit_id3
#define reset_id3 INT123_reset_id3
#define id3_link INT123_id3_link
#define parse_new_id3 INT123_parse_new_id3
#define id3_to_utf8 INT123_id3_to_utf8
#define fi_init INT123_fi_init
#define fi_exit INT123_fi_exit
#define fi_resize INT123_fi_resize
#define fi_add INT123_fi_add
#define fi_set INT123_fi_set
#define fi_reset INT123_fi_reset
#define decode_update INT123_decode_update
#define decoder_synth_bytes INT123_decoder_synth_bytes
#define samples_to_bytes INT123_samples_to_bytes
#define bytes_to_samples INT123_bytes_to_samples
#define outblock_bytes INT123_outblock_bytes
#define postprocess_buffer INT123_postprocess_buffer
#define open_fixed_pre INT123_open_fixed_pre
#define open_fixed_post INT123_open_fixed_post
#define frame_cpu_opt INT123_frame_cpu_opt
#define set_synth_functions INT123_set_synth_functions
#define dectype INT123_dectype
#define defdec INT123_defdec
#define decclass INT123_decclass
#define read_frame_init INT123_read_frame_init
#define frame_bitrate INT123_frame_bitrate
#define frame_freq INT123_frame_freq
#define read_frame_recover INT123_read_frame_recover
#define read_frame INT123_read_frame
#define set_pointer INT123_set_pointer
#define position_info INT123_position_info
#define compute_bpf INT123_compute_bpf
#define time_to_frame INT123_time_to_frame
#define get_songlen INT123_get_songlen
#define bc_prepare INT123_bc_prepare
#define bc_cleanup INT123_bc_cleanup
#define bc_poolsize INT123_bc_poolsize
#define bc_fill INT123_bc_fill
#define open_stream INT123_open_stream
#define open_stream_handle INT123_open_stream_handle
#define open_feed INT123_open_feed
#define feed_more INT123_feed_more
#define feed_forget INT123_feed_forget
#define feed_set_pos INT123_feed_set_pos
#define open_bad INT123_open_bad
#define open_module INT123_open_module
#define close_module INT123_close_module
#define list_modules INT123_list_modules
#define buffer_init INT123_buffer_init
#define buffer_exit INT123_buffer_exit
#define buffer_sync_param INT123_buffer_sync_param
#define buffer_open INT123_buffer_open
#define buffer_encodings INT123_buffer_encodings
#define buffer_formats INT123_buffer_formats
#define buffer_start INT123_buffer_start
#define buffer_ndrain INT123_buffer_ndrain
#define buffer_stop INT123_buffer_stop
#define buffer_close INT123_buffer_close
#define buffer_continue INT123_buffer_continue
#define buffer_ignore_lowmem INT123_buffer_ignore_lowmem
#define buffer_drain INT123_buffer_drain
#define buffer_end INT123_buffer_end
#define buffer_pause INT123_buffer_pause
#define buffer_drop INT123_buffer_drop
#define buffer_write INT123_buffer_write
#define buffer_fill INT123_buffer_fill
#define read_buf INT123_read_buf
#define xfer_write_string INT123_xfer_write_string
#define xfer_read_string INT123_xfer_read_string
#define xfermem_init INT123_xfermem_init
#define xfermem_init_writer INT123_xfermem_init_writer
#define xfermem_init_reader INT123_xfermem_init_reader
#define xfermem_get_freespace INT123_xfermem_get_freespace
#define xfermem_get_usedspace INT123_xfermem_get_usedspace
#define xfermem_getcmd INT123_xfermem_getcmd
#define xfermem_getcmds INT123_xfermem_getcmds
#define xfermem_putcmd INT123_xfermem_putcmd
#define xfermem_writer_block INT123_xfermem_writer_block
#define xfermem_write INT123_xfermem_write
#define xfermem_done INT123_xfermem_done
#define au_open INT123_au_open
#define cdr_open INT123_cdr_open
#define raw_open INT123_raw_open
#define wav_open INT123_wav_open
#define wav_write INT123_wav_write
#define wav_close INT123_wav_close
#define au_close INT123_au_close
#define raw_close INT123_raw_close
#define cdr_formats INT123_cdr_formats
#define au_formats INT123_au_formats
#define raw_formats INT123_raw_formats
#define wav_formats INT123_wav_formats
#define wav_drain INT123_wav_drain
#define write_parameters INT123_write_parameters
#define read_parameters INT123_read_parameters
#define stringlists_add INT123_stringlists_add
#define check_neon INT123_check_neon
#define dct64_3dnow INT123_dct64_3dnow
#define dct64_3dnowext INT123_dct64_3dnowext
#define dct64_avx INT123_dct64_avx
#define dct64_real_avx INT123_dct64_real_avx
#define dct64_mmx INT123_dct64_mmx
#define dct64_MMX INT123_dct64_MMX
#define dct64_neon INT123_dct64_neon
#define dct64_neon64 INT123_dct64_neon64
#define dct64_real_neon64 INT123_dct64_real_neon64
#define dct64_real_neon INT123_dct64_real_neon
#define dct64_sse INT123_dct64_sse
#define dct64_real_sse INT123_dct64_real_sse
#define dct64_x86_64 INT123_dct64_x86_64
#define dct64_real_x86_64 INT123_dct64_real_x86_64
#define do_equalizer_3dnow INT123_do_equalizer_3dnow
#define synth_1to1_3dnow_asm INT123_synth_1to1_3dnow_asm
#define synth_1to1_arm_asm INT123_synth_1to1_arm_asm
#define synth_1to1_arm_accurate_asm INT123_synth_1to1_arm_accurate_asm
#define synth_1to1_i586_asm INT123_synth_1to1_i586_asm
#define synth_1to1_i586_asm_dither INT123_synth_1to1_i586_asm_dither
#define synth_1to1_MMX INT123_synth_1to1_MMX
#define synth_1to1_neon_asm INT123_synth_1to1_neon_asm
#define synth_1to1_neon64_asm INT123_synth_1to1_neon64_asm
#define synth_1to1_neon64_accurate_asm INT123_synth_1to1_neon64_accurate_asm
#define synth_1to1_real_neon64_asm INT123_synth_1to1_real_neon64_asm
#define synth_1to1_s32_neon64_asm INT123_synth_1to1_s32_neon64_asm
#define synth_1to1_neon_accurate_asm INT123_synth_1to1_neon_accurate_asm
#define synth_1to1_real_neon_asm INT123_synth_1to1_real_neon_asm
#define synth_1to1_s32_neon_asm INT123_synth_1to1_s32_neon_asm
#define synth_1to1_sse_accurate_asm INT123_synth_1to1_sse_accurate_asm
#define synth_1to1_real_sse_asm INT123_synth_1to1_real_sse_asm
#define synth_1to1_s32_sse_asm INT123_synth_1to1_s32_sse_asm
#define synth_1to1_s_avx_asm INT123_synth_1to1_s_avx_asm
#define synth_1to1_s_avx_accurate_asm INT123_synth_1to1_s_avx_accurate_asm
#define synth_1to1_real_s_avx_asm INT123_synth_1to1_real_s_avx_asm
#define synth_1to1_s32_s_avx_asm INT123_synth_1to1_s32_s_avx_asm
#define synth_1to1_s_neon_asm INT123_synth_1to1_s_neon_asm
#define synth_1to1_s_neon64_asm INT123_synth_1to1_s_neon64_asm
#define synth_1to1_s_neon64_accurate_asm INT123_synth_1to1_s_neon64_accurate_asm
#define synth_1to1_real_s_neon64_asm INT123_synth_1to1_real_s_neon64_asm
#define synth_1to1_s32_s_neon64_asm INT123_synth_1to1_s32_s_neon64_asm
#define synth_1to1_s_neon_accurate_asm INT123_synth_1to1_s_neon_accurate_asm
#define synth_1to1_real_s_neon_asm INT123_synth_1to1_real_s_neon_asm
#define synth_1to1_s32_s_neon_asm INT123_synth_1to1_s32_s_neon_asm
#define synth_1to1_s_sse_accurate_asm INT123_synth_1to1_s_sse_accurate_asm
#define synth_1to1_real_s_sse_asm INT123_synth_1to1_real_s_sse_asm
#define synth_1to1_s32_s_sse_asm INT123_synth_1to1_s32_s_sse_asm
#define synth_1to1_s_x86_64_asm INT123_synth_1to1_s_x86_64_asm
#define synth_1to1_s_x86_64_accurate_asm INT123_synth_1to1_s_x86_64_accurate_asm
#define synth_1to1_real_s_x86_64_asm INT123_synth_1to1_real_s_x86_64_asm
#define synth_1to1_s32_s_x86_64_asm INT123_synth_1to1_s32_s_x86_64_asm
#define synth_1to1_x86_64_asm INT123_synth_1to1_x86_64_asm
#define synth_1to1_x86_64_accurate_asm INT123_synth_1to1_x86_64_accurate_asm
#define synth_1to1_real_x86_64_asm INT123_synth_1to1_real_x86_64_asm
#define synth_1to1_s32_x86_64_asm INT123_synth_1to1_s32_x86_64_asm
#define costab_mmxsse INT123_costab_mmxsse
#define make_decode_tables_mmx_asm INT123_make_decode_tables_mmx_asm
#ifndef HAVE_STRERROR
#define strerror INT123_strerror
#endif
#endif

View File

@ -0,0 +1,41 @@
/*
abi_align: An attempt to avoid breakage because of mixing
compilers with different alignment.
copyright 1995-2015 by the mpg123 project
free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
There used to be code that checks alignment, but it did not really
work anyway. The only straw we have is putting that alignment
attribute to API functions.
*/
#ifndef MPG123_H_ABI_ALIGN
#define MPG123_H_ABI_ALIGN
#include "config.h"
/* ABI conformance for other compilers.
mpg123 needs 16byte-aligned (or more) stack for SSE and friends.
gcc provides that, but others don't necessarily. */
#ifdef ABI_ALIGN_FUN
#ifndef attribute_align_arg
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
# define attribute_align_arg __attribute__((force_align_arg_pointer))
/* The gcc that can align the stack does not need the check... nor does it work with gcc 4.3+, anyway. */
#else
# define attribute_align_arg
#endif
#endif /* attribute_align_arg */
#else /* ABI_ALIGN_FUN */
#define attribute_align_arg
#endif /* ABI_ALIGN_FUN */
#endif /* MPG123_H_ABI_ALIGN */

View File

@ -0,0 +1,81 @@
// cos MPEG decoding tables
// output of:
// src/libmpg123/calctables cos
#if defined(RUNTIME_TABLES)
#ifdef REAL_IS_FLOAT
// aligned to 16 bytes for vector instructions, e.g. AltiVec
static ALIGNED(16) real cos64[16];
static ALIGNED(16) real cos32[8];
static ALIGNED(16) real cos16[4];
static ALIGNED(16) real cos8[2];
static ALIGNED(16) real cos4[1];
#endif
#else
#ifdef REAL_IS_FLOAT
// aligned to 16 bytes for vector instructions, e.g. AltiVec
static const ALIGNED(16) real cos64[16] =
{
5.00602998e-01, 5.05470960e-01, 5.15447310e-01, 5.31042591e-01
, 5.53103896e-01, 5.82934968e-01, 6.22504123e-01, 6.74808341e-01
, 7.44536271e-01, 8.39349645e-01, 9.72568238e-01, 1.16943993e+00
, 1.48416462e+00, 2.05778101e+00, 3.40760842e+00, 1.01900081e+01
};
static const ALIGNED(16) real cos32[8] =
{
5.02419286e-01, 5.22498615e-01, 5.66944035e-01, 6.46821783e-01
, 7.88154623e-01, 1.06067769e+00, 1.72244710e+00, 5.10114862e+00
};
static const ALIGNED(16) real cos16[4] =
{
5.09795579e-01, 6.01344887e-01, 8.99976223e-01, 2.56291545e+00
};
static const ALIGNED(16) real cos8[2] =
{
5.41196100e-01, 1.30656296e+00
};
static const ALIGNED(16) real cos4[1] =
{
7.07106781e-01
};
#endif
#ifdef REAL_IS_FIXED
static const real cos64[16] =
{
8398725, 8480395, 8647771, 8909416
, 9279544, 9780026, 10443886, 11321405
, 12491246, 14081950, 16316987, 19619946
, 24900150, 34523836, 57170182, 170959967
};
static const real cos32[8] =
{
8429197, 8766072, 9511743, 10851869
, 13223040, 17795219, 28897867, 85583072
};
static const real cos16[4] =
{
8552951, 10088893, 15099095, 42998586
};
static const real cos8[2] =
{
9079764, 21920489
};
static const real cos4[1] =
{
11863283
};
#endif
#endif

View File

@ -0,0 +1,175 @@
/*
dct64.c: DCT64, the plain C version
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
*/
/*
* Discrete Cosine Tansform (DCT) for subband synthesis
*
* -funroll-loops (for gcc) will remove the loops for better performance
* using loops in the source-code enhances readabillity
*
*
* TODO: write an optimized version for the down-sampling modes
* (in these modes the bands 16-31 (2:1) or 8-31 (4:1) are zero
*/
#include "mpg123lib_intern.h"
void dct64(real *out0,real *out1,real *samples)
{
real bufs[64];
{
register int i,j;
register real *b1,*b2,*bs;
register const real *costab;
b1 = samples;
bs = bufs;
costab = pnts[0]+16;
b2 = b1 + 32;
for(i=15;i>=0;i--)
*bs++ = (*b1++ + *--b2);
for(i=15;i>=0;i--)
*bs++ = REAL_MUL((*--b2 - *b1++), *--costab);
b1 = bufs;
costab = pnts[1]+8;
b2 = b1 + 16;
{
for(i=7;i>=0;i--)
*bs++ = (*b1++ + *--b2);
for(i=7;i>=0;i--)
*bs++ = REAL_MUL((*--b2 - *b1++), *--costab);
b2 += 32;
costab += 8;
for(i=7;i>=0;i--)
*bs++ = (*b1++ + *--b2);
for(i=7;i>=0;i--)
*bs++ = REAL_MUL((*b1++ - *--b2), *--costab);
b2 += 32;
}
bs = bufs;
costab = pnts[2];
b2 = b1 + 8;
for(j=2;j;j--)
{
for(i=3;i>=0;i--)
*bs++ = (*b1++ + *--b2);
for(i=3;i>=0;i--)
*bs++ = REAL_MUL((*--b2 - *b1++), costab[i]);
b2 += 16;
for(i=3;i>=0;i--)
*bs++ = (*b1++ + *--b2);
for(i=3;i>=0;i--)
*bs++ = REAL_MUL((*b1++ - *--b2), costab[i]);
b2 += 16;
}
b1 = bufs;
costab = pnts[3];
b2 = b1 + 4;
for(j=4;j;j--)
{
*bs++ = (*b1++ + *--b2);
*bs++ = (*b1++ + *--b2);
*bs++ = REAL_MUL((*--b2 - *b1++), costab[1]);
*bs++ = REAL_MUL((*--b2 - *b1++), costab[0]);
b2 += 8;
*bs++ = (*b1++ + *--b2);
*bs++ = (*b1++ + *--b2);
*bs++ = REAL_MUL((*b1++ - *--b2), costab[1]);
*bs++ = REAL_MUL((*b1++ - *--b2), costab[0]);
b2 += 8;
}
bs = bufs;
costab = pnts[4];
for(j=8;j;j--)
{
real v0,v1;
v0=*b1++; v1 = *b1++;
*bs++ = (v0 + v1);
*bs++ = REAL_MUL((v0 - v1), (*costab));
v0=*b1++; v1 = *b1++;
*bs++ = (v0 + v1);
*bs++ = REAL_MUL((v1 - v0), (*costab));
}
}
{
register real *b1;
register int i;
for(b1=bufs,i=8;i;i--,b1+=4)
b1[2] += b1[3];
for(b1=bufs,i=4;i;i--,b1+=8)
{
b1[4] += b1[6];
b1[6] += b1[5];
b1[5] += b1[7];
}
for(b1=bufs,i=2;i;i--,b1+=16)
{
b1[8] += b1[12];
b1[12] += b1[10];
b1[10] += b1[14];
b1[14] += b1[9];
b1[9] += b1[13];
b1[13] += b1[11];
b1[11] += b1[15];
}
}
out0[0x10*16] = REAL_SCALE_DCT64(bufs[0]);
out0[0x10*15] = REAL_SCALE_DCT64(bufs[16+0] + bufs[16+8]);
out0[0x10*14] = REAL_SCALE_DCT64(bufs[8]);
out0[0x10*13] = REAL_SCALE_DCT64(bufs[16+8] + bufs[16+4]);
out0[0x10*12] = REAL_SCALE_DCT64(bufs[4]);
out0[0x10*11] = REAL_SCALE_DCT64(bufs[16+4] + bufs[16+12]);
out0[0x10*10] = REAL_SCALE_DCT64(bufs[12]);
out0[0x10* 9] = REAL_SCALE_DCT64(bufs[16+12] + bufs[16+2]);
out0[0x10* 8] = REAL_SCALE_DCT64(bufs[2]);
out0[0x10* 7] = REAL_SCALE_DCT64(bufs[16+2] + bufs[16+10]);
out0[0x10* 6] = REAL_SCALE_DCT64(bufs[10]);
out0[0x10* 5] = REAL_SCALE_DCT64(bufs[16+10] + bufs[16+6]);
out0[0x10* 4] = REAL_SCALE_DCT64(bufs[6]);
out0[0x10* 3] = REAL_SCALE_DCT64(bufs[16+6] + bufs[16+14]);
out0[0x10* 2] = REAL_SCALE_DCT64(bufs[14]);
out0[0x10* 1] = REAL_SCALE_DCT64(bufs[16+14] + bufs[16+1]);
out0[0x10* 0] = REAL_SCALE_DCT64(bufs[1]);
out1[0x10* 0] = REAL_SCALE_DCT64(bufs[1]);
out1[0x10* 1] = REAL_SCALE_DCT64(bufs[16+1] + bufs[16+9]);
out1[0x10* 2] = REAL_SCALE_DCT64(bufs[9]);
out1[0x10* 3] = REAL_SCALE_DCT64(bufs[16+9] + bufs[16+5]);
out1[0x10* 4] = REAL_SCALE_DCT64(bufs[5]);
out1[0x10* 5] = REAL_SCALE_DCT64(bufs[16+5] + bufs[16+13]);
out1[0x10* 6] = REAL_SCALE_DCT64(bufs[13]);
out1[0x10* 7] = REAL_SCALE_DCT64(bufs[16+13] + bufs[16+3]);
out1[0x10* 8] = REAL_SCALE_DCT64(bufs[3]);
out1[0x10* 9] = REAL_SCALE_DCT64(bufs[16+3] + bufs[16+11]);
out1[0x10*10] = REAL_SCALE_DCT64(bufs[11]);
out1[0x10*11] = REAL_SCALE_DCT64(bufs[16+11] + bufs[16+7]);
out1[0x10*12] = REAL_SCALE_DCT64(bufs[7]);
out1[0x10*13] = REAL_SCALE_DCT64(bufs[16+7] + bufs[16+15]);
out1[0x10*14] = REAL_SCALE_DCT64(bufs[15]);
out1[0x10*15] = REAL_SCALE_DCT64(bufs[16+15]);
}

View File

@ -0,0 +1,132 @@
/*
Some macros for printing debugging/warning/error messages with location info.
public domain (or LGPL / GPL, if you like that more;-)
generated by debugdef.pl, what was
trivially written by Thomas Orgis <thomas@orgis.org>
You decide to define DEBUG or not and write debug("foo") or
mdebug("foo: %s", message) and variants with more arguments and this
is converted to an elaborate call to fprintf(stderr, ...) that prints your
message with a line end attached and with information on where the call
occured.
*/
#include "config.h"
#ifdef ME
#define DBGPRFX ME": "
#else
#define DBGPRFX ""
#endif
#define noop ((void)0)
#ifdef XDEBUG
#define mxdebug(s, ...) mdebug(s, __VA_ARGS__)
#define xdebug(s) debug(s)
#else
#define mxdebug(s, ...) noop
#define xdebug(s) noop
#endif
// Used for debugging and warning messages.
#include <stdio.h>
#define debug_print(t, s, ...) fprintf(stderr, DBGPRFX "[" __FILE__ ":%s():%i] " t ": " s "\n", __func__, __LINE__, __VA_ARGS__)
#ifdef DEBUG
#define mdebug(s, ...) debug_print("debug", s, __VA_ARGS__)
#else
#define mdebug(s, ...) noop
#endif
#define debug(s) mdebug("%s", s)
// Print warning message.
#ifndef NO_WARNING
#define mwarning(s, ...) debug_print("warning", s, __VA_ARGS__)
#else
#define mwarning(s, ...)
#endif
#define warning(s) mwarning("%s", s)
// Print error message.
#ifndef NO_ERRORMSG
#define merror(s, ...) debug_print("error", s, __VA_ARGS__)
#else
#define merror(s, ...) noop
#endif
#define error(s) merror("%s", s)
// Print error message and return given value.
#ifndef NO_ERETURN
#define mereturn(rv, s, ...) do{ debug_print("ereturn", s, __VA_ARGS__); return rv; } while (0)
#else
#define mereturn(rv, s, ...) return rv
#endif
#define ereturn(rv, s) mereturn(rv, "%s", s)
// For old code that had to hardcode the argument number.
#define debug1(s, a) mdebug(s,a)
#define debug2(s, a, b) mdebug(s, a, b)
#define debug3(s, a, b, c) mdebug(s, a, b, c)
#define debug4(s, a, b, c, d) mdebug(s, a, b, c, d)
#define debug5(s, a, b, c, d, e) mdebug(s, a, b, c, d, e)
#define debug6(s, a, b, c, d, e, f) mdebug(s, a, b, c, d, e, f)
#define debug7(s, a, b, c, d, e, f, g) mdebug(s, a, b, c, d, e, f, g)
#define debug8(s, a, b, c, d, e, f, g, h) mdebug(s, a, b, c, d, e, f, g, h)
#define debug9(s, a, b, c, d, e, f, g, h, i) mdebug(s, a, b, c, d, e, f, g, h, i)
#define debug10(s, a, b, c, d, e, f, g, h, i, j) mdebug(s, a, b, c, d, e, f, g, h, i, j)
#define debug11(s, a, b, c, d, e, f, g, h, i, j, k) mdebug(s, a, b, c, d, e, f, g, h, i, j, k)
#define debug12(s, a, b, c, d, e, f, g, h, i, j, k, l) mdebug(s, a, b, c, d, e, f, g, h, i, j, k, l)
#define debug13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) mdebug(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
#define debug14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) mdebug(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define debug15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) mdebug(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#define warning1(s, a) mwarning(s, a)
#define warning2(s, a, b) mwarning(s, a, b)
#define warning3(s, a, b, c) mwarning(s, a, b, c)
#define warning4(s, a, b, c, d) mwarning(s, a, b, c, d)
#define warning5(s, a, b, c, d, e) mwarning(s, a, b, c, d, e)
#define warning6(s, a, b, c, d, e, f) mwarning(s, a, b, c, d, e, f)
#define warning7(s, a, b, c, d, e, f, g) mwarning(s, a, b, c, d, e, f, g)
#define warning8(s, a, b, c, d, e, f, g, h) mwarning(s, a, b, c, d, e, f, g, h)
#define warning9(s, a, b, c, d, e, f, g, h, i) mwarning(s, a, b, c, d, e, f, g, h, i)
#define warning10(s, a, b, c, d, e, f, g, h, i, j) mwarning(s, a, b, c, d, e, f, g, h, i, j)
#define warning11(s, a, b, c, d, e, f, g, h, i, j, k) mwarning(s, a, b, c, d, e, f, g, h, i, j, k)
#define warning12(s, a, b, c, d, e, f, g, h, i, j, k, l) mwarning(s, a, b, c, d, e, f, g, h, i, j, k, l)
#define warning13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) mwarning(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
#define warning14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) mwarning(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define warning15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) mwarning(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#define error1(s, a) merror(s, a)
#define error2(s, a, b) merror(s, a, b)
#define error3(s, a, b, c) merror(s, a, b, c)
#define error4(s, a, b, c, d) merror(s, a, b, c, d)
#define error5(s, a, b, c, d, e) merror(s, a, b, c, d, e)
#define error6(s, a, b, c, d, e, f) merror(s, a, b, c, d, e, f)
#define error7(s, a, b, c, d, e, f, g) merror(s, a, b, c, d, e, f, g)
#define error8(s, a, b, c, d, e, f, g, h) merror(s, a, b, c, d, e, f, g, h)
#define error9(s, a, b, c, d, e, f, g, h, i) merror(s, a, b, c, d, e, f, g, h, i)
#define error10(s, a, b, c, d, e, f, g, h, i, j) merror(s, a, b, c, d, e, f, g, h, i, j)
#define error11(s, a, b, c, d, e, f, g, h, i, j, k) merror(s, a, b, c, d, e, f, g, h, i, j, k)
#define error12(s, a, b, c, d, e, f, g, h, i, j, k, l) merror(s, a, b, c, d, e, f, g, h, i, j, k, l)
#define error13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) merror(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
#define error14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) merror(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define error15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) merror(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#define ereturn1(rv, s, a) mereturn(rv, s, a)
#define ereturn2(rv, s, a, b) mereturn(rv, s, a, b)
#define ereturn3(rv, s, a, b, c) mereturn(rv, s, a, b, c)
#define ereturn4(rv, s, a, b, c, d) mereturn(rv, s, a, b, c, d)
#define ereturn5(rv, s, a, b, c, d, e) mereturn(rv, s, a, b, c, d, e)
#define ereturn6(rv, s, a, b, c, d, e, f) mereturn(rv, s, a, b, c, d, e, f)
#define ereturn7(rv, s, a, b, c, d, e, f, g) mereturn(rv, s, a, b, c, d, e, f, g)
#define ereturn8(rv, s, a, b, c, d, e, f, g, h) mereturn(rv, s, a, b, c, d, e, f, g, h)
#define ereturn9(rv, s, a, b, c, d, e, f, g, h, i) mereturn(rv, s, a, b, c, d, e, f, g, h, i)
#define ereturn10(rv, s, a, b, c, d, e, f, g, h, i, j) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j)
#define ereturn11(rv, s, a, b, c, d, e, f, g, h, i, j, k) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j, k)
#define ereturn12(rv, s, a, b, c, d, e, f, g, h, i, j, k, l) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j, k, l)
#define ereturn13(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m)
#define ereturn14(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define ereturn15(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) mereturn(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)

View File

@ -0,0 +1,292 @@
/*
decode.h: common definitions for decode functions
This file is strongly tied with optimize.h concerning the synth functions.
Perhaps one should restructure that a bit.
copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, taking WRITE_SAMPLE from decode.c
*/
#ifndef MPG123_DECODE_H
#define MPG123_DECODE_H
/* Selection of class of output routines for basic format. */
#ifndef REAL_IS_FIXED
#define OUT_FORMATS 4 /* Basic output formats: 16bit, 8bit, real and s32 */
#else
#define OUT_FORMATS 2 /* Only up to 16bit */
#endif
#define OUT_16 0
#define OUT_8 1
/* Those are defined but not supported for fixed point decoding! */
#define OUT_REAL 2 /* Write a floating point sample (that is, one matching the internal real type). */
#define OUT_S32 3
#ifdef NO_NTOM
#define NTOM_MAX 1
#else
#define NTOM_MAX 8 /* maximum allowed factor for upsampling */
#define NTOM_MAX_FREQ 96000 /* maximum frequency to upsample to / downsample from */
#define NTOM_MUL (32768)
void ntom_set_ntom(mpg123_handle *fr, off_t num);
#endif
/* Let's collect all possible synth functions here, for an overview.
If they are actually defined and used depends on preprocessor machinery.
See synth.c and optimize.h for that, also some special C and assembler files. */
#ifndef NO_16BIT
/* The signed-16bit-producing variants. */
int synth_1to1 (real*, int, mpg123_handle*, int);
int synth_1to1_dither (real*, int, mpg123_handle*, int);
int synth_1to1_i386 (real*, int, mpg123_handle*, int);
int synth_1to1_i586 (real*, int, mpg123_handle*, int);
int synth_1to1_i586_dither(real*, int, mpg123_handle*, int);
int synth_1to1_mmx (real*, int, mpg123_handle*, int);
int synth_1to1_3dnow (real*, int, mpg123_handle*, int);
int synth_1to1_sse (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_sse (real*, real*, mpg123_handle*);
int synth_1to1_3dnowext (real*, int, mpg123_handle*, int);
int synth_1to1_altivec (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_altivec(real*, real*, mpg123_handle*);
int synth_1to1_x86_64 (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_x86_64(real*, real*, mpg123_handle*);
int synth_1to1_avx (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_avx (real*, real*, mpg123_handle*);
int synth_1to1_arm (real*, int, mpg123_handle*, int);
int synth_1to1_neon (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_neon(real*, real*, mpg123_handle*);
int synth_1to1_neon64 (real*, int, mpg123_handle*, int);
int synth_1to1_stereo_neon64(real*, real*, mpg123_handle*);
/* This is different, special usage in layer3.c only.
Hence, the name... and now forget about it.
Never use it outside that special portion of code inside layer3.c! */
int absynth_1to1_i486(real*, int, mpg123_handle*, int);
/* These mono/stereo converters use one of the above for the grunt work. */
int synth_1to1_mono (real*, mpg123_handle*);
int synth_1to1_m2s(real*, mpg123_handle*);
/* Sample rate decimation comes in less flavours. */
#ifndef NO_DOWNSAMPLE
int synth_2to1 (real*, int, mpg123_handle*, int);
int synth_2to1_dither (real*, int, mpg123_handle*, int);
int synth_2to1_i386 (real*, int, mpg123_handle*, int);
int synth_2to1_mono (real*, mpg123_handle*);
int synth_2to1_m2s(real*, mpg123_handle*);
int synth_4to1 (real *,int, mpg123_handle*, int);
int synth_4to1_dither (real *,int, mpg123_handle*, int);
int synth_4to1_i386 (real*, int, mpg123_handle*, int);
int synth_4to1_mono (real*, mpg123_handle*);
int synth_4to1_m2s(real*, mpg123_handle*);
#endif
#ifndef NO_NTOM
/* NtoM is really just one implementation. */
int synth_ntom (real *,int, mpg123_handle*, int);
int synth_ntom_mono (real *, mpg123_handle *);
int synth_ntom_m2s (real *, mpg123_handle *);
#endif
#endif
#ifndef NO_8BIT
/* The 8bit-producing variants. */
/* There are direct 8-bit synths and wrappers over a possibly optimized 16bit one. */
int synth_1to1_8bit (real*, int, mpg123_handle*, int);
int synth_1to1_8bit_i386 (real*, int, mpg123_handle*, int);
#ifndef NO_16BIT
int synth_1to1_8bit_wrap (real*, int, mpg123_handle*, int);
int synth_1to1_8bit_mono (real*, mpg123_handle*);
#endif
int synth_1to1_8bit_m2s(real*, mpg123_handle*);
#ifndef NO_16BIT
int synth_1to1_8bit_wrap_mono (real*, mpg123_handle*);
int synth_1to1_8bit_wrap_m2s(real*, mpg123_handle*);
#endif
#ifndef NO_DOWNSAMPLE
int synth_2to1_8bit (real*, int, mpg123_handle*, int);
int synth_2to1_8bit_i386 (real*, int, mpg123_handle*, int);
int synth_2to1_8bit_mono (real*, mpg123_handle*);
int synth_2to1_8bit_m2s(real*, mpg123_handle*);
int synth_4to1_8bit (real*, int, mpg123_handle*, int);
int synth_4to1_8bit_i386 (real*, int, mpg123_handle*, int);
int synth_4to1_8bit_mono (real*, mpg123_handle*);
int synth_4to1_8bit_m2s(real*, mpg123_handle*);
#endif
#ifndef NO_NTOM
int synth_ntom_8bit (real*, int, mpg123_handle*, int);
int synth_ntom_8bit_mono (real*, mpg123_handle*);
int synth_ntom_8bit_m2s(real*, mpg123_handle*);
#endif
#endif
#ifndef REAL_IS_FIXED
#ifndef NO_REAL
/* The real-producing variants. */
int synth_1to1_real (real*, int, mpg123_handle*, int);
int synth_1to1_real_i386 (real*, int, mpg123_handle*, int);
int synth_1to1_real_sse (real*, int, mpg123_handle*, int);
int synth_1to1_real_stereo_sse (real*, real*, mpg123_handle*);
int synth_1to1_real_x86_64 (real*, int, mpg123_handle*, int);
int synth_1to1_real_stereo_x86_64(real*, real*, mpg123_handle*);
int synth_1to1_real_avx (real*, int, mpg123_handle*, int);
int synth_1to1_fltst_avx (real*, real*, mpg123_handle*);
int synth_1to1_real_altivec (real*, int, mpg123_handle*, int);
int synth_1to1_fltst_altivec(real*, real*, mpg123_handle*);
int synth_1to1_real_neon (real*, int, mpg123_handle*, int);
int synth_1to1_real_stereo_neon(real*, real*, mpg123_handle*);
int synth_1to1_real_neon64 (real*, int, mpg123_handle*, int);
int synth_1to1_fltst_neon64(real*, real*, mpg123_handle*);
int synth_1to1_real_mono (real*, mpg123_handle*);
int synth_1to1_real_m2s(real*, mpg123_handle*);
#ifndef NO_DOWNSAMPLE
int synth_2to1_real (real*, int, mpg123_handle*, int);
int synth_2to1_real_i386 (real*, int, mpg123_handle*, int);
int synth_2to1_real_mono (real*, mpg123_handle*);
int synth_2to1_real_m2s(real*, mpg123_handle*);
int synth_4to1_real (real*, int, mpg123_handle*, int);
int synth_4to1_real_i386 (real*, int, mpg123_handle*, int);
int synth_4to1_real_mono (real*, mpg123_handle*);
int synth_4to1_real_m2s(real*, mpg123_handle*);
#endif
#ifndef NO_NTOM
int synth_ntom_real (real*, int, mpg123_handle*, int);
int synth_ntom_real_mono (real*, mpg123_handle*);
int synth_ntom_real_m2s(real*, mpg123_handle*);
#endif
#endif
#ifndef NO_32BIT
/* 32bit integer */
int synth_1to1_s32 (real*, int, mpg123_handle*, int);
int synth_1to1_s32_i386 (real*, int, mpg123_handle*, int);
int synth_1to1_s32_sse (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_sse (real*, real*, mpg123_handle*);
int synth_1to1_s32_x86_64 (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_x86_64(real*, real*, mpg123_handle*);
int synth_1to1_s32_avx (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_avx (real*, real*, mpg123_handle*);
int synth_1to1_s32_altivec (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_altivec(real*, real*, mpg123_handle*);
int synth_1to1_s32_neon (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_neon(real*, real*, mpg123_handle*);
int synth_1to1_s32_neon64 (real*, int, mpg123_handle*, int);
int synth_1to1_s32st_neon64(real*, real*, mpg123_handle*);
int synth_1to1_s32_mono (real*, mpg123_handle*);
int synth_1to1_s32_m2s(real*, mpg123_handle*);
#ifndef NO_DOWNSAMPLE
int synth_2to1_s32 (real*, int, mpg123_handle*, int);
int synth_2to1_s32_i386 (real*, int, mpg123_handle*, int);
int synth_2to1_s32_mono (real*, mpg123_handle*);
int synth_2to1_s32_m2s(real*, mpg123_handle*);
int synth_4to1_s32 (real*, int, mpg123_handle*, int);
int synth_4to1_s32_i386 (real*, int, mpg123_handle*, int);
int synth_4to1_s32_mono (real*, mpg123_handle*);
int synth_4to1_s32_m2s(real*, mpg123_handle*);
#endif
#ifndef NO_NTOM
int synth_ntom_s32 (real*, int, mpg123_handle*, int);
int synth_ntom_s32_mono (real*, mpg123_handle*);
int synth_ntom_s32_m2s(real*, mpg123_handle*);
#endif
#endif
#endif /* FIXED */
/* Inside these synth functions, some dct64 variants may be used.
The special optimized ones that only appear in assembler code are not mentioned here.
And, generally, these functions are only employed in a matching synth function. */
void dct64 (real *,real *,real *);
void dct64_i386 (real *,real *,real *);
void dct64_altivec(real *,real *,real *);
void dct64_i486(int*, int* , real*); /* Yeah, of no use outside of synth_i486.c .*/
/* This is used by the layer 3 decoder, one generic function and 3DNow variants. */
void dct36 (real *,real *,real *,const real *,real *);
void dct36_3dnow (real *,real *,real *,const real *,real *);
void dct36_3dnowext(real *,real *,real *,const real *,real *);
void dct36_x86_64 (real *,real *,real *,const real *,real *);
void dct36_sse (real *,real *,real *,const real *,real *);
void dct36_avx (real *,real *,real *,const real *,real *);
void dct36_neon (real *,real *,real *,const real *,real *);
void dct36_neon64 (real *,real *,real *,const real *,real *);
/* Tools for NtoM resampling synth, defined in ntom.c . */
int synth_ntom_set_step(mpg123_handle *fr); /* prepare ntom decoding */
unsigned long ntom_val(mpg123_handle *fr, off_t frame); /* compute ntom_val for frame offset */
/* Frame and sample offsets. */
#ifndef NO_NTOM
/*
Outsamples of _this_ frame.
To be exact: The samples to be expected from the next frame decode (using the current ntom_val). When you already decoded _this_ frame, this is the number of samples to be expected from the next one.
*/
off_t ntom_frame_outsamples(mpg123_handle *fr);
/* Total out/insample offset. */
off_t ntom_frmouts(mpg123_handle *fr, off_t frame);
off_t ntom_ins2outs(mpg123_handle *fr, off_t ins);
off_t ntom_frameoff(mpg123_handle *fr, off_t soff);
#endif
/* Initialization of any static data that majy be needed at runtime.
Make sure you call these once before it is too late. */
#ifndef NO_LAYER3
#ifdef RUNTIME_TABLES
void init_layer3(void);
#endif
real init_layer3_gainpow2(mpg123_handle *fr, int i);
void init_layer3_stuff(mpg123_handle *fr, real (*gainpow2)(mpg123_handle *fr, int i));
#endif
#ifndef NO_LAYER12
#ifdef RUNTIME_TABLES
void init_layer12(void);
#endif
real* init_layer12_table(mpg123_handle *fr, real *table, int m);
void init_layer12_stuff(mpg123_handle *fr, real* (*init_table)(mpg123_handle *fr, real *table, int m));
#endif
#ifdef RUNTIME_TABLES
void init_costabs(void);
#else
const
#endif
extern real *pnts[5]; /* costab.h provides, dct64 needs */
/* Runtime (re)init functions; needed more often. */
void make_decode_tables(mpg123_handle *fr); /* For every volume change. */
/* Stuff needed after updating synth setup (see set_synth_functions()). */
#ifdef OPT_MMXORSSE
/* Special treatment for mmx-like decoders, these functions go into the slots below. */
void make_decode_tables_mmx(mpg123_handle *fr);
#ifndef NO_LAYER3
real init_layer3_gainpow2_mmx(mpg123_handle *fr, int i);
#endif
#ifndef NO_LAYER12
real* init_layer12_table_mmx(mpg123_handle *fr, real *table, int m);
#endif
#endif
#ifndef NO_8BIT
/* Needed when switching to 8bit output. */
int make_conv16to8_table(mpg123_handle *fr);
#endif
/* These are the actual workers.
They operate on the parsed frame data and handle decompression to audio samples.
The synth functions defined above are called from inside the layer handlers. */
#ifndef NO_LAYER3
int do_layer3(mpg123_handle *fr);
#endif
#ifndef NO_LAYER2
int do_layer2(mpg123_handle *fr);
#endif
#ifndef NO_LAYER1
int do_layer1(mpg123_handle *fr);
#endif
/* There's an 3DNow counterpart in asm. */
void do_equalizer(real *bandPtr,int channel, real equalizer[2][32]);
#endif

View File

@ -0,0 +1,3 @@
/* Hack to allow building the same code with and without libtool. */
#include "intsym.h"
#include "dither_impl.h"

View File

@ -0,0 +1,23 @@
/*
dither: Generate noise for dithering / noise shaping.
copyright 2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Taihei Monma
*/
#ifndef MPG123_DITHER_H
#define MPG123_DITHER_H
#define DITHERSIZE 65536
enum mpg123_noise_type
{
mpg123_white_noise = 0
,mpg123_tpdf_noise
,mpg123_highpass_tpdf_noise
};
void mpg123_noise(float* table, size_t count, enum mpg123_noise_type noisetype);
void dither_table_init(float *dithertable);
#endif

View File

@ -0,0 +1,119 @@
/*
dither: Generate shaped noise for dithering
copyright 2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Taihei Monma
*/
#include "config.h"
#include "compat.h"
#include "dither.h"
static const uint32_t init_seed = 2463534242UL;
#define LAP 100
/*
xorshift random number generator, with output scaling to [-0.5, 0.5]
This is the white noise...
See http://www.jstatsoft.org/v08/i14/paper on XOR shift random number generators.
*/
static float rand_xorshift32(uint32_t *seed)
{
union
{
uint32_t i;
float f;
} fi;
fi.i = *seed;
fi.i ^= (fi.i<<13);
fi.i ^= (fi.i>>17);
fi.i ^= (fi.i<<5);
*seed = fi.i;
/* scale the number to [-0.5, 0.5] */
#ifdef IEEE_FLOAT
fi.i = (fi.i>>9)|0x3f800000;
fi.f -= 1.5f;
#else
fi.f = (double)fi.i / 4294967295.0;
fi.f -= 0.5f;
#endif
return fi.f;
}
static void white_noise(float *table, size_t count)
{
size_t i;
uint32_t seed = init_seed;
for(i=0; i<count; ++i)
table[i] = rand_xorshift32(&seed);
}
static void tpdf_noise(float *table, size_t count)
{
size_t i;
uint32_t seed = init_seed;
for(i=0; i<count; ++i)
table[i] = rand_xorshift32(&seed) + rand_xorshift32(&seed);
}
static void highpass_tpdf_noise(float *table, size_t count)
{
size_t i;
uint32_t seed = init_seed;
/* Ensure some minimum lap for keeping the high-pass filter circular. */
size_t lap = count > 2*LAP ? LAP : count/2;
float input_noise;
float xv[9], yv[9];
for(i=0;i<9;i++)
{
xv[i] = yv[i] = 0.0f;
}
for(i=0;i<count+lap;i++)
{
if(i==count) seed=init_seed;
/* generate and add 2 random numbers, to make a TPDF noise distribution */
input_noise = rand_xorshift32(&seed) + rand_xorshift32(&seed);
/* apply 8th order Chebyshev high-pass IIR filter */
/* Coefficients are from http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html
Given parameters are: Chebyshev, Highpass, ripple=-1, order=8, samplerate=44100, corner1=19000 */
xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4]; xv[4] = xv[5]; xv[5] = xv[6]; xv[6] = xv[7]; xv[7] = xv[8];
xv[8] = input_noise / 1.382814179e+07;
yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4]; yv[4] = yv[5]; yv[5] = yv[6]; yv[6] = yv[7]; yv[7] = yv[8];
yv[8] = (xv[0] + xv[8]) - 8 * (xv[1] + xv[7]) + 28 * (xv[2] + xv[6])
- 56 * (xv[3] + xv[5]) + 70 * xv[4]
+ ( -0.6706204984 * yv[0]) + ( -5.3720827038 * yv[1])
+ (-19.0865382480 * yv[2]) + (-39.2831607860 * yv[3])
+ (-51.2308985070 * yv[4]) + (-43.3590135780 * yv[5])
+ (-23.2632305320 * yv[6]) + ( -7.2370122050 * yv[7]);
if(i>=lap) table[i-lap] = yv[8] * 3.0f;
}
}
void mpg123_noise(float* table, size_t count, enum mpg123_noise_type noisetype)
{
switch(noisetype)
{
case mpg123_white_noise: white_noise(table, count); break;
case mpg123_tpdf_noise: tpdf_noise(table, count); break;
case mpg123_highpass_tpdf_noise:
highpass_tpdf_noise(table, count);
break;
}
}
/* Generate white noise and shape it with a high pass filter. */
void dither_table_init(float *dithertable)
{
highpass_tpdf_noise(dithertable, DITHERSIZE);
}

View File

@ -0,0 +1,17 @@
/*
equalizer.c: equalizer settings
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
*/
#include "mpg123lib_intern.h"
void do_equalizer(real *bandPtr,int channel, real equalizer[2][32])
{
int i;
for(i=0;i<32;i++)
bandPtr[i] = REAL_MUL(bandPtr[i], equalizer[channel][i]);
}

View File

@ -0,0 +1,159 @@
/*
libmpg123: MPEG Audio Decoder library
separate header just for audio format definitions not tied to
library code
copyright 1995-2020 by the mpg123 project
free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
*/
#ifndef MPG123_ENC_H
#define MPG123_ENC_H
/** \file fmt123.h Audio format definitions. */
/** \defgroup mpg123_enc mpg123 PCM sample encodings
* These are definitions for audio formats used by libmpg123 and
* libout123.
*
* @{
*/
/** An enum over all sample types possibly known to mpg123.
* The values are designed as bit flags to allow bitmasking for encoding
* families.
* This is also why the enum is not used as type for actual encoding variables,
* plain integers (at least 16 bit, 15 bit being used) cover the possible
* combinations of these flags.
*
* Note that (your build of) libmpg123 does not necessarily support all these.
* Usually, you can expect the 8bit encodings and signed 16 bit.
* Also 32bit float will be usual beginning with mpg123-1.7.0 .
* What you should bear in mind is that (SSE, etc) optimized routines may be
* absent for some formats. We do have SSE for 16, 32 bit and float, though.
* 24 bit integer is done via postprocessing of 32 bit output -- just cutting
* the last byte, no rounding, even. If you want better, do it yourself.
*
* All formats are in native byte order. If you need different endinaness, you
* can simply postprocess the output buffers (libmpg123 wouldn't do anything
* else). The macro MPG123_SAMPLESIZE() can be helpful there.
*/
enum mpg123_enc_enum
{
/* 0000 0000 0000 1111 Some 8 bit integer encoding. */
MPG123_ENC_8 = 0x00f
/* 0000 0000 0100 0000 Some 16 bit integer encoding. */
, MPG123_ENC_16 = 0x040
/* 0100 0000 0000 0000 Some 24 bit integer encoding. */
, MPG123_ENC_24 = 0x4000
/* 0000 0001 0000 0000 Some 32 bit integer encoding. */
, MPG123_ENC_32 = 0x100
/* 0000 0000 1000 0000 Some signed integer encoding. */
, MPG123_ENC_SIGNED = 0x080
/* 0000 1110 0000 0000 Some float encoding. */
, MPG123_ENC_FLOAT = 0xe00
/* 0000 0000 1101 0000 signed 16 bit */
, MPG123_ENC_SIGNED_16 = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10)
/* 0000 0000 0110 0000 unsigned 16 bit */
, MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20)
/* 0000 0000 0000 0001 unsigned 8 bit */
, MPG123_ENC_UNSIGNED_8 = 0x01
/* 0000 0000 1000 0010 signed 8 bit */
, MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED|0x02)
/* 0000 0000 0000 0100 ulaw 8 bit */
, MPG123_ENC_ULAW_8 = 0x04
/* 0000 0000 0000 1000 alaw 8 bit */
, MPG123_ENC_ALAW_8 = 0x08
/* 0001 0001 1000 0000 signed 32 bit */
, MPG123_ENC_SIGNED_32 = MPG123_ENC_32|MPG123_ENC_SIGNED|0x1000
/* 0010 0001 0000 0000 unsigned 32 bit */
, MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x2000
/* 0101 0000 1000 0000 signed 24 bit */
, MPG123_ENC_SIGNED_24 = MPG123_ENC_24|MPG123_ENC_SIGNED|0x1000
/* 0110 0000 0000 0000 unsigned 24 bit */
, MPG123_ENC_UNSIGNED_24 = MPG123_ENC_24|0x2000
/* 0000 0010 0000 0000 32bit float */
, MPG123_ENC_FLOAT_32 = 0x200
/* 0000 0100 0000 0000 64bit float */
, MPG123_ENC_FLOAT_64 = 0x400
/* Any possibly known encoding from the list above. */
, MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 | MPG123_ENC_UNSIGNED_16
| MPG123_ENC_UNSIGNED_8 | MPG123_ENC_SIGNED_8
| MPG123_ENC_ULAW_8 | MPG123_ENC_ALAW_8
| MPG123_ENC_SIGNED_32 | MPG123_ENC_UNSIGNED_32
| MPG123_ENC_SIGNED_24 | MPG123_ENC_UNSIGNED_24
| MPG123_ENC_FLOAT_32 | MPG123_ENC_FLOAT_64 )
};
/** Get size of one PCM sample with given encoding.
* This is included both in libmpg123 and libout123. Both offer
* an API function to provide the macro results from library
* compile-time, not that of you application. This most likely
* does not matter as I do not expect any fresh PCM sample
* encoding to appear. But who knows? Perhaps the encoding type
* will be abused for funny things in future, not even plain PCM.
* And, by the way: Thomas really likes the ?: operator.
* \param enc the encoding (mpg123_enc_enum value)
* \return size of one sample in bytes
*/
#define MPG123_SAMPLESIZE(enc) ( \
(enc) < 1 \
? 0 \
: ( (enc) & MPG123_ENC_8 \
? 1 \
: ( (enc) & MPG123_ENC_16 \
? 2 \
: ( (enc) & MPG123_ENC_24 \
? 3 \
: ( ( (enc) & MPG123_ENC_32 \
|| (enc) == MPG123_ENC_FLOAT_32 ) \
? 4 \
: ( (enc) == MPG123_ENC_FLOAT_64 \
? 8 \
: 0 \
) ) ) ) ) )
/** Representation of zero in differing encodings.
* This exists to define proper silence in various encodings without
* having to link to libsyn123 to do actual conversions at runtime.
* You have to handle big/little endian order yourself, though.
* This takes the shortcut that any signed encoding has a zero with
* all-zero bits. Unsigned linear encodings just have the highest bit set
* (2^(n-1) for n bits), while the nonlinear 8-bit ones are special.
* \param enc the encoding (mpg123_enc_enum value)
* \param siz bytes per sample (return value of MPG123_SAMPLESIZE(enc))
* \param off byte (octet) offset counted from LSB
* \return unsigned byte value for the designated octet
*/
#define MPG123_ZEROSAMPLE(enc, siz, off) ( \
(enc) == MPG123_ENC_ULAW_8 \
? (off == 0 ? 0xff : 0x00) \
: ( (enc) == MPG123_ENC_ALAW_8 \
? (off == 0 ? 0xd5 : 0x00) \
: ( (((enc) & (MPG123_ENC_SIGNED|MPG123_ENC_FLOAT)) || (siz) != ((off)+1)) \
? 0x00 \
: 0x80 \
) ) )
/** Structure defining an audio format.
* Providing the members as individual function arguments to define a certain
* output format is easy enough. This struct makes is more comfortable to deal
* with a list of formats.
* Negative values for the members might be used to communicate use of default
* values.
*/
struct mpg123_fmt
{
long rate; /**< sampling rate in Hz */
int channels; /**< channel count */
/** encoding code, can be single value or bitwise or of members of
* mpg123_enc_enum */
int encoding;
};
/** @} */
#endif

View File

@ -0,0 +1,776 @@
/*
format: routines to deal with audio (output) format
copyright 2008-20 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, starting with parts of the old audio.c, with only faintly manage to show now
A Major change from mpg123 <= 1.18 is that all encodings are only really
disabled when done so via specific build configuration. Otherwise, the
missing support of decoders to produce a certain format is augmented by
postprocessing that converts the samples. This means happily creating
data with higher resolution from less accurate decoder output.
The main point is to still offer float encoding when the decoding core uses
a fixed point representation that has only 16 bit output. Actually, that's
the only point: A fixed-point build needs to create float from 16 bit, also
32 or 24 bit from the same source. That's all there is to it: Everything else
is covered by fallback synth functions. It may be a further step to check if
there are cases where conversion in postprocessing works well enough to omit
a certain specialized decoder ... but usually, they are justified by some
special way to get from float to integer to begin with.
I won't cover the case of faking double output with float/s16 decoders here.
Double precision output is a thing for experimental builds anyway. Mostly
theoretical and without a point.
*/
#include "mpg123lib_intern.h"
#include "sample.h"
#include "debug.h"
/* static int chans[NUM_CHANNELS] = { 1 , 2 }; */
static const long my_rates[MPG123_RATES] = /* only the standard rates */
{
8000, 11025, 12000,
16000, 22050, 24000,
32000, 44100, 48000,
};
static const int my_encodings[MPG123_ENCODINGS] =
{
MPG123_ENC_SIGNED_16,
MPG123_ENC_UNSIGNED_16,
MPG123_ENC_SIGNED_32,
MPG123_ENC_UNSIGNED_32,
MPG123_ENC_SIGNED_24,
MPG123_ENC_UNSIGNED_24,
/* Floating point range, see below. */
MPG123_ENC_FLOAT_32,
MPG123_ENC_FLOAT_64,
/* 8 bit range, see below. */
MPG123_ENC_SIGNED_8,
MPG123_ENC_UNSIGNED_8,
MPG123_ENC_ULAW_8,
MPG123_ENC_ALAW_8
};
/* Make that match the above table.
And yes, I still don't like this kludgy stuff. */
/* range[0] <= i < range[1] for forced floating point */
static const int enc_float_range[2] = { 6, 8 };
/* same for 8 bit encodings */
static const int enc_8bit_range[2] = { 8, 12 };
// for 24 bit quality (24 and 32 bit integers)
static const int enc_24bit_range[2] = { 2, 6 };
// for completeness, the 16 bits
static const int enc_16bit_range[2] = { 0, 2};
/*
Only one type of float is supported.
Actually, double is a very special experimental case not occuring in normal
builds. Might actually get rid of it.
Remember here: Also with REAL_IS_FIXED, I want to be able to produce float
output (f32) via post-processing.
*/
# ifdef REAL_IS_DOUBLE
# define MPG123_FLOAT_ENC MPG123_ENC_FLOAT_64
# else
# define MPG123_FLOAT_ENC MPG123_ENC_FLOAT_32
# endif
/* The list of actually possible encodings. */
static const int good_encodings[] =
{
#ifndef NO_16BIT
MPG123_ENC_SIGNED_16,
MPG123_ENC_UNSIGNED_16,
#endif
#ifndef NO_32BIT
MPG123_ENC_SIGNED_32,
MPG123_ENC_UNSIGNED_32,
MPG123_ENC_SIGNED_24,
MPG123_ENC_UNSIGNED_24,
#endif
#ifndef NO_REAL
MPG123_FLOAT_ENC,
#endif
#ifndef NO_8BIT
MPG123_ENC_SIGNED_8,
MPG123_ENC_UNSIGNED_8,
MPG123_ENC_ULAW_8,
MPG123_ENC_ALAW_8
#endif
};
/* Check if encoding is a valid one in this build.
...lazy programming: linear search. */
static int good_enc(const int enc)
{
size_t i;
for(i=0; i<sizeof(good_encodings)/sizeof(int); ++i)
if(enc == good_encodings[i]) return TRUE;
return FALSE;
}
void attribute_align_arg mpg123_rates(const long **list, size_t *number)
{
if(list != NULL) *list = my_rates;
if(number != NULL) *number = sizeof(my_rates)/sizeof(long);
}
/* Now that's a bit tricky... One build of the library knows only a subset of the encodings. */
void attribute_align_arg mpg123_encodings(const int **list, size_t *number)
{
if(list != NULL) *list = good_encodings;
if(number != NULL) *number = sizeof(good_encodings)/sizeof(int);
}
int attribute_align_arg mpg123_encsize(int encoding)
{
return MPG123_SAMPLESIZE(encoding);
}
/* char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS]; */
static int rate2num(mpg123_pars *mp, long r)
{
int i;
for(i=0;i<MPG123_RATES;i++) if(my_rates[i] == r) return i;
#ifndef NO_NTOM
if(mp && mp->force_rate != 0 && mp->force_rate == r) return MPG123_RATES;
#endif
return -1;
}
static int enc2num(int encoding)
{
int i;
for(i=0;i<MPG123_ENCODINGS;++i)
if(my_encodings[i] == encoding) return i;
return -1;
}
static int cap_fit(mpg123_pars *p, struct audioformat *nf, int f0, int f2)
{
int i;
int c = nf->channels-1;
int rn = rate2num(p, nf->rate);
if(rn >= 0) for(i=f0;i<f2;i++)
{
if(p->audio_caps[c][rn][i])
{
nf->encoding = my_encodings[i];
return 1;
}
}
return 0;
}
static int imin(int a, int b)
{
return a < b ? a : b;
}
static int imax(int a, int b)
{
return a > b ? a : b;
}
// Find a possible encoding with given rate and channel count,
// try differing channel count, too.
// This updates the given format and returns TRUE if an encoding
// was found.
static int enc_chan_fit( mpg123_pars *p, long rate, struct audioformat *nnf
, int f0, int f2, int try_float )
{
#define ENCRANGE(range) imax(f0, range[0]), imin(f2, range[1])
struct audioformat nf = *nnf;
nf.rate = rate;
if(cap_fit(p, &nf, ENCRANGE(enc_16bit_range)))
goto eend;
if(cap_fit(p, &nf, ENCRANGE(enc_24bit_range)))
goto eend;
if(try_float &&
cap_fit(p, &nf, ENCRANGE(enc_float_range)))
goto eend;
if(cap_fit(p, &nf, ENCRANGE(enc_8bit_range)))
goto eend;
/* try again with different stereoness */
if(nf.channels == 2 && !(p->flags & MPG123_FORCE_STEREO)) nf.channels = 1;
else if(nf.channels == 1 && !(p->flags & MPG123_FORCE_MONO)) nf.channels = 2;
if(cap_fit(p, &nf, ENCRANGE(enc_16bit_range)))
goto eend;
if(cap_fit(p, &nf, ENCRANGE(enc_24bit_range)))
goto eend;
if(try_float &&
cap_fit(p, &nf, ENCRANGE(enc_float_range)))
goto eend;
if(cap_fit(p, &nf, ENCRANGE(enc_8bit_range)))
goto eend;
return FALSE;
eend:
*nnf = nf;
return TRUE;
#undef ENCRANGE
}
/* match constraints against supported audio formats, store possible setup in frame
return: -1: error; 0: no format change; 1: format change */
int frame_output_format(mpg123_handle *fr)
{
struct audioformat nf;
int f0=0;
int f2=MPG123_ENCODINGS+1; // Include all encodings by default.
mpg123_pars *p = &fr->p;
int try_float = (p->flags & MPG123_FLOAT_FALLBACK) ? 0 : 1;
/* initialize new format, encoding comes later */
nf.channels = fr->stereo;
mdebug("native frame format: %d ch @ %ld Hz", fr->stereo, frame_freq(fr));
// I intended the forcing stuff to be weaved into the format support table,
// but this probably will never happen, as this would change library behaviour.
// One could introduce an additional effective format table that takes for
// forcings into account, but that would have to be updated on any flag
// change. Tedious.
if(p->flags & MPG123_FORCE_8BIT)
{
f0 = enc_8bit_range[0];
f2 = enc_8bit_range[1];
}
if(p->flags & MPG123_FORCE_FLOAT)
{
try_float = 1;
f0 = enc_float_range[0];
f2 = enc_float_range[1];
}
/* force stereo is stronger */
if(p->flags & MPG123_FORCE_MONO) nf.channels = 1;
if(p->flags & MPG123_FORCE_STEREO) nf.channels = 2;
// Strategy update: Avoid too early triggering of the NtoM decoder.
// Main target is the native rate, with any encoding.
// Then, native rate with any channel count and any encoding.
// Then, it's down_sample from native rate.
// As last resort: NtoM rate.
// So the priority is 1. rate 2. channels 3. encoding.
// As encodings go, 16 bit is tranditionally preferred as efficient choice.
// Next in line are wider float and integer encodings, then 8 bit as
// last resort.
#ifndef NO_NTOM
if(p->force_rate)
{
if(enc_chan_fit(p, p->force_rate, &nf, f0, f2, try_float))
goto end;
// Keep the order consistent if float is considered fallback only.
if(!try_float &&
enc_chan_fit(p, p->force_rate, &nf, f0, f2, TRUE))
goto end;
merror( "Unable to set up output format! Constraints: %s%s%liHz."
, ( p->flags & MPG123_FORCE_STEREO ? "stereo, " :
(p->flags & MPG123_FORCE_MONO ? "mono, " : "") )
, ( p->flags & MPG123_FORCE_FLOAT ? "float, " :
(p->flags & MPG123_FORCE_8BIT ? "8bit, " : "") )
, p->force_rate );
/* if(NOQUIET && p->verbose <= 1) print_capabilities(fr); */
fr->err = MPG123_BAD_OUTFORMAT;
return -1;
}
#endif
// Native decoder rate first.
if(enc_chan_fit(p, frame_freq(fr)>>p->down_sample, &nf, f0, f2, try_float))
goto end;
// Then downsamplings.
if(p->flags & MPG123_AUTO_RESAMPLE && p->down_sample < 2)
{
if(enc_chan_fit( p, frame_freq(fr)>>(p->down_sample+1), &nf
, f0, f2, try_float ))
goto end;
if(p->down_sample < 1 && enc_chan_fit( p, frame_freq(fr)>>2, &nf
, f0, f2, try_float ))
goto end;
}
// And again the whole deal with float fallback.
if(!try_float)
{
if(enc_chan_fit(p, frame_freq(fr)>>p->down_sample, &nf, f0, f2, TRUE))
goto end;
// Then downsamplings.
if(p->flags & MPG123_AUTO_RESAMPLE && p->down_sample < 2)
{
if(enc_chan_fit( p, frame_freq(fr)>>(p->down_sample+1), &nf
, f0, f2, TRUE ))
goto end;
if(p->down_sample < 1 && enc_chan_fit( p, frame_freq(fr)>>2, &nf
, f0, f2, TRUE ))
goto end;
}
}
#ifndef NO_NTOM
// Try to find any rate that works and resample using NtoM hackery.
if( p->flags & MPG123_AUTO_RESAMPLE && fr->p.down_sample == 0)
{
int i;
int rn = rate2num(p, frame_freq(fr));
int rrn;
if(rn < 0) return 0;
/* Try higher rates first. */
for(rrn=rn+1; rrn<MPG123_RATES; ++rrn)
if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, try_float))
goto end;
/* Then lower rates. */
for(i=f0;i<f2;i++) for(rrn=rn-1; rrn>=0; --rrn)
if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, try_float))
goto end;
// And again for float fallback.
if(!try_float)
{
/* Try higher rates first. */
for(rrn=rn+1; rrn<MPG123_RATES; ++rrn)
if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, TRUE))
goto end;
/* Then lower rates. */
for(i=f0;i<f2;i++) for(rrn=rn-1; rrn>=0; --rrn)
if(enc_chan_fit(p, my_rates[rrn], &nf, f0, f2, TRUE))
goto end;
}
}
#endif
/* Here is the _bad_ end. */
merror( "Unable to set up output format! Constraints: %s%s%li, %li or %liHz."
, ( p->flags & MPG123_FORCE_STEREO ? "stereo, " :
(p->flags & MPG123_FORCE_MONO ? "mono, " : "") )
, ( p->flags & MPG123_FORCE_FLOAT ? "float, " :
(p->flags & MPG123_FORCE_8BIT ? "8bit, " : "") )
, frame_freq(fr)>>p->down_sample
, frame_freq(fr)>>(p->down_sample ? p->down_sample : 1)
, frame_freq(fr)>>2 );
/* if(NOQUIET && p->verbose <= 1) print_capabilities(fr); */
fr->err = MPG123_BAD_OUTFORMAT;
return -1;
end: /* Here is the _good_ end. */
/* we had a successful match, now see if there's a change */
if(nf.rate == fr->af.rate && nf.channels == fr->af.channels && nf.encoding == fr->af.encoding)
{
debug2("Old format with %i channels, and FORCE_MONO=%li", nf.channels, p->flags & MPG123_FORCE_MONO);
return 0; /* the same format as before */
}
else /* a new format */
{
debug1("New format with %i channels!", nf.channels);
fr->af.rate = nf.rate;
fr->af.channels = nf.channels;
fr->af.encoding = nf.encoding;
/* Cache the size of one sample in bytes, for ease of use. */
fr->af.encsize = mpg123_encsize(fr->af.encoding);
if(fr->af.encsize < 1)
{
error1("Some unknown encoding??? (%i)", fr->af.encoding);
fr->err = MPG123_BAD_OUTFORMAT;
return -1;
}
/* Set up the decoder synth format. Might differ. */
#ifdef NO_SYNTH32
/* Without high-precision synths, 16 bit signed is the basis for
everything higher than 8 bit. */
if(fr->af.encsize > 2)
fr->af.dec_enc = MPG123_ENC_SIGNED_16;
else
{
#endif
switch(fr->af.encoding)
{
#ifndef NO_32BIT
case MPG123_ENC_SIGNED_24:
case MPG123_ENC_UNSIGNED_24:
case MPG123_ENC_UNSIGNED_32:
fr->af.dec_enc = MPG123_ENC_SIGNED_32;
break;
#endif
#ifndef NO_16BIT
case MPG123_ENC_UNSIGNED_16:
fr->af.dec_enc = MPG123_ENC_SIGNED_16;
break;
#endif
default:
fr->af.dec_enc = fr->af.encoding;
}
#ifdef NO_SYNTH32
}
#endif
fr->af.dec_encsize = mpg123_encsize(fr->af.dec_enc);
return 1;
}
}
int attribute_align_arg mpg123_format_none(mpg123_handle *mh)
{
int r;
if(mh == NULL) return MPG123_BAD_HANDLE;
r = mpg123_fmt_none(&mh->p);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
return r;
}
int attribute_align_arg mpg123_fmt_none(mpg123_pars *mp)
{
if(mp == NULL) return MPG123_BAD_PARS;
if(PVERB(mp,3)) fprintf(stderr, "Note: Disabling all formats.\n");
memset(mp->audio_caps,0,sizeof(mp->audio_caps));
return MPG123_OK;
}
int attribute_align_arg mpg123_format_all(mpg123_handle *mh)
{
int r;
if(mh == NULL) return MPG123_BAD_HANDLE;
r = mpg123_fmt_all(&mh->p);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
return r;
}
int attribute_align_arg mpg123_fmt_all(mpg123_pars *mp)
{
size_t rate, ch, enc;
if(mp == NULL) return MPG123_BAD_PARS;
if(PVERB(mp,3)) fprintf(stderr, "Note: Enabling all formats.\n");
for(ch=0; ch < NUM_CHANNELS; ++ch)
for(rate=0; rate < MPG123_RATES+1; ++rate)
for(enc=0; enc < MPG123_ENCODINGS; ++enc)
mp->audio_caps[ch][rate][enc] = good_enc(my_encodings[enc]) ? 1 : 0;
return MPG123_OK;
}
int attribute_align_arg mpg123_format2(mpg123_handle *mh, long rate, int channels, int encodings)
{
int r;
if(mh == NULL) return MPG123_BAD_HANDLE;
r = mpg123_fmt2(&mh->p, rate, channels, encodings);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
return r;
}
// Keep old behaviour.
int attribute_align_arg mpg123_format(mpg123_handle *mh, long rate, int channels, int encodings)
{
int r;
if(mh == NULL) return MPG123_BAD_HANDLE;
r = mpg123_fmt(&mh->p, rate, channels, encodings);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
return r;
}
int attribute_align_arg mpg123_fmt2(mpg123_pars *mp, long rate, int channels, int encodings)
{
int ie, ic, ratei, r1, r2;
int ch[2] = {0, 1};
if(mp == NULL) return MPG123_BAD_PARS;
if(!(channels & (MPG123_MONO|MPG123_STEREO))) return MPG123_BAD_CHANNEL;
if(PVERB(mp,3)) fprintf(stderr, "Note: Want to enable format %li/%i for encodings 0x%x.\n", rate, channels, encodings);
if(!(channels & MPG123_STEREO)) ch[1] = 0; /* {0,0} */
else if(!(channels & MPG123_MONO)) ch[0] = 1; /* {1,1} */
if(rate)
{
r1 = rate2num(mp, rate);
r2 = r1+1;
}
else
{
r1 = 0;
r2 = MPG123_RATES+1; /* including forced rate */
}
if(r1 < 0) return MPG123_BAD_RATE;
/* now match the encodings */
for(ratei = r1; ratei < r2; ++ratei)
for(ic = 0; ic < 2; ++ic)
{
for(ie = 0; ie < MPG123_ENCODINGS; ++ie)
if(good_enc(my_encodings[ie]) && ((my_encodings[ie] & encodings) == my_encodings[ie]))
mp->audio_caps[ch[ic]][ratei][ie] = 1;
if(ch[0] == ch[1]) break; /* no need to do it again */
}
return MPG123_OK;
}
// Keep old behaviour, error on rate=0.
int attribute_align_arg mpg123_fmt(mpg123_pars *mp, long rate, int channels, int encodings)
{
return (rate == 0)
? MPG123_BAD_RATE
: mpg123_fmt2(mp, rate, channels, encodings);
}
int attribute_align_arg mpg123_format_support(mpg123_handle *mh, long rate, int encoding)
{
if(mh == NULL) return 0;
else return mpg123_fmt_support(&mh->p, rate, encoding);
}
int attribute_align_arg mpg123_fmt_support(mpg123_pars *mp, long rate, int encoding)
{
int ch = 0;
int ratei, enci;
ratei = rate2num(mp, rate);
enci = enc2num(encoding);
if(mp == NULL || ratei < 0 || enci < 0) return 0;
if(mp->audio_caps[0][ratei][enci]) ch |= MPG123_MONO;
if(mp->audio_caps[1][ratei][enci]) ch |= MPG123_STEREO;
return ch;
}
/* Call this one to ensure that any valid format will be something different than this. */
void invalidate_format(struct audioformat *af)
{
af->encoding = 0;
af->rate = 0;
af->channels = 0;
}
/* Number of bytes the decoder produces. */
off_t decoder_synth_bytes(mpg123_handle *fr, off_t s)
{
return s * fr->af.dec_encsize * fr->af.channels;
}
/* Samples/bytes for output buffer after post-processing. */
/* take into account: channels, bytes per sample -- NOT resampling!*/
off_t samples_to_bytes(mpg123_handle *fr , off_t s)
{
return s * fr->af.encsize * fr->af.channels;
}
off_t bytes_to_samples(mpg123_handle *fr , off_t b)
{
return b / fr->af.encsize / fr->af.channels;
}
/* Number of bytes needed for decoding _and_ post-processing. */
off_t outblock_bytes(mpg123_handle *fr, off_t s)
{
int encsize = (fr->af.encoding & MPG123_ENC_24)
? 4 /* Intermediate 32 bit. */
: (fr->af.encsize > fr->af.dec_encsize
? fr->af.encsize
: fr->af.dec_encsize);
return s * encsize * fr->af.channels;
}
#ifndef NO_32BIT
/* Remove every fourth byte, facilitating conversion from 32 bit to 24 bit integers.
This has to be aware of endianness, of course. */
static void chop_fourth_byte(struct outbuffer *buf)
{
unsigned char *wpos = buf->data;
unsigned char *rpos = buf->data;
size_t blocks = buf->fill/4;
size_t i;
for(i=0; i<blocks; ++i,wpos+=3,rpos+=4)
DROP4BYTE(wpos, rpos)
buf->fill = wpos-buf->data;
}
static void conv_s32_to_u32(struct outbuffer *buf)
{
size_t i;
int32_t *ssamples = (int32_t*) buf->data;
uint32_t *usamples = (uint32_t*) buf->data;
size_t count = buf->fill/sizeof(int32_t);
for(i=0; i<count; ++i)
usamples[i] = CONV_SU32(ssamples[i]);
}
#endif
/* We always assume that whole numbers are written!
partials will be cut out. */
static const char *bufsizeerr = "Fatal: Buffer too small for postprocessing!";
#ifndef NO_16BIT
static void conv_s16_to_u16(struct outbuffer *buf)
{
size_t i;
int16_t *ssamples = (int16_t*) buf->data;
uint16_t *usamples = (uint16_t*)buf->data;
size_t count = buf->fill/sizeof(int16_t);
for(i=0; i<count; ++i)
usamples[i] = CONV_SU16(ssamples[i]);
}
#ifndef NO_REAL
static void conv_s16_to_f32(struct outbuffer *buf)
{
ssize_t i;
int16_t *in = (int16_t*) buf->data;
float *out = (float*) buf->data;
size_t count = buf->fill/sizeof(int16_t);
/* Does that make any sense? In x86, there is an actual instruction to divide
float by integer ... but then, if we have that FPU, we don't really need
fixed point decoder hacks ...? */
float scale = 1./SHORT_SCALE;
if(buf->size < count*sizeof(float))
{
error1("%s", bufsizeerr);
return;
}
/* Work from the back since output is bigger. */
for(i=count-1; i>=0; --i)
out[i] = (float)in[i] * scale;
buf->fill = count*sizeof(float);
}
#endif
#ifndef NO_32BIT
static void conv_s16_to_s32(struct outbuffer *buf)
{
ssize_t i;
int16_t *in = (int16_t*) buf->data;
int32_t *out = (int32_t*) buf->data;
size_t count = buf->fill/sizeof(int16_t);
if(buf->size < count*sizeof(int32_t))
{
error1("%s", bufsizeerr);
return;
}
/* Work from the back since output is bigger. */
for(i=count-1; i>=0; --i)
{
out[i] = in[i];
/* Could just shift bytes, but would have to mess with sign bit. */
out[i] *= S32_RESCALE;
}
buf->fill = count*sizeof(int32_t);
}
#endif
#endif
#include "swap_bytes_impl.h"
void swap_endian(struct outbuffer *buf, int block)
{
size_t count;
if(block >= 2)
{
count = buf->fill/(unsigned int)block;
swap_bytes(buf->data, (size_t)block, count);
}
}
void postprocess_buffer(mpg123_handle *fr)
{
/*
This caters for the final output formats that are never produced by
decoder synth directly (wide unsigned and 24 bit formats) or that are
missing because of limited decoder precision (16 bit synth but 32 or
24 bit output).
*/
switch(fr->af.dec_enc)
{
#ifndef NO_32BIT
case MPG123_ENC_SIGNED_32:
switch(fr->af.encoding)
{
case MPG123_ENC_UNSIGNED_32:
conv_s32_to_u32(&fr->buffer);
break;
case MPG123_ENC_UNSIGNED_24:
conv_s32_to_u32(&fr->buffer);
chop_fourth_byte(&fr->buffer);
break;
case MPG123_ENC_SIGNED_24:
chop_fourth_byte(&fr->buffer);
break;
}
break;
#endif
#ifndef NO_16BIT
case MPG123_ENC_SIGNED_16:
switch(fr->af.encoding)
{
case MPG123_ENC_UNSIGNED_16:
conv_s16_to_u16(&fr->buffer);
break;
#ifndef NO_REAL
case MPG123_ENC_FLOAT_32:
conv_s16_to_f32(&fr->buffer);
break;
#endif
#ifndef NO_32BIT
case MPG123_ENC_SIGNED_32:
conv_s16_to_s32(&fr->buffer);
break;
case MPG123_ENC_UNSIGNED_32:
conv_s16_to_s32(&fr->buffer);
conv_s32_to_u32(&fr->buffer);
break;
case MPG123_ENC_UNSIGNED_24:
conv_s16_to_s32(&fr->buffer);
conv_s32_to_u32(&fr->buffer);
chop_fourth_byte(&fr->buffer);
break;
case MPG123_ENC_SIGNED_24:
conv_s16_to_s32(&fr->buffer);
chop_fourth_byte(&fr->buffer);
break;
#endif
}
break;
#endif
}
if(fr->p.flags & MPG123_FORCE_ENDIAN)
{
if(
#ifdef WORDS_BIGENDIAN
!(
#endif
fr->p.flags & MPG123_BIG_ENDIAN
#ifdef WORDS_BIGENDIAN
)
#endif
)
swap_endian(&fr->buffer, mpg123_encsize(fr->af.encoding));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,431 @@
/*
frame: Central data structures and opmitization hooks.
copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#ifndef MPG123_FRAME_H
#define MPG123_FRAME_H
#include <stdio.h>
#include "config.h"
#include "mpg123.h"
#include "optimize.h"
#include "getcpuflags.h"
#include "id3.h"
#include "icy.h"
#include "reader.h"
#ifdef FRAME_INDEX
#include "index.h"
#endif
#include "synths.h"
#ifdef OPT_DITHER
#include "dither.h"
int frame_dither_init(mpg123_handle *fr);
#endif
/* max = 1728 */
#define MAXFRAMESIZE 3456
struct al_table
{
short bits;
short d;
};
/* the output buffer, used to be pcm_sample, pcm_point and audiobufsize */
struct outbuffer
{
unsigned char *data; /* main data pointer, aligned */
unsigned char *p; /* read pointer */
size_t fill; /* fill from read pointer */
size_t size;
unsigned char *rdata; /* unaligned base pointer */
};
struct audioformat
{
int encoding; /* Final encoding, after post-processing. */
int encsize; /* Size of one sample in bytes, plain int should be fine here... */
int dec_enc; /* Encoding of decoder synth. */
int dec_encsize; /* Size of one decoder sample. */
int channels;
long rate;
};
void invalidate_format(struct audioformat *af);
struct mpg123_pars_struct
{
int verbose; /* verbose level */
long flags; /* combination of above */
#ifndef NO_NTOM
long force_rate;
#endif
int down_sample;
int rva; /* (which) rva to do: 0: nothing, 1: radio/mix/track 2: album/audiophile */
long halfspeed;
long doublespeed;
long timeout;
#define NUM_CHANNELS 2
char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS];
/* long start_frame; */ /* frame offset to begin with */
/* long frame_number;*/ /* number of frames to decode */
#ifndef NO_ICY
long icy_interval;
#endif
double outscale;
long resync_limit;
long index_size; /* Long, because: negative values have a meaning. */
long preframes;
#ifndef NO_FEEDER
long feedpool;
long feedbuffer;
#endif
long freeformat_framesize;
};
enum frame_state_flags
{
FRAME_ACCURATE = 0x1 /**< 0001 Positions are considered accurate. */
,FRAME_FRANKENSTEIN = 0x2 /**< 0010 This stream is concatenated. */
,FRAME_FRESH_DECODER = 0x4 /**< 0100 Decoder is fleshly initialized. */
,FRAME_DECODER_LIVE = 0x8 /**< 1000 Decoder can be used. */
};
/* There is a lot to condense here... many ints can be merged as flags; though the main space is still consumed by buffers. */
struct mpg123_handle_struct
{
int fresh; /* to be moved into flags */
int new_format;
real hybrid_block[2][2][SBLIMIT*SSLIMIT];
int hybrid_blc[2];
/* the scratch vars for the decoders, sometimes real, sometimes short... sometimes int/long */
short *short_buffs[2][2];
real *real_buffs[2][2];
unsigned char *rawbuffs;
int rawbuffss;
#ifdef OPT_I486
int i486bo[2];
#endif
int bo; /* Just have it always here. */
#ifdef OPT_DITHER
int ditherindex;
float *dithernoise;
#endif
unsigned char* rawdecwin; /* the block with all decwins */
int rawdecwins; /* size of rawdecwin memory */
real *decwin; /* _the_ decode table */
#ifdef OPT_MMXORSSE
/* I am not really sure that I need both of them... used in assembler */
float *decwin_mmx;
float *decwins;
#endif
#ifndef NO_EQUALIZER
int have_eq_settings;
real equalizer[2][32];
#endif
/* for halfspeed mode */
unsigned char ssave[34];
int halfphase;
#ifndef NO_8BIT
/* a raw buffer and a pointer into the middle for signed short conversion, only allocated on demand */
unsigned char *conv16to8_buf;
unsigned char *conv16to8;
#endif
/* There's some possible memory saving for stuff that is not _really_ dynamic. */
/* layer3 */
int longLimit[9][23];
int shortLimit[9][14];
#ifdef REAL_IS_FIXED
const real *gainpow2; // Actually static storage elsewhere.
#else
real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */
#endif
/* layer2 */
real muls[27][64]; /* also used by layer 1 */
#ifndef NO_NTOM
/* decode_ntom */
unsigned long ntom_val[2];
unsigned long ntom_step;
#endif
/* special i486 fun */
#ifdef OPT_I486
int *int_buffs[2][2];
#endif
/* special altivec... */
#ifdef OPT_ALTIVEC
real *areal_buffs[4][4];
#endif
struct synth_s synths;
struct
{
#ifdef OPT_MULTI
#ifndef NO_LAYER3
#if (defined OPT_3DNOW_VINTAGE || defined OPT_3DNOWEXT_VINTAGE || defined OPT_SSE || defined OPT_X86_64 || defined OPT_AVX || defined OPT_NEON || defined OPT_NEON64)
void (*the_dct36)(real *,real *,real *,const real *,real *);
#endif
#endif
#endif
enum optdec type;
enum optcla class;
} cpu_opts;
#ifdef OPT_CPU_FLAGS
struct cpuflags cpu_flags;
#endif
int verbose; /* 0: nothing, 1: just print chosen decoder, 2: be verbose */
const struct al_table *alloc;
/* The runtime-chosen decoding, based on input and output format. */
func_synth synth;
func_synth_stereo synth_stereo;
func_synth_mono synth_mono;
/* Yes, this function is runtime-switched, too. */
void (*make_decode_tables)(mpg123_handle *fr); /* That is the volume control. */
int stereo; /* I _think_ 1 for mono and 2 for stereo */
int jsbound;
#define SINGLE_STEREO -1
#define SINGLE_LEFT 0
#define SINGLE_RIGHT 1
#define SINGLE_MIX 3
int single;
int II_sblimit;
int down_sample_sblimit;
int lsf; /* 0: MPEG 1.0; 1: MPEG 2.0/2.5 -- both used as bool and array index! */
/* Many flags in disguise as integers... wasting bytes. */
int mpeg25;
int down_sample;
int header_change;
int lay;
long spf; /* cached count of samples per frame */
int (*do_layer)(mpg123_handle *);
int error_protection;
int bitrate_index;
int sampling_frequency;
int padding;
int extension;
int mode;
int mode_ext;
int copyright;
int original;
int emphasis;
int framesize; /* computed framesize */
int freesize; /* free format frame size */
enum mpg123_vbr vbr; /* 1 if variable bitrate was detected */
off_t num; /* frame offset ... */
off_t input_offset; /* byte offset of this frame in input stream */
off_t playnum; /* playback offset... includes repetitions, reset at seeks */
off_t audio_start; /* The byte offset in the file where audio data begins. */
int state_flags;
char silent_resync; /* Do not complain for the next n resyncs. */
unsigned char* xing_toc; /* The seek TOC from Xing header. */
int freeformat;
long freeformat_framesize;
/* bitstream info; bsi */
int bitindex;
long bits_avail;
unsigned char *wordpointer;
/* temporary storage for getbits stuff */
unsigned long ultmp;
unsigned char uctmp;
/* rva data, used in common.c, set in id3.c */
double maxoutburst; /* The maximum amplitude in current sample represenation. */
double lastscale;
struct
{
int level[2];
float gain[2];
float peak[2];
} rva;
/* input data */
off_t track_frames;
off_t track_samples;
double mean_framesize;
off_t mean_frames;
int fsizeold;
int ssize;
unsigned int bitreservoir;
unsigned char bsspace[2][MAXFRAMESIZE+512+4]; /* MAXFRAMESIZE */
unsigned char *bsbuf;
unsigned char *bsbufold;
int bsnum;
/* That is the header matching the last read frame body. */
unsigned long oldhead;
/* That is the header that is supposedly the first of the stream. */
unsigned long firsthead;
int abr_rate;
#ifdef FRAME_INDEX
struct frame_index index;
#endif
/* output data */
struct outbuffer buffer;
struct audioformat af;
int own_buffer;
size_t outblock; /* number of bytes that this frame produces (upper bound) */
int to_decode; /* this frame holds data to be decoded */
int to_ignore; /* the same, somehow */
off_t firstframe; /* start decoding from here */
off_t lastframe; /* last frame to decode (for gapless or num_frames limit) */
off_t ignoreframe; /* frames to decode but discard before firstframe */
#ifdef GAPLESS
off_t gapless_frames; /* frame count for the gapless part */
off_t firstoff; /* number of samples to ignore from firstframe */
off_t lastoff; /* number of samples to use from lastframe */
off_t begin_s; /* overall begin offset in samples */
off_t begin_os;
off_t end_s; /* overall end offset in samples */
off_t end_os;
off_t fullend_os; /* gapless_frames translated to output samples */
#endif
unsigned int crc; /* Well, I need a safe 16bit type, actually. But wider doesn't hurt. */
struct reader *rd; /* pointer to the reading functions */
struct reader_data rdat; /* reader data and state info */
struct mpg123_pars_struct p;
int err;
int decoder_change;
int delayed_change;
long clip;
/* the meta crap */
int metaflags;
unsigned char id3buf[128];
#ifndef NO_ID3V2
mpg123_id3v2 id3v2;
#endif
unsigned char *id3v2_raw;
size_t id3v2_size;
#ifndef NO_ICY
struct icy_meta icy;
#endif
/*
More variables needed for decoders, layerX.c.
This time it is not about static variables but about the need for alignment which cannot be guaranteed on the stack by certain compilers (Sun Studio).
We do not require the compiler to align stuff for our hand-written assembly. We only hope that it's able to align stuff for SSE and similar ops it generates itself.
*/
/*
Those layer-specific structs could actually share memory, as they are not in use simultaneously. One might allocate on decoder switch, too.
They all reside in one lump of memory (after each other), allocated to layerscratch.
*/
real *layerscratch;
#ifndef NO_LAYER1
struct
{
real (*fraction)[SBLIMIT]; /* ALIGNED(16) real fraction[2][SBLIMIT]; */
} layer1;
#endif
#ifndef NO_LAYER2
struct
{
real (*fraction)[4][SBLIMIT]; /* ALIGNED(16) real fraction[2][4][SBLIMIT] */
} layer2;
#endif
#ifndef NO_LAYER3
/* These are significant chunks of memory already... */
struct
{
real (*hybrid_in)[SBLIMIT][SSLIMIT]; /* ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT]; */
real (*hybrid_out)[SSLIMIT][SBLIMIT]; /* ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT]; */
} layer3;
#endif
/* A place for storing additional data for the large file wrapper.
This is cruft! */
void *wrapperdata;
/* A callback used to properly destruct the wrapper data. */
void (*wrapperclean)(void*);
int enc_delay;
int enc_padding;
#ifndef NO_MOREINFO
struct mpg123_moreinfo *pinfo;
#endif
};
/* generic init, does not include dynamic buffers */
void frame_init(mpg123_handle *fr);
void frame_init_par(mpg123_handle *fr, mpg123_pars *mp);
/* output buffer and format */
int frame_outbuffer(mpg123_handle *fr);
int frame_output_format(mpg123_handle *fr);
int frame_buffers(mpg123_handle *fr); /* various decoder buffers, needed once */
int frame_reset(mpg123_handle* fr); /* reset for next track */
int frame_buffers_reset(mpg123_handle *fr);
void frame_exit(mpg123_handle *fr); /* end, free all buffers */
/* Index functions... */
/* Well... print it... */
int mpg123_print_index(mpg123_handle *fr, FILE* out);
/* Find a seek position in index. */
off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame);
/* Apply index_size setting. */
int frame_index_setup(mpg123_handle *fr);
void do_volume(mpg123_handle *fr, double factor);
void do_rva(mpg123_handle *fr);
/* samples per frame ...
Layer I
Layer II
Layer III
MPEG-1
384
1152
1152
MPEG-2 LSF
384
1152
576
MPEG 2.5
384
1152
576
*/
// Well, I take that one for granted... at least layer3.
// The value is needed for mpg123_getstate() in any build.
#define GAPLESS_DELAY 529
#ifdef GAPLESS
void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip);
void frame_gapless_realinit(mpg123_handle *fr);
void frame_gapless_update(mpg123_handle *mh, off_t total_samples);
/*void frame_gapless_position(mpg123_handle* fr);
void frame_gapless_bytify(mpg123_handle *fr);
void frame_gapless_ignore(mpg123_handle *fr, off_t frames);*/
/* void frame_gapless_buffercheck(mpg123_handle *fr); */
#endif
/* Number of samples the decoding of the current frame should yield. */
off_t frame_expect_outsamples(mpg123_handle *fr);
/* Skip this frame... do some fake action to get away without actually decoding it. */
void frame_skip(mpg123_handle *fr);
/*
Seeking core functions:
- convert input sample offset to output sample offset
- convert frame offset to output sample offset
- get leading frame offset for output sample offset
The offsets are "unadjusted"/internal; resampling is being taken care of.
*/
off_t frame_ins2outs(mpg123_handle *fr, off_t ins);
off_t frame_outs(mpg123_handle *fr, off_t num);
/* This one just computes the expected sample count for _this_ frame. */
off_t frame_expect_outsampels(mpg123_handle *fr);
off_t frame_offset(mpg123_handle *fr, off_t outs);
void frame_set_frameseek(mpg123_handle *fr, off_t fe);
void frame_set_seek(mpg123_handle *fr, off_t sp);
off_t frame_tell_seek(mpg123_handle *fr);
/* Take a copy of the Xing VBR TOC for fuzzy seeking. */
int frame_fill_toc(mpg123_handle *fr, unsigned char* in);
#endif

View File

@ -0,0 +1,119 @@
/*
sampleadjust: gapless sample offset math
copyright 1995-2012 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
This is no stand-alone header, precisely to be able to fool it into using fake handle types for testing the math.
*/
#include "debug.h"
#ifdef GAPLESS
/* From internal sample number to external. */
static off_t sample_adjust(mpg123_handle *mh, off_t x)
{
off_t s;
if(mh->p.flags & MPG123_GAPLESS)
{
/* It's a bit tricky to do this computation for the padding samples.
They are not there on the outside. */
if(x > mh->end_os)
{
if(x < mh->fullend_os)
s = mh->end_os - mh->begin_os;
else
s = x - (mh->fullend_os - mh->end_os + mh->begin_os);
}
else
s = x - mh->begin_os;
}
else
s = x;
return s;
}
/* from external samples to internal */
static off_t sample_unadjust(mpg123_handle *mh, off_t x)
{
off_t s;
if(mh->p.flags & MPG123_GAPLESS)
{
s = x + mh->begin_os;
/* There is a hole; we don't create sample positions in there.
Jump from the end of the gapless track directly to after the padding. */
if(s >= mh->end_os)
s += mh->fullend_os - mh->end_os;
}
else s = x;
return s;
}
/*
Take the buffer after a frame decode (strictly: it is the data from frame fr->num!) and cut samples out.
fr->buffer.fill may then be smaller than before...
*/
static void frame_buffercheck(mpg123_handle *fr)
{
/* When we have no accurate position, gapless code does not make sense. */
if(!(fr->state_flags & FRAME_ACCURATE)) return;
/* Get a grip on dirty streams that start with a gapless header.
Simply accept all data from frames that are too much,
they are supposedly attached to the stream after the fact. */
if(fr->gapless_frames > 0 && fr->num >= fr->gapless_frames) return;
/* Important: We first cut samples from the end, then cut from beginning (including left-shift of the buffer).
This order works also for the case where firstframe == lastframe. */
/* The last interesting (planned) frame: Only use some leading samples.
Note a difference from the below: The last frame and offset are unchanges by seeks.
The lastoff keeps being valid. */
if(fr->lastframe > -1 && fr->num >= fr->lastframe)
{
/* There can be more than one frame of padding at the end, so we ignore the whole frame if we are beyond lastframe. */
off_t byteoff = (fr->num == fr->lastframe) ? samples_to_bytes(fr, fr->lastoff) : 0;
if((off_t)fr->buffer.fill > byteoff)
{
fr->buffer.fill = byteoff;
}
if(VERBOSE3) fprintf(stderr, "\nNote: Cut frame %"OFF_P" buffer on end of stream to %"OFF_P" samples, fill now %"SIZE_P" bytes.\n", (off_p)fr->num, (off_p)(fr->num == fr->lastframe ? fr->lastoff : 0), (size_p)fr->buffer.fill);
}
/* The first interesting frame: Skip some leading samples. */
if(fr->firstoff && fr->num == fr->firstframe)
{
off_t byteoff = samples_to_bytes(fr, fr->firstoff);
if((off_t)fr->buffer.fill > byteoff)
{
fr->buffer.fill -= byteoff;
/* buffer.p != buffer.data only for own buffer */
debug6("cutting %li samples/%li bytes on begin, own_buffer=%i at %p=%p, buf[1]=%i",
(long)fr->firstoff, (long)byteoff, fr->own_buffer, (void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
if(fr->own_buffer) fr->buffer.p = fr->buffer.data + byteoff;
else memmove(fr->buffer.data, fr->buffer.data + byteoff, fr->buffer.fill);
debug3("done cutting, buffer at %p =? %p, buf[1]=%i",
(void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
}
else fr->buffer.fill = 0;
if(VERBOSE3) fprintf(stderr, "\nNote: Cut frame %"OFF_P" buffer on beginning of stream by %"OFF_P" samples, fill now %"SIZE_P" bytes.\n", (off_p)fr->num, (off_p)fr->firstoff, (size_p)fr->buffer.fill);
/* We can only reach this frame again by seeking. And on seeking, firstoff will be recomputed.
So it is safe to null it here (and it makes the if() decision abort earlier). */
fr->firstoff = 0;
}
}
#define SAMPLE_ADJUST(mh,x) sample_adjust(mh,x)
#define SAMPLE_UNADJUST(mh,x) sample_unadjust(mh,x)
#define FRAME_BUFFERCHECK(mh) frame_buffercheck(mh)
#else /* no gapless code included */
#define SAMPLE_ADJUST(mh,x) (x)
#define SAMPLE_UNADJUST(mh,x) (x)
#define FRAME_BUFFERCHECK(mh)
#endif

View File

@ -0,0 +1,103 @@
/*
getbits
copyright ?-2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
All code is in the header to suggest/force inlining of these small often-used functions.
This indeed has some impact on performance.
*/
#ifndef _MPG123_GETBITS_H_
#define _MPG123_GETBITS_H_
#include "mpg123lib_intern.h"
#include "debug.h"
#define backbits(fr,nob) ((void)( \
fr->bits_avail += nob, \
fr->bitindex -= nob, \
fr->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 0x7 ))
#define getbitoffset(fr) ((-fr->bitindex)&0x7)
/* Precomputing the bytes to be read is error-prone, and some over-read
is even expected for Huffman. Just play safe and return zeros in case
of overflow. This assumes you made bitindex zero already! */
#define getbyte(fr) ( (fr)->bits_avail-=8, (fr)->bits_avail >= 0 \
? *((fr)->wordpointer++) \
: 0 )
static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
{
unsigned long rval;
#ifdef DEBUG_GETBITS
fprintf(stderr,"g%d",number_of_bits);
#endif
fr->bits_avail -= number_of_bits;
/* Safety catch until we got the nasty code fully figured out. */
/* No, that catch stays here, even if we think we got it figured out! */
if(fr->bits_avail < 0)
{
if(NOQUIET)
error2( "Tried to read %i bits with %li available."
, number_of_bits, fr->bits_avail );
return 0;
}
/* This is actually slow: if(!number_of_bits)
return 0; */
#if 0
check_buffer_range(number_of_bits+fr->bitindex);
#endif
{
rval = fr->wordpointer[0];
rval <<= 8;
rval |= fr->wordpointer[1];
rval <<= 8;
rval |= fr->wordpointer[2];
rval <<= fr->bitindex;
rval &= 0xffffff;
fr->bitindex += number_of_bits;
rval >>= (24-number_of_bits);
fr->wordpointer += (fr->bitindex>>3);
fr->bitindex &= 7;
}
#ifdef DEBUG_GETBITS
fprintf(stderr,":%lx\n",rval);
#endif
return rval;
}
#define skipbits(fr, nob) fr->ultmp = ( \
fr->ultmp = fr->wordpointer[0], fr->ultmp <<= 8, fr->ultmp |= fr->wordpointer[1], \
fr->ultmp <<= 8, fr->ultmp |= fr->wordpointer[2], fr->ultmp <<= fr->bitindex, \
fr->ultmp &= 0xffffff, fr->bitindex += nob, fr->bits_avail -= nob, \
fr->ultmp >>= (24-nob), fr->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 7 )
#define getbits_fast(fr, nob) ( \
fr->ultmp = (unsigned char) (fr->wordpointer[0] << fr->bitindex), \
fr->ultmp |= ((unsigned long) fr->wordpointer[1]<<fr->bitindex)>>8, \
fr->ultmp <<= nob, fr->ultmp >>= 8, \
fr->bitindex += nob, fr->bits_avail -= nob, \
fr->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 7, fr->ultmp )
#define get1bit(fr) ( \
fr->uctmp = *fr->wordpointer << fr->bitindex, \
++fr->bitindex, --fr->bits_avail, \
fr->wordpointer += (fr->bitindex>>3), fr->bitindex &= 7, fr->uctmp>>7 )
#endif

View File

@ -0,0 +1,101 @@
/*
getcpucpuflags: get cpuflags for ia32
copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http:#mpg123.org
initially written by KIMURA Takuhiro (for 3DNow!)
extended for general use by Thomas Orgis
*/
#ifndef MPG123_H_GETCPUFLAGS
#define MPG123_H_GETCPUFLAGS
#include "config.h"
/* standard level flags part 1 (ECX)*/
#define FLAG_SSE3 0x00000001
#define FLAG_SSSE3 0x00000200
#define FLAG_AVX 0x1C000000
/* standard level flags part 2 (EDX) */
#define FLAG2_MMX 0x00800000
#define FLAG2_SSE 0x02000000
#define FLAG2_SSE2 0x04000000
#define FLAG2_FPU 0x00000001
/* cpuid extended level 1 (AMD) */
#define XFLAG_MMX 0x00800000
#define XFLAG_3DNOW 0x80000000
#define XFLAG_3DNOWEXT 0x40000000
/* eXtended Control Register 0 */
#define XCR0FLAG_AVX 0x00000006
struct cpuflags
{
#if defined(OPT_ARM) || defined(OPT_NEON) || defined(OPT_NEON64)
unsigned int has_neon;
#else
unsigned int id;
unsigned int std;
unsigned int std2;
unsigned int ext;
unsigned int xcr0_lo;
#endif
};
unsigned int getcpuflags(struct cpuflags* cf);
#ifdef WANT_GETCPUFLAGS
#include <string.h>
// Wrapper needed for ignorant clang memory sanitizer that chokes
// because it does not know the assembly code intialized the vlaues.
static unsigned int wrap_getcpuflags(struct cpuflags* cf)
{
memset(cf, 0, sizeof(*cf));
#if ((defined OPT_X86) || (defined OPT_X86_64) || (defined OPT_NEON) || (defined OPT_NEON64)) && (defined OPT_MULTI)
return getcpuflags(cf);
#else
return 0;
#endif
}
#endif
#if ((defined OPT_X86) || (defined OPT_X86_64) || (defined OPT_NEON) || (defined OPT_NEON64)) && (defined OPT_MULTI)
// We really evaluate the CPU flags.
#define OPT_CPU_FLAGS
/* checks the family */
#define cpu_i586(s) ( ((s.id & 0xf00)>>8) == 0 || ((s.id & 0xf00)>>8) > 4 )
/* checking some flags... */
#define cpu_fpu(s) (FLAG2_FPU & s.std2)
#define cpu_mmx(s) (FLAG2_MMX & s.std2 || XFLAG_MMX & s.ext)
#define cpu_3dnow(s) (XFLAG_3DNOW & s.ext)
#define cpu_3dnowext(s) (XFLAG_3DNOWEXT & s.ext)
#define cpu_sse(s) (FLAG2_SSE & s.std2)
#define cpu_sse2(s) (FLAG2_SSE2 & s.std2)
#define cpu_sse3(s) (FLAG_SSE3 & s.std)
#define cpu_avx(s) ((FLAG_AVX & s.std) == FLAG_AVX && (XCR0FLAG_AVX & s.xcr0_lo) == XCR0FLAG_AVX)
#define cpu_fast_sse(s) ((((s.id & 0xf00)>>8) == 6 && FLAG_SSSE3 & s.std) /* for Intel/VIA; family 6 CPUs with SSSE3 */ || \
(((s.id & 0xf00)>>8) == 0xf && (((s.id & 0x0ff00000)>>20) > 0 && ((s.id & 0x0ff00000)>>20) != 5))) /* for AMD; family > 0xF CPUs except Bobcat */
#define cpu_neon(s) (s.has_neon)
#else
/* Faking stuff for non-multi builds. The same code for synth function choice is used.
Just no runtime dependency of result... */
#define cpu_flags nothing
#define cpu_i586(s) 1
#define cpu_fpu(s) 1
#define cpu_mmx(s) 1
#define cpu_3dnow(s) 1
#define cpu_3dnowext(s) 1
#define cpu_sse(s) 1
#define cpu_sse2(s) 1
#define cpu_sse3(s) 1
#define cpu_avx(s) 1
#define cpu_neon(s) 1
#endif
#endif

View File

@ -0,0 +1,340 @@
/*
huffman.h: huffman tables ... recalcualted to work with optimized decoder scheme (MH)
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
probably we could save a few bytes of memory, because the
smaller tables are often the part of a bigger table
*/
#ifndef _MPG123_HUFFMAN_H_
#define _MPG123_HUFFMAN_H_
struct newhuff
{
unsigned int linbits;
const short *table;
};
static const short tab0[] =
{
0
};
static const short tab1[] =
{
-5, -3, -1, 17, 1, 16, 0
};
static const short tab2[] =
{
-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1,
16, 0
};
static const short tab3[] =
{
-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
1, 0
};
static const short tab5[] =
{
-29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19,
3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16,
0
};
static const short tab6[] =
{
-25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19,
49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16,
0
};
static const short tab7[] =
{
-69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83,
-1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1,
80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7,
-3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18,
-5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0
};
static const short tab8[] =
{
-65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83,
-3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52,
67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4,
64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1,
2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0
};
static const short tab9[] =
{
-63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1,
84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67,
-1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5,
-3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2,
18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0
};
static const short tab10[] =
{
-125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118,
87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3,
-1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1,
100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23,
-17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81,
-1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7,
-3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1,
50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1,
2, 32, 17, -1, 1, 16, 0
};
static const short tab11[] =
{
-121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117,
-3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55,
-1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114,
-1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96,
-1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38,
6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1,
36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50,
-1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2,
32, 17, -3, -1, 1, 16, 0
};
static const short tab12[] =
{
-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87,
117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115,
85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7,
112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5,
-1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37,
82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4,
36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3,
-1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1,
2, 32, 0, 17, -1, 1, 16
};
static const short tab13[] =
{
-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9,
-7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238,
207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1,
236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249,
234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158,
-5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1,
203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245,
231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1,
63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15,
-5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1,
200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1,
240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1,
46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3,
-1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1,
198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5,
-1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167,
151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76,
196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137,
28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106,
-5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43,
-1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178,
-11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1,
58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161,
-3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88,
-1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1,
131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25,
145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100,
40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113,
-1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38,
-1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6,
96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81,
-7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11,
-5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3,
-1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
};
static const short tab15[] =
{
-495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239,
-1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237,
191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3,
-1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219,
-3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173,
-3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246,
-3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9,
-3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243,
216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1,
31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1,
125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3,
-1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5,
-1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124,
199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1,
198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183,
-5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76,
-1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1,
122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15,
-7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106,
-5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5,
-1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74,
-1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1,
42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134,
73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29,
-13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7,
-3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7,
-3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86,
-3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100,
23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69,
-1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9,
-5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1,
5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20,
4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48,
34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16,
0
};
static const short tab16[] =
{
-509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223,
253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3,
-1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5,
-3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19,
-13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1,
238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5,
-1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125,
94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13,
-5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3,
-1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186,
-1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1,
214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169,
-5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213,
-3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154,
108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1,
153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1,
192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45,
-1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107,
-1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12,
-1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1,
178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74,
164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33,
-19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3,
-1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147,
-1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1,
145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3,
-1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1,
8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3,
-1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1,
99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9,
-5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33,
-23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20,
-5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1,
3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
};
static const short tab24[] =
{
-451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1,
207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9,
-5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79,
244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31,
240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1,
236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3,
-1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3,
-1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235,
-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3,
-1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9,
-5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1,
78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185,
170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199,
77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3,
-1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3,
-1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196,
-3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1,
167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1,
137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10,
26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9,
144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165,
27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135,
-1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104,
-1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3,
-1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3,
-1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7,
-3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86,
101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15,
-7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84,
-7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1,
83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5,
80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5,
-1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1,
3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16,
0
};
static const short tab_c0[] =
{
-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
0
};
static const short tab_c1[] =
{
-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
0
};
static const struct newhuff ht[] =
{
{ /* 0 */ 0 , tab0 } ,
{ /* 2 */ 0 , tab1 } ,
{ /* 3 */ 0 , tab2 } ,
{ /* 3 */ 0 , tab3 } ,
{ /* 0 */ 0 , tab0 } ,
{ /* 4 */ 0 , tab5 } ,
{ /* 4 */ 0 , tab6 } ,
{ /* 6 */ 0 , tab7 } ,
{ /* 6 */ 0 , tab8 } ,
{ /* 6 */ 0 , tab9 } ,
{ /* 8 */ 0 , tab10 } ,
{ /* 8 */ 0 , tab11 } ,
{ /* 8 */ 0 , tab12 } ,
{ /* 16 */ 0 , tab13 } ,
{ /* 0 */ 0 , tab0 } ,
{ /* 16 */ 0 , tab15 } ,
{ /* 16 */ 1 , tab16 } ,
{ /* 16 */ 2 , tab16 } ,
{ /* 16 */ 3 , tab16 } ,
{ /* 16 */ 4 , tab16 } ,
{ /* 16 */ 6 , tab16 } ,
{ /* 16 */ 8 , tab16 } ,
{ /* 16 */ 10, tab16 } ,
{ /* 16 */ 13, tab16 } ,
{ /* 16 */ 4 , tab24 } ,
{ /* 16 */ 5 , tab24 } ,
{ /* 16 */ 6 , tab24 } ,
{ /* 16 */ 7 , tab24 } ,
{ /* 16 */ 8 , tab24 } ,
{ /* 16 */ 9 , tab24 } ,
{ /* 16 */ 11, tab24 } ,
{ /* 16 */ 13, tab24 }
};
static const struct newhuff htc[] =
{
{ /* 1 , 1 , */ 0 , tab_c0 } ,
{ /* 1 , 1 , */ 0 , tab_c1 }
};
#endif

View File

@ -0,0 +1,34 @@
/*
icy: Puny code to pretend for a serious ICY data structure.
copyright 2007-2015 by the mpg123 project
-= free software under the terms of the LGPL 2.1 =-
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#include "intsym.h"
#include "icy.h"
void init_icy(struct icy_meta *icy)
{
icy->data = NULL;
}
void clear_icy(struct icy_meta *icy)
{
if(icy->data != NULL) free(icy->data);
init_icy(icy);
}
void reset_icy(struct icy_meta *icy)
{
clear_icy(icy);
init_icy(icy);
}
/*void set_icy(struct icy_meta *icy, char* new_data)
{
if(icy->data) free(icy->data);
icy->data = new_data;
icy->changed = 1;
}*/

View File

@ -0,0 +1,38 @@
/*
icy: support for SHOUTcast ICY meta info, an attempt to keep it organized
copyright 2006-7 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis and modelled after patch by Honza
*/
#ifndef MPG123_ICY_H
#define MPG123_ICY_H
#ifndef NO_ICY
#include "compat.h"
#include "mpg123.h"
struct icy_meta
{
char* data;
off_t interval;
off_t next;
};
void init_icy(struct icy_meta *);
void clear_icy(struct icy_meta *);
void reset_icy(struct icy_meta *);
#else
#undef init_icy
#define init_icy(a)
#undef clear_icy
#define clear_icy(a)
#undef reset_icy
#define reset_icy(a)
#endif /* NO_ICY */
#endif

View File

@ -0,0 +1,440 @@
/* mpg123 note: This is BSD-licensed code that is no problem for mpg123 usage under LGPL.
It's Free, understood? ;-) */
/* Another note: This code is basically written by Thorsten Glaser,
Thomas Orgis did just some rearrangements and comments. */
/*-
* Copyright (c) 2008
* Thorsten Glaser <tg@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un-
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person's immediate fault when using the work as intended.
*-
* Convert from ICY encoding (windows-1252 codepage) to UTF-8
*/
#include "config.h"
#include "intsym.h"
/* Includes string and stdlib headers... */
#include "compat.h"
/* ThOr: too lazy for this type check; also we use char/short all around anyway.
Of cource, it would be the proper way to use _these_ kind of types all around. */
#define uint8_t unsigned char
#define uint16_t unsigned short
static const uint8_t cp1252_utf8[] = {
/* 0x00 @ 0 */ 0x00,
/* 0x01 @ 1 */ 0x01,
/* 0x02 @ 2 */ 0x02,
/* 0x03 @ 3 */ 0x03,
/* 0x04 @ 4 */ 0x04,
/* 0x05 @ 5 */ 0x05,
/* 0x06 @ 6 */ 0x06,
/* 0x07 @ 7 */ 0x07,
/* 0x08 @ 8 */ 0x08,
/* 0x09 @ 9 */ 0x09,
/* 0x0A @ 10 */ 0x0A,
/* 0x0B @ 11 */ 0x0B,
/* 0x0C @ 12 */ 0x0C,
/* 0x0D @ 13 */ 0x0D,
/* 0x0E @ 14 */ 0x0E,
/* 0x0F @ 15 */ 0x0F,
/* 0x10 @ 16 */ 0x10,
/* 0x11 @ 17 */ 0x11,
/* 0x12 @ 18 */ 0x12,
/* 0x13 @ 19 */ 0x13,
/* 0x14 @ 20 */ 0x14,
/* 0x15 @ 21 */ 0x15,
/* 0x16 @ 22 */ 0x16,
/* 0x17 @ 23 */ 0x17,
/* 0x18 @ 24 */ 0x18,
/* 0x19 @ 25 */ 0x19,
/* 0x1A @ 26 */ 0x1A,
/* 0x1B @ 27 */ 0x1B,
/* 0x1C @ 28 */ 0x1C,
/* 0x1D @ 29 */ 0x1D,
/* 0x1E @ 30 */ 0x1E,
/* 0x1F @ 31 */ 0x1F,
/* 0x20 @ 32 */ 0x20,
/* 0x21 @ 33 */ 0x21,
/* 0x22 @ 34 */ 0x22,
/* 0x23 @ 35 */ 0x23,
/* 0x24 @ 36 */ 0x24,
/* 0x25 @ 37 */ 0x25,
/* 0x26 @ 38 */ 0x26,
/* 0x27 @ 39 */ 0x27,
/* 0x28 @ 40 */ 0x28,
/* 0x29 @ 41 */ 0x29,
/* 0x2A @ 42 */ 0x2A,
/* 0x2B @ 43 */ 0x2B,
/* 0x2C @ 44 */ 0x2C,
/* 0x2D @ 45 */ 0x2D,
/* 0x2E @ 46 */ 0x2E,
/* 0x2F @ 47 */ 0x2F,
/* 0x30 @ 48 */ 0x30,
/* 0x31 @ 49 */ 0x31,
/* 0x32 @ 50 */ 0x32,
/* 0x33 @ 51 */ 0x33,
/* 0x34 @ 52 */ 0x34,
/* 0x35 @ 53 */ 0x35,
/* 0x36 @ 54 */ 0x36,
/* 0x37 @ 55 */ 0x37,
/* 0x38 @ 56 */ 0x38,
/* 0x39 @ 57 */ 0x39,
/* 0x3A @ 58 */ 0x3A,
/* 0x3B @ 59 */ 0x3B,
/* 0x3C @ 60 */ 0x3C,
/* 0x3D @ 61 */ 0x3D,
/* 0x3E @ 62 */ 0x3E,
/* 0x3F @ 63 */ 0x3F,
/* 0x40 @ 64 */ 0x40,
/* 0x41 @ 65 */ 0x41,
/* 0x42 @ 66 */ 0x42,
/* 0x43 @ 67 */ 0x43,
/* 0x44 @ 68 */ 0x44,
/* 0x45 @ 69 */ 0x45,
/* 0x46 @ 70 */ 0x46,
/* 0x47 @ 71 */ 0x47,
/* 0x48 @ 72 */ 0x48,
/* 0x49 @ 73 */ 0x49,
/* 0x4A @ 74 */ 0x4A,
/* 0x4B @ 75 */ 0x4B,
/* 0x4C @ 76 */ 0x4C,
/* 0x4D @ 77 */ 0x4D,
/* 0x4E @ 78 */ 0x4E,
/* 0x4F @ 79 */ 0x4F,
/* 0x50 @ 80 */ 0x50,
/* 0x51 @ 81 */ 0x51,
/* 0x52 @ 82 */ 0x52,
/* 0x53 @ 83 */ 0x53,
/* 0x54 @ 84 */ 0x54,
/* 0x55 @ 85 */ 0x55,
/* 0x56 @ 86 */ 0x56,
/* 0x57 @ 87 */ 0x57,
/* 0x58 @ 88 */ 0x58,
/* 0x59 @ 89 */ 0x59,
/* 0x5A @ 90 */ 0x5A,
/* 0x5B @ 91 */ 0x5B,
/* 0x5C @ 92 */ 0x5C,
/* 0x5D @ 93 */ 0x5D,
/* 0x5E @ 94 */ 0x5E,
/* 0x5F @ 95 */ 0x5F,
/* 0x60 @ 96 */ 0x60,
/* 0x61 @ 97 */ 0x61,
/* 0x62 @ 98 */ 0x62,
/* 0x63 @ 99 */ 0x63,
/* 0x64 @ 100 */ 0x64,
/* 0x65 @ 101 */ 0x65,
/* 0x66 @ 102 */ 0x66,
/* 0x67 @ 103 */ 0x67,
/* 0x68 @ 104 */ 0x68,
/* 0x69 @ 105 */ 0x69,
/* 0x6A @ 106 */ 0x6A,
/* 0x6B @ 107 */ 0x6B,
/* 0x6C @ 108 */ 0x6C,
/* 0x6D @ 109 */ 0x6D,
/* 0x6E @ 110 */ 0x6E,
/* 0x6F @ 111 */ 0x6F,
/* 0x70 @ 112 */ 0x70,
/* 0x71 @ 113 */ 0x71,
/* 0x72 @ 114 */ 0x72,
/* 0x73 @ 115 */ 0x73,
/* 0x74 @ 116 */ 0x74,
/* 0x75 @ 117 */ 0x75,
/* 0x76 @ 118 */ 0x76,
/* 0x77 @ 119 */ 0x77,
/* 0x78 @ 120 */ 0x78,
/* 0x79 @ 121 */ 0x79,
/* 0x7A @ 122 */ 0x7A,
/* 0x7B @ 123 */ 0x7B,
/* 0x7C @ 124 */ 0x7C,
/* 0x7D @ 125 */ 0x7D,
/* 0x7E @ 126 */ 0x7E,
/* 0x7F @ 127 */ 0x7F,
/* 0x80 @ 128 */ 0xE2, 0x82, 0xAC,
/* 0x81 @ 131 */ 0xEF, 0xBF, 0xBD,
/* 0x82 @ 134 */ 0xE2, 0x80, 0x9A,
/* 0x83 @ 137 */ 0xC6, 0x92,
/* 0x84 @ 139 */ 0xE2, 0x80, 0x9E,
/* 0x85 @ 142 */ 0xE2, 0x80, 0xA6,
/* 0x86 @ 145 */ 0xE2, 0x80, 0xA0,
/* 0x87 @ 148 */ 0xE2, 0x80, 0xA1,
/* 0x88 @ 151 */ 0xCB, 0x86,
/* 0x89 @ 153 */ 0xE2, 0x80, 0xB0,
/* 0x8A @ 156 */ 0xC5, 0xA0,
/* 0x8B @ 158 */ 0xE2, 0x80, 0xB9,
/* 0x8C @ 161 */ 0xC5, 0x92,
/* 0x8D @ 163 */ 0xEF, 0xBF, 0xBD,
/* 0x8E @ 166 */ 0xC5, 0xBD,
/* 0x8F @ 168 */ 0xEF, 0xBF, 0xBD,
/* 0x90 @ 171 */ 0xEF, 0xBF, 0xBD,
/* 0x91 @ 174 */ 0xE2, 0x80, 0x98,
/* 0x92 @ 177 */ 0xE2, 0x80, 0x99,
/* 0x93 @ 180 */ 0xE2, 0x80, 0x9C,
/* 0x94 @ 183 */ 0xE2, 0x80, 0x9D,
/* 0x95 @ 186 */ 0xE2, 0x80, 0xA2,
/* 0x96 @ 189 */ 0xE2, 0x80, 0x93,
/* 0x97 @ 192 */ 0xE2, 0x80, 0x94,
/* 0x98 @ 195 */ 0xCB, 0x9C,
/* 0x99 @ 197 */ 0xE2, 0x84, 0xA2,
/* 0x9A @ 200 */ 0xC5, 0xA1,
/* 0x9B @ 202 */ 0xE2, 0x80, 0xBA,
/* 0x9C @ 205 */ 0xC5, 0x93,
/* 0x9D @ 207 */ 0xEF, 0xBF, 0xBD,
/* 0x9E @ 210 */ 0xC5, 0xBE,
/* 0x9F @ 212 */ 0xC5, 0xB8,
/* 0xA0 @ 214 */ 0xC2, 0xA0,
/* 0xA1 @ 216 */ 0xC2, 0xA1,
/* 0xA2 @ 218 */ 0xC2, 0xA2,
/* 0xA3 @ 220 */ 0xC2, 0xA3,
/* 0xA4 @ 222 */ 0xC2, 0xA4,
/* 0xA5 @ 224 */ 0xC2, 0xA5,
/* 0xA6 @ 226 */ 0xC2, 0xA6,
/* 0xA7 @ 228 */ 0xC2, 0xA7,
/* 0xA8 @ 230 */ 0xC2, 0xA8,
/* 0xA9 @ 232 */ 0xC2, 0xA9,
/* 0xAA @ 234 */ 0xC2, 0xAA,
/* 0xAB @ 236 */ 0xC2, 0xAB,
/* 0xAC @ 238 */ 0xC2, 0xAC,
/* 0xAD @ 240 */ 0xC2, 0xAD,
/* 0xAE @ 242 */ 0xC2, 0xAE,
/* 0xAF @ 244 */ 0xC2, 0xAF,
/* 0xB0 @ 246 */ 0xC2, 0xB0,
/* 0xB1 @ 248 */ 0xC2, 0xB1,
/* 0xB2 @ 250 */ 0xC2, 0xB2,
/* 0xB3 @ 252 */ 0xC2, 0xB3,
/* 0xB4 @ 254 */ 0xC2, 0xB4,
/* 0xB5 @ 256 */ 0xC2, 0xB5,
/* 0xB6 @ 258 */ 0xC2, 0xB6,
/* 0xB7 @ 260 */ 0xC2, 0xB7,
/* 0xB8 @ 262 */ 0xC2, 0xB8,
/* 0xB9 @ 264 */ 0xC2, 0xB9,
/* 0xBA @ 266 */ 0xC2, 0xBA,
/* 0xBB @ 268 */ 0xC2, 0xBB,
/* 0xBC @ 270 */ 0xC2, 0xBC,
/* 0xBD @ 272 */ 0xC2, 0xBD,
/* 0xBE @ 274 */ 0xC2, 0xBE,
/* 0xBF @ 276 */ 0xC2, 0xBF,
/* 0xC0 @ 278 */ 0xC3, 0x80,
/* 0xC1 @ 280 */ 0xC3, 0x81,
/* 0xC2 @ 282 */ 0xC3, 0x82,
/* 0xC3 @ 284 */ 0xC3, 0x83,
/* 0xC4 @ 286 */ 0xC3, 0x84,
/* 0xC5 @ 288 */ 0xC3, 0x85,
/* 0xC6 @ 290 */ 0xC3, 0x86,
/* 0xC7 @ 292 */ 0xC3, 0x87,
/* 0xC8 @ 294 */ 0xC3, 0x88,
/* 0xC9 @ 296 */ 0xC3, 0x89,
/* 0xCA @ 298 */ 0xC3, 0x8A,
/* 0xCB @ 300 */ 0xC3, 0x8B,
/* 0xCC @ 302 */ 0xC3, 0x8C,
/* 0xCD @ 304 */ 0xC3, 0x8D,
/* 0xCE @ 306 */ 0xC3, 0x8E,
/* 0xCF @ 308 */ 0xC3, 0x8F,
/* 0xD0 @ 310 */ 0xC3, 0x90,
/* 0xD1 @ 312 */ 0xC3, 0x91,
/* 0xD2 @ 314 */ 0xC3, 0x92,
/* 0xD3 @ 316 */ 0xC3, 0x93,
/* 0xD4 @ 318 */ 0xC3, 0x94,
/* 0xD5 @ 320 */ 0xC3, 0x95,
/* 0xD6 @ 322 */ 0xC3, 0x96,
/* 0xD7 @ 324 */ 0xC3, 0x97,
/* 0xD8 @ 326 */ 0xC3, 0x98,
/* 0xD9 @ 328 */ 0xC3, 0x99,
/* 0xDA @ 330 */ 0xC3, 0x9A,
/* 0xDB @ 332 */ 0xC3, 0x9B,
/* 0xDC @ 334 */ 0xC3, 0x9C,
/* 0xDD @ 336 */ 0xC3, 0x9D,
/* 0xDE @ 338 */ 0xC3, 0x9E,
/* 0xDF @ 340 */ 0xC3, 0x9F,
/* 0xE0 @ 342 */ 0xC3, 0xA0,
/* 0xE1 @ 344 */ 0xC3, 0xA1,
/* 0xE2 @ 346 */ 0xC3, 0xA2,
/* 0xE3 @ 348 */ 0xC3, 0xA3,
/* 0xE4 @ 350 */ 0xC3, 0xA4,
/* 0xE5 @ 352 */ 0xC3, 0xA5,
/* 0xE6 @ 354 */ 0xC3, 0xA6,
/* 0xE7 @ 356 */ 0xC3, 0xA7,
/* 0xE8 @ 358 */ 0xC3, 0xA8,
/* 0xE9 @ 360 */ 0xC3, 0xA9,
/* 0xEA @ 362 */ 0xC3, 0xAA,
/* 0xEB @ 364 */ 0xC3, 0xAB,
/* 0xEC @ 366 */ 0xC3, 0xAC,
/* 0xED @ 368 */ 0xC3, 0xAD,
/* 0xEE @ 370 */ 0xC3, 0xAE,
/* 0xEF @ 372 */ 0xC3, 0xAF,
/* 0xF0 @ 374 */ 0xC3, 0xB0,
/* 0xF1 @ 376 */ 0xC3, 0xB1,
/* 0xF2 @ 378 */ 0xC3, 0xB2,
/* 0xF3 @ 380 */ 0xC3, 0xB3,
/* 0xF4 @ 382 */ 0xC3, 0xB4,
/* 0xF5 @ 384 */ 0xC3, 0xB5,
/* 0xF6 @ 386 */ 0xC3, 0xB6,
/* 0xF7 @ 388 */ 0xC3, 0xB7,
/* 0xF8 @ 390 */ 0xC3, 0xB8,
/* 0xF9 @ 392 */ 0xC3, 0xB9,
/* 0xFA @ 394 */ 0xC3, 0xBA,
/* 0xFB @ 396 */ 0xC3, 0xBB,
/* 0xFC @ 398 */ 0xC3, 0xBC,
/* 0xFD @ 400 */ 0xC3, 0xBD,
/* 0xFE @ 402 */ 0xC3, 0xBE,
/* 0xFF @ 404 */ 0xC3, 0xBF,
};
static const uint16_t tblofs[257] = {
/* 0x00 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 0x08 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 0x10 */ 16, 17, 18, 19, 20, 21, 22, 23,
/* 0x18 */ 24, 25, 26, 27, 28, 29, 30, 31,
/* 0x20 */ 32, 33, 34, 35, 36, 37, 38, 39,
/* 0x28 */ 40, 41, 42, 43, 44, 45, 46, 47,
/* 0x30 */ 48, 49, 50, 51, 52, 53, 54, 55,
/* 0x38 */ 56, 57, 58, 59, 60, 61, 62, 63,
/* 0x40 */ 64, 65, 66, 67, 68, 69, 70, 71,
/* 0x48 */ 72, 73, 74, 75, 76, 77, 78, 79,
/* 0x50 */ 80, 81, 82, 83, 84, 85, 86, 87,
/* 0x58 */ 88, 89, 90, 91, 92, 93, 94, 95,
/* 0x60 */ 96, 97, 98, 99, 100, 101, 102, 103,
/* 0x68 */ 104, 105, 106, 107, 108, 109, 110, 111,
/* 0x70 */ 112, 113, 114, 115, 116, 117, 118, 119,
/* 0x78 */ 120, 121, 122, 123, 124, 125, 126, 127,
/* 0x80 */ 128, 131, 134, 137, 139, 142, 145, 148,
/* 0x88 */ 151, 153, 156, 158, 161, 163, 166, 168,
/* 0x90 */ 171, 174, 177, 180, 183, 186, 189, 192,
/* 0x98 */ 195, 197, 200, 202, 205, 207, 210, 212,
/* 0xA0 */ 214, 216, 218, 220, 222, 224, 226, 228,
/* 0xA8 */ 230, 232, 234, 236, 238, 240, 242, 244,
/* 0xB0 */ 246, 248, 250, 252, 254, 256, 258, 260,
/* 0xB8 */ 262, 264, 266, 268, 270, 272, 274, 276,
/* 0xC0 */ 278, 280, 282, 284, 286, 288, 290, 292,
/* 0xC8 */ 294, 296, 298, 300, 302, 304, 306, 308,
/* 0xD0 */ 310, 312, 314, 316, 318, 320, 322, 324,
/* 0xD8 */ 326, 328, 330, 332, 334, 336, 338, 340,
/* 0xE0 */ 342, 344, 346, 348, 350, 352, 354, 356,
/* 0xE8 */ 358, 360, 362, 364, 366, 368, 370, 372,
/* 0xF0 */ 374, 376, 378, 380, 382, 384, 386, 388,
/* 0xF8 */ 390, 392, 394, 396, 398, 400, 402, 404,
/* sizeof (cp1252_utf8) */ 406
};
/* Check if a string qualifies as UTF-8. */
static int
is_utf8(const char* src)
{
uint8_t ch;
size_t i;
const uint8_t* s = (const uint8_t*) src;
/* We make a loop over every character, until we find a null one.
Remember: The string is supposed to end with a NUL, so ahead checks are safe. */
while ((ch = *s++)) {
/* Ye olde 7bit ASCII chars 'rr fine for anything */
if(ch < 0x80) continue;
/* Now, we watch out for non-UTF conform sequences. */
else if ((ch < 0xC2) || (ch > 0xFD))
return 0;
/* check for some misformed sequences */
if (((ch == 0xC2) && (s[0] < 0xA0)) ||
((ch == 0xEF) && (s[0] == 0xBF) && (s[1] > 0xBD)))
/* XXX add more for outside the BMP */
return 0;
/* Check the continuation bytes. */
if (ch < 0xE0) i = 1;
else if (ch < 0xF0) i = 2;
else if (ch < 0xF8) i = 3;
else if (ch < 0xFC) i = 4;
else
i = 5;
while (i--)
if ((*s++ & 0xC0) != 0x80)
return 0;
}
/* If no check failed, the string indeed looks like valid UTF-8. */
return 1;
}
/* The main conversion routine.
ICY in CP-1252 (or UTF-8 alreay) to UTF-8 encoded string.
If force is applied, it will always encode to UTF-8, without checking. */
char *
icy2utf8(const char *src, int force)
{
const uint8_t *s = (const uint8_t *)src;
size_t srclen, dstlen, i, k;
uint8_t ch, *d;
char *dst;
/* Some funny streams from Apple/iTunes give ICY info in UTF-8 already.
So, be prepared and don't try to re-encode such. Unless forced. */
if(!force && is_utf8(src)) return (compat_strdup(src));
srclen = strlen(src) + 1;
/* allocate conservatively */
if ((d = malloc(srclen * 3)) == NULL)
return (NULL);
i = 0;
dstlen = 0;
while (i < srclen) {
ch = s[i++];
k = tblofs[ch];
while (k < tblofs[ch + 1])
d[dstlen++] = cp1252_utf8[k++];
}
/* dstlen includes trailing NUL since srclen also does */
if ((dst = realloc(d, dstlen)) == NULL) {
free(d);
return (NULL);
}
return (dst);
}
/* This stuff is for testing only. */
#ifdef TEST
static const char intext[] = "\225 Gr\374\337e kosten 0,55 \200\205";
#include <stdio.h>
int
main(void)
{
char *t, *t2;
if ((t = icy2utf8(intext, 0)) == NULL) {
fprintf(stderr, "out of memory\n");
return (1);
}
/* make sure it won't be converted twice */
if ((t2 = icy2utf8(t), 0) == NULL) {
fprintf(stderr, "out of memory\n");
return (1);
}
printf("Result is:\t\343\200\214%s\343\200\215\n"
"\t\t\343\200\214%s\343\200\215\n", t, t2);
free(t);
free(t2);
return (0);
}
#endif

View File

@ -0,0 +1,10 @@
/* You expect a license plate for _this_ file? */
#ifndef MPG123_ICY2UTF_H
#define MPG123_ICY2UTF_H
#ifndef NO_ICY
/* (string, force conversion) */
char *icy2utf8(const char *, int);
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
/*
id3: ID3v2.3 and ID3v2.4 parsing (a relevant subset)
copyright 2006-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#ifndef MPG123_ID3_H
#define MPG123_ID3_H
/* really need it _here_! */
#include "frame.h"
#ifdef NO_ID3V2
# ifdef init_id3
# undef init_id3
# endif
# define init_id3(fr)
# ifdef exit_id3
# undef exit_id3
# endif
# define exit_id3(fr)
# ifdef reset_id3
# undef reset_id3
# endif
# define reset_id3(fr)
# ifdef id3_link
# undef id3_link
# endif
# define id3_link(fr)
#else
void init_id3(mpg123_handle *fr);
void exit_id3(mpg123_handle *fr);
void reset_id3(mpg123_handle *fr);
void id3_link(mpg123_handle *fr);
#endif
int parse_new_id3(mpg123_handle *fr, unsigned long first4bytes);
/* Convert text from some ID3 encoding to UTf-8.
On error, sb->fill is 0. The noquiet flag enables warning/error messages. */
void id3_to_utf8(mpg123_string *sb, unsigned char encoding, const unsigned char *source, size_t source_size, int noquiet);
#endif

View File

@ -0,0 +1,132 @@
/*
index: frame index data structure and functions
copyright 2007-2020 by the mpg123 project
-= free software under the terms of the LGPL 2.1 =-
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#include "intsym.h"
#include "index.h"
#include "debug.h"
/* The next expected frame offset, one step ahead. */
static off_t fi_next(struct frame_index *fi)
{
return (off_t)fi->fill*fi->step;
}
/* Shrink down the used index to the half.
Be careful with size = 1 ... there's no shrinking possible there. */
static void fi_shrink(struct frame_index *fi)
{
if(fi->fill < 2) return; /* Won't shrink below 1. */
else
{ /* Double the step, half the fill. Should work as well for fill%2 = 1 */
size_t c;
debug2("shrink index with fill %lu and step %lu", (unsigned long)fi->fill, (unsigned long)fi->step);
fi->step *= 2;
fi->fill /= 2;
/* Move the data down. */
for(c = 0; c < fi->fill; ++c)
fi->data[c] = fi->data[2*c];
}
fi->next = fi_next(fi);
}
void fi_init(struct frame_index *fi)
{
fi->data = NULL;
fi->step = 1;
fi->fill = 0;
fi->size = 0;
fi->grow_size = 0;
fi->next = fi_next(fi);
}
void fi_exit(struct frame_index *fi)
{
debug2("fi_exit: %p and %lu", (void*)fi->data, (unsigned long)fi->size);
if(fi->size && fi->data != NULL) free(fi->data);
fi_init(fi); /* Be prepared for further fun, still. */
}
int fi_resize(struct frame_index *fi, size_t newsize)
{
off_t *newdata = NULL;
if(newsize == fi->size) return 0;
if(newsize > 0 && newsize < fi->size)
{ /* When we reduce buffer size a bit, shrink stuff. */
while(fi->fill > newsize){ fi_shrink(fi); }
}
newdata = safe_realloc(fi->data, newsize*sizeof(off_t));
if(newsize == 0 || newdata != NULL)
{
fi->data = newdata;
fi->size = newsize;
if(fi->fill > fi->size) fi->fill = fi->size;
fi->next = fi_next(fi);
debug2("new index of size %lu at %p", (unsigned long)fi->size, (void*)fi->data);
return 0;
} else
return -1;
}
void fi_add(struct frame_index *fi, off_t pos)
{
debug3("wanting to add to fill %lu, step %lu, size %lu", (unsigned long)fi->fill, (unsigned long)fi->step, (unsigned long)fi->size);
if(fi->fill == fi->size)
{ /* Index is full, we need to shrink... or grow. */
/* Store the current frame number to check later if we still want it. */
off_t framenum = fi->fill*fi->step;
/* If we want not / cannot grow, we shrink. */
if( !(fi->grow_size && fi_resize(fi, fi->size+fi->grow_size)==0) )
fi_shrink(fi);
/* Now check if we still want to add this frame (could be that not, because of changed step). */
if(fi->next != framenum) return;
}
/* When we are here, we want that frame. */
if(fi->fill < fi->size) /* safeguard for size=1, or just generally */
{
debug1("adding to index at %p", (void*)(fi->data+fi->fill));
fi->data[fi->fill] = pos;
++fi->fill;
fi->next = fi_next(fi);
debug3("added pos %li to index with fill %lu and step %lu", (long) pos, (unsigned long)fi->fill, (unsigned long)fi->step);
}
}
int fi_set(struct frame_index *fi, off_t *offsets, off_t step, size_t fill)
{
if(fi_resize(fi, fill) == -1) return -1;
fi->step = step;
if(offsets != NULL)
{
memcpy(fi->data, offsets, fill*sizeof(off_t));
fi->fill = fill;
}
else
{
/* allocation only, no entries in index yet */
fi->fill = 0;
}
fi->next = fi_next(fi);
debug3("set new index of fill %lu, size %lu at %p",
(unsigned long)fi->fill, (unsigned long)fi->size, (void*)fi->data);
return 0;
}
void fi_reset(struct frame_index *fi)
{
debug1("reset with size %"SIZE_P, (size_p)fi->size);
fi->fill = 0;
fi->step = 1;
fi->next = fi_next(fi);
}

View File

@ -0,0 +1,59 @@
#ifndef MPG123_H_INDEX
#define MPG123_H_INDEX
/*
index: frame index data structure and functions
This is for keeping track of frame positions for accurate seeking.
Now in it's own file, with initial code from frame.c and parse.c .
The idea of the index with a certain amount of entries is to cover
all yet-encountered frame positions with minimal coarseness.
Meaning: At first every frame position is recorded, then, when
the index is full, every second position is trown away to make
space. Next time it is full, the same happens. And so on.
In this manner we maintain a good resolution with the given
maximum index size while covering the whole stream.
copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#include "config.h"
#include "compat.h"
struct frame_index
{
off_t *data; /* actual data, the frame positions */
off_t step; /* advancement in frame number per index point */
off_t next; /* frame offset supposed to come next into the index */
size_t size; /* total number of possible entries */
size_t fill; /* number of used entries */
size_t grow_size; /* if > 0: index allowed to grow on need with these steps, instead of lowering resolution */
};
/* The condition for a framenum to be appended to the index.
if(FI_NEXT(fr->index, fr->num)) fi_add(offset); */
#define FI_NEXT(fi, framenum) ((fi).size && framenum == (fi).next)
/* Initialize stuff, set things to zero and NULL... */
void fi_init(struct frame_index *fi);
/* Deallocate/zero things. */
void fi_exit(struct frame_index *fi);
/* Prepare a given size, preserving current fill, if possible.
If the new size is smaller than fill, the entry density is reduced.
Return 0 on success. */
int fi_resize(struct frame_index *fi, size_t newsize);
/* Append a frame position, reducing index density if needed. */
void fi_add(struct frame_index *fi, off_t pos);
/* Replace the frame index */
int fi_set(struct frame_index *fi, off_t *offsets, off_t step, size_t fill);
/* Empty the index (setting fill=0 and step=1), but keep current size. */
void fi_reset(struct frame_index *fi);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,167 @@
/*
l2tables.h: Layer 2 Alloc tables
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
most other tables are calculated on program start (which is (of course) not ISO-conform)
Layer-3 huffman table is in huffman.h
Note: runtime computation of those other tables is optional now, and only for
floating point decoding.
*/
#ifndef _MPG123_L2TABLES_H_
#define _MPG123_L2TABLES_H_
static const struct al_table alloc_0[] = {
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767} };
static const struct al_table alloc_1[] = {
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767},
{2,0},{5,3},{7,5},{16,-32767} };
static const struct al_table alloc_2[] = {
{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
static const struct al_table alloc_3[] = {
{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
static const struct al_table alloc_4[] = {
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9},
{2,0},{5,3},{7,5},{10,9} };
#endif

View File

@ -0,0 +1,94 @@
/*
l3bandinfo.h: the layer III bandInfo structures and gainpow2_scale
copyright 1995-2021 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
This is separated out of layer3.c to re-use independently in calctables.
*/
struct bandInfoStruct
{
unsigned short longIdx[23];
unsigned char longDiff[22];
unsigned short shortIdx[14];
unsigned char shortDiff[13];
};
/* Techy details about our friendly MPEG data. Fairly constant over the years;-) */
static const struct bandInfoStruct bandInfo[9] =
{
{ /* MPEG 1.0 */
{0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
{4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
{0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
{4,4,4,4,6,8,10,12,14,18,22,30,56}
},
{
{0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
{4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
{0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
{4,4,4,4,6,6,10,12,14,16,20,26,66}
},
{
{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},
{4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26},
{0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3},
{4,4,4,4,6,8,12,16,20,26,34,42,12}
},
{ /* MPEG 2.0 */
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
{0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
{4,4,4,6,6,8,10,14,18,26,32,42,18 }
},
{ /* Twiddling 3 values here (not just 330->332!) fixed bug 1895025. */
{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576},
{6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 },
{0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3},
{4,4,4,6,8,10,12,14,18,24,32,44,12 }
},
{
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
{0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
{4,4,4,6,8,10,12,14,18,24,30,40,18 }
},
{ /* MPEG 2.5 */
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
{4,4,4,6,8,10,12,14,18,24,30,40,18}
},
{
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
{4,4,4,6,8,10,12,14,18,24,30,40,18}
},
{
{0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
{12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
{0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
{8,8,8,12,16,20,24,28,36,2,2,2,26}
}
};
#if defined(REAL_IS_FIXED) || defined(CALCTABLES)
static const char gainpow2_scale[256+118+4+1] =
{
19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,
27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,0
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,250 @@
/*
layer1.c: the layer 1 decoder
copyright 1995-2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
may have a few bugs after last optimization ...
*/
#include "mpg123lib_intern.h"
#include "getbits.h"
#include "debug.h"
/*
Allocation value is not allowed to be 15. Initially, libmad showed me the
error that mpg123 used to ignore. Then, I found a quote on that in
Shlien, S. (1994): Guide to MPEG-1 Audio Standard.
IEEE Transactions on Broadcasting 40, 4
"To avoid conflicts with the synchronization code, code '1111' is defined
to be illegal."
*/
static int check_balloc(mpg123_handle *fr, unsigned int *balloc, unsigned int *end)
{
unsigned int *ba;
for(ba=balloc; ba != end; ++ba)
if(*ba == 15)
{
if(NOQUIET) error("Illegal bit allocation value.");
return -1;
}
return 0;
}
#define NEED_BITS(fr, num) \
if((fr)->bits_avail < num) \
{ \
if(NOQUIET) \
error2("%u bits needed, %li available", num, (fr)->bits_avail); \
return -1; \
} \
static int I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr)
{
unsigned int *ba=balloc;
unsigned int *sca = (unsigned int *) scale_index;
if(fr->stereo == 2)
{
int i;
int jsbound = fr->jsbound;
unsigned int needbits = jsbound*2*4 + (SBLIMIT-jsbound)*4;
NEED_BITS(fr, needbits);
needbits = 0;
for(i=0;i<jsbound;i++)
{
ba[0] = getbits_fast(fr, 4);
ba[1] = getbits_fast(fr, 4);
needbits += ((ba[0]?1:0)+(ba[1]?1:0))*6;
ba+=2;
}
for(i=jsbound;i<SBLIMIT;i++)
{
*ba = getbits_fast(fr, 4);
needbits += (*ba?1:0)*12;
++ba;
}
if(check_balloc(fr, balloc, ba)) return -1;
ba = balloc;
NEED_BITS(fr, needbits)
for(i=0;i<jsbound;i++)
{
if ((*ba++))
*sca++ = getbits_fast(fr, 6);
if ((*ba++))
*sca++ = getbits_fast(fr, 6);
}
for (i=jsbound;i<SBLIMIT;i++) if((*ba++))
{
*sca++ = getbits_fast(fr, 6);
*sca++ = getbits_fast(fr, 6);
}
}
else
{
int i;
unsigned int needbits = SBLIMIT*4;
NEED_BITS(fr, needbits)
needbits = 0;
for(i=0;i<SBLIMIT;i++)
{
*ba = getbits_fast(fr, 4);
needbits += (*ba?1:0)*6;
++ba;
}
if(check_balloc(fr, balloc, ba)) return -1;
ba = balloc;
NEED_BITS(fr, needbits)
for (i=0;i<SBLIMIT;i++)
if ((*ba++))
*sca++ = getbits_fast(fr, 6);
}
return 0;
}
/* Something sane in place of undefined (-1)<<n. Well, not really. */
#define MINUS_SHIFT(n) ( (int)(((unsigned int)-1)<<(n)) )
static int I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr)
{
int i,n;
int smpb[2*SBLIMIT]; /* values: 0-65535 */
int *sample;
register unsigned int *ba;
register unsigned int *sca = (unsigned int *) scale_index;
if(fr->stereo == 2)
{
unsigned int needbits = 0;
int jsbound = fr->jsbound;
register real *f0 = fraction[0];
register real *f1 = fraction[1];
ba = balloc;
for(sample=smpb,i=0;i<jsbound;i++)
{
if((n=*ba++))
needbits += n+1;
if((n=*ba++))
needbits += n+1;
}
for(i=jsbound;i<SBLIMIT;i++)
if((n = *ba++))
needbits += n+1;
NEED_BITS(fr, needbits)
ba = balloc;
for(sample=smpb,i=0;i<jsbound;i++)
{
if((n = *ba++)) *sample++ = getbits(fr, n+1);
if((n = *ba++)) *sample++ = getbits(fr, n+1);
}
for(i=jsbound;i<SBLIMIT;i++)
if((n = *ba++))
*sample++ = getbits(fr, n+1);
ba = balloc;
for(sample=smpb,i=0;i<jsbound;i++)
{
if((n=*ba++))
*f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
else *f0++ = DOUBLE_TO_REAL(0.0);
if((n=*ba++))
*f1++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
else *f1++ = DOUBLE_TO_REAL(0.0);
}
for(i=jsbound;i<SBLIMIT;i++)
{
if((n=*ba++))
{
real samp = DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1);
*f0++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]);
*f1++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]);
}
else *f0++ = *f1++ = DOUBLE_TO_REAL(0.0);
}
for(i=fr->down_sample_sblimit;i<32;i++)
fraction[0][i] = fraction[1][i] = 0.0;
}
else
{
unsigned int needbits = 0;
register real *f0 = fraction[0];
ba = balloc;
for(sample=smpb,i=0;i<SBLIMIT;i++)
if((n = *ba++))
needbits += n+1;
NEED_BITS(fr, needbits);
ba = balloc;
for(sample=smpb,i=0;i<SBLIMIT;i++)
if ((n = *ba++))
*sample++ = getbits(fr, n+1);
ba = balloc;
for(sample=smpb,i=0;i<SBLIMIT;i++)
{
if((n=*ba++))
*f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
else *f0++ = DOUBLE_TO_REAL(0.0);
}
for(i=fr->down_sample_sblimit;i<32;i++)
fraction[0][i] = DOUBLE_TO_REAL(0.0);
}
return 0;
}
int do_layer1(mpg123_handle *fr)
{
int clip=0;
int i,stereo = fr->stereo;
unsigned int balloc[2*SBLIMIT];
unsigned int scale_index[2][SBLIMIT];
real (*fraction)[SBLIMIT] = fr->layer1.fraction; /* fraction[2][SBLIMIT] */
int single = fr->single;
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
if(stereo == 1 || single == SINGLE_MIX) /* I don't see mixing handled here */
single = SINGLE_LEFT;
if(I_step_one(balloc,scale_index,fr))
{
if(NOQUIET)
error("Aborting layer I decoding after step one.");
return clip;
}
for(i=0;i<SCALE_BLOCK;i++)
{
if(I_step_two(fraction,balloc,scale_index,fr))
{
if(NOQUIET)
error("Aborting layer I decoding after step two.");
return clip;
}
if(single != SINGLE_STEREO)
clip += (fr->synth_mono)(fraction[single], fr);
else
clip += (fr->synth_stereo)(fraction[0], fraction[1], fr);
}
return clip;
}

View File

@ -0,0 +1,380 @@
/*
layer2.c: the layer 2 decoder, root of mpg123
copyright 1994-2021 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
mpg123 started as mp2 decoder a long time ago...
part of this file is required for layer 1, too.
*/
#include "mpg123lib_intern.h"
#ifndef NO_LAYER2
#include "l2tables.h"
#endif
#include "getbits.h"
#ifndef NO_LAYER12 /* Stuff needed for layer I and II. */
#include "l12tabs.h"
#ifdef RUNTIME_TABLES
#include "init_layer12.h"
#endif
// The layer12_table is already in real format (fixed or float), just needs
// a little scaling in the MMX/SSE case.
void init_layer12_stuff(mpg123_handle *fr, real* (*init_table)(mpg123_handle *fr, real *table, int m))
{
int k;
real *table;
for(k=0;k<27;k++)
{
table = init_table(fr, fr->muls[k], k);
*table++ = 0.0;
}
}
real* init_layer12_table(mpg123_handle *fr, real *table, int m)
{
int i;
for(i=0;i<63;i++)
*table++ = layer12_table[m][i];
return table;
}
#ifdef OPT_MMXORSSE
real* init_layer12_table_mmx(mpg123_handle *fr, real *table, int m)
{
int i,j;
if(!fr->p.down_sample)
{
for(j=3,i=0;i<63;i++,j--)
*table++ = 16384 * layer12_table[m][i];
}
else
{
for(j=3,i=0;i<63;i++,j--)
*table++ = layer12_table[m][i];
}
return table;
}
#endif
#endif /* NO_LAYER12 */
/* The rest is the actual decoding of layer II data. */
#ifndef NO_LAYER2
static int II_step_one(unsigned int *bit_alloc,int *scale,mpg123_handle *fr)
{
int stereo = fr->stereo-1;
int sblimit = fr->II_sblimit;
int jsbound = fr->jsbound;
int sblimit2 = fr->II_sblimit<<stereo;
const struct al_table *alloc1 = fr->alloc;
int i;
unsigned int scfsi_buf[64];
unsigned int *scfsi,*bita;
int sc,step;
/* Count the bits needed for getbits_fast(). */
unsigned int needbits = 0;
unsigned int scale_bits[4] = { 18, 12, 6, 12 };
bita = bit_alloc;
if(stereo)
{
for(i=jsbound;i;i--,alloc1+=(1<<step))
{
step=alloc1->bits;
bita[0] = (char) getbits(fr, step);
bita[1] = (char) getbits(fr, step);
needbits += ((bita[0]?1:0)+(bita[1]?1:0))*2;
bita+=2;
}
for(i=sblimit-jsbound;i;i--,alloc1+=(1<<step))
{
step=alloc1->bits;
bita[0] = (char) getbits(fr, step);
bita[1] = bita[0];
needbits += (bita[0]?1:0)*2*2;
bita+=2;
}
bita = bit_alloc;
scfsi=scfsi_buf;
if(fr->bits_avail < needbits)
{
if(NOQUIET)
error2("need %u bits, have %li", needbits, fr->bits_avail);
return -1;
}
for(i=sblimit2;i;i--)
if(*bita++) *scfsi++ = (char) getbits_fast(fr, 2);
}
else /* mono */
{
for(i=sblimit;i;i--,alloc1+=(1<<step))
{
step=alloc1->bits;
*bita = (char) getbits(fr, step);
if(*bita)
needbits += 2;
++bita;
}
bita = bit_alloc;
scfsi=scfsi_buf;
if(fr->bits_avail < needbits)
{
if(NOQUIET)
error2("need %u bits, have %li", needbits, fr->bits_avail);
return -1;
}
for(i=sblimit;i;i--)
if(*bita++) *scfsi++ = (char) getbits_fast(fr, 2);
}
needbits = 0;
bita = bit_alloc;
scfsi=scfsi_buf;
for(i=sblimit2;i;--i)
if(*bita++)
needbits += scale_bits[*scfsi++];
if(fr->bits_avail < needbits)
{
if(NOQUIET)
error2("need %u bits, have %li", needbits, fr->bits_avail);
return -1;
}
bita = bit_alloc;
scfsi=scfsi_buf;
for(i=sblimit2;i;--i)
if(*bita++)
switch(*scfsi++)
{
case 0:
*scale++ = getbits_fast(fr, 6);
*scale++ = getbits_fast(fr, 6);
*scale++ = getbits_fast(fr, 6);
break;
case 1 :
*scale++ = sc = getbits_fast(fr, 6);
*scale++ = sc;
*scale++ = getbits_fast(fr, 6);
break;
case 2:
*scale++ = sc = getbits_fast(fr, 6);
*scale++ = sc;
*scale++ = sc;
break;
default: /* case 3 */
*scale++ = getbits_fast(fr, 6);
*scale++ = sc = getbits_fast(fr, 6);
*scale++ = sc;
break;
}
return 0;
}
static void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,mpg123_handle *fr,int x1)
{
int i,j,k,ba;
int stereo = fr->stereo;
int sblimit = fr->II_sblimit;
int jsbound = fr->jsbound;
const struct al_table *alloc2,*alloc1 = fr->alloc;
unsigned int *bita=bit_alloc;
int d1,step;
for(i=0;i<jsbound;i++,alloc1+=(1<<step))
{
step = alloc1->bits;
for(j=0;j<stereo;j++)
{
if( (ba=*bita++) )
{
k=(alloc2 = alloc1+ba)->bits;
if( (d1=alloc2->d) < 0)
{
real cm=fr->muls[k][scale[x1]];
fraction[j][0][i] = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1), cm);
fraction[j][1][i] = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1), cm);
fraction[j][2][i] = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1), cm);
}
else
{
const unsigned char *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
unsigned int m=scale[x1];
unsigned int idx = (unsigned int) getbits(fr, k);
const unsigned char *tab = table[d1] + idx + idx + idx;
fraction[j][0][i] = REAL_SCALE_LAYER12(fr->muls[*tab++][m]);
fraction[j][1][i] = REAL_SCALE_LAYER12(fr->muls[*tab++][m]);
fraction[j][2][i] = REAL_SCALE_LAYER12(fr->muls[*tab][m]);
}
scale+=3;
}
else
fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = DOUBLE_TO_REAL(0.0);
if(fr->bits_avail < 0)
return; /* Caller checks that again. */
}
}
for(i=jsbound;i<sblimit;i++,alloc1+=(1<<step))
{
step = alloc1->bits;
bita++; /* channel 1 and channel 2 bitalloc are the same */
if( (ba=*bita++) )
{
k=(alloc2 = alloc1+ba)->bits;
if( (d1=alloc2->d) < 0)
{
real cm;
cm=fr->muls[k][scale[x1+3]];
fraction[0][0][i] = DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1);
fraction[0][1][i] = DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1);
fraction[0][2][i] = DOUBLE_TO_REAL_15((int)getbits(fr, k) + d1);
fraction[1][0][i] = REAL_MUL_SCALE_LAYER12(fraction[0][0][i], cm);
fraction[1][1][i] = REAL_MUL_SCALE_LAYER12(fraction[0][1][i], cm);
fraction[1][2][i] = REAL_MUL_SCALE_LAYER12(fraction[0][2][i], cm);
cm=fr->muls[k][scale[x1]];
fraction[0][0][i] = REAL_MUL_SCALE_LAYER12(fraction[0][0][i], cm);
fraction[0][1][i] = REAL_MUL_SCALE_LAYER12(fraction[0][1][i], cm);
fraction[0][2][i] = REAL_MUL_SCALE_LAYER12(fraction[0][2][i], cm);
}
else
{
const unsigned char *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
unsigned int m1 = scale[x1];
unsigned int m2 = scale[x1+3];
unsigned int idx = (unsigned int) getbits(fr, k);
const unsigned char *tab = table[d1] + idx + idx + idx;
fraction[0][0][i] = REAL_SCALE_LAYER12(fr->muls[*tab][m1]); fraction[1][0][i] = REAL_SCALE_LAYER12(fr->muls[*tab++][m2]);
fraction[0][1][i] = REAL_SCALE_LAYER12(fr->muls[*tab][m1]); fraction[1][1][i] = REAL_SCALE_LAYER12(fr->muls[*tab++][m2]);
fraction[0][2][i] = REAL_SCALE_LAYER12(fr->muls[*tab][m1]); fraction[1][2][i] = REAL_SCALE_LAYER12(fr->muls[*tab][m2]);
}
scale+=6;
if(fr->bits_avail < 0)
return; /* Caller checks that again. */
}
else
{
fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = DOUBLE_TO_REAL(0.0);
}
/*
Historic comment...
should we use individual scalefac for channel 2 or
is the current way the right one , where we just copy channel 1 to
channel 2 ??
The current 'strange' thing is, that we throw away the scalefac
values for the second channel ...!!
-> changed .. now we use the scalefac values of channel one !!
*/
}
if(sblimit > (fr->down_sample_sblimit) )
sblimit = fr->down_sample_sblimit;
for(i=sblimit;i<SBLIMIT;i++)
for (j=0;j<stereo;j++)
fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = DOUBLE_TO_REAL(0.0);
}
static void II_select_table(mpg123_handle *fr)
{
const int translate[3][2][16] =
{
{
{ 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 },
{ 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 }
},
{
{ 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 },
{ 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 }
},
{
{ 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 },
{ 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 }
}
};
int table,sblim;
const struct al_table *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
const int sblims[5] = { 27 , 30 , 8, 12 , 30 };
if(fr->sampling_frequency >= 3) /* Or equivalent: (fr->lsf == 1) */
table = 4;
else
table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
sblim = sblims[table];
fr->alloc = tables[table];
fr->II_sblimit = sblim;
}
int do_layer2(mpg123_handle *fr)
{
int clip=0;
int i,j;
int stereo = fr->stereo;
/* pick_table clears unused subbands */
/* replacement for real fraction[2][4][SBLIMIT], needs alignment. */
real (*fraction)[4][SBLIMIT] = fr->layer2.fraction;
unsigned int bit_alloc[64];
int scale[192];
int single = fr->single;
II_select_table(fr);
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : fr->II_sblimit;
if(fr->jsbound > fr->II_sblimit)
{
fprintf(stderr, "Truncating stereo boundary to sideband limit.\n");
fr->jsbound=fr->II_sblimit;
}
/* TODO: What happens with mono mixing, actually? */
if(stereo == 1 || single == SINGLE_MIX) /* also, mix not really handled */
single = SINGLE_LEFT;
if(II_step_one(bit_alloc, scale, fr))
{
if(NOQUIET)
error("first step of layer I decoding failed");
return clip;
}
for(i=0;i<SCALE_BLOCK;i++)
{
II_step_two(bit_alloc,fraction,scale,fr,i>>2);
if(fr->bits_avail < 0)
{
if(NOQUIET)
error("missing bits in layer II step two");
return clip;
}
for(j=0;j<3;j++)
{
if(single != SINGLE_STEREO)
clip += (fr->synth_mono)(fraction[single][j], fr);
else
clip += (fr->synth_stereo)(fraction[0][j], fraction[1][j], fr);
}
}
return clip;
}
#endif /* NO_LAYER2 */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,781 @@
/*
lfs_wrap: Crappy wrapper code for supporting crappy ambiguous large file support.
copyright 2010-2020 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, thanks to Guido Draheim for consulting
This file contains wrappers for the case that _FILE_OFFSET_BITS (or equivalent, theoretically, depends on mpg123.h) is defined and thus certain mpg123 API calls get renamed with a suffix (p.ex. _64).
The renamed calls expect large off_t arguments, and possibly return large off_t values... these wrappers here provide the same functionality with long integer arguments/values.
Prototypical idea: There is
off_t mpg123_seek_64(mpg123_handle*, off_t, int)
This code provides
long mpg123_seek(mpg123_handle*, long, int)
This is rather simple business... wouldn't mpg123 offer replacing the I/O core with callbacks. Translating the callbacks between long and off_t world is the main reason why this file contains non-trivial code.
Note about file descriptors: We just assume that they are generally interchangeable between large and small file code... and that a large file descriptor will trigger errors when accessed with small file code where it may cause trouble (a really large file).
*/
/* It mainly needs the official API ... */
/* ... but also some inside access (frame struct, readers). */
#include "mpg123lib_intern.h"
/* Include the system headers _after_ the implied config.h!
Otherwise _FILE_OFFSET_BITS is not in effect! */
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "compat.h"
#include "debug.h"
/*
Now, start off easy... translate simple API calls.
I need to deal with these here:
perl -ne '
if(/^\s*MPG123_EXPORT\s+(\S+)\s+(mpg123_\S+)\((.*)\);\s*$/)
{
$type = $1;
$name = $2;
$args = $3;
next unless ($type =~ /off_t/ or $args =~ /off_t/);
print "$name\n" unless grep {$_ eq $name}
("mpg123_open", "mpg123_open_fd", "mpg123_open_handle", "mpg123_replace_reader", "mpg123_replace_reader_handle");
}' < mpg123.h.in
mpg123_decode_frame
mpg123_framebyframe_decode
mpg123_framepos
mpg123_tell
mpg123_tellframe
mpg123_tell_stream
mpg123_seek
mpg123_feedseek
mpg123_seek_frame
mpg123_timeframe
mpg123_index
mpg123_set_index
mpg123_position
mpg123_length
mpg123_set_filesize
mpg123_decode_raw ... that's experimental.
Let's work on them in that order.
*/
/* I see that I will need custom data storage. Main use is for the replaced I/O later, but the seek table for small file offsets needs extra storage, too. */
/* The wrapper handle for descriptor and handle I/O. */
/* The handle is used for nothing (0), or one of these two modes of operation: */
#define IO_FD 1 /* Wrapping over callbacks operation on integer file descriptor. */
#define IO_HANDLE 2 /* Wrapping over custom handle callbacks. */
struct wrap_data
{
/* Storage for small offset index table. */
long *indextable;
/* I/O handle stuff */
int iotype; /* IO_FD or IO_HANDLE */
/* Data for IO_FD. */
int fd;
int my_fd; /* A descriptor that the wrapper code opened itself. */
/* The actual callbacks from the outside. */
ssize_t (*r_read) (int, void *, size_t);
long (*r_lseek)(int, long, int);
/* Data for IO_HANDLE. */
void* handle;
ssize_t (*r_h_read)(void *, void *, size_t);
long (*r_h_lseek)(void*, long, int);
void (*h_cleanup)(void*);
};
/* Cleanup I/O part of the handle handle... but not deleting the wrapper handle itself.
That is stored in the frame and only deleted on mpg123_delete(). */
static void wrap_io_cleanup(void *handle)
{
struct wrap_data *ioh = handle;
if(ioh->iotype == IO_HANDLE)
{
if(ioh->h_cleanup != NULL && ioh->handle != NULL)
ioh->h_cleanup(ioh->handle);
ioh->handle = NULL;
}
if(ioh->my_fd >= 0)
{
close(ioh->my_fd);
ioh->my_fd = -1;
}
}
/* Really finish off the handle... freeing all memory. */
static void wrap_destroy(void *handle)
{
struct wrap_data *wh = handle;
wrap_io_cleanup(handle);
if(wh->indextable != NULL)
free(wh->indextable);
free(wh);
}
/* More helper code... extract the special wrapper handle, possible allocate and initialize it. */
static struct wrap_data* wrap_get(mpg123_handle *mh)
{
struct wrap_data* whd;
if(mh == NULL) return NULL;
/* Access the private storage inside the mpg123 handle.
The real callback functions and handles are stored there. */
if(mh->wrapperdata == NULL)
{
/* Create a new one. */
mh->wrapperdata = malloc(sizeof(struct wrap_data));
if(mh->wrapperdata == NULL)
{
mh->err = MPG123_OUT_OF_MEM;
return NULL;
}
/* When we have wrapper data present, the callback for its proper cleanup is needed. */
mh->wrapperclean = wrap_destroy;
whd = mh->wrapperdata;
whd->indextable = NULL;
whd->iotype = 0;
whd->fd = -1;
whd->my_fd = -1;
whd->r_read = NULL;
whd->r_lseek = NULL;
whd->handle = NULL;
whd->r_h_read = NULL;
whd->r_h_lseek = NULL;
whd->h_cleanup = NULL;
}
else whd = mh->wrapperdata;
return whd;
}
/* After settling the data... start with some simple wrappers. */
#undef mpg123_decode_frame
/* int mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes) */
int attribute_align_arg mpg123_decode_frame(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
{
off_t largenum;
int err;
err = MPG123_LARGENAME(mpg123_decode_frame)(mh, &largenum, audio, bytes);
if(err == MPG123_OK && num != NULL)
{
*num = largenum;
if(*num != largenum)
{
mh->err = MPG123_LFS_OVERFLOW;
err = MPG123_ERR;
}
}
return err;
}
#undef mpg123_framebyframe_decode
/* int mpg123_framebyframe_decode(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes); */
int attribute_align_arg mpg123_framebyframe_decode(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
{
off_t largenum;
int err;
err = MPG123_LARGENAME(mpg123_framebyframe_decode)(mh, &largenum, audio, bytes);
if(err == MPG123_OK && num != NULL)
{
*num = largenum;
if(*num != largenum)
{
mh->err = MPG123_LFS_OVERFLOW;
err = MPG123_ERR;
}
}
return err;
}
#undef mpg123_framepos
/* off_t mpg123_framepos(mpg123_handle *mh); */
long attribute_align_arg mpg123_framepos(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_framepos)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_tell
/* off_t mpg123_tell(mpg123_handle *mh); */
long attribute_align_arg mpg123_tell(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_tell)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_tellframe
/* off_t mpg123_tellframe(mpg123_handle *mh); */
long attribute_align_arg mpg123_tellframe(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_tellframe)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_tell_stream
/* off_t mpg123_tell_stream(mpg123_handle *mh); */
long attribute_align_arg mpg123_tell_stream(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_tell_stream)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_seek
/* off_t mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence); */
long attribute_align_arg mpg123_seek(mpg123_handle *mh, long sampleoff, int whence)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_seek)(mh, sampleoff, whence);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_feedseek
/* off_t mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset); */
long attribute_align_arg mpg123_feedseek(mpg123_handle *mh, long sampleoff, int whence, long *input_offset)
{
long val;
off_t largeioff;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_feedseek)(mh, sampleoff, whence, &largeioff);
/* Error/message codes are small... */
if(largeval < 0) return (long)largeval;
val = largeval;
*input_offset = largeioff;
if(val != largeval || *input_offset != largeioff)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_seek_frame
/* off_t mpg123_seek_frame(mpg123_handle *mh, off_t frameoff, int whence); */
long attribute_align_arg mpg123_seek_frame(mpg123_handle *mh, long frameoff, int whence)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_seek_frame)(mh, frameoff, whence);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_timeframe
/* off_t mpg123_timeframe(mpg123_handle *mh, double sec); */
long attribute_align_arg mpg123_timeframe(mpg123_handle *mh, double sec)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_timeframe)(mh, sec);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
/* Now something less simple: Index retrieval and manipulation.
The index is an _array_ of off_t, which means that I need to construct a copy with translated long values. */
#undef mpg123_index
/* int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill) */
int attribute_align_arg mpg123_index(mpg123_handle *mh, long **offsets, long *step, size_t *fill)
{
int err;
size_t i;
long smallstep;
size_t thefill;
off_t largestep;
off_t *largeoffsets;
struct wrap_data *whd;
whd = wrap_get(mh);
if(whd == NULL) return MPG123_ERR;
err = MPG123_LARGENAME(mpg123_index)(mh, &largeoffsets, &largestep, &thefill);
if(err != MPG123_OK) return err;
/* For a _very_ large file, even the step could overflow. */
smallstep = largestep;
if(smallstep != largestep)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
if(step != NULL) *step = smallstep;
/* When there are no values stored, there is no table content to take care of.
Table pointer does not matter. Mission completed. */
if(thefill == 0) return MPG123_OK;
if(fill != NULL) *fill = thefill;
/* Construct a copy of the index to hand over to the small-minded client. */
*offsets = safe_realloc(whd->indextable, (*fill)*sizeof(long));
if(*offsets == NULL)
{
mh->err = MPG123_OUT_OF_MEM;
return MPG123_ERR;
}
whd->indextable = *offsets;
/* Elaborate conversion of each index value, with overflow check. */
for(i=0; i<*fill; ++i)
{
whd->indextable[i] = largeoffsets[i];
if(whd->indextable[i] != largeoffsets[i])
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
}
/* If we came that far... there should be a valid copy of the table now. */
return MPG123_OK;
}
/* The writing does basically the same than the above, just the opposite.
Oh, and the overflow checks are not needed -- off_t is bigger than long. */
#undef mpg123_set_index
/* int mpg123_set_index(mpg123_handle *mh, off_t *offsets, off_t step, size_t fill); */
int attribute_align_arg mpg123_set_index(mpg123_handle *mh, long *offsets, long step, size_t fill)
{
int err;
size_t i;
struct wrap_data *whd;
off_t *indextmp;
whd = wrap_get(mh);
if(whd == NULL) return MPG123_ERR;
/* Expensive temporary storage... for staying outside at the API layer. */
indextmp = malloc(fill*sizeof(off_t));
if(indextmp == NULL)
{
mh->err = MPG123_OUT_OF_MEM;
return MPG123_ERR;
}
if(fill > 0 && offsets == NULL)
{
mh->err = MPG123_BAD_INDEX_PAR;
err = MPG123_ERR;
}
else
{
/* Fill the large-file copy of the provided index, then feed it to mpg123. */
for(i=0; i<fill; ++i)
indextmp[i] = offsets[i];
err = MPG123_LARGENAME(mpg123_set_index)(mh, indextmp, step, fill);
}
free(indextmp);
return err;
}
/* So... breathe... a couple of simple wrappers before the big mess. */
#undef mpg123_position
/* int mpg123_position( mpg123_handle *mh, off_t frame_offset, off_t buffered_bytes, off_t *current_frame, off_t *frames_left, double *current_seconds, double *seconds_left); */
int attribute_align_arg mpg123_position(mpg123_handle *mh, long frame_offset, long buffered_bytes, long *current_frame, long *frames_left, double *current_seconds, double *seconds_left)
{
off_t curframe, frameleft;
long small_curframe, small_frameleft;
int err;
err = MPG123_LARGENAME(mpg123_position)(mh, frame_offset, buffered_bytes, &curframe, &frameleft, current_seconds, seconds_left);
if(err != MPG123_OK) return err;
small_curframe = curframe;
small_frameleft = frameleft;
if(small_curframe != curframe || small_frameleft != frameleft)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
if(current_frame != NULL) *current_frame = small_curframe;
if(frames_left != NULL) *frames_left = small_frameleft;
return MPG123_OK;
}
#undef mpg123_framelength
/* off_t mpg123_framelength(mpg123_handle *mh); */
long attribute_align_arg mpg123_framelength(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_framelength)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
#undef mpg123_length
/* off_t mpg123_length(mpg123_handle *mh); */
long attribute_align_arg mpg123_length(mpg123_handle *mh)
{
long val;
off_t largeval;
largeval = MPG123_LARGENAME(mpg123_length)(mh);
val = largeval;
if(val != largeval)
{
mh->err = MPG123_LFS_OVERFLOW;
return MPG123_ERR;
}
return val;
}
/* The simplest wrapper of all... */
#undef mpg123_set_filesize
/* int mpg123_set_filesize(mpg123_handle *mh, off_t size); */
int attribute_align_arg mpg123_set_filesize(mpg123_handle *mh, long size)
{
return MPG123_LARGENAME(mpg123_set_filesize)(mh, size);
}
/* =========================================
THE BOUNDARY OF SANITY
Behold, stranger!
========================================= */
/*
The messy part: Replacement of I/O core (actally, this is only due to lseek()).
Both descriptor and handle replaced I/O are mapped to replaced handle I/O, the handle wrapping over the actual callbacks and the actual handle/descriptor.
You got multiple levels of handles and callbacks to think about. Have fun reading and comprehending.
*/
/* Could go into compat.h ... Windows needs that flag. */
#ifndef O_BINARY
#define O_BINARY 0
#endif
/* Read callback needs nothing special. */
ssize_t wrap_read(void* handle, void *buf, size_t count)
{
struct wrap_data *ioh = handle;
switch(ioh->iotype)
{
case IO_FD: return ioh->r_read(ioh->fd, buf, count);
case IO_HANDLE: return ioh->r_h_read(ioh->handle, buf, count);
}
error("Serious breakage - bad IO type in LFS wrapper!");
return -1;
}
/* Seek callback needs protection from too big offsets. */
off_t wrap_lseek(void *handle, off_t offset, int whence)
{
struct wrap_data *ioh = handle;
long smalloff = offset;
if(smalloff == offset)
{
switch(ioh->iotype)
{
case IO_FD: return ioh->r_lseek(ioh->fd, smalloff, whence);
case IO_HANDLE: return ioh->r_h_lseek(ioh->handle, smalloff, whence);
}
return -1;
}
else
{
errno = EOVERFLOW;
return -1;
}
}
/*
Now, let's replace the API dealing with replacement I/O.
Start with undefining the renames...
*/
#undef mpg123_replace_reader
#undef mpg123_replace_reader_handle
#undef mpg123_open
#undef mpg123_open_fixed
#undef mpg123_open_fd
#undef mpg123_open_handle
/* Normal reader replacement needs fallback implementations. */
static ssize_t fallback_read(int fd, void *buf, size_t count)
{
return read(fd, buf, count);
}
static long fallback_lseek(int fd, long offset, int whence)
{
/* Since the offset is long int already, the returned value really should fit into a long... but whatever. */
long newpos_long;
off_t newpos;
newpos = lseek(fd, offset, whence);
newpos_long = newpos;
if(newpos_long == newpos)
return newpos_long;
else
{
errno = EOVERFLOW;
return -1;
}
}
/* Reader replacement prepares the hidden handle storage for next mpg123_open_fd() or plain mpg123_open(). */
int attribute_align_arg mpg123_replace_reader(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), long (*r_lseek)(int, long, int) )
{
struct wrap_data* ioh;
if(mh == NULL) return MPG123_ERR;
mpg123_close(mh);
ioh = wrap_get(mh);
if(ioh == NULL) return MPG123_ERR;
/* If both callbacks are NULL, switch totally to internal I/O, else just use fallback for at most half of them. */
if(r_read == NULL && r_lseek == NULL)
{
/* Only the type is actually important to disable the code. */
ioh->iotype = 0;
ioh->fd = -1;
ioh->r_read = NULL;
ioh->r_lseek = NULL;
}
else
{
ioh->iotype = IO_FD;
ioh->fd = -1; /* On next mpg123_open_fd(), this gets a value. */
ioh->r_read = r_read != NULL ? r_read : fallback_read;
ioh->r_lseek = r_lseek != NULL ? r_lseek : fallback_lseek;
}
/* The real reader replacement will happen while opening. */
return MPG123_OK;
}
int attribute_align_arg mpg123_replace_reader_handle(mpg123_handle *mh, ssize_t (*r_read) (void*, void *, size_t), long (*r_lseek)(void*, long, int), void (*cleanup)(void*))
{
struct wrap_data* ioh;
if(mh == NULL) return MPG123_ERR;
mpg123_close(mh);
ioh = wrap_get(mh);
if(ioh == NULL) return MPG123_ERR;
ioh->iotype = IO_HANDLE;
ioh->handle = NULL;
ioh->r_h_read = r_read;
ioh->r_h_lseek = r_lseek;
ioh->h_cleanup = cleanup;
/* The real reader replacement will happen while opening. */
return MPG123_OK;
}
/*
The open routines always need to watch out for a prepared wrapper handle to use replaced normal I/O.
Two cases to consider:
1. Plain normal open using internal I/O.
2. Client called mpg123_replace_reader() before.
The second case needs hackery to activate the client I/O callbacks. For that, we create a custom I/O handle and use the guts of mpg123_open_fd() on it.
*/
int attribute_align_arg mpg123_open(mpg123_handle *mh, const char *path)
{
struct wrap_data* ioh;
if(mh == NULL) return MPG123_ERR;
ioh = mh->wrapperdata;
/* Mimic the use of mpg123_replace_reader() functions by lower levels...
IO_HANDLE is not valid here, though. Only IO_FD. */
if(ioh != NULL && ioh->iotype == IO_FD)
{
int err;
err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
if(err != MPG123_OK) return MPG123_ERR;
/* The above call implied mpg123_close() already */
/*
I really need to open the file here... to be able to use the replacer handle I/O ...
my_fd is used to indicate closing of the descriptor on cleanup.
*/
ioh->my_fd = compat_open(path, O_RDONLY|O_BINARY);
if(ioh->my_fd < 0)
{
if(!(mh->p.flags & MPG123_QUIET)) error2("Cannot open file %s: %s", path, strerror(errno));
mh->err = MPG123_BAD_FILE;
return MPG123_ERR;
}
/* Store a copy of the descriptor where it is actually used. */
ioh->fd = ioh->my_fd;
/* Initiate I/O operating on my handle now. */
err = open_stream_handle(mh, ioh);
if(err != MPG123_OK)
{
wrap_io_cleanup(ioh);
return MPG123_ERR;
}
/* All fine... */
return MPG123_OK;
}
else return MPG123_LARGENAME(mpg123_open)(mh, path);
}
// This one needs to follow the logic of the original, and wrap the actual
// mpg123_open() here.
int attribute_align_arg mpg123_open_fixed( mpg123_handle *mh, const char *path
, int channels, int encoding )
{
int err = open_fixed_pre(mh, channels, encoding);
if(err == MPG123_OK)
err = mpg123_open(mh, path);
if(err == MPG123_OK)
err = open_fixed_post(mh, channels, encoding);
return err;
}
/*
This is in fact very similar to the above:
The open routines always need to watch out for a prepared wrapper handle to use replaced normal I/O.
Two cases to consider:
1. Plain normal open_fd using internal I/O.
2. Client called mpg123_replace_reader() before.
The second case needs hackery to activate the client I/O callbacks. For that, we create a custom I/O handle and use the guts of mpg123_open_fd() on it.
*/
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
struct wrap_data* ioh;
if(mh == NULL) return MPG123_ERR;
mpg123_close(mh);
ioh = mh->wrapperdata;
if(ioh != NULL && ioh->iotype == IO_FD)
{
int err;
err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
if(err != MPG123_OK) return MPG123_ERR;
/* The above call implied mpg123_close() already */
/* Store the real file descriptor inside the handle. */
ioh->fd = fd;
/* Initiate I/O operating on my handle now. */
err = open_stream_handle(mh, ioh);
if(err != MPG123_OK)
{
wrap_io_cleanup(ioh);
return MPG123_ERR;
}
/* All fine... */
return MPG123_OK;
}
else return MPG123_LARGENAME(mpg123_open_fd)(mh, fd);
}
int attribute_align_arg mpg123_open_handle(mpg123_handle *mh, void *handle)
{
struct wrap_data* ioh;
if(mh == NULL) return MPG123_ERR;
mpg123_close(mh);
ioh = mh->wrapperdata;
if(ioh != NULL && ioh->iotype == IO_HANDLE && ioh->r_h_read != NULL)
{
/* Wrap the custom handle into my handle. */
int err;
err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
if(err != MPG123_OK) return MPG123_ERR;
ioh->handle = handle;
/* No extra error handling, keep behaviour of the original open_handle. */
return open_stream_handle(mh, ioh);
}
else
{
/* This is an error ... you need to prepare the I/O before using it. */
mh->err = MPG123_BAD_CUSTOM_IO;
return MPG123_ERR;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,89 @@
/*
mpeghead: the bits of an MPEG frame header
copyright ?-2011 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp & Thomas Orgis (from parse.c)
*/
#ifndef MPG123_MPEGHEAD_H
#define MPG123_MPEGHEAD_H
/*
Avoid human error, let perl do the work of dissecting an MPEG header into parts.
To be clear: Never edit the following definitions by hand, modify the code block inside this comment and run it through perl instead!
$head = "AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM";
%parts = qw(A sync B version C layer D crc E bitrate F samplerate G padding H private I channel J chanex K copyright L original M emphasis);
for(sort keys %parts)
{
$name = uc($parts{$_});
$bits = $head;
$bits =~ s/$_/1/g;
$bits =~ s/[^1 ]/0/g;
print "\/\* $bits \*\/\n";
$bits =~ s/\s//g;
print "#define HDR_$name".(" " x (18-length($name))).sprintf("0x%08x", eval("0b$bits"))."\n";
$bits =~ m/(0*)$/;
print "#define HDR_${name}_VAL(h)".(" " x (11-length($name)))."(((h)\&HDR_$name) >> ".length($1).")\n";
}
*/
/* 11111111 11100000 00000000 00000000 */
#define HDR_SYNC 0xffe00000
#define HDR_SYNC_VAL(h) (((h)&HDR_SYNC) >> 21)
/* 00000000 00011000 00000000 00000000 */
#define HDR_VERSION 0x00180000
#define HDR_VERSION_VAL(h) (((h)&HDR_VERSION) >> 19)
/* 00000000 00000110 00000000 00000000 */
#define HDR_LAYER 0x00060000
#define HDR_LAYER_VAL(h) (((h)&HDR_LAYER) >> 17)
/* 00000000 00000001 00000000 00000000 */
#define HDR_CRC 0x00010000
#define HDR_CRC_VAL(h) (((h)&HDR_CRC) >> 16)
/* 00000000 00000000 11110000 00000000 */
#define HDR_BITRATE 0x0000f000
#define HDR_BITRATE_VAL(h) (((h)&HDR_BITRATE) >> 12)
/* 00000000 00000000 00001100 00000000 */
#define HDR_SAMPLERATE 0x00000c00
#define HDR_SAMPLERATE_VAL(h) (((h)&HDR_SAMPLERATE) >> 10)
/* 00000000 00000000 00000010 00000000 */
#define HDR_PADDING 0x00000200
#define HDR_PADDING_VAL(h) (((h)&HDR_PADDING) >> 9)
/* 00000000 00000000 00000001 00000000 */
#define HDR_PRIVATE 0x00000100
#define HDR_PRIVATE_VAL(h) (((h)&HDR_PRIVATE) >> 8)
/* 00000000 00000000 00000000 11000000 */
#define HDR_CHANNEL 0x000000c0
#define HDR_CHANNEL_VAL(h) (((h)&HDR_CHANNEL) >> 6)
/* 00000000 00000000 00000000 00110000 */
#define HDR_CHANEX 0x00000030
#define HDR_CHANEX_VAL(h) (((h)&HDR_CHANEX) >> 4)
/* 00000000 00000000 00000000 00001000 */
#define HDR_COPYRIGHT 0x00000008
#define HDR_COPYRIGHT_VAL(h) (((h)&HDR_COPYRIGHT) >> 3)
/* 00000000 00000000 00000000 00000100 */
#define HDR_ORIGINAL 0x00000004
#define HDR_ORIGINAL_VAL(h) (((h)&HDR_ORIGINAL) >> 2)
/* 00000000 00000000 00000000 00000011 */
#define HDR_EMPHASIS 0x00000003
#define HDR_EMPHASIS_VAL(h) (((h)&HDR_EMPHASIS) >> 0)
/*
A generic mask for telling if a header is somewhat valid for the current stream.
Meaning: Most basic info is not allowed to change.
Checking of channel count needs to be done, too, though. So,
if channel count matches, frames are decoded the same way: frame buffers and decoding
routines can stay the same, especially frame buffers (think spf * channels!).
*/
#define HDR_CMPMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_SAMPLERATE)
/* A stricter mask, for matching free format headers. */
#define HDR_SAMEMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_BITRATE|HDR_SAMPLERATE|HDR_CHANNEL)
/* Free format headers have zero bitrate value. */
#define HDR_FREE_FORMAT(head) (!(head & HDR_BITRATE))
/* A mask for changed sampling rate (version or rate bits). */
#define HDR_SAMPMASK (HDR_VERSION|HDR_SAMPLERATE)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,342 @@
/*
mpg123lib_intern: Common non-public stuff for libmpg123
copyright 1995-2021 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
derived from the old mpg123.h
*/
#ifndef MPG123_H_INTERN
#define MPG123_H_INTERN
#define MPG123_RATES 9
#define MPG123_ENCODINGS 12
#include "config.h" /* Load this before _anything_ */
#include "intsym.h" /* Prefixing of internal symbols that still are public in a static lib. */
#include "abi_align.h"
/* export DLL symbols */
#if defined(WIN32) && defined(DYNAMIC_BUILD)
#define BUILD_MPG123_DLL
#endif
#include "compat.h"
#define MPG123_ENUM_API
#include "mpg123.h"
#define SKIP_JUNK 1
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
#ifndef M_SQRT2
# define M_SQRT2 1.41421356237309504880
#endif
#ifdef SUNOS
#define memmove(dst,src,size) bcopy(src,dst,size)
#endif
// The real type is either 32 bit float or integer. We do not attempt
// double precision for MPEG audio decoding (or any audio storage/compression
// format, even).
// The calctables tool works in double precision float, but converts to fixed
// point 'real' on output in addition to floating point.
// The base type used in the computation code.
// With C11 we could rely on tgmath for sin() to use the right precision.
#ifdef CALCTABLES
# define clreal double
# define COS cos
# define SIN sin
# define TAN tan
# define POW pow
#else
# define clreal float
# define COS cosf
# define SIN sinf
# define TAN tanf
# define POW powf
#endif
#if defined(REAL_IS_FLOAT) && !defined(CALCTABLES)
#define real float
#elif defined(REAL_IS_FIXED) || defined(CALCTABLES)
#ifdef RUNTIME_TABLES
#error "Runtime tables are only for floating point decoders."
#endif
# define real int32_t
# define dreal int64_t
/*
for fixed-point decoders, use pre-calculated tables to avoid expensive floating-point maths
undef this macro for run-time calculation
*/
# define REAL_RADIX 24
# define REAL_FACTOR 16777216.0
static inline int32_t double_to_long_rounded(double x, double scalefac)
{
x *= scalefac;
x += (x > 0) ? 0.5 : -0.5;
return (int32_t)x;
}
static inline int32_t scale_rounded(int32_t x, int shift)
{
x += (x >> 31);
x >>= (shift - 1);
x += (x & 1);
return (x >> 1);
}
# ifdef __GNUC__
# if defined(OPT_I386)
/* for i386_nofpu decoder */
# define REAL_MUL_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y); \
__asm__ ( \
"imull %1 \n\t" \
"shrdl %2, %%edx, %0 \n\t" \
: "+&a" (_x) \
: "mr" (_y), "I" (radix) \
: "%edx", "cc" \
); \
_x; \
})
# define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y), _radix=(radix); \
__asm__ ( \
"imull %1 \n\t" \
"shrdl %%cl, %%edx, %0 \n\t" \
: "+&a" (_x) \
: "mr" (_y), "c" (_radix) \
: "%edx", "cc" \
); \
_x; \
})
# elif defined(OPT_PPC)
/* for powerpc */
# define REAL_MUL_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y), _mull, _mulh; \
__asm__ ( \
"mullw %0, %2, %3 \n\t" \
"mulhw %1, %2, %3 \n\t" \
"srwi %0, %0, %4 \n\t" \
"rlwimi %0, %1, %5, 0, %6 \n\t" \
: "=&r" (_mull), "=&r" (_mulh) \
: "r" (_x), "r" (_y), "i" (radix), "i" (32-(radix)), "i" ((radix)-1) \
); \
_mull; \
})
# define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
__asm__ ( \
"mullw %0, %3, %4 \n\t" \
"mulhw %1, %3, %4 \n\t" \
"subfic %2, %5, 32 \n\t" \
"srw %0, %0, %5 \n\t" \
"slw %1, %1, %2 \n\t" \
"or %0, %0, %1 \n\t" \
: "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
: "r" (_x), "r" (_y), "r" (_radix) \
: "cc" \
); \
_mull; \
})
# elif defined(OPT_ARM)
/* for arm */
# define REAL_MUL_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y), _mull, _mulh; \
__asm__ ( \
"smull %0, %1, %2, %3 \n\t" \
"mov %0, %0, lsr %4 \n\t" \
"orr %0, %0, %1, lsl %5 \n\t" \
: "=&r" (_mull), "=&r" (_mulh) \
: "r" (_x), "r" (_y), "M" (radix), "M" (32-(radix)) \
); \
_mull; \
})
# define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
({ \
long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
__asm__ ( \
"smull %0, %1, %3, %4 \n\t" \
"mov %0, %0, lsr %5 \n\t" \
"rsb %2, %5, #32 \n\t" \
"mov %1, %1, lsl %2 \n\t" \
"orr %0, %0, %1 \n\t" \
: "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
: "r" (_x), "r" (_y), "r" (_radix) \
); \
_mull; \
})
# endif
# endif
/* I just changed the (int) to (real) there... seemed right. */
# define DOUBLE_TO_REAL(x) (double_to_long_rounded(x, REAL_FACTOR))
# define SCALE_15 32768.0
# define DOUBLE_TO_REAL_15(x) (double_to_long_rounded(x, SCALE_15))
# define SCALE_POW43 8192.0
# define DOUBLE_TO_REAL_POW43(x) (double_to_long_rounded(x, SCALE_POW43))
# define SCALE_LAYER12 1073741824.0
# define DOUBLE_TO_REAL_SCALE_LAYER12(x) (double_to_long_rounded(x, SCALE_LAYER12))
# define DOUBLE_TO_REAL_SCALE_LAYER3(x, y) (double_to_long_rounded(x, pow(2.0,gainpow2_scale[y])))
# define REAL_TO_DOUBLE(x) ((double)(x) / REAL_FACTOR)
# ifdef REAL_MUL_ASM
# define REAL_MUL(x, y) REAL_MUL_ASM(x, y, REAL_RADIX)
# define REAL_MUL_15(x, y) REAL_MUL_ASM(x, y, 15)
# define REAL_MUL_SCALE_LAYER12(x, y) REAL_MUL_ASM(x, y, 15 + 30 - REAL_RADIX)
# else
# define REAL_MUL(x, y) (((dreal)(x) * (dreal)(y)) >> REAL_RADIX)
# define REAL_MUL_15(x, y) (((dreal)(x) * (dreal)(y)) >> 15)
# define REAL_MUL_SCALE_LAYER12(x, y) (((dreal)(x) * (dreal)(y)) >> (15 + 30 - REAL_RADIX))
# endif
# ifdef REAL_MUL_SCALE_LAYER3_ASM
# define REAL_MUL_SCALE_LAYER3(x, y, z) REAL_MUL_SCALE_LAYER3_ASM(x, y, 13 + gainpow2_scale[z] - REAL_RADIX)
# else
# define REAL_MUL_SCALE_LAYER3(x, y, z) (((dreal)(x) * (dreal)(y)) >> (13 + gainpow2_scale[z] - REAL_RADIX))
# endif
# define REAL_SCALE_LAYER12(x) ((real)((x) >> (30 - REAL_RADIX)))
# define REAL_SCALE_LAYER3(x, y) ((real)((x) >> (gainpow2_scale[y] - REAL_RADIX)))
# ifdef ACCURATE_ROUNDING
# define REAL_MUL_SYNTH(x, y) REAL_MUL(x, y)
# define REAL_SCALE_DCT64(x) (x)
# define REAL_SCALE_WINDOW(x) (x)
# else
# define REAL_MUL_SYNTH(x, y) ((x) * (y))
# define REAL_SCALE_DCT64(x) ((x) >> 8)
# define REAL_SCALE_WINDOW(x) scale_rounded(x, 16)
# endif
#else
#error "Simple float or fixed-point, nothing else makes sense."
#endif
#ifndef REAL_IS_FIXED
# if (defined SIZEOF_INT32_T) && (SIZEOF_INT32_T != 4)
# error "Bad 32bit types!!!"
# endif
#endif
#ifndef DOUBLE_TO_REAL
# define DOUBLE_TO_REAL(x) (real)(x)
#endif
#ifndef DOUBLE_TO_REAL_15
# define DOUBLE_TO_REAL_15(x) (real)(x)
#endif
#ifndef DOUBLE_TO_REAL_POW43
# define DOUBLE_TO_REAL_POW43(x) (real)(x)
#endif
#ifndef DOUBLE_TO_REAL_SCALE_LAYER12
# define DOUBLE_TO_REAL_SCALE_LAYER12(x) (real)(x)
#endif
#ifndef DOUBLE_TO_REAL_SCALE_LAYER3
# define DOUBLE_TO_REAL_SCALE_LAYER3(x, y) (real)(x)
#endif
#ifndef REAL_TO_DOUBLE
# define REAL_TO_DOUBLE(x) (x)
#endif
#ifndef REAL_MUL
# define REAL_MUL(x, y) ((x) * (y))
#endif
#ifndef REAL_MUL_SYNTH
# define REAL_MUL_SYNTH(x, y) ((x) * (y))
#endif
#ifndef REAL_MUL_15
# define REAL_MUL_15(x, y) ((x) * (y))
#endif
#ifndef REAL_MUL_SCALE_LAYER12
# define REAL_MUL_SCALE_LAYER12(x, y) ((x) * (y))
#endif
#ifndef REAL_MUL_SCALE_LAYER3
# define REAL_MUL_SCALE_LAYER3(x, y, z) ((x) * (y))
#endif
#ifndef REAL_SCALE_LAYER12
# define REAL_SCALE_LAYER12(x) (x)
#endif
#ifndef REAL_SCALE_LAYER3
# define REAL_SCALE_LAYER3(x, y) (x)
#endif
#ifndef REAL_SCALE_DCT64
# define REAL_SCALE_DCT64(x) (x)
#endif
/* used to be: AUDIOBUFSIZE = n*64 with n=1,2,3 ...
now: factor on minimum frame buffer size (which takes upsampling into account) */
#define AUDIOBUFSIZE 2
#include "true.h"
#define MAX_NAME_SIZE 81
#define SBLIMIT 32
#define SCALE_BLOCK 12
#define SSLIMIT 18
/* Same as MPG_M_* */
#define MPG_MD_STEREO 0
#define MPG_MD_JOINT_STEREO 1
#define MPG_MD_DUAL_CHANNEL 2
#define MPG_MD_MONO 3
/* We support short or float output samples...
Short integer amplitude is scaled by this. */
#define SHORT_SCALE 32768
/* That scales a short-scaled value to a 32bit integer scaled one
value = 2**31/2**15 */
#define S32_RESCALE 65536
/* Pre Shift fo 16 to 8 bit converter table */
#define AUSHIFT (3)
#include "optimize.h"
#include "decode.h"
#include "parse.h"
#include "frame.h"
/* fr is a mpg123_handle* by convention here... */
#define NOQUIET (!(fr->p.flags & MPG123_QUIET))
#define VERBOSE (NOQUIET && fr->p.verbose)
#define VERBOSE2 (NOQUIET && fr->p.verbose > 1)
#define VERBOSE3 (NOQUIET && fr->p.verbose > 2)
#define VERBOSE4 (NOQUIET && fr->p.verbose > 3)
#define PVERB(mp, level) (!((mp)->flags & MPG123_QUIET) && (mp)->verbose >= (level))
int decode_update(mpg123_handle *mh);
/* residing in format.c */
off_t decoder_synth_bytes(mpg123_handle *fr , off_t s);
off_t samples_to_bytes(mpg123_handle *fr , off_t s);
off_t bytes_to_samples(mpg123_handle *fr , off_t b);
off_t outblock_bytes(mpg123_handle *fr, off_t s);
/* Postprocessing format conversion of freshly decoded buffer. */
void postprocess_buffer(mpg123_handle *fr);
int open_fixed_pre(mpg123_handle *mh, int channels, int encoding);
int open_fixed_post(mpg123_handle *mh, int channels, int encoding);
/* If networking is enabled and we really mean internal networking, the timeout_read function is available. */
#if defined (NETWORK) && !defined (WANT_WIN32_SOCKETS)
/* Does not work with win32 */
#define TIMEOUT_READ
#endif
#endif

View File

@ -0,0 +1,824 @@
/*
nwehuffman.h: optimized huffman tables (radix-4 lookup)
copyright 1995-2013 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Taihei Monma
*/
#ifndef _MPG123_NEWHUFFMAN_H_
#define _MPG123_NEWHUFFMAN_H_
struct newhuff
{
unsigned int linbits;
const short *table;
};
static const short tab0_[] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
static const short tab1_[] =
{
0x0311, 0x0311, 0x0301, 0x0301, 0x0210, 0x0210, 0x0210, 0x0210,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
};
static const short tab2_[] =
{
-16, -32, 0x0311, 0x0311, 0x0301, 0x0301, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
0x0222, 0x0222, 0x0222, 0x0222, 0x0202, 0x0202, 0x0202, 0x0202,
0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120,
};
static const short tab3_[] =
{
-16, -32, 0x0310, 0x0310, 0x0211, 0x0211, 0x0211, 0x0211,
0x0201, 0x0201, 0x0201, 0x0201, 0x0200, 0x0200, 0x0200, 0x0200,
0x0222, 0x0222, 0x0222, 0x0222, 0x0202, 0x0202, 0x0202, 0x0202,
0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120
};
static const short tab5_[] =
{
-16, -32, 0x0311, 0x0311, 0x0301, 0x0301, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
0x0433, 0x0423, 0x0332, 0x0332, 0x0231, 0x0231, 0x0231, 0x0231,
0x0313, 0x0313, 0x0303, 0x0303, 0x0330, 0x0330, 0x0322, 0x0322,
0x0212, 0x0212, 0x0212, 0x0212, 0x0221, 0x0221, 0x0221, 0x0221,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
};
static const short tab6_[] =
{
-16, -32, -48, 0x0412, 0x0421, 0x0420, 0x0301, 0x0301,
0x0211, 0x0211, 0x0211, 0x0211, 0x0310, 0x0310, 0x0300, 0x0300,
0x0333, 0x0333, 0x0303, 0x0303, 0x0223, 0x0223, 0x0223, 0x0223,
0x0232, 0x0232, 0x0232, 0x0232, 0x0230, 0x0230, 0x0230, 0x0230,
0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113,
0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131,
0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122,
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
};
static const short tab7_[] =
{
-16, -32, -48, 0x0411, 0x0301, 0x0301, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
-48, -64, -80, 0x0415, 0x0451, -96, 0x0450, -112,
0x0424, 0x0442, 0x0314, 0x0314, 0x0341, 0x0341, 0x0340, 0x0340,
0x0404, 0x0423, 0x0432, 0x0403, 0x0313, 0x0313, 0x0331, 0x0331,
0x0330, 0x0330, 0x0322, 0x0322, 0x0212, 0x0212, 0x0212, 0x0212,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
0x0255, 0x0255, 0x0255, 0x0255, 0x0245, 0x0245, 0x0245, 0x0245,
0x0254, 0x0254, 0x0254, 0x0254, 0x0253, 0x0253, 0x0253, 0x0253,
0x0135, 0x0135, 0x0135, 0x0135, 0x0135, 0x0135, 0x0135, 0x0135,
0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144,
0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125,
0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134,
0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
};
static const short tab8_[] =
{
-16, -32, 0x0412, 0x0421, 0x0211, 0x0211, 0x0211, 0x0211,
0x0301, 0x0301, 0x0310, 0x0310, 0x0200, 0x0200, 0x0200, 0x0200,
-32, -48, -64, 0x0415, 0x0451, -80, -96, 0x0424,
0x0442, 0x0414, 0x0341, 0x0341, 0x0404, 0x0440, 0x0423, 0x0432,
0x0413, 0x0431, 0x0403, 0x0430, 0x0222, 0x0222, 0x0222, 0x0222,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
0x0355, 0x0355, 0x0354, 0x0354, 0x0245, 0x0245, 0x0245, 0x0245,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153,
0x0235, 0x0235, 0x0235, 0x0235, 0x0244, 0x0244, 0x0244, 0x0244,
0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125,
0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134,
0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143,
0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
};
static const short tab9_[] =
{
-16, -32, -48, -64, -80, 0x0412, 0x0421, 0x0420,
0x0311, 0x0311, 0x0301, 0x0301, 0x0310, 0x0310, 0x0300, 0x0300,
-80, 0x0435, 0x0453, -96, 0x0444, 0x0425, 0x0452, 0x0415,
0x0351, 0x0351, 0x0334, 0x0334, 0x0343, 0x0343, 0x0450, 0x0404,
0x0324, 0x0324, 0x0342, 0x0342, 0x0333, 0x0333, 0x0340, 0x0340,
0x0214, 0x0214, 0x0214, 0x0214, 0x0241, 0x0241, 0x0241, 0x0241,
0x0223, 0x0223, 0x0223, 0x0223, 0x0232, 0x0232, 0x0232, 0x0232,
0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113,
0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131,
0x0203, 0x0203, 0x0203, 0x0203, 0x0230, 0x0230, 0x0230, 0x0230,
0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122,
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155,
0x0145, 0x0145, 0x0145, 0x0145, 0x0145, 0x0145, 0x0145, 0x0145,
0x0154, 0x0154, 0x0154, 0x0154, 0x0154, 0x0154, 0x0154, 0x0154,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
};
static const short tab10_[] =
{
-16, -32, -48, 0x0411, 0x0301, 0x0301, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
-48, -64, -80, -96, -112, -128, -144, 0x0417,
0x0471, -160, -176, -192, 0x0416, 0x0461, 0x0460, -208,
-208, -224, 0x0414, 0x0441, 0x0440, 0x0423, 0x0432, 0x0403,
0x0313, 0x0313, 0x0331, 0x0331, 0x0330, 0x0330, 0x0322, 0x0322,
0x0212, 0x0212, 0x0212, 0x0212, 0x0221, 0x0221, 0x0221, 0x0221,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
0x0377, 0x0377, 0x0367, 0x0367, 0x0376, 0x0376, 0x0357, 0x0357,
0x0375, 0x0375, 0x0366, 0x0366, 0x0247, 0x0247, 0x0247, 0x0247,
0x0274, 0x0274, 0x0274, 0x0274, 0x0256, 0x0256, 0x0256, 0x0256,
0x0265, 0x0265, 0x0265, 0x0265, 0x0237, 0x0237, 0x0237, 0x0237,
0x0273, 0x0273, 0x0273, 0x0273, 0x0246, 0x0246, 0x0246, 0x0246,
0x0355, 0x0355, 0x0354, 0x0354, 0x0263, 0x0263, 0x0263, 0x0263,
0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127,
0x0172, 0x0172, 0x0172, 0x0172, 0x0172, 0x0172, 0x0172, 0x0172,
0x0264, 0x0264, 0x0264, 0x0264, 0x0207, 0x0207, 0x0207, 0x0207,
0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170,
0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162,
0x0245, 0x0245, 0x0245, 0x0245, 0x0235, 0x0235, 0x0235, 0x0235,
0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106,
0x0253, 0x0253, 0x0253, 0x0253, 0x0244, 0x0244, 0x0244, 0x0244,
0x0136, 0x0136, 0x0136, 0x0136, 0x0136, 0x0136, 0x0136, 0x0136,
0x0126, 0x0126, 0x0126, 0x0126, 0x0126, 0x0126, 0x0126, 0x0126,
0x0225, 0x0225, 0x0225, 0x0225, 0x0252, 0x0252, 0x0252, 0x0252,
0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115,
0x0151, 0x0151, 0x0151, 0x0151, 0x0151, 0x0151, 0x0151, 0x0151,
0x0234, 0x0234, 0x0234, 0x0234, 0x0243, 0x0243, 0x0243, 0x0243,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150,
0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124,
0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104,
};
static const short tab11_[] =
{
-16, -32, -48, -64, 0x0412, -80, 0x0311, 0x0311,
0x0301, 0x0301, 0x0310, 0x0310, 0x0200, 0x0200, 0x0200, 0x0200,
-80, -96, -112, -128, -144, 0x0427, 0x0472, -160,
0x0371, 0x0371, 0x0417, 0x0470, 0x0436, 0x0463, 0x0460, -176,
-176, 0x0415, 0x0362, 0x0362, 0x0426, 0x0406, 0x0316, 0x0316,
0x0361, 0x0361, 0x0451, 0x0434, 0x0450, -192, 0x0424, 0x0442,
0x0414, 0x0441, 0x0404, 0x0440, 0x0323, 0x0323, 0x0332, 0x0332,
0x0213, 0x0213, 0x0213, 0x0213, 0x0231, 0x0231, 0x0231, 0x0231,
0x0303, 0x0303, 0x0330, 0x0330, 0x0222, 0x0222, 0x0222, 0x0222,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120,
0x0277, 0x0277, 0x0277, 0x0277, 0x0267, 0x0267, 0x0267, 0x0267,
0x0276, 0x0276, 0x0276, 0x0276, 0x0275, 0x0275, 0x0275, 0x0275,
0x0266, 0x0266, 0x0266, 0x0266, 0x0247, 0x0247, 0x0247, 0x0247,
0x0274, 0x0274, 0x0274, 0x0274, 0x0357, 0x0357, 0x0355, 0x0355,
0x0256, 0x0256, 0x0256, 0x0256, 0x0265, 0x0265, 0x0265, 0x0265,
0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137,
0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173,
0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146,
0x0245, 0x0245, 0x0245, 0x0245, 0x0254, 0x0254, 0x0254, 0x0254,
0x0235, 0x0235, 0x0235, 0x0235, 0x0253, 0x0253, 0x0253, 0x0253,
0x0164, 0x0164, 0x0164, 0x0164, 0x0164, 0x0164, 0x0164, 0x0164,
0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107,
0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144, 0x0144,
0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125,
0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
};
static const short tab12_[] =
{
-16, -32, -48, -64, -80, -96, 0x0412, 0x0421,
-112, 0x0400, 0x0311, 0x0311, 0x0301, 0x0301, 0x0310, 0x0310,
-112, -128, -144, -160, 0x0456, 0x0437, -176, 0x0427,
0x0472, 0x0446, 0x0464, 0x0417, 0x0471, -192, 0x0436, 0x0463,
0x0445, 0x0454, 0x0444, -192, 0x0326, 0x0326, 0x0362, 0x0362,
0x0361, 0x0361, 0x0416, 0x0460, 0x0435, 0x0453, 0x0425, 0x0452,
0x0315, 0x0315, 0x0351, 0x0351, 0x0334, 0x0334, 0x0343, 0x0343,
0x0450, 0x0404, 0x0324, 0x0324, 0x0342, 0x0342, 0x0314, 0x0314,
0x0233, 0x0233, 0x0233, 0x0233, 0x0241, 0x0241, 0x0241, 0x0241,
0x0223, 0x0223, 0x0223, 0x0223, 0x0232, 0x0232, 0x0232, 0x0232,
0x0340, 0x0340, 0x0303, 0x0303, 0x0230, 0x0230, 0x0230, 0x0230,
0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113, 0x0113,
0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131, 0x0131,
0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122,
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120,
0x0277, 0x0277, 0x0277, 0x0277, 0x0267, 0x0267, 0x0267, 0x0267,
0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176,
0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157,
0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175,
0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166,
0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147,
0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174,
0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165,
0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173,
0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155, 0x0155,
0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107,
0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170,
0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
};
static const short tab13_[] =
{
-16, -32, -48, -64, 0x0411, 0x0401, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
-64, -80, -96, -112, -128, -144, -160, -176,
-192, -208, -224, -240, -256, -272, -288, -304,
-304, -320, -336, -352, 0x0481, -368, -384, -400,
-416, -432, 0x0415, 0x0451, -448, -464, -480, 0x0414,
0x0341, 0x0341, 0x0404, 0x0440, 0x0423, 0x0432, 0x0313, 0x0313,
0x0331, 0x0331, 0x0303, 0x0303, 0x0330, 0x0330, 0x0322, 0x0322,
0x0212, 0x0212, 0x0212, 0x0212, 0x0221, 0x0221, 0x0221, 0x0221,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
-448, -464, -480, -496, -512, -528, -544, -560,
-576, -592, -608, -624, -640, -656, 0x041f, 0x04f1,
0x04f0, -656, -672, -688, 0x04e2, -704, 0x041e, 0x04e1,
-720, -736, -752, -768, -784, -800, 0x04c6, 0x043d,
-800, 0x042d, 0x04d2, 0x041d, 0x04b7, -816, -832, 0x04c3,
-848, 0x044b, 0x03d1, 0x03d1, 0x040d, 0x04d0, 0x048a, 0x04a8,
0x044c, 0x04c4, 0x046b, 0x04b6, 0x033c, 0x033c, 0x032c, 0x032c,
0x03c2, 0x03c2, 0x035b, 0x035b, 0x04b5, 0x0489, 0x031c, 0x031c,
0x03c1, 0x03c1, 0x0498, 0x040c, 0x03c0, 0x03c0, 0x04b4, 0x046a,
0x04a6, 0x0479, 0x033b, 0x033b, 0x03b3, 0x03b3, 0x0488, 0x045a,
0x032b, 0x032b, 0x04a5, 0x0469, 0x03a4, 0x03a4, 0x0478, 0x0487,
0x0394, 0x0394, 0x0477, 0x0476, 0x02b2, 0x02b2, 0x02b2, 0x02b2,
0x021b, 0x021b, 0x021b, 0x021b, 0x02b1, 0x02b1, 0x02b1, 0x02b1,
0x030b, 0x030b, 0x03b0, 0x03b0, 0x0396, 0x0396, 0x034a, 0x034a,
0x033a, 0x033a, 0x03a3, 0x03a3, 0x0359, 0x0359, 0x0395, 0x0395,
0x022a, 0x022a, 0x022a, 0x022a, 0x02a2, 0x02a2, 0x02a2, 0x02a2,
0x021a, 0x021a, 0x021a, 0x021a, 0x02a1, 0x02a1, 0x02a1, 0x02a1,
0x030a, 0x030a, 0x0368, 0x0368, 0x02a0, 0x02a0, 0x02a0, 0x02a0,
0x0386, 0x0386, 0x0349, 0x0349, 0x0293, 0x0293, 0x0293, 0x0293,
0x0339, 0x0339, 0x0358, 0x0358, 0x0385, 0x0385, 0x0367, 0x0367,
0x0229, 0x0229, 0x0229, 0x0229, 0x0292, 0x0292, 0x0292, 0x0292,
0x0357, 0x0357, 0x0375, 0x0375, 0x0238, 0x0238, 0x0238, 0x0238,
0x0283, 0x0283, 0x0283, 0x0283, 0x0366, 0x0366, 0x0347, 0x0347,
0x0374, 0x0374, 0x0356, 0x0356, 0x0365, 0x0365, 0x0373, 0x0373,
0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119,
0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191,
0x0209, 0x0209, 0x0209, 0x0209, 0x0290, 0x0290, 0x0290, 0x0290,
0x0248, 0x0248, 0x0248, 0x0248, 0x0284, 0x0284, 0x0284, 0x0284,
0x0272, 0x0272, 0x0272, 0x0272, 0x0346, 0x0346, 0x0364, 0x0364,
0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128,
0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182,
0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118,
0x0237, 0x0237, 0x0237, 0x0237, 0x0227, 0x0227, 0x0227, 0x0227,
0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117,
0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171,
0x0255, 0x0255, 0x0255, 0x0255, 0x0207, 0x0207, 0x0207, 0x0207,
0x0270, 0x0270, 0x0270, 0x0270, 0x0236, 0x0236, 0x0236, 0x0236,
0x0263, 0x0263, 0x0263, 0x0263, 0x0245, 0x0245, 0x0245, 0x0245,
0x0254, 0x0254, 0x0254, 0x0254, 0x0226, 0x0226, 0x0226, 0x0226,
0x0262, 0x0262, 0x0262, 0x0262, 0x0235, 0x0235, 0x0235, 0x0235,
0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108,
0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116,
0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161,
0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106,
0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160,
0x0253, 0x0253, 0x0253, 0x0253, 0x0244, 0x0244, 0x0244, 0x0244,
0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125,
0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134,
0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143,
0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150,
0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124,
0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
-448, 0x04ff, 0x04ef, 0x04df, 0x04ee, 0x04cf, 0x04de, 0x04bf,
0x04fb, 0x04ce, 0x04dc, -464, 0x03ec, 0x03ec, 0x03dd, 0x03dd,
0x04fa, 0x04cd, 0x03be, 0x03be, 0x03eb, 0x03eb, 0x039f, 0x039f,
0x03f9, 0x03f9, 0x03ea, 0x03ea, 0x03bd, 0x03bd, 0x03db, 0x03db,
0x038f, 0x038f, 0x03f8, 0x03f8, 0x03cc, 0x03cc, 0x04ae, 0x049e,
0x038e, 0x038e, 0x047f, 0x047e, 0x02f7, 0x02f7, 0x02f7, 0x02f7,
0x02da, 0x02da, 0x02da, 0x02da, 0x03ad, 0x03ad, 0x03bc, 0x03bc,
0x03cb, 0x03cb, 0x03f6, 0x03f6, 0x026f, 0x026f, 0x026f, 0x026f,
0x02e8, 0x02e8, 0x02e8, 0x02e8, 0x025f, 0x025f, 0x025f, 0x025f,
0x029d, 0x029d, 0x029d, 0x029d, 0x02d9, 0x02d9, 0x02d9, 0x02d9,
0x02f5, 0x02f5, 0x02f5, 0x02f5, 0x02e7, 0x02e7, 0x02e7, 0x02e7,
0x02ac, 0x02ac, 0x02ac, 0x02ac, 0x02bb, 0x02bb, 0x02bb, 0x02bb,
0x024f, 0x024f, 0x024f, 0x024f, 0x02f4, 0x02f4, 0x02f4, 0x02f4,
0x03ca, 0x03ca, 0x03e6, 0x03e6, 0x02f3, 0x02f3, 0x02f3, 0x02f3,
0x013f, 0x013f, 0x013f, 0x013f, 0x013f, 0x013f, 0x013f, 0x013f,
0x028d, 0x028d, 0x028d, 0x028d, 0x02d8, 0x02d8, 0x02d8, 0x02d8,
0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f,
0x01f2, 0x01f2, 0x01f2, 0x01f2, 0x01f2, 0x01f2, 0x01f2, 0x01f2,
0x026e, 0x026e, 0x026e, 0x026e, 0x029c, 0x029c, 0x029c, 0x029c,
0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f,
0x02c9, 0x02c9, 0x02c9, 0x02c9, 0x025e, 0x025e, 0x025e, 0x025e,
0x01ab, 0x01ab, 0x01ab, 0x01ab, 0x01ab, 0x01ab, 0x01ab, 0x01ab,
0x027d, 0x027d, 0x027d, 0x027d, 0x02d7, 0x02d7, 0x02d7, 0x02d7,
0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e,
0x02c8, 0x02c8, 0x02c8, 0x02c8, 0x02d6, 0x02d6, 0x02d6, 0x02d6,
0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e,
0x01b9, 0x01b9, 0x01b9, 0x01b9, 0x01b9, 0x01b9, 0x01b9, 0x01b9,
0x029b, 0x029b, 0x029b, 0x029b, 0x02aa, 0x02aa, 0x02aa, 0x02aa,
0x01ba, 0x01ba, 0x01ba, 0x01ba, 0x01ba, 0x01ba, 0x01ba, 0x01ba,
0x01e5, 0x01e5, 0x01e5, 0x01e5, 0x01e5, 0x01e5, 0x01e5, 0x01e5,
0x01e4, 0x01e4, 0x01e4, 0x01e4, 0x01e4, 0x01e4, 0x01e4, 0x01e4,
0x018c, 0x018c, 0x018c, 0x018c, 0x018c, 0x018c, 0x018c, 0x018c,
0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d,
0x01e3, 0x01e3, 0x01e3, 0x01e3, 0x01e3, 0x01e3, 0x01e3, 0x01e3,
0x012e, 0x012e, 0x012e, 0x012e, 0x012e, 0x012e, 0x012e, 0x012e,
0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e,
0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0,
0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d,
0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5,
0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c,
0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7,
0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d,
0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b,
0x01b8, 0x01b8, 0x01b8, 0x01b8, 0x01b8, 0x01b8, 0x01b8, 0x01b8,
0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4,
0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a,
0x01a9, 0x01a9, 0x01a9, 0x01a9, 0x01a9, 0x01a9, 0x01a9, 0x01a9,
0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c,
0x01d3, 0x01d3, 0x01d3, 0x01d3, 0x01d3, 0x01d3, 0x01d3, 0x01d3,
0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b,
0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c,
0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5,
0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199,
0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a,
0x01a7, 0x01a7, 0x01a7, 0x01a7, 0x01a7, 0x01a7, 0x01a7, 0x01a7,
0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197,
0x03fe, 0x03fe, 0x03fc, 0x03fc, 0x02fd, 0x02fd, 0x02fd, 0x02fd,
0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed,
0x01af, 0x01af, 0x01af, 0x01af, 0x01af, 0x01af, 0x01af, 0x01af,
0x01e9, 0x01e9, 0x01e9, 0x01e9, 0x01e9, 0x01e9, 0x01e9, 0x01e9,
};
static const short tab15_[] =
{
-16, -32, -48, -64, -80, -96, -112, -128,
-144, -160, 0x0311, 0x0311, 0x0401, 0x0410, 0x0300, 0x0300,
-160, -176, -192, -208, -224, -240, -256, -272,
-288, -304, -320, -336, -352, -368, -384, -400,
-400, -416, -432, -448, -464, -480, -496, -512,
-528, -544, -560, -576, -592, -608, -624, -640,
-640, -656, 0x0491, -672, -688, -704, -720, -736,
0x0428, 0x0482, 0x0418, 0x0481, -752, -768, -784, -800,
0x0427, 0x0472, 0x0464, 0x0417, 0x0455, 0x0471, -800, 0x0436,
0x0463, 0x0445, 0x0454, 0x0426, 0x0462, 0x0416, -816, 0x0435,
0x0361, 0x0361, 0x0453, 0x0444, 0x0325, 0x0325, 0x0352, 0x0352,
0x0315, 0x0315, 0x0351, 0x0351, 0x0405, 0x0450, 0x0334, 0x0334,
0x0343, 0x0343, 0x0324, 0x0324, 0x0342, 0x0342, 0x0333, 0x0333,
0x0241, 0x0241, 0x0241, 0x0241, 0x0314, 0x0314, 0x0304, 0x0304,
0x0223, 0x0223, 0x0223, 0x0223, 0x0232, 0x0232, 0x0232, 0x0232,
0x0340, 0x0340, 0x0303, 0x0303, 0x0213, 0x0213, 0x0213, 0x0213,
0x0231, 0x0231, 0x0231, 0x0231, 0x0230, 0x0230, 0x0230, 0x0230,
0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122, 0x0122,
0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120, 0x0120,
-720, -736, 0x04ee, -752, -768, -784, 0x04fb, -800,
0x04dd, 0x04af, 0x04fa, 0x04be, 0x04eb, 0x04cd, 0x04dc, 0x049f,
0x04f9, 0x04ea, 0x04bd, 0x04db, 0x048f, 0x04f8, 0x04cc, 0x049e,
0x04e9, 0x047f, 0x04f7, 0x04ad, 0x04da, 0x04bc, 0x046f, -800,
0x03cb, 0x03cb, 0x03f6, 0x03f6, 0x048e, 0x04e8, 0x045f, 0x049d,
0x03f5, 0x03f5, 0x037e, 0x037e, 0x03e7, 0x03e7, 0x03ac, 0x03ac,
0x03ca, 0x03ca, 0x03bb, 0x03bb, 0x04d9, 0x048d, 0x034f, 0x034f,
0x03f4, 0x03f4, 0x033f, 0x033f, 0x03f3, 0x03f3, 0x03d8, 0x03d8,
0x03e6, 0x03e6, 0x032f, 0x032f, 0x03f2, 0x03f2, 0x046e, 0x04f0,
0x031f, 0x031f, 0x03f1, 0x03f1, 0x039c, 0x039c, 0x03c9, 0x03c9,
0x035e, 0x035e, 0x03ab, 0x03ab, 0x03ba, 0x03ba, 0x03e5, 0x03e5,
0x037d, 0x037d, 0x03d7, 0x03d7, 0x034e, 0x034e, 0x03e4, 0x03e4,
0x038c, 0x038c, 0x03c8, 0x03c8, 0x033e, 0x033e, 0x036d, 0x036d,
0x03d6, 0x03d6, 0x03e3, 0x03e3, 0x039b, 0x039b, 0x03b9, 0x03b9,
0x032e, 0x032e, 0x03aa, 0x03aa, 0x03e2, 0x03e2, 0x031e, 0x031e,
0x03e1, 0x03e1, 0x040e, 0x04e0, 0x035d, 0x035d, 0x03d5, 0x03d5,
0x037c, 0x037c, 0x03c7, 0x03c7, 0x034d, 0x034d, 0x038b, 0x038b,
0x02d4, 0x02d4, 0x02d4, 0x02d4, 0x03b8, 0x03b8, 0x039a, 0x039a,
0x03a9, 0x03a9, 0x036c, 0x036c, 0x03c6, 0x03c6, 0x033d, 0x033d,
0x02d3, 0x02d3, 0x02d3, 0x02d3, 0x02d2, 0x02d2, 0x02d2, 0x02d2,
0x032d, 0x032d, 0x030d, 0x030d, 0x021d, 0x021d, 0x021d, 0x021d,
0x027b, 0x027b, 0x027b, 0x027b, 0x02b7, 0x02b7, 0x02b7, 0x02b7,
0x02d1, 0x02d1, 0x02d1, 0x02d1, 0x035c, 0x035c, 0x03d0, 0x03d0,
0x02c5, 0x02c5, 0x02c5, 0x02c5, 0x028a, 0x028a, 0x028a, 0x028a,
0x02a8, 0x02a8, 0x02a8, 0x02a8, 0x024c, 0x024c, 0x024c, 0x024c,
0x02c4, 0x02c4, 0x02c4, 0x02c4, 0x026b, 0x026b, 0x026b, 0x026b,
0x02b6, 0x02b6, 0x02b6, 0x02b6, 0x0399, 0x0399, 0x030c, 0x030c,
0x023c, 0x023c, 0x023c, 0x023c, 0x02c3, 0x02c3, 0x02c3, 0x02c3,
0x027a, 0x027a, 0x027a, 0x027a, 0x02a7, 0x02a7, 0x02a7, 0x02a7,
0x02a6, 0x02a6, 0x02a6, 0x02a6, 0x03c0, 0x03c0, 0x030b, 0x030b,
0x01c2, 0x01c2, 0x01c2, 0x01c2, 0x01c2, 0x01c2, 0x01c2, 0x01c2,
0x022c, 0x022c, 0x022c, 0x022c, 0x025b, 0x025b, 0x025b, 0x025b,
0x02b5, 0x02b5, 0x02b5, 0x02b5, 0x021c, 0x021c, 0x021c, 0x021c,
0x0289, 0x0289, 0x0289, 0x0289, 0x0298, 0x0298, 0x0298, 0x0298,
0x02c1, 0x02c1, 0x02c1, 0x02c1, 0x024b, 0x024b, 0x024b, 0x024b,
0x02b4, 0x02b4, 0x02b4, 0x02b4, 0x026a, 0x026a, 0x026a, 0x026a,
0x023b, 0x023b, 0x023b, 0x023b, 0x0279, 0x0279, 0x0279, 0x0279,
0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3,
0x0297, 0x0297, 0x0297, 0x0297, 0x0288, 0x0288, 0x0288, 0x0288,
0x022b, 0x022b, 0x022b, 0x022b, 0x025a, 0x025a, 0x025a, 0x025a,
0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2,
0x02a5, 0x02a5, 0x02a5, 0x02a5, 0x021b, 0x021b, 0x021b, 0x021b,
0x01b1, 0x01b1, 0x01b1, 0x01b1, 0x01b1, 0x01b1, 0x01b1, 0x01b1,
0x02b0, 0x02b0, 0x02b0, 0x02b0, 0x0269, 0x0269, 0x0269, 0x0269,
0x0296, 0x0296, 0x0296, 0x0296, 0x024a, 0x024a, 0x024a, 0x024a,
0x02a4, 0x02a4, 0x02a4, 0x02a4, 0x0278, 0x0278, 0x0278, 0x0278,
0x0287, 0x0287, 0x0287, 0x0287, 0x023a, 0x023a, 0x023a, 0x023a,
0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3,
0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159,
0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195,
0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a,
0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2,
0x011a, 0x011a, 0x011a, 0x011a, 0x011a, 0x011a, 0x011a, 0x011a,
0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1,
0x020a, 0x020a, 0x020a, 0x020a, 0x02a0, 0x02a0, 0x02a0, 0x02a0,
0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168,
0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186,
0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149,
0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194,
0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139,
0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193,
0x0277, 0x0277, 0x0277, 0x0277, 0x0209, 0x0209, 0x0209, 0x0209,
0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158,
0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185,
0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129,
0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167,
0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176,
0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192,
0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119,
0x0190, 0x0190, 0x0190, 0x0190, 0x0190, 0x0190, 0x0190, 0x0190,
0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148,
0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184,
0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157,
0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175,
0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138,
0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183,
0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166,
0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147,
0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174,
0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108,
0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156,
0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165,
0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137,
0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173, 0x0173,
0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146, 0x0146,
0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107, 0x0107,
0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170, 0x0170,
0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106,
0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160,
0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
0x01ef, 0x01ef, 0x01ef, 0x01ef, 0x01ef, 0x01ef, 0x01ef, 0x01ef,
0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe,
0x01df, 0x01df, 0x01df, 0x01df, 0x01df, 0x01df, 0x01df, 0x01df,
0x01fd, 0x01fd, 0x01fd, 0x01fd, 0x01fd, 0x01fd, 0x01fd, 0x01fd,
0x01cf, 0x01cf, 0x01cf, 0x01cf, 0x01cf, 0x01cf, 0x01cf, 0x01cf,
0x01fc, 0x01fc, 0x01fc, 0x01fc, 0x01fc, 0x01fc, 0x01fc, 0x01fc,
0x01de, 0x01de, 0x01de, 0x01de, 0x01de, 0x01de, 0x01de, 0x01de,
0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed, 0x01ed,
0x01bf, 0x01bf, 0x01bf, 0x01bf, 0x01bf, 0x01bf, 0x01bf, 0x01bf,
0x01ce, 0x01ce, 0x01ce, 0x01ce, 0x01ce, 0x01ce, 0x01ce, 0x01ce,
0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec,
0x01ae, 0x01ae, 0x01ae, 0x01ae, 0x01ae, 0x01ae, 0x01ae, 0x01ae,
0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f,
};
static const short tab16_[] =
{
-16, -32, -48, -64, 0x0411, 0x0401, 0x0310, 0x0310,
0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
-64, -80, -96, 0x04ff, -112, -128, -144, 0x04f2,
-160, 0x041f, 0x04f1, -176, -192, -208, -224, -240,
-240, -256, -272, -288, -304, -320, -336, -352,
-368, -384, -400, -416, -432, -448, 0x0451, -464,
-464, -480, -496, 0x0414, 0x0441, -512, 0x0423, 0x0432,
0x0313, 0x0313, 0x0331, 0x0331, 0x0403, 0x0430, 0x0322, 0x0322,
0x0212, 0x0212, 0x0212, 0x0212, 0x0221, 0x0221, 0x0221, 0x0221,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
0x03ef, 0x03ef, 0x03fe, 0x03fe, 0x03df, 0x03df, 0x03fd, 0x03fd,
0x03cf, 0x03cf, 0x03fc, 0x03fc, 0x03bf, 0x03bf, 0x03fb, 0x03fb,
0x02af, 0x02af, 0x02af, 0x02af, 0x03fa, 0x03fa, 0x039f, 0x039f,
0x03f9, 0x03f9, 0x03f8, 0x03f8, 0x028f, 0x028f, 0x028f, 0x028f,
0x027f, 0x027f, 0x027f, 0x027f, 0x02f7, 0x02f7, 0x02f7, 0x02f7,
0x026f, 0x026f, 0x026f, 0x026f, 0x02f6, 0x02f6, 0x02f6, 0x02f6,
0x025f, 0x025f, 0x025f, 0x025f, 0x02f5, 0x02f5, 0x02f5, 0x02f5,
0x014f, 0x014f, 0x014f, 0x014f, 0x014f, 0x014f, 0x014f, 0x014f,
0x01f4, 0x01f4, 0x01f4, 0x01f4, 0x01f4, 0x01f4, 0x01f4, 0x01f4,
0x01f3, 0x01f3, 0x01f3, 0x01f3, 0x01f3, 0x01f3, 0x01f3, 0x01f3,
0x01f0, 0x01f0, 0x01f0, 0x01f0, 0x01f0, 0x01f0, 0x01f0, 0x01f0,
0x023f, 0x023f, 0x023f, 0x023f, -416, -432, -448, -464,
0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f, 0x012f,
0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f,
-448, -464, -480, -496, -512, -528, -544, -560,
-576, -592, -608, 0x04e3, -624, -640, -656, -672,
-672, -688, -704, 0x040d, -720, -736, -752, 0x043c,
-768, 0x041c, 0x04c0, -784, 0x03e2, 0x03e2, 0x042e, 0x041e,
0x04d3, 0x042d, 0x04d2, 0x04d1, 0x043b, -784, 0x031d, 0x031d,
0x04c4, 0x046b, 0x04c3, 0x04a7, 0x032c, 0x032c, 0x04c2, 0x04b5,
0x04c1, 0x040c, 0x044b, 0x04b4, 0x046a, 0x04a6, 0x03b3, 0x03b3,
0x045a, 0x04a5, 0x032b, 0x032b, 0x03b2, 0x03b2, 0x031b, 0x031b,
0x03b1, 0x03b1, 0x040b, 0x04b0, 0x0469, 0x0496, 0x044a, 0x04a4,
0x0478, 0x0487, 0x03a3, 0x03a3, 0x043a, 0x0459, 0x032a, 0x032a,
0x0495, 0x0468, 0x03a1, 0x03a1, 0x0486, 0x0477, 0x0394, 0x0394,
0x0449, 0x0457, 0x0367, 0x0367, 0x02a2, 0x02a2, 0x02a2, 0x02a2,
0x021a, 0x021a, 0x021a, 0x021a, 0x030a, 0x030a, 0x03a0, 0x03a0,
0x0339, 0x0339, 0x0393, 0x0393, 0x0358, 0x0358, 0x0385, 0x0385,
0x0229, 0x0229, 0x0229, 0x0229, 0x0292, 0x0292, 0x0292, 0x0292,
0x0376, 0x0376, 0x0309, 0x0309, 0x0219, 0x0219, 0x0219, 0x0219,
0x0291, 0x0291, 0x0291, 0x0291, 0x0390, 0x0390, 0x0348, 0x0348,
0x0384, 0x0384, 0x0375, 0x0375, 0x0338, 0x0338, 0x0383, 0x0383,
0x0366, 0x0366, 0x0328, 0x0328, 0x0282, 0x0282, 0x0282, 0x0282,
0x0347, 0x0347, 0x0374, 0x0374, 0x0218, 0x0218, 0x0218, 0x0218,
0x0281, 0x0281, 0x0281, 0x0281, 0x0280, 0x0280, 0x0280, 0x0280,
0x0308, 0x0308, 0x0356, 0x0356, 0x0237, 0x0237, 0x0237, 0x0237,
0x0273, 0x0273, 0x0273, 0x0273, 0x0365, 0x0365, 0x0346, 0x0346,
0x0227, 0x0227, 0x0227, 0x0227, 0x0272, 0x0272, 0x0272, 0x0272,
0x0364, 0x0364, 0x0355, 0x0355, 0x0207, 0x0207, 0x0207, 0x0207,
0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117,
0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171, 0x0171,
0x0270, 0x0270, 0x0270, 0x0270, 0x0236, 0x0236, 0x0236, 0x0236,
0x0263, 0x0263, 0x0263, 0x0263, 0x0245, 0x0245, 0x0245, 0x0245,
0x0254, 0x0254, 0x0254, 0x0254, 0x0226, 0x0226, 0x0226, 0x0226,
0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162, 0x0162,
0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116, 0x0116,
0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161, 0x0161,
0x0206, 0x0206, 0x0206, 0x0206, 0x0260, 0x0260, 0x0260, 0x0260,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153,
0x0235, 0x0235, 0x0235, 0x0235, 0x0244, 0x0244, 0x0244, 0x0244,
0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125, 0x0125,
0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152, 0x0152,
0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115, 0x0115,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134, 0x0134,
0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143, 0x0143,
0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150,
0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124, 0x0124,
0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142, 0x0142,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104,
0x0140, 0x0140, 0x0140, 0x0140, 0x0140, 0x0140, 0x0140, 0x0140,
0x04ce, -448, 0x03de, 0x03de, 0x03e9, 0x03e9, 0x04ea, 0x04d9,
0x02ee, 0x02ee, 0x02ee, 0x02ee, 0x03ed, 0x03ed, 0x03eb, 0x03eb,
0x02be, 0x02be, 0x02be, 0x02be, 0x02cd, 0x02cd, 0x02cd, 0x02cd,
0x03dc, 0x03dc, 0x03db, 0x03db, 0x02ae, 0x02ae, 0x02ae, 0x02ae,
0x02cc, 0x02cc, 0x02cc, 0x02cc, 0x03ad, 0x03ad, 0x03da, 0x03da,
0x037e, 0x037e, 0x03ac, 0x03ac, 0x02ca, 0x02ca, 0x02ca, 0x02ca,
0x03c9, 0x03c9, 0x037d, 0x037d, 0x025e, 0x025e, 0x025e, 0x025e,
0x01bd, 0x01bd, 0x01bd, 0x01bd, 0x01bd, 0x01bd, 0x01bd, 0x01bd,
0x019e, 0x019e, 0x019e, 0x019e, 0x019e, 0x019e, 0x019e, 0x019e,
0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02cb, 0x02cb, 0x02cb, 0x02cb,
0x028e, 0x028e, 0x028e, 0x028e, 0x02e8, 0x02e8, 0x02e8, 0x02e8,
0x029d, 0x029d, 0x029d, 0x029d, 0x02e7, 0x02e7, 0x02e7, 0x02e7,
0x02bb, 0x02bb, 0x02bb, 0x02bb, 0x028d, 0x028d, 0x028d, 0x028d,
0x02d8, 0x02d8, 0x02d8, 0x02d8, 0x026e, 0x026e, 0x026e, 0x026e,
0x01e6, 0x01e6, 0x01e6, 0x01e6, 0x01e6, 0x01e6, 0x01e6, 0x01e6,
0x019c, 0x019c, 0x019c, 0x019c, 0x019c, 0x019c, 0x019c, 0x019c,
0x02ab, 0x02ab, 0x02ab, 0x02ab, 0x02ba, 0x02ba, 0x02ba, 0x02ba,
0x02e5, 0x02e5, 0x02e5, 0x02e5, 0x02d7, 0x02d7, 0x02d7, 0x02d7,
0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e, 0x014e,
0x02e4, 0x02e4, 0x02e4, 0x02e4, 0x028c, 0x028c, 0x028c, 0x028c,
0x01c8, 0x01c8, 0x01c8, 0x01c8, 0x01c8, 0x01c8, 0x01c8, 0x01c8,
0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e, 0x013e,
0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d, 0x016d,
0x02d6, 0x02d6, 0x02d6, 0x02d6, 0x029b, 0x029b, 0x029b, 0x029b,
0x02b9, 0x02b9, 0x02b9, 0x02b9, 0x02aa, 0x02aa, 0x02aa, 0x02aa,
0x01e1, 0x01e1, 0x01e1, 0x01e1, 0x01e1, 0x01e1, 0x01e1, 0x01e1,
0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4, 0x01d4,
0x02b8, 0x02b8, 0x02b8, 0x02b8, 0x02a9, 0x02a9, 0x02a9, 0x02a9,
0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b, 0x017b,
0x02b7, 0x02b7, 0x02b7, 0x02b7, 0x02d0, 0x02d0, 0x02d0, 0x02d0,
0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e, 0x010e,
0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0, 0x01e0,
0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d, 0x015d,
0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5, 0x01d5,
0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c, 0x017c,
0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7, 0x01c7,
0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d, 0x014d,
0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b, 0x018b,
0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a, 0x019a,
0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c, 0x016c,
0x01c6, 0x01c6, 0x01c6, 0x01c6, 0x01c6, 0x01c6, 0x01c6, 0x01c6,
0x013d, 0x013d, 0x013d, 0x013d, 0x013d, 0x013d, 0x013d, 0x013d,
0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c, 0x015c,
0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5, 0x01c5,
0x018a, 0x018a, 0x018a, 0x018a, 0x018a, 0x018a, 0x018a, 0x018a,
0x01a8, 0x01a8, 0x01a8, 0x01a8, 0x01a8, 0x01a8, 0x01a8, 0x01a8,
0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199, 0x0199,
0x014c, 0x014c, 0x014c, 0x014c, 0x014c, 0x014c, 0x014c, 0x014c,
0x01b6, 0x01b6, 0x01b6, 0x01b6, 0x01b6, 0x01b6, 0x01b6, 0x01b6,
0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a, 0x017a,
0x015b, 0x015b, 0x015b, 0x015b, 0x015b, 0x015b, 0x015b, 0x015b,
0x0189, 0x0189, 0x0189, 0x0189, 0x0189, 0x0189, 0x0189, 0x0189,
0x0198, 0x0198, 0x0198, 0x0198, 0x0198, 0x0198, 0x0198, 0x0198,
0x0179, 0x0179, 0x0179, 0x0179, 0x0179, 0x0179, 0x0179, 0x0179,
0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197, 0x0197,
0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188,
0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec, 0x01ec,
0x01dd, 0x01dd, 0x01dd, 0x01dd, 0x01dd, 0x01dd, 0x01dd, 0x01dd,
};
static const short tab24_[] =
{
-16, -32, -48, 0x04ff, -64, -80, -96, -112,
-128, -144, -160, -176, 0x0411, 0x0401, 0x0410, 0x0400,
0x04ef, 0x04fe, 0x04df, 0x04fd, 0x04cf, 0x04fc, 0x04bf, 0x04fb,
0x03fa, 0x03fa, 0x04af, 0x049f, 0x03f9, 0x03f9, 0x03f8, 0x03f8,
0x048f, 0x047f, 0x03f7, 0x03f7, 0x036f, 0x036f, 0x03f6, 0x03f6,
0x035f, 0x035f, 0x03f5, 0x03f5, 0x034f, 0x034f, 0x03f4, 0x03f4,
0x033f, 0x033f, 0x03f3, 0x03f3, 0x032f, 0x032f, 0x03f2, 0x03f2,
0x03f1, 0x03f1, 0x041f, 0x04f0, -144, -160, -176, -192,
-192, -208, -224, -240, -256, -272, -288, -304,
-320, -336, -352, -368, -384, -400, -416, -432,
-432, -448, -464, -480, -496, -512, -528, -544,
-560, -576, -592, -608, -624, -640, -656, -672,
-672, -688, -704, -720, -736, -752, -768, -784,
-800, -816, -832, -848, -864, 0x0473, -880, 0x0472,
0x0446, 0x0464, 0x0455, 0x0471, 0x0436, 0x0463, 0x0445, 0x0454,
0x0426, 0x0462, 0x0416, 0x0461, -880, 0x0435, 0x0453, 0x0444,
0x0425, 0x0452, 0x0415, -880, 0x0351, 0x0351, 0x0434, 0x0443,
0x0324, 0x0324, 0x0342, 0x0342, 0x0333, 0x0333, 0x0314, 0x0314,
0x0341, 0x0341, 0x0404, 0x0440, 0x0323, 0x0323, 0x0332, 0x0332,
0x0213, 0x0213, 0x0213, 0x0213, 0x0231, 0x0231, 0x0231, 0x0231,
0x0303, 0x0303, 0x0330, 0x0330, 0x0222, 0x0222, 0x0222, 0x0222,
0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112, 0x0112,
0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121, 0x0121,
0x0202, 0x0202, 0x0202, 0x0202, 0x0220, 0x0220, 0x0220, 0x0220,
0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f, 0x010f,
0x03ee, 0x03ee, 0x03de, 0x03de, 0x03ed, 0x03ed, 0x03ce, 0x03ce,
0x03ec, 0x03ec, 0x03dd, 0x03dd, 0x03be, 0x03be, 0x03eb, 0x03eb,
0x03cd, 0x03cd, 0x03dc, 0x03dc, 0x03ae, 0x03ae, 0x03ea, 0x03ea,
0x03bd, 0x03bd, 0x03db, 0x03db, 0x03cc, 0x03cc, 0x039e, 0x039e,
0x03e9, 0x03e9, 0x03ad, 0x03ad, 0x03da, 0x03da, 0x03bc, 0x03bc,
0x03cb, 0x03cb, 0x038e, 0x038e, 0x03e8, 0x03e8, 0x039d, 0x039d,
0x03d9, 0x03d9, 0x037e, 0x037e, 0x03e7, 0x03e7, 0x03ac, 0x03ac,
0x03ca, 0x03ca, 0x03bb, 0x03bb, 0x038d, 0x038d, 0x03d8, 0x03d8,
0x040e, 0x04e0, 0x030d, 0x030d, 0x02e6, 0x02e6, 0x02e6, 0x02e6,
0x036e, 0x036e, 0x039c, 0x039c, 0x02c9, 0x02c9, 0x02c9, 0x02c9,
0x025e, 0x025e, 0x025e, 0x025e, 0x02ba, 0x02ba, 0x02ba, 0x02ba,
0x02e5, 0x02e5, 0x02e5, 0x02e5, 0x03ab, 0x03ab, 0x037d, 0x037d,
0x02d7, 0x02d7, 0x02d7, 0x02d7, 0x02e4, 0x02e4, 0x02e4, 0x02e4,
0x028c, 0x028c, 0x028c, 0x028c, 0x02c8, 0x02c8, 0x02c8, 0x02c8,
0x034e, 0x034e, 0x032e, 0x032e, 0x023e, 0x023e, 0x023e, 0x023e,
0x026d, 0x026d, 0x026d, 0x026d, 0x02d6, 0x02d6, 0x02d6, 0x02d6,
0x02e3, 0x02e3, 0x02e3, 0x02e3, 0x029b, 0x029b, 0x029b, 0x029b,
0x02b9, 0x02b9, 0x02b9, 0x02b9, 0x02aa, 0x02aa, 0x02aa, 0x02aa,
0x02e2, 0x02e2, 0x02e2, 0x02e2, 0x021e, 0x021e, 0x021e, 0x021e,
0x02e1, 0x02e1, 0x02e1, 0x02e1, 0x025d, 0x025d, 0x025d, 0x025d,
0x02d5, 0x02d5, 0x02d5, 0x02d5, 0x027c, 0x027c, 0x027c, 0x027c,
0x02c7, 0x02c7, 0x02c7, 0x02c7, 0x024d, 0x024d, 0x024d, 0x024d,
0x028b, 0x028b, 0x028b, 0x028b, 0x02b8, 0x02b8, 0x02b8, 0x02b8,
0x02d4, 0x02d4, 0x02d4, 0x02d4, 0x029a, 0x029a, 0x029a, 0x029a,
0x02a9, 0x02a9, 0x02a9, 0x02a9, 0x026c, 0x026c, 0x026c, 0x026c,
0x02c6, 0x02c6, 0x02c6, 0x02c6, 0x023d, 0x023d, 0x023d, 0x023d,
0x02d3, 0x02d3, 0x02d3, 0x02d3, 0x022d, 0x022d, 0x022d, 0x022d,
0x02d2, 0x02d2, 0x02d2, 0x02d2, 0x021d, 0x021d, 0x021d, 0x021d,
0x027b, 0x027b, 0x027b, 0x027b, 0x02b7, 0x02b7, 0x02b7, 0x02b7,
0x02d1, 0x02d1, 0x02d1, 0x02d1, 0x025c, 0x025c, 0x025c, 0x025c,
0x02c5, 0x02c5, 0x02c5, 0x02c5, 0x028a, 0x028a, 0x028a, 0x028a,
0x02a8, 0x02a8, 0x02a8, 0x02a8, 0x0299, 0x0299, 0x0299, 0x0299,
0x024c, 0x024c, 0x024c, 0x024c, 0x02c4, 0x02c4, 0x02c4, 0x02c4,
0x026b, 0x026b, 0x026b, 0x026b, 0x02b6, 0x02b6, 0x02b6, 0x02b6,
0x03d0, 0x03d0, 0x030c, 0x030c, 0x023c, 0x023c, 0x023c, 0x023c,
0x02c3, 0x02c3, 0x02c3, 0x02c3, 0x027a, 0x027a, 0x027a, 0x027a,
0x02a7, 0x02a7, 0x02a7, 0x02a7, 0x022c, 0x022c, 0x022c, 0x022c,
0x02c2, 0x02c2, 0x02c2, 0x02c2, 0x025b, 0x025b, 0x025b, 0x025b,
0x02b5, 0x02b5, 0x02b5, 0x02b5, 0x021c, 0x021c, 0x021c, 0x021c,
0x0289, 0x0289, 0x0289, 0x0289, 0x0298, 0x0298, 0x0298, 0x0298,
0x02c1, 0x02c1, 0x02c1, 0x02c1, 0x024b, 0x024b, 0x024b, 0x024b,
0x03c0, 0x03c0, 0x030b, 0x030b, 0x023b, 0x023b, 0x023b, 0x023b,
0x03b0, 0x03b0, 0x030a, 0x030a, 0x021a, 0x021a, 0x021a, 0x021a,
0x01b4, 0x01b4, 0x01b4, 0x01b4, 0x01b4, 0x01b4, 0x01b4, 0x01b4,
0x026a, 0x026a, 0x026a, 0x026a, 0x02a6, 0x02a6, 0x02a6, 0x02a6,
0x0279, 0x0279, 0x0279, 0x0279, 0x0297, 0x0297, 0x0297, 0x0297,
0x03a0, 0x03a0, 0x0309, 0x0309, 0x0290, 0x0290, 0x0290, 0x0290,
0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3, 0x01b3,
0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188, 0x0188,
0x022b, 0x022b, 0x022b, 0x022b, 0x025a, 0x025a, 0x025a, 0x025a,
0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2, 0x01b2,
0x02a5, 0x02a5, 0x02a5, 0x02a5, 0x021b, 0x021b, 0x021b, 0x021b,
0x02b1, 0x02b1, 0x02b1, 0x02b1, 0x0269, 0x0269, 0x0269, 0x0269,
0x0196, 0x0196, 0x0196, 0x0196, 0x0196, 0x0196, 0x0196, 0x0196,
0x01a4, 0x01a4, 0x01a4, 0x01a4, 0x01a4, 0x01a4, 0x01a4, 0x01a4,
0x024a, 0x024a, 0x024a, 0x024a, 0x0278, 0x0278, 0x0278, 0x0278,
0x0187, 0x0187, 0x0187, 0x0187, 0x0187, 0x0187, 0x0187, 0x0187,
0x013a, 0x013a, 0x013a, 0x013a, 0x013a, 0x013a, 0x013a, 0x013a,
0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3, 0x01a3,
0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159, 0x0159,
0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195, 0x0195,
0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a, 0x012a,
0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2, 0x01a2,
0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1, 0x01a1,
0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168, 0x0168,
0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186, 0x0186,
0x0177, 0x0177, 0x0177, 0x0177, 0x0177, 0x0177, 0x0177, 0x0177,
0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149, 0x0149,
0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194, 0x0194,
0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139, 0x0139,
0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193, 0x0193,
0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158, 0x0158,
0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185, 0x0185,
0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129, 0x0129,
0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167, 0x0167,
0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176, 0x0176,
0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192, 0x0192,
0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119, 0x0119,
0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191, 0x0191,
0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148, 0x0148,
0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184, 0x0184,
0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157, 0x0157,
0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175, 0x0175,
0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138, 0x0138,
0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183,
0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166, 0x0166,
0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128, 0x0128,
0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182,
0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118, 0x0118,
0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147, 0x0147,
0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174, 0x0174,
0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181,
0x0208, 0x0208, 0x0208, 0x0208, 0x0280, 0x0280, 0x0280, 0x0280,
0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156, 0x0156,
0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165, 0x0165,
0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117, 0x0117,
0x0207, 0x0207, 0x0207, 0x0207, 0x0270, 0x0270, 0x0270, 0x0270,
0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137, 0x0137,
0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127, 0x0127,
0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106, 0x0106,
0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160, 0x0160,
0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105, 0x0105,
0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150, 0x0150,
};
static const short tab_c0[] =
{
-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
0
};
static const short tab_c1[] =
{
-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
0
};
static const struct newhuff ht[] =
{
{ /* 0 */ 0 , tab0_ } ,
{ /* 2 */ 0 , tab1_ } ,
{ /* 3 */ 0 , tab2_ } ,
{ /* 3 */ 0 , tab3_ } ,
{ /* 0 */ 0 , tab0_ } ,
{ /* 4 */ 0 , tab5_ } ,
{ /* 4 */ 0 , tab6_ } ,
{ /* 6 */ 0 , tab7_ } ,
{ /* 6 */ 0 , tab8_ } ,
{ /* 6 */ 0 , tab9_ } ,
{ /* 8 */ 0 , tab10_ } ,
{ /* 8 */ 0 , tab11_ } ,
{ /* 8 */ 0 , tab12_ } ,
{ /* 16 */ 0 , tab13_ } ,
{ /* 0 */ 0 , tab0_ } ,
{ /* 16 */ 0 , tab15_ } ,
{ /* 16 */ 1 , tab16_ } ,
{ /* 16 */ 2 , tab16_ } ,
{ /* 16 */ 3 , tab16_ } ,
{ /* 16 */ 4 , tab16_ } ,
{ /* 16 */ 6 , tab16_ } ,
{ /* 16 */ 8 , tab16_ } ,
{ /* 16 */ 10, tab16_ } ,
{ /* 16 */ 13, tab16_ } ,
{ /* 16 */ 4 , tab24_ } ,
{ /* 16 */ 5 , tab24_ } ,
{ /* 16 */ 6 , tab24_ } ,
{ /* 16 */ 7 , tab24_ } ,
{ /* 16 */ 8 , tab24_ } ,
{ /* 16 */ 9 , tab24_ } ,
{ /* 16 */ 11, tab24_ } ,
{ /* 16 */ 13, tab24_ }
};
static const struct newhuff htc[] =
{
{ /* 1 , 1 , */ 0 , tab_c0 } ,
{ /* 1 , 1 , */ 0 , tab_c1 }
};
#endif

View File

@ -0,0 +1,148 @@
/*
ntom.c: N->M down/up sampling; the setup code.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
*/
#define SAFE_NTOM /* Do not depend on off_t*off_t with big values still being in the range... */
#include "mpg123lib_intern.h"
#include "debug.h"
int synth_ntom_set_step(mpg123_handle *fr)
{
long m,n;
m = frame_freq(fr);
n = fr->af.rate;
if(VERBOSE2)
fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
if(n > NTOM_MAX_FREQ || m > NTOM_MAX_FREQ || m <= 0 || n <= 0) {
if(NOQUIET) error("NtoM converter: illegal rates");
fr->err = MPG123_BAD_RATE;
return -1;
}
n *= NTOM_MUL;
fr->ntom_step = (unsigned long) n / m;
if(fr->ntom_step > (unsigned long)NTOM_MAX*NTOM_MUL) {
if(NOQUIET) error3("max. 1:%i conversion allowed (%lu vs %lu)!", NTOM_MAX, fr->ntom_step, (unsigned long)8*NTOM_MUL);
fr->err = MPG123_BAD_RATE;
return -1;
}
fr->ntom_val[0] = fr->ntom_val[1] = ntom_val(fr, fr->num);
return 0;
}
/*
The SAFE_NTOM does iterative loops instead of straight multiplication.
The safety is not just about the algorithm closely mimicking the decoder instead of applying some formula,
it is more about avoiding multiplication of possibly big sample offsets (a 32bit off_t could overflow too easily).
*/
unsigned long ntom_val(mpg123_handle *fr, off_t frame)
{
off_t ntm;
#ifdef SAFE_NTOM /* Carry out the loop, without the threatening integer overflow. */
off_t f;
ntm = NTOM_MUL>>1; /* for frame 0 */
for(f=0; f<frame; ++f) /* for frame > 0 */
{
ntm += fr->spf*fr->ntom_step;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
}
#else /* Just make one computation with overall sample offset. */
ntm = (NTOM_MUL>>1) + fr->spf*frame*fr->ntom_step;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
#endif
return (unsigned long) ntm;
}
/* Set the ntom value for next expected frame to be decoded.
This is for keeping output consistent across seeks. */
void ntom_set_ntom(mpg123_handle *fr, off_t num)
{
fr->ntom_val[1] = fr->ntom_val[0] = ntom_val(fr, num);
}
/* Carry out the ntom sample count operation for this one frame.
No fear of integer overflow here. */
off_t ntom_frame_outsamples(mpg123_handle *fr)
{
/* The do this before decoding the separate channels, so there is only one common ntom value. */
int ntm = fr->ntom_val[0];
ntm += fr->spf*fr->ntom_step;
return ntm/NTOM_MUL;
}
/* Convert frame offset to unadjusted output sample offset. */
off_t ntom_frmouts(mpg123_handle *fr, off_t frame)
{
#ifdef SAFE_NTOM
off_t f;
#endif
off_t soff = 0;
off_t ntm = ntom_val(fr,0);
#ifdef SAFE_NTOM
if(frame <= 0) return 0;
for(f=0; f<frame; ++f)
{
ntm += fr->spf*fr->ntom_step;
soff += ntm/NTOM_MUL;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
}
#else
soff = (ntm + frame*(off_t)fr->spf*(off_t)fr->ntom_step)/(off_t)NTOM_MUL;
#endif
return soff;
}
/* Convert input samples to unadjusted output samples. */
off_t ntom_ins2outs(mpg123_handle *fr, off_t ins)
{
off_t soff = 0;
off_t ntm = ntom_val(fr,0);
#ifdef SAFE_NTOM
{
off_t block = fr->spf;
if(ins <= 0) return 0;
do
{
off_t nowblock = ins > block ? block : ins;
ntm += nowblock*fr->ntom_step;
soff += ntm/NTOM_MUL;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
ins -= nowblock;
} while(ins > 0);
}
#else
/* Beware of overflows: when off_t is 32bits, the multiplication blows too easily.
Of course, it blows for 64bits, too, in theory, but that's for _really_ large files. */
soff = ((off_t)ntm + (off_t)ins*(off_t)fr->ntom_step)/(off_t)NTOM_MUL;
#endif
return soff;
}
/* Determine frame offset from unadjusted output sample offset. */
off_t ntom_frameoff(mpg123_handle *fr, off_t soff)
{
off_t ioff = 0; /* frames or samples */
off_t ntm = ntom_val(fr,0);
#ifdef SAFE_NTOM
if(soff <= 0) return 0;
for(ioff=0; 1; ++ioff)
{
ntm += fr->spf*fr->ntom_step;
if(ntm/NTOM_MUL > soff) break;
soff -= ntm/NTOM_MUL;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
}
return ioff;
#else
ioff = (soff*(off_t)NTOM_MUL-ntm)/(off_t)fr->ntom_step;
return ioff/(off_t)fr->spf;
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,388 @@
#ifndef MPG123_H_OPTIMIZE
#define MPG123_H_OPTIMIZE
/*
optimize: get a grip on the different optimizations
copyright 2007-2013 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, taking from mpg123.[hc]
for building mpg123 with one optimization only, you have to choose exclusively between
OPT_GENERIC (generic C code for everyone)
OPT_GENERIC_DITHER (same with dithering for 1to1)
OPT_I386 (Intel i386)
OPT_I486 (Somewhat special code for i486; does not work together with others.)
OPT_I586 (Intel Pentium)
OPT_I586_DITHER (Intel Pentium with dithering/noise shaping for enhanced quality)
OPT_MMX (Intel Pentium and compatibles with MMX, fast, but not the best accuracy)
OPT_3DNOW (AMD 3DNow!, K6-2/3, Athlon, compatibles...)
OPT_3DNOW_VINTAGE
OPT_3DNOWEXT (AMD 3DNow! extended, generally Athlon, compatibles...)
OPT_3DNOWEXT_VINTAGE
OPT_SSE
OPT_SSE_VINTAGE
OPT_ALTIVEC (Motorola/IBM PPC with AltiVec under MacOSX)
OPT_X86_64 (x86-64 / AMD64 / Intel 64)
OPT_AVX
or you define OPT_MULTI and give a combination which makes sense (do not include i486, do not mix altivec and x86).
I still have to examine the dynamics of this here together with REAL_IS_FIXED.
Basic point is: Don't use REAL_IS_FIXED with something else than generic or i386.
Also, one should minimize code size by really ensuring that only functions that are really needed are included.
Currently, all generic functions will be always there (to be safe for fallbacks for advanced decoders).
Strictly, at least the synth_1to1 should not be necessary for single-decoder mode.
*/
/* Runtime optimization interface now here: */
/* Nedit inline Perl script to generate decoder list and name mapping in one place
optimize.c defining I_AM_OPTIMIZE to get the names
perl <<'EOT'
## order is important (autodec first, nodec last)
@names=
(
['autodec', 'auto']
,['generic', 'generic']
,['generic_dither', 'generic_dither']
,['idrei', 'i386']
,['ivier', 'i486']
,['ifuenf', 'i586']
,['ifuenf_dither', 'i586_dither']
,['mmx', 'MMX']
,['dreidnow', '3DNow']
,['dreidnowext', '3DNowExt']
,['altivec', 'AltiVec']
,['sse', 'SSE']
,['x86_64', 'x86-64']
,['arm','ARM']
,['neon','NEON']
,['avx','AVX']
,['dreidnow_vintage', '3DNow_vintage']
,['dreidnowext_vintage', '3DNowExt_vintage']
,['sse_vintage', 'SSE_vintage']
,['nodec', 'nodec']
);
print "enum optdec\n{\n";
for my $n (@names)
{
$name = $n->[0];
$enum = $name eq 'autodec' ? $name = " $name=0" : ",$name";
print "\t$enum\n"
}
print "};\n";
print "##ifdef I_AM_OPTIMIZE\n";
for my $n (@names)
{
my $key = $n->[0];
my $val = $n->[1];
print "static const char dn_$key\[\] = \"$val\";\n";
}
print "static const char* decname[] =\n{\n";
for my $n (@names)
{
my $key = $n->[0];
print "\t".($key eq 'autodec' ? ' ' : ',')."dn_$key\n";
}
print "};\n##endif"
EOT
*/
enum optdec
{
autodec=0
,generic
,generic_dither
,idrei
,ivier
,ifuenf
,ifuenf_dither
,mmx
,dreidnow
,dreidnowext
,altivec
,sse
,x86_64
,arm
,neon
,neon64
,avx
,dreidnow_vintage
,dreidnowext_vintage
,sse_vintage
,nodec
};
#ifdef I_AM_OPTIMIZE
static const char dn_autodec[] = "auto";
static const char dn_generic[] = "generic";
static const char dn_generic_dither[] = "generic_dither";
static const char dn_idrei[] = "i386";
static const char dn_ivier[] = "i486";
static const char dn_ifuenf[] = "i586";
static const char dn_ifuenf_dither[] = "i586_dither";
static const char dn_mmx[] = "MMX";
static const char dn_dreidnow[] = "3DNow";
static const char dn_dreidnowext[] = "3DNowExt";
static const char dn_altivec[] = "AltiVec";
static const char dn_sse[] = "SSE";
static const char dn_x86_64[] = "x86-64";
static const char dn_arm[] = "ARM";
static const char dn_neon[] = "NEON";
static const char dn_neon64[] = "NEON64";
static const char dn_avx[] = "AVX";
static const char dn_dreidnow_vintage[] = "3DNow_vintage";
static const char dn_dreidnowext_vintage[] = "3DNowExt_vintage";
static const char dn_sse_vintage[] = "SSE_vintage";
static const char dn_nodec[] = "nodec";
static const char* decname[] =
{
dn_autodec
,dn_generic
,dn_generic_dither
,dn_idrei
,dn_ivier
,dn_ifuenf
,dn_ifuenf_dither
,dn_mmx
,dn_dreidnow
,dn_dreidnowext
,dn_altivec
,dn_sse
,dn_x86_64
,dn_arm
,dn_neon
,dn_neon64
,dn_avx
,dn_dreidnow_vintage
,dn_dreidnowext_vintage
,dn_sse_vintage
,dn_nodec
};
#endif
enum optcla { nocla=0, normal, mmxsse };
/* - Set up the table of synth functions for current decoder choice. */
int frame_cpu_opt(mpg123_handle *fr, const char* cpu);
/* - Choose, from the synth table, the synth functions to use for current output format/rate. */
int set_synth_functions(mpg123_handle *fr);
/* - Parse decoder name and return numerical code. */
enum optdec dectype(const char* decoder);
/* - Return the default decoder type. */
enum optdec defdec(void);
/* - Return the class of a decoder type (mmxsse or normal). */
enum optcla decclass(const enum optdec);
/* Now comes a whole lot of definitions, for multi decoder mode and single decoder mode.
Because of the latter, it may look redundant at times. */
/* this is included in mpg123.h, which includes config.h */
#ifdef CCALIGN
#define ALIGNED(a) __attribute__((aligned(a)))
#else
#define ALIGNED(a)
#endif
/* Safety catch for invalid decoder choice. */
#ifdef REAL_IS_FIXED
#if (defined OPT_I486) || (defined OPT_I586) || (defined OPT_I586_DITHER) \
|| (defined OPT_MMX) || (defined OPT_SSE) || (defined_OPT_ALTIVEC) \
|| (defined OPT_3DNOW) || (defined OPT_3DNOWEXT) || (defined OPT_X86_64) \
|| (defined OPT_3DNOW_VINTAGE) || (defined OPT_3DNOWEXT_VINTAGE) \
|| (defined OPT_SSE_VINTAGE) \
|| (defined OPT_NEON) || (defined OPT_NEON64) || (defined OPT_AVX) \
|| (defined OPT_GENERIC_DITHER)
#error "Bad decoder choice together with fixed point math!"
#endif
#endif
#if (defined NO_LAYER1 && defined NO_LAYER2)
#define NO_LAYER12
#endif
#ifdef OPT_GENERIC
#ifndef OPT_MULTI
# define defopt generic
#endif
#endif
#ifdef OPT_GENERIC_DITHER
#define OPT_DITHER
#ifndef OPT_MULTI
# define defopt generic_dither
#endif
#endif
/* i486 is special... always alone! */
#ifdef OPT_I486
#define OPT_X86
#define defopt ivier
#ifdef OPT_MULTI
#error "i486 can only work alone!"
#endif
#define FIR_BUFFER_SIZE 128
#define FIR_SIZE 16
#endif
#ifdef OPT_I386
#define OPT_X86
#ifndef OPT_MULTI
# define defopt idrei
#endif
#endif
#ifdef OPT_I586
#define OPT_X86
#ifndef OPT_MULTI
# define defopt ifuenf
#endif
#endif
#ifdef OPT_I586_DITHER
#define OPT_X86
#define OPT_DITHER
#ifndef OPT_MULTI
# define defopt ifuenf_dither
#endif
#endif
/* We still have some special code around MMX tables. */
#ifdef OPT_MMX
#define OPT_MMXORSSE
#define OPT_X86
#ifndef OPT_MULTI
# define defopt mmx
#endif
#endif
#ifdef OPT_SSE
#define OPT_MMXORSSE
#define OPT_MPLAYER
#define OPT_X86
#ifndef OPT_MULTI
# define defopt sse
# define opt_dct36(fr) dct36_sse
#endif
#endif
#ifdef OPT_SSE_VINTAGE
#define OPT_MMXORSSE
#define OPT_MPLAYER
#define OPT_X86
#ifndef OPT_MULTI
# define defopt sse
#endif
#endif
#ifdef OPT_3DNOWEXT
#define OPT_MMXORSSE
#define OPT_MPLAYER
#define OPT_X86
#ifndef OPT_MULTI
# define defopt dreidnowext
#endif
#endif
/* same as above but also using 3DNowExt dct36 */
#ifdef OPT_3DNOWEXT_VINTAGE
#define OPT_MMXORSSE
#define OPT_MPLAYER
#define OPT_X86
#ifndef OPT_MULTI
# define defopt dreidnowext_vintage
# define opt_dct36(fr) dct36_3dnowext
#endif
#endif
#ifdef OPT_MPLAYER
extern const int costab_mmxsse[];
#endif
/* 3dnow used to use synth_1to1_i586 for mono / 8bit conversion - was that intentional? */
/* I'm trying to skip the pentium code here ... until I see that that is indeed a bad idea */
#ifdef OPT_3DNOW
#define OPT_X86
#ifndef OPT_MULTI
# define defopt dreidnow
#endif
#endif
/* same as above but also using 3DNow dct36 */
#ifdef OPT_3DNOW_VINTAGE
#define OPT_X86
#ifndef OPT_MULTI
# define defopt dreidnow_vintage
# define opt_dct36(fr) dct36_3dnow
#endif
#endif
#ifdef OPT_ALTIVEC
#ifndef OPT_MULTI
# define defopt altivec
#endif
#endif
#ifdef OPT_X86_64
#define OPT_MMXORSSE
#ifndef OPT_MULTI
# define defopt x86_64
# define opt_dct36(fr) dct36_x86_64
#endif
#endif
#ifdef OPT_AVX
#define OPT_MMXORSSE
#ifndef OPT_MULTI
# define defopt avx
# define opt_dct36(fr) dct36_avx
#endif
#endif
#ifdef OPT_ARM
#ifndef OPT_MULTI
# define defopt arm
#endif
#endif
#ifdef OPT_NEON
#define OPT_MMXORSSE
#ifndef OPT_MULTI
# define defopt neon
# define opt_dct36(fr) dct36_neon
#endif
#endif
#ifdef OPT_NEON64
#define OPT_MMXORSSE
#ifndef OPT_MULTI
# define defopt neon64
# define opt_dct36(fr) dct36_neon64
#endif
#endif
/*
Now come two blocks of standard definitions for multi-decoder mode and single-decoder mode.
Most stuff is so automatic that it's indeed generated by some inline shell script.
Remember to use these scripts when possible, instead of direct repetitive hacking.
*/
#ifdef OPT_MULTI
# define defopt nodec
# if (defined OPT_3DNOW_VINTAGE || defined OPT_3DNOWEXT_VINTAGE || defined OPT_SSE || defined OPT_X86_64 || defined OPT_AVX || defined OPT_NEON || defined OPT_NEON64)
# define opt_dct36(fr) ((fr)->cpu_opts.the_dct36)
# endif
#endif /* OPT_MULTI else */
# ifndef opt_dct36
# define opt_dct36(fr) dct36
# endif
#endif /* MPG123_H_OPTIMIZE */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
/*
parse: spawned from common; clustering around stream/frame parsing
copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp & Thomas Orgis
*/
#ifndef MPG123_PARSE_H
#define MPG123_PARSE_H
#include "frame.h"
int read_frame_init(mpg123_handle* fr);
int frame_bitrate(mpg123_handle *fr);
long frame_freq(mpg123_handle *fr);
int read_frame_recover(mpg123_handle* fr); /* dead? */
int read_frame(mpg123_handle *fr);
void set_pointer(mpg123_handle *fr, int part2, long backstep);
int position_info(mpg123_handle* fr, unsigned long no, long buffsize, unsigned long* frames_left, double* current_seconds, double* seconds_left);
double compute_bpf(mpg123_handle *fr);
long time_to_frame(mpg123_handle *fr, double seconds);
int get_songlen(mpg123_handle *fr,int no);
#endif

View File

@ -0,0 +1,140 @@
/*
reader: reading input data
copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis (after code from Michael Hipp)
*/
#ifndef MPG123_READER_H
#define MPG123_READER_H
#include "config.h"
#include "mpg123.h"
#ifndef NO_FEEDER
struct buffy
{
unsigned char *data;
ssize_t size;
ssize_t realsize;
struct buffy *next;
};
struct bufferchain
{
struct buffy* first; /* The beginning of the chain. */
struct buffy* last; /* The end... of the chain. */
ssize_t size; /* Aggregated size of all buffies. */
/* These positions are relative to buffer chain beginning. */
ssize_t pos; /* Position in whole chain. */
ssize_t firstpos; /* The point of return on non-forget() */
/* The "real" filepos is fileoff + pos. */
off_t fileoff; /* Beginning of chain is at this file offset. */
size_t bufblock; /* Default (minimal) size of buffers. */
size_t pool_size; /* Keep that many buffers in storage. */
size_t pool_fill; /* That many buffers are there. */
/* A pool of buffers to re-use, if activated. It's a linked list that is worked on from the front. */
struct buffy *pool;
};
/* Call this before any buffer chain use (even bc_init()). */
void bc_prepare(struct bufferchain *, size_t pool_size, size_t bufblock);
/* Free persistent data in the buffer chain, after bc_reset(). */
void bc_cleanup(struct bufferchain *);
/* Change pool size. This does not actually allocate/free anything on itself, just instructs later operations to free less / allocate more buffers. */
void bc_poolsize(struct bufferchain *, size_t pool_size, size_t bufblock);
/* Return available byte count in the buffer. */
size_t bc_fill(struct bufferchain *bc);
#endif
struct reader_data
{
off_t filelen; /* total file length or total buffer size */
off_t filepos; /* position in file or position in buffer chain */
int filept;
/* Custom opaque I/O handle from the client. */
void *iohandle;
int flags;
long timeout_sec;
ssize_t (*fdread) (mpg123_handle *, void *, size_t);
/* User can replace the read and lseek functions. The r_* are the stored replacement functions or NULL. */
ssize_t (*r_read) (int fd, void *buf, size_t count);
off_t (*r_lseek)(int fd, off_t offset, int whence);
/* These are custom I/O routines for opaque user handles.
They get picked if there's some iohandle set. */
ssize_t (*r_read_handle) (void *handle, void *buf, size_t count);
off_t (*r_lseek_handle)(void *handle, off_t offset, int whence);
/* An optional cleaner for the handle on closing the stream. */
void (*cleanup_handle)(void *handle);
/* These two pointers are the actual workers (default map to POSIX read/lseek). */
ssize_t (*read) (int fd, void *buf, size_t count);
off_t (*lseek)(int fd, off_t offset, int whence);
/* Buffered readers want that abstracted, set internally. */
ssize_t (*fullread)(mpg123_handle *, unsigned char *, ssize_t);
#ifndef NO_FEEDER
struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */
#endif
};
/* start to use off_t to properly do LFS in future ... used to be long */
#ifdef __MORPHOS__
#undef tell /* unistd.h defines it as lseek(x, 0L, 1) */
#endif
struct reader
{
int (*init) (mpg123_handle *);
void (*close) (mpg123_handle *);
ssize_t (*fullread) (mpg123_handle *, unsigned char *, ssize_t);
int (*head_read) (mpg123_handle *, unsigned long *newhead); /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
int (*head_shift) (mpg123_handle *, unsigned long *head); /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
off_t (*skip_bytes) (mpg123_handle *, off_t len); /* succ: >=0, else error or READER_MORE */
int (*read_frame_body)(mpg123_handle *, unsigned char *, int size);
int (*back_bytes) (mpg123_handle *, off_t bytes);
int (*seek_frame) (mpg123_handle *, off_t num);
off_t (*tell) (mpg123_handle *);
void (*rewind) (mpg123_handle *);
void (*forget) (mpg123_handle *);
};
/* Open a file by path or use an opened file descriptor. */
int open_stream(mpg123_handle *, const char *path, int fd);
/* Open an external handle. */
int open_stream_handle(mpg123_handle *, void *iohandle);
/* feed based operation has some specials */
int open_feed(mpg123_handle *);
/* externally called function, returns 0 on success, -1 on error */
int feed_more(mpg123_handle *fr, const unsigned char *in, long count);
void feed_forget(mpg123_handle *fr); /* forget the data that has been read (free some buffers) */
off_t feed_set_pos(mpg123_handle *fr, off_t pos); /* Set position (inside available data if possible), return wanted byte offset of next feed. */
void open_bad(mpg123_handle *);
#define READER_FD_OPENED 0x1
#define READER_ID3TAG 0x2
#define READER_SEEKABLE 0x4
#define READER_BUFFERED 0x8
#define READER_NONBLOCK 0x20
#define READER_HANDLEIO 0x40
#define READER_STREAM 0
#define READER_ICY_STREAM 1
#define READER_FEED 2
/* These two add a little buffering to enable small seeks for peek ahead. */
#define READER_BUF_STREAM 3
#define READER_BUF_ICY_STREAM 4
#ifdef READ_SYSTEM
#define READER_SYSTEM 5
#define READERS 6
#else
#define READERS 5
#endif
#define READER_ERROR MPG123_ERR
#define READER_MORE MPG123_NEED_MORE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,195 @@
/*
sample.h: The conversion from internal data to output samples of differing formats.
copyright 2007-9 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis, taking WRITE_SAMPLE from decode.c
Later added the end-conversion specific macros here, too.
*/
#ifndef SAMPLE_H
#define SAMPLE_H
/* mpg123lib_intern.h is included already, right? */
/* Special case is fixed point math... which does work, but not that nice yet. */
#ifdef REAL_IS_FIXED
static inline int16_t idiv_signed_rounded(int32_t x, int shift)
{
x >>= (shift - 1);
x += (x & 1);
return (int16_t)(x >> 1);
}
# define REAL_PLUS_32767 ( 32767 << 15 )
# define REAL_MINUS_32768 ( -32768 << 15 )
# define REAL_TO_SHORT(x) (idiv_signed_rounded(x, 15))
/* No better code (yet). */
# define REAL_TO_SHORT_ACCURATE(x) REAL_TO_SHORT(x)
/* This is just here for completeness, it is not used! */
# define REAL_TO_S32(x) (x)
#endif
/* From now on for single precision float... double precision is a possible option once we added some bits. But, it would be rather insane. */
#ifndef REAL_TO_SHORT
#if (defined FORCE_ACCURATE) || (defined ACCURATE_ROUNDING)
/* Define the accurate rounding function. */
# if (defined REAL_IS_FLOAT) && (defined IEEE_FLOAT)
/* This function is only available for IEEE754 single-precision values
This is nearly identical to proper rounding, just -+0.5 is rounded to 0 */
static inline int16_t ftoi16(float x)
{
union
{
float f;
int32_t i;
} u_fi;
u_fi.f = x + 12582912.0f; /* Magic Number: 2^23 + 2^22 */
return (int16_t)u_fi.i;
}
# define REAL_TO_SHORT_ACCURATE(x) ftoi16(x)
# else
/* The "proper" rounding, plain C, a bit slow. */
# define REAL_TO_SHORT_ACCURATE(x) (short)((x)>0.0?(x)+0.5:(x)-0.5)
# endif
#endif
/* Now define the normal rounding. */
# ifdef ACCURATE_ROUNDING
# define REAL_TO_SHORT(x) REAL_TO_SHORT_ACCURATE(x)
# else
/* Non-accurate rounding... simple truncation. Fastest, most LSB errors. */
# define REAL_TO_SHORT(x) (short)(x)
# endif
#endif /* REAL_TO_SHORT */
/* We should add dithering for S32, too? */
#ifndef REAL_TO_S32
# ifdef ACCURATE_ROUNDING
# define REAL_TO_S32(x) (int32_t)((x)>0.0?(x)+0.5:(x)-0.5)
# else
# define REAL_TO_S32(x) (int32_t)(x)
# endif
#endif
#ifndef REAL_PLUS_32767
# define REAL_PLUS_32767 32767.0
#endif
#ifndef REAL_MINUS_32768
# define REAL_MINUS_32768 -32768.0
#endif
#ifndef REAL_PLUS_S32
# define REAL_PLUS_S32 2147483647.0
#endif
#ifndef REAL_MINUS_S32
# define REAL_MINUS_S32 -2147483648.0
#endif
/* The actual storage of a decoded sample is separated in the following macros.
We can handle different types, we could also handle dithering here. */
#ifdef NEWOLD_WRITE_SAMPLE
/* This is the old new mpg123 WRITE_SAMPLE, fixed for newer GCC by MPlayer folks.
Makes a huge difference on old machines. */
#if WORDS_BIGENDIAN
#define MANTISSA_OFFSET 1
#else
#define MANTISSA_OFFSET 0
#endif
#define WRITE_SHORT_SAMPLE(samples,sum,clip) { \
union { double dtemp; int itemp[2]; } u; int v; \
u.dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\
v = u.itemp[MANTISSA_OFFSET] - 0x80000000; \
if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \
else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = v; } \
}
#else
/* Macro to produce a short (signed 16bit) output sample from internal representation,
which may be float, double or indeed some integer for fixed point handling. */
#define WRITE_SHORT_SAMPLE(samples,sum,clip) \
if( (sum) > REAL_PLUS_32767) { *(samples) = 0x7fff; (clip)++; } \
else if( (sum) < REAL_MINUS_32768) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = REAL_TO_SHORT(sum); }
#endif
/* Same as above, but always using accurate rounding. Would we want softer clipping here, too? */
#define WRITE_SHORT_SAMPLE_ACCURATE(samples,sum,clip) \
if( (sum) > REAL_PLUS_32767) { *(samples) = 0x7fff; (clip)++; } \
else if( (sum) < REAL_MINUS_32768) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = REAL_TO_SHORT_ACCURATE(sum); }
/*
32bit signed
We do clipping with the same old borders... but different conversion.
We see here that we need extra work for non-16bit output... we optimized for 16bit.
-0x7fffffff-1 is the minimum 32 bit signed integer value expressed so that MSVC
does not give a compile time warning.
*/
#define WRITE_S32_SAMPLE(samples,sum,clip) \
{ \
real tmpsum = REAL_MUL((sum),S32_RESCALE); \
if( tmpsum > REAL_PLUS_S32 ){ *(samples) = 0x7fffffff; (clip)++; } \
else if( tmpsum < REAL_MINUS_S32 ) { *(samples) = -0x7fffffff-1; (clip)++; } \
else { *(samples) = REAL_TO_S32(tmpsum); } \
}
/* Produce an 8bit sample, via 16bit intermediate. */
#define WRITE_8BIT_SAMPLE(samples,sum,clip) \
{ \
int16_t write_8bit_tmp; \
if( (sum) > REAL_PLUS_32767) { write_8bit_tmp = 0x7fff; (clip)++; } \
else if( (sum) < REAL_MINUS_32768) { write_8bit_tmp = -0x8000; (clip)++; } \
else { write_8bit_tmp = REAL_TO_SHORT(sum); } \
*(samples) = fr->conv16to8[write_8bit_tmp>>AUSHIFT]; \
}
#ifndef REAL_IS_FIXED
#define WRITE_REAL_SAMPLE(samples,sum,clip) *(samples) = ((real)1./SHORT_SCALE)*(sum)
#endif
/* Finished 32 bit sample to unsigned 32 bit sample. */
#define CONV_SU32(s) \
( (s >= 0) \
? ((uint32_t)s + (uint32_t)2147483648UL) \
: (s == -2147483647L-1L /* Work around to prevent a non-conformant MSVC warning/error */ \
? 0 /* Separate because negation would overflow. */ \
: (uint32_t)2147483648UL - (uint32_t)(-s) ) \
)
/* Finished 16 bit sample to unsigned 16 bit sample. */
#define CONV_SU16(s) (uint16_t)((int32_t)(s)+32768)
/* Same style for syn123 generic conversion. */
#define CONV_SU8(s) (uint8_t)((int16_t)s+128)
/* Unsigned 32 bit sample to signed 32 bit sample. */
#define CONV_US32(u) \
( (u >= 2147483648UL) \
? (int32_t)((uint32_t)u - (uint32_t)2147483648UL) \
: ((u == 0) \
? (int32_t)(-2147483647L-1L) \
: -(int32_t)((uint32_t)2147483648UL - u) ) \
)
/* Unsigned 16 bit sample to signed 16 bit sample. */
#define CONV_US16(s) (int16_t)((int32_t)s-32768)
/* Same style for syn123 generic conversion. */
#define CONV_US8(s) (int8_t)((int16_t)s-128)
/* 24 bit conversion: drop or add a least significant byte. */
#ifdef WORDS_BIGENDIAN
/* Highest byte first. Drop last. */
#define DROP4BYTE(w,r) {(w)[0]=(r)[0]; (w)[1]=(r)[1]; (w)[2]=(r)[2];}
#define ADD4BYTE(w,r) {(w)[0]=(r)[0]; (w)[1]=(r)[1]; (w)[2]=(r)[2]; (w)[3]=0;}
#else
/* Lowest byte first, drop that. */
#define DROP4BYTE(w,r) {(w)[0]=(r)[1]; (w)[1]=(r)[2]; (w)[2]=(r)[3];}
#define ADD4BYTE(w,r) {(w)[0]=0; (w)[1]=(r)[0]; (w)[2]=(r)[1]; (w)[3]=(r)[2];}
#endif
#endif

View File

@ -0,0 +1,250 @@
/*
stringbuf: mimicking a bit of C++ to more safely handle strings
copyright 2006-20 by the mpg123 project
- free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
*/
#include "mpg123lib_intern.h"
#include "config.h"
#include "mpg123.h"
#include "compat.h"
#include <string.h>
#include "debug.h"
mpg123_string* attribute_align_arg mpg123_new_string(const char *val)
{
mpg123_string *sb = malloc(sizeof(mpg123_string));
if(!sb)
return NULL;
mpg123_init_string(sb);
mpg123_set_string(sb, val);
return sb;
}
void attribute_align_arg mpg123_delete_string(mpg123_string* sb)
{
if(!sb)
return;
mpg123_free_string(sb);
free(sb);
}
void attribute_align_arg mpg123_init_string(mpg123_string* sb)
{
/* Handing in NULL here is a fatal mistake and rightfully so. */
sb->p = NULL;
sb->size = 0;
sb->fill = 0;
}
void attribute_align_arg mpg123_free_string(mpg123_string* sb)
{
if(!sb)
return;
if(sb->p != NULL) free(sb->p);
mpg123_init_string(sb);
}
int attribute_align_arg mpg123_grow_string(mpg123_string* sb, size_t new)
{
if(!sb)
return 0;
if(sb->size < new) return mpg123_resize_string(sb, new);
else return 1;
}
int attribute_align_arg mpg123_resize_string(mpg123_string* sb, size_t new)
{
if(!sb)
return 0;
debug3("resizing string pointer %p from %lu to %lu", (void*) sb->p, (unsigned long)sb->size, (unsigned long)new);
if(new == 0)
{
if(sb->size && sb->p != NULL) free(sb->p);
mpg123_init_string(sb);
return 1;
}
if(sb->size != new)
{
char* t;
debug("really!");
t = (char*) safe_realloc(sb->p, new*sizeof(char));
debug1("safe_realloc returned %p", (void*) t);
if(t != NULL)
{
sb->p = t;
sb->size = new;
if(sb->size < sb->fill)
{
// Cut short the existing data, properly.
sb->fill = sb->size;
sb->p[sb->fill-1] = 0;
}
return 1;
}
else return 0;
}
else return 1; /* success */
}
int attribute_align_arg mpg123_copy_string(mpg123_string* from, mpg123_string* to)
{
size_t fill;
char *text;
debug2("called copy_string with %p -> %p", (void*)from, (void*)to);
if(to == NULL)
return 0;
if(from == NULL)
{
fill = 0;
text = NULL;
}
else
{
fill = from->fill;
text = from->p;
}
if(mpg123_resize_string(to, fill))
{
if(fill) /* Avoid memcpy(NULL, NULL, 0) */
memcpy(to->p, text, fill);
to->fill = fill;
return 1;
}
else return 0;
}
int attribute_align_arg mpg123_move_string(mpg123_string *from, mpg123_string *to)
{
if(to)
mpg123_free_string(to);
else
mpg123_free_string(from);
if(from && to)
*to = *from;
if(from)
mpg123_init_string(from);
return (from && to) ? 1 : 0;
}
int attribute_align_arg mpg123_add_string(mpg123_string* sb, const char* stuff)
{
debug1("adding %s", stuff);
return mpg123_add_substring(sb, stuff, 0, stuff ? strlen(stuff) : 0);
}
int attribute_align_arg mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count)
{
debug("adding a substring");
if(!sb || !stuff)
return 0;
if(sb->fill) /* includes zero byte... */
{
if( (SIZE_MAX - sb->fill >= count) /* Avoid overflow. */
&& (sb->size >= sb->fill+count || mpg123_grow_string(sb, sb->fill+count)) )
{
memcpy(sb->p+sb->fill-1, stuff+from, count);
sb->fill += count;
sb->p[sb->fill-1] = 0; /* Terminate! */
}
else return 0;
}
else
{
if( count < SIZE_MAX && mpg123_grow_string(sb, count+1) )
{
memcpy(sb->p, stuff+from, count);
sb->fill = count+1;
sb->p[sb->fill-1] = 0; /* Terminate! */
}
else return 0;
}
return 1;
}
int attribute_align_arg mpg123_set_substring(mpg123_string* sb, const char* stuff, size_t from, size_t count)
{
if(!sb)
return 0;
sb->fill = 0;
return mpg123_add_substring(sb, stuff, from, count);
}
int attribute_align_arg mpg123_set_string(mpg123_string* sb, const char* stuff)
{
if(!sb)
return 0;
sb->fill = 0;
return mpg123_add_string(sb, stuff);
}
size_t attribute_align_arg mpg123_strlen(mpg123_string *sb, int utf8)
{
size_t i;
size_t bytelen;
/* Notions of empty string. If there's only a single character, it has to be the trailing zero, and if the first is the trailing zero anyway, we got empty. */
if(!sb || sb->fill < 2 || sb->p[0] == 0) return 0;
/* Find the first non-null character from the back.
We already established that the first character is non-null
That at fill-2 has to be null, though. */
for(i=sb->fill-2; i>0; --i)
if(sb->p[i] != 0) break;
/* For simple byte strings, we are done now. */
bytelen = i+1;
if(!utf8) return bytelen;
else
{
/* Work out the actual count of UTF8 bytes.
This employs no particular encoding error checking. */
size_t len = 0;
for(i=0; i<bytelen; ++i)
{
/* Every byte that is not a continuation byte ( 0xc0 == 10xx xxxx ) stands for a character. */
if((sb->p[i] & 0xc0) != 0x80) len++;
}
return len;
}
}
int attribute_align_arg mpg123_chomp_string(mpg123_string *sb)
{
ssize_t i;
if(!sb || !sb->fill) return 0;
/* Ensure that it is zero-terminated. */
sb->p[sb->fill-1] = 0;
for(i=sb->fill-2; i>=0; --i)
{
char *c = sb->p+i;
/* Stop at the first proper character. */
if(*c && *c != '\r' && *c != '\n') break;
else *c = 0;
}
/* initial fill at least 1, so i at least -1,
+2 means nothing happened for fill=1 .
With i=0, we got one non-null character, fill shall be 2
to accomodate the trailing zero. */
sb->fill = (size_t)i+2;
return 1;
}
int attribute_align_arg mpg123_same_string(mpg123_string *a, mpg123_string *b)
{
if(!a || !b)
return 0;
if(a->fill != b->fill)
return 0;
if(memcmp(a->p, b->p, a->fill))
return 0;
return 1;
}

View File

@ -0,0 +1,103 @@
/*
swap_bytes: Swap byte order of samples in a buffer.
copyright 2018 by the mpg123 project
licensed under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
This is C source to include in your code to get the function named
swap_bytes. It is serves intentional duplication in libmpg123 and
libsyn123 to avoid introducing a dependency between them. This function
is too small for that.
*/
/* Other headers are already included! */
/* Optionally use platform-specific byteswap macros. */
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
/* Plain stupid swapping of elements in a byte array. */
/* This is the fallback when there is no native bswap macro. */
#define SWAP(a,b) tmp = p[a]; p[a] = p[b]; p[b] = tmp;
/* Convert samplecount elements of samplesize bytes each in buffer buf. */
static void swap_bytes(void *buf, size_t samplesize, size_t samplecount)
{
unsigned char *p = buf;
unsigned char *pend = (unsigned char*)buf+samplesize*samplecount;
unsigned char tmp;
if(samplesize < 2)
return;
switch(samplesize)
{
case 2: /* AB -> BA */
#ifdef HAVE_BYTESWAP_H
{
uint16_t* pp = (uint16_t*)p;
for(; pp<(uint16_t*)pend; ++pp)
*pp = bswap_16(*pp);
}
#else
for(; p<pend; p+=2)
{
SWAP(0,1)
}
#endif
break;
case 3: /* ABC -> CBA */
for(; p<pend; p+=3)
{
SWAP(0,2)
}
break;
case 4: /* ABCD -> DCBA */
#ifdef HAVE_BYTESWAP_H
{
uint32_t* pp = (uint32_t*)p;
for(; pp<(uint32_t*)pend; ++pp)
*pp = bswap_32(*pp);
}
#else
for(; p<pend; p+=4)
{
SWAP(0,3)
SWAP(1,2)
}
#endif
break;
case 8: /* ABCDEFGH -> HGFEDCBA */
#ifdef HAVE_BYTESWAP_H
{
uint64_t* pp = (uint64_t*)p;
for(; pp<(uint64_t*)pend; ++pp)
*pp = bswap_64(*pp);
}
#else
for(; p<pend; p+=8)
{
SWAP(0,7)
SWAP(1,6)
SWAP(2,5)
SWAP(3,4)
}
#endif
break;
/* All the weird choices with the full nested loop. */
default:
for(; p<pend; p+=samplesize)
{
size_t j;
for(j=0; j<samplesize/2; ++j)
{
SWAP(j, samplesize-j-1)
}
}
}
}
#undef SWAP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,196 @@
/*
synth.h: generic synth functions
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, generalized by Thomas Orgis
This header is used multiple times to create different variants of these functions.
See decode.c and friends.
Hint: BLOCK, MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T as well as WRITE_SAMPLE do vary.
Thomas looked closely at the decode_1to1, decode_2to1 and decode_4to1 contents, seeing that they are too similar to be separate files.
This is what resulted...
Basically, you need one set of these functions for each output sample type.
That currently means signed short, 8bit or float/double; though unsigned short may come, too.
Define NO_AUTOINCREMENT i386 code that shall not rely on autoincrement.
Actual benefit of this has to be examined; may apply to specific (old) compilers, only.
*/
/* Main synth function, uses the plain dct64 or dct64_i386. */
int SYNTH_NAME(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
#ifndef NO_AUTOINCREMENT
#define BACKPEDAL 0x10 /* We use autoincrement and thus need this re-adjustment for window/b0. */
#define MY_DCT64 dct64
#else
#define BACKPEDAL 0x00 /* i386 code does not need that. */
#define MY_DCT64 dct64_i386
#endif
static const int step = 2;
SAMPLE_T *samples = (SAMPLE_T *) (fr->buffer.data + fr->buffer.fill);
real *b0, **buf; /* (*buf)[0x110]; */
int clip = 0;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
#ifdef USE_DITHER
/* We always go forward 32 dither points (and back again for the second channel),
(re)sampling the noise the same way as the original signal. */
fr->ditherindex -= 32;
#endif
samples++;
buf = fr->real_buffs[1];
}
#ifdef USE_DITHER
/* We check only once for the overflow of dither index here ...
this wraps differently than the original i586 dither code, in theory (but when DITHERSIZE % BLOCK/2 == 0 it's the same). */
if(DITHERSIZE-fr->ditherindex < 32) fr->ditherindex = 0;
/* And we define a macro for the dither action... */
#define ADD_DITHER(fr,sum) sum+=fr->dithernoise[fr->ditherindex]; fr->ditherindex += 64/BLOCK;
#else
#define ADD_DITHER(fr,sum)
#endif
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
MY_DCT64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
MY_DCT64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
{
register int j;
real *window = fr->decwin + 16 - bo1;
for(j=(BLOCK/4); j; j--, b0+=0x400/BLOCK-BACKPEDAL, window+=0x800/BLOCK-BACKPEDAL, samples+=step)
{
real sum;
#ifndef NO_AUTOINCREMENT
sum = REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
#else
sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);
sum -= REAL_MUL_SYNTH(window[0x1], b0[0x1]);
sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);
sum -= REAL_MUL_SYNTH(window[0x3], b0[0x3]);
sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);
sum -= REAL_MUL_SYNTH(window[0x5], b0[0x5]);
sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);
sum -= REAL_MUL_SYNTH(window[0x7], b0[0x7]);
sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);
sum -= REAL_MUL_SYNTH(window[0x9], b0[0x9]);
sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);
sum -= REAL_MUL_SYNTH(window[0xB], b0[0xB]);
sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);
sum -= REAL_MUL_SYNTH(window[0xD], b0[0xD]);
sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);
sum -= REAL_MUL_SYNTH(window[0xF], b0[0xF]);
#endif
ADD_DITHER(fr,sum)
WRITE_SAMPLE(samples,sum,clip);
}
{
real sum;
sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);
sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);
sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);
sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);
sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);
sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);
sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);
sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);
ADD_DITHER(fr,sum)
WRITE_SAMPLE(samples,sum,clip);
samples += step;
b0-=0x400/BLOCK;
window-=0x800/BLOCK;
}
window += bo1<<1;
for(j=(BLOCK/4)-1; j; j--, b0-=0x400/BLOCK+BACKPEDAL, window-=0x800/BLOCK-BACKPEDAL, samples+=step)
{
real sum;
#ifndef NO_AUTOINCREMENT
sum = -REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
#else
sum = -REAL_MUL_SYNTH(window[-0x1], b0[0x0]);
sum -= REAL_MUL_SYNTH(window[-0x2], b0[0x1]);
sum -= REAL_MUL_SYNTH(window[-0x3], b0[0x2]);
sum -= REAL_MUL_SYNTH(window[-0x4], b0[0x3]);
sum -= REAL_MUL_SYNTH(window[-0x5], b0[0x4]);
sum -= REAL_MUL_SYNTH(window[-0x6], b0[0x5]);
sum -= REAL_MUL_SYNTH(window[-0x7], b0[0x6]);
sum -= REAL_MUL_SYNTH(window[-0x8], b0[0x7]);
sum -= REAL_MUL_SYNTH(window[-0x9], b0[0x8]);
sum -= REAL_MUL_SYNTH(window[-0xA], b0[0x9]);
sum -= REAL_MUL_SYNTH(window[-0xB], b0[0xA]);
sum -= REAL_MUL_SYNTH(window[-0xC], b0[0xB]);
sum -= REAL_MUL_SYNTH(window[-0xD], b0[0xC]);
sum -= REAL_MUL_SYNTH(window[-0xE], b0[0xD]);
sum -= REAL_MUL_SYNTH(window[-0xF], b0[0xE]);
sum -= REAL_MUL_SYNTH(window[-0x0], b0[0xF]); /* Is that right? 0x0? Just wondering... */
#endif
ADD_DITHER(fr,sum)
WRITE_SAMPLE(samples,sum,clip);
}
}
if(final) fr->buffer.fill += BLOCK*sizeof(SAMPLE_T);
return clip;
#undef ADD_DITHER
#undef BACKPEDAL
#undef MY_DCT64
}

View File

@ -0,0 +1,142 @@
/*
synth_8bit.c: The functions for synthesizing 8bit samples, at the end of decoding.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, heavily dissected and rearranged by Thomas Orgis
*/
#include "mpg123lib_intern.h"
#include "sample.h"
#include "debug.h"
/*
Part 2: All synth functions that produce 8bit output.
What we need is just a special WRITE_SAMPLE. For the generic and i386 functions, that is.
For the rather optimized synth_1to1, we will need the postprocessing 8bit converters from synth_8bit.h .
*/
#define SAMPLE_T unsigned char
#define WRITE_SAMPLE(samples,sum,clip) WRITE_8BIT_SAMPLE(samples,sum,clip)
/* Part 2a: All straight 1to1 decoding functions */
#define BLOCK 0x40 /* One decoding block is 64 samples. */
#define SYNTH_NAME synth_1to1_8bit
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_1to1_8bit (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_1to1][f_8]
#define MONO_NAME synth_1to1_8bit_mono
#define MONO2STEREO_NAME synth_1to1_8bit_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_1to1_8bit_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
/* But now, we need functions that take the 16bit output of optimized synth_1to1 and convert it.
I suppose that is still faster than dropping the optimization altogether! */
#define BASE_SYNTH_NAME fr->synths.plain[r_1to1][f_16]
#define SYNTH_NAME synth_1to1_8bit_wrap
#define MONO_NAME synth_1to1_8bit_wrap_mono
#define MONO2STEREO_NAME synth_1to1_8bit_wrap_m2s
#include "synth_8bit.h"
#undef BASE_SYNTH_NAME
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#undef BLOCK
#ifndef NO_DOWNSAMPLE
/*
Part 2b: 2to1 synth. Only generic and i386.
*/
#define BLOCK 0x20 /* One decoding block is 32 samples. */
#define SYNTH_NAME synth_2to1_8bit
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_2to1_8bit (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_2to1][f_8]
#define MONO_NAME synth_2to1_8bit_mono
#define MONO2STEREO_NAME synth_2to1_8bit_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_2to1_8bit_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
/*
Part 2c: 4to1 synth. Only generic and i386.
*/
#define BLOCK 0x10 /* One decoding block is 16 samples. */
#define SYNTH_NAME synth_4to1_8bit
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_4to1_8bit (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_4to1][f_8]
#define MONO_NAME synth_4to1_8bit_mono
#define MONO2STEREO_NAME synth_4to1_8bit_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_4to1_8bit_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
#endif /* NO_DOWNSAMPLE */
#ifndef NO_NTOM
/*
Part 2d: ntom synth.
Same procedure as above... Just no extra play anymore, straight synth that may use an optimized dct64.
*/
/* These are all in one header, there's no flexibility to gain. */
#define SYNTH_NAME synth_ntom_8bit
#define MONO_NAME synth_ntom_8bit_mono
#define MONO2STEREO_NAME synth_ntom_8bit_m2s
#include "synth_ntom.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#endif
#undef SAMPLE_T
#undef WRITE_SAMPLE

View File

@ -0,0 +1,86 @@
/*
synth_8bit.h: Wrappers over optimized synth_xtoy for converting signed short to 8bit.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, code generalized to the wrapper by Thomas Orgis
Only variable is the BLOCK size to choose 1to1, 2to1 or 4to1.
Oh, and the names: BASE_SYNTH_NAME, SYNTH_NAME, MONO_NAME, MONO2STEREO_NAME
(p.ex. opt_synth_1to1(fr), synth_1to1_8bit, synth_1to1_8bit_mono, ...).
*/
int SYNTH_NAME(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
short samples_tmp[BLOCK];
short *tmp1 = samples_tmp + channel;
int i,ret;
unsigned char *samples = fr->buffer.data;
int pnt = fr->buffer.fill;
fr->buffer.data = (unsigned char*) samples_tmp;
fr->buffer.fill = 0;
ret = BASE_SYNTH_NAME(bandPtr, channel, fr , 0);
fr->buffer.data = samples;
samples += channel + pnt;
for(i=0;i<(BLOCK/2);i++)
{
*samples = fr->conv16to8[*tmp1>>AUSHIFT];
samples += 2;
tmp1 += 2;
}
fr->buffer.fill = pnt + (final ? BLOCK : 0 );
return ret;
}
int MONO_NAME(real *bandPtr, mpg123_handle *fr)
{
short samples_tmp[BLOCK];
short *tmp1 = samples_tmp;
int i,ret;
unsigned char *samples = fr->buffer.data;
int pnt = fr->buffer.fill;
fr->buffer.data = (unsigned char*) samples_tmp;
fr->buffer.fill = 0;
ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0);
fr->buffer.data = samples;
samples += pnt;
for(i=0;i<(BLOCK/2);i++)
{
*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
tmp1+=2;
}
fr->buffer.fill = pnt + BLOCK/2;
return ret;
}
int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
{
short samples_tmp[BLOCK];
short *tmp1 = samples_tmp;
int i,ret;
unsigned char *samples = fr->buffer.data;
int pnt = fr->buffer.fill;
fr->buffer.data = (unsigned char*) samples_tmp;
fr->buffer.fill = 0;
ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0);
fr->buffer.data = samples;
samples += pnt;
for(i=0;i<(BLOCK/2);i++)
{
*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
tmp1 += 2;
}
fr->buffer.fill = pnt + BLOCK;
return ret;
}

View File

@ -0,0 +1,64 @@
/*
monosynth.h: generic mono related synth functions
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, generalized by Thomas Orgis
This header is used multiple times to create different variants of these functions.
See decode.c and synth.h .
Hint: BLOCK, MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T do vary.
Thomas looked closely at the decode_1to1, decode_2to1 and decode_4to1 contents, seeing that they are too similar to be separate files.
This is what resulted...
Reason to separate this from synth.h:
There are decoders that have a special synth_1to1 but still can use these generic derivations for the mono stuff.
It generally makes a good deal of sense to set SYNTH_NAME to opt_synth_1to1(fr) (or opt_synth_2to1(fr), etc.).
*/
/* Mono synth, wrapping over SYNTH_NAME */
int MONO_NAME(real *bandPtr, mpg123_handle *fr)
{
SAMPLE_T samples_tmp[BLOCK];
SAMPLE_T *tmp1 = samples_tmp;
int i,ret;
/* save buffer stuff, trick samples_tmp into there, decode, restore */
unsigned char *samples = fr->buffer.data;
int pnt = fr->buffer.fill;
fr->buffer.data = (unsigned char*) samples_tmp;
fr->buffer.fill = 0;
ret = SYNTH_NAME(bandPtr, 0, fr, 0); /* decode into samples_tmp */
fr->buffer.data = samples; /* restore original value */
/* now append samples from samples_tmp */
samples += pnt; /* just the next mem in frame buffer */
for(i=0;i<(BLOCK/2);i++)
{
*( (SAMPLE_T *)samples) = *tmp1;
samples += sizeof(SAMPLE_T);
tmp1 += 2;
}
fr->buffer.fill = pnt + (BLOCK/2)*sizeof(SAMPLE_T);
return ret;
}
/* Mono to stereo synth, wrapping over SYNTH_NAME */
int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
{
int i,ret;
unsigned char *samples = fr->buffer.data;
ret = SYNTH_NAME(bandPtr,0,fr,1);
samples += fr->buffer.fill - BLOCK*sizeof(SAMPLE_T);
for(i=0;i<(BLOCK/2);i++)
{
((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
samples+=2*sizeof(SAMPLE_T);
}
return ret;
}

View File

@ -0,0 +1,213 @@
/*
synth_ntom.h: ntom-resampling synth functions
This header is used multiple times to create different variants of this function.
Hint: MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T as well as WRITE_SAMPLE do vary.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, generalized by Thomas Orgis
Well, this is very simple resampling... you may or may not like what you hear.
But it's cheap.
But still, we don't implement a non-autoincrement version of this one.
*/
/* Note: These mono functions would also work generically,
it's just that they need a runtime calculation for the conversion loop...
The fixed XtoY functions have the chance for loop unrolling... */
int MONO_NAME(real *bandPtr, mpg123_handle *fr)
{
SAMPLE_T samples_tmp[8*64];
SAMPLE_T *tmp1 = samples_tmp;
size_t i;
int ret;
size_t pnt = fr->buffer.fill;
unsigned char *samples = fr->buffer.data;
fr->buffer.data = (unsigned char*) samples_tmp;
fr->buffer.fill = 0;
ret = SYNTH_NAME(bandPtr, 0, fr, 1);
fr->buffer.data = samples;
samples += pnt;
for(i=0;i<(fr->buffer.fill/(2*sizeof(SAMPLE_T)));i++)
{
*( (SAMPLE_T *)samples) = *tmp1;
samples += sizeof(SAMPLE_T);
tmp1 += 2;
}
fr->buffer.fill = pnt + (fr->buffer.fill/2);
return ret;
}
int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
{
size_t i;
int ret;
size_t pnt1 = fr->buffer.fill;
unsigned char *samples = fr->buffer.data + pnt1;
ret = SYNTH_NAME(bandPtr, 0, fr, 1);
for(i=0;i<((fr->buffer.fill-pnt1)/(2*sizeof(SAMPLE_T)));i++)
{
((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
samples+=2*sizeof(SAMPLE_T);
}
return ret;
}
int SYNTH_NAME(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
static const int step = 2;
SAMPLE_T *samples = (SAMPLE_T *) (fr->buffer.data + fr->buffer.fill);
real *b0, **buf; /* (*buf)[0x110]; */
int clip = 0;
int bo1;
int ntom;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
ntom = fr->ntom_val[1] = fr->ntom_val[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
ntom = fr->ntom_val[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
{
register int j;
real *window = fr->decwin + 16 - bo1;
for (j=16;j;j--,window+=0x10)
{
real sum;
ntom += fr->ntom_step;
if(ntom < NTOM_MUL)
{
window += 16;
b0 += 16;
continue;
}
sum = REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
sum += REAL_MUL_SYNTH(*window++, *b0++);
sum -= REAL_MUL_SYNTH(*window++, *b0++);
while(ntom >= NTOM_MUL)
{
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
ntom += fr->ntom_step;
if(ntom >= NTOM_MUL)
{
real sum;
sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);
sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);
sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);
sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);
sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);
sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);
sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);
sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);
while(ntom >= NTOM_MUL)
{
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
b0-=0x10,window-=0x20;
window += bo1<<1;
for (j=15;j;j--,b0-=0x20,window-=0x10)
{
real sum;
ntom += fr->ntom_step;
if(ntom < NTOM_MUL)
{
window -= 16;
b0 += 16;
continue;
}
sum = REAL_MUL_SYNTH(-*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
sum -= REAL_MUL_SYNTH(*(--window), *b0++);
while(ntom >= NTOM_MUL)
{
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
}
fr->ntom_val[channel] = ntom;
if(final) fr->buffer.fill = ((unsigned char *) samples - fr->buffer.data - (channel ? sizeof(SAMPLE_T) : 0));
return clip;
}

View File

@ -0,0 +1,585 @@
/*
synth_real.c: The functions for synthesizing real (float) samples, at the end of decoding.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, heavily dissected and rearranged by Thomas Orgis
*/
#include "mpg123lib_intern.h"
#include "sample.h"
#include "debug.h"
#ifdef REAL_IS_FIXED
#error "Do not build this file with fixed point math!"
#else
/*
Part 3: All synth functions that produce float output.
What we need is just a special WRITE_SAMPLE. For the generic and i386 functions, that is.
The optimized synths would need to be changed internally to support float output.
*/
#define SAMPLE_T real
#define WRITE_SAMPLE(samples,sum,clip) WRITE_REAL_SAMPLE(samples,sum,clip)
/* Part 3a: All straight 1to1 decoding functions */
#define BLOCK 0x40 /* One decoding block is 64 samples. */
#define SYNTH_NAME synth_1to1_real
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_1to1_real (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_1to1][f_real]
#define MONO_NAME synth_1to1_real_mono
#define MONO2STEREO_NAME synth_1to1_real_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_1to1_real_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
/* At least one optimized real decoder... */
#ifdef OPT_X86_64
/* Assembler routines. */
int synth_1to1_real_x86_64_asm(real *window, real *b0, real *samples, int bo1);
int synth_1to1_real_s_x86_64_asm(real *window, real *b0l, real *b0r, real *samples, int bo1);
void dct64_real_x86_64(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_real_x86_64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_x86_64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_x86_64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
synth_1to1_real_x86_64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return 0;
}
int synth_1to1_real_stereo_x86_64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_x86_64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_x86_64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_x86_64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_x86_64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
synth_1to1_real_s_x86_64_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return 0;
}
#endif
#ifdef OPT_AVX
/* Assembler routines. */
#ifndef OPT_X86_64
int synth_1to1_real_x86_64_asm(real *window, real *b0, real *samples, int bo1);
#endif
int synth_1to1_real_s_avx_asm(real *window, real *b0l, real *b0r, real *samples, int bo1);
void dct64_real_avx(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_real_avx(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_avx(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_avx(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
synth_1to1_real_x86_64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return 0;
}
int synth_1to1_fltst_avx(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_avx(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_avx(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_avx(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_avx(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
synth_1to1_real_s_avx_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return 0;
}
#endif
#if defined(OPT_SSE) || defined(OPT_SSE_VINTAGE)
/* Assembler routines. */
int synth_1to1_real_sse_asm(real *window, real *b0, real *samples, int bo1);
int synth_1to1_real_s_sse_asm(real *window, real *b0l, real *b0r, real *samples, int bo1);
void dct64_real_sse(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_real_sse(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_sse(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_sse(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
synth_1to1_real_sse_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return 0;
}
int synth_1to1_real_stereo_sse(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_sse(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_sse(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_sse(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_sse(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
synth_1to1_real_s_sse_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return 0;
}
#endif
#ifdef OPT_NEON
/* Assembler routines. */
int synth_1to1_real_neon_asm(real *window, real *b0, real *samples, int bo1);
int synth_1to1_real_s_neon_asm(real *window, real *b0l, real *b0r, real *samples, int bo1);
void dct64_real_neon(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_real_neon(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_neon(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_neon(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
synth_1to1_real_neon_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return 0;
}
int synth_1to1_real_stereo_neon(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_neon(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_neon(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_neon(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_neon(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
synth_1to1_real_s_neon_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return 0;
}
#endif
#ifdef OPT_NEON64
/* Assembler routines. */
int synth_1to1_real_neon64_asm(real *window, real *b0, real *samples, int bo1);
int synth_1to1_real_s_neon64_asm(real *window, real *b0l, real *b0r, real *samples, int bo1);
void dct64_real_neon64(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_real_neon64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_neon64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_neon64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
synth_1to1_real_neon64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return 0;
}
int synth_1to1_fltst_neon64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
real *samples = (real *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_neon64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_neon64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_neon64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_neon64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
synth_1to1_real_s_neon64_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return 0;
}
#endif
#ifndef NO_DOWNSAMPLE
/*
Part 3b: 2to1 synth. Only generic and i386.
*/
#define BLOCK 0x20 /* One decoding block is 32 samples. */
#define SYNTH_NAME synth_2to1_real
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_2to1_real (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_2to1][f_real]
#define MONO_NAME synth_2to1_real_mono
#define MONO2STEREO_NAME synth_2to1_real_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_2to1_real_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
/*
Part 3c: 4to1 synth. Only generic and i386.
*/
#define BLOCK 0x10 /* One decoding block is 16 samples. */
#define SYNTH_NAME synth_4to1_real
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_4to1_real (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_4to1][f_real]
#define MONO_NAME synth_4to1_real_mono
#define MONO2STEREO_NAME synth_4to1_real_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_4to1_real_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
#endif /* NO_DOWNSAMPLE */
#ifndef NO_NTOM
/*
Part 3d: ntom synth.
Same procedure as above... Just no extra play anymore, straight synth that may use an optimized dct64.
*/
/* These are all in one header, there's no flexibility to gain. */
#define SYNTH_NAME synth_ntom_real
#define MONO_NAME synth_ntom_real_mono
#define MONO2STEREO_NAME synth_ntom_real_m2s
#include "synth_ntom.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#endif
#undef SAMPLE_T
#undef WRITE_SAMPLE
#endif /* non-fixed type */

View File

@ -0,0 +1,598 @@
/*
synth_s32.c: The functions for synthesizing real (float) samples, at the end of decoding.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp, heavily dissected and rearranged by Thomas Orgis
*/
#include "mpg123lib_intern.h"
#include "sample.h"
#include "debug.h"
#ifdef REAL_IS_FIXED
#error "Do not build this file with fixed point math!"
#else
/*
Part 4: All synth functions that produce signed 32 bit output.
What we need is just a special WRITE_SAMPLE.
*/
#define SAMPLE_T int32_t
#define WRITE_SAMPLE(samples,sum,clip) WRITE_S32_SAMPLE(samples,sum,clip)
/* Part 4a: All straight 1to1 decoding functions */
#define BLOCK 0x40 /* One decoding block is 64 samples. */
#define SYNTH_NAME synth_1to1_s32
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_1to1_s32 (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_1to1][f_32]
#define MONO_NAME synth_1to1_s32_mono
#define MONO2STEREO_NAME synth_1to1_s32_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_1to1_s32_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#ifdef OPT_X86_64
/* Assembler routines. */
int synth_1to1_s32_x86_64_asm(real *window, real *b0, int32_t *samples, int bo1);
int synth_1to1_s32_s_x86_64_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
void dct64_real_x86_64(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_s32_x86_64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_x86_64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_x86_64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_s32_x86_64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return clip;
}
int synth_1to1_s32_stereo_x86_64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_x86_64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_x86_64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_x86_64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_x86_64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_s32_s_x86_64_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return clip;
}
#endif
#ifdef OPT_AVX
/* Assembler routines. */
#ifndef OPT_x86_64
int synth_1to1_s32_x86_64_asm(real *window, real *b0, int32_t *samples, int bo1);
#endif
int synth_1to1_s32_s_avx_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
void dct64_real_avx(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_s32_avx(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_avx(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_avx(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_s32_x86_64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return clip;
}
int synth_1to1_s32_stereo_avx(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_avx(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_avx(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_avx(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_avx(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_s32_s_avx_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return clip;
}
#endif
#if defined(OPT_SSE) || defined(OPT_SSE_VINTAGE)
/* Assembler routines. */
int synth_1to1_s32_sse_asm(real *window, real *b0, int32_t *samples, int bo1);
int synth_1to1_s32_s_sse_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
void dct64_real_sse(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_s32_sse(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_sse(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_sse(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_s32_sse_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return clip;
}
int synth_1to1_s32_stereo_sse(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_sse(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_sse(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_sse(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_sse(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_s32_s_sse_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return clip;
}
#endif
#ifdef OPT_NEON
/* Assembler routines. */
int synth_1to1_s32_neon_asm(real *window, real *b0, int32_t *samples, int bo1);
int synth_1to1_s32_s_neon_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
void dct64_real_neon(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_s32_neon(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_neon(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_neon(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_s32_neon_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return clip;
}
int synth_1to1_s32_stereo_neon(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_neon(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_neon(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_neon(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_neon(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_s32_s_neon_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return clip;
}
#endif
#ifdef OPT_NEON64
/* Assembler routines. */
int synth_1to1_s32_neon64_asm(real *window, real *b0, int32_t *samples, int bo1);
int synth_1to1_s32_s_neon64_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
void dct64_real_neon64(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_s32_neon64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
#endif
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->real_buffs[0];
}
else
{
samples++;
buf = fr->real_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_real_neon64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_real_neon64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_s32_neon64_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 256;
return clip;
}
int synth_1to1_s32st_neon64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
#ifndef NO_EQUALIZER
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
#endif
fr->bo--;
fr->bo &= 0xf;
bufl = fr->real_buffs[0];
bufr = fr->real_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_real_neon64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_real_neon64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
}
else
{
b0l = bufl[1];
b0r = bufr[1];
bo1 = fr->bo+1;
dct64_real_neon64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_real_neon64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_s32_s_neon64_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 256;
return clip;
}
#endif
#undef BLOCK
#ifndef NO_DOWNSAMPLE
/*
Part 4b: 2to1 synth. Only generic and i386.
*/
#define BLOCK 0x20 /* One decoding block is 32 samples. */
#define SYNTH_NAME synth_2to1_s32
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_2to1_s32 (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_2to1][f_32]
#define MONO_NAME synth_2to1_s32_mono
#define MONO2STEREO_NAME synth_2to1_s32_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_2to1_s32_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
/*
Part 4c: 4to1 synth. Only generic and i386.
*/
#define BLOCK 0x10 /* One decoding block is 16 samples. */
#define SYNTH_NAME synth_4to1_s32
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_4to1_s32 (could be generic, could be i386). */
#define SYNTH_NAME fr->synths.plain[r_4to1][f_32]
#define MONO_NAME synth_4to1_s32_mono
#define MONO2STEREO_NAME synth_4to1_s32_m2s
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_4to1_s32_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
#endif /* NO_DOWNSAMPLE */
#ifndef NO_NTOM
/*
Part 4d: ntom synth.
Same procedure as above... Just no extra play anymore, straight synth that may use an optimized dct64.
*/
/* These are all in one header, there's no flexibility to gain. */
#define SYNTH_NAME synth_ntom_s32
#define MONO_NAME synth_ntom_s32_mono
#define MONO2STEREO_NAME synth_ntom_s32_m2s
#include "synth_ntom.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#endif
#undef SAMPLE_T
#undef WRITE_SAMPLE
#endif /* non-fixed type */

View File

@ -0,0 +1,52 @@
#ifndef MPG123_SYNTH_H
#define MPG123_SYNTH_H
/* This is included inside frame.h, which is included in mpg123lib_intern.h,
at the appropriate place.
Explicit header inclusions here would cause circular dependencies. */
/* The handle needs these types for selecting the decoding routine at runtime.
Not just for optimization, mainly for XtoY, mono/stereo. */
typedef int (*func_synth)(real *,int, mpg123_handle *,int );
typedef int (*func_synth_mono)(real *, mpg123_handle *);
typedef int (*func_synth_stereo)(real *, real *, mpg123_handle *);
enum synth_channel { c_plain=0, c_stereo, c_m2s, c_mono, c_limit };
enum synth_resample
{
r_none=-1
,r_1to1=0
# ifndef NO_DOWNSAMPLE
,r_2to1
,r_4to1
# endif
# ifndef NO_NTOM
,r_ntom
# endif
,r_limit
};
enum synth_format
{
f_none=-1
# ifndef NO_16BIT
,f_16
# endif
# ifndef NO_8BIT
,f_8
# endif
# ifndef NO_REAL
,f_real
# endif
# ifndef NO_32BIT
,f_32
# endif
,f_limit
};
struct synth_s
{
func_synth plain[r_limit][f_limit];
func_synth_stereo stereo[r_limit][f_limit];
func_synth_mono mono2stereo[r_limit][f_limit];
func_synth_mono mono[r_limit][f_limit];
};
#endif

View File

@ -0,0 +1,345 @@
/*
tabinit.c: initialize tables...
copyright ?-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
*/
#include "mpg123lib_intern.h"
#include "debug.h"
// The (normally precomputed) cos tables.
#include "costabs.h"
#ifdef RUNTIME_TABLES
#include "init_costabs.h"
#else
const
#endif
real *pnts[] = { cos64,cos32,cos16,cos8,cos4 };
static const long intwinbase[] = {
0, -1, -1, -1, -1, -1, -1, -2, -2, -2,
-2, -3, -3, -4, -4, -5, -5, -6, -7, -7,
-8, -9, -10, -11, -13, -14, -16, -17, -19, -21,
-24, -26, -29, -31, -35, -38, -41, -45, -49, -53,
-58, -63, -68, -73, -79, -85, -91, -97, -104, -111,
-117, -125, -132, -139, -147, -154, -161, -169, -176, -183,
-190, -196, -202, -208, -213, -218, -222, -225, -227, -228,
-228, -227, -224, -221, -215, -208, -200, -189, -177, -163,
-146, -127, -106, -83, -57, -29, 2, 36, 72, 111,
153, 197, 244, 294, 347, 401, 459, 519, 581, 645,
711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356,
1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962,
2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000,
1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970,
794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388,
-1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
-8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
-9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
-7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
-70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455,
12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
73415, 73908, 74313, 74630, 74856, 74992, 75038 };
#ifdef OPT_MMXORSSE
#if !defined(OPT_X86_64) && !defined(OPT_NEON) && !defined(OPT_NEON64) && !defined(OPT_AVX)
void make_decode_tables_mmx_asm(long scaleval, float* decwin_mmx, float *decwins);
void make_decode_tables_mmx(mpg123_handle *fr)
{
debug("MMX decode tables");
/* Take care: The scale should be like before, when we didn't have float output all around. */
make_decode_tables_mmx_asm((long)((fr->lastscale < 0 ? fr->p.outscale : fr->lastscale)*SHORT_SCALE), fr->decwin_mmx, fr->decwins);
debug("MMX decode tables done");
}
#else
/* This mimics round() as defined in C99. We stay C89. */
static int rounded(double f)
{
return (int)(f>0 ? floor(f+0.5) : ceil(f-0.5));
}
/* x86-64 doesn't use asm version */
void make_decode_tables_mmx(mpg123_handle *fr)
{
int i,j,val;
int idx = 0;
short *ptr = (short *)fr->decwins;
/* Scale is always based on 1.0 . */
double scaleval = -0.5*(fr->lastscale < 0 ? fr->p.outscale : fr->lastscale);
debug1("MMX decode tables with scaleval %g", scaleval);
for(i=0,j=0;i<256;i++,j++,idx+=32)
{
if(idx < 512+16)
fr->decwin_mmx[idx+16] = fr->decwin_mmx[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
if(i % 32 == 31)
idx -= 1023;
if(i % 64 == 63)
scaleval = - scaleval;
}
for( /* i=256 */ ;i<512;i++,j--,idx+=32)
{
if(idx < 512+16)
fr->decwin_mmx[idx+16] = fr->decwin_mmx[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
if(i % 32 == 31)
idx -= 1023;
if(i % 64 == 63)
scaleval = - scaleval;
}
for(i=0; i<512; i++) {
if(i&1) val = rounded(fr->decwin_mmx[i]*0.5);
else val = rounded(fr->decwin_mmx[i]*-0.5);
if(val > 32767) val = 32767;
else if(val < -32768) val = -32768;
ptr[i] = val;
}
for(i=512; i<512+32; i++) {
if(i&1) val = rounded(fr->decwin_mmx[i]*0.5);
else val = 0;
if(val > 32767) val = 32767;
else if(val < -32768) val = -32768;
ptr[i] = val;
}
for(i=0; i<512; i++) {
val = rounded(fr->decwin_mmx[511-i]*-0.5);
if(val > 32767) val = 32767;
else if(val < -32768) val = -32768;
ptr[512+32+i] = val;
}
debug("decode tables done");
}
#endif
#endif
#ifdef REAL_IS_FIXED
/* Need saturating multiplication that keeps table values in 32 bit range,
with the option to swap sign at will (so -2**31 is out).
This code is far from the decoder core and so assembly optimization might
be overkill. */
static int32_t sat_mul32(int32_t a, int32_t b)
{
int64_t prod = (int64_t)a * (int64_t)b;
/* TODO: record the clipping? An extra flag? */
if(prod > 2147483647L) return 2147483647L;
if(prod < -2147483647L) return -2147483647L;
return (int32_t)prod;
}
#endif
void make_decode_tables(mpg123_handle *fr)
{
int i,j;
int idx = 0;
double scaleval;
#ifdef REAL_IS_FIXED
real scaleval_long;
#endif
/* Scale is always based on 1.0 . */
scaleval = -0.5*(fr->lastscale < 0 ? fr->p.outscale : fr->lastscale);
debug1("decode tables with scaleval %g", scaleval);
#ifdef REAL_IS_FIXED
scaleval_long = DOUBLE_TO_REAL_15(scaleval);
debug1("decode table with fixed scaleval %li", (long)scaleval_long);
if(scaleval_long > 28618 || scaleval_long < -28618)
{
/* TODO: Limit the scaleval itself or limit the multiplication afterwards?
The former basically disables significant amplification for fixed-point
decoders, but avoids (possibly subtle) distortion. */
/* This would limit the amplification instead:
scaleval_long = scaleval_long < 0 ? -28618 : 28618; */
if(NOQUIET) warning("Desired amplification may introduce distortion.");
}
#endif
for(i=0,j=0;i<256;i++,j++,idx+=32)
{
if(idx < 512+16)
#ifdef REAL_IS_FIXED
fr->decwin[idx+16] = fr->decwin[idx] =
REAL_SCALE_WINDOW(sat_mul32(intwinbase[j],scaleval_long));
#else
fr->decwin[idx+16] = fr->decwin[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
#endif
if(i % 32 == 31)
idx -= 1023;
if(i % 64 == 63)
#ifdef REAL_IS_FIXED
scaleval_long = - scaleval_long;
#else
scaleval = - scaleval;
#endif
}
for( /* i=256 */ ;i<512;i++,j--,idx+=32)
{
if(idx < 512+16)
#ifdef REAL_IS_FIXED
fr->decwin[idx+16] = fr->decwin[idx] =
REAL_SCALE_WINDOW(sat_mul32(intwinbase[j],scaleval_long));
#else
fr->decwin[idx+16] = fr->decwin[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
#endif
if(i % 32 == 31)
idx -= 1023;
if(i % 64 == 63)
#ifdef REAL_IS_FIXED
scaleval_long = - scaleval_long;
#else
scaleval = - scaleval;
#endif
}
#if defined(OPT_X86_64) || defined(OPT_ALTIVEC) || defined(OPT_SSE) || defined(OPT_SSE_VINTAGE) || defined(OPT_ARM) || defined(OPT_NEON) || defined(OPT_NEON64) || defined(OPT_AVX)
if( fr->cpu_opts.type == x86_64
|| fr->cpu_opts.type == altivec
|| fr->cpu_opts.type == sse
|| fr->cpu_opts.type == sse_vintage
|| fr->cpu_opts.type == arm
|| fr->cpu_opts.type == neon
|| fr->cpu_opts.type == neon64
|| fr->cpu_opts.type == avx )
{ /* for float SSE / AltiVec / ARM decoder */
for(i=512; i<512+32; i++)
{
fr->decwin[i] = (i&1) ? fr->decwin[i] : 0;
}
for(i=0; i<512; i++)
{
fr->decwin[512+32+i] = -fr->decwin[511-i];
}
#if defined(OPT_NEON) || defined(OPT_NEON64)
if(fr->cpu_opts.type == neon || fr->cpu_opts.type == neon64)
{
for(i=0; i<512; i+=2)
{
fr->decwin[i] = -fr->decwin[i];
}
}
#endif
}
#endif
debug("decode tables done");
}
#ifndef NO_8BIT
int make_conv16to8_table(mpg123_handle *fr)
{
int i;
int mode = fr->af.dec_enc;
/*
* ????: 8.0 is right but on SB cards '2.0' is a better value ???
*/
const double mul = 8.0;
if(!fr->conv16to8_buf){
fr->conv16to8_buf = (unsigned char *) malloc(8192);
if(!fr->conv16to8_buf) {
fr->err = MPG123_ERR_16TO8TABLE;
if(NOQUIET) error("Can't allocate 16 to 8 converter table!");
return -1;
}
fr->conv16to8 = fr->conv16to8_buf + 4096;
}
switch(mode)
{
case MPG123_ENC_ULAW_8:
{
double m=127.0 / log(256.0);
int c1;
for(i=-4096;i<4096;i++)
{
/* dunno whether this is a valid transformation rule ?!?!? */
if(i < 0)
c1 = 127 - (int) (log( 1.0 - 255.0 * (double) i*mul / 32768.0 ) * m);
else
c1 = 255 - (int) (log( 1.0 + 255.0 * (double) i*mul / 32768.0 ) * m);
if(c1 < 0 || c1 > 255)
{
if(NOQUIET) error2("Converror %d %d",i,c1);
return -1;
}
if(c1 == 0)
c1 = 2;
fr->conv16to8[i] = (unsigned char) c1;
}
}
break;
case MPG123_ENC_SIGNED_8:
for(i=-4096;i<4096;i++)
fr->conv16to8[i] = i>>5;
break;
case MPG123_ENC_UNSIGNED_8:
for(i=-4096;i<4096;i++)
fr->conv16to8[i] = (i>>5)+128;
break;
case MPG123_ENC_ALAW_8:
{
/*
Let's believe Wikipedia (http://en.wikipedia.org/wiki/G.711) that this
is the correct table:
s0000000wxyza... n000wxyz [0-31] -> [0-15]
s0000001wxyza... n001wxyz [32-63] -> [16-31]
s000001wxyzab... n010wxyz [64-127] -> [32-47]
s00001wxyzabc... n011wxyz [128-255] -> [48-63]
s0001wxyzabcd... n100wxyz [256-511] -> [64-79]
s001wxyzabcde... n101wxyz [512-1023] -> [80-95]
s01wxyzabcdef... n110wxyz [1024-2047] -> [96-111]
s1wxyzabcdefg... n111wxyz [2048-4095] -> [112-127]
Let's extend to -4096, too.
Also, bytes are xored with 0x55 for transmission.
Since it sounds OK, I assume it is fine;-)
*/
for(i=0; i<64; ++i)
fr->conv16to8[i] = ((unsigned int)i)>>1;
for(i=64; i<128; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>2) & 0xf) | (2<<4);
for(i=128; i<256; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>3) & 0xf) | (3<<4);
for(i=256; i<512; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>4) & 0xf) | (4<<4);
for(i=512; i<1024; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>5) & 0xf) | (5<<4);
for(i=1024; i<2048; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>6) & 0xf) | (6<<4);
for(i=2048; i<4096; ++i)
fr->conv16to8[i] = ((((unsigned int)i)>>7) & 0xf) | (7<<4);
for(i=-4095; i<0; ++i)
fr->conv16to8[i] = fr->conv16to8[-i] | 0x80;
fr->conv16to8[-4096] = fr->conv16to8[-4095];
for(i=-4096;i<4096;i++)
{
/* fr->conv16to8[i] = - i>>5; */
/* fprintf(stderr, "table %i %i\n", i<<AUSHIFT, fr->conv16to8[i]); */
fr->conv16to8[i] ^= 0x55;
}
}
break;
default:
fr->err = MPG123_ERR_16TO8TABLE;
if(NOQUIET) error("Unknown 8 bit encoding choice.");
return -1;
break;
}
return 0;
}
#endif

View File

@ -0,0 +1,15 @@
/*
true: a trivial truth
copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http:#mpg123.org
*/
#ifndef MPG123_H_TRUE
#define MPG123_H_TRUE
#define MAYBE -1
#define FALSE 0
#define TRUE 1
#endif