libmpg123 1.9.0

git-svn-id: svn://kolibrios.org@1905 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-03-11 10:57:03 +00:00
parent 423f2f50d2
commit a316fa7c9d
58 changed files with 18597 additions and 3 deletions

View File

@ -3,7 +3,7 @@ LIBRARY = cairo
CC = gcc
CFLAGS = -c -O2 -fomit-frame-pointer
CFLAGS = -c -O2 -fomit-frame-pointer -ffast-math
LDIMPORT:= -nostdlib --out-implib libcairoimp.a --exclude-libs libamz.a

View File

@ -0,0 +1,64 @@
CC=gcc
CPP=gcc -E
CFLAGS= -c -combine -O2 -fomit-frame-pointer -ffast-math -mmmx -finline-functions
LDIMPORT:= -nostdlib --out-implib libmpg123imp.a
LDFLAGS:= -shared -s -T../newlib/dll.lds -Map map --image-base 0
INCLUDES= -I../newlib/include
LIBPATH:= -L../newlib
LIBS:= -lamz -lgcc -lcimp
NAME:= libmpg123
DEFINES:= -DHAVE_CONFIG_H -DOPT_MMX -DOPT_MULTI -DREAL_IS_FLOAT -DNOXFERMEM
SRCS= \
libmpg123.c \
compat.c \
dct64.c \
dct64_i386.c \
equalizer.c \
optimize.c \
icy.c \
id3.c \
index.c \
layer1.c \
layer2.c \
layer3.c \
synth.c \
tabinit.c \
parse.c \
readers.c \
frame.c \
format.c
ASM= \
getcpuflags.S \
tabinit_mmx.S \
dct64_mmx.S \
synth_mmx.S
ASM_OBJS = $(patsubst %.S, %.o, $(ASM))
SRCS_OBJ = $(patsubst %.c, %.o, $(SRCS))
all: $(NAME).dll
$(NAME).dll: $(SRCS_OBJ) $(ASM_OBJS) Makefile
ld $(LDIMPORT) $(LIBPATH) $(LDFLAGS) -o $@ $(SRCS_OBJ) $(ASM_OBJS) $(LIBS)
%.o : %.S $(ASM) Makefile
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
%.o: %.c Makefile
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<

View File

@ -0,0 +1,36 @@
.global ___chkstk
.global __alloca
.section .text
___chkstk:
__alloca:
pushl %ecx /* save temp */
leal 8(%esp), %ecx /* point past return addr */
cmpl $0x1000, %eax /* > 4k ?*/
jb Ldone
Lprobe:
subl $0x1000, %ecx /* yes, move pointer down 4k*/
orl $0x0, (%ecx) /* probe there */
subl $0x1000, %eax /* decrement count */
cmpl $0x1000, %eax
ja Lprobe /* and do it again */
Ldone:
subl %eax, %ecx
orl $0x0, (%ecx) /* less than 4k, just peek here */
movl %esp, %eax /* save old stack pointer */
movl %ecx, %esp /* decrement stack */
movl (%eax), %ecx /* recover saved temp */
movl 4(%eax), %eax /* recover return address */
/* Push the return value back. Doing this instead of just
jumping to %eax preserves the cached call-return stack
used by most modern processors. */
pushl %eax
ret

View File

@ -0,0 +1,41 @@
/*
compat: Some compatibility functions. 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.
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"
/* 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);
}
#ifndef HAVE_STRERROR
const char *strerror(int errnum)
{
extern int sys_nerr;
extern char *sys_errlist[];
return (errnum < sys_nerr) ? sys_errlist[errnum] : "";
}
#endif
#ifndef HAVE_STRDUP
char *strdup(const char *src)
{
char *dest;
if (!(dest = (char *) malloc(strlen(src)+1)))
return NULL;
else
return strcpy(dest, src);
}
#endif

View File

@ -0,0 +1,124 @@
/*
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-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
*/
#ifndef MPG123_COMPAT_H
#define MPG123_COMPAT_H
#include "config.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 ULONG_MAX
#define ULONG_MAX ((unsigned long)-1)
#endif
#ifdef HAVE_STRING_H
#include <string.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
/* To parse big numbers... */
#ifdef HAVE_ATOLL
#define atobigint atoll
#else
#define atobigint atol
#endif
typedef unsigned char byte;
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
void *safe_realloc(void *ptr, size_t size);
#ifndef HAVE_STRERROR
const char *strerror(int errnum);
#endif
#ifndef HAVE_STRDUP
char *strdup(const char *s);
#endif
/* 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 PLAIN_C89) && (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 PLAIN_C89) && (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 PLAIN_C89) && (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
#endif

View File

@ -0,0 +1,386 @@
/* 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's for 32bit x86... */
#define ABI_ALIGN_FUN 1
/* Define to use proper rounding. */
/* #undef ACCURATE_ROUNDING */
/* 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 checking of stack alignment is wanted. */
#define CHECK_ALIGN 1
/* Define if debugging is enabled. */
/* #undef DEBUG */
/* The default audio output module(s) to use */
#define DEFAULT_OUTPUT_MODULE "win32"
/* Define if building with dynamcally linked libmpg123 */
#define DYNAMIC_BUILD 1
/* Define if FIFO support is enabled. */
/* #undef FIFO */
/* 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 <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 <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
/* Define to 1 if you have the `getaddrinfo' function. */
/* #undef HAVE_GETADDRINFO */
/* Define to 1 if you have the `getpagesize' function. */
#define HAVE_GETPAGESIZE 1
/* 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 <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 if libltdl is available */
/* #undef HAVE_LTDL */
/* Define to 1 if you have the <machine/soundcard.h> header file. */
/* #undef HAVE_MACHINE_SOUNDCARD_H */
/* 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 a working `mmap' system call. */
/* #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. */
/* #undef HAVE_SCHED_H */
/* 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 <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 `strdup' function. */
#define HAVE_STRDUP 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/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/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. */
#define 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 <windows.h> header file. */
#define HAVE_WINDOWS_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. */
/* #undef IPV6 */
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Define if network support is enabled. */
/* #undef NETWORK */
/* Define to disable 16 bit integer output. */
/* #undef NO_16BIT */
/* Define to disable 32 bit integer output. */
#define NO_32BIT 1
/* Define to disable 8 bit integer output. */
#define NO_8BIT 1
/* Define to disable downsampled decoding. */
/* #undef NO_DOWNSAMPLE */
/* Define to disable error messages in combination with a return value (the
return is left intact). */
#define NO_ERETURN 1
/* Define to disable error messages. */
#define NO_ERROR 1
/* Define to disable feeder and buffered readers. */
#define NO_FEEDER 1
/* Define to disable ICY handling. */
#define NO_ICY 1
/* Define to disable ID3v2 parsing. */
#define NO_ID3V2 1
/* 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 ntom resampling. */
#define NO_NTOM 1
/* Define to disable real output. */
#define NO_REAL 1
/* Define to disable string functions. */
#define NO_STRING
/* Define to disable warning messages. */
#define NO_WARNING 1
/* Name of package */
#define PACKAGE "mpg123"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "mpg123-devel@lists.sourceforge.net"
/* 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.9.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "mpg123"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.9.0"
/* Define if portaudio v18 API is wanted. */
/* #undef PORTAUDIO18 */
/* 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 `off_t', as computed by sizeof. */
#define SIZEOF_OFF_T 4
/* 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 if modules are enabled */
/* #undef USE_MODULES */
/* Version number of package */
#define VERSION "1.9.0"
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
/* 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 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 */

View File

@ -0,0 +1,174 @@
/*
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,*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,336 @@
/*
dct64_i386.c: DCT64, a C variant for i386
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
* optimized for machines with no auto-increment.
* The performance is highly compiler dependend. Maybe
* the dct64.c version for 'normal' processor may be faster
* even for Intel processors.
*/
#include "mpg123lib_intern.h"
static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples)
{
{
register real *costab = pnts[0];
b1[0x00] = samples[0x00] + samples[0x1F];
b1[0x01] = samples[0x01] + samples[0x1E];
b1[0x1F] = REAL_MUL(samples[0x00] - samples[0x1F], costab[0x0]);
b1[0x1E] = REAL_MUL(samples[0x01] - samples[0x1E], costab[0x1]);
b1[0x02] = samples[0x02] + samples[0x1D];
b1[0x03] = samples[0x03] + samples[0x1C];
b1[0x1D] = REAL_MUL(samples[0x02] - samples[0x1D], costab[0x2]);
b1[0x1C] = REAL_MUL(samples[0x03] - samples[0x1C], costab[0x3]);
b1[0x04] = samples[0x04] + samples[0x1B];
b1[0x05] = samples[0x05] + samples[0x1A];
b1[0x1B] = REAL_MUL(samples[0x04] - samples[0x1B], costab[0x4]);
b1[0x1A] = REAL_MUL(samples[0x05] - samples[0x1A], costab[0x5]);
b1[0x06] = samples[0x06] + samples[0x19];
b1[0x07] = samples[0x07] + samples[0x18];
b1[0x19] = REAL_MUL(samples[0x06] - samples[0x19], costab[0x6]);
b1[0x18] = REAL_MUL(samples[0x07] - samples[0x18], costab[0x7]);
b1[0x08] = samples[0x08] + samples[0x17];
b1[0x09] = samples[0x09] + samples[0x16];
b1[0x17] = REAL_MUL(samples[0x08] - samples[0x17], costab[0x8]);
b1[0x16] = REAL_MUL(samples[0x09] - samples[0x16], costab[0x9]);
b1[0x0A] = samples[0x0A] + samples[0x15];
b1[0x0B] = samples[0x0B] + samples[0x14];
b1[0x15] = REAL_MUL(samples[0x0A] - samples[0x15], costab[0xA]);
b1[0x14] = REAL_MUL(samples[0x0B] - samples[0x14], costab[0xB]);
b1[0x0C] = samples[0x0C] + samples[0x13];
b1[0x0D] = samples[0x0D] + samples[0x12];
b1[0x13] = REAL_MUL(samples[0x0C] - samples[0x13], costab[0xC]);
b1[0x12] = REAL_MUL(samples[0x0D] - samples[0x12], costab[0xD]);
b1[0x0E] = samples[0x0E] + samples[0x11];
b1[0x0F] = samples[0x0F] + samples[0x10];
b1[0x11] = REAL_MUL(samples[0x0E] - samples[0x11], costab[0xE]);
b1[0x10] = REAL_MUL(samples[0x0F] - samples[0x10], costab[0xF]);
}
{
register real *costab = pnts[1];
b2[0x00] = b1[0x00] + b1[0x0F];
b2[0x01] = b1[0x01] + b1[0x0E];
b2[0x0F] = REAL_MUL(b1[0x00] - b1[0x0F], costab[0]);
b2[0x0E] = REAL_MUL(b1[0x01] - b1[0x0E], costab[1]);
b2[0x02] = b1[0x02] + b1[0x0D];
b2[0x03] = b1[0x03] + b1[0x0C];
b2[0x0D] = REAL_MUL(b1[0x02] - b1[0x0D], costab[2]);
b2[0x0C] = REAL_MUL(b1[0x03] - b1[0x0C], costab[3]);
b2[0x04] = b1[0x04] + b1[0x0B];
b2[0x05] = b1[0x05] + b1[0x0A];
b2[0x0B] = REAL_MUL(b1[0x04] - b1[0x0B], costab[4]);
b2[0x0A] = REAL_MUL(b1[0x05] - b1[0x0A], costab[5]);
b2[0x06] = b1[0x06] + b1[0x09];
b2[0x07] = b1[0x07] + b1[0x08];
b2[0x09] = REAL_MUL(b1[0x06] - b1[0x09], costab[6]);
b2[0x08] = REAL_MUL(b1[0x07] - b1[0x08], costab[7]);
/* */
b2[0x10] = b1[0x10] + b1[0x1F];
b2[0x11] = b1[0x11] + b1[0x1E];
b2[0x1F] = REAL_MUL(b1[0x1F] - b1[0x10], costab[0]);
b2[0x1E] = REAL_MUL(b1[0x1E] - b1[0x11], costab[1]);
b2[0x12] = b1[0x12] + b1[0x1D];
b2[0x13] = b1[0x13] + b1[0x1C];
b2[0x1D] = REAL_MUL(b1[0x1D] - b1[0x12], costab[2]);
b2[0x1C] = REAL_MUL(b1[0x1C] - b1[0x13], costab[3]);
b2[0x14] = b1[0x14] + b1[0x1B];
b2[0x15] = b1[0x15] + b1[0x1A];
b2[0x1B] = REAL_MUL(b1[0x1B] - b1[0x14], costab[4]);
b2[0x1A] = REAL_MUL(b1[0x1A] - b1[0x15], costab[5]);
b2[0x16] = b1[0x16] + b1[0x19];
b2[0x17] = b1[0x17] + b1[0x18];
b2[0x19] = REAL_MUL(b1[0x19] - b1[0x16], costab[6]);
b2[0x18] = REAL_MUL(b1[0x18] - b1[0x17], costab[7]);
}
{
register real *costab = pnts[2];
b1[0x00] = b2[0x00] + b2[0x07];
b1[0x07] = REAL_MUL(b2[0x00] - b2[0x07], costab[0]);
b1[0x01] = b2[0x01] + b2[0x06];
b1[0x06] = REAL_MUL(b2[0x01] - b2[0x06], costab[1]);
b1[0x02] = b2[0x02] + b2[0x05];
b1[0x05] = REAL_MUL(b2[0x02] - b2[0x05], costab[2]);
b1[0x03] = b2[0x03] + b2[0x04];
b1[0x04] = REAL_MUL(b2[0x03] - b2[0x04], costab[3]);
b1[0x08] = b2[0x08] + b2[0x0F];
b1[0x0F] = REAL_MUL(b2[0x0F] - b2[0x08], costab[0]);
b1[0x09] = b2[0x09] + b2[0x0E];
b1[0x0E] = REAL_MUL(b2[0x0E] - b2[0x09], costab[1]);
b1[0x0A] = b2[0x0A] + b2[0x0D];
b1[0x0D] = REAL_MUL(b2[0x0D] - b2[0x0A], costab[2]);
b1[0x0B] = b2[0x0B] + b2[0x0C];
b1[0x0C] = REAL_MUL(b2[0x0C] - b2[0x0B], costab[3]);
b1[0x10] = b2[0x10] + b2[0x17];
b1[0x17] = REAL_MUL(b2[0x10] - b2[0x17], costab[0]);
b1[0x11] = b2[0x11] + b2[0x16];
b1[0x16] = REAL_MUL(b2[0x11] - b2[0x16], costab[1]);
b1[0x12] = b2[0x12] + b2[0x15];
b1[0x15] = REAL_MUL(b2[0x12] - b2[0x15], costab[2]);
b1[0x13] = b2[0x13] + b2[0x14];
b1[0x14] = REAL_MUL(b2[0x13] - b2[0x14], costab[3]);
b1[0x18] = b2[0x18] + b2[0x1F];
b1[0x1F] = REAL_MUL(b2[0x1F] - b2[0x18], costab[0]);
b1[0x19] = b2[0x19] + b2[0x1E];
b1[0x1E] = REAL_MUL(b2[0x1E] - b2[0x19], costab[1]);
b1[0x1A] = b2[0x1A] + b2[0x1D];
b1[0x1D] = REAL_MUL(b2[0x1D] - b2[0x1A], costab[2]);
b1[0x1B] = b2[0x1B] + b2[0x1C];
b1[0x1C] = REAL_MUL(b2[0x1C] - b2[0x1B], costab[3]);
}
{
register real const cos0 = pnts[3][0];
register real const cos1 = pnts[3][1];
b2[0x00] = b1[0x00] + b1[0x03];
b2[0x03] = REAL_MUL(b1[0x00] - b1[0x03], cos0);
b2[0x01] = b1[0x01] + b1[0x02];
b2[0x02] = REAL_MUL(b1[0x01] - b1[0x02], cos1);
b2[0x04] = b1[0x04] + b1[0x07];
b2[0x07] = REAL_MUL(b1[0x07] - b1[0x04], cos0);
b2[0x05] = b1[0x05] + b1[0x06];
b2[0x06] = REAL_MUL(b1[0x06] - b1[0x05], cos1);
b2[0x08] = b1[0x08] + b1[0x0B];
b2[0x0B] = REAL_MUL(b1[0x08] - b1[0x0B], cos0);
b2[0x09] = b1[0x09] + b1[0x0A];
b2[0x0A] = REAL_MUL(b1[0x09] - b1[0x0A], cos1);
b2[0x0C] = b1[0x0C] + b1[0x0F];
b2[0x0F] = REAL_MUL(b1[0x0F] - b1[0x0C], cos0);
b2[0x0D] = b1[0x0D] + b1[0x0E];
b2[0x0E] = REAL_MUL(b1[0x0E] - b1[0x0D], cos1);
b2[0x10] = b1[0x10] + b1[0x13];
b2[0x13] = REAL_MUL(b1[0x10] - b1[0x13], cos0);
b2[0x11] = b1[0x11] + b1[0x12];
b2[0x12] = REAL_MUL(b1[0x11] - b1[0x12], cos1);
b2[0x14] = b1[0x14] + b1[0x17];
b2[0x17] = REAL_MUL(b1[0x17] - b1[0x14], cos0);
b2[0x15] = b1[0x15] + b1[0x16];
b2[0x16] = REAL_MUL(b1[0x16] - b1[0x15], cos1);
b2[0x18] = b1[0x18] + b1[0x1B];
b2[0x1B] = REAL_MUL(b1[0x18] - b1[0x1B], cos0);
b2[0x19] = b1[0x19] + b1[0x1A];
b2[0x1A] = REAL_MUL(b1[0x19] - b1[0x1A], cos1);
b2[0x1C] = b1[0x1C] + b1[0x1F];
b2[0x1F] = REAL_MUL(b1[0x1F] - b1[0x1C], cos0);
b2[0x1D] = b1[0x1D] + b1[0x1E];
b2[0x1E] = REAL_MUL(b1[0x1E] - b1[0x1D], cos1);
}
{
register real const cos0 = pnts[4][0];
b1[0x00] = b2[0x00] + b2[0x01];
b1[0x01] = REAL_MUL(b2[0x00] - b2[0x01], cos0);
b1[0x02] = b2[0x02] + b2[0x03];
b1[0x03] = REAL_MUL(b2[0x03] - b2[0x02], cos0);
b1[0x02] += b1[0x03];
b1[0x04] = b2[0x04] + b2[0x05];
b1[0x05] = REAL_MUL(b2[0x04] - b2[0x05], cos0);
b1[0x06] = b2[0x06] + b2[0x07];
b1[0x07] = REAL_MUL(b2[0x07] - b2[0x06], cos0);
b1[0x06] += b1[0x07];
b1[0x04] += b1[0x06];
b1[0x06] += b1[0x05];
b1[0x05] += b1[0x07];
b1[0x08] = b2[0x08] + b2[0x09];
b1[0x09] = REAL_MUL(b2[0x08] - b2[0x09], cos0);
b1[0x0A] = b2[0x0A] + b2[0x0B];
b1[0x0B] = REAL_MUL(b2[0x0B] - b2[0x0A], cos0);
b1[0x0A] += b1[0x0B];
b1[0x0C] = b2[0x0C] + b2[0x0D];
b1[0x0D] = REAL_MUL(b2[0x0C] - b2[0x0D], cos0);
b1[0x0E] = b2[0x0E] + b2[0x0F];
b1[0x0F] = REAL_MUL(b2[0x0F] - b2[0x0E], cos0);
b1[0x0E] += b1[0x0F];
b1[0x0C] += b1[0x0E];
b1[0x0E] += b1[0x0D];
b1[0x0D] += b1[0x0F];
b1[0x10] = b2[0x10] + b2[0x11];
b1[0x11] = REAL_MUL(b2[0x10] - b2[0x11], cos0);
b1[0x12] = b2[0x12] + b2[0x13];
b1[0x13] = REAL_MUL(b2[0x13] - b2[0x12], cos0);
b1[0x12] += b1[0x13];
b1[0x14] = b2[0x14] + b2[0x15];
b1[0x15] = REAL_MUL(b2[0x14] - b2[0x15], cos0);
b1[0x16] = b2[0x16] + b2[0x17];
b1[0x17] = REAL_MUL(b2[0x17] - b2[0x16], cos0);
b1[0x16] += b1[0x17];
b1[0x14] += b1[0x16];
b1[0x16] += b1[0x15];
b1[0x15] += b1[0x17];
b1[0x18] = b2[0x18] + b2[0x19];
b1[0x19] = REAL_MUL(b2[0x18] - b2[0x19], cos0);
b1[0x1A] = b2[0x1A] + b2[0x1B];
b1[0x1B] = REAL_MUL(b2[0x1B] - b2[0x1A], cos0);
b1[0x1A] += b1[0x1B];
b1[0x1C] = b2[0x1C] + b2[0x1D];
b1[0x1D] = REAL_MUL(b2[0x1C] - b2[0x1D], cos0);
b1[0x1E] = b2[0x1E] + b2[0x1F];
b1[0x1F] = REAL_MUL(b2[0x1F] - b2[0x1E], cos0);
b1[0x1E] += b1[0x1F];
b1[0x1C] += b1[0x1E];
b1[0x1E] += b1[0x1D];
b1[0x1D] += b1[0x1F];
}
out0[0x10*16] = REAL_SCALE_DCT64(b1[0x00]);
out0[0x10*12] = REAL_SCALE_DCT64(b1[0x04]);
out0[0x10* 8] = REAL_SCALE_DCT64(b1[0x02]);
out0[0x10* 4] = REAL_SCALE_DCT64(b1[0x06]);
out0[0x10* 0] = REAL_SCALE_DCT64(b1[0x01]);
out1[0x10* 0] = REAL_SCALE_DCT64(b1[0x01]);
out1[0x10* 4] = REAL_SCALE_DCT64(b1[0x05]);
out1[0x10* 8] = REAL_SCALE_DCT64(b1[0x03]);
out1[0x10*12] = REAL_SCALE_DCT64(b1[0x07]);
#if 1
out0[0x10*14] = REAL_SCALE_DCT64(b1[0x08] + b1[0x0C]);
out0[0x10*10] = REAL_SCALE_DCT64(b1[0x0C] + b1[0x0a]);
out0[0x10* 6] = REAL_SCALE_DCT64(b1[0x0A] + b1[0x0E]);
out0[0x10* 2] = REAL_SCALE_DCT64(b1[0x0E] + b1[0x09]);
out1[0x10* 2] = REAL_SCALE_DCT64(b1[0x09] + b1[0x0D]);
out1[0x10* 6] = REAL_SCALE_DCT64(b1[0x0D] + b1[0x0B]);
out1[0x10*10] = REAL_SCALE_DCT64(b1[0x0B] + b1[0x0F]);
out1[0x10*14] = REAL_SCALE_DCT64(b1[0x0F]);
#else
b1[0x08] += b1[0x0C];
out0[0x10*14] = REAL_SCALE_DCT64(b1[0x08]);
b1[0x0C] += b1[0x0a];
out0[0x10*10] = REAL_SCALE_DCT64(b1[0x0C]);
b1[0x0A] += b1[0x0E];
out0[0x10* 6] = REAL_SCALE_DCT64(b1[0x0A]);
b1[0x0E] += b1[0x09];
out0[0x10* 2] = REAL_SCALE_DCT64(b1[0x0E]);
b1[0x09] += b1[0x0D];
out1[0x10* 2] = REAL_SCALE_DCT64(b1[0x09]);
b1[0x0D] += b1[0x0B];
out1[0x10* 6] = REAL_SCALE_DCT64(b1[0x0D]);
b1[0x0B] += b1[0x0F];
out1[0x10*10] = REAL_SCALE_DCT64(b1[0x0B]);
out1[0x10*14] = REAL_SCALE_DCT64(b1[0x0F]);
#endif
{
real tmp;
tmp = b1[0x18] + b1[0x1C];
out0[0x10*15] = REAL_SCALE_DCT64(tmp + b1[0x10]);
out0[0x10*13] = REAL_SCALE_DCT64(tmp + b1[0x14]);
tmp = b1[0x1C] + b1[0x1A];
out0[0x10*11] = REAL_SCALE_DCT64(tmp + b1[0x14]);
out0[0x10* 9] = REAL_SCALE_DCT64(tmp + b1[0x12]);
tmp = b1[0x1A] + b1[0x1E];
out0[0x10* 7] = REAL_SCALE_DCT64(tmp + b1[0x12]);
out0[0x10* 5] = REAL_SCALE_DCT64(tmp + b1[0x16]);
tmp = b1[0x1E] + b1[0x19];
out0[0x10* 3] = REAL_SCALE_DCT64(tmp + b1[0x16]);
out0[0x10* 1] = REAL_SCALE_DCT64(tmp + b1[0x11]);
tmp = b1[0x19] + b1[0x1D];
out1[0x10* 1] = REAL_SCALE_DCT64(tmp + b1[0x11]);
out1[0x10* 3] = REAL_SCALE_DCT64(tmp + b1[0x15]);
tmp = b1[0x1D] + b1[0x1B];
out1[0x10* 5] = REAL_SCALE_DCT64(tmp + b1[0x15]);
out1[0x10* 7] = REAL_SCALE_DCT64(tmp + b1[0x13]);
tmp = b1[0x1B] + b1[0x1F];
out1[0x10* 9] = REAL_SCALE_DCT64(tmp + b1[0x13]);
out1[0x10*11] = REAL_SCALE_DCT64(tmp + b1[0x17]);
out1[0x10*13] = REAL_SCALE_DCT64(b1[0x17] + b1[0x1F]);
out1[0x10*15] = REAL_SCALE_DCT64(b1[0x1F]);
}
}
/*
* the call via dct64 is a trick to force GCC to use
* (new) registers for the b1,b2 pointer to the bufs[xx] field
*/
void dct64_i386(real *a,real *b,real *c)
{
real bufs[0x40];
dct64_1(a,b,bufs,bufs+0x20,c);
}

View File

@ -0,0 +1,815 @@
/*
dct64_mmx.s: MMX optimized DCT64
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 the mysterious higway (apparently)
*/
#include "mangle.h"
.text
ALIGN32
.globl ASM_NAME(dct64_mmx)
ASM_NAME(dct64_mmx):
xorl %ecx,%ecx
.globl ASM_NAME(dct64_MMX)
ASM_NAME(dct64_MMX):
pushl %ebx
pushl %esi
pushl %edi
subl $256,%esp
movl 280(%esp),%eax
flds (%eax)
leal 128(%esp),%edx
fadds 124(%eax)
movl 272(%esp),%esi
fstps (%edx)
movl 276(%esp),%edi
flds 4(%eax)
movl ASM_VALUE(costab_mmxsse),%ebx
fadds 120(%eax)
orl %ecx,%ecx
fstps 4(%edx)
flds (%eax)
movl %esp,%ecx
fsubs 124(%eax)
fmuls (%ebx)
fstps 124(%edx)
flds 4(%eax)
fsubs 120(%eax)
fmuls 4(%ebx)
fstps 120(%edx)
flds 8(%eax)
fadds 116(%eax)
fstps 8(%edx)
flds 12(%eax)
fadds 112(%eax)
fstps 12(%edx)
flds 8(%eax)
fsubs 116(%eax)
fmuls 8(%ebx)
fstps 116(%edx)
flds 12(%eax)
fsubs 112(%eax)
fmuls 12(%ebx)
fstps 112(%edx)
flds 16(%eax)
fadds 108(%eax)
fstps 16(%edx)
flds 20(%eax)
fadds 104(%eax)
fstps 20(%edx)
flds 16(%eax)
fsubs 108(%eax)
fmuls 16(%ebx)
fstps 108(%edx)
flds 20(%eax)
fsubs 104(%eax)
fmuls 20(%ebx)
fstps 104(%edx)
flds 24(%eax)
fadds 100(%eax)
fstps 24(%edx)
flds 28(%eax)
fadds 96(%eax)
fstps 28(%edx)
flds 24(%eax)
fsubs 100(%eax)
fmuls 24(%ebx)
fstps 100(%edx)
flds 28(%eax)
fsubs 96(%eax)
fmuls 28(%ebx)
fstps 96(%edx)
flds 32(%eax)
fadds 92(%eax)
fstps 32(%edx)
flds 36(%eax)
fadds 88(%eax)
fstps 36(%edx)
flds 32(%eax)
fsubs 92(%eax)
fmuls 32(%ebx)
fstps 92(%edx)
flds 36(%eax)
fsubs 88(%eax)
fmuls 36(%ebx)
fstps 88(%edx)
flds 40(%eax)
fadds 84(%eax)
fstps 40(%edx)
flds 44(%eax)
fadds 80(%eax)
fstps 44(%edx)
flds 40(%eax)
fsubs 84(%eax)
fmuls 40(%ebx)
fstps 84(%edx)
flds 44(%eax)
fsubs 80(%eax)
fmuls 44(%ebx)
fstps 80(%edx)
flds 48(%eax)
fadds 76(%eax)
fstps 48(%edx)
flds 52(%eax)
fadds 72(%eax)
fstps 52(%edx)
flds 48(%eax)
fsubs 76(%eax)
fmuls 48(%ebx)
fstps 76(%edx)
flds 52(%eax)
fsubs 72(%eax)
fmuls 52(%ebx)
fstps 72(%edx)
flds 56(%eax)
fadds 68(%eax)
fstps 56(%edx)
flds 60(%eax)
fadds 64(%eax)
fstps 60(%edx)
flds 56(%eax)
fsubs 68(%eax)
fmuls 56(%ebx)
fstps 68(%edx)
flds 60(%eax)
fsubs 64(%eax)
fmuls 60(%ebx)
fstps 64(%edx)
flds (%edx)
fadds 60(%edx)
fstps (%ecx)
flds 4(%edx)
fadds 56(%edx)
fstps 4(%ecx)
flds (%edx)
fsubs 60(%edx)
fmuls 64(%ebx)
fstps 60(%ecx)
flds 4(%edx)
fsubs 56(%edx)
fmuls 68(%ebx)
fstps 56(%ecx)
flds 8(%edx)
fadds 52(%edx)
fstps 8(%ecx)
flds 12(%edx)
fadds 48(%edx)
fstps 12(%ecx)
flds 8(%edx)
fsubs 52(%edx)
fmuls 72(%ebx)
fstps 52(%ecx)
flds 12(%edx)
fsubs 48(%edx)
fmuls 76(%ebx)
fstps 48(%ecx)
flds 16(%edx)
fadds 44(%edx)
fstps 16(%ecx)
flds 20(%edx)
fadds 40(%edx)
fstps 20(%ecx)
flds 16(%edx)
fsubs 44(%edx)
fmuls 80(%ebx)
fstps 44(%ecx)
flds 20(%edx)
fsubs 40(%edx)
fmuls 84(%ebx)
fstps 40(%ecx)
flds 24(%edx)
fadds 36(%edx)
fstps 24(%ecx)
flds 28(%edx)
fadds 32(%edx)
fstps 28(%ecx)
flds 24(%edx)
fsubs 36(%edx)
fmuls 88(%ebx)
fstps 36(%ecx)
flds 28(%edx)
fsubs 32(%edx)
fmuls 92(%ebx)
fstps 32(%ecx)
flds 64(%edx)
fadds 124(%edx)
fstps 64(%ecx)
flds 68(%edx)
fadds 120(%edx)
fstps 68(%ecx)
flds 124(%edx)
fsubs 64(%edx)
fmuls 64(%ebx)
fstps 124(%ecx)
flds 120(%edx)
fsubs 68(%edx)
fmuls 68(%ebx)
fstps 120(%ecx)
flds 72(%edx)
fadds 116(%edx)
fstps 72(%ecx)
flds 76(%edx)
fadds 112(%edx)
fstps 76(%ecx)
flds 116(%edx)
fsubs 72(%edx)
fmuls 72(%ebx)
fstps 116(%ecx)
flds 112(%edx)
fsubs 76(%edx)
fmuls 76(%ebx)
fstps 112(%ecx)
flds 80(%edx)
fadds 108(%edx)
fstps 80(%ecx)
flds 84(%edx)
fadds 104(%edx)
fstps 84(%ecx)
flds 108(%edx)
fsubs 80(%edx)
fmuls 80(%ebx)
fstps 108(%ecx)
flds 104(%edx)
fsubs 84(%edx)
fmuls 84(%ebx)
fstps 104(%ecx)
flds 88(%edx)
fadds 100(%edx)
fstps 88(%ecx)
flds 92(%edx)
fadds 96(%edx)
fstps 92(%ecx)
flds 100(%edx)
fsubs 88(%edx)
fmuls 88(%ebx)
fstps 100(%ecx)
flds 96(%edx)
fsubs 92(%edx)
fmuls 92(%ebx)
fstps 96(%ecx)
flds (%ecx)
fadds 28(%ecx)
fstps (%edx)
flds (%ecx)
fsubs 28(%ecx)
fmuls 96(%ebx)
fstps 28(%edx)
flds 4(%ecx)
fadds 24(%ecx)
fstps 4(%edx)
flds 4(%ecx)
fsubs 24(%ecx)
fmuls 100(%ebx)
fstps 24(%edx)
flds 8(%ecx)
fadds 20(%ecx)
fstps 8(%edx)
flds 8(%ecx)
fsubs 20(%ecx)
fmuls 104(%ebx)
fstps 20(%edx)
flds 12(%ecx)
fadds 16(%ecx)
fstps 12(%edx)
flds 12(%ecx)
fsubs 16(%ecx)
fmuls 108(%ebx)
fstps 16(%edx)
flds 32(%ecx)
fadds 60(%ecx)
fstps 32(%edx)
flds 60(%ecx)
fsubs 32(%ecx)
fmuls 96(%ebx)
fstps 60(%edx)
flds 36(%ecx)
fadds 56(%ecx)
fstps 36(%edx)
flds 56(%ecx)
fsubs 36(%ecx)
fmuls 100(%ebx)
fstps 56(%edx)
flds 40(%ecx)
fadds 52(%ecx)
fstps 40(%edx)
flds 52(%ecx)
fsubs 40(%ecx)
fmuls 104(%ebx)
fstps 52(%edx)
flds 44(%ecx)
fadds 48(%ecx)
fstps 44(%edx)
flds 48(%ecx)
fsubs 44(%ecx)
fmuls 108(%ebx)
fstps 48(%edx)
flds 64(%ecx)
fadds 92(%ecx)
fstps 64(%edx)
flds 64(%ecx)
fsubs 92(%ecx)
fmuls 96(%ebx)
fstps 92(%edx)
flds 68(%ecx)
fadds 88(%ecx)
fstps 68(%edx)
flds 68(%ecx)
fsubs 88(%ecx)
fmuls 100(%ebx)
fstps 88(%edx)
flds 72(%ecx)
fadds 84(%ecx)
fstps 72(%edx)
flds 72(%ecx)
fsubs 84(%ecx)
fmuls 104(%ebx)
fstps 84(%edx)
flds 76(%ecx)
fadds 80(%ecx)
fstps 76(%edx)
flds 76(%ecx)
fsubs 80(%ecx)
fmuls 108(%ebx)
fstps 80(%edx)
flds 96(%ecx)
fadds 124(%ecx)
fstps 96(%edx)
flds 124(%ecx)
fsubs 96(%ecx)
fmuls 96(%ebx)
fstps 124(%edx)
flds 100(%ecx)
fadds 120(%ecx)
fstps 100(%edx)
flds 120(%ecx)
fsubs 100(%ecx)
fmuls 100(%ebx)
fstps 120(%edx)
flds 104(%ecx)
fadds 116(%ecx)
fstps 104(%edx)
flds 116(%ecx)
fsubs 104(%ecx)
fmuls 104(%ebx)
fstps 116(%edx)
flds 108(%ecx)
fadds 112(%ecx)
fstps 108(%edx)
flds 112(%ecx)
fsubs 108(%ecx)
fmuls 108(%ebx)
fstps 112(%edx)
flds (%edx)
fadds 12(%edx)
fstps (%ecx)
flds (%edx)
fsubs 12(%edx)
fmuls 112(%ebx)
fstps 12(%ecx)
flds 4(%edx)
fadds 8(%edx)
fstps 4(%ecx)
flds 4(%edx)
fsubs 8(%edx)
fmuls 116(%ebx)
fstps 8(%ecx)
flds 16(%edx)
fadds 28(%edx)
fstps 16(%ecx)
flds 28(%edx)
fsubs 16(%edx)
fmuls 112(%ebx)
fstps 28(%ecx)
flds 20(%edx)
fadds 24(%edx)
fstps 20(%ecx)
flds 24(%edx)
fsubs 20(%edx)
fmuls 116(%ebx)
fstps 24(%ecx)
flds 32(%edx)
fadds 44(%edx)
fstps 32(%ecx)
flds 32(%edx)
fsubs 44(%edx)
fmuls 112(%ebx)
fstps 44(%ecx)
flds 36(%edx)
fadds 40(%edx)
fstps 36(%ecx)
flds 36(%edx)
fsubs 40(%edx)
fmuls 116(%ebx)
fstps 40(%ecx)
flds 48(%edx)
fadds 60(%edx)
fstps 48(%ecx)
flds 60(%edx)
fsubs 48(%edx)
fmuls 112(%ebx)
fstps 60(%ecx)
flds 52(%edx)
fadds 56(%edx)
fstps 52(%ecx)
flds 56(%edx)
fsubs 52(%edx)
fmuls 116(%ebx)
fstps 56(%ecx)
flds 64(%edx)
fadds 76(%edx)
fstps 64(%ecx)
flds 64(%edx)
fsubs 76(%edx)
fmuls 112(%ebx)
fstps 76(%ecx)
flds 68(%edx)
fadds 72(%edx)
fstps 68(%ecx)
flds 68(%edx)
fsubs 72(%edx)
fmuls 116(%ebx)
fstps 72(%ecx)
flds 80(%edx)
fadds 92(%edx)
fstps 80(%ecx)
flds 92(%edx)
fsubs 80(%edx)
fmuls 112(%ebx)
fstps 92(%ecx)
flds 84(%edx)
fadds 88(%edx)
fstps 84(%ecx)
flds 88(%edx)
fsubs 84(%edx)
fmuls 116(%ebx)
fstps 88(%ecx)
flds 96(%edx)
fadds 108(%edx)
fstps 96(%ecx)
flds 96(%edx)
fsubs 108(%edx)
fmuls 112(%ebx)
fstps 108(%ecx)
flds 100(%edx)
fadds 104(%edx)
fstps 100(%ecx)
flds 100(%edx)
fsubs 104(%edx)
fmuls 116(%ebx)
fstps 104(%ecx)
flds 112(%edx)
fadds 124(%edx)
fstps 112(%ecx)
flds 124(%edx)
fsubs 112(%edx)
fmuls 112(%ebx)
fstps 124(%ecx)
flds 116(%edx)
fadds 120(%edx)
fstps 116(%ecx)
flds 120(%edx)
fsubs 116(%edx)
fmuls 116(%ebx)
fstps 120(%ecx)
flds 32(%ecx)
fadds 36(%ecx)
fstps 32(%edx)
flds 32(%ecx)
fsubs 36(%ecx)
fmuls 120(%ebx)
fstps 36(%edx)
flds 44(%ecx)
fsubs 40(%ecx)
fmuls 120(%ebx)
fsts 44(%edx)
fadds 40(%ecx)
fadds 44(%ecx)
fstps 40(%edx)
flds 48(%ecx)
fsubs 52(%ecx)
fmuls 120(%ebx)
flds 60(%ecx)
fsubs 56(%ecx)
fmuls 120(%ebx)
fld %st(0)
fadds 56(%ecx)
fadds 60(%ecx)
fld %st(0)
fadds 48(%ecx)
fadds 52(%ecx)
fstps 48(%edx)
fadd %st(2)
fstps 56(%edx)
fsts 60(%edx)
faddp %st(1)
fstps 52(%edx)
flds 64(%ecx)
fadds 68(%ecx)
fstps 64(%edx)
flds 64(%ecx)
fsubs 68(%ecx)
fmuls 120(%ebx)
fstps 68(%edx)
flds 76(%ecx)
fsubs 72(%ecx)
fmuls 120(%ebx)
fsts 76(%edx)
fadds 72(%ecx)
fadds 76(%ecx)
fstps 72(%edx)
flds 92(%ecx)
fsubs 88(%ecx)
fmuls 120(%ebx)
fsts 92(%edx)
fadds 92(%ecx)
fadds 88(%ecx)
fld %st(0)
fadds 80(%ecx)
fadds 84(%ecx)
fstps 80(%edx)
flds 80(%ecx)
fsubs 84(%ecx)
fmuls 120(%ebx)
fadd %st(0), %st(1)
fadds 92(%edx)
fstps 84(%edx)
fstps 88(%edx)
flds 96(%ecx)
fadds 100(%ecx)
fstps 96(%edx)
flds 96(%ecx)
fsubs 100(%ecx)
fmuls 120(%ebx)
fstps 100(%edx)
flds 108(%ecx)
fsubs 104(%ecx)
fmuls 120(%ebx)
fsts 108(%edx)
fadds 104(%ecx)
fadds 108(%ecx)
fstps 104(%edx)
flds 124(%ecx)
fsubs 120(%ecx)
fmuls 120(%ebx)
fsts 124(%edx)
fadds 120(%ecx)
fadds 124(%ecx)
fld %st(0)
fadds 112(%ecx)
fadds 116(%ecx)
fstps 112(%edx)
flds 112(%ecx)
fsubs 116(%ecx)
fmuls 120(%ebx)
fadd %st(0),%st(1)
fadds 124(%edx)
fstps 116(%edx)
fstps 120(%edx)
jnz .L01
flds (%ecx)
fadds 4(%ecx)
fstps 1024(%esi)
flds (%ecx)
fsubs 4(%ecx)
fmuls 120(%ebx)
fsts (%esi)
fstps (%edi)
flds 12(%ecx)
fsubs 8(%ecx)
fmuls 120(%ebx)
fsts 512(%edi)
fadds 12(%ecx)
fadds 8(%ecx)
fstps 512(%esi)
flds 16(%ecx)
fsubs 20(%ecx)
fmuls 120(%ebx)
flds 28(%ecx)
fsubs 24(%ecx)
fmuls 120(%ebx)
fsts 768(%edi)
fld %st(0)
fadds 24(%ecx)
fadds 28(%ecx)
fld %st(0)
fadds 16(%ecx)
fadds 20(%ecx)
fstps 768(%esi)
fadd %st(2)
fstps 256(%esi)
faddp %st(1)
fstps 256(%edi)
flds 32(%edx)
fadds 48(%edx)
fstps 896(%esi)
flds 48(%edx)
fadds 40(%edx)
fstps 640(%esi)
flds 40(%edx)
fadds 56(%edx)
fstps 384(%esi)
flds 56(%edx)
fadds 36(%edx)
fstps 128(%esi)
flds 36(%edx)
fadds 52(%edx)
fstps 128(%edi)
flds 52(%edx)
fadds 44(%edx)
fstps 384(%edi)
flds 60(%edx)
fsts 896(%edi)
fadds 44(%edx)
fstps 640(%edi)
flds 96(%edx)
fadds 112(%edx)
fld %st(0)
fadds 64(%edx)
fstps 960(%esi)
fadds 80(%edx)
fstps 832(%esi)
flds 112(%edx)
fadds 104(%edx)
fld %st(0)
fadds 80(%edx)
fstps 704(%esi)
fadds 72(%edx)
fstps 576(%esi)
flds 104(%edx)
fadds 120(%edx)
fld %st(0)
fadds 72(%edx)
fstps 448(%esi)
fadds 88(%edx)
fstps 320(%esi)
flds 120(%edx)
fadds 100(%edx)
fld %st(0)
fadds 88(%edx)
fstps 192(%esi)
fadds 68(%edx)
fstps 64(%esi)
flds 100(%edx)
fadds 116(%edx)
fld %st(0)
fadds 68(%edx)
fstps 64(%edi)
fadds 84(%edx)
fstps 192(%edi)
flds 116(%edx)
fadds 108(%edx)
fld %st(0)
fadds 84(%edx)
fstps 320(%edi)
fadds 76(%edx)
fstps 448(%edi)
flds 108(%edx)
fadds 124(%edx)
fld %st(0)
fadds 76(%edx)
fstps 576(%edi)
fadds 92(%edx)
fstps 704(%edi)
flds 124(%edx)
fsts 960(%edi)
fadds 92(%edx)
fstps 832(%edi)
addl $256,%esp
popl %edi
popl %esi
popl %ebx
ret
.L01:
flds (%ecx)
fadds 4(%ecx)
fistps 512(%esi)
flds (%ecx)
fsubs 4(%ecx)
fmuls 120(%ebx)
fistps (%esi)
flds 12(%ecx)
fsubs 8(%ecx)
fmuls 120(%ebx)
fists 256(%edi)
fadds 12(%ecx)
fadds 8(%ecx)
fistps 256(%esi)
flds 16(%ecx)
fsubs 20(%ecx)
fmuls 120(%ebx)
flds 28(%ecx)
fsubs 24(%ecx)
fmuls 120(%ebx)
fists 384(%edi)
fld %st(0)
fadds 24(%ecx)
fadds 28(%ecx)
fld %st(0)
fadds 16(%ecx)
fadds 20(%ecx)
fistps 384(%esi)
fadd %st(2)
fistps 128(%esi)
faddp %st(1)
fistps 128(%edi)
flds 32(%edx)
fadds 48(%edx)
fistps 448(%esi)
flds 48(%edx)
fadds 40(%edx)
fistps 320(%esi)
flds 40(%edx)
fadds 56(%edx)
fistps 192(%esi)
flds 56(%edx)
fadds 36(%edx)
fistps 64(%esi)
flds 36(%edx)
fadds 52(%edx)
fistps 64(%edi)
flds 52(%edx)
fadds 44(%edx)
fistps 192(%edi)
flds 60(%edx)
fists 448(%edi)
fadds 44(%edx)
fistps 320(%edi)
flds 96(%edx)
fadds 112(%edx)
fld %st(0)
fadds 64(%edx)
fistps 480(%esi)
fadds 80(%edx)
fistps 416(%esi)
flds 112(%edx)
fadds 104(%edx)
fld %st(0)
fadds 80(%edx)
fistps 352(%esi)
fadds 72(%edx)
fistps 288(%esi)
flds 104(%edx)
fadds 120(%edx)
fld %st(0)
fadds 72(%edx)
fistps 224(%esi)
fadds 88(%edx)
fistps 160(%esi)
flds 120(%edx)
fadds 100(%edx)
fld %st(0)
fadds 88(%edx)
fistps 96(%esi)
fadds 68(%edx)
fistps 32(%esi)
flds 100(%edx)
fadds 116(%edx)
fld %st(0)
fadds 68(%edx)
fistps 32(%edi)
fadds 84(%edx)
fistps 96(%edi)
flds 116(%edx)
fadds 108(%edx)
fld %st(0)
fadds 84(%edx)
fistps 160(%edi)
fadds 76(%edx)
fistps 224(%edi)
flds 108(%edx)
fadds 124(%edx)
fld %st(0)
fadds 76(%edx)
fistps 288(%edi)
fadds 92(%edx)
fistps 352(%edi)
flds 124(%edx)
fists 480(%edi)
fadds 92(%edx)
fistps 416(%edi)
movsw
addl $256,%esp
popl %edi
popl %esi
popl %ebx
ret
/* Mark non-executable stack. */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@ -0,0 +1,171 @@
/*
debug.h:
if DEBUG defined: debugging macro fprintf wrappers
else: macros defined to do nothing
That saves typing #ifdef DEBUG all the time and still preserves
lean code without debugging.
public domain (or LGPL / GPL, if you like that more;-)
generated by debugdef.pl, what was
trivially written by Thomas Orgis <thomas@orgis.org>
*/
#include "config.h"
/*
I could do that with variadic macros available:
#define sdebug(me, s) fprintf(stderr, "[location] " s "\n")
#define debug(me, s, ...) fprintf(stderr, "[location] " s "}n", __VA_ARGS__)
Variadic macros are a C99 feature...
Now just predefining stuff non-variadic for up to 15 arguments.
It's cumbersome to have them all with different names, though...
*/
#ifdef DEBUG
#include <stdio.h>
#define debug(s) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__)
#define debug1(s, a) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a)
#define debug2(s, a, b) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b)
#define debug3(s, a, b, c) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c)
#define debug4(s, a, b, c, d) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d)
#define debug5(s, a, b, c, d, e) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e)
#define debug6(s, a, b, c, d, e, f) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f)
#define debug7(s, a, b, c, d, e, f, g) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g)
#define debug8(s, a, b, c, d, e, f, g, h) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
#define debug9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
#define debug10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
#define debug11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#else
#define debug(s)
#define debug1(s, a)
#define debug2(s, a, b)
#define debug3(s, a, b, c)
#define debug4(s, a, b, c, d)
#define debug5(s, a, b, c, d, e)
#define debug6(s, a, b, c, d, e, f)
#define debug7(s, a, b, c, d, e, f, g)
#define debug8(s, a, b, c, d, e, f, g, h)
#define debug9(s, a, b, c, d, e, f, g, h, i)
#define debug10(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)
#define debug12(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)
#define debug14(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)
#endif
/* warning macros also here... */
#ifndef NO_WARNING
#define warning(s) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__)
#define warning1(s, a) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a)
#define warning2(s, a, b) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b)
#define warning3(s, a, b, c) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c)
#define warning4(s, a, b, c, d) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d)
#define warning5(s, a, b, c, d, e) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e)
#define warning6(s, a, b, c, d, e, f) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f)
#define warning7(s, a, b, c, d, e, f, g) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g)
#define warning8(s, a, b, c, d, e, f, g, h) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
#define warning9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
#define warning10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
#define warning11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#else
#define warning(s)
#define warning1(s, a)
#define warning2(s, a, b)
#define warning3(s, a, b, c)
#define warning4(s, a, b, c, d)
#define warning5(s, a, b, c, d, e)
#define warning6(s, a, b, c, d, e, f)
#define warning7(s, a, b, c, d, e, f, g)
#define warning8(s, a, b, c, d, e, f, g, h)
#define warning9(s, a, b, c, d, e, f, g, h, i)
#define warning10(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)
#define warning12(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)
#define warning14(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)
#endif
/* error macros also here... */
#ifndef NO_ERROR
#define error(s) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__)
#define error1(s, a) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a)
#define error2(s, a, b) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b)
#define error3(s, a, b, c) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c)
#define error4(s, a, b, c, d) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d)
#define error5(s, a, b, c, d, e) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e)
#define error6(s, a, b, c, d, e, f) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f)
#define error7(s, a, b, c, d, e, f, g) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g)
#define error8(s, a, b, c, d, e, f, g, h) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
#define error9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
#define error10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
#define error11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, 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) fprintf(stderr, "[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
#else
#define error(s)
#define error1(s, a)
#define error2(s, a, b)
#define error3(s, a, b, c)
#define error4(s, a, b, c, d)
#define error5(s, a, b, c, d, e)
#define error6(s, a, b, c, d, e, f)
#define error7(s, a, b, c, d, e, f, g)
#define error8(s, a, b, c, d, e, f, g, h)
#define error9(s, a, b, c, d, e, f, g, h, i)
#define error10(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)
#define error12(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)
#define error14(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)
#endif
/* ereturn macros also here... */
#ifndef NO_ERETURN
#define ereturn(rv, s) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__); return rv; }while(0)
#define ereturn1(rv, s, a) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a); return rv; }while(0)
#define ereturn2(rv, s, a, b) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b); return rv; }while(0)
#define ereturn3(rv, s, a, b, c) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c); return rv; }while(0)
#define ereturn4(rv, s, a, b, c, d) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d); return rv; }while(0)
#define ereturn5(rv, s, a, b, c, d, e) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e); return rv; }while(0)
#define ereturn6(rv, s, a, b, c, d, e, f) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f); return rv; }while(0)
#define ereturn7(rv, s, a, b, c, d, e, f, g) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g); return rv; }while(0)
#define ereturn8(rv, s, a, b, c, d, e, f, g, h) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h); return rv; }while(0)
#define ereturn9(rv, s, a, b, c, d, e, f, g, h, i) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i); return rv; }while(0)
#define ereturn10(rv, s, a, b, c, d, e, f, g, h, i, j) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j); return rv; }while(0)
#define ereturn11(rv, s, a, b, c, d, e, f, g, h, i, j, k) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k); return rv; }while(0)
#define ereturn12(rv, s, a, b, c, d, e, f, g, h, i, j, k, l) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l); return rv; }while(0)
#define ereturn13(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m); return rv; }while(0)
#define ereturn14(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n); return rv; }while(0)
#define ereturn15(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) do{ fprintf(stderr, "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); return rv; }while(0)
#else
#define ereturn(rv, s) return rv
#define ereturn1(rv, s, a) return rv
#define ereturn2(rv, s, a, b) return rv
#define ereturn3(rv, s, a, b, c) return rv
#define ereturn4(rv, s, a, b, c, d) return rv
#define ereturn5(rv, s, a, b, c, d, e) return rv
#define ereturn6(rv, s, a, b, c, d, e, f) return rv
#define ereturn7(rv, s, a, b, c, d, e, f, g) return rv
#define ereturn8(rv, s, a, b, c, d, e, f, g, h) return rv
#define ereturn9(rv, s, a, b, c, d, e, f, g, h, i) return rv
#define ereturn10(rv, s, a, b, c, d, e, f, g, h, i, j) return rv
#define ereturn11(rv, s, a, b, c, d, e, f, g, h, i, j, k) return rv
#define ereturn12(rv, s, a, b, c, d, e, f, g, h, i, j, k, l) return rv
#define ereturn13(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m) return rv
#define ereturn14(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) return rv
#define ereturn15(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) return rv
#endif

View File

@ -0,0 +1,260 @@
/*
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)
#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. */
/* The call of left and right plain synth, wrapped.
This may be replaced by a direct stereo optimized synth. */
int synth_stereo_wrap(real*, real*, mpg123_handle*);
#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_arm (real*, int, mpg123_handle*, int);
/* 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_mono2stereo(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_mono2stereo(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_mono2stereo(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_mono2stereo (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_mono2stereo(real*, mpg123_handle*);
#ifndef NO_16BIT
int synth_1to1_8bit_wrap_mono (real*, mpg123_handle*);
int synth_1to1_8bit_wrap_mono2stereo(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_mono2stereo(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_mono2stereo(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_mono2stereo(real*, mpg123_handle*);
void ntom_set_ntom(mpg123_handle *fr, off_t num);
#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_altivec (real*, int, mpg123_handle*, int);
int synth_1to1_real_stereo_altivec(real*, real*, mpg123_handle*);
int synth_1to1_real_mono (real*, mpg123_handle*);
int synth_1to1_real_mono2stereo(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_mono2stereo(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_mono2stereo(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_mono2stereo(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_altivec (real*, int, mpg123_handle*, int);
int synth_1to1_s32_stereo_altivec(real*, real*, mpg123_handle*);
int synth_1to1_s32_mono (real*, mpg123_handle*);
int synth_1to1_s32_mono2stereo(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_mono2stereo(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_mono2stereo(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_mono2stereo(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 *,real *,real *);
void dct36_3dnow (real *,real *,real *,real *,real *);
void dct36_3dnowext(real *,real *,real *,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
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
void init_layer3(void);
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
void init_layer12(void);
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
void prepare_decode_tables(void);
extern real *pnts[5]; /* tabinit 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,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,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,395 @@
/*
format:routines to deal with audio (output) format
copyright 2008-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, starting with parts of the old audio.c, with only faintly manage to show now
*/
#include "mpg123lib_intern.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_FLOAT_32,
MPG123_ENC_FLOAT_64,
MPG123_ENC_SIGNED_8,
MPG123_ENC_UNSIGNED_8,
MPG123_ENC_ULAW_8,
MPG123_ENC_ALAW_8
};
/* Only one type of float is supported. */
# ifdef REAL_IS_FLOAT
# define MPG123_FLOAT_ENC MPG123_ENC_FLOAT_32
# else
# define MPG123_FLOAT_ENC MPG123_ENC_FLOAT_64
# 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,
#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);
}
/* 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_handle *fr, struct audioformat *nf, int f0, int f2)
{
int i;
int c = nf->channels-1;
int rn = rate2num(&fr->p, nf->rate);
if(rn >= 0) for(i=f0;i<f2;i++)
{
if(fr->p.audio_caps[c][rn][i])
{
nf->encoding = my_encodings[i];
return 1;
}
}
return 0;
}
static int freq_fit(mpg123_handle *fr, struct audioformat *nf, int f0, int f2)
{
nf->rate = frame_freq(fr)>>fr->p.down_sample;
if(cap_fit(fr,nf,f0,f2)) return 1;
nf->rate>>=1;
if(cap_fit(fr,nf,f0,f2)) return 1;
nf->rate>>=1;
if(cap_fit(fr,nf,f0,f2)) return 1;
#ifndef NO_NTOM
/* If nothing worked, try the other rates, only without constrains from user.
In case you didn't guess: We enable flexible resampling if we find a working rate. */
if(!fr->p.force_rate && fr->p.down_sample == 0)
{
int i;
int c = nf->channels-1;
int rn = rate2num(&fr->p, frame_freq(fr));
int rrn;
if(rn < 0) return 0;
/* Try higher rates first. */
for(i=f0;i<f2;i++) for(rrn=rn+1; rrn<MPG123_RATES; ++rrn)
if(fr->p.audio_caps[c][rrn][i])
{
nf->rate = my_rates[rrn];
nf->encoding = my_encodings[i];
return 1;
}
/* Then lower rates. */
for(i=f0;i<f2;i++) for(rrn=rn-1; rrn>=0; --rrn)
if(fr->p.audio_caps[c][rrn][i])
{
nf->rate = my_rates[rrn];
nf->encoding = my_encodings[i];
return 1;
}
}
#endif
return 0;
}
/* 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; /* Omit the 32bit and float encodings. */
mpg123_pars *p = &fr->p;
/* initialize new format, encoding comes later */
nf.channels = fr->stereo;
/* All this forcing should be removed in favour of the capabilities table... */
if(p->flags & MPG123_FORCE_8BIT)
{
f0 = 6;
f2 = 10;
}
if(p->flags & MPG123_FORCE_FLOAT)
{
f0 = 4;
f2 = 6;
}
/* force stereo is stronger */
if(p->flags & MPG123_FORCE_MONO) nf.channels = 1;
if(p->flags & MPG123_FORCE_STEREO) nf.channels = 2;
#ifndef NO_NTOM
if(p->force_rate)
{
nf.rate = p->force_rate;
if(cap_fit(fr,&nf,f0,2)) goto end; /* 16bit encodings */
if(cap_fit(fr,&nf,f0<=2 ? 2 : f0,f2)) goto end; /* 8bit encodings */
/* 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(fr,&nf,f0,2)) goto end; /* 16bit encodings */
if(cap_fit(fr,&nf,f0<=2 ? 2 : f0,f2)) goto end; /* 8bit encodings */
if(NOQUIET)
error3( "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_8BIT ? "8bit, " : ""),
p->force_rate );
/* if(NOQUIET && p->verbose <= 1) print_capabilities(fr); */
fr->err = MPG123_BAD_OUTFORMAT;
return -1;
}
#endif
if(freq_fit(fr, &nf, f0, 2)) goto end; /* try rates with 16bit */
if(freq_fit(fr, &nf, f0<=2 ? 2 : f0, f2)) goto end; /* ... 8bit */
/* 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(freq_fit(fr, &nf, f0, 2)) goto end; /* try rates with 16bit */
if(freq_fit(fr, &nf, f0<=2 ? 2 : f0, f2)) goto end; /* ... 8bit */
/* Here is the _bad_ end. */
if(NOQUIET)
{
error5( "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_8BIT ? "8bit, " : ""),
frame_freq(fr), frame_freq(fr)>>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. */
if(fr->af.encoding & MPG123_ENC_8)
fr->af.encsize = 1;
else if(fr->af.encoding & MPG123_ENC_16)
fr->af.encsize = 2;
else if(fr->af.encoding & MPG123_ENC_32 || fr->af.encoding == MPG123_ENC_FLOAT_32)
fr->af.encsize = 4;
else if(fr->af.encoding == MPG123_ENC_FLOAT_64)
fr->af.encsize = 8;
else
{
if(NOQUIET) error1("Some unknown encoding??? (%i)", fr->af.encoding);
fr->err = MPG123_BAD_OUTFORMAT;
return -1;
}
return 1;
}
}
int attribute_align_arg mpg123_format_none(mpg123_handle *mh)
{
int r;
if(mh == NULL) return MPG123_ERR;
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_ERR;
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_format(mpg123_handle *mh, long rate, int channels, int encodings)
{
int r;
if(mh == NULL) return MPG123_ERR;
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_fmt(mpg123_pars *mp, long rate, int channels, int encodings)
{
int ie, ic, ratei;
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} */
ratei = rate2num(mp, rate);
if(ratei < 0) return MPG123_BAD_RATE;
/* now match the encodings */
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;
}
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;
}
/* 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;
}

View File

@ -0,0 +1,888 @@
/*
frame: Heap of routines dealing with the core mpg123 data structure.
copyright 2008-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
*/
#include "mpg123lib_intern.h"
#include "getcpuflags.h"
#include "debug.h"
static void frame_fixed_reset(mpg123_handle *fr);
/* that's doubled in decode_ntom.c */
#define NTOM_MUL (32768)
#define aligned_pointer(p,type,alignment) \
(((char*)(p)-(char*)NULL) % (alignment)) \
? (type*)((char*)(p) + (alignment) - (((char*)(p)-(char*)NULL) % (alignment))) \
: (type*)(p)
void frame_default_pars(mpg123_pars *mp)
{
mp->outscale = 1.0;
#ifdef GAPLESS
mp->flags = MPG123_GAPLESS;
#else
mp->flags = 0;
#endif
#ifndef NO_NTOM
mp->force_rate = 0;
#endif
mp->down_sample = 0;
mp->rva = 0;
mp->halfspeed = 0;
mp->doublespeed = 0;
mp->verbose = 0;
#ifndef NO_ICY
mp->icy_interval = 0;
#endif
#ifndef WIN32
mp->timeout = 0;
#endif
mp->resync_limit = 1024;
#ifdef FRAME_INDEX
mp->index_size = INDEX_SIZE;
#endif
mp->preframes = 4; /* That's good for layer 3 ISO compliance bitstream. */
mpg123_fmt_all(mp);
}
void frame_init(mpg123_handle *fr)
{
frame_init_par(fr, NULL);
}
void frame_init_par(mpg123_handle *fr, mpg123_pars *mp)
{
fr->own_buffer = FALSE;
fr->buffer.data = NULL;
fr->rawbuffs = NULL;
fr->rawbuffss = 0;
fr->rawdecwin = NULL;
fr->rawdecwins = 0;
#ifndef NO_8BIT
fr->conv16to8_buf = NULL;
#endif
#ifdef OPT_DITHER
fr->dithernoise = NULL;
#endif
fr->xing_toc = NULL;
fr->cpu_opts.type = defdec();
fr->cpu_opts.class = decclass(fr->cpu_opts.type);
#ifndef NO_NTOM
/* these two look unnecessary, check guarantee for synth_ntom_set_step (in control_generic, even)! */
fr->ntom_val[0] = NTOM_MUL>>1;
fr->ntom_val[1] = NTOM_MUL>>1;
fr->ntom_step = NTOM_MUL;
#endif
/* unnecessary: fr->buffer.size = fr->buffer.fill = 0; */
mpg123_reset_eq(fr);
init_icy(&fr->icy);
init_id3(fr);
/* frame_outbuffer is missing... */
/* frame_buffers is missing... that one needs cpu opt setting! */
/* after these... frame_reset is needed before starting full decode */
invalidate_format(&fr->af);
fr->rdat.r_read = NULL;
fr->rdat.r_lseek = NULL;
fr->decoder_change = 1;
fr->err = MPG123_OK;
if(mp == NULL) frame_default_pars(&fr->p);
else memcpy(&fr->p, mp, sizeof(struct mpg123_pars_struct));
fr->down_sample = 0; /* Initialize to silence harmless errors when debugging. */
frame_fixed_reset(fr); /* Reset only the fixed data, dynamic buffers are not there yet! */
fr->synth = NULL;
fr->synth_mono = NULL;
fr->make_decode_tables = NULL;
#ifdef FRAME_INDEX
fi_init(&fr->index);
frame_index_setup(fr); /* Apply the size setting. */
#endif
}
#ifdef OPT_DITHER
/* Also, only allocate the memory for the table on demand.
In future, one could create special noise for different sampling frequencies(?). */
int frame_dither_init(mpg123_handle *fr)
{
/* run-time dither noise table generation */
if(fr->dithernoise == NULL)
{
fr->dithernoise = malloc(sizeof(float)*DITHERSIZE);
if(fr->dithernoise == NULL) return 0;
dither_table_init(fr->dithernoise);
}
return 1;
}
#endif
mpg123_pars attribute_align_arg *mpg123_new_pars(int *error)
{
mpg123_pars *mp = malloc(sizeof(struct mpg123_pars_struct));
if(mp != NULL){ frame_default_pars(mp); if(error != NULL) *error = MPG123_OK; }
else if(error != NULL) *error = MPG123_OUT_OF_MEM;
return mp;
}
void attribute_align_arg mpg123_delete_pars(mpg123_pars* mp)
{
if(mp != NULL) free(mp);
}
int attribute_align_arg mpg123_reset_eq(mpg123_handle *mh)
{
int i;
mh->have_eq_settings = 0;
for(i=0; i < 32; ++i) mh->equalizer[0][i] = mh->equalizer[1][i] = DOUBLE_TO_REAL(1.0);
return MPG123_OK;
}
int frame_outbuffer(mpg123_handle *fr)
{
size_t size = mpg123_safe_buffer()*AUDIOBUFSIZE;
if(!fr->own_buffer) fr->buffer.data = NULL;
if(fr->buffer.data != NULL && fr->buffer.size != size)
{
free(fr->buffer.data);
fr->buffer.data = NULL;
}
fr->buffer.size = size;
if(fr->buffer.data == NULL) fr->buffer.data = (unsigned char*) malloc(fr->buffer.size);
if(fr->buffer.data == NULL)
{
fr->err = MPG123_OUT_OF_MEM;
return -1;
}
fr->own_buffer = TRUE;
fr->buffer.fill = 0;
return 0;
}
int attribute_align_arg mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size)
{
if(data == NULL || size < mpg123_safe_buffer())
{
mh->err = MPG123_BAD_BUFFER;
return MPG123_ERR;
}
if(mh->own_buffer && mh->buffer.data != NULL) free(mh->buffer.data);
mh->own_buffer = FALSE;
mh->buffer.data = data;
mh->buffer.size = size;
mh->buffer.fill = 0;
return MPG123_OK;
}
#ifdef FRAME_INDEX
int frame_index_setup(mpg123_handle *fr)
{
int ret = MPG123_ERR;
if(fr->p.index_size >= 0)
{ /* Simple fixed index. */
fr->index.grow_size = 0;
debug1("resizing index to %li", fr->p.index_size);
ret = fi_resize(&fr->index, (size_t)fr->p.index_size);
debug2("index resized... %lu at %p", (unsigned long)fr->index.size, (void*)fr->index.data);
}
else
{ /* A growing index. We give it a start, though. */
fr->index.grow_size = (size_t)(- fr->p.index_size);
if(fr->index.size < fr->index.grow_size)
ret = fi_resize(&fr->index, fr->index.grow_size);
else
ret = MPG123_OK; /* We have minimal size already... and since growing is OK... */
}
debug2("set up frame index of size %lu (ret=%i)", (unsigned long)fr->index.size, ret);
return ret;
}
#endif
static void frame_decode_buffers_reset(mpg123_handle *fr)
{
memset(fr->rawbuffs, 0, fr->rawbuffss);
}
int frame_buffers(mpg123_handle *fr)
{
int buffssize = 0;
debug1("frame %p buffer", (void*)fr);
/*
the used-to-be-static buffer of the synth functions, has some subtly different types/sizes
2to1, 4to1, ntom, generic, i386: real[2][2][0x110]
mmx, sse: short[2][2][0x110]
i586(_dither): 4352 bytes; int/long[2][2][0x110]
i486: int[2][2][17*FIR_BUFFER_SIZE]
altivec: static real __attribute__ ((aligned (16))) buffs[4][4][0x110]
Huh, altivec looks like fun. Well, let it be large... then, the 16 byte alignment seems to be implicit on MacOSX malloc anyway.
Let's make a reasonable attempt to allocate enough memory...
Keep in mind: biggest ones are i486 and altivec (mutually exclusive!), then follows i586 and normal real.
mmx/sse use short but also real for resampling.
Thus, minimum is 2*2*0x110*sizeof(real).
*/
if(fr->cpu_opts.type == altivec) buffssize = 4*4*0x110*sizeof(real);
#ifdef OPT_I486
else if(fr->cpu_opts.type == ivier) buffssize = 2*2*17*FIR_BUFFER_SIZE*sizeof(int);
#endif
else if(fr->cpu_opts.type == ifuenf || fr->cpu_opts.type == ifuenf_dither || fr->cpu_opts.type == dreidnow)
buffssize = 2*2*0x110*4; /* don't rely on type real, we need 4352 bytes */
if(2*2*0x110*sizeof(real) > buffssize)
buffssize = 2*2*0x110*sizeof(real);
buffssize += 15; /* For 16-byte alignment (SSE likes that). */
if(fr->rawbuffs != NULL && fr->rawbuffss != buffssize)
{
free(fr->rawbuffs);
fr->rawbuffs = NULL;
}
if(fr->rawbuffs == NULL) fr->rawbuffs = (unsigned char*) malloc(buffssize);
if(fr->rawbuffs == NULL) return -1;
fr->rawbuffss = buffssize;
fr->short_buffs[0][0] = aligned_pointer(fr->rawbuffs,short,16);
fr->short_buffs[0][1] = fr->short_buffs[0][0] + 0x110;
fr->short_buffs[1][0] = fr->short_buffs[0][1] + 0x110;
fr->short_buffs[1][1] = fr->short_buffs[1][0] + 0x110;
fr->real_buffs[0][0] = aligned_pointer(fr->rawbuffs,real,16);
fr->real_buffs[0][1] = fr->real_buffs[0][0] + 0x110;
fr->real_buffs[1][0] = fr->real_buffs[0][1] + 0x110;
fr->real_buffs[1][1] = fr->real_buffs[1][0] + 0x110;
#ifdef OPT_I486
if(fr->cpu_opts.type == ivier)
{
fr->int_buffs[0][0] = (int*) fr->rawbuffs;
fr->int_buffs[0][1] = fr->int_buffs[0][0] + 17*FIR_BUFFER_SIZE;
fr->int_buffs[1][0] = fr->int_buffs[0][1] + 17*FIR_BUFFER_SIZE;
fr->int_buffs[1][1] = fr->int_buffs[1][0] + 17*FIR_BUFFER_SIZE;
}
#endif
#ifdef OPT_ALTIVEC
if(fr->cpu_opts.type == altivec)
{
int i,j;
fr->areal_buffs[0][0] = (real*) fr->rawbuffs;
for(i=0; i<4; ++i) for(j=0; j<4; ++j)
fr->areal_buffs[i][j] = fr->areal_buffs[0][0] + (i*4+j)*0x110;
}
#endif
/* now the different decwins... all of the same size, actually */
/* The MMX ones want 32byte alignment, which I'll try to ensure manually */
{
int decwin_size = (512+32)*sizeof(real);
#ifdef OPT_MMXORSSE
#ifdef OPT_MULTI
if(fr->cpu_opts.class == mmxsse)
{
#endif
/* decwin_mmx will share, decwins will be appended ... sizeof(float)==4 */
if(decwin_size < (512+32)*4) decwin_size = (512+32)*4;
/* the second window + alignment zone -- we align for 32 bytes for SSE as
requirement, 64 byte for matching cache line size (that matters!) */
decwin_size += (512+32)*4 + 63;
/* (512+32)*4/32 == 2176/32 == 68, so one decwin block retains alignment for 32 or 64 bytes */
#ifdef OPT_MULTI
}
#endif
#endif
#if defined(OPT_ALTIVEC) || defined(OPT_ARM)
if(decwin_size < (512+32)*4) decwin_size = (512+32)*4;
decwin_size += 512*4;
#endif
/* Hm, that's basically realloc() ... */
if(fr->rawdecwin != NULL && fr->rawdecwins != decwin_size)
{
free(fr->rawdecwin);
fr->rawdecwin = NULL;
}
if(fr->rawdecwin == NULL)
fr->rawdecwin = (unsigned char*) malloc(decwin_size);
if(fr->rawdecwin == NULL) return -1;
fr->rawdecwins = decwin_size;
fr->decwin = (real*) fr->rawdecwin;
#ifdef OPT_MMXORSSE
#ifdef OPT_MULTI
if(fr->cpu_opts.class == mmxsse)
{
#endif
/* align decwin, assign that to decwin_mmx, append decwins */
/* I need to add to decwin what is missing to the next full 64 byte -- also I want to make gcc -pedantic happy... */
fr->decwin = aligned_pointer(fr->rawdecwin,real,64);
debug1("aligned decwin: %p", (void*)fr->decwin);
fr->decwin_mmx = (float*)fr->decwin;
fr->decwins = fr->decwin_mmx+512+32;
#ifdef OPT_MULTI
}
else debug("no decwins/decwin_mmx for that class");
#endif
#endif
}
/* Only reset the buffers we created just now. */
frame_decode_buffers_reset(fr);
debug1("frame %p buffer done", (void*)fr);
return 0;
}
int frame_buffers_reset(mpg123_handle *fr)
{
fr->buffer.fill = 0; /* hm, reset buffer fill... did we do a flush? */
fr->bsnum = 0;
/* Wondering: could it be actually _wanted_ to retain buffer contents over different files? (special gapless / cut stuff) */
fr->bsbuf = fr->bsspace[1];
fr->bsbufold = fr->bsbuf;
fr->bitreservoir = 0; /* Not entirely sure if this is the right place for that counter. */
frame_decode_buffers_reset(fr);
memset(fr->bsspace, 0, 2*(MAXFRAMESIZE+512));
memset(fr->ssave, 0, 34);
fr->hybrid_blc[0] = fr->hybrid_blc[1] = 0;
memset(fr->hybrid_block, 0, sizeof(real)*2*2*SBLIMIT*SSLIMIT);
return 0;
}
void frame_icy_reset(mpg123_handle* fr)
{
#ifndef NO_ICY
if(fr->icy.data != NULL) free(fr->icy.data);
fr->icy.data = NULL;
fr->icy.interval = 0;
fr->icy.next = 0;
#endif
}
void frame_free_toc(mpg123_handle *fr)
{
if(fr->xing_toc != NULL){ free(fr->xing_toc); fr->xing_toc = NULL; }
}
/* Just copy the Xing TOC over... */
int frame_fill_toc(mpg123_handle *fr, unsigned char* in)
{
if(fr->xing_toc == NULL) fr->xing_toc = malloc(100);
if(fr->xing_toc != NULL)
{
memcpy(fr->xing_toc, in, 100);
#ifdef DEBUG
debug("Got a TOC! Showing the values...");
{
int i;
for(i=0; i<100; ++i)
debug2("entry %i = %i", i, fr->xing_toc[i]);
}
#endif
return TRUE;
}
return FALSE;
}
/* Prepare the handle for a new track.
Reset variables, buffers... */
int frame_reset(mpg123_handle* fr)
{
frame_buffers_reset(fr);
frame_fixed_reset(fr);
frame_free_toc(fr);
#ifdef FRAME_INDEX
fi_reset(&fr->index);
#endif
return 0;
}
/* Reset everythign except dynamic memory. */
static void frame_fixed_reset(mpg123_handle *fr)
{
frame_icy_reset(fr);
open_bad(fr);
fr->to_decode = FALSE;
fr->to_ignore = FALSE;
fr->metaflags = 0;
fr->outblock = mpg123_safe_buffer();
fr->num = -1;
fr->playnum = -1;
fr->accurate = TRUE;
fr->silent_resync = 0;
fr->audio_start = 0;
fr->clip = 0;
fr->oldhead = 0;
fr->firsthead = 0;
fr->vbr = MPG123_CBR;
fr->abr_rate = 0;
fr->track_frames = 0;
fr->track_samples = -1;
fr->framesize=0;
fr->mean_frames = 0;
fr->mean_framesize = 0;
fr->freesize = 0;
fr->lastscale = -1;
fr->rva.level[0] = -1;
fr->rva.level[1] = -1;
fr->rva.gain[0] = 0;
fr->rva.gain[1] = 0;
fr->rva.peak[0] = 0;
fr->rva.peak[1] = 0;
fr->fsizeold = 0;
fr->firstframe = 0;
fr->ignoreframe = fr->firstframe-fr->p.preframes;
fr->lastframe = -1;
fr->fresh = 1;
fr->new_format = 0;
#ifdef GAPLESS
frame_gapless_init(fr,0,0);
fr->lastoff = 0;
fr->firstoff = 0;
#endif
#ifdef OPT_I486
fr->i486bo[0] = fr->i486bo[1] = FIR_SIZE-1;
#endif
fr->bo = 1; /* the usual bo */
#ifdef OPT_DITHER
fr->ditherindex = 0;
#endif
reset_id3(fr);
reset_icy(&fr->icy);
/* ICY stuff should go into icy.c, eh? */
#ifndef NO_ICY
fr->icy.interval = 0;
fr->icy.next = 0;
#endif
fr->halfphase = 0; /* here or indeed only on first-time init? */
fr->error_protection = 0;
fr->freeformat_framesize = -1;
}
void frame_free_buffers(mpg123_handle *fr)
{
if(fr->rawbuffs != NULL) free(fr->rawbuffs);
fr->rawbuffs = NULL;
fr->rawbuffss = 0;
if(fr->rawdecwin != NULL) free(fr->rawdecwin);
fr->rawdecwin = NULL;
fr->rawdecwins = 0;
#ifndef NO_8BIT
if(fr->conv16to8_buf != NULL) free(fr->conv16to8_buf);
fr->conv16to8_buf = NULL;
#endif
}
void frame_exit(mpg123_handle *fr)
{
if(fr->own_buffer && fr->buffer.data != NULL)
{
debug1("freeing buffer at %p", (void*)fr->buffer.data);
free(fr->buffer.data);
}
fr->buffer.data = NULL;
frame_free_buffers(fr);
frame_free_toc(fr);
#ifdef FRAME_INDEX
fi_exit(&fr->index);
#endif
#ifdef OPT_DITHER
if(fr->dithernoise != NULL)
{
free(fr->dithernoise);
fr->dithernoise = NULL;
}
#endif
exit_id3(fr);
clear_icy(&fr->icy);
}
int attribute_align_arg mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi)
{
if(mh == NULL) return MPG123_ERR;
if(mi == NULL)
{
mh->err = MPG123_ERR_NULL;
return MPG123_ERR;
}
mi->version = mh->mpeg25 ? MPG123_2_5 : (mh->lsf ? MPG123_2_0 : MPG123_1_0);
mi->layer = mh->lay;
mi->rate = frame_freq(mh);
switch(mh->mode)
{
case 0: mi->mode = MPG123_M_STEREO; break;
case 1: mi->mode = MPG123_M_JOINT; break;
case 2: mi->mode = MPG123_M_DUAL; break;
case 3: mi->mode = MPG123_M_MONO; break;
default: error("That mode cannot be!");
}
mi->mode_ext = mh->mode_ext;
mi->framesize = mh->framesize+4; /* Include header. */
mi->flags = 0;
if(mh->error_protection) mi->flags |= MPG123_CRC;
if(mh->copyright) mi->flags |= MPG123_COPYRIGHT;
if(mh->extension) mi->flags |= MPG123_PRIVATE;
if(mh->original) mi->flags |= MPG123_ORIGINAL;
mi->emphasis = mh->emphasis;
mi->bitrate = frame_bitrate(mh);
mi->abr_rate = mh->abr_rate;
mi->vbr = mh->vbr;
return MPG123_OK;
}
/*
Fuzzy frame offset searching (guessing).
When we don't have an accurate position, we may use an inaccurate one.
Possibilities:
- use approximate positions from Xing TOC (not yet parsed)
- guess wildly from mean framesize and offset of first frame / beginning of file.
*/
off_t frame_fuzzy_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame)
{
/* Default is to go to the beginning. */
off_t ret = fr->audio_start;
*get_frame = 0;
/* But we try to find something better. */
/* Xing VBR TOC works with relative positions, both in terms of audio frames and stream bytes.
Thus, it only works when whe know the length of things.
Oh... I assume the offsets are relative to the _total_ file length. */
if(fr->xing_toc != NULL && fr->track_frames > 0 && fr->rdat.filelen > 0)
{
/* One could round... */
int toc_entry = (int) ((double)want_frame*100./fr->track_frames);
/* It is an index in the 100-entry table. */
if(toc_entry < 0) toc_entry = 0;
if(toc_entry > 99) toc_entry = 99;
/* Now estimate back what frame we get. */
*get_frame = (off_t) ((double)toc_entry/100. * fr->track_frames);
fr->accurate = FALSE;
fr->silent_resync = 1;
/* Question: Is the TOC for whole file size (with/without ID3) or the "real" audio data only?
ID3v1 info could also matter. */
ret = (off_t) ((double)fr->xing_toc[toc_entry]/256.* fr->rdat.filelen);
}
else if(fr->mean_framesize > 0)
{ /* Just guess with mean framesize (may be exact with CBR files). */
/* Query filelen here or not? */
fr->accurate = FALSE; /* Fuzzy! */
fr->silent_resync = 1;
*get_frame = want_frame;
ret = (off_t) (fr->audio_start+fr->mean_framesize*want_frame);
}
debug5("fuzzy: want %li of %li, get %li at %li B of %li B",
(long)want_frame, (long)fr->track_frames, (long)*get_frame, (long)ret, (long)(fr->rdat.filelen-fr->audio_start));
return ret;
}
/*
find the best frame in index just before the wanted one, seek to there
then step to just before wanted one with read_frame
do not care tabout the stuff that was in buffer but not played back
everything that left the decoder is counted as played
Decide if you want low latency reaction and accurate timing info or stable long-time playback with buffer!
*/
off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame)
{
/* default is file start if no index position */
off_t gopos = 0;
*get_frame = 0;
#ifdef FRAME_INDEX
/* Possibly use VBRI index, too? I'd need an example for this... */
if(fr->index.fill)
{
/* find in index */
size_t fi;
/* at index fi there is frame step*fi... */
fi = want_frame/fr->index.step;
if(fi >= fr->index.fill) /* If we are beyond the end of frame index...*/
{
/* When fuzzy seek is allowed, we have some limited tolerance for the frames we want to read rather then jump over. */
if(fr->p.flags & MPG123_FUZZY && want_frame - (fr->index.fill-1)*fr->index.step > 10)
{
gopos = frame_fuzzy_find(fr, want_frame, get_frame);
if(gopos > fr->audio_start) return gopos; /* Only in that case, we have a useful guess. */
/* Else... just continue, fuzzyness didn't help. */
}
/* Use the last available position, slowly advancing from that one. */
fi = fr->index.fill - 1;
}
/* We have index position, that yields frame and byte offsets. */
*get_frame = fi*fr->index.step;
gopos = fr->index.data[fi];
fr->accurate = TRUE; /* When using the frame index, we are accurate. */
}
else
{
#endif
if(fr->p.flags & MPG123_FUZZY)
return frame_fuzzy_find(fr, want_frame, get_frame);
/* A bit hackish here... but we need to be fresh when looking for the first header again. */
fr->firsthead = 0;
fr->oldhead = 0;
#ifdef FRAME_INDEX
}
#endif
debug2("index: 0x%lx for frame %li", (unsigned long)gopos, (long) *get_frame);
return gopos;
}
off_t frame_ins2outs(mpg123_handle *fr, off_t ins)
{
off_t outs = 0;
switch(fr->down_sample)
{
case 0:
# ifndef NO_DOWNSAMPLE
case 1:
case 2:
# endif
outs = ins>>fr->down_sample;
break;
# ifndef NO_NTOM
case 3: outs = ntom_ins2outs(fr, ins); break;
# endif
default: error1("Bad down_sample (%i) ... should not be possible!!", fr->down_sample);
}
return outs;
}
off_t frame_outs(mpg123_handle *fr, off_t num)
{
off_t outs = 0;
switch(fr->down_sample)
{
case 0:
# ifndef NO_DOWNSAMPLE
case 1:
case 2:
# endif
outs = (spf(fr)>>fr->down_sample)*num;
break;
#ifndef NO_NTOM
case 3: outs = ntom_frmouts(fr, num); break;
#endif
default: error1("Bad down_sample (%i) ... should not be possible!!", fr->down_sample);
}
return outs;
}
off_t frame_offset(mpg123_handle *fr, off_t outs)
{
off_t num = 0;
switch(fr->down_sample)
{
case 0:
# ifndef NO_DOWNSAMPLE
case 1:
case 2:
# endif
num = outs/(spf(fr)>>fr->down_sample);
break;
#ifndef NO_NTOM
case 3: num = ntom_frameoff(fr, outs); break;
#endif
default: error("Bad down_sample ... should not be possible!!");
}
return num;
}
#ifdef GAPLESS
/* input in _input_ samples */
void frame_gapless_init(mpg123_handle *fr, off_t b, off_t e)
{
fr->begin_s = b;
fr->end_s = e;
/* These will get proper values later, from above plus resampling info. */
fr->begin_os = 0;
fr->end_os = 0;
debug2("frame_gapless_init: from %lu to %lu samples", (long unsigned)fr->begin_s, (long unsigned)fr->end_s);
}
void frame_gapless_realinit(mpg123_handle *fr)
{
fr->begin_os = frame_ins2outs(fr, fr->begin_s);
fr->end_os = frame_ins2outs(fr, fr->end_s);
debug2("frame_gapless_realinit: from %lu to %lu samples", (long unsigned)fr->begin_os, (long unsigned)fr->end_os);
}
/* When we got a new sample count, update the gaplessness. */
void frame_gapless_update(mpg123_handle *fr, off_t total_samples)
{
if(fr->end_s < 1)
{
fr->end_s = total_samples;
frame_gapless_realinit(fr);
}
else if(fr->end_s > total_samples)
{
if(NOQUIET) error2("end sample count smaller than gapless end! (%"OFF_P" < %"OFF_P").", (off_p)total_samples, (off_p)fr->end_s);
fr->end_s = total_samples;
}
}
#endif
/* Compute the needed frame to ignore from, for getting accurate/consistent output for intended firstframe. */
static off_t ignoreframe(mpg123_handle *fr)
{
off_t preshift = fr->p.preframes;
/* Layer 3 _really_ needs at least one frame before. */
if(fr->lay==3 && preshift < 1) preshift = 1;
/* Layer 1 & 2 reall do not need more than 2. */
if(fr->lay!=3 && preshift > 2) preshift = 2;
return fr->firstframe - preshift;
}
/* The frame seek... This is not simply the seek to fe*spf(fr) samples in output because we think of _input_ frames here.
Seek to frame offset 1 may be just seek to 200 samples offset in output since the beginning of first frame is delay/padding.
Hm, is that right? OK for the padding stuff, but actually, should the decoder delay be better totally hidden or not?
With gapless, even the whole frame position could be advanced further than requested (since Homey don't play dat). */
void frame_set_frameseek(mpg123_handle *fr, off_t fe)
{
fr->firstframe = fe;
#ifdef GAPLESS
if(fr->p.flags & MPG123_GAPLESS)
{
/* Take care of the beginning... */
off_t beg_f = frame_offset(fr, fr->begin_os);
if(fe <= beg_f)
{
fr->firstframe = beg_f;
fr->firstoff = fr->begin_os - frame_outs(fr, beg_f);
}
else fr->firstoff = 0;
/* The end is set once for a track at least, on the frame_set_frameseek called in get_next_frame() */
if(fr->end_os > 0)
{
fr->lastframe = frame_offset(fr,fr->end_os);
fr->lastoff = fr->end_os - frame_outs(fr, fr->lastframe);
} else fr->lastoff = 0;
} else { fr->firstoff = fr->lastoff = 0; fr->lastframe = -1; }
#endif
fr->ignoreframe = ignoreframe(fr);
#ifdef GAPLESS
debug5("frame_set_frameseek: begin at %li frames and %li samples, end at %li and %li; ignore from %li",
(long) fr->firstframe, (long) fr->firstoff,
(long) fr->lastframe, (long) fr->lastoff, (long) fr->ignoreframe);
#else
debug3("frame_set_frameseek: begin at %li frames, end at %li; ignore from %li",
(long) fr->firstframe, (long) fr->lastframe, (long) fr->ignoreframe);
#endif
}
void frame_skip(mpg123_handle *fr)
{
#ifndef NO_LAYER3
if(fr->lay == 3) set_pointer(fr, 512);
#endif
}
/* Sample accurate seek prepare for decoder. */
/* This gets unadjusted output samples and takes resampling into account */
void frame_set_seek(mpg123_handle *fr, off_t sp)
{
fr->firstframe = frame_offset(fr, sp);
#ifndef NO_NTOM
if(fr->down_sample == 3) ntom_set_ntom(fr, fr->firstframe);
#endif
fr->ignoreframe = ignoreframe(fr);
#ifdef GAPLESS /* The sample offset is used for non-gapless mode, too! */
fr->firstoff = sp - frame_outs(fr, fr->firstframe);
debug5("frame_set_seek: begin at %li frames and %li samples, end at %li and %li; ignore from %li",
(long) fr->firstframe, (long) fr->firstoff,
(long) fr->lastframe, (long) fr->lastoff, (long) fr->ignoreframe);
#else
debug3("frame_set_seek: begin at %li frames, end at %li; ignore from %li",
(long) fr->firstframe, (long) fr->lastframe, (long) fr->ignoreframe);
#endif
}
int attribute_align_arg mpg123_volume_change(mpg123_handle *mh, double change)
{
if(mh == NULL) return MPG123_ERR;
return mpg123_volume(mh, change + (double) mh->p.outscale);
}
int attribute_align_arg mpg123_volume(mpg123_handle *mh, double vol)
{
if(mh == NULL) return MPG123_ERR;
if(vol >= 0) mh->p.outscale = vol;
else mh->p.outscale = 0.;
do_rva(mh);
return MPG123_OK;
}
static int get_rva(mpg123_handle *fr, double *peak, double *gain)
{
double p = -1;
double g = 0;
int ret = 0;
if(fr->p.rva)
{
int rt = 0;
/* Should one assume a zero RVA as no RVA? */
if(fr->p.rva == 2 && fr->rva.level[1] != -1) rt = 1;
if(fr->rva.level[rt] != -1)
{
p = fr->rva.peak[rt];
g = fr->rva.gain[rt];
ret = 1; /* Success. */
}
}
if(peak != NULL) *peak = p;
if(gain != NULL) *gain = g;
return ret;
}
/* adjust the volume, taking both fr->outscale and rva values into account */
void do_rva(mpg123_handle *fr)
{
double peak = 0;
double gain = 0;
double newscale;
double rvafact = 1;
if(get_rva(fr, &peak, &gain))
{
if(NOQUIET && fr->p.verbose > 1) fprintf(stderr, "Note: doing RVA with gain %f\n", gain);
rvafact = pow(10,gain/20);
}
newscale = fr->p.outscale*rvafact;
/* if peak is unknown (== 0) this check won't hurt */
if((peak*newscale) > 1.0)
{
newscale = 1.0/peak;
warning2("limiting scale value to %f to prevent clipping with indicated peak factor of %f", newscale, peak);
}
/* first rva setting is forced with fr->lastscale < 0 */
if(newscale != fr->lastscale || fr->decoder_change)
{
debug3("changing scale value from %f to %f (peak estimated to %f)", fr->lastscale != -1 ? fr->lastscale : fr->p.outscale, newscale, (double) (newscale*peak));
fr->lastscale = newscale;
/* It may be too early, actually. */
if(fr->make_decode_tables != NULL) fr->make_decode_tables(fr); /* the actual work */
}
}
int attribute_align_arg mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db)
{
if(mh == NULL) return MPG123_ERR;
if(base) *base = mh->p.outscale;
if(really) *really = mh->lastscale;
get_rva(mh, NULL, rva_db);
return MPG123_OK;
}

View File

@ -0,0 +1,363 @@
/*
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 "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;
unsigned char *p; /* read pointer */
size_t fill; /* fill from read pointer */
size_t size; /* that's actually more like a safe size, after we have more than that, flush it */
};
struct audioformat
{
int encoding;
int encsize; /* Size of one sample in bytes, plain int should be fine here... */
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;
#ifndef WIN32
long timeout;
#endif
#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;
};
/* 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
int have_eq_settings;
real equalizer[2][32];
/* 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];
real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */
/* 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 || defined OPT_3DNOWEXT)
void (*dct36)(real *,real *,real *,real *,real *);
#endif
#endif
#endif
enum optdec type;
enum optcla class;
} cpu_opts;
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;
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 playnum; /* playback offset... includes repetitions, reset at seeks */
off_t audio_start; /* The byte offset in the file where audio data begins. */
char accurate; /* Flag to see if we trust the frame number. */
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;
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]; /* MAXFRAMESIZE */
unsigned char *bsbuf;
unsigned char *bsbufold;
int bsnum;
unsigned long oldhead;
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 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;
#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
#ifndef NO_ICY
struct icy_meta icy;
#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
*/
#define spf(fr) ((fr)->lay == 1 ? 384 : ((fr)->lay==2 ? 1152 : ((fr)->lsf || (fr)->mpeg25 ? 576 : 1152)))
#ifdef GAPLESS
/* well, I take that one for granted... at least layer3 */
#define GAPLESS_DELAY 529
/* still fine-tuning the "real music" window... see read_frame */
void frame_gapless_init(mpg123_handle *fr, off_t b, off_t e);
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
/* 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);
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);
/* adjust volume to current outscale and rva values if wanted */
void do_rva(mpg123_handle *fr);
#endif

View File

@ -0,0 +1,100 @@
/*
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"
#define backbits(fr,nob) ((void)( \
fr->bitindex -= nob, \
fr->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 0x7 ))
#define getbitoffset(fr) ((-fr->bitindex)&0x7)
#define getbyte(fr) (*fr->wordpointer++)
/* There is something wrong with that macro... the function below works also for the layer1 test case. */
#define macro_getbits(fr, nob) ( \
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->ultmp >>= (24-nob), \
fr->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 7, \
fr->ultmp)
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
/* 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->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->wordpointer += (fr->bitindex>>3), \
fr->bitindex &= 7, fr->ultmp )
#define get1bit(fr) ( \
fr->uctmp = *fr->wordpointer << fr->bitindex, fr->bitindex++, \
fr->wordpointer += (fr->bitindex>>3), fr->bitindex &= 7, fr->uctmp>>7 )
#endif

View File

@ -0,0 +1,94 @@
/*
getcpucpuflags: get cpuflags for ia32
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 KIMURA Takuhiro (for 3DNow!)
extended for general use by Thomas Orgis
extern int getcpuid(struct cpuflags*)
or just
extern int getcpuid(unsigned int*)
where there is memory for 4 ints
-> the first set of idflags (basic cpu family info)
and the idflags, stdflags, std2flags, extflags written to the parameter
-> 0x00000000 (CPUID instruction not supported)
*/
#include "mangle.h"
.text
ALIGN4
.globl ASM_NAME(getcpuflags)
/* .type ASM_NAME(getcpuflags),@function */
ASM_NAME(getcpuflags):
pushl %ebp
movl %esp,%ebp
pushl %edx
pushl %ecx
pushl %ebx
pushl %esi
/* get the int pointer for storing the flags */
movl 8(%ebp), %esi
/* does that one make sense? */
movl $0x80000000,%eax
/* now save the flags and do a check for cpuid availability */
pushfl
pushfl
popl %eax
movl %eax,%ebx
/* set that bit... */
xorl $0x00200000,%eax
pushl %eax
popfl
/* ...and read back the flags to see if it is understood */
pushfl
popl %eax
popfl
cmpl %ebx,%eax
je .Lnocpuid
/* In principle, I would have to check the CPU's identify first to be sure how to interpret the extended flags. */
/* now get the info, first extended */
movl $0x0, 12(%esi) /* clear value */
/* only if supported... */
movl $0x80000000, %eax
cpuid
/* IDT CPUs should not change EAX, generally I hope that non-3DNow cpus do not set a bogus support level here. */
cmpl $0x80000001, %eax
jb .Lnoextended /* Skip ext check without minimal support level. */
/* is supported, get flags value */
movl $0x80000001,%eax
cpuid
movl %edx,12(%esi)
.Lnoextended:
/* then the other ones, called last to get the id flags in %eax for ret */
movl $0x00000001,%eax
cpuid
movl %eax, (%esi)
movl %ecx, 4(%esi)
movl %edx, 8(%esi)
jmp .Lend
ALIGN4
.Lnocpuid:
/* error: set everything to zero */
movl $0, %eax
movl $0, (%esi)
movl $0, 4(%esi)
movl $0, 8(%esi)
movl $0, 12(%esi)
ALIGN4
.Lend:
/* return value are the id flags, still stored in %eax */
popl %esi
popl %ebx
popl %ecx
popl %edx
movl %ebp,%esp
popl %ebp
ret
/* Mark non-executable stack. */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@ -0,0 +1,49 @@
/*
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
/* standard level flags part 1 (ECX)*/
#define FLAG_SSE3 0x00000001
/* 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
struct cpuflags
{
unsigned int id;
unsigned int std;
unsigned int std2;
unsigned int ext;
};
extern struct cpuflags cpu_flags;
unsigned int getcpuflags(struct cpuflags* cf);
/* 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)
#endif

View File

@ -0,0 +1,340 @@
/*
huffman.h: huffman tables ... recalcualted to work with optimzed 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;
short *table;
};
static short tab0[] =
{
0
};
static short tab1[] =
{
-5, -3, -1, 17, 1, 16, 0
};
static short tab2[] =
{
-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1,
16, 0
};
static short tab3[] =
{
-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
1, 0
};
static 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 struct newhuff htc[] =
{
{ /* 1 , 1 , */ 0 , tab_c0 } ,
{ /* 1 , 1 , */ 0 , tab_c1 }
};
#endif

View File

@ -0,0 +1,32 @@
/*
icy: Puny code to pretend for a serious ICY data structure.
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
*/
#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,35 @@
/*
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
#define init_icy(a)
#define clear_icy(a)
#define reset_icy(a)
#endif /* NO_ICY */
#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

View File

@ -0,0 +1,984 @@
/*
id3: ID3v2.3 and ID3v2.4 parsing (a relevant subset)
copyright 2006-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 Thomas Orgis
*/
#include "mpg123lib_intern.h"
#include "id3.h"
#include "debug.h"
#ifndef NO_ID3V2 /* Only the main parsing routine will always be there. */
/* We know the usual text frames plus some specifics. */
#define KNOWN_FRAMES 4
static const char frame_type[KNOWN_FRAMES][5] = { "COMM", "TXXX", "RVA2", "USLT" };
enum frame_types { unknown = -2, text = -1, comment, extra, rva2, uslt };
/* UTF support definitions */
typedef void (*text_converter)(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
static void convert_latin1 (mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
static void convert_utf16bom(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
static void convert_utf8 (mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
static const text_converter text_converters[4] =
{
convert_latin1,
/* We always check for (multiple) BOM in 16bit unicode. Without BOM, UTF16 BE is the default.
Errors in encoding are detected anyway. */
convert_utf16bom,
convert_utf16bom,
convert_utf8
};
const unsigned int encoding_widths[4] = { 1, 2, 2, 1 };
/* the code starts here... */
static void null_id3_links(mpg123_handle *fr)
{
fr->id3v2.title = NULL;
fr->id3v2.artist = NULL;
fr->id3v2.album = NULL;
fr->id3v2.year = NULL;
fr->id3v2.genre = NULL;
fr->id3v2.comment = NULL;
}
void init_id3(mpg123_handle *fr)
{
fr->id3v2.version = 0; /* nothing there */
null_id3_links(fr);
fr->id3v2.comments = 0;
fr->id3v2.comment_list = NULL;
fr->id3v2.texts = 0;
fr->id3v2.text = NULL;
fr->id3v2.extras = 0;
fr->id3v2.extra = NULL;
}
/* Managing of the text, comment and extra lists. */
/* Initialize one element. */
static void init_mpg123_text(mpg123_text *txt)
{
mpg123_init_string(&txt->text);
mpg123_init_string(&txt->description);
txt->id[0] = 0;
txt->id[1] = 0;
txt->id[2] = 0;
txt->id[3] = 0;
txt->lang[0] = 0;
txt->lang[1] = 0;
txt->lang[2] = 0;
}
/* Free memory of one element. */
static void free_mpg123_text(mpg123_text *txt)
{
mpg123_free_string(&txt->text);
mpg123_free_string(&txt->description);
}
/* Free memory of whole list. */
#define free_comment(mh) free_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
#define free_text(mh) free_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
#define free_extra(mh) free_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
static void free_id3_text(mpg123_text **list, size_t *size)
{
size_t i;
for(i=0; i<*size; ++i) free_mpg123_text(&((*list)[i]));
free(*list);
*list = NULL;
*size = 0;
}
/* Add items to the list. */
#define add_comment(mh) add_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
#define add_text(mh) add_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
#define add_extra(mh) add_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
static mpg123_text *add_id3_text(mpg123_text **list, size_t *size)
{
mpg123_text *x = safe_realloc(*list, sizeof(mpg123_text)*(*size+1));
if(x == NULL) return NULL; /* bad */
*list = x;
*size += 1;
init_mpg123_text(&((*list)[*size-1]));
return &((*list)[*size-1]); /* Return pointer to the added text. */
}
/* Remove the last item. */
#define pop_comment(mh) pop_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
#define pop_text(mh) pop_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
#define pop_extra(mh) pop_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
static void pop_id3_text(mpg123_text **list, size_t *size)
{
mpg123_text *x;
if(*size < 1) return;
free_mpg123_text(&((*list)[*size-1]));
if(*size > 1)
{
x = safe_realloc(*list, sizeof(mpg123_text)*(*size-1));
if(x != NULL){ *list = x; *size -= 1; }
}
else
{
free(*list);
*list = NULL;
*size = 0;
}
}
/* OK, back t the higher level functions. */
void exit_id3(mpg123_handle *fr)
{
free_comment(fr);
free_extra(fr);
free_text(fr);
}
void reset_id3(mpg123_handle *fr)
{
exit_id3(fr);
init_id3(fr);
}
/* Set the id3v2.artist id3v2.title ... links to elements of the array. */
void id3_link(mpg123_handle *fr)
{
size_t i;
mpg123_id3v2 *v2 = &fr->id3v2;
debug("linking ID3v2");
null_id3_links(fr);
for(i=0; i<v2->texts; ++i)
{
mpg123_text *entry = &v2->text[i];
if (!strncmp("TIT2", entry->id, 4)) v2->title = &entry->text;
else if(!strncmp("TALB", entry->id, 4)) v2->album = &entry->text;
else if(!strncmp("TPE1", entry->id, 4)) v2->artist = &entry->text;
else if(!strncmp("TYER", entry->id, 4)) v2->year = &entry->text;
else if(!strncmp("TCON", entry->id, 4)) v2->genre = &entry->text;
}
for(i=0; i<v2->comments; ++i)
{
mpg123_text *entry = &v2->comment_list[i];
if(entry->description.fill == 0 || entry->description.p[0] == 0)
v2->comment = &entry->text;
}
/* When no generic comment found, use the last non-generic one. */
if(v2->comment == NULL && v2->comments > 0)
v2->comment = &v2->comment_list[v2->comments-1].text;
}
/*
Store ID3 text data in an mpg123_string; either verbatim copy or everything translated to UTF-8 encoding.
Preserve the zero string separator (I don't need strlen for the total size).
ID3v2 standard says that there should be one text frame of specific type per tag, and subsequent tags overwrite old values.
So, I always replace the text that may be stored already (perhaps with a list of zero-separated strings, though).
*/
void store_id3_text(mpg123_string *sb, char *source, size_t source_size, const int noquiet, const int notranslate)
{
if(!source_size)
{
debug("Empty id3 data!");
return;
}
/* We shall just copy the data. Client wants to decode itself. */
if(notranslate)
{
/* Future: Add a path for ID3 errors. */
if(!mpg123_resize_string(sb, source_size))
{
if(noquiet) error("Cannot resize target string, out of memory?");
return;
}
memcpy(sb->p, source, source_size);
sb->fill = source_size;
debug1("stored undecoded ID3 text of size %"SIZE_P, (size_p)source_size);
return;
}
id3_to_utf8(sb, ((unsigned char *)source)[0], (unsigned char*)source+1, source_size-1, noquiet);
if(sb->fill) debug1("UTF-8 string (the first one): %s", sb->p);
else if(noquiet) error("unable to convert string to UTF-8 (out of memory, junk input?)!");
}
/* On error, sb->size is 0. */
void id3_to_utf8(mpg123_string *sb, unsigned char encoding, const unsigned char *source, size_t source_size, int noquiet)
{
unsigned int bwidth;
debug1("encoding: %u", encoding);
/* A note: ID3v2.3 uses UCS-2 non-variable 16bit encoding, v2.4 uses UTF16.
UTF-16 uses a reserved/private range in UCS-2 to add the magic, so we just always treat it as UTF. */
if(encoding > mpg123_id3_enc_max)
{
if(noquiet) error1("Unknown text encoding %u, I take no chances, sorry!", encoding);
mpg123_free_string(sb);
return;
}
bwidth = encoding_widths[encoding];
/* Hack! I've seen a stray zero byte before BOM. Is that supposed to happen? */
if(encoding != mpg123_id3_utf16be) /* UTF16be _can_ beging with a null byte! */
while(source_size > bwidth && source[0] == 0)
{
--source_size;
++source;
debug("skipped leading zero");
}
if(source_size % bwidth)
{
/* When we need two bytes for a character, it's strange to have an uneven bytestream length. */
if(noquiet) warning2("Weird tag size %d for encoding %u - I will probably trim too early or something but I think the MP3 is broken.", (int)source_size, encoding);
source_size -= source_size % bwidth;
}
text_converters[encoding](sb, source, source_size, noquiet);
}
char *next_text(char* prev, int encoding, size_t limit)
{
char *text = prev;
size_t width = encoding_widths[encoding];
/* So I go lengths to find zero or double zero...
Remember bug 2834636: Only check for aligned NULLs! */
while(text-prev < (ssize_t)limit)
{
if(text[0] == 0)
{
if(width <= limit-(text-prev))
{
size_t i = 1;
for(; i<width; ++i) if(text[i] != 0) break;
if(i == width) /* found a null wide enough! */
{
text += width;
break;
}
}
else return NULL; /* No full character left? This text is broken */
}
text += width;
}
if(text-prev >= limit) text = NULL;
return text;
}
static const char *enc_name(int enc)
{
switch(enc)
{
case 0: return "Latin 1";
case 1: return "UTF-16 BOM";
case 2: return "UTF-16 BE";
case 3: return "UTF-8";
default: return "unknown!";
}
}
static void process_text(mpg123_handle *fr, char *realdata, size_t realsize, char *id)
{
/* Text encoding $xx */
/* The text (encoded) ... */
mpg123_text *t = add_text(fr);
if(VERBOSE4) fprintf(stderr, "Note: Storing text from %s encoding\n", enc_name(realdata[0]));
if(t == NULL)
{
if(NOQUIET) error("Unable to attach new text!");
return;
}
memcpy(t->id, id, 4);
store_id3_text(&t->text, realdata, realsize, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
if(VERBOSE4) fprintf(stderr, "Note: ID3v2 %c%c%c%c text frame: %s\n", id[0], id[1], id[2], id[3], t->text.p);
}
/* Store a new comment that perhaps is a RVA / RVA_ALBUM/AUDIOPHILE / RVA_MIX/RADIO one
Special gimmik: It also stores USLT to the texts. Stucture is the same as for comments. */
static void process_comment(mpg123_handle *fr, enum frame_types tt, char *realdata, size_t realsize, int rva_level, char *id)
{
/* Text encoding $xx */
/* Language $xx xx xx */
/* Short description (encoded!) <text> $00 (00) */
/* Then the comment text (encoded) ... */
char encoding = realdata[0];
char *lang = realdata+1; /* I'll only use the 3 bytes! */
char *descr = realdata+4;
char *text = NULL;
mpg123_text *xcom = NULL;
mpg123_text localcom; /* UTF-8 variant for local processing. */
if((int)realsize < descr-realdata)
{
if(NOQUIET) error1("Invalid frame size of %lu (too small for anything).", (unsigned long)realsize);
return;
}
xcom = (tt == uslt ? add_text(fr) : add_comment(fr));
if(VERBOSE4) fprintf(stderr, "Note: Storing comment from %s encoding\n", enc_name(realdata[0]));
if(xcom == NULL)
{
if(NOQUIET) error("Unable to attach new comment!");
return;
}
memcpy(xcom->lang, lang, 3);
memcpy(xcom->id, id, 4);
/* Now I can abuse a byte from lang for the encoding. */
descr[-1] = encoding;
/* Be careful with finding the end of description, I have to honor encoding here. */
text = next_text(descr, encoding, realsize-(descr-realdata));
if(text == NULL)
{
if(NOQUIET) error("No comment text / valid description?");
pop_comment(fr);
return;
}
init_mpg123_text(&localcom);
/* Store the text, without translation to UTF-8, but for comments always a local copy in UTF-8.
Reminder: No bailing out from here on without freeing the local comment data! */
store_id3_text(&xcom->description, descr-1, text-descr+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
if(tt == comment)
store_id3_text(&localcom.description, descr-1, text-descr+1, NOQUIET, 1);
text[-1] = encoding; /* Byte abusal for encoding... */
store_id3_text(&xcom->text, text-1, realsize+1-(text-realdata), NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
/* Remember: I will probably decode the above (again) for rva comment checking. So no messing around, please. */
if(VERBOSE4) /* Do _not_ print the verbatim text: The encoding might be funny! */
{
fprintf(stderr, "Note: ID3 comm/uslt desc of length %"SIZE_P".\n", (size_p)xcom->description.fill);
fprintf(stderr, "Note: ID3 comm/uslt text of length %"SIZE_P".\n", (size_p)xcom->text.fill);
}
/* Look out for RVA info only when we really deal with a straight comment. */
if(tt == comment && localcom.description.fill > 0)
{
int rva_mode = -1; /* mix / album */
if( !strcasecmp(localcom.description.p, "rva")
|| !strcasecmp(localcom.description.p, "rva_mix")
|| !strcasecmp(localcom.description.p, "rva_track")
|| !strcasecmp(localcom.description.p, "rva_radio") )
rva_mode = 0;
else if( !strcasecmp(localcom.description.p, "rva_album")
|| !strcasecmp(localcom.description.p, "rva_audiophile")
|| !strcasecmp(localcom.description.p, "rva_user") )
rva_mode = 1;
if((rva_mode > -1) && (fr->rva.level[rva_mode] <= rva_level))
{
/* Only translate the contents in here where we really need them. */
store_id3_text(&localcom.text, text-1, realsize+1-(text-realdata), NOQUIET, 1);
if(localcom.text.fill > 0)
{
fr->rva.gain[rva_mode] = (float) atof(localcom.text.p);
if(VERBOSE3) fprintf(stderr, "Note: RVA value %fdB\n", fr->rva.gain[rva_mode]);
fr->rva.peak[rva_mode] = 0;
fr->rva.level[rva_mode] = rva_level;
}
}
}
/* Make sure to free the local memory... */
free_mpg123_text(&localcom);
}
void process_extra(mpg123_handle *fr, char* realdata, size_t realsize, int rva_level, char *id)
{
/* Text encoding $xx */
/* Description ... $00 (00) */
/* Text ... */
char encoding = realdata[0];
char *descr = realdata+1; /* remember, the encoding is descr[-1] */
char *text;
mpg123_text *xex;
mpg123_text localex;
if((int)realsize < descr-realdata)
{
if(NOQUIET) error1("Invalid frame size of %lu (too small for anything).", (unsigned long)realsize);
return;
}
text = next_text(descr, encoding, realsize-(descr-realdata));
if(VERBOSE4) fprintf(stderr, "Note: Storing extra from %s encoding\n", enc_name(realdata[0]));
if(text == NULL)
{
if(NOQUIET) error("No extra frame text / valid description?");
return;
}
xex = add_extra(fr);
if(xex == NULL)
{
if(NOQUIET) error("Unable to attach new extra text!");
return;
}
memcpy(xex->id, id, 4);
init_mpg123_text(&localex); /* For our local copy. */
store_id3_text(&xex->description, descr-1, text-descr+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
store_id3_text(&localex.description, descr-1, text-descr+1, NOQUIET, 1);
text[-1] = encoding;
store_id3_text(&xex->text, text-1, realsize-(text-realdata)+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
/* Now check if we would like to interpret this extra info for RVA. */
if(localex.description.fill > 0)
{
int is_peak = 0;
int rva_mode = -1; /* mix / album */
if(!strncasecmp(localex.description.p, "replaygain_track_",17))
{
if(VERBOSE3) fprintf(stderr, "Note: RVA ReplayGain track gain/peak\n");
rva_mode = 0;
if(!strcasecmp(localex.description.p, "replaygain_track_peak")) is_peak = 1;
else if(strcasecmp(localex.description.p, "replaygain_track_gain")) rva_mode = -1;
}
else
if(!strncasecmp(localex.description.p, "replaygain_album_",17))
{
if(VERBOSE3) fprintf(stderr, "Note: RVA ReplayGain album gain/peak\n");
rva_mode = 1;
if(!strcasecmp(localex.description.p, "replaygain_album_peak")) is_peak = 1;
else if(strcasecmp(localex.description.p, "replaygain_album_gain")) rva_mode = -1;
}
if((rva_mode > -1) && (fr->rva.level[rva_mode] <= rva_level))
{
/* Now we need the translated copy of the data. */
store_id3_text(&localex.text, text-1, realsize-(text-realdata)+1, NOQUIET, 1);
if(localex.text.fill > 0)
{
if(is_peak)
{
fr->rva.peak[rva_mode] = (float) atof(localex.text.p);
if(VERBOSE3) fprintf(stderr, "Note: RVA peak %f\n", fr->rva.peak[rva_mode]);
}
else
{
fr->rva.gain[rva_mode] = (float) atof(localex.text.p);
if(VERBOSE3) fprintf(stderr, "Note: RVA gain %fdB\n", fr->rva.gain[rva_mode]);
}
fr->rva.level[rva_mode] = rva_level;
}
}
}
free_mpg123_text(&localex);
}
/* Make a ID3v2.3+ 4-byte ID from a ID3v2.2 3-byte ID
Note that not all frames survived to 2.4; the mapping goes to 2.3 .
A notable miss is the old RVA frame, which is very unspecific anyway.
This function returns -1 when a not known 3 char ID was encountered, 0 otherwise. */
int promote_framename(mpg123_handle *fr, char *id) /* fr because of VERBOSE macros */
{
size_t i;
char *old[] =
{
"COM", "TAL", "TBP", "TCM", "TCO", "TCR", "TDA", "TDY", "TEN", "TFT",
"TIM", "TKE", "TLA", "TLE", "TMT", "TOA", "TOF", "TOL", "TOR", "TOT",
"TP1", "TP2", "TP3", "TP4", "TPA", "TPB", "TRC", "TDA", "TRK", "TSI",
"TSS", "TT1", "TT2", "TT3", "TXT", "TXX", "TYE"
};
char *new[] =
{
"COMM", "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDAT", "TDLY", "TENC", "TFLT",
"TIME", "TKEY", "TLAN", "TLEN", "TMED", "TOPE", "TOFN", "TOLY", "TORY", "TOAL",
"TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPUB", "TSRC", "TRDA", "TRCK", "TSIZ",
"TSSE", "TIT1", "TIT2", "TIT3", "TEXT", "TXXX", "TYER"
};
for(i=0; i<sizeof(old)/sizeof(char*); ++i)
{
if(!strncmp(id, old[i], 3))
{
memcpy(id, new[i], 4);
if(VERBOSE3) fprintf(stderr, "Translated ID3v2.2 frame %s to %s\n", old[i], new[i]);
return 0;
}
}
if(VERBOSE3) fprintf(stderr, "Ignoring untranslated ID3v2.2 frame %c%c%c\n", id[0], id[1], id[2]);
return -1;
}
#endif /* NO_ID3V2 */
/*
trying to parse ID3v2.3 and ID3v2.4 tags...
returns: 0: bad or just unparseable tag
1: good, (possibly) new tag info
<0: reader error (may need more data feed, try again)
*/
int parse_new_id3(mpg123_handle *fr, unsigned long first4bytes)
{
#define UNSYNC_FLAG 128
#define EXTHEAD_FLAG 64
#define EXP_FLAG 32
#define FOOTER_FLAG 16
#define UNKNOWN_FLAGS 15 /* 00001111*/
unsigned char buf[6];
unsigned long length=0;
unsigned char flags = 0;
int ret = 1;
int ret2;
unsigned char* tagdata = NULL;
unsigned char major = first4bytes & 0xff;
debug1("ID3v2: major tag version: %i", major);
if(major == 0xff) return 0; /* Invalid... */
if((ret2 = fr->rd->read_frame_body(fr, buf, 6)) < 0) /* read more header information */
return ret2;
if(buf[0] == 0xff) return 0; /* Revision, will never be 0xff. */
/* second new byte are some nice flags, if these are invalid skip the whole thing */
flags = buf[1];
debug1("ID3v2: flags 0x%08x", flags);
/* use 4 bytes from buf to construct 28bit uint value and return 1; return 0 if bytes are not synchsafe */
#define synchsafe_to_long(buf,res) \
( \
(((buf)[0]|(buf)[1]|(buf)[2]|(buf)[3]) & 0x80) ? 0 : \
(res = (((unsigned long) (buf)[0]) << 21) \
| (((unsigned long) (buf)[1]) << 14) \
| (((unsigned long) (buf)[2]) << 7) \
| ((unsigned long) (buf)[3]) \
,1) \
)
/* id3v2.3 does not store synchsafe frame sizes, but synchsafe tag size - doh! */
#define bytes_to_long(buf,res) \
( \
major == 3 ? \
(res = (((unsigned long) (buf)[0]) << 24) \
| (((unsigned long) (buf)[1]) << 16) \
| (((unsigned long) (buf)[2]) << 8) \
| ((unsigned long) (buf)[3]) \
,1) : synchsafe_to_long(buf,res) \
)
/* for id3v2.2 only */
#define threebytes_to_long(buf,res) \
( \
res = (((unsigned long) (buf)[0]) << 16) \
| (((unsigned long) (buf)[1]) << 8) \
| ((unsigned long) (buf)[2]) \
,1 \
)
/* length-10 or length-20 (footer present); 4 synchsafe integers == 28 bit number */
/* we have already read 10 bytes, so left are length or length+10 bytes belonging to tag */
if(!synchsafe_to_long(buf+2,length))
{
if(NOQUIET) error4("Bad tag length (not synchsafe): 0x%02x%02x%02x%02x; You got a bad ID3 tag here.", buf[2],buf[3],buf[4],buf[5]);
return 0;
}
debug1("ID3v2: tag data length %lu", length);
#ifndef NO_ID3V2
if(VERBOSE2) fprintf(stderr,"Note: ID3v2.%i rev %i tag of %lu bytes\n", major, buf[0], length);
/* skip if unknown version/scary flags, parse otherwise */
if((flags & UNKNOWN_FLAGS) || (major > 4) || (major < 2))
{
/* going to skip because there are unknown flags set */
if(NOQUIET) warning2("ID3v2: Won't parse the ID3v2 tag with major version %u and flags 0x%xu - some extra code may be needed", major, flags);
#endif
if((ret2 = fr->rd->skip_bytes(fr,length)) < 0) /* will not store data in backbuff! */
ret = ret2;
#ifndef NO_ID3V2
}
else
{
fr->id3v2.version = major;
/* try to interpret that beast */
if((tagdata = (unsigned char*) malloc(length+1)) != NULL)
{
debug("ID3v2: analysing frames...");
if((ret2 = fr->rd->read_frame_body(fr,tagdata,length)) > 0)
{
unsigned long tagpos = 0;
debug1("ID3v2: have read at all %lu bytes for the tag now", (unsigned long)length+6);
/* going to apply strlen for strings inside frames, make sure that it doesn't overflow! */
tagdata[length] = 0;
if(flags & EXTHEAD_FLAG)
{
debug("ID3v2: skipping extended header");
if(!bytes_to_long(tagdata, tagpos))
{
ret = 0;
if(NOQUIET) error4("Bad (non-synchsafe) tag offset: 0x%02x%02x%02x%02x", tagdata[0], tagdata[1], tagdata[2], tagdata[3]);
}
}
if(ret > 0)
{
char id[5];
unsigned long framesize;
unsigned long fflags; /* need 16 bits, actually */
id[4] = 0;
/* pos now advanced after ext head, now a frame has to follow */
while(tagpos < length-10) /* I want to read at least a full header */
{
int i = 0;
unsigned long pos = tagpos;
int head_part = fr->id3v2.version == 2 ? 3 : 4; /* bytes of frame title and of framesize value */
/* level 1,2,3 - 0 is info from lame/info tag! */
/* rva tags with ascending significance, then general frames */
enum frame_types tt = unknown;
/* we may have entered the padding zone or any other strangeness: check if we have valid frame id characters */
for(i=0; i< head_part; ++i)
if( !( ((tagdata[tagpos+i] > 47) && (tagdata[tagpos+i] < 58))
|| ((tagdata[tagpos+i] > 64) && (tagdata[tagpos+i] < 91)) ) )
{
debug5("ID3v2: real tag data apparently ended after %lu bytes with 0x%02x%02x%02x%02x", tagpos, tagdata[tagpos], tagdata[tagpos+1], tagdata[tagpos+2], tagdata[tagpos+3]);
/* This is no hard error... let's just hope that we got something meaningful already (ret==1 in that case). */
goto tagparse_cleanup; /* Need to escape two loops here. */
}
if(ret > 0)
{
/* 4 or 3 bytes id */
strncpy(id, (char*) tagdata+pos, head_part);
pos += head_part;
tagpos += head_part;
/* size as 32 bits or 28 bits */
if(fr->id3v2.version == 2) threebytes_to_long(tagdata+pos, framesize);
else
if(!bytes_to_long(tagdata+pos, framesize))
{
/* Just assume that up to now there was some good data. */
if(NOQUIET) error1("ID3v2: non-syncsafe size of %s frame, skipping the remainder of tag", id);
break;
}
if(VERBOSE3) fprintf(stderr, "Note: ID3v2 %s frame of size %lu\n", id, framesize);
tagpos += head_part + framesize; /* the important advancement in whole tag */
if(tagpos > length)
{
if(NOQUIET) error("Whoa! ID3v2 frame claims to be larger than the whole rest of the tag.");
break;
}
pos += head_part;
if(fr->id3v2.version > 2)
{
fflags = (((unsigned long) tagdata[pos]) << 8) | ((unsigned long) tagdata[pos+1]);
pos += 2;
tagpos += 2;
}
else fflags = 0;
/* for sanity, after full parsing tagpos should be == pos */
/* debug4("ID3v2: found %s frame, size %lu (as bytes: 0x%08lx), flags 0x%016lx", id, framesize, framesize, fflags); */
/* %0abc0000 %0h00kmnp */
#define BAD_FFLAGS (unsigned long) 36784
#define PRES_TAG_FFLAG 16384
#define PRES_FILE_FFLAG 8192
#define READ_ONLY_FFLAG 4096
#define GROUP_FFLAG 64
#define COMPR_FFLAG 8
#define ENCR_FFLAG 4
#define UNSYNC_FFLAG 2
#define DATLEN_FFLAG 1
if(head_part < 4 && promote_framename(fr, id) != 0) continue;
/* shall not or want not handle these */
if(fflags & (BAD_FFLAGS | COMPR_FFLAG | ENCR_FFLAG))
{
if(NOQUIET) warning("ID3v2: skipping invalid/unsupported frame");
continue;
}
for(i = 0; i < KNOWN_FRAMES; ++i)
if(!strncmp(frame_type[i], id, 4)){ tt = i; break; }
if(id[0] == 'T' && tt != extra) tt = text;
if(tt != unknown)
{
int rva_mode = -1; /* mix / album */
unsigned long realsize = framesize;
unsigned char* realdata = tagdata+pos;
if((flags & UNSYNC_FLAG) || (fflags & UNSYNC_FFLAG))
{
unsigned long ipos = 0;
unsigned long opos = 0;
debug("Id3v2: going to de-unsync the frame data");
/* de-unsync: FF00 -> FF; real FF00 is simply represented as FF0000 ... */
/* damn, that means I have to delete bytes from withing the data block... thus need temporal storage */
/* standard mandates that de-unsync should always be safe if flag is set */
realdata = (unsigned char*) malloc(framesize); /* will need <= bytes */
if(realdata == NULL)
{
if(NOQUIET) error("ID3v2: unable to allocate working buffer for de-unsync");
continue;
}
/* now going byte per byte through the data... */
realdata[0] = tagdata[pos];
opos = 1;
for(ipos = pos+1; ipos < pos+framesize; ++ipos)
{
if(!((tagdata[ipos] == 0) && (tagdata[ipos-1] == 0xff)))
{
realdata[opos++] = tagdata[ipos];
}
}
realsize = opos;
debug2("ID3v2: de-unsync made %lu out of %lu bytes", realsize, framesize);
}
pos = 0; /* now at the beginning again... */
switch(tt)
{
case comment:
case uslt:
process_comment(fr, tt, (char*)realdata, realsize, comment+1, id);
break;
case extra: /* perhaps foobar2000's work */
process_extra(fr, (char*)realdata, realsize, extra+1, id);
break;
case rva2: /* "the" RVA tag */
{
/* starts with null-terminated identification */
if(VERBOSE3) fprintf(stderr, "Note: RVA2 identification \"%s\"\n", realdata);
/* default: some individual value, mix mode */
rva_mode = 0;
if( !strncasecmp((char*)realdata, "album", 5)
|| !strncasecmp((char*)realdata, "audiophile", 10)
|| !strncasecmp((char*)realdata, "user", 4))
rva_mode = 1;
if(fr->rva.level[rva_mode] <= rva2+1)
{
pos += strlen((char*) realdata) + 1;
if(realdata[pos] == 1)
{
++pos;
/* only handle master channel */
debug("ID3v2: it is for the master channel");
/* two bytes adjustment, one byte for bits representing peak - n bytes, eh bits, for peak */
/* 16 bit signed integer = dB * 512 ... the double cast is needed to preserve the sign of negative values! */
fr->rva.gain[rva_mode] = (float) ( (((short)((signed char)realdata[pos])) << 8) | realdata[pos+1] ) / 512;
pos += 2;
if(VERBOSE3) fprintf(stderr, "Note: RVA value %fdB\n", fr->rva.gain[rva_mode]);
/* heh, the peak value is represented by a number of bits - but in what manner? Skipping that part */
fr->rva.peak[rva_mode] = 0;
fr->rva.level[rva_mode] = rva2+1;
}
}
}
break;
/* non-rva metainfo, simply store... */
case text:
process_text(fr, (char*)realdata, realsize, id);
break;
default: if(NOQUIET) error1("ID3v2: unknown frame type %i", tt);
}
if((flags & UNSYNC_FLAG) || (fflags & UNSYNC_FFLAG)) free(realdata);
}
#undef BAD_FFLAGS
#undef PRES_TAG_FFLAG
#undef PRES_FILE_FFLAG
#undef READ_ONLY_FFLAG
#undef GROUP_FFLAG
#undef COMPR_FFLAG
#undef ENCR_FFLAG
#undef UNSYNC_FFLAG
#undef DATLEN_FFLAG
}
else break;
#undef KNOWN_FRAMES
}
}
}
else
{
if(NOQUIET) error("ID3v2: Duh, not able to read ID3v2 tag data.");
ret = ret2;
}
tagparse_cleanup:
free(tagdata);
}
else
{
if(NOQUIET) error1("ID3v2: Arrg! Unable to allocate %lu bytes for interpreting ID3v2 data - trying to skip instead.", length);
if((ret2 = fr->rd->skip_bytes(fr,length)) < 0) ret = ret2; /* will not store data in backbuff! */
else ret = 0;
}
}
#endif /* NO_ID3V2 */
/* skip footer if present */
if((ret > 0) && (flags & FOOTER_FLAG) && ((ret2 = fr->rd->skip_bytes(fr,length)) < 0)) ret = ret2;
return ret;
#undef UNSYNC_FLAG
#undef EXTHEAD_FLAG
#undef EXP_FLAG
#undef FOOTER_FLAG
#undef UNKOWN_FLAGS
}
#ifndef NO_ID3V2 /* Disabling all the rest... */
static void convert_latin1(mpg123_string *sb, const unsigned char* s, size_t l, const int noquiet)
{
size_t length = l;
size_t i;
unsigned char *p;
/* determine real length, a latin1 character can at most take 2 in UTF8 */
for(i=0; i<l; ++i)
if(s[i] >= 0x80) ++length;
debug1("UTF-8 length: %lu", (unsigned long)length);
/* one extra zero byte for paranoia */
if(!mpg123_resize_string(sb, length+1)){ mpg123_free_string(sb); return ; }
p = (unsigned char*) sb->p; /* Signedness doesn't matter but it shows I thought about the non-issue */
for(i=0; i<l; ++i)
if(s[i] < 0x80){ *p = s[i]; ++p; }
else /* two-byte encoding */
{
*p = 0xc0 | (s[i]>>6);
*(p+1) = 0x80 | (s[i] & 0x3f);
p+=2;
}
sb->p[length] = 0;
sb->fill = length+1;
}
/*
Check if we have a byte oder mark(s) there, return:
-1: little endian
0: no BOM
1: big endian
This modifies source and len to indicate the data _after_ the BOM(s).
Note on nasty data: The last encountered BOM determines the endianess.
I have seen data with multiple BOMS, namely from "the" id3v2 program.
Not nice, but what should I do?
*/
static int check_bom(const unsigned char** source, size_t *len)
{
int this_bom = 0;
int further_bom = 0;
if(*len < 2) return 0;
if((*source)[0] == 0xff && (*source)[1] == 0xfe)
this_bom = -1;
if((*source)[0] == 0xfe && (*source)[1] == 0xff)
this_bom = 1;
/* Skip the detected BOM. */
if(this_bom != 0)
{
*source += 2;
*len -= 2;
/* Check for following BOMs. The last one wins! */
further_bom = check_bom(source, len);
if(further_bom == 0) return this_bom; /* End of the recursion. */
else return further_bom;
}
else return 0;
}
#define FULLPOINT(f,s) ( (((f)&0x3ff)<<10) + ((s)&0x3ff) + 0x10000 )
/* Remember: There's a limit at 0x1ffff. */
#define UTF8LEN(x) ( (x)<0x80 ? 1 : ((x)<0x800 ? 2 : ((x)<0x10000 ? 3 : 4)))
static void convert_utf16bom(mpg123_string *sb, const unsigned char* s, size_t l, const int noquiet)
{
size_t i;
size_t n; /* number bytes that make up full pairs */
unsigned char *p;
size_t length = 0; /* the resulting UTF-8 length */
/* Determine real length... extreme case can be more than utf-16 length. */
size_t high = 0;
size_t low = 1;
int bom_endian;
debug1("convert_utf16 with length %lu", (unsigned long)l);
bom_endian = check_bom(&s, &l);
debug1("UTF16 endianess check: %i", bom_endian);
if(bom_endian == -1) /* little-endian */
{
high = 1; /* The second byte is the high byte. */
low = 0; /* The first byte is the low byte. */
}
n = (l/2)*2; /* number bytes that make up full pairs */
/* first: get length, check for errors -- stop at first one */
for(i=0; i < n; i+=2)
{
unsigned long point = ((unsigned long) s[i+high]<<8) + s[i+low];
if((point & 0xd800) == 0xd800) /* lead surrogate */
{
unsigned short second = (i+3 < l) ? (s[i+2+high]<<8) + s[i+2+low] : 0;
if((second & 0xdc00) == 0xdc00) /* good... */
{
point = FULLPOINT(point,second);
length += UTF8LEN(point); /* possibly 4 bytes */
i+=2; /* We overstepped one word. */
}
else /* if no valid pair, break here */
{
if(noquiet) error2("Invalid UTF16 surrogate pair at %li (0x%04lx).", (unsigned long)i, point);
n = i; /* Forget the half pair, END! */
break;
}
}
else length += UTF8LEN(point); /* 1,2 or 3 bytes */
}
if(!mpg123_resize_string(sb, length+1)){ mpg123_free_string(sb); return ; }
/* Now really convert, skip checks as these have been done just before. */
p = (unsigned char*) sb->p; /* Signedness doesn't matter but it shows I thought about the non-issue */
for(i=0; i < n; i+=2)
{
unsigned long codepoint = ((unsigned long) s[i+high]<<8) + s[i+low];
if((codepoint & 0xd800) == 0xd800) /* lead surrogate */
{
unsigned short second = (s[i+2+high]<<8) + s[i+2+low];
codepoint = FULLPOINT(codepoint,second);
i+=2; /* We overstepped one word. */
}
if(codepoint < 0x80) *p++ = (unsigned char) codepoint;
else if(codepoint < 0x800)
{
*p++ = (unsigned char) (0xc0 | (codepoint>>6));
*p++ = (unsigned char) (0x80 | (codepoint & 0x3f));
}
else if(codepoint < 0x10000)
{
*p++ = (unsigned char) (0xe0 | (codepoint>>12));
*p++ = 0x80 | ((codepoint>>6) & 0x3f);
*p++ = 0x80 | (codepoint & 0x3f);
}
else if (codepoint < 0x200000)
{
*p++ = (unsigned char) (0xf0 | codepoint>>18);
*p++ = (unsigned char) (0x80 | ((codepoint>>12) & 0x3f));
*p++ = (unsigned char) (0x80 | ((codepoint>>6) & 0x3f));
*p++ = (unsigned char) (0x80 | (codepoint & 0x3f));
} /* ignore bigger ones (that are not possible here anyway) */
}
sb->p[sb->size-1] = 0; /* paranoia... */
sb->fill = sb->size;
}
#undef UTF8LEN
#undef FULLPOINT
static void convert_utf8(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet)
{
if(mpg123_resize_string(sb, len+1))
{
memcpy(sb->p, source, len);
sb->p[len] = 0;
sb->fill = len+1;
}
else mpg123_free_string(sb);
}
#endif

View File

@ -0,0 +1,31 @@
/*
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
# define init_id3(fr)
# define exit_id3(fr)
# define reset_id3(fr)
# 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,114 @@
/*
index: frame index data structure and functions
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 "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
{
error("failed to resize index!");
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);
}
}
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,56 @@
#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);
/* Empty the index (setting fill=0 and step=1), but keep current size. */
void fi_reset(struct frame_index *fi);
#endif

View File

@ -0,0 +1,278 @@
/*
l12_integer_tables.h: Layer1/2 Constant tables for integer decoders
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 Taihei Monma
*/
#ifndef MPG123_L12_INTEGER_TABLES_H
#define MPG123_L12_INTEGER_TABLES_H
static const real layer12_table[27][64] =
{
{
},
{
-1431655765,-1136305934,-901886617,-715827883,-568152967,-450943309,-357913941,-284076483,
-225471654,-178956971,-142038242,-112735827,-89478485,-71019121,-56367914,-44739243,
-35509560,-28183957,-22369621,-17754780,-14091978,-11184811,-8877390,-7045989,
-5592405,-4438695,-3522995,-2796203,-2219348,-1761497,-1398101,-1109674,
-880749,-699051,-554837,-440374,-349525,-277418,-220187,-174763,
-138709,-110094,-87381,-69355,-55047,-43691,-34677,-27523,
-21845,-17339,-13762,-10923,-8669,-6881,-5461,-4335,
-3440,-2731,-2167,-1720,-1365,-1084,-860,0
},
{
1431655765,1136305934,901886617,715827883,568152967,450943309,357913941,284076483,
225471654,178956971,142038242,112735827,89478485,71019121,56367914,44739243,
35509560,28183957,22369621,17754780,14091978,11184811,8877390,7045989,
5592405,4438695,3522995,2796203,2219348,1761497,1398101,1109674,
880749,699051,554837,440374,349525,277418,220187,174763,
138709,110094,87381,69355,55047,43691,34677,27523,
21845,17339,13762,10923,8669,6881,5461,4335,
3440,2731,2167,1720,1365,1084,860,0
},
{
613566757,486988257,386522836,306783378,243494129,193261418,153391689,121747064,
96630709,76695845,60873532,48315355,38347922,30436766,24157677,19173961,
15218383,12078839,9586981,7609192,6039419,4793490,3804596,3019710,
2396745,1902298,1509855,1198373,951149,754927,599186,475574,
377464,299593,237787,188732,149797,118894,94366,74898,
59447,47183,37449,29723,23591,18725,14862,11796,
9362,7431,5898,4681,3715,2949,2341,1858,
1474,1170,929,737,585,464,369,0
},
{
286331153,227261187,180377323,143165577,113630593,90188662,71582788,56815297,
45094331,35791394,28407648,22547165,17895697,14203824,11273583,8947849,
7101912,5636791,4473924,3550956,2818396,2236962,1775478,1409198,
1118481,887739,704599,559241,443870,352299,279620,221935,
176150,139810,110967,88075,69905,55484,44037,34953,
27742,22019,17476,13871,11009,8738,6935,5505,
4369,3468,2752,2185,1734,1376,1092,867,
688,546,433,344,273,217,172,0
},
{
138547332,109965090,87279350,69273666,54982545,43639675,34636833,27491273,
21819838,17318417,13745636,10909919,8659208,6872818,5454959,4329604,
3436409,2727480,2164802,1718205,1363740,1082401,859102,681870,
541201,429551,340935,270600,214776,170467,135300,107388,
85234,67650,53694,42617,33825,26847,21308,16913,
13423,10654,8456,6712,5327,4228,3356,2664,
2114,1678,1332,1057,839,666,529,419,
333,264,210,166,132,105,83,0
},
{
68174084,54109806,42946982,34087042,27054903,21473491,17043521,13527452,
10736745,8521761,6763726,5368373,4260880,3381863,2684186,2130440,
1690931,1342093,1065220,845466,671047,532610,422733,335523,
266305,211366,167762,133153,105683,83881,66576,52842,
41940,33288,26421,20970,16644,13210,10485,8322,
6605,5243,4161,3303,2621,2081,1651,1311,
1040,826,655,520,413,328,260,206,
164,130,103,82,65,52,41,0
},
{
33818640,26841872,21304408,16909320,13420936,10652204,8454660,6710468,
5326102,4227330,3355234,2663051,2113665,1677617,1331526,1056833,
838809,665763,528416,419404,332881,264208,209702,166441,
132104,104851,83220,66052,52426,41610,33026,26213,
20805,16513,13106,10403,8257,6553,5201,4128,
3277,2601,2064,1638,1300,1032,819,650,
516,410,325,258,205,163,129,102,
81,65,51,41,32,26,20,0
},
{
16843009,13368305,10610431,8421505,6684153,5305215,4210752,3342076,
2652608,2105376,1671038,1326304,1052688,835519,663152,526344,
417760,331576,263172,208880,165788,131586,104440,82894,
65793,52220,41447,32897,26110,20723,16448,13055,
10362,8224,6527,5181,4112,3264,2590,2056,
1632,1295,1028,816,648,514,408,324,
257,204,162,129,102,81,64,51,
40,32,25,20,16,13,10,0
},
{
8405024,6671072,5294833,4202512,3335536,2647417,2101256,1667768,
1323708,1050628,833884,661854,525314,416942,330927,262657,
208471,165464,131329,104236,82732,65664,52118,41366,
32832,26059,20683,16416,13029,10341,8208,6515,
5171,4104,3257,2585,2052,1629,1293,1026,
814,646,513,407,323,257,204,162,
128,102,81,64,51,40,32,25,
20,16,13,10,8,6,5,0
},
{
4198404,3332275,2644829,2099202,1666138,1322414,1049601,833069,
661207,524801,416534,330604,262400,208267,165302,131200,
104134,82651,65600,52067,41325,32800,26033,20663,
16400,13017,10331,8200,6508,5166,4100,3254,
2583,2050,1627,1291,1025,814,646,513,
407,323,256,203,161,128,102,81,
64,51,40,32,25,20,16,13,
10,8,6,5,4,3,3,0
},
{
2098177,1665324,1321768,1049088,832662,660884,524544,416331,
330442,262272,208165,165221,131136,104083,82611,65568,
52041,41305,32784,26021,20653,16392,13010,10326,
8196,6505,5163,4098,3253,2582,2049,1626,
1291,1025,813,645,512,407,323,256,
203,161,128,102,81,64,51,40,
32,25,20,16,13,10,8,6,
5,4,3,3,2,2,1,0
},
{
1048832,832459,660723,524416,416229,330361,262208,208115,
165181,131104,104057,82590,65552,52029,41295,32776,
26014,20648,16388,13007,10324,8194,6504,5162,
4097,3252,2581,2049,1626,1290,1024,813,
645,512,406,323,256,203,161,128,
102,81,64,51,40,32,25,20,
16,13,10,8,6,5,4,3,
3,2,2,1,1,1,1,0
},
{
524352,416178,330321,262176,208089,165161,131088,104045,
82580,65544,52022,41290,32772,26011,20645,16386,
13006,10323,8193,6503,5161,4097,3251,2581,
2048,1626,1290,1024,813,645,512,406,
323,256,203,161,128,102,81,64,
51,40,32,25,20,16,13,10,
8,6,5,4,3,3,2,2,
1,1,1,1,1,0,0,0
},
{
262160,208077,165150,131080,104038,82575,65540,52019,
41288,32770,26010,20644,16385,13005,10322,8193,
6502,5161,4096,3251,2580,2048,1626,1290,
1024,813,645,512,406,323,256,203,
161,128,102,81,64,51,40,32,
25,20,16,13,10,8,6,5,
4,3,3,2,2,1,1,1,
1,1,0,0,0,0,0,0
},
{
131076,104035,82573,65538,52018,41286,32769,26009,
20643,16385,13004,10322,8192,6502,5161,4096,
3251,2580,2048,1626,1290,1024,813,645,
512,406,323,256,203,161,128,102,
81,64,51,40,32,25,20,16,
13,10,8,6,5,4,3,3,
2,2,1,1,1,1,1,0,
0,0,0,0,0,0,0,0
},
{
65537,52017,41286,32769,26008,20643,16384,13004,
10321,8192,6502,5161,4096,3251,2580,2048,
1626,1290,1024,813,645,512,406,323,
256,203,161,128,102,81,64,51,
40,32,25,20,16,13,10,8,
6,5,4,3,3,2,2,1,
1,1,1,1,0,0,0,0,
0,0,0,0,0,0,0,0
},
{
-1717986918,-1363567121,-1082263941,-858993459,-681783560,-541131970,-429496730,-340891780,
-270565985,-214748365,-170445890,-135282993,-107374182,-85222945,-67641496,-53687091,
-42611473,-33820748,-26843546,-21305736,-16910374,-13421773,-10652868,-8455187,
-6710886,-5326434,-4227594,-3355443,-2663217,-2113797,-1677722,-1331609,
-1056898,-838861,-665804,-528449,-419430,-332902,-264225,-209715,
-166451,-132112,-104858,-83226,-66056,-52429,-41613,-33028,
-26214,-20806,-16514,-13107,-10403,-8257,-6554,-5202,
-4129,-3277,-2601,-2064,-1638,-1300,-1032,0
},
{
-858993459,-681783560,-541131970,-429496730,-340891780,-270565985,-214748365,-170445890,
-135282993,-107374182,-85222945,-67641496,-53687091,-42611473,-33820748,-26843546,
-21305736,-16910374,-13421773,-10652868,-8455187,-6710886,-5326434,-4227594,
-3355443,-2663217,-2113797,-1677722,-1331609,-1056898,-838861,-665804,
-528449,-419430,-332902,-264225,-209715,-166451,-132112,-104858,
-83226,-66056,-52429,-41613,-33028,-26214,-20806,-16514,
-13107,-10403,-8257,-6554,-5202,-4129,-3277,-2601,
-2064,-1638,-1300,-1032,-819,-650,-516,0
},
{
858993459,681783560,541131970,429496730,340891780,270565985,214748365,170445890,
135282993,107374182,85222945,67641496,53687091,42611473,33820748,26843546,
21305736,16910374,13421773,10652868,8455187,6710886,5326434,4227594,
3355443,2663217,2113797,1677722,1331609,1056898,838861,665804,
528449,419430,332902,264225,209715,166451,132112,104858,
83226,66056,52429,41613,33028,26214,20806,16514,
13107,10403,8257,6554,5202,4129,3277,2601,
2064,1638,1300,1032,819,650,516,0
},
{
1717986918,1363567121,1082263941,858993459,681783560,541131970,429496730,340891780,
270565985,214748365,170445890,135282993,107374182,85222945,67641496,53687091,
42611473,33820748,26843546,21305736,16910374,13421773,10652868,8455187,
6710886,5326434,4227594,3355443,2663217,2113797,1677722,1331609,
1056898,838861,665804,528449,419430,332902,264225,209715,
166451,132112,104858,83226,66056,52429,41613,33028,
26214,20806,16514,13107,10403,8257,6554,5202,
4129,3277,2601,2064,1638,1300,1032,0
},
{
-1908874354,-1515074579,-1202515490,-954437177,-757537289,-601257745,-477218588,-378768645,
-300628872,-238609294,-189384322,-150314436,-119304647,-94692161,-75157218,-59652324,
-47346081,-37578609,-29826162,-23673040,-18789305,-14913081,-11836520,-9394652,
-7456540,-5918260,-4697326,-3728270,-2959130,-2348663,-1864135,-1479565,
-1174332,-932068,-739783,-587166,-466034,-369891,-293583,-233017,
-184946,-146791,-116508,-92473,-73396,-58254,-46236,-36698,
-29127,-23118,-18349,-14564,-11559,-9174,-7282,-5780,
-4587,-3641,-2890,-2294,-1820,-1445,-1147,0
},
{
-954437177,-757537289,-601257745,-477218588,-378768645,-300628872,-238609294,-189384322,
-150314436,-119304647,-94692161,-75157218,-59652324,-47346081,-37578609,-29826162,
-23673040,-18789305,-14913081,-11836520,-9394652,-7456540,-5918260,-4697326,
-3728270,-2959130,-2348663,-1864135,-1479565,-1174332,-932068,-739783,
-587166,-466034,-369891,-293583,-233017,-184946,-146791,-116508,
-92473,-73396,-58254,-46236,-36698,-29127,-23118,-18349,
-14564,-11559,-9174,-7282,-5780,-4587,-3641,-2890,
-2294,-1820,-1445,-1147,-910,-722,-573,0
},
{
-477218588,-378768645,-300628872,-238609294,-189384322,-150314436,-119304647,-94692161,
-75157218,-59652324,-47346081,-37578609,-29826162,-23673040,-18789305,-14913081,
-11836520,-9394652,-7456540,-5918260,-4697326,-3728270,-2959130,-2348663,
-1864135,-1479565,-1174332,-932068,-739783,-587166,-466034,-369891,
-293583,-233017,-184946,-146791,-116508,-92473,-73396,-58254,
-46236,-36698,-29127,-23118,-18349,-14564,-11559,-9174,
-7282,-5780,-4587,-3641,-2890,-2294,-1820,-1445,
-1147,-910,-722,-573,-455,-361,-287,0
},
{
477218588,378768645,300628872,238609294,189384322,150314436,119304647,94692161,
75157218,59652324,47346081,37578609,29826162,23673040,18789305,14913081,
11836520,9394652,7456540,5918260,4697326,3728270,2959130,2348663,
1864135,1479565,1174332,932068,739783,587166,466034,369891,
293583,233017,184946,146791,116508,92473,73396,58254,
46236,36698,29127,23118,18349,14564,11559,9174,
7282,5780,4587,3641,2890,2294,1820,1445,
1147,910,722,573,455,361,287,0
},
{
954437177,757537289,601257745,477218588,378768645,300628872,238609294,189384322,
150314436,119304647,94692161,75157218,59652324,47346081,37578609,29826162,
23673040,18789305,14913081,11836520,9394652,7456540,5918260,4697326,
3728270,2959130,2348663,1864135,1479565,1174332,932068,739783,
587166,466034,369891,293583,233017,184946,146791,116508,
92473,73396,58254,46236,36698,29127,23118,18349,
14564,11559,9174,7282,5780,4587,3641,2890,
2294,1820,1445,1147,910,722,573,0
},
{
1908874354,1515074579,1202515490,954437177,757537289,601257745,477218588,378768645,
300628872,238609294,189384322,150314436,119304647,94692161,75157218,59652324,
47346081,37578609,29826162,23673040,18789305,14913081,11836520,9394652,
7456540,5918260,4697326,3728270,2959130,2348663,1864135,1479565,
1174332,932068,739783,587166,466034,369891,293583,233017,
184946,146791,116508,92473,73396,58254,46236,36698,
29127,23118,18349,14564,11559,9174,7282,5780,
4587,3641,2890,2294,1820,1445,1147,0
},
};
#endif

View File

@ -0,0 +1,164 @@
/*
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
*/
#ifndef _MPG123_L2TABLES_H_
#define _MPG123_L2TABLES_H_
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} };
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} };
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} };
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} };
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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
/*
layer1.c: the layer 1 decoder
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
may have a few bugs after last optimization ...
*/
#include "mpg123lib_intern.h"
#include "getbits.h"
void 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;
for(i=0;i<jsbound;i++)
{
*ba++ = getbits(fr, 4);
*ba++ = getbits(fr, 4);
}
for(i=jsbound;i<SBLIMIT;i++) *ba++ = getbits(fr, 4);
ba = balloc;
for(i=0;i<jsbound;i++)
{
if ((*ba++))
*sca++ = getbits(fr, 6);
if ((*ba++))
*sca++ = getbits(fr, 6);
}
for (i=jsbound;i<SBLIMIT;i++)
if((*ba++))
{
*sca++ = getbits(fr, 6);
*sca++ = getbits(fr, 6);
}
}
else
{
int i;
for(i=0;i<SBLIMIT;i++) *ba++ = getbits(fr, 4);
ba = balloc;
for (i=0;i<SBLIMIT;i++)
if ((*ba++))
*sca++ = getbits(fr, 6);
}
}
void 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)
{
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++)) *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( ((-1)<<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( ((-1)<<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( ((-1)<<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
{
register real *f0 = fraction[0];
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( ((-1)<<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);
}
}
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];
ALIGNED(16) real 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;
I_step_one(balloc,scale_index,fr);
for(i=0;i<SCALE_BLOCK;i++)
{
I_step_two(fraction,balloc,scale_index,fr);
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,369 @@
/*
layer2.c: the layer 2 decoder, root of mpg123
copyright 1994-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
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. */
static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */
static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */
static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
#if defined(REAL_IS_FIXED) && defined(PRECALC_TABLES)
#include "l12_integer_tables.h"
#else
static const double mulmul[27] =
{
0.0 , -2.0/3.0 , 2.0/3.0 ,
2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 ,
2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 ,
2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 ,
-4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 ,
-8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0
};
#endif
void init_layer12(void)
{
const int base[3][9] =
{
{ 1 , 0, 2 , } ,
{ 17, 18, 0 , 19, 20 , } ,
{ 21, 1, 22, 23, 0, 24, 25, 2, 26 }
};
int i,j,k,l,len;
const int tablen[3] = { 3 , 5 , 9 };
int *itable;
int *tables[3] = { grp_3tab , grp_5tab , grp_9tab };
for(i=0;i<3;i++)
{
itable = tables[i];
len = tablen[i];
for(j=0;j<len;j++)
for(k=0;k<len;k++)
for(l=0;l<len;l++)
{
*itable++ = base[i][l];
*itable++ = base[i][k];
*itable++ = base[i][j];
}
}
}
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)
{
#if defined(REAL_IS_FIXED) && defined(PRECALC_TABLES)
int i;
for(i=0;i<63;i++)
*table++ = layer12_table[m][i];
#else
int i,j;
for(j=3,i=0;i<63;i++,j--)
*table++ = DOUBLE_TO_REAL_SCALE_LAYER12(mulmul[m] * pow(2.0,(double) j / 3.0));
#endif
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++ = DOUBLE_TO_REAL(16384 * mulmul[m] * pow(2.0,(double) j / 3.0));
}
else
{
for(j=3,i=0;i<63;i++,j--)
*table++ = DOUBLE_TO_REAL(mulmul[m] * pow(2.0,(double) j / 3.0));
}
return table;
}
#endif
#endif /* NO_LAYER12 */
/* The rest is the actual decoding of layer II data. */
#ifndef NO_LAYER2
void 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;
bita = bit_alloc;
if(stereo)
{
for(i=jsbound;i;i--,alloc1+=(1<<step))
{
step=alloc1->bits;
*bita++ = (char) getbits(fr, step);
*bita++ = (char) getbits(fr, step);
}
for(i=sblimit-jsbound;i;i--,alloc1+=(1<<step))
{
step=alloc1->bits;
bita[0] = (char) getbits(fr, step);
bita[1] = bita[0];
bita+=2;
}
bita = bit_alloc;
scfsi=scfsi_buf;
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);
}
bita = bit_alloc;
scfsi=scfsi_buf;
for(i=sblimit;i;i--)
if(*bita++) *scfsi++ = (char) getbits_fast(fr, 2);
}
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;
}
}
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 int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
unsigned int idx,*tab,m=scale[x1];
idx = (unsigned int) getbits(fr, k);
tab = (unsigned int *) (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);
}
}
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 int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
unsigned int idx,*tab,m1,m2;
m1 = scale[x1]; m2 = scale[x1+3];
idx = (unsigned int) getbits(fr, k);
tab = (unsigned int *) (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;
}
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;
ALIGNED(16) real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
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;
II_step_one(bit_alloc, scale, fr);
for(i=0;i<SCALE_BLOCK;i++)
{
II_step_two(bit_alloc,fraction,scale,fr,i>>2);
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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
/*
mangle: support defines for preprocessed assembler
copyright 1995-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
This once started out as mangle.h from MPlayer, but you can't really call it derived work... the small part that in principle stems from MPlayer also being not very special (once you decided to use such a header at all, it's quite obvious material).
*/
#ifndef __MANGLE_H
#define __MANGLE_H
#include "config.h"
#ifdef CCALIGN
#define MOVUAPS movaps
#else
#define MOVUAPS movups
#endif
#ifdef ASMALIGN_EXP
#define ALIGN4 .align 2
#define ALIGN8 .align 3
#define ALIGN16 .align 4
#define ALIGN32 .align 5
#else
#define ALIGN4 .align 4
#define ALIGN8 .align 8
#define ALIGN16 .align 16
#define ALIGN32 .align 32
#endif
/* Feel free to add more to the list, eg. a.out IMO */
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || defined(_MSC_VER) || \
(defined(__OpenBSD__) && !defined(__ELF__)) || defined(__APPLE__)
#define ASM_NAME(a) _##a
#define ASM_VALUE(a) $_##a
#else
#define ASM_NAME(a) a
#define ASM_VALUE(a) $##a
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)
#define COMM(a,b,c) .comm a,b
#else
#define COMM(a,b,c) .comm a,b,c
#endif
/* more hacks for macosx; no .bss ... */
#ifdef __APPLE__
#define BSS .data
#else
#define BSS .bss
#endif
#endif /* !__MANGLE_H */

View File

@ -0,0 +1,924 @@
/*
libmpg123: MPEG Audio Decoder library (version 1.9.0)
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
*/
#ifndef MPG123_LIB_H
#define MPG123_LIB_H
/** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */
/* These aren't actually in use... seems to work without using libtool. */
#ifdef BUILD_MPG123_DLL
/* The dll exports. */
#define EXPORT __declspec(dllexport)
#else
#ifdef LINK_MPG123_DLL
/* The exe imports. */
#define EXPORT __declspec(dllimport)
#else
/* Nothing on normal/UNIX builds */
#define EXPORT
#endif
#endif
#ifndef MPG123_NO_CONFIGURE /* Enable use of this file without configure. */
#include <stdlib.h>
#include <sys/types.h>
#if 0 /* If we need trickery for large file support. */
/* Check for compiling programs agains this libmpg123. */
#if (defined _FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS+0 == )
/* ...all is fine, having enabled large file support and also the correct sort of which. */
#else
#error "Mismatch in large file setup! Enable/disable large file support appropriately to use libmpg123."
#endif
/* Redefine names of functions dealing with file and file offsets
...everything handling off_t, for example, which can be 32 or 64 bits. */
#define mpg123_open mpg123_open
#define mpg123_open_fd mpg123_open_fd
#define mpg123_decode_frame mpg123_decode_frame
#define mpg123_tell mpg123_tell
#define mpg123_tellframe mpg123_tellframe
#define mpg123_tell_stream mpg123_tell_stream
#define mpg123_seek mpg123_seek
#define mpg123_feedseek mpg123_feedseek
#define mpg123_seek_frame mpg123_seek_frame
#define mpg123_timeframe mpg123_timeframe
#define mpg123_index mpg123_index
#define mpg123_position mpg123_position
#define mpg123_length mpg123_length
#define mpg123_set_filesize mpg123_set_filesize
#endif /* LARGEFILE_SWITCH */
#endif /* MPG123_NO_CONFIGURE */
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup mpg123_init mpg123 library and handle setup
*
* Functions to initialise and shutdown the mpg123 library and handles.
* The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-)
* Tip: Use a RVA setting...
*
* @{
*/
/** Opaque structure for the libmpg123 decoder handle. */
struct mpg123_handle_struct;
/** Opaque structure for the libmpg123 decoder handle.
* Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner.
*/
typedef struct mpg123_handle_struct mpg123_handle;
/** Function to initialise the mpg123 library.
* This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library.
*
* \return MPG123_OK if successful, otherwise an error number.
*/
EXPORT int mpg123_init(void);
/** Function to close down the mpg123 library.
* This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. */
EXPORT void mpg123_exit(void);
/** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()).
* and optional retrieval of an error code to feed to mpg123_plain_strerror().
* Optional means: Any of or both the parameters may be NULL.
*
* \return Non-NULL pointer when successful.
*/
EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error);
/** Delete handle, mh is either a valid mpg123 handle or NULL. */
EXPORT void mpg123_delete(mpg123_handle *mh);
/** Enumeration of the parameters types that it is possible to set/get. */
enum mpg123_parms
{
MPG123_VERBOSE, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense (integer) */
MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX (integer) */
MPG123_ADD_FLAGS, /**< add some flags (integer) */
MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value (integer) */
MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate (integer) */
MPG123_RVA, /**< one of the RVA choices above (integer) */
MPG123_DOWNSPEED, /**< play a frame N times (integer) */
MPG123_UPSPEED, /**< play every Nth frame (integer) */
MPG123_START_FRAME, /**< start with this frame (skip frames before that, integer) */
MPG123_DECODE_FRAMES, /**< decode only this number of frames (integer) */
MPG123_ICY_INTERVAL, /**< stream contains ICY metadata with this interval (integer) */
MPG123_OUTSCALE, /**< the scale for output samples (amplitude - integer or float according to mpg123 output format, normally integer) */
MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32, integer) */
MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS, integer) */
MPG123_RESYNC_LIMIT, /**< Try resync on frame parsing for that many bytes or until end of stream (<0 ... integer). */
MPG123_INDEX_SIZE /**< Set the frame index size (if supported). Values <0 mean that the index is allowed to grow dynamically in these steps (in positive direction, of course) -- Use this when you really want a full index with every individual frame. */
,MPG123_PREFRAMES /**< Decode/ignore that many frames in advance for layer 3. This is needed to fill bit reservoir after seeking, for example (but also at least one frame in advance is needed to have all "normal" data for layer 3). Give a positive integer value, please.*/
};
/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
enum mpg123_param_flags
{
MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */
,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */
,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */
,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */
,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */
,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */
,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */
,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
,MPG123_PLAIN_ID3TEXT = 0x800 /**< 100000000000 Do not translate ID3 text data to UTF-8. ID3 strings will contain the raw text data, with the first byte containing the ID3 encoding code. */
};
/** choices for MPG123_RVA */
enum mpg123_param_rva
{
MPG123_RVA_OFF = 0 /**< RVA disabled (default). */
,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */
,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */
,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */
};
/* TODO: Assess the possibilities and troubles of changing parameters during playback. */
/** Set a specific parameter, for a specific mpg123_handle, using a parameter
* type key chosen from the mpg123_parms enumeration, to the specified value. */
EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue);
/** Get a specific parameter, for a specific mpg123_handle.
* See the mpg123_parms enumeration for a list of available parameters. */
EXPORT int mpg123_getparam(mpg123_handle *mh, enum mpg123_parms type, long *val, double *fval);
/* @} */
/** \defgroup mpg123_error mpg123 error handling
*
* Functions to get text version of the error numbers and an enumeration
* of the error codes returned by libmpg123.
*
* Most functions operating on a mpg123_handle simply return MPG123_OK on success and MPG123_ERR on failure (setting the internal error variable of the handle to the specific error code).
* Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).
* The positive range of return values is used for "useful" values when appropriate.
*
* @{
*/
/** Enumeration of the message and error codes and returned by libmpg123 functions. */
enum mpg123_errors
{
MPG123_DONE=-12, /**< Message: Track ended. Stop decoding. */
MPG123_NEW_FORMAT=-11, /**< Message: Output format will be different on next call. Note that some libmpg123 versions between 1.4.3 and 1.8.0 insist on you calling mpg123_getformat() after getting this message code. Newer verisons behave like advertised: You have the chance to call mpg123_getformat(), but you can also just continue decoding and get your data. */
MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
MPG123_ERR=-1, /**< Generic Error */
MPG123_OK=0, /**< Success */
MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */
MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */
MPG123_BAD_RATE, /**< Invalid sample rate specified. */
MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */
MPG123_BAD_PARAM, /**< Bad parameter id! */
MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */
MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */
MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */
MPG123_BAD_DECODER, /**< Invalid decoder choice. */
MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */
MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */
MPG123_BAD_RVA, /**< Invalid RVA mode. */
MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */
MPG123_NO_SPACE, /**< Not enough buffer space. */
MPG123_BAD_TYPES, /**< Incompatible numeric data types. */
MPG123_BAD_BAND, /**< Bad equalizer band. */
MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */
MPG123_ERR_READER, /**< Error reading the stream. */
MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */
MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/
MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */
MPG123_BAD_FILE, /**< File access error. */
MPG123_NO_SEEK, /**< Seek not supported by stream. */
MPG123_NO_READER, /**< No stream opened. */
MPG123_BAD_PARS, /**< Bad parameter handle. */
MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() */
MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */
MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */
MPG123_NO_8BIT, /**< No 8bit encoding possible. */
MPG123_BAD_ALIGN, /**< Stack aligmnent error */
MPG123_NULL_BUFFER, /**< NULL input buffer with non-zero size... */
MPG123_NO_RELSEEK, /**< Relative seek not possible (screwed up file offset) */
MPG123_NULL_POINTER, /**< You gave a null pointer somewhere where you shouldn't have. */
MPG123_BAD_KEY, /**< Bad key value given. */
MPG123_NO_INDEX, /**< No frame index in this build. */
MPG123_INDEX_FAIL, /**< Something with frame index went wrong. */
MPG123_BAD_DECODER_SETUP, /**< Something prevents a proper decoder setup */
MPG123_MISSING_FEATURE /**< This feature has not been built into libmpg123. */
,MPG123_BAD_VALUE /**< A bad value has been given, somewhere. */
,MPG123_LSEEK_FAILED /**< Low-level seek failed. */
};
/** Return a string describing that error errcode means. */
EXPORT const char* mpg123_plain_strerror(int errcode);
/** Give string describing what error has occured in the context of handle mh.
* When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via
* char *errmsg = mpg123_strerror(mh)
* This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE. */
EXPORT const char* mpg123_strerror(mpg123_handle *mh);
/** Return the plain errcode intead of a string. */
EXPORT int mpg123_errcode(mpg123_handle *mh);
/*@}*/
/** \defgroup mpg123_decoder mpg123 decoder selection
*
* Functions to list and select the available decoders.
* Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is).
*
* @{
*/
/** Return a NULL-terminated array of generally available decoder names (plain 8bit ASCII). */
EXPORT const char **mpg123_decoders();
/** Return a NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII). */
EXPORT const char **mpg123_supported_decoders();
/** Set the chosen decoder to 'decoder_name' */
EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name);
/** Get the currently active decoder engine name.
The active decoder engine can vary depening on output constraints,
mostly non-resampling, integer output is accelerated via 3DNow & Co. but for other modes a fallback engine kicks in.
Note that this can return a decoder that is ony active in the hidden and not available as decoder choice from the outside.
\return The decoder name or NULL on error. */
EXPORT const char* mpg123_current_decoder(mpg123_handle *mh);
/*@}*/
/** \defgroup mpg123_output mpg123 output audio format
*
* Functions to get and select the format of the decoded audio.
*
* @{
*/
/** An enum over all sample types possibly known to mpg123.
* The values are designed as bit flags to allow bitmasking for encoding families.
*
* 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 are just for
* signed 16bit (and 8bit derived from that). Other formats use plain C code.
*
* All formats are in native byte order. On a little endian machine this should mean
* that you can just feed the MPG123_ENC_SIGNED_32 data to common 24bit hardware that
* ignores the lowest byte (or you could choose to do rounding with these lower bits).
*/
enum mpg123_enc_enum
{
MPG123_ENC_8 = 0x00f /**< 0000 0000 1111 Some 8 bit integer encoding. */
,MPG123_ENC_16 = 0x040 /**< 0000 0100 0000 Some 16 bit integer encoding. */
,MPG123_ENC_32 = 0x100 /**< 0001 0000 0000 Some 32 bit integer encoding. */
,MPG123_ENC_SIGNED = 0x080 /**< 0000 1000 0000 Some signed integer encoding. */
,MPG123_ENC_FLOAT = 0xe00 /**< 1110 0000 0000 Some float encoding. */
,MPG123_ENC_SIGNED_16 = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10) /**< 1101 0000 signed 16 bit */
,MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20) /**< 0110 0000 unsigned 16 bit */
,MPG123_ENC_UNSIGNED_8 = 0x01 /**< 0000 0001 unsigned 8 bit */
,MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED|0x02) /**< 1000 0010 signed 8 bit */
,MPG123_ENC_ULAW_8 = 0x04 /**< 0000 0100 ulaw 8 bit */
,MPG123_ENC_ALAW_8 = 0x08 /**< 0000 1000 alaw 8 bit */
,MPG123_ENC_SIGNED_32 = MPG123_ENC_32|MPG123_ENC_SIGNED|0x1000 /**< 0001 0001 1000 0000 signed 32 bit */
,MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x2000 /**< 0010 0001 0000 0000 unsigned 32 bit */
,MPG123_ENC_FLOAT_32 = 0x200 /**< 0010 0000 0000 32bit float */
,MPG123_ENC_FLOAT_64 = 0x400 /**< 0100 0000 0000 64bit float */
,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_FLOAT_32 | MPG123_ENC_FLOAT_64 ) /**< any encoding */
};
/** They can be combined into one number (3) to indicate mono and stereo... */
enum mpg123_channelcount
{
MPG123_MONO = 1
,MPG123_STEREO = 2
};
/** An array of supported standard sample rates
* These are possible native sample rates of MPEG audio files.
* You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings.
* \param list Store a pointer to the sample rates array there.
* \param number Store the number of sample rates there. */
EXPORT void mpg123_rates(const long **list, size_t *number);
/** An array of supported audio encodings.
* An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED).
* \param list Store a pointer to the encodings array there.
* \param number Store the number of encodings there. */
EXPORT void mpg123_encodings(const int **list, size_t *number);
/** Configure a mpg123 handle to accept no output format at all,
* use before specifying supported formats with mpg123_format */
EXPORT int mpg123_format_none(mpg123_handle *mh);
/** Configure mpg123 handle to accept all formats
* (also any custom rate you may set) -- this is default. */
EXPORT int mpg123_format_all(mpg123_handle *mh);
/** Set the audio format support of a mpg123_handle in detail:
* \param mh audio decoder handle
* \param rate The sample rate value (in Hertz).
* \param channels A combination of MPG123_STEREO and MPG123_MONO.
* \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support). Please note that some encodings may not be supported in the library build and thus will be ignored here.
* \return MPG123_OK on success, MPG123_ERR if there was an error. */
EXPORT int mpg123_format(mpg123_handle *mh, long rate, int channels, int encodings);
/** Check to see if a specific format at a specific rate is supported
* by mpg123_handle.
* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
EXPORT int mpg123_format_support(mpg123_handle *mh, long rate, int encoding);
/** Get the current output format written to the addresses givenr. */
EXPORT int mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding);
/*@}*/
/** \defgroup mpg123_input mpg123 file input and decoding
*
* Functions for input bitstream and decoding operations.
* Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE (please read up on these on how to react!).
* @{
*/
/* reading samples / triggering decoding, possible return values: */
/** Enumeration of the error codes returned by libmpg123 functions. */
/** Open and prepare to decode the specified file by filesystem path.
* This does not open HTTP urls; libmpg123 contains no networking code.
* If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed().
*/
EXPORT int mpg123_open(mpg123_handle *mh, const char *path);
/** Use an already opened file descriptor as the bitstream input
* mpg123_close() will _not_ close the file descriptor.
*/
EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd);
/** Open a new bitstream and prepare for direct feeding
* This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream.
*/
EXPORT int mpg123_open_feed(mpg123_handle *mh);
/** Closes the source, if libmpg123 opened it. */
EXPORT int mpg123_close(mpg123_handle *mh);
/** Read from stream and decode up to outmemsize bytes.
* \param outmemory address of output buffer to write to
* \param outmemsize maximum number of bytes to write
* \param done address to store the number of actually decoded bytes to
* \return error/message code (watch out for MPG123_DONE and friends!) */
EXPORT int mpg123_read(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done);
/** Feed data for a stream that has been opened with mpg123_open_feed().
* It's give and take: You provide the bytestream, mpg123 gives you the decoded samples.
* \param in input buffer
* \param size number of input bytes
* \return error/message code. */
EXPORT int mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size);
/** Decode MPEG Audio from inmemory to outmemory.
* This is very close to a drop-in replacement for old mpglib.
* When you give zero-sized output buffer the input will be parsed until
* decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it)
* without taking decoded data.
* Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-).
* You can actually always decide if you want those specialized functions in separate steps or one call this one here.
* \param inmemory input buffer
* \param inmemsize number of input bytes
* \param outmemory output buffer
* \param outmemsize maximum number of output bytes
* \param done address to store the number of actually decoded bytes to
* \return error/message code (watch out especially for MPG123_NEED_MORE)
*/
EXPORT int mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize,
unsigned char *outmemory, size_t outmemsize, size_t *done);
/** Decode next MPEG frame to internal buffer
* or read a frame and return after setting a new format.
* \param num current frame offset gets stored there
* \param audio This pointer is set to the internal buffer to read the decoded audio from.
* \param bytes number of output bytes ready in the buffer
*/
EXPORT int mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes);
/*@}*/
/** \defgroup mpg123_seek mpg123 position and seeking
*
* Functions querying and manipulating position in the decoded audio bitstream.
* The position is measured in decoded audio samples, or MPEG frame offset for the specific functions.
* If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-)
* The general usage is modelled after stdlib's ftell() and fseek().
* Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h:
* - SEEK_SET: set position to (or near to) specified offset
* - SEEK_CUR: change position by offset from now
* - SEEK_END: set position to offset from end
*
* Note that sample-accurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise.
* Also, really sample-accurate seeking (meaning that you get the identical sample value after seeking compared to plain decoding up to the position) is only guaranteed when you do not mess with the position code by using MPG123_UPSPEED, MPG123_DOWNSPEED or MPG123_START_FRAME. The first two mainly should cause trouble with NtoM resampling, but in any case with these options in effect, you have to keep in mind that the sample offset is not the same as counting the samples you get from decoding since mpg123 counts the skipped samples, too (or the samples played twice only once)!
* Short: When you care about the sample position, don't mess with those parameters;-)
* Also, seeking is not guaranteed to work for all streams (underlying stream may not support it).
*
* @{
*/
/** Returns the current position in samples.
* On the next read, you'd get that sample. */
EXPORT off_t mpg123_tell(mpg123_handle *mh);
/** Returns the frame number that the next read will give you data from. */
EXPORT off_t mpg123_tellframe(mpg123_handle *mh);
/** Returns the current byte offset in the input stream. */
EXPORT off_t mpg123_tell_stream(mpg123_handle *mh);
/** Seek to a desired sample offset.
* Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
* \return The resulting offset >= 0 or error/message code */
EXPORT off_t mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence);
/** Seek to a desired sample offset in data feeding mode.
* This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position.
* \param input_offset The position it expects to be at the
* next time data is fed to mpg123_decode().
* \return The resulting offset >= 0 or error/message code */
EXPORT off_t mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset);
/** Seek to a desired MPEG frame index.
* Set whence to SEEK_SET, SEEK_CUR or SEEK_END.
* \return The resulting offset >= 0 or error/message code */
EXPORT off_t mpg123_seek_frame(mpg123_handle *mh, off_t frameoff, int whence);
/** Return a MPEG frame offset corresponding to an offset in seconds.
* This assumes that the samples per frame do not change in the file/stream, which is a good assumption for any sane file/stream only.
* \return frame offset >= 0 or error/message code */
EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec);
/** Give access to the frame index table that is managed for seeking.
* You are asked not to modify the values... unless you are really aware of what you are doing.
* \param offsets pointer to the index array
* \param step one index byte offset advances this many MPEG frames
* \param fill number of recorded index offsets; size of the array */
EXPORT int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill);
/** Get information about current and remaining frames/seconds.
* WARNING: This function is there because of special usage by standalone mpg123 and may be removed in the final version of libmpg123!
* You provide an offset (in frames) from now and a number of output bytes
* served by libmpg123 but not yet played. You get the projected current frame
* and seconds, as well as the remaining frames/seconds. This does _not_ care
* about skipped samples due to gapless playback. */
EXPORT 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);
/*@}*/
/** \defgroup mpg123_voleq mpg123 volume and equalizer
*
* @{
*/
enum mpg123_channels
{
MPG123_LEFT=0x1 /**< The Left Channel. */
,MPG123_RIGHT=0x2 /**< The Right Channel. */
,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */
};
/** Set the 32 Band Audio Equalizer settings.
* \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both.
* \param band The equaliser band to change (from 0 to 31)
* \param val The (linear) adjustment factor. */
EXPORT int mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val);
/** Get the 32 Band Audio Equalizer settings.
* \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for (arithmetic mean of) both.
* \param band The equaliser band to change (from 0 to 31)
* \return The (linear) adjustment factor. */
EXPORT double mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band);
/** Reset the 32 Band Audio Equalizer settings to flat */
EXPORT int mpg123_reset_eq(mpg123_handle *mh);
/** Set the absolute output volume including the RVA setting,
* vol<0 just applies (a possibly changed) RVA setting. */
EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
/** Adjust output volume including the RVA setting by chosen amount */
EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
/** Return current volume setting, the actual value due to RVA, and the RVA
* adjustment itself. It's all as double float value to abstract the sample
* format. The volume values are linear factors / amplitudes (not percent)
* and the RVA value is in decibels. */
EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db);
/* TODO: Set some preamp in addition / to replace internal RVA handling? */
/*@}*/
/** \defgroup mpg123_status mpg123 status and information
*
* @{
*/
/** Enumeration of the mode types of Variable Bitrate */
enum mpg123_vbr {
MPG123_CBR=0, /**< Constant Bitrate Mode (default) */
MPG123_VBR, /**< Variable Bitrate Mode */
MPG123_ABR /**< Average Bitrate Mode */
};
/** Enumeration of the MPEG Versions */
enum mpg123_version {
MPG123_1_0=0, /**< MPEG Version 1.0 */
MPG123_2_0, /**< MPEG Version 2.0 */
MPG123_2_5 /**< MPEG Version 2.5 */
};
/** Enumeration of the MPEG Audio mode.
* Only the mono mode has 1 channel, the others have 2 channels. */
enum mpg123_mode {
MPG123_M_STEREO=0, /**< Standard Stereo. */
MPG123_M_JOINT, /**< Joint Stereo. */
MPG123_M_DUAL, /**< Dual Channel. */
MPG123_M_MONO /**< Single Channel. */
};
/** Enumeration of the MPEG Audio flag bits */
enum mpg123_flags {
MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */
MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */
MPG123_PRIVATE=0x4, /**< The private bit has been set. */
MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */
};
/** Data structure for storing information about a frame of MPEG Audio */
struct mpg123_frameinfo
{
enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */
int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */
long rate; /**< The sampling rate in Hz. */
enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */
int mode_ext; /**< The mode extension bit flag. */
int framesize; /**< The size of the frame (in bytes). */
enum mpg123_flags flags; /**< MPEG Audio flag bits. */
int emphasis; /**< The emphasis type. */
int bitrate; /**< Bitrate of the frame (kbps). */
int abr_rate; /**< The target average bitrate. */
enum mpg123_vbr vbr; /**< The VBR mode. */
};
/** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure. */
EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi);
/** Get the safe output buffer size for all cases (when you want to replace the internal buffer) */
EXPORT size_t mpg123_safe_buffer();
/** Make a full parsing scan of each frame in the file. ID3 tags are found. An accurate length
* value is stored. Seek index will be filled. A seek back to current position
* is performed. At all, this function refuses work when stream is
* not seekable.
* \return MPG123_OK or MPG123_ERR.
*/
EXPORT int mpg123_scan(mpg123_handle *mh);
/** Return, if possible, the full (expected) length of current track in samples.
* \return length >= 0 or MPG123_ERR if there is no length guess possible. */
EXPORT off_t mpg123_length(mpg123_handle *mh);
/** Override the value for file size in bytes.
* Useful for getting sensible track length values in feed mode or for HTTP streams.
* \return MPG123_OK or MPG123_ERR */
EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size);
/** Returns the time (seconds) per frame; <0 is error. */
EXPORT double mpg123_tpf(mpg123_handle *mh);
/** Get and reset the clip count. */
EXPORT long mpg123_clip(mpg123_handle *mh);
/** The key values for state information from mpg123_getstate(). */
enum mpg123_state
{
MPG123_ACCURATE = 1 /**< Query if positons are currently accurate (integer value, 0 if false, 1 if true) */
};
/** Get various current decoder/stream state information.
* \param key the key to identify the information to give.
* \param val the address to return (long) integer values to
* \param fval the address to return floating point values to
* \return MPG123_OK or MPG123_ERR for success
*/
EXPORT int mpg123_getstate(mpg123_handle *mh, enum mpg123_state key, long *val, double *fval);
/*@}*/
/** \defgroup mpg123_metadata mpg123 metadata handling
*
* Functions to retrieve the metadata from MPEG Audio files and streams.
* Also includes string handling functions.
*
* @{
*/
/** Data structure for storing strings in a safer way than a standard C-String.
* Can also hold a number of null-terminated strings. */
typedef struct
{
char* p; /**< pointer to the string data */
size_t size; /**< raw number of bytes allocated */
size_t fill; /**< number of used bytes (including closing zero byte) */
} mpg123_string;
/** Create and allocate memory for a new mpg123_string */
EXPORT void mpg123_init_string(mpg123_string* sb);
/** Free-up mempory for an existing mpg123_string */
EXPORT void mpg123_free_string(mpg123_string* sb);
/** Change the size of a mpg123_string
* \return 0 on error, 1 on success */
EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news);
/** Increase size of a mpg123_string if necessary (it may stay larger).
* Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string().
* That way, you can preallocate memory and safely work afterwards with pieces.
* \return 0 on error, 1 on success */
EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news);
/** Copy the contents of one mpg123_string string to another.
* \return 0 on error, 1 on success */
EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to);
/** Append a C-String to an mpg123_string
* \return 0 on error, 1 on success */
EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff);
/** Append a C-substring to an mpg123 string
* \return 0 on error, 1 on success
* \param from offset to copy from
* \param count number of characters to copy (a null-byte is always appended) */
EXPORT int mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
/** Set the conents of a mpg123_string to a C-string
* \return 0 on error, 1 on success */
EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff);
/** Set the contents of a mpg123_string to a C-substring
* \return 0 on error, 1 on success
* \param from offset to copy from
* \param count number of characters to copy (a null-byte is always appended) */
EXPORT int mpg123_set_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count);
/** The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info. */
enum mpg123_text_encoding
{
mpg123_text_unknown = 0 /**< Unkown encoding... mpg123_id3_encoding can return that on invalid codes. */
,mpg123_text_utf8 = 1 /**< UTF-8 */
,mpg123_text_latin1 = 2 /**< ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings. */
,mpg123_text_icy = 3 /**< ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such. */
,mpg123_text_cp1252 = 4 /**< Really CP-1252 without any guessing. */
,mpg123_text_utf16 = 5 /**< Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
* When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
* you don't mess with the reserved code points. If you want to decode little endian data
* without BOM you need to prepend 0xff 0xfe yourself. */
,mpg123_text_utf16bom = 6 /**< Just an alias for UTF-16, ID3v2 has this as distinct code. */
,mpg123_text_utf16be = 7 /**< Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
* BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
* One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
* types (we expect a BOM before real data there), not so for utf16be!*/
,mpg123_text_max = 7 /**< Placeholder for the maximum encoding value. */
};
/** The encoding byte values from ID3v2. */
enum mpg123_id3_enc
{
mpg123_id3_latin1 = 0 /**< Note: This sometimes can mean anything in practice... */
,mpg123_id3_utf16bom = 1 /**< UTF16, UCS-2 ... it's all the same for practical purposes. */
,mpg123_id3_utf16be = 2 /**< Big-endian UTF-16, BOM see note for mpg123_text_utf16be. */
,mpg123_id3_utf8 = 3 /**< Our lovely overly ASCII-compatible 8 byte encoding for the world. */
,mpg123_id3_enc_max = 3 /**< Placeholder to check valid range of encoding byte. */
};
/** Convert ID3 encoding byte to mpg123 encoding index. */
EXPORT enum mpg123_text_encoding mpg123_enc_from_id3(unsigned char id3_enc_byte);
/** Store text data in string, after converting to UTF-8 from indicated encoding
* \return 0 on error, 1 on success (on error, mpg123_free_string is called on sb)
* \param sb target string
* \param enc mpg123 text encoding value
* \param source source buffer with plain unsigned bytes (you might need to cast from char *)
* \param source_size number of bytes in the source buffer
*
* A prominent error can be that you provided an unknown encoding value, or this build of libmpg123 lacks support for certain encodings (ID3 or ICY stuff missing).
* Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).
*/
EXPORT int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size);
/** Sub data structure for ID3v2, for storing various text fields (including comments).
* This is for ID3v2 COMM, TXXX and all the other text fields.
* Only COMM and TXXX have a description, only COMM and USLT have a language.
* You should consult the ID3v2 specification for the use of the various text fields ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */
typedef struct
{
char lang[3]; /**< Three-letter language code (not terminated). */
char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */
mpg123_string description; /**< Empty for the generic comment... */
mpg123_string text; /**< ... */
} mpg123_text;
/** Data structure for storing IDV3v2 tags.
* This structure is not a direct binary mapping with the file contents.
* The ID3v2 text frames are allowed to contain multiple strings.
* So check for null bytes until you reach the mpg123_string fill.
* All text is encoded in UTF-8. */
typedef struct
{
unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */
mpg123_string *title; /**< Title string (pointer into text_list). */
mpg123_string *artist; /**< Artist string (pointer into text_list). */
mpg123_string *album; /**< Album string (pointer into text_list). */
mpg123_string *year; /**< The year as a string (pointer into text_list). */
mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */
mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */
/* Encountered ID3v2 fields are appended to these lists.
There can be multiple occurences, the pointers above always point to the last encountered data. */
mpg123_text *comment_list; /**< Array of comments. */
size_t comments; /**< Number of comments. */
mpg123_text *text; /**< Array of ID3v2 text fields (including USLT) */
size_t texts; /**< Numer of text fields. */
mpg123_text *extra; /**< The array of extra (TXXX) fields. */
size_t extras; /**< Number of extra text (TXXX) fields. */
} mpg123_id3v2;
/** Data structure for ID3v1 tags (the last 128 bytes of a file).
* Don't take anything for granted (like string termination)!
* Also note the change ID3v1.1 did: comment[28] = 0; comment[19] = track_number
* It is your task to support ID3v1 only or ID3v1.1 ...*/
typedef struct
{
char tag[3]; /**< Always the string "TAG", the classic intro. */
char title[30]; /**< Title string. */
char artist[30]; /**< Artist string. */
char album[30]; /**< Album string. */
char year[4]; /**< Year string. */
char comment[30]; /**< Comment string. */
unsigned char genre; /**< Genre index. */
} mpg123_id3v1;
#define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */
#define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */
#define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/
#define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */
/** Query if there is (new) meta info, be it ID3 or ICY (or something new in future).
The check function returns a combination of flags. */
EXPORT int mpg123_meta_check(mpg123_handle *mh); /* On error (no valid handle) just 0 is returned. */
/** Point v1 and v2 to existing data structures wich may change on any next read/decode function call.
* v1 and/or v2 can be set to NULL when there is no corresponding data.
* \return Return value is MPG123_OK or MPG123_ERR, */
EXPORT int mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2);
/** Point icy_meta to existing data structure wich may change on any next read/decode function call.
* \return Return value is MPG123_OK or MPG123_ERR, */
EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); /* same for ICY meta string */
/** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8.
* Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .
* \param icy_text The input data in ICY encoding
* \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */
EXPORT char* mpg123_icy2utf8(const char* icy_text);
/* @} */
/** \defgroup mpg123_advpar mpg123 advanced parameter API
*
* Direct access to a parameter set without full handle around it.
* Possible uses:
* - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE).
* - Use one set of parameters for multiple handles.
*
* The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt()
* family) directly return a fully qualified mpg123 error code, the ones
* operating on full handles normally MPG123_OK or MPG123_ERR, storing the
* specific error code itseld inside the handle.
*
* @{
*/
/** Opaque structure for the libmpg123 decoder parameters. */
struct mpg123_pars_struct;
/** Opaque structure for the libmpg123 decoder parameters. */
typedef struct mpg123_pars_struct mpg123_pars;
/** Create a handle with preset parameters. */
EXPORT mpg123_handle *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error);
/** Allocate memory for and return a pointer to a new mpg123_pars */
EXPORT mpg123_pars *mpg123_new_pars(int *error);
/** Delete and free up memory used by a mpg123_pars data structure */
EXPORT void mpg123_delete_pars(mpg123_pars* mp);
/** Configure mpg123 parameters to accept no output format at all,
* use before specifying supported formats with mpg123_format */
EXPORT int mpg123_fmt_none(mpg123_pars *mp);
/** Configure mpg123 parameters to accept all formats
* (also any custom rate you may set) -- this is default. */
EXPORT int mpg123_fmt_all(mpg123_pars *mp);
/** Set the audio format support of a mpg123_pars in detail:
\param rate The sample rate value (in Hertz).
\param channels A combination of MPG123_STEREO and MPG123_MONO.
\param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no support).
\return 0 on success, -1 if there was an error. /
*/
EXPORT int mpg123_fmt(mpg123_pars *mh, long rate, int channels, int encodings); /* 0 is good, -1 is error */
/** Check to see if a specific format at a specific rate is supported
* by mpg123_pars.
* \return 0 for no support (that includes invalid parameters), MPG123_STEREO,
* MPG123_MONO or MPG123_STEREO|MPG123_MONO. */
EXPORT int mpg123_fmt_support(mpg123_pars *mh, long rate, int encoding);
/** Set a specific parameter, for a specific mpg123_pars, using a parameter
* type key chosen from the mpg123_parms enumeration, to the specified value. */
EXPORT int mpg123_par(mpg123_pars *mp, enum mpg123_parms type, long value, double fvalue);
/** Get a specific parameter, for a specific mpg123_pars.
* See the mpg123_parms enumeration for a list of available parameters. */
EXPORT int mpg123_getpar(mpg123_pars *mp, enum mpg123_parms type, long *val, double *fval);
/* @} */
/** \defgroup mpg123_lowio mpg123 low level I/O
* You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket...
*
* @{ */
/** Replace default internal buffer with user-supplied buffer.
* Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. */
EXPORT int mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size);
/** The max size of one frame's decoded output with current settings.
* Use that to determine an appropriate minimum buffer size for decoding one frame. */
EXPORT size_t mpg123_outblock(mpg123_handle *mh);
/** Replace low-level stream access functions; read and lseek as known in POSIX.
* You can use this to make any fancy file opening/closing yourself,
* using open_fd to set the file descriptor for your read/lseek (doesn't need to be a "real" file descriptor...).
* Setting a function to NULL means that the default internal read is
* used (active from next mpg123_open call on). */
EXPORT int mpg123_replace_reader( mpg123_handle *mh,
ssize_t (*r_read) (int, void *, size_t),
off_t (*r_lseek)(int, off_t, int) );
/* @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,321 @@
/*
mpg123lib_intern: Common non-public stuff for libmpg123
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
derived from the old mpg123.h
*/
#ifndef MPG123_H_INTERN
#define MPG123_H_INTERN
#define MPG123_RATES 9
#define MPG123_ENCODINGS 10
#include "config.h" /* Load this before _anything_ */
/* ABI conformance for other compilers.
mpg123 needs 16byte-aligned 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
# define NEED_ALIGNCHECK /* Other compilers get code to catch misaligned stack. */
#endif
#endif
#else
#define attribute_align_arg
/* We won't try the align check... */
#endif
/* export DLL symbols */
#if defined(WIN32) && defined(DYNAMIC_BUILD)
#define BUILD_MPG123_DLL
#endif
#include "compat.h"
#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
/* some stuff has to go back to mpg123.h */
#ifdef REAL_IS_FLOAT
# define real float
# define REAL_SCANF "%f"
# define REAL_PRINTF "%f"
#elif defined(REAL_IS_LONG_DOUBLE)
# define real long double
# define REAL_SCANF "%Lf"
# define REAL_PRINTF "%Lf"
#elif defined(REAL_IS_FIXED)
/* Disable some output formats for fixed point decoder... */
# define real long
/*
for fixed-point decoders, use pre-calculated tables to avoid expensive floating-point maths
undef this macro for run-time calculation
*/
#define PRECALC_TABLES
# define REAL_RADIX 24
# define REAL_FACTOR 16777216.0
static inline long double_to_long_rounded(double x, double scalefac)
{
x *= scalefac;
x += (x > 0) ? 0.5 : -0.5;
return (long)x;
}
static inline long scale_rounded(long 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" \
"orr %0, %0, %1, lsl %2 \n\t" \
: "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
: "%r" (_x), "r" (_y), "r" (_radix) \
); \
_mull; \
})
# endif
# endif
/* I just changed the (int) to (long) there... seemed right. */
# define DOUBLE_TO_REAL(x) (double_to_long_rounded(x, REAL_FACTOR))
# define DOUBLE_TO_REAL_15(x) (double_to_long_rounded(x, 32768.0))
# define DOUBLE_TO_REAL_POW43(x) (double_to_long_rounded(x, 8192.0))
# define DOUBLE_TO_REAL_SCALE_LAYER12(x) (double_to_long_rounded(x, 1073741824.0))
# 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) (((long long)(x) * (long long)(y)) >> REAL_RADIX)
# define REAL_MUL_15(x, y) (((long long)(x) * (long long)(y)) >> 15)
# define REAL_MUL_SCALE_LAYER12(x, y) (((long long)(x) * (long long)(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) (((long long)(x) * (long long)(y)) >> (13 + gainpow2_scale[z] - REAL_RADIX))
# endif
# define REAL_SCALE_LAYER12(x) ((long)((x) >> (30 - REAL_RADIX)))
# define REAL_SCALE_LAYER3(x, y) ((long)((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
# define REAL_SCANF "%ld"
# define REAL_PRINTF "%ld"
#else
# define real double
# define REAL_SCANF "%lf"
# define REAL_PRINTF "%f"
#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 0 /*(!(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) 0 /*(!((mp)->flags & MPG123_QUIET) && (mp)->verbose >= (level)) */
int decode_update(mpg123_handle *mh);
/* residing in format.c */
off_t samples_to_bytes(mpg123_handle *fr , off_t s);
off_t bytes_to_samples(mpg123_handle *fr , off_t b);
#endif

View File

@ -0,0 +1,904 @@
/*
optimize: get a grip on the different optimizations
copyright 2006-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, inspired by 3DNow stuff in mpg123.[hc]
Currently, this file contains the struct and function to choose an optimization variant and works only when OPT_MULTI is in effect.
*/
#include "mpg123lib_intern.h" /* includes optimize.h */
#include "debug.h"
/* Must match the enum dectype! */
/*
It SUCKS having to define these names that way, but compile-time intialization of string arrays is a bitch.
GCC doesn't see constant stuff when it's wiggling in front of it!
Anyhow: Have a script for that:
names="generic generic_dither i386 i486 i586 i586_dither MMX 3DNow 3DNowExt AltiVec SSE x86-64"
for i in $names; do echo "##define dn_${i/-/_} \"$i\""; done
echo -n "static const char* decname[] =
{
\"auto\"
"
for i in $names; do echo -n ", dn_${i/-/_}"; done
echo "
, \"nodec\"
};"
*/
#define dn_generic "generic"
#define dn_generic_dither "generic_dither"
#define dn_i386 "i386"
#define dn_i486 "i486"
#define dn_i586 "i586"
#define dn_i586_dither "i586_dither"
#define dn_MMX "MMX"
#define dn_3DNow "3DNow"
#define dn_3DNowExt "3DNowExt"
#define dn_AltiVec "AltiVec"
#define dn_SSE "SSE"
#define dn_x86_64 "x86-64"
#define dn_ARM "ARM"
static const char* decname[] =
{
"auto"
, dn_generic, dn_generic_dither, dn_i386, dn_i486, dn_i586, dn_i586_dither, dn_MMX, dn_3DNow, dn_3DNowExt, dn_AltiVec, dn_SSE, dn_x86_64, dn_ARM
, "nodec"
};
#if (defined OPT_X86) && (defined OPT_MULTI)
#include "getcpuflags.h"
struct cpuflags cpu_flags;
#else
/* Faking stuff for non-multi builds. The same code for synth function choice is used.
Just no runtime dependency of result... */
char cpu_flags;
#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
#endif
/* Ugly macros to build conditional synth function array values. */
#ifndef NO_8BIT
#define IF8(synth) synth,
#else
#define IF8(synth)
#endif
#ifndef NO_REAL
#define IFREAL(synth) synth,
#else
#define IFREAL(synth)
#endif
#ifndef NO_32BIT
#define IF32(synth) synth
#else
#define IF32(synth)
#endif
#ifndef NO_16BIT
# define OUT_SYNTHS(synth_16, synth_8, synth_real, synth_32) { synth_16, IF8(synth_8) IFREAL(synth_real) IF32(synth_32) }
#else
# define OUT_SYNTHS(synth_16, synth_8, synth_real, synth_32) { IF8(synth_8) IFREAL(synth_real) IF32(synth_32) }
#endif
const struct synth_s synth_base =
{
{ /* plain */
OUT_SYNTHS(synth_1to1, synth_1to1_8bit, synth_1to1_real, synth_1to1_s32)
# ifndef NO_DOWNSAMPLE
,OUT_SYNTHS(synth_2to1, synth_2to1_8bit, synth_2to1_real, synth_2to1_s32)
,OUT_SYNTHS(synth_4to1, synth_4to1_8bit, synth_4to1_real, synth_4to1_s32)
# endif
# ifndef NO_NTOM
,OUT_SYNTHS(synth_ntom, synth_ntom_8bit, synth_ntom_real, synth_ntom_s32)
# endif
},
{ /* stereo, by default only wrappers over plain synth */
OUT_SYNTHS(synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap)
# ifndef NO_DOWNSAMPLE
,OUT_SYNTHS(synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap)
,OUT_SYNTHS(synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap)
# endif
# ifndef NO_NTOM
,OUT_SYNTHS(synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap, synth_stereo_wrap)
# endif
},
{ /* mono2stereo */
OUT_SYNTHS(synth_1to1_mono2stereo, synth_1to1_8bit_mono2stereo, synth_1to1_real_mono2stereo, synth_1to1_s32_mono2stereo)
# ifndef NO_DOWNSAMPLE
,OUT_SYNTHS(synth_2to1_mono2stereo, synth_2to1_8bit_mono2stereo, synth_2to1_real_mono2stereo, synth_2to1_s32_mono2stereo)
,OUT_SYNTHS(synth_4to1_mono2stereo, synth_4to1_8bit_mono2stereo, synth_4to1_real_mono2stereo, synth_4to1_s32_mono2stereo)
# endif
# ifndef NO_NTOM
,OUT_SYNTHS(synth_ntom_mono2stereo, synth_ntom_8bit_mono2stereo, synth_ntom_real_mono2stereo, synth_ntom_s32_mono2stereo)
# endif
},
{ /* mono*/
OUT_SYNTHS(synth_1to1_mono, synth_1to1_8bit_mono, synth_1to1_real_mono, synth_1to1_s32_mono)
# ifndef NO_DOWNSAMPLE
,OUT_SYNTHS(synth_2to1_mono, synth_2to1_8bit_mono, synth_2to1_real_mono, synth_2to1_s32_mono)
,OUT_SYNTHS(synth_4to1_mono, synth_4to1_8bit_mono, synth_4to1_real_mono, synth_4to1_s32_mono)
# endif
# ifndef NO_NTOM
,OUT_SYNTHS(synth_ntom_mono, synth_ntom_8bit_mono, synth_ntom_real_mono, synth_ntom_s32_mono)
#endif
}
};
#ifdef OPT_X86
/* More plain synths for i386 */
const func_synth plain_i386[r_limit][f_limit] =
{ /* plain */
OUT_SYNTHS(synth_1to1_i386, synth_1to1_8bit_i386, synth_1to1_real_i386, synth_1to1_s32_i386)
# ifndef NO_DOWNSAMPLE
,OUT_SYNTHS(synth_2to1_i386, synth_2to1_8bit_i386, synth_2to1_real_i386, synth_2to1_s32_i386)
,OUT_SYNTHS(synth_4to1_i386, synth_4to1_8bit_i386, synth_4to1_real_i386, synth_4to1_s32_i386)
# endif
# ifndef NO_NTOM
,OUT_SYNTHS(synth_ntom, synth_ntom_8bit, synth_ntom_real, synth_ntom_s32)
# endif
};
#endif
enum optdec defdec(void){ return defopt; }
enum optcla decclass(const enum optdec type)
{
return (type == mmx || type == sse || type == dreidnowext || type == x86_64 ) ? mmxsse : normal;
}
static int find_synth(func_synth synth, const func_synth synths[r_limit][f_limit])
{
enum synth_resample ri;
enum synth_format fi;
for(ri=0; ri<r_limit; ++ri)
for(fi=0; fi<f_limit; ++fi)
if(synth == synths[ri][fi])
return TRUE;
return FALSE;
}
/* Determine what kind of decoder is actually active
This depends on runtime choices which may cause fallback to i386 or generic code. */
static int find_dectype(mpg123_handle *fr)
{
enum optdec type = nodec;
/* Direct and indirect usage, 1to1 stereo decoding.
Concentrating on the plain stereo synth should be fine, mono stuff is derived. */
func_synth basic_synth = fr->synth;
#ifndef NO_8BIT
#ifndef NO_16BIT
if(basic_synth == synth_1to1_8bit_wrap)
basic_synth = fr->synths.plain[r_1to1][f_16]; /* That is what's really below the surface. */
#endif
#endif
if(FALSE) ; /* Just to initialize the else if ladder. */
#ifndef NO_16BIT
#ifdef OPT_3DNOWEXT
else if(basic_synth == synth_1to1_3dnowext) type = dreidnowext;
#endif
#ifdef OPT_SSE
else if(basic_synth == synth_1to1_sse) type = sse;
#endif
#ifdef OPT_3DNOW
else if(basic_synth == synth_1to1_3dnow) type = dreidnow;
#endif
#ifdef OPT_MMX
else if(basic_synth == synth_1to1_mmx) type = mmx;
#endif
#ifdef OPT_I586_DITHER
else if(basic_synth == synth_1to1_i586_dither) type = ifuenf_dither;
#endif
#ifdef OPT_I586
else if(basic_synth == synth_1to1_i586) type = ifuenf;
#endif
#ifdef OPT_ALTIVEC
else if(basic_synth == synth_1to1_altivec) type = altivec;
#endif
#ifdef OPT_X86_64
else if(basic_synth == synth_1to1_x86_64) type = x86_64;
#endif
#ifdef OPT_ARM
else if(basic_synth == synth_1to1_arm) type = arm;
#endif
#ifdef OPT_GENERIC_DITHER
else if(basic_synth == synth_1to1_dither) type = generic_dither;
#endif
#ifdef OPT_DITHER /* either i586 or generic! */
#ifndef NO_DOWNSAMPLE
else if
(
basic_synth == synth_2to1_dither
|| basic_synth == synth_4to1_dither
) type = generic_dither;
#endif
#endif
#endif /* 16bit */
#ifndef NO_REAL
#ifdef OPT_SSE
else if(basic_synth == synth_1to1_real_sse) type = sse;
#endif
#ifdef OPT_X86_64
else if(basic_synth == synth_1to1_real_x86_64) type = x86_64;
#endif
#ifdef OPT_ALTIVEC
else if(basic_synth == synth_1to1_real_altivec) type = altivec;
#endif
#endif /* real */
#ifndef NO_32BIT
#ifdef OPT_SSE
else if(basic_synth == synth_1to1_s32_sse) type = sse;
#endif
#ifdef OPT_X86_64
else if(basic_synth == synth_1to1_s32_x86_64) type = x86_64;
#endif
#ifdef OPT_ALTIVEC
else if(basic_synth == synth_1to1_s32_altivec) type = altivec;
#endif
#endif /* 32bit */
#ifdef OPT_X86
else if(find_synth(basic_synth, plain_i386))
type = idrei;
#endif
else if(find_synth(basic_synth, synth_base.plain))
type = generic;
#ifdef OPT_I486
/* i486 is special ... the specific code is in use for 16bit 1to1 stereo
otherwise we have i386 active... but still, the distinction doesn't matter*/
type = ivier;
#endif
if(type != nodec)
{
fr->cpu_opts.type = type;
fr->cpu_opts.class = decclass(type);
debug3("determined active decoder type %i (%s) of class %i", type, decname[type], fr->cpu_opts.class);
return MPG123_OK;
}
else
{
if(NOQUIET) error("Unable to determine active decoder type -- this is SERIOUS b0rkage!");
fr->err = MPG123_BAD_DECODER_SETUP;
return MPG123_ERR;
}
}
/* set synth functions for current frame, optimizations handled by opt_* macros */
int set_synth_functions(mpg123_handle *fr)
{
enum synth_resample resample = r_none;
enum synth_format basic_format = f_none; /* Default is always 16bit, or whatever. */
/* Select the basic output format, different from 16bit: 8bit, real. */
if(FALSE){}
#ifndef NO_16BIT
else if(fr->af.encoding & MPG123_ENC_16)
basic_format = f_16;
#endif
#ifndef NO_8BIT
else if(fr->af.encoding & MPG123_ENC_8)
basic_format = f_8;
#endif
#ifndef NO_REAL
else if(fr->af.encoding & MPG123_ENC_FLOAT)
basic_format = f_real;
#endif
#ifndef NO_32BIT
else if(fr->af.encoding & MPG123_ENC_32)
basic_format = f_32;
#endif
/* Make sure the chosen format is compiled into this lib. */
if(basic_format == f_none)
{
if(NOQUIET) error("set_synth_functions: This output format is disabled in this build!");
return -1;
}
/* Be explicit about downsampling variant. */
switch(fr->down_sample)
{
case 0: resample = r_1to1; break;
#ifndef NO_DOWNSAMPLE
case 1: resample = r_2to1; break;
case 2: resample = r_4to1; break;
#endif
#ifndef NO_NTOM
case 3: resample = r_ntom; break;
#endif
}
if(resample == r_none)
{
if(NOQUIET) error("set_synth_functions: This resampling mode is not supported in this build!");
return -1;
}
debug2("selecting synth: resample=%i format=%i", resample, basic_format);
/* Finally selecting the synth functions for stereo / mono. */
fr->synth = fr->synths.plain[resample][basic_format];
fr->synth_stereo = fr->synths.stereo[resample][basic_format];
fr->synth_mono = fr->af.channels==2
? fr->synths.mono2stereo[resample][basic_format] /* Mono MPEG file decoded to stereo. */
: fr->synths.mono[resample][basic_format]; /* Mono MPEG file decoded to mono. */
if(find_dectype(fr) != MPG123_OK) /* Actually determine the currently active decoder breed. */
{
fr->err = MPG123_BAD_DECODER_SETUP;
return MPG123_ERR;
}
if(frame_buffers(fr) != 0)
{
fr->err = MPG123_NO_BUFFERS;
if(NOQUIET) error("Failed to set up decoder buffers!");
return MPG123_ERR;
}
#ifndef NO_8BIT
if(basic_format == f_8)
{
if(make_conv16to8_table(fr) != 0)
{
if(NOQUIET) error("Failed to set up conv16to8 table!");
/* it's a bit more work to get proper error propagation up */
return -1;
}
}
#endif
#ifdef OPT_MMXORSSE
/* Special treatment for MMX, SSE and 3DNowExt stuff.
The real-decoding SSE for x86-64 uses normal tables! */
if(fr->cpu_opts.class == mmxsse
# ifndef NO_REAL
&& basic_format != f_real
# endif
# ifndef NO_32BIT
&& basic_format != f_32
# endif
# ifdef ACCURATE_ROUNDING
&& fr->cpu_opts.type != sse
&& fr->cpu_opts.type != x86_64
# endif
)
{
#ifndef NO_LAYER3
init_layer3_stuff(fr, init_layer3_gainpow2_mmx);
#endif
#ifndef NO_LAYER12
init_layer12_stuff(fr, init_layer12_table_mmx);
#endif
fr->make_decode_tables = make_decode_tables_mmx;
}
else
#endif
{
#ifndef NO_LAYER3
init_layer3_stuff(fr, init_layer3_gainpow2);
#endif
#ifndef NO_LAYER12
init_layer12_stuff(fr, init_layer12_table);
#endif
fr->make_decode_tables = make_decode_tables;
}
/* We allocated the table buffers just now, so (re)create the tables. */
fr->make_decode_tables(fr);
return 0;
}
int frame_cpu_opt(mpg123_handle *fr, const char* cpu)
{
const char* chosen = ""; /* the chosen decoder opt as string */
enum optdec want_dec = nodec;
int done = 0;
int auto_choose = 0;
#ifdef OPT_DITHER
int dithered = FALSE; /* If some dithered decoder is chosen. */
#endif
want_dec = dectype(cpu);
auto_choose = want_dec == autodec;
/* Fill whole array of synth functions with generic code first. */
fr->synths = synth_base;
#ifndef OPT_MULTI
{
if(!auto_choose && want_dec != defopt)
{
if(NOQUIET) error2("you wanted decoder type %i, I only have %i", want_dec, defopt);
}
auto_choose = TRUE; /* There will be only one choice anyway. */
}
#endif
fr->cpu_opts.type = nodec;
/* covers any i386+ cpu; they actually differ only in the synth_1to1 function, mostly... */
#ifdef OPT_X86
#ifndef NO_LAYER3
#if (defined OPT_3DNOW || defined OPT_3DNOWEXT)
fr->cpu_opts.dct36 = dct36;
#endif
#endif
if(cpu_i586(cpu_flags))
{
# ifdef OPT_MULTI
debug2("standard flags: 0x%08x\textended flags: 0x%08x", cpu_flags.std, cpu_flags.ext);
# endif
#ifdef OPT_SSE
if( !done && (auto_choose || want_dec == sse)
&& cpu_sse(cpu_flags) && cpu_mmx(cpu_flags) )
{
chosen = "SSE";
fr->cpu_opts.type = sse;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_sse;
# ifdef ACCURATE_ROUNDING
fr->synths.stereo[r_1to1][f_16] = synth_1to1_stereo_sse;
# endif
# endif
# ifndef NO_REAL
fr->synths.plain[r_1to1][f_real] = synth_1to1_real_sse;
fr->synths.stereo[r_1to1][f_real] = synth_1to1_real_stereo_sse;
# endif
# ifndef NO_32BIT
fr->synths.plain[r_1to1][f_32] = synth_1to1_s32_sse;
fr->synths.stereo[r_1to1][f_32] = synth_1to1_s32_stereo_sse;
# endif
done = 1;
}
#endif
# ifdef OPT_3DNOWEXT
if( !done && (auto_choose || want_dec == dreidnowext )
&& cpu_3dnow(cpu_flags)
&& cpu_3dnowext(cpu_flags)
&& cpu_mmx(cpu_flags) )
{
chosen = "3DNowExt";
fr->cpu_opts.type = dreidnowext;
# ifndef NO_LAYER3
fr->cpu_opts.dct36 = dct36_3dnowext;
# endif
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_3dnowext;
# endif
done = 1;
}
#endif
#ifdef OPT_3DNOW
if( !done && (auto_choose || want_dec == dreidnow)
&& cpu_3dnow(cpu_flags) && cpu_mmx(cpu_flags) )
{
chosen = "3DNow";
fr->cpu_opts.type = dreidnow;
# ifndef NO_LAYER3
fr->cpu_opts.dct36 = dct36_3dnow;
# endif
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_3dnow;
# endif
done = 1;
}
#endif
#ifdef OPT_MMX
if( !done && (auto_choose || want_dec == mmx)
&& cpu_mmx(cpu_flags) )
{
chosen = "MMX";
fr->cpu_opts.type = mmx;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_mmx;
# endif
done = 1;
}
#endif
#ifdef OPT_I586
if(!done && (auto_choose || want_dec == ifuenf))
{
chosen = "i586/pentium";
fr->cpu_opts.type = ifuenf;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_i586;
# endif
done = 1;
}
#endif
#ifdef OPT_I586_DITHER
if(!done && (auto_choose || want_dec == ifuenf_dither))
{
chosen = "dithered i586/pentium";
fr->cpu_opts.type = ifuenf_dither;
dithered = TRUE;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_i586_dither;
# ifndef NO_DOWNSAMPLE
fr->synths.plain[r_2to1][f_16] = synth_2to1_dither;
fr->synths.plain[r_4to1][f_16] = synth_4to1_dither;
# endif
# endif
done = 1;
}
#endif
}
#ifdef OPT_I486
/* That won't cooperate in multi opt mode - forcing i486 in layer3.c
But still... here it is... maybe for real use in future. */
if(!done && (auto_choose || want_dec == ivier))
{
chosen = "i486";
fr->cpu_opts.type = ivier;
done = 1;
}
#endif
#ifdef OPT_I386
if(!done && (auto_choose || want_dec == idrei))
{
chosen = "i386";
fr->cpu_opts.type = idrei;
done = 1;
}
#endif
if(done)
{
/*
We have chosen some x86 decoder... fillup some i386 stuff.
There is an open question about using dithered synth_1to1 for 8bit wrappers.
For quality it won't make sense, but wrapped i586_dither wrapped may still be faster...
*/
enum synth_resample ri;
enum synth_format fi;
# ifndef NO_8BIT
# ifndef NO_16BIT /* possibility to use a 16->8 wrapper... */
if(fr->synths.plain[r_1to1][f_16] != synth_base.plain[r_1to1][f_16])
{
fr->synths.plain[r_1to1][f_8] = synth_1to1_8bit_wrap;
fr->synths.mono[r_1to1][f_8] = synth_1to1_8bit_wrap_mono;
fr->synths.mono2stereo[r_1to1][f_8] = synth_1to1_8bit_wrap_mono2stereo;
}
# endif
# endif
for(ri=0; ri<r_limit; ++ri)
for(fi=0; fi<f_limit; ++fi)
{
if(fr->synths.plain[ri][fi] == synth_base.plain[ri][fi])
fr->synths.plain[ri][fi] = plain_i386[ri][fi];
}
}
#endif /* OPT_X86 */
#ifdef OPT_X86_64
if(!done && (auto_choose || want_dec == x86_64))
{
chosen = "x86-64 (SSE)";
fr->cpu_opts.type = x86_64;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_x86_64;
fr->synths.stereo[r_1to1][f_16] = synth_1to1_stereo_x86_64;
# endif
# ifndef NO_REAL
fr->synths.plain[r_1to1][f_real] = synth_1to1_real_x86_64;
fr->synths.stereo[r_1to1][f_real] = synth_1to1_real_stereo_x86_64;
# endif
# ifndef NO_32BIT
fr->synths.plain[r_1to1][f_32] = synth_1to1_s32_x86_64;
fr->synths.stereo[r_1to1][f_32] = synth_1to1_s32_stereo_x86_64;
# endif
done = 1;
}
#endif
#ifdef OPT_GENERIC_DITHER
if(!done && (auto_choose || want_dec == generic_dither))
{
chosen = "dithered generic";
fr->cpu_opts.type = generic_dither;
dithered = TRUE;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_dither;
# ifndef NO_DOWNSAMPLE
fr->synths.plain[r_2to1][f_16] = synth_2to1_dither;
fr->synths.plain[r_4to1][f_16] = synth_4to1_dither;
# endif
# endif
done = 1;
}
#endif
# ifdef OPT_ALTIVEC
if(!done && (auto_choose || want_dec == altivec))
{
chosen = "AltiVec";
fr->cpu_opts.type = altivec;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_altivec;
fr->synths.stereo[r_1to1][f_16] = synth_1to1_stereo_altivec;
# endif
# ifndef NO_REAL
fr->synths.plain[r_1to1][f_real] = synth_1to1_real_altivec;
fr->synths.stereo[r_1to1][f_real] = synth_1to1_real_stereo_altivec;
# endif
# ifndef NO_32BIT
fr->synths.plain[r_1to1][f_32] = synth_1to1_s32_altivec;
fr->synths.stereo[r_1to1][f_32] = synth_1to1_s32_stereo_altivec;
# endif
done = 1;
}
# endif
# ifdef OPT_ARM
if(!done && (auto_choose || want_dec == arm))
{
chosen = "ARM";
fr->cpu_opts.type = arm;
# ifndef NO_16BIT
fr->synths.plain[r_1to1][f_16] = synth_1to1_arm;
# endif
done = 1;
}
# endif
# ifdef OPT_GENERIC
if(!done && (auto_choose || want_dec == generic))
{
chosen = "generic";
fr->cpu_opts.type = generic;
done = 1;
}
# endif
fr->cpu_opts.class = decclass(fr->cpu_opts.type);
# ifndef NO_8BIT
# ifndef NO_16BIT /* possibility to use a 16->8 wrapper... */
/* Last chance to use some optimized routine via generic wrappers (for 8bit). */
if( fr->cpu_opts.type != ifuenf_dither
&& fr->cpu_opts.type != generic_dither
&& fr->synths.plain[r_1to1][f_16] != synth_base.plain[r_1to1][f_16] )
{
fr->synths.plain[r_1to1][f_8] = synth_1to1_8bit_wrap;
fr->synths.mono[r_1to1][f_8] = synth_1to1_8bit_wrap_mono;
fr->synths.mono2stereo[r_1to1][f_8] = synth_1to1_8bit_wrap_mono2stereo;
}
# endif
# endif
#ifdef OPT_DITHER
if(done && dithered)
{
/* run-time dither noise table generation */
if(!frame_dither_init(fr))
{
if(NOQUIET) error("Dither noise setup failed!");
return 0;
}
}
#endif
if(done)
{
if(VERBOSE) fprintf(stderr, "Decoder: %s\n", chosen);
return 1;
}
else
{
if(NOQUIET) error("Could not set optimization!");
return 0;
}
}
enum optdec dectype(const char* decoder)
{
enum optdec dt;
if( (decoder == NULL)
|| (decoder[0] == 0) )
return autodec;
for(dt=autodec; dt<nodec; ++dt)
if(!strcasecmp(decoder, decname[dt])) return dt;
return nodec; /* If we found nothing... */
}
#ifdef OPT_MULTI
/* same number of entries as full list, but empty at beginning */
static const char *mpg123_supported_decoder_list[] =
{
#ifdef OPT_SSE
NULL,
#endif
#ifdef OPT_3DNOWEXT
NULL,
#endif
#ifdef OPT_3DNOW
NULL,
#endif
#ifdef OPT_MMX
NULL,
#endif
#ifdef OPT_I586
NULL,
#endif
#ifdef OPT_I586_DITHER
NULL,
#endif
#ifdef OPT_I486
NULL,
#endif
#ifdef OPT_I386
NULL,
#endif
#ifdef OPT_ALTIVEC
NULL,
#endif
#ifdef OPT_X86_64
NULL,
#endif
#ifdef OPT_ARM
NULL,
#endif
#ifdef OPT_GENERIC_FLOAT
NULL,
#endif
# ifdef OPT_GENERIC
NULL,
# endif
# ifdef OPT_GENERIC_DITHER
NULL,
# endif
NULL
};
#endif
static const char *mpg123_decoder_list[] =
{
#ifdef OPT_SSE
dn_SSE,
#endif
#ifdef OPT_3DNOWEXT
dn_3DNowExt,
#endif
#ifdef OPT_3DNOW
dn_3DNow,
#endif
#ifdef OPT_MMX
dn_MMX,
#endif
#ifdef OPT_I586
dn_i586,
#endif
#ifdef OPT_I586_DITHER
dn_i586_dither,
#endif
#ifdef OPT_I486
dn_i486,
#endif
#ifdef OPT_I386
dn_i386,
#endif
#ifdef OPT_ALTIVEC
dn_AltiVec,
#endif
#ifdef OPT_X86_64
dn_x86_64,
#endif
#ifdef OPT_ARM
dn_ARM,
#endif
#ifdef OPT_GENERIC
dn_generic,
#endif
#ifdef OPT_GENERIC_DITHER
dn_generic_dither,
#endif
NULL
};
void check_decoders(void )
{
#ifndef OPT_MULTI
/* In non-multi mode, only the full list (one entry) is used. */
return;
#else
const char **d = mpg123_supported_decoder_list;
#ifdef OPT_X86
getcpuflags(&cpu_flags);
if(cpu_i586(cpu_flags))
{
/* not yet: if(cpu_sse2(cpu_flags)) printf(" SSE2");
if(cpu_sse3(cpu_flags)) printf(" SSE3"); */
#ifdef OPT_SSE
if(cpu_sse(cpu_flags)) *(d++) = decname[sse];
#endif
#ifdef OPT_3DNOWEXT
if(cpu_3dnowext(cpu_flags)) *(d++) = decname[dreidnowext];
#endif
#ifdef OPT_3DNOW
if(cpu_3dnow(cpu_flags)) *(d++) = decname[dreidnow];
#endif
#ifdef OPT_MMX
if(cpu_mmx(cpu_flags)) *(d++) = decname[mmx];
#endif
#ifdef OPT_I586
*(d++) = decname[ifuenf];
#endif
#ifdef OPT_I586_DITHER
*(d++) = decname[ifuenf_dither];
#endif
}
#endif
/* just assume that the i486 built is run on a i486 cpu... */
#ifdef OPT_I486
*(d++) = decname[ivier];
#endif
#ifdef OPT_ALTIVEC
*(d++) = decname[altivec];
#endif
/* every supported x86 can do i386, any cpu can do generic */
#ifdef OPT_I386
*(d++) = decname[idrei];
#endif
#ifdef OPT_X86_64
*(d++) = decname[x86_64];
#endif
#ifdef OPT_ARM
*(d++) = decname[arm];
#endif
#ifdef OPT_GENERIC
*(d++) = decname[generic];
#endif
#ifdef OPT_GENERIC_DITHER
*(d++) = decname[generic_dither];
#endif
#endif /* ndef OPT_MULTI */
}
const char* attribute_align_arg mpg123_current_decoder(mpg123_handle *mh)
{
if(mh == NULL) return NULL;
return decname[mh->cpu_opts.type];
}
const char attribute_align_arg **mpg123_decoders(){ return mpg123_decoder_list; }
const char attribute_align_arg **mpg123_supported_decoders()
{
#ifdef OPT_MULTI
return mpg123_supported_decoder_list;
#else
return mpg123_decoder_list;
#endif
}

View File

@ -0,0 +1,211 @@
#ifndef MPG123_H_OPTIMIZE
#define MPG123_H_OPTIMIZE
/*
optimize: get a grip on the different optimizations
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, 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_3DNOWEXT (AMD 3DNow! extended, generally Athlon, compatibles...)
OPT_ALTIVEC (Motorola/IBM PPC with AltiVec under MacOSX)
OPT_X86_64 (x86-64 / AMD64 / Intel 64)
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: */
enum optdec
{ /* autodec needs to be =0 and the first, nodec needs to be the last -- for loops! */
autodec=0, generic, generic_dither, idrei,
ivier, ifuenf, ifuenf_dither, mmx,
dreidnow, dreidnowext, altivec, sse, x86_64, arm,
nodec
};
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_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
#endif
#endif
#ifdef OPT_3DNOWEXT
#define OPT_MMXORSSE
#define OPT_MPLAYER
#define OPT_X86
#ifndef OPT_MULTI
# define defopt dreidnowext
# 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
# 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
#endif
#endif
#ifdef OPT_ARM
#ifndef OPT_MULTI
# define defopt arm
#endif
#endif
/* used for multi opt mode and the single 3dnow mode to have the old 3dnow test flag still working */
void check_decoders(void);
/*
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 || defined OPT_3DNOWEXT)
# define opt_dct36(fr) ((fr)->cpu_opts.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, 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,107 @@
/*
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"
struct buffy
{
unsigned char *data;
ssize_t size;
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. */
};
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;
int flags;
#ifndef WIN32
long timeout_sec;
#endif
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,
The second two pointers are the actual workers (default map to POSIX read/lseek). */
ssize_t (*r_read) (int fd, void *buf, size_t count);
off_t (*r_lseek)(int fd, off_t offset, int whence);
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);
struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */
};
/* start to use off_t to properly do LFS in future ... used to be long */
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);
/* 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_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

View File

@ -0,0 +1,960 @@
/* TODO: Check all read calls (in loops, especially!) for return value 0 (EOF)! */
/*
readers.c: reading input data
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 <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
/* For select(), I need select.h according to POSIX 2001, else: sys/time.h sys/types.h unistd.h */
/* Including these here although it works without on my Linux install... curious about _why_. */
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _MSC_VER
#include <io.h>
#endif
#include "debug.h"
static int default_init(mpg123_handle *fr);
static off_t get_fileinfo(mpg123_handle *);
static ssize_t posix_read(int fd, void *buf, size_t count){ return read(fd, buf, count); }
static off_t posix_lseek(int fd, off_t offset, int whence){ return lseek(fd, offset, whence); }
static ssize_t plain_fullread(mpg123_handle *fr,unsigned char *buf, ssize_t count);
#ifndef NO_FEEDER
/* Bufferchain methods. */
static void bc_init(struct bufferchain *bc);
static void bc_reset(struct bufferchain *bc);
static int bc_append(struct bufferchain *bc, ssize_t size);
#if 0
static void bc_drop(struct bufferchain *bc);
#endif
static int bc_add(struct bufferchain *bc, const unsigned char *data, ssize_t size);
static ssize_t bc_give(struct bufferchain *bc, unsigned char *out, ssize_t size);
static ssize_t bc_skip(struct bufferchain *bc, ssize_t count);
static ssize_t bc_seekback(struct bufferchain *bc, ssize_t count);
static void bc_forget(struct bufferchain *bc);
#else
#define bc_init(a)
#define bc_reset(a)
#endif
/* A normal read and a read with timeout. */
static ssize_t plain_read(mpg123_handle *fr, void *buf, size_t count)
{
ssize_t ret = fr->rdat.read(fr->rdat.filept, buf, count);
if(VERBOSE3) debug2("read %li bytes of %li", (long)ret, (long)count);
return ret;
}
#ifndef NO_ICY
/* stream based operation with icy meta data*/
static ssize_t icy_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count)
{
ssize_t ret,cnt;
cnt = 0;
if(fr->rdat.flags & READER_SEEKABLE)
{
if(NOQUIET) error("mpg123 programmer error: I don't do ICY on seekable streams.");
return -1;
}
/*
There used to be a check for expected file end here (length value or ID3 flag).
This is not needed:
1. EOF is indicated by fdread returning zero bytes anyway.
2. We get false positives of EOF for either files that grew or
3. ... files that have ID3v1 tags in between (stream with intro).
*/
while(cnt < count)
{
/* all icy code is inside this if block, everything else is the plain fullread we know */
/* debug1("read: %li left", (long) count-cnt); */
if(fr->icy.next < count-cnt)
{
unsigned char temp_buff;
size_t meta_size;
ssize_t cut_pos;
/* we are near icy-metaint boundary, read up to the boundary */
if(fr->icy.next > 0)
{
cut_pos = fr->icy.next;
ret = fr->rdat.fdread(fr,buf,cut_pos);
if(ret < 1)
{
if(ret == 0) break; /* Just EOF. */
if(NOQUIET) error("icy boundary read");
return READER_ERROR;
}
fr->rdat.filepos += ret;
cnt += ret;
fr->icy.next -= ret;
if(fr->icy.next > 0)
{
debug1("another try... still %li left", (long)fr->icy.next);
continue;
}
}
/* now off to read icy data */
/* one byte icy-meta size (must be multiplied by 16 to get icy-meta length) */
ret = fr->rdat.fdread(fr,&temp_buff,1); /* Getting one single byte hast to suceed. */
if(ret < 0){ if(NOQUIET) error("reading icy size"); return READER_ERROR; }
if(ret == 0) break;
debug2("got meta-size byte: %u, at filepos %li", temp_buff, (long)fr->rdat.filepos );
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret; /* 1... */
if((meta_size = ((size_t) temp_buff) * 16))
{
/* we have got some metadata */
char *meta_buff;
meta_buff = malloc(meta_size+1);
if(meta_buff != NULL)
{
ssize_t left = meta_size;
while(left > 0)
{
ret = fr->rdat.fdread(fr,meta_buff+meta_size-left,left);
/* 0 is error here, too... there _must_ be the ICY data, the server promised! */
if(ret < 1){ if(NOQUIET) error("reading icy-meta"); return READER_ERROR; }
left -= ret;
}
meta_buff[meta_size] = 0; /* string paranoia */
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret;
if(fr->icy.data) free(fr->icy.data);
fr->icy.data = meta_buff;
fr->metaflags |= MPG123_NEW_ICY;
debug2("icy-meta: %s size: %d bytes", fr->icy.data, (int)meta_size);
}
else
{
if(NOQUIET) error1("cannot allocate memory for meta_buff (%lu bytes) ... trying to skip the metadata!", (unsigned long)meta_size);
fr->rd->skip_bytes(fr, meta_size);
}
}
fr->icy.next = fr->icy.interval;
}
ret = plain_fullread(fr, buf+cnt, count-cnt);
if(ret < 0){ if(NOQUIET) error1("reading the rest of %li", (long)(count-cnt)); return READER_ERROR; }
if(ret == 0) break;
cnt += ret;
fr->icy.next -= ret;
}
/* debug1("done reading, got %li", (long)cnt); */
return cnt;
}
#else
#define icy_fullread NULL
#endif /* NO_ICY */
/* stream based operation */
static ssize_t plain_fullread(mpg123_handle *fr,unsigned char *buf, ssize_t count)
{
ssize_t ret,cnt=0;
/*
There used to be a check for expected file end here (length value or ID3 flag).
This is not needed:
1. EOF is indicated by fdread returning zero bytes anyway.
2. We get false positives of EOF for either files that grew or
3. ... files that have ID3v1 tags in between (stream with intro).
*/
while(cnt < count)
{
ret = fr->rdat.fdread(fr,buf+cnt,count-cnt);
if(ret < 0) return READER_ERROR;
if(ret == 0) break;
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret;
cnt += ret;
}
return cnt;
}
static off_t stream_lseek(mpg123_handle *fr, off_t pos, int whence)
{
off_t ret;
ret = fr->rdat.lseek(fr->rdat.filept, pos, whence);
if (ret >= 0) fr->rdat.filepos = ret;
else
{
fr->err = MPG123_LSEEK_FAILED;
ret = READER_ERROR; /* not the original value */
}
return ret;
}
static void stream_close(mpg123_handle *fr)
{
if(fr->rdat.flags & READER_FD_OPENED) close(fr->rdat.filept);
if(fr->rdat.flags & READER_BUFFERED) bc_reset(&fr->rdat.buffer);
}
static int stream_seek_frame(mpg123_handle *fr, off_t newframe)
{
debug2("seek_frame to %"OFF_P" (from %"OFF_P")", (off_p)newframe, (off_p)fr->num);
/* Seekable streams can go backwards and jump forwards.
Non-seekable streams still can go forward, just not jump. */
if((fr->rdat.flags & READER_SEEKABLE) || (newframe >= fr->num))
{
off_t preframe; /* a leading frame we jump to */
off_t seek_to; /* the byte offset we want to reach */
off_t to_skip; /* bytes to skip to get there (can be negative) */
/*
now seek to nearest leading index position and read from there until newframe is reached.
We use skip_bytes, which handles seekable and non-seekable streams
(the latter only for positive offset, which we ensured before entering here).
*/
seek_to = frame_index_find(fr, newframe, &preframe);
/* No need to seek to index position if we are closer already.
But I am picky about fr->num == newframe, play safe by reading the frame again.
If you think that's stupid, don't call a seek to the current frame. */
if(fr->num >= newframe || fr->num < preframe)
{
to_skip = seek_to - fr->rd->tell(fr);
if(fr->rd->skip_bytes(fr, to_skip) != seek_to)
return READER_ERROR;
debug2("going to %lu; just got %lu", (long unsigned)newframe, (long unsigned)preframe);
fr->num = preframe-1; /* Watch out! I am going to read preframe... fr->num should indicate the frame before! */
}
while(fr->num < newframe)
{
/* try to be non-fatal now... frameNum only gets advanced on success anyway */
if(!read_frame(fr)) break;
}
/* Now the wanted frame should be ready for decoding. */
debug1("arrived at %lu", (long unsigned)fr->num);
return MPG123_OK;
}
else
{
fr->err = MPG123_NO_SEEK;
return READER_ERROR; /* invalid, no seek happened */
}
}
/* return FALSE on error, TRUE on success, READER_MORE on occasion */
static int generic_head_read(mpg123_handle *fr,unsigned long *newhead)
{
unsigned char hbuf[4];
int ret = fr->rd->fullread(fr,hbuf,4);
if(ret == READER_MORE) return ret;
if(ret != 4) return FALSE;
*newhead = ((unsigned long) hbuf[0] << 24) |
((unsigned long) hbuf[1] << 16) |
((unsigned long) hbuf[2] << 8) |
(unsigned long) hbuf[3];
return TRUE;
}
/* return FALSE on error, TRUE on success, READER_MORE on occasion */
static int generic_head_shift(mpg123_handle *fr,unsigned long *head)
{
unsigned char hbuf;
int ret = fr->rd->fullread(fr,&hbuf,1);
if(ret == READER_MORE) return ret;
if(ret != 1) return FALSE;
*head <<= 8;
*head |= hbuf;
*head &= 0xffffffff;
return TRUE;
}
/* returns reached position... negative ones are bad... */
static off_t stream_skip_bytes(mpg123_handle *fr,off_t len)
{
if(fr->rdat.flags & READER_SEEKABLE)
{
off_t ret = stream_lseek(fr, len, SEEK_CUR);
return (ret < 0) ? READER_ERROR : ret;
}
else if(len >= 0)
{
unsigned char buf[1024]; /* ThOr: Compaq cxx complained and it makes sense to me... or should one do a cast? What for? */
ssize_t ret;
while (len > 0)
{
ssize_t num = len < (off_t)sizeof(buf) ? (ssize_t)len : (ssize_t)sizeof(buf);
ret = fr->rd->fullread(fr, buf, num);
if (ret < 0) return ret;
else if(ret == 0) break; /* EOF... an error? interface defined to tell the actual position... */
len -= ret;
}
return fr->rd->tell(fr);
}
else if(fr->rdat.flags & READER_BUFFERED)
{ /* Perhaps we _can_ go a bit back. */
if(fr->rdat.buffer.pos >= -len)
{
fr->rdat.buffer.pos += len;
return fr->rd->tell(fr);
}
else
{
fr->err = MPG123_NO_SEEK;
return READER_ERROR;
}
}
else
{
fr->err = MPG123_NO_SEEK;
return READER_ERROR;
}
}
/* Return 0 on success... */
static int stream_back_bytes(mpg123_handle *fr, off_t bytes)
{
off_t want = fr->rd->tell(fr)-bytes;
if(want < 0) return READER_ERROR;
if(stream_skip_bytes(fr,-bytes) != want) return READER_ERROR;
return 0;
}
/* returns size on success... */
static int generic_read_frame_body(mpg123_handle *fr,unsigned char *buf, int size)
{
long l;
if((l=fr->rd->fullread(fr,buf,size)) != size)
{
long ll = l;
if(ll <= 0) ll = 0;
/* This allows partial frames at the end... do we really want to pad and decode these?! */
memset(buf+ll,0,size-ll);
}
return l;
}
static off_t generic_tell(mpg123_handle *fr)
{
if(fr->rdat.flags & READER_BUFFERED)
fr->rdat.filepos = fr->rdat.buffer.fileoff+fr->rdat.buffer.pos;
return fr->rdat.filepos;
}
/* This does not (fully) work for non-seekable streams... You have to check for that flag, pal! */
static void stream_rewind(mpg123_handle *fr)
{
if(fr->rdat.flags & READER_SEEKABLE)
fr->rdat.buffer.fileoff = fr->rdat.filepos = stream_lseek(fr,0,SEEK_SET);
if(fr->rdat.flags & READER_BUFFERED)
{
fr->rdat.buffer.pos = 0;
fr->rdat.buffer.firstpos = 0;
fr->rdat.filepos = fr->rdat.buffer.fileoff;
}
}
/*
* returns length of a file (if filept points to a file)
* reads the last 128 bytes information into buffer
* ... that is not totally safe...
*/
static off_t get_fileinfo(mpg123_handle *fr)
{
off_t len;
if((len=fr->rdat.lseek(fr->rdat.filept,0,SEEK_END)) < 0) return -1;
if(fr->rdat.lseek(fr->rdat.filept,-128,SEEK_END) < 0) return -1;
if(fr->rd->fullread(fr,(unsigned char *)fr->id3buf,128) != 128) return -1;
if(!strncmp((char*)fr->id3buf,"TAG",3)) len -= 128;
if(fr->rdat.lseek(fr->rdat.filept,0,SEEK_SET) < 0) return -1;
if(len <= 0) return -1;
return len;
}
#ifndef NO_FEEDER
/* Methods for the buffer chain, mainly used for feed reader, but not just that. */
static void bc_init(struct bufferchain *bc)
{
bc->first = NULL;
bc->last = bc->first;
bc->size = 0;
bc->pos = 0;
bc->firstpos = 0;
bc->fileoff = 0;
}
static void bc_reset(struct bufferchain *bc)
{
/* free the buffer chain */
struct buffy *b = bc->first;
while(b != NULL)
{
struct buffy *n = b->next;
free(b->data);
free(b);
b = n;
}
bc_init(bc);
}
/* Create a new buffy at the end to be filled. */
static int bc_append(struct bufferchain *bc, ssize_t size)
{
struct buffy *newbuf;
if(size < 1) return -1;
newbuf = malloc(sizeof(struct buffy));
if(newbuf == NULL) return -2;
newbuf->data = malloc(size);
if(newbuf->data == NULL)
{
free(newbuf);
return -3;
}
newbuf->size = size;
newbuf->next = NULL;
if(bc->last != NULL) bc->last->next = newbuf;
else if(bc->first == NULL) bc->first = newbuf;
bc->last = newbuf;
bc->size += size;
return 0;
}
/* Append a new buffer and copy content to it. */
static int bc_add(struct bufferchain *bc, const unsigned char *data, ssize_t size)
{
int ret = 0;
if((ret = bc_append(bc, size)) == 0)
memcpy(bc->last->data, data, size);
return ret;
}
/* Give some data, advancing position but not forgetting yet. */
static ssize_t bc_give(struct bufferchain *bc, unsigned char *out, ssize_t size)
{
struct buffy *b = bc->first;
ssize_t gotcount = 0;
ssize_t offset = 0;
if(bc->size - bc->pos < size)
{
debug3("hit end, back to beginning (%li - %li < %li)", (long)bc->size, (long)bc->pos, (long)size);
/* go back to firstpos, undo the previous reads */
bc->pos = bc->firstpos;
return READER_MORE;
}
/* find the current buffer */
while(b != NULL && (offset + b->size) <= bc->pos)
{
offset += b->size;
b = b->next;
}
/* now start copying from there */
while(gotcount < size && (b != NULL))
{
ssize_t loff = bc->pos - offset;
ssize_t chunk = size - gotcount; /* amount of bytes to get from here... */
if(chunk > b->size - loff) chunk = b->size - loff;
#ifdef EXTRA_DEBUG
debug3("copying %liB from %p+%li",(long)chunk, b->data, (long)loff); */
#endif
memcpy(out+gotcount, b->data+loff, chunk);
gotcount += chunk;
bc->pos += chunk;
offset += b->size;
b = b->next;
}
#ifdef EXTRA_DEBUG
debug2("got %li bytes, pos advanced to %li", (long)gotcount, (long)bc->pos);
#endif
return gotcount;
}
/* Skip some bytes and return the new position.
The buffers are still there, just the read pointer is moved! */
static ssize_t bc_skip(struct bufferchain *bc, ssize_t count)
{
if(count >= 0)
{
if(bc->size - bc->pos < count) return READER_MORE;
else return bc->pos += count;
}
else return READER_ERROR;
}
static ssize_t bc_seekback(struct bufferchain *bc, ssize_t count)
{
if(count >= 0 && count <= bc->pos) return bc->pos -= count;
else return READER_ERROR;
}
/* Throw away buffies that we passed. */
static void bc_forget(struct bufferchain *bc)
{
struct buffy *b = bc->first;
/* free all buffers that are def'n'tly outdated */
/* we have buffers until filepos... delete all buffers fully below it */
#ifdef EXTRA_DEBUG
if(b) debug2("bc_forget: block %lu pos %lu", (unsigned long)b->size, (unsigned long)bc->pos);
else debug("forget with nothing there!");
#endif
while(b != NULL && bc->pos >= b->size)
{
struct buffy *n = b->next; /* != NULL or this is indeed the end and the last cycle anyway */
if(n == NULL) bc->last = NULL; /* Going to delete the last buffy... */
bc->fileoff += b->size;
bc->pos -= b->size;
bc->size -= b->size;
#ifdef EXTRA_DEBUG
debug5("bc_forget: forgot %p with %lu, pos=%li, size=%li, fileoff=%li", (void*)b->data, (long)b->size, (long)bc->pos, (long)bc->size, (long)bc->fileoff);
#endif
free(b->data);
free(b);
b = n;
}
bc->first = b;
bc->firstpos = bc->pos;
}
/* reader for input via manually provided buffers */
static int feed_init(mpg123_handle *fr)
{
bc_init(&fr->rdat.buffer);
fr->rdat.filelen = 0;
fr->rdat.filepos = 0;
fr->rdat.flags |= READER_BUFFERED;
return 0;
}
/* externally called function, returns 0 on success, -1 on error */
int feed_more(mpg123_handle *fr, const unsigned char *in, long count)
{
int ret = 0;
if(VERBOSE3) debug("feed_more");
if((ret = bc_add(&fr->rdat.buffer, in, count)) != 0)
{
ret = READER_ERROR;
if(NOQUIET) error1("Failed to add buffer, return: %i", ret);
}
else /* Not talking about filelen... that stays at 0. */
if(VERBOSE3) debug3("feed_more: %p %luB bufsize=%lu", fr->rdat.buffer.last->data,
(unsigned long)fr->rdat.buffer.last->size, (unsigned long)fr->rdat.buffer.size);
return ret;
}
static ssize_t feed_read(mpg123_handle *fr, unsigned char *out, ssize_t count)
{
ssize_t gotcount = bc_give(&fr->rdat.buffer, out, count);
if(gotcount >= 0 && gotcount != count) return READER_ERROR;
else return gotcount;
}
/* returns reached position... negative ones are bad... */
static off_t feed_skip_bytes(mpg123_handle *fr,off_t len)
{
return fr->rdat.buffer.fileoff+bc_skip(&fr->rdat.buffer, (ssize_t)len);
}
static int feed_back_bytes(mpg123_handle *fr, off_t bytes)
{
if(bytes >=0)
return bc_seekback(&fr->rdat.buffer, (ssize_t)bytes) >= 0 ? 0 : READER_ERROR;
else
return feed_skip_bytes(fr, -bytes) >= 0 ? 0 : READER_ERROR;
}
static int feed_seek_frame(mpg123_handle *fr, off_t num){ return READER_ERROR; }
/* Not just for feed reader, also for self-feeding buffered reader. */
static void buffered_forget(mpg123_handle *fr)
{
bc_forget(&fr->rdat.buffer);
fr->rdat.filepos = fr->rdat.buffer.fileoff + fr->rdat.buffer.pos;
}
off_t feed_set_pos(mpg123_handle *fr, off_t pos)
{
struct bufferchain *bc = &fr->rdat.buffer;
if(pos >= bc->fileoff && pos-bc->fileoff < bc->size)
{ /* We have the position! */
bc->pos = (ssize_t)(pos - bc->fileoff);
return pos+bc->size; /* Next input after end of buffer... */
}
else
{ /* I expect to get the specific position on next feed. Forget what I have now. */
bc_reset(bc);
bc->fileoff = pos;
return pos; /* Next input from exactly that position. */
}
}
/* The specific stuff for buffered stream reader. */
/* Let's work in nice 4K blocks, that may be nicely reusable (by malloc(), even). */
#define BUFFBLOCK 4096
static ssize_t buffered_fullread(mpg123_handle *fr, unsigned char *out, ssize_t count)
{
struct bufferchain *bc = &fr->rdat.buffer;
ssize_t gotcount;
if(bc->size - bc->pos < count)
{ /* Add more stuff to buffer. If hitting end of file, adjust count. */
unsigned char readbuf[BUFFBLOCK];
ssize_t need = count - (bc->size-bc->pos);
while(need>0)
{
int ret;
ssize_t got = fr->rdat.fullread(fr, readbuf, BUFFBLOCK);
if(got < 0)
{
if(NOQUIET) error("buffer reading");
return READER_ERROR;
}
if(VERBOSE3) debug1("buffered_fullread: buffering %li bytes from stream (if > 0)", (long)got);
if(got > 0 && (ret=bc_add(bc, readbuf, got)) != 0)
{
if(NOQUIET) error1("unable to add to chain, return: %i", ret);
return READER_ERROR;
}
need -= got; /* May underflow here... */
if(got < BUFFBLOCK) /* That naturally catches got == 0, too. */
{
if(VERBOSE3) fprintf(stderr, "Note: Input data end.\n");
break; /* End. */
}
}
if(bc->size - bc->pos < count)
count = bc->size - bc->pos; /* We want only what we got. */
}
gotcount = bc_give(bc, out, count);
if(VERBOSE3) debug2("wanted %li, got %li", (long)count, (long)gotcount);
if(gotcount != count){ if(NOQUIET) error("gotcount != count"); return READER_ERROR; }
else return gotcount;
}
#else
int feed_more(mpg123_handle *fr, const unsigned char *in, long count)
{
fr->err = MPG123_MISSING_FEATURE;
return -1;
}
off_t feed_set_pos(mpg123_handle *fr, off_t pos)
{
fr->err = MPG123_MISSING_FEATURE;
return -1;
}
#endif /* NO_FEEDER */
/*****************************************************************
* read frame helper
*/
#define bugger_off { mh->err = MPG123_NO_READER; return MPG123_ERR; }
int bad_init(mpg123_handle *mh) bugger_off
void bad_close(mpg123_handle *mh){}
ssize_t bad_fullread(mpg123_handle *mh, unsigned char *data, ssize_t count) bugger_off
int bad_head_read(mpg123_handle *mh, unsigned long *newhead) bugger_off
int bad_head_shift(mpg123_handle *mh, unsigned long *head) bugger_off
off_t bad_skip_bytes(mpg123_handle *mh, off_t len) bugger_off
int bad_read_frame_body(mpg123_handle *mh, unsigned char *data, int size) bugger_off
int bad_back_bytes(mpg123_handle *mh, off_t bytes) bugger_off
int bad_seek_frame(mpg123_handle *mh, off_t num) bugger_off
off_t bad_tell(mpg123_handle *mh) bugger_off
void bad_rewind(mpg123_handle *mh){}
#undef bugger_off
#define READER_STREAM 0
#define READER_ICY_STREAM 1
#define READER_FEED 2
#define READER_BUF_STREAM 3
#define READER_BUF_ICY_STREAM 4
struct reader readers[] =
{
{ /* READER_STREAM */
default_init,
stream_close,
plain_fullread,
generic_head_read,
generic_head_shift,
stream_skip_bytes,
generic_read_frame_body,
stream_back_bytes,
stream_seek_frame,
generic_tell,
stream_rewind,
NULL
} ,
{ /* READER_ICY_STREAM */
default_init,
stream_close,
icy_fullread,
generic_head_read,
generic_head_shift,
stream_skip_bytes,
generic_read_frame_body,
stream_back_bytes,
stream_seek_frame,
generic_tell,
stream_rewind,
NULL
},
#ifdef NO_FEEDER
#define feed_init NULL
#define feed_read NULL
#define buffered_fullread NULL
#define feed_seek_frame NULL
#define feed_back_bytes NULL
#define feed_skip_bytes NULL
#define buffered_forget NULL
#endif
{ /* READER_FEED */
feed_init,
stream_close,
feed_read,
generic_head_read,
generic_head_shift,
feed_skip_bytes,
generic_read_frame_body,
feed_back_bytes,
feed_seek_frame,
generic_tell,
stream_rewind,
buffered_forget
},
{ /* READER_BUF_STREAM */
default_init,
stream_close,
buffered_fullread,
generic_head_read,
generic_head_shift,
stream_skip_bytes,
generic_read_frame_body,
stream_back_bytes,
stream_seek_frame,
generic_tell,
stream_rewind,
buffered_forget
} ,
{ /* READER_BUF_ICY_STREAM */
default_init,
stream_close,
buffered_fullread,
generic_head_read,
generic_head_shift,
stream_skip_bytes,
generic_read_frame_body,
stream_back_bytes,
stream_seek_frame,
generic_tell,
stream_rewind,
buffered_forget
},
#ifdef READ_SYSTEM
,{
system_init,
NULL, /* filled in by system_init() */
fullread,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}
#endif
};
struct reader bad_reader =
{
bad_init,
bad_close,
bad_fullread,
bad_head_read,
bad_head_shift,
bad_skip_bytes,
bad_read_frame_body,
bad_back_bytes,
bad_seek_frame,
bad_tell,
bad_rewind,
NULL
};
static int default_init(mpg123_handle *fr)
{
fr->rdat.fdread = plain_read;
fr->rdat.read = fr->rdat.r_read != NULL ? fr->rdat.r_read : posix_read;
fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : posix_lseek;
fr->rdat.filelen = get_fileinfo(fr);
fr->rdat.filepos = 0;
if(fr->rdat.filelen >= 0)
{
fr->rdat.flags |= READER_SEEKABLE;
if(!strncmp((char*)fr->id3buf,"TAG",3))
{
fr->rdat.flags |= READER_ID3TAG;
fr->metaflags |= MPG123_NEW_ID3;
}
}
/* Switch reader to a buffered one, if allowed. */
else if(fr->p.flags & MPG123_SEEKBUFFER)
{
#ifdef NO_FEEDER
error("Buffered readers not supported in this build.");
fr->err = MPG123_MISSING_FEATURE;
return -1;
#else
if (fr->rd == &readers[READER_STREAM])
{
fr->rd = &readers[READER_BUF_STREAM];
fr->rdat.fullread = plain_fullread;
}
#ifndef NO_ICY
else if(fr->rd == &readers[READER_ICY_STREAM])
{
fr->rd = &readers[READER_BUF_ICY_STREAM];
fr->rdat.fullread = icy_fullread;
}
#endif
else
{
if(NOQUIET) error("mpg123 Programmer's fault: invalid reader");
return -1;
}
bc_init(&fr->rdat.buffer);
fr->rdat.filelen = 0; /* We carry the offset, but never know how big the stream is. */
fr->rdat.flags |= READER_BUFFERED;
#endif /* NO_FEEDER */
}
return 0;
}
void open_bad(mpg123_handle *mh)
{
#ifndef NO_ICY
clear_icy(&mh->icy);
#endif
mh->rd = &bad_reader;
mh->rdat.flags = 0;
bc_init(&mh->rdat.buffer);
}
int open_feed(mpg123_handle *fr)
{
debug("feed reader");
#ifdef NO_FEEDER
error("Buffered readers not supported in this build.");
fr->err = MPG123_MISSING_FEATURE;
return -1;
#else
#ifndef NO_ICY
if(fr->p.icy_interval > 0)
{
if(NOQUIET) error("Feed reader cannot do ICY parsing!");
return -1;
}
clear_icy(&fr->icy);
#endif
fr->rd = &readers[READER_FEED];
fr->rdat.flags = 0;
if(fr->rd->init(fr) < 0) return -1;
return 0;
#endif /* NO_FEEDER */
}
int open_stream(mpg123_handle *fr, const char *bs_filenam, int fd)
{
int filept_opened = 1;
int filept; /* descriptor of opened file/stream */
clear_icy(&fr->icy); /* can be done inside frame_clear ...? */
if(!bs_filenam) /* no file to open, got a descriptor (stdin) */
{
filept = fd;
filept_opened = 0; /* and don't try to close it... */
}
#ifndef O_BINARY
#define O_BINARY (0)
#endif
else if((filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) /* a plain old file to open... */
{
if(NOQUIET) error2("Cannot open file %s: %s", bs_filenam, strerror(errno));
fr->err = MPG123_BAD_FILE;
return MPG123_ERR; /* error... */
}
/* now we have something behind filept and can init the reader */
fr->rdat.filelen = -1;
fr->rdat.filept = filept;
fr->rdat.flags = 0;
if(filept_opened) fr->rdat.flags |= READER_FD_OPENED;
#ifndef NO_ICY
if(fr->p.icy_interval > 0)
{
debug("ICY reader");
fr->icy.interval = fr->p.icy_interval;
fr->icy.next = fr->icy.interval;
fr->rd = &readers[READER_ICY_STREAM];
}
else
#endif
{
fr->rd = &readers[READER_STREAM];
debug("stream reader");
}
if(fr->rd->init(fr) < 0) return -1;
return MPG123_OK;
}

View File

@ -0,0 +1,132 @@
/*
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 short idiv_signed_rounded(long x, int shift)
{
x >>= (shift - 1);
x += (x & 1);
return (short)(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
/* 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 short ftoi16(float x)
{
union
{
float f;
int32_t i;
} u_fi;
u_fi.f = x + 12582912.0f; /* Magic Number: 2^23 + 2^22 */
return (short)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
/* 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. */
/* 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); }
/* 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) \
{ \
short 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
#endif

View File

@ -0,0 +1,131 @@
/*
stringbuf: mimicking a bit of C++ to more safely handle strings
copyright 2006-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 "mpg123lib_intern.h"
#include "config.h"
#include "mpg123.h"
#include "compat.h"
#include <string.h>
#include "debug.h"
void attribute_align_arg mpg123_init_string(mpg123_string* sb)
{
sb->p = NULL;
sb->size = 0;
sb->fill = 0;
}
void attribute_align_arg mpg123_free_string(mpg123_string* sb)
{
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->size < new) return mpg123_resize_string(sb, new);
else return 1;
}
int attribute_align_arg mpg123_resize_string(mpg123_string* sb, size_t new)
{
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;
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;
if(to == NULL) return -1;
debug2("called copy_string with %p -> %p", (void*)from, (void*)to);
if(from == NULL)
{
fill = 0;
text = NULL;
}
else
{
fill = from->fill;
text = from->p;
}
if(mpg123_resize_string(to, fill))
{
memcpy(to->p, text, fill);
to->fill = fill;
return 1;
}
else return 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, strlen(stuff));
}
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->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)
{
sb->fill = 0;
return mpg123_add_substring(sb, stuff, from, count);
}
int attribute_align_arg mpg123_set_string(mpg123_string* sb, const char* stuff)
{
sb->fill = 0;
return mpg123_add_string(sb, stuff);
}

View File

@ -0,0 +1,643 @@
/*
synth.c: The functions for synthesizing 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"
/* Stereo-related synth, wrapping over _some_ plain synth. */
int synth_stereo_wrap(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
int clip;
clip = (fr->synth)(bandPtr_l, 0, fr, 0);
clip += (fr->synth)(bandPtr_r, 1, fr, 1);
return clip;
}
/*
Part 1: All synth functions that produce signed short.
That is:
- synth_1to1 with cpu-specific variants (synth_1to1_i386, synth_1to1_i586 ...)
- synth_1to1_mono and synth_1to1_mono2stereo; which use fr->synths.plain[r_1to1][f_16].
Nearly every decoder variant has it's own synth_1to1, while the mono conversion is shared.
*/
#define SAMPLE_T short
#define WRITE_SAMPLE(samples,sum,clip) WRITE_SHORT_SAMPLE(samples,sum,clip)
/* Part 1a: All straight 1to1 decoding functions */
#define BLOCK 0x40 /* One decoding block is 64 samples. */
#define SYNTH_NAME synth_1to1
#include "synth.h"
#undef SYNTH_NAME
/* Mono-related synths; they wrap over _some_ synth_1to1. */
#define SYNTH_NAME fr->synths.plain[r_1to1][f_16]
#define MONO_NAME synth_1to1_mono
#define MONO2STEREO_NAME synth_1to1_mono2stereo
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
/* Now we have possibly some special synth_1to1 ...
... they produce signed short; the mono functions defined above work on the special synths, too. */
#ifdef OPT_GENERIC_DITHER
#define SYNTH_NAME synth_1to1_dither
/* We need the accurate sample writing... */
#undef WRITE_SAMPLE
#define WRITE_SAMPLE(samples,sum,clip) WRITE_SHORT_SAMPLE_ACCURATE(samples,sum,clip)
#define USE_DITHER
#include "synth.h"
#undef USE_DITHER
#undef SYNTH_NAME
#undef WRITE_SAMPLE
#define WRITE_SAMPLE(samples,sum,clip) WRITE_SHORT_SAMPLE(samples,sum,clip)
#endif
#ifdef OPT_X86
/* The i386-specific C code, here as short variant, later 8bit and float. */
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_1to1_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK /* Following functions are so special that they don't need this. */
#ifdef OPT_I586
/* This is defined in assembler. */
int synth_1to1_i586_asm(real *bandPtr, int channel, unsigned char *out, unsigned char *buffs, int *bo, real *decwin);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_i586(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
int ret;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
ret = synth_1to1_i586_asm(bandPtr, channel, fr->buffer.data+fr->buffer.fill, fr->rawbuffs, &fr->bo, fr->decwin);
if(final) fr->buffer.fill += 128;
return ret;
}
#endif
#ifdef OPT_I586_DITHER
/* This is defined in assembler. */
int synth_1to1_i586_asm_dither(real *bandPtr, int channel, unsigned char *out, unsigned char *buffs, int *bo, real *decwin, float *dithernoise);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_i586_dither(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
int ret;
int bo_dither[2]; /* Temporary workaround? Could expand the asm code. */
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
/* Applying this hack, to change the asm only bit by bit (adding dithernoise pointer). */
bo_dither[0] = fr->bo;
bo_dither[1] = fr->ditherindex;
ret = synth_1to1_i586_asm_dither(bandPtr, channel, fr->buffer.data+fr->buffer.fill, fr->rawbuffs, bo_dither, fr->decwin, fr->dithernoise);
fr->bo = bo_dither[0];
fr->ditherindex = bo_dither[1];
if(final) fr->buffer.fill += 128;
return ret;
}
#endif
#ifdef OPT_3DNOW
/* Those are defined in assembler. */
void do_equalizer_3dnow(real *bandPtr,int channel, real equalizer[2][32]);
int synth_1to1_3dnow_asm(real *bandPtr, int channel, unsigned char *out, unsigned char *buffs, int *bo, real *decwin);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_3dnow(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
int ret;
if(fr->have_eq_settings) do_equalizer_3dnow(bandPtr,channel,fr->equalizer);
/* this is in asm, can be dither or not */
/* uh, is this return from pointer correct? */
ret = (int) synth_1to1_3dnow_asm(bandPtr, channel, fr->buffer.data+fr->buffer.fill, fr->rawbuffs, &fr->bo, fr->decwin);
if(final) fr->buffer.fill += 128;
return ret;
}
#endif
#ifdef OPT_MMX
/* This is defined in assembler. */
int synth_1to1_MMX(real *bandPtr, int channel, short *out, short *buffs, int *bo, float *decwins);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_mmx(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
/* in asm */
synth_1to1_MMX(bandPtr, channel, (short*) (fr->buffer.data+fr->buffer.fill), (short *) fr->rawbuffs, &fr->bo, fr->decwins);
if(final) fr->buffer.fill += 128;
return 0;
}
#endif
#ifdef OPT_SSE
#ifdef ACCURATE_ROUNDING
/* This is defined in assembler. */
int synth_1to1_sse_accurate_asm(real *window, real *b0, short *samples, int bo1);
int synth_1to1_stereo_sse_accurate_asm(real *window, real *b0l, real *b0r, short *samples, int bo1);
void dct64_real_sse(real *out0, real *out1, real *samples);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_sse(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int clip;
int bo1;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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_sse_accurate_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 128;
return clip;
}
int synth_1to1_stereo_sse(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
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_stereo_sse_accurate_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 128;
return clip;
}
#else
/* This is defined in assembler. */
void synth_1to1_sse_asm(real *bandPtr, int channel, short *samples, short *buffs, int *bo, real *decwin);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_sse(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
synth_1to1_sse_asm(bandPtr, channel, (short*) (fr->buffer.data+fr->buffer.fill), (short *) fr->rawbuffs, &fr->bo, fr->decwins);
if(final) fr->buffer.fill += 128;
return 0;
}
#endif
#endif
#ifdef OPT_3DNOWEXT
/* This is defined in assembler. */
void synth_1to1_3dnowext_asm(real *bandPtr, int channel, short *samples, short *buffs, int *bo, real *decwin);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_3dnowext(real *bandPtr, int channel, mpg123_handle *fr, int final)
{
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
synth_1to1_3dnowext_asm(bandPtr, channel, (short*) (fr->buffer.data+fr->buffer.fill), (short *) fr->rawbuffs, &fr->bo, fr->decwins);
if(final) fr->buffer.fill += 128;
return 0;
}
#endif
#ifdef OPT_X86_64
#ifdef ACCURATE_ROUNDING
/* Assembler routines. */
int synth_1to1_x86_64_accurate_asm(real *window, real *b0, short *samples, int bo1);
int synth_1to1_stereo_x86_64_accurate_asm(real *window, real *b0l, real *b0r, short *samples, int bo1);
void dct64_real_x86_64(real *out0, real *out1, real *samples);
/* Hull for C mpg123 API */
int synth_1to1_x86_64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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_x86_64_accurate_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 128;
return clip;
}
int synth_1to1_stereo_x86_64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0l, *b0r, **bufl, **bufr;
int bo1;
int clip;
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
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_stereo_x86_64_accurate_asm(fr->decwin, b0l, b0r, samples, bo1);
fr->buffer.fill += 128;
return clip;
}
#else
/* This is defined in assembler. */
int synth_1to1_x86_64_asm(short *window, short *b0, short *samples, int bo1);
int synth_1to1_stereo_x86_64_asm(short *window, short *b0l, short *b0r, short *samples, int bo1);
void dct64_x86_64(short *out0, short *out1, real *samples);
/* This is just a hull to use the mpg123 handle. */
int synth_1to1_x86_64(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
short *b0, **buf;
int clip;
int bo1;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
if(!channel)
{
fr->bo--;
fr->bo &= 0xf;
buf = fr->short_buffs[0];
}
else
{
samples++;
buf = fr->short_buffs[1];
}
if(fr->bo & 0x1)
{
b0 = buf[0];
bo1 = fr->bo;
dct64_x86_64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
}
else
{
b0 = buf[1];
bo1 = fr->bo+1;
dct64_x86_64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
}
clip = synth_1to1_x86_64_asm((short *)fr->decwins, b0, samples, bo1);
if(final) fr->buffer.fill += 128;
return clip;
}
int synth_1to1_stereo_x86_64(real *bandPtr_l,real *bandPtr_r, mpg123_handle *fr)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
short *b0l, *b0r, **bufl, **bufr;
int clip;
int bo1;
if(fr->have_eq_settings)
{
do_equalizer(bandPtr_l,0,fr->equalizer);
do_equalizer(bandPtr_r,1,fr->equalizer);
}
fr->bo--;
fr->bo &= 0xf;
bufl = fr->short_buffs[0];
bufr = fr->short_buffs[1];
if(fr->bo & 0x1)
{
b0l = bufl[0];
b0r = bufr[0];
bo1 = fr->bo;
dct64_x86_64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
dct64_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_x86_64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
dct64_x86_64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
}
clip = synth_1to1_stereo_x86_64_asm((short *)fr->decwins, b0l, b0r, samples, bo1);
fr->buffer.fill += 128;
return clip;
}
#endif
#endif
#ifdef OPT_ARM
#ifdef ACCURATE_ROUNDING
/* Assembler routines. */
int synth_1to1_arm_accurate_asm(real *window, real *b0, short *samples, int bo1);
/* Hull for C mpg123 API */
int synth_1to1_arm(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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(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);
}
clip = synth_1to1_arm_accurate_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 128;
return clip;
}
#else
/* Assembler routines. */
int synth_1to1_arm_asm(real *window, real *b0, short *samples, int bo1);
/* Hull for C mpg123 API */
int synth_1to1_arm(real *bandPtr,int channel, mpg123_handle *fr, int final)
{
short *samples = (short *) (fr->buffer.data+fr->buffer.fill);
real *b0, **buf;
int bo1;
int clip;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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(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);
}
clip = synth_1to1_arm_asm(fr->decwin, b0, samples, bo1);
if(final) fr->buffer.fill += 128;
return clip;
}
#endif
#endif
#ifndef NO_DOWNSAMPLE
/*
Part 1b: 2to1 synth.
Only generic and i386 functions this time.
*/
#define BLOCK 0x20 /* One decoding block is 32 samples. */
#define SYNTH_NAME synth_2to1
#include "synth.h"
#undef SYNTH_NAME
#ifdef OPT_DITHER /* Used for generic_dither and as fallback for i586_dither. */
#define SYNTH_NAME synth_2to1_dither
#define USE_DITHER
#include "synth.h"
#undef USE_DITHER
#undef SYNTH_NAME
#endif
#define SYNTH_NAME fr->synths.plain[r_2to1][f_16]
#define MONO_NAME synth_2to1_mono
#define MONO2STEREO_NAME synth_2to1_mono2stereo
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_2to1_i386
#include "synth.h"
#undef SYNTH_NAME
/* i386 uses the normal mono functions. */
#undef NO_AUTOINCREMENT
#endif
#undef BLOCK
/*
Part 1c: 4to1 synth.
Same procedure as above...
*/
#define BLOCK 0x10 /* One decoding block is 16 samples. */
#define SYNTH_NAME synth_4to1
#include "synth.h"
#undef SYNTH_NAME
#ifdef OPT_DITHER
#define SYNTH_NAME synth_4to1_dither
#define USE_DITHER
#include "synth.h"
#undef USE_DITHER
#undef SYNTH_NAME
#endif
#define SYNTH_NAME fr->synths.plain[r_4to1][f_16] /* This is just for the _i386 one... gotta check if it is really useful... */
#define MONO_NAME synth_4to1_mono
#define MONO2STEREO_NAME synth_4to1_mono2stereo
#include "synth_mono.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#ifdef OPT_X86
#define NO_AUTOINCREMENT
#define SYNTH_NAME synth_4to1_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 1d: ntom synth.
Same procedure as above... Just no extra play anymore, straight synth that uses the plain dct64.
*/
/* These are all in one header, there's no flexibility to gain. */
#define SYNTH_NAME synth_ntom
#define MONO_NAME synth_ntom_mono
#define MONO2STEREO_NAME synth_ntom_mono2stereo
#include "synth_ntom.h"
#undef SYNTH_NAME
#undef MONO_NAME
#undef MONO2STEREO_NAME
#endif
/* Done with short output. */
#undef SAMPLE_T
#undef WRITE_SAMPLE

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;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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,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,129 @@
/*
decode_MMX.s: MMX optimized synth
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 the mysterious higway (apparently)
Thomas' words about a note:
Initially, I found the note "this code comes under GPL" in this file.
After asking Michael about legal status of the MMX files, he said that he got them without any comment and thus I believe that the GPL comment was made by Michael, since he made mpg123 GPL at some time - and marked some files that way, but not all.
Based on that thought, I now consider this file along with the other parts of higway's MMX optimization to be licensed under LGPL 2.1 by Michael's decision.
*/
#include "mangle.h"
.text
.globl ASM_NAME(synth_1to1_MMX)
/* int synth_1to1_MMX(real *bandPtr, int channel, short *out, short *buffs, int *bo, float *decwins); */
ASM_NAME(synth_1to1_MMX):
pushl %ebp
pushl %edi
pushl %esi
pushl %ebx
/* stack: 0=ebx, 4=esi, 8=edi, 12=ebp, 16=back, 20=bandPtr, 24=channel, 28=out, 32=buffs, 36=bo, 40=decwins */
movl 24(%esp),%ecx
movl 28(%esp),%edi
movl $15,%ebx
movl 36(%esp),%edx
leal (%edi,%ecx,2),%edi
decl %ecx
movl 32(%esp),%esi
movl (%edx),%eax
jecxz .L1
decl %eax
andl %ebx,%eax
leal 1088(%esi),%esi
movl %eax,(%edx)
.L1:
leal (%esi,%eax,2),%edx
movl %eax,%ebp
incl %eax
pushl 20(%esp)
andl %ebx,%eax
leal 544(%esi,%eax,2),%ecx
incl %ebx
testl $1, %eax
jnz .L2
xchgl %edx,%ecx
incl %ebp
leal 544(%esi),%esi
.L2:
pushl %edx
pushl %ecx
call ASM_NAME(dct64_MMX)
addl $12,%esp
/* stack like before, pushed 3, incremented again */
leal 1(%ebx), %ecx
subl %ebp,%ebx
pushl %eax
movl 44(%esp),%eax /* decwins */
leal (%eax,%ebx,2), %edx
popl %eax
.L3:
movq (%edx),%mm0
pmaddwd (%esi),%mm0
movq 8(%edx),%mm1
pmaddwd 8(%esi),%mm1
movq 16(%edx),%mm2
pmaddwd 16(%esi),%mm2
movq 24(%edx),%mm3
pmaddwd 24(%esi),%mm3
paddd %mm1,%mm0
paddd %mm2,%mm0
paddd %mm3,%mm0
movq %mm0,%mm1
psrlq $32,%mm1
paddd %mm1,%mm0
psrad $13,%mm0
packssdw %mm0,%mm0
movd %mm0,%eax
movw %ax, (%edi)
leal 32(%esi),%esi
leal 64(%edx),%edx
leal 4(%edi),%edi
loop .L3
subl $64,%esi
movl $15,%ecx
.L4:
movq (%edx),%mm0
pmaddwd (%esi),%mm0
movq 8(%edx),%mm1
pmaddwd 8(%esi),%mm1
movq 16(%edx),%mm2
pmaddwd 16(%esi),%mm2
movq 24(%edx),%mm3
pmaddwd 24(%esi),%mm3
paddd %mm1,%mm0
paddd %mm2,%mm0
paddd %mm3,%mm0
movq %mm0,%mm1
psrlq $32,%mm1
paddd %mm0,%mm1
psrad $13,%mm1
packssdw %mm1,%mm1
psubd %mm0,%mm0
psubsw %mm1,%mm0
movd %mm0,%eax
movw %ax,(%edi)
subl $32,%esi
addl $64,%edx
leal 4(%edi),%edi
loop .L4
emms
popl %ebx
popl %esi
popl %edi
popl %ebp
ret
/* Mark non-executable stack. */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

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;
if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
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,246 @@
/*
decode_sse3d: Synth for SSE and extended 3DNow (yeah, the name is a relic)
copyright 2006-2007 by Zuxy Meng/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 the mysterious higway for MMX (apparently)
then developed into SSE opt by Zuxy Meng, also building on Romain Dolbeau's AltiVec
Both have agreed to distribution under LGPL 2.1 .
Transformed back into standalone asm, with help of
gcc -S -DHAVE_CONFIG_H -I. -march=pentium -O3 -Wall -pedantic -fno-strict-aliasing -DREAL_IS_FLOAT -c -o decode_mmxsse.{S,c}
The difference between SSE and 3DNowExt is the dct64 function and the synth function name.
This template here uses the SYNTH_NAME and MPL_DCT64 macros for this - see decode_sse.S and decode_3dnowext.S...
That's not memory efficient since there's doubled code, but it's easier than giving another function pointer.
Maybe I'll change it in future, but now I need something that works.
Original comment from MPlayer source follows:
*/
/*
* this code comes under GPL
* This code was taken from http://www.mpg123.org
* See ChangeLog of mpg123-0.59s-pre.1 for detail
* Applied to mplayer by Nick Kurshev <nickols_k@mail.ru>
*
* Local ChangeLog:
* - Partial loops unrolling and removing MOVW insn from loops
*/
#include "mangle.h"
.data
ALIGN8
one_null:
.long -65536
.long -65536
ALIGN8
null_one:
.long 65535
.long 65535
.text
ALIGN16,,15
/* void SYNTH_NAME(real *bandPtr, int channel, short *samples, short *buffs, int *bo, float *decwins) */
.globl SYNTH_NAME
SYNTH_NAME:
pushl %ebp
/* stack:0=ebp 4=back 8=bandptr 12=channel 16=samples 20=buffs 24=bo 28=decwins */
movl %esp, %ebp
/* Now the old stack addresses are preserved via %epb. */
subl $4,%esp /* What has been called temp before. */
pushl %edi
pushl %esi
pushl %ebx
#define TEMP 12(%esp)
/* APP */
movl 12(%ebp),%ecx
movl 16(%ebp),%edi
movl $15,%ebx
movl 24(%ebp),%edx
leal (%edi,%ecx,2),%edi
decl %ecx
movl 20(%ebp),%esi
movl (%edx),%eax
jecxz .L01
decl %eax
andl %ebx,%eax
leal 1088(%esi),%esi
movl %eax,(%edx)
.L01:
leal (%esi,%eax,2),%edx
movl %eax,TEMP
incl %eax
andl %ebx,%eax
leal 544(%esi,%eax,2),%ecx
incl %ebx
testl $1, %eax
jnz .L02
xchgl %edx,%ecx
incl TEMP
leal 544(%esi),%esi
.L02:
pushl 8(%ebp)
pushl %edx
pushl %ecx
call MPL_DCT64
addl $12, %esp
leal 1(%ebx), %ecx
subl TEMP,%ebx
pushl %ecx
/* leal ASM_NAME(decwins)(%ebx,%ebx,1), %edx */
movl 28(%ebp),%ecx
leal (%ecx,%ebx,2), %edx
movl (%esp),%ecx /* restore, but leave value on stack */
shrl $1, %ecx
ALIGN16
.L03:
movq (%edx),%mm0
movq 64(%edx),%mm4
pmaddwd (%esi),%mm0
pmaddwd 32(%esi),%mm4
movq 8(%edx),%mm1
movq 72(%edx),%mm5
pmaddwd 8(%esi),%mm1
pmaddwd 40(%esi),%mm5
movq 16(%edx),%mm2
movq 80(%edx),%mm6
pmaddwd 16(%esi),%mm2
pmaddwd 48(%esi),%mm6
movq 24(%edx),%mm3
movq 88(%edx),%mm7
pmaddwd 24(%esi),%mm3
pmaddwd 56(%esi),%mm7
paddd %mm1,%mm0
paddd %mm5,%mm4
paddd %mm2,%mm0
paddd %mm6,%mm4
paddd %mm3,%mm0
paddd %mm7,%mm4
movq %mm0,%mm1
movq %mm4,%mm5
psrlq $32,%mm1
psrlq $32,%mm5
paddd %mm1,%mm0
paddd %mm5,%mm4
psrad $13,%mm0
psrad $13,%mm4
packssdw %mm0,%mm0
packssdw %mm4,%mm4
movq (%edi), %mm1
punpckldq %mm4, %mm0
pand one_null, %mm1
pand null_one, %mm0
por %mm0, %mm1
movq %mm1,(%edi)
leal 64(%esi),%esi
leal 128(%edx),%edx
leal 8(%edi),%edi
decl %ecx
jnz .L03
popl %ecx
andl $1, %ecx
jecxz .next_loop
movq (%edx),%mm0
pmaddwd (%esi),%mm0
movq 8(%edx),%mm1
pmaddwd 8(%esi),%mm1
movq 16(%edx),%mm2
pmaddwd 16(%esi),%mm2
movq 24(%edx),%mm3
pmaddwd 24(%esi),%mm3
paddd %mm1,%mm0
paddd %mm2,%mm0
paddd %mm3,%mm0
movq %mm0,%mm1
psrlq $32,%mm1
paddd %mm1,%mm0
psrad $13,%mm0
packssdw %mm0,%mm0
movd %mm0,%eax
movw %ax, (%edi)
leal 32(%esi),%esi
leal 64(%edx),%edx
leal 4(%edi),%edi
.next_loop:
subl $64,%esi
movl $7,%ecx
ALIGN16
.L04:
movq (%edx),%mm0
movq 64(%edx),%mm4
pmaddwd (%esi),%mm0
pmaddwd -32(%esi),%mm4
movq 8(%edx),%mm1
movq 72(%edx),%mm5
pmaddwd 8(%esi),%mm1
pmaddwd -24(%esi),%mm5
movq 16(%edx),%mm2
movq 80(%edx),%mm6
pmaddwd 16(%esi),%mm2
pmaddwd -16(%esi),%mm6
movq 24(%edx),%mm3
movq 88(%edx),%mm7
pmaddwd 24(%esi),%mm3
pmaddwd -8(%esi),%mm7
paddd %mm1,%mm0
paddd %mm5,%mm4
paddd %mm2,%mm0
paddd %mm6,%mm4
paddd %mm3,%mm0
paddd %mm7,%mm4
movq %mm0,%mm1
movq %mm4,%mm5
psrlq $32,%mm1
psrlq $32,%mm5
paddd %mm0,%mm1
paddd %mm4,%mm5
psrad $13,%mm1
psrad $13,%mm5
packssdw %mm1,%mm1
packssdw %mm5,%mm5
psubd %mm0,%mm0
psubd %mm4,%mm4
psubsw %mm1,%mm0
psubsw %mm5,%mm4
movq (%edi), %mm1
punpckldq %mm4, %mm0
pand one_null, %mm1
pand null_one, %mm0
por %mm0, %mm1
movq %mm1,(%edi)
subl $64,%esi
addl $128,%edx
leal 8(%edi),%edi
decl %ecx
jnz .L04
movq (%edx),%mm0
pmaddwd (%esi),%mm0
movq 8(%edx),%mm1
pmaddwd 8(%esi),%mm1
movq 16(%edx),%mm2
pmaddwd 16(%esi),%mm2
movq 24(%edx),%mm3
pmaddwd 24(%esi),%mm3
paddd %mm1,%mm0
paddd %mm2,%mm0
paddd %mm3,%mm0
movq %mm0,%mm1
psrlq $32,%mm1
paddd %mm0,%mm1
psrad $13,%mm1
packssdw %mm1,%mm1
psubd %mm0,%mm0
psubsw %mm1,%mm0
movd %mm0,%eax
movw %ax,(%edi)
emms
/* NO_APP */
popl %ebx
popl %esi
popl %edi
addl $4,%esp
popl %ebp
ret

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_mono2stereo, 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,285 @@
/*
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"
/* That altivec alignment part here should not hurt generic code, I hope */
#ifdef OPT_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];
#elif defined(REAL_IS_FIXED) && defined(PRECALC_TABLES)
static real cos64[16] =
{
8398725,8480395,8647771,8909416,9279544,9780026,10443886,11321405,
12491246,14081950,16316987,19619946,24900150,34523836,57170182,170959967
};
static real cos32[8] =
{
8429197,8766072,9511743,10851869,13223040,17795219,28897867,85583072
};
static real cos16[4] =
{
8552951,10088893,15099095,42998586
};
static real cos8[2] =
{
9079764,21920489
};
static real cos4[1] =
{
11863283
};
#else
static real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1];
#endif
real *pnts[] = { cos64,cos32,cos16,cos8,cos4 };
static 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 };
void prepare_decode_tables()
{
#if !defined(REAL_IS_FIXED) || !defined(PRECALC_TABLES)
int i,k,kr,divv;
real *costab;
for(i=0;i<5;i++)
{
kr=0x10>>i; divv=0x40>>i;
costab = pnts[i];
for(k=0;k<kr;k++)
costab[k] = DOUBLE_TO_REAL(1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv)));
}
#endif
}
#ifdef OPT_MMXORSSE
#ifndef OPT_X86_64
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
void make_decode_tables(mpg123_handle *fr)
{
int i,j;
int idx = 0;
/* Scale is always based on 1.0 . */
double scaleval = -0.5*(fr->lastscale < 0 ? fr->p.outscale : fr->lastscale);
debug1("decode tables with scaleval %g", scaleval);
#ifdef REAL_IS_FIXED
long scaleval_long = DOUBLE_TO_REAL_15(scaleval);
#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(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(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_ARM)
if(fr->cpu_opts.type == x86_64 || fr->cpu_opts.type == altivec || fr->cpu_opts.type == sse || fr->cpu_opts.type == arm)
{ /* 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];
}
}
#endif
debug("decode tables done");
}
#ifndef NO_8BIT
int make_conv16to8_table(mpg123_handle *fr)
{
int i;
int mode = fr->af.encoding;
/*
* ????: 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;
}
if(fr->af.encoding == 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) && NOQUIET) error2("Converror %d %d",i,c1);
if(c1 == 0)
c1 = 2;
fr->conv16to8[i] = (unsigned char) c1;
}
}
else if(mode == MPG123_ENC_SIGNED_8) {
for(i=-4096;i<4096;i++) {
fr->conv16to8[i] = i>>5;
}
}
else if(mode == MPG123_ENC_UNSIGNED_8) {
for(i=-4096;i<4096;i++) {
fr->conv16to8[i] = (i>>5)+128;
}
}
else {
for(i=-4096;i<4096;i++) {
fr->conv16to8[i] = 0;
}
}
return 0;
}
#endif

View File

@ -0,0 +1,213 @@
/*
tabinit_mmx: make_decode_tables_mmx
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 the mysterious higway (apparently)
*/
#include "mangle.h"
.data
ALIGN32
.globl ASM_NAME(costab_mmxsse)
ASM_NAME(costab_mmxsse):
.long 1056974725
.long 1057056395
.long 1057223771
.long 1057485416
.long 1057855544
.long 1058356026
.long 1059019886
.long 1059897405
.long 1061067246
.long 1062657950
.long 1064892987
.long 1066774581
.long 1069414683
.long 1073984175
.long 1079645762
.long 1092815430
.long 1057005197
.long 1057342072
.long 1058087743
.long 1059427869
.long 1061799040
.long 1065862217
.long 1071413542
.long 1084439708
.long 1057128951
.long 1058664893
.long 1063675095
.long 1076102863
.long 1057655764
.long 1067924853
.long 1060439283
ALIGN32
intwinbase:
.value 0, -1, -1, -1, -1, -1, -1, -2
.value -2, -2, -2, -3, -3, -4, -4, -5
.value -5, -6, -7, -7, -8, -9, -10, -11
.value -13, -14, -16, -17, -19, -21, -24, -26
.value -29, -31, -35, -38, -41, -45, -49, -53
.value -58, -63, -68, -73, -79, -85, -91, -97
.value -104, -111, -117, -125, -132, -139, -147, -154
.value -161, -169, -176, -183, -190, -196, -202, -208
.value -213, -218, -222, -225, -227, -228, -228, -227
.value -224, -221, -215, -208, -200, -189, -177, -163
.value -146, -127, -106, -83, -57, -29, 2, 36
.value 72, 111, 153, 197, 244, 294, 347, 401
.value 459, 519, 581, 645, 711, 779, 848, 919
.value 991, 1064, 1137, 1210, 1283, 1356, 1428, 1498
.value 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962
.value 2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063
.value 2037, 2000, 1952, 1893, 1822, 1739, 1644, 1535
.value 1414, 1280, 1131, 970, 794, 605, 402, 185
.value -45, -288, -545, -814, -1095, -1388, -1692, -2006
.value -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788
.value -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597
.value -7910, -8209, -8491, -8755, -8998, -9219, -9416, -9585
.value -9727, -9838, -9916, -9959, -9966, -9935, -9863, -9750
.value -9592, -9389, -9139, -8840, -8492, -8092, -7640, -7134
.value -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082
.value -70, 998, 2122, 3300, 4533, 5818, 7154, 8540
.value 9975, 11455, 12980, 14548, 16155, 17799, 19478, 21189
.value 22929, 24694, 26482, 28289, 30112, 31947,-26209,-24360
.value -22511,-20664,-18824,-16994,-15179,-13383,-11610, -9863
.value -8147, -6466, -4822, -3222, -1667, -162, 1289, 2684
.value 4019, 5290, 6494, 7629, 8692, 9679, 10590, 11420
.value 12169, 12835, 13415, 13908, 14313, 14630, 14856, 14992
.value 15038
intwindiv:
.long 0x47800000 # 65536.0
.text
ALIGN32
/* void make_decode_tables_mmx_asm(long scaleval, float* decwin_mmx, float *decwins); */
.globl ASM_NAME(make_decode_tables_mmx_asm)
ASM_NAME(make_decode_tables_mmx_asm):
pushl %edi
pushl %esi
pushl %ebx
/* stack: 0=ebx, 4=esi, 8=edi, 12=back, 16=scaleval, 20=decwin_mmx, 24=decwins */
xorl %ecx,%ecx
xorl %ebx,%ebx
movl $32,%esi
movl $intwinbase,%edi
negl 16(%esp) /* scaleval */
pushl $2 /* intwinbase step */
/* stack: 20=scaleval 24=decwin_mmx, 28=decwins */
.L00:
cmpl $528,%ecx
jnc .L02
movswl (%edi),%eax
cmpl $intwinbase+444,%edi
jc .L01
addl $60000,%eax
.L01:
pushl %eax
/* stack: 24=scaleval 28=decwin_mmx, 32=decwins */
fildl (%esp)
fdivs intwindiv
fimull 24(%esp) /* scaleval */
/* eax used to be popped the line before... I'll just use it here a bit */
movl 28(%esp),%eax /* decwin_mmx */
fsts (%eax,%ecx,4)
fstps 64(%eax,%ecx,4)
popl %eax
/* stack: 20=scaleval 24=decwin_mmx, 28=decwins */
.L02:
leal -1(%esi),%edx
and %ebx,%edx
cmp $31,%edx
jnz .L03
addl $-1023,%ecx
test %esi,%ebx
jz .L03
negl 20(%esp)
.L03:
addl %esi,%ecx
addl (%esp),%edi
incl %ebx
cmpl $intwinbase,%edi
jz .L04
cmp $256,%ebx
jnz .L00
negl (%esp)
jmp .L00
.L04:
popl %eax
xorl %ecx,%ecx
xorl %ebx,%ebx
pushl $2 /* paired with popl above */
.L05:
cmpl $528,%ecx
jnc .L11
movswl (%edi),%eax
cmpl $intwinbase+444,%edi
jc .L06
addl $60000,%eax
.L06:
cltd
imull 20(%esp)
shrdl $17,%edx,%eax
cmpl $32767,%eax
movl $1055,%edx
jle .L07
movl $32767,%eax
jmp .L08
.L07:
cmpl $-32767,%eax
jge .L08
movl $-32767,%eax
.L08:
/* going to use ebx for decwins, watch the jumps */
pushl %ebx
/* stack: 24=scaleval 28=decwin_mmx, 32=decwins */
movl 32(%esp),%ebx
cmpl $512,%ecx
jnc .L09
subl %ecx,%edx
movw %ax,(%ebx,%edx,2) /* decwins */
movw %ax,-32(%ebx,%edx,2)
.L09:
testl $1,%ecx
jnz .L10
negl %eax
.L10:
movw %ax,(%ebx,%ecx,2)
movw %ax,32(%ebx,%ecx,2)
popl %ebx /* that has to match the pushl before */
.L11:
leal -1(%esi),%edx
and %ebx,%edx
cmp $31,%edx
jnz .L12
addl $-1023,%ecx
test %esi,%ebx
jz .L12
negl 20(%esp)
.L12:
addl %esi,%ecx
addl (%esp),%edi
incl %ebx
cmpl $intwinbase,%edi
jz .L13
cmp $256,%ebx
jnz .L05
negl (%esp)
jmp .L05
.L13:
popl %eax
popl %ebx
popl %esi
popl %edi
ret
/* Mark non-executable stack. */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif

View File

@ -0,0 +1,14 @@
/*
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 FALSE 0
#define TRUE 1
#endif

View File

@ -7,7 +7,7 @@ CPP=gcc -E
CFLAGS= -O3 -c -fomit-frame-pointer
LDIMPORT:= -nostdlib --out-implib libzimp.a
LDIMPORT:= -nostdlib
LDFLAGS:= -shared -s -T ../newlib/dll.lds -Map map --image-base 0
@ -36,7 +36,8 @@ libz.a: $(OBJS)
$(AR) $@ $(OBJS)
libz.dll: $(OBJECTS) Makefile
ld $(LDFLAGS) $(LDIMPORT) $(LIBPATH) -o $@ $(OBJS) $(LIBS)
dlltool -d zlib.def -Dlibz.dll -e exports.o -l libzimp.a
ld $(LDFLAGS) $(LDIMPORT) --exclude-all-symbols $(LIBPATH) -o $@ $(OBJS) exports.o $(LIBS)
%.o: %.c Makefile

View File

@ -0,0 +1,74 @@
LIBRARY zlib.dll
; zlib data compression library
EXPORTS
; basic functions
zlibVersion
deflate
deflateEnd
inflate
inflateEnd
; advanced functions
deflateSetDictionary
deflateCopy
deflateReset
deflateParams
deflateTune
deflateBound
deflatePrime
deflateSetHeader
inflateSetDictionary
inflateSync
inflateCopy
inflateReset
inflateReset2
inflatePrime
inflateMark
inflateGetHeader
inflateBack
inflateBackEnd
zlibCompileFlags
; utility functions
compress
compress2
compressBound
uncompress
gzopen
gzdopen
gzbuffer
gzsetparams
gzread
gzwrite
gzprintf
gzputs
gzgets
gzputc
gzgetc
gzungetc
gzflush
gzseek
gzrewind
gztell
gzoffset
gzeof
gzdirect
gzclose
gzclose_r
gzclose_w
gzerror
gzclearerr
; checksum functions
adler32
crc32
adler32_combine
crc32_combine
; various hacks, don't look :)
deflateInit_
deflateInit2_
inflateInit_
inflateInit2_
inflateBackInit_
zError
inflateSyncPoint
get_crc_table
inflateUndermine