Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 1903 → Rev 1905

/programs/develop/libraries/cairo/Makefile
3,7 → 3,7
 
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
 
/programs/develop/libraries/libmpg123/Makefile
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 $@ $<
/programs/develop/libraries/libmpg123/chkstk.S
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
 
 
/programs/develop/libraries/libmpg123/compat.c
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
/programs/develop/libraries/libmpg123/compat.h
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
/programs/develop/libraries/libmpg123/config.h
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 */
/programs/develop/libraries/libmpg123/dct64.c
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]);
 
}
 
 
/programs/develop/libraries/libmpg123/dct64_i386.c
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);
}
 
/programs/develop/libraries/libmpg123/dct64_mmx.S
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
 
/programs/develop/libraries/libmpg123/debug.h
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
/programs/develop/libraries/libmpg123/decode.h
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
/programs/develop/libraries/libmpg123/dither.h
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
/programs/develop/libraries/libmpg123/equalizer.c
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]);
}
/programs/develop/libraries/libmpg123/format.c
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;
}
/programs/develop/libraries/libmpg123/frame.c
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;
}
 
/programs/develop/libraries/libmpg123/frame.h
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
/programs/develop/libraries/libmpg123/getbits.h
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
/programs/develop/libraries/libmpg123/getcpuflags.S
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
/programs/develop/libraries/libmpg123/getcpuflags.h
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
/programs/develop/libraries/libmpg123/huffman.h
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
/programs/develop/libraries/libmpg123/icy.c
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;
}*/
/programs/develop/libraries/libmpg123/icy.h
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
/programs/develop/libraries/libmpg123/icy2utf8.h
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
/programs/develop/libraries/libmpg123/id3.c
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
/programs/develop/libraries/libmpg123/id3.h
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
/programs/develop/libraries/libmpg123/index.c
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);
}
/programs/develop/libraries/libmpg123/index.h
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
/programs/develop/libraries/libmpg123/l12_integer_tables.h
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
/programs/develop/libraries/libmpg123/l2tables.h
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
 
/programs/develop/libraries/libmpg123/l3_integer_tables.h
0,0 → 1,1002
/*
l3_integer_tables.h: Layer3 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_L3_INTEGER_TABLES_H
#define MPG123_L3_INTEGER_TABLES_H
 
#ifdef PRECALC_TABLES
static const real ispow[8207] =
{
0,8192,20643,35445,52016,70041,89315,109695,131072,153360,
176491,200407,225060,250408,276414,303048,330281,358087,386444,415331,
444730,474623,504995,535830,567116,598839,630988,663552,696521,729884,
763633,797760,832255,867112,902323,937880,973778,1010010,1046569,1083451,
1120650,1158160,1195976,1234093,1272507,1311213,1350207,1389485,1429042,1468875,
1508979,1549352,1589990,1630889,1672046,1713458,1755122,1797035,1839193,1881594,
1924236,1967115,2010229,2053576,2097152,2140956,2184985,2229238,2273710,2318402,
2363310,2408432,2453767,2499312,2545065,2591025,2637190,2683558,2730126,2776895,
2823861,2871023,2918379,2965929,3013670,3061600,3109719,3158025,3206517,3255192,
3304050,3353089,3402309,3451707,3501282,3551033,3600960,3651060,3701332,3751776,
3802390,3853172,3904123,3955241,4006524,4057972,4109583,4161357,4213293,4265389,
4317644,4370058,4422630,4475359,4528243,4581282,4634476,4687822,4741320,4794970,
4848770,4902720,4956819,5011066,5065460,5120000,5174686,5229517,5284492,5339610,
5394871,5450274,5505818,5561502,5617327,5673290,5729391,5785631,5842007,5898519,
5955168,6011951,6068869,6125920,6183105,6240422,6297871,6355451,6413162,6471004,
6528974,6587074,6645302,6703658,6762141,6820751,6879487,6938349,6997336,7056447,
7115683,7175042,7234524,7294129,7353855,7413703,7473672,7533762,7593972,7654301,
7714750,7775317,7836002,7896805,7957725,8018762,8079916,8141185,8202570,8264070,
8325685,8387413,8449256,8511212,8573281,8635462,8697756,8760161,8822678,8885305,
8948043,9010892,9073850,9136917,9200094,9263379,9326772,9390274,9453882,9517598,
9581421,9645351,9709386,9773527,9837774,9902125,9966582,10031143,10095807,10160576,
10225448,10290423,10355500,10420681,10485963,10551347,10616832,10682419,10748106,10813894,
10879782,10945770,11011857,11078044,11144330,11210715,11277198,11343779,11410458,11477234,
11544108,11611079,11678147,11745311,11812571,11879927,11947378,12014925,12082567,12150304,
12218135,12286061,12354081,12422194,12490401,12558701,12627094,12695580,12764158,12832829,
12901592,12970446,13039392,13108429,13177557,13246776,13316085,13385485,13454975,13524554,
13594224,13663982,13733830,13803767,13873792,13943906,14014108,14084398,14154776,14225242,
14295794,14366435,14437162,14507975,14578876,14649862,14720935,14792093,14863337,14934667,
15006082,15077582,15149167,15220837,15292591,15364429,15436351,15508358,15580448,15652621,
15724878,15797217,15869640,15942146,16014734,16087404,16160156,16232991,16305907,16378905,
16451984,16525145,16598386,16671709,16745112,16818596,16892160,16965804,17039528,17113332,
17187216,17261179,17335222,17409343,17483544,17557824,17632182,17706618,17781133,17855726,
17930397,18005146,18079973,18154877,18229858,18304917,18380052,18455265,18530554,18605920,
18681362,18756880,18832475,18908145,18983891,19059713,19135610,19211583,19287630,19363753,
19439951,19516223,19592571,19668992,19745488,19822058,19898702,19975420,20052211,20129076,
20206015,20283027,20360112,20437270,20514501,20591805,20669181,20746630,20824151,20901745,
20979410,21057148,21134957,21212838,21290791,21368815,21446910,21525076,21603314,21681622,
21760001,21838451,21916971,21995561,22074222,22152953,22231754,22310625,22389566,22468576,
22547656,22626806,22706024,22785312,22864669,22944094,23023589,23103152,23182783,23262484,
23342252,23422089,23501993,23581966,23662007,23742115,23822291,23902534,23982845,24063223,
24143669,24224181,24304761,24385407,24466120,24546899,24627745,24708658,24789637,24870682,
24951793,25032970,25114213,25195521,25276895,25358335,25439841,25521411,25603047,25684748,
25766514,25848345,25930241,26012201,26094226,26176316,26258469,26340688,26422970,26505317,
26587727,26670202,26752740,26835342,26918008,27000737,27083530,27166386,27249305,27332287,
27415332,27498440,27581611,27664845,27748142,27831501,27914922,27998406,28081952,28165561,
28249231,28332963,28416758,28500614,28584532,28668511,28752552,28836655,28920819,29005044,
29089330,29173677,29258086,29342555,29427085,29511676,29596328,29681040,29765813,29850646,
29935539,30020493,30105507,30190581,30275714,30360908,30446162,30531475,30616848,30702280,
30787772,30873323,30958934,31044604,31130332,31216120,31301967,31387873,31473838,31559862,
31645944,31732084,31818284,31904541,31990857,32077231,32163664,32250154,32336703,32423309,
32509974,32596696,32683476,32770313,32857208,32944161,33031171,33118238,33205363,33292544,
33379783,33467079,33554432,33641842,33729308,33816832,33904412,33992048,34079741,34167491,
34255297,34343159,34431078,34519052,34607083,34695170,34783312,34871511,34959765,35048075,
35136441,35224862,35313339,35401872,35490459,35579102,35667801,35756554,35845363,35934226,
36023145,36112118,36201147,36290230,36379367,36468560,36557807,36647108,36736464,36825875,
36915339,37004858,37094431,37184058,37273739,37363474,37453263,37543106,37633003,37722953,
37812957,37903015,37993126,38083291,38173509,38263780,38354105,38444483,38534914,38625398,
38715935,38806525,38897168,38987864,39078612,39169414,39260268,39351174,39442133,39533145,
39624209,39715325,39806494,39897714,39988987,40080312,40171690,40263119,40354600,40446133,
40537718,40629354,40721042,40812782,40904574,40996417,41088311,41180257,41272254,41364303,
41456402,41548553,41640755,41733008,41825313,41917668,42010074,42102530,42195038,42287596,
42380205,42472865,42565575,42658336,42751147,42844009,42936921,43029883,43122895,43215958,
43309070,43402233,43495446,43588709,43682022,43775384,43868797,43962259,44055771,44149332,
44242943,44336604,44430314,44524073,44617882,44711741,44805648,44899605,44993611,45087666,
45181770,45275923,45370126,45464377,45558677,45653025,45747423,45841869,45936364,46030908,
46125500,46220141,46314830,46409567,46504353,46599187,46694070,46789001,46883980,46979007,
47074082,47169205,47264376,47359595,47454862,47550177,47645540,47740950,47836408,47931914,
48027467,48123068,48218716,48314412,48410155,48505945,48601783,48697668,48793601,48889580,
48985607,49081681,49177802,49273969,49370184,49466446,49562754,49659109,49755511,49851960,
49948456,50044998,50141586,50238222,50334903,50431631,50528406,50625227,50722094,50819007,
50915967,51012973,51110025,51207123,51304267,51401457,51498694,51595976,51693304,51790677,
51888097,51985562,52083073,52180630,52278232,52375880,52473573,52571312,52669097,52766926,
52864801,52962722,53060688,53158699,53256755,53354856,53453002,53551194,53649430,53747712,
53846038,53944410,54042826,54141287,54239793,54338344,54436939,54535579,54634263,54732993,
54831766,54930585,55029447,55128354,55227306,55326302,55425342,55524426,55623555,55722728,
55821945,55921206,56020511,56119860,56219253,56318690,56418171,56517696,56617265,56716877,
56816534,56916234,57015977,57115764,57215595,57315470,57415388,57515349,57615354,57715403,
57815494,57915629,58015808,58116029,58216294,58316602,58416954,58517348,58617785,58718266,
58818789,58919356,59019965,59120617,59221312,59322050,59422831,59523654,59624521,59725429,
59826381,59927375,60028412,60129491,60230613,60331777,60432983,60534232,60635524,60736857,
60838233,60939651,61041112,61142614,61244159,61345746,61447375,61549046,61650759,61752513,
61854310,61956149,62058030,62159952,62261916,62363922,62465970,62568059,62670191,62772363,
62874578,62976833,63079131,63181470,63283850,63386272,63488735,63591239,63693785,63796372,
63899001,64001670,64104381,64207133,64309926,64412760,64515636,64618552,64721509,64824507,
64927546,65030627,65133747,65236909,65340112,65443355,65546639,65649964,65753329,65856735,
65960182,66063669,66167197,66270765,66374374,66478023,66581713,66685443,66789213,66893024,
66996875,67100766,67204698,67308669,67412681,67516733,67620825,67724957,67829130,67933342,
68037594,68141886,68246218,68350590,68455002,68559454,68663945,68768476,68873047,68977658,
69082308,69186998,69291728,69396497,69501306,69606154,69711042,69815969,69920936,70025942,
70130987,70236072,70341196,70446360,70551562,70656804,70762085,70867406,70972765,71078164,
71183601,71289078,71394594,71500149,71605742,71711375,71817046,71922757,72028506,72134294,
72240121,72345987,72451891,72557835,72663817,72769837,72875896,72981994,73088130,73194305,
73300519,73406770,73513061,73619389,73725757,73832162,73938606,74045088,74151609,74258168,
74364765,74471400,74578073,74684785,74791535,74898323,75005149,75112012,75218914,75325854,
75432832,75539848,75646902,75753994,75861123,75968291,76075496,76182739,76290020,76397338,
76504694,76612088,76719520,76826989,76934495,77042040,77149622,77257241,77364898,77472592,
77580324,77688093,77795899,77903743,78011625,78119543,78227499,78335492,78443522,78551590,
78659695,78767836,78876015,78984232,79092485,79200775,79309102,79417467,79525868,79634306,
79742781,79851293,79959842,80068428,80177050,80285710,80394406,80503139,80611908,80720715,
80829558,80938438,81047354,81156307,81265296,81374322,81483385,81592484,81701620,81810792,
81920000,82029245,82138526,82247844,82357198,82466588,82576014,82685477,82794976,82904512,
83014083,83123691,83233334,83343014,83452730,83562482,83672271,83782095,83891955,84001851,
84111783,84221751,84331755,84441795,84551870,84661982,84772129,84882312,84992531,85102786,
85213076,85323402,85433764,85544161,85654594,85765063,85875567,85986107,86096682,86207293,
86317939,86428621,86539338,86650091,86760879,86871702,86982561,87093455,87204384,87315349,
87426349,87537384,87648455,87759560,87870701,87981877,88093088,88204334,88315616,88426932,
88538283,88649670,88761091,88872548,88984039,89095565,89207126,89318723,89430353,89542019,
89653720,89765455,89877226,89989030,90100870,90212745,90324654,90436598,90548576,90660589,
90772637,90884719,90996836,91108987,91221173,91333394,91445648,91557938,91670262,91782620,
91895012,92007439,92119901,92232396,92344926,92457491,92570089,92682722,92795389,92908090,
93020826,93133595,93246399,93359237,93472109,93585015,93697955,93810929,93923937,94036980,
94150056,94263166,94376310,94489488,94602700,94715946,94829225,94942539,95055886,95169267,
95282682,95396131,95509613,95623129,95736679,95850263,95963880,96077530,96191215,96304933,
96418684,96532470,96646288,96760140,96874026,96987945,97101898,97215884,97329904,97443956,
97558043,97672162,97786315,97900502,98014721,98128974,98243260,98357580,98471933,98586318,
98700737,98815190,98929675,99044194,99158745,99273330,99387948,99502598,99617282,99731999,
99846749,99961532,100076348,100191197,100306078,100420993,100535940,100650921,100765934,100880980,
100996059,101111170,101226315,101341492,101456702,101571944,101687220,101802528,101917868,102033241,
102148647,102264086,102379557,102495061,102610597,102726166,102841767,102957401,103073067,103188765,
103304497,103420260,103536056,103651884,103767745,103883638,103999563,104115521,104231511,104347533,
104463588,104579675,104695794,104811945,104928128,105044344,105160592,105276871,105393183,105509527,
105625904,105742312,105858752,105975224,106091729,106208265,106324833,106441433,106558066,106674730,
106791426,106908154,107024913,107141705,107258528,107375384,107492271,107609190,107726140,107843123,
107960137,108077182,108194260,108311369,108428510,108545683,108662887,108780122,108897390,109014689,
109132019,109249381,109366775,109484200,109601656,109719144,109836664,109954215,110071797,110189411,
110307056,110424733,110542441,110660180,110777950,110895752,111013585,111131450,111249346,111367273,
111485231,111603220,111721241,111839292,111957375,112075489,112193635,112311811,112430018,112548257,
112666526,112784827,112903159,113021521,113139915,113258339,113376795,113495282,113613799,113732347,
113850927,113969537,114088178,114206850,114325552,114444286,114563050,114681845,114800671,114919528,
115038415,115157333,115276282,115395262,115514272,115633313,115752384,115871486,115990619,116109783,
116228976,116348201,116467456,116586742,116706058,116825404,116944781,117064189,117183627,117303095,
117422594,117542124,117661683,117781273,117900894,118020545,118140226,118259937,118379679,118499451,
118619253,118739086,118858948,118978842,119098765,119218718,119338702,119458716,119578759,119698834,
119818938,119939072,120059236,120179431,120299655,120419910,120540194,120660509,120780854,120901228,
121021633,121142067,121262532,121383026,121503550,121624105,121744689,121865303,121985946,122106620,
122227323,122348057,122468820,122589613,122710435,122831287,122952170,123073081,123194023,123314994,
123435995,123557025,123678085,123799175,123920295,124041444,124162622,124283830,124405068,124526335,
124647632,124768959,124890314,125011700,125133114,125254559,125376032,125497536,125619068,125740630,
125862221,125983842,126105492,126227171,126348880,126470618,126592386,126714182,126836008,126957863,
127079748,127201661,127323604,127445576,127567578,127689608,127811668,127933756,128055874,128178021,
128300197,128422403,128544637,128666900,128789193,128911514,129033865,129156244,129278652,129401090,
129523556,129646052,129768576,129891129,130013711,130136323,130258963,130381631,130504329,130627056,
130749811,130872595,130995408,131118250,131241120,131364020,131486948,131609905,131732890,131855904,
131978947,132102019,132225119,132348248,132471406,132594592,132717807,132841050,132964323,133087623,
133210952,133334310,133457696,133581111,133704554,133828026,133951527,134075055,134198613,134322198,
134445812,134569455,134693126,134816825,134940553,135064309,135188094,135311906,135435747,135559617,
135683515,135807441,135931395,136055378,136179388,136303427,136427495,136551590,136675714,136799866,
136924046,137048254,137172490,137296755,137421048,137545368,137669717,137794094,137918499,138042932,
138167393,138291882,138416400,138540945,138665518,138790119,138914748,139039405,139164090,139288803,
139413544,139538313,139663110,139787934,139912787,140037667,140162575,140287511,140412475,140537467,
140662486,140787533,140912608,141037711,141162842,141288000,141413186,141538399,141663641,141788910,
141914207,142039531,142164883,142290263,142415670,142541105,142666567,142792057,142917575,143043120,
143168693,143294294,143419921,143545577,143671260,143796970,143922708,144048473,144174266,144300086,
144425934,144551809,144677712,144803641,144929599,145055583,145181595,145307635,145433701,145559795,
145685917,145812065,145938241,146064445,146190675,146316933,146443218,146569530,146695869,146822236,
146948630,147075051,147201499,147327974,147454477,147581007,147707563,147834147,147960758,148087396,
148214061,148340754,148467473,148594219,148720993,148847793,148974620,149101475,149228356,149355264,
149482200,149609162,149736151,149863167,149990210,150117280,150244377,150371501,150498652,150625829,
150753033,150880265,151007523,151134807,151262119,151389457,151516823,151644215,151771633,151899079,
152026551,152154050,152281576,152409128,152536707,152664313,152791945,152919604,153047290,153175002,
153302741,153430507,153558299,153686118,153813963,153941835,154069734,154197659,154325610,154453588,
154581593,154709624,154837682,154965766,155093876,155222013,155350177,155478367,155606583,155734826,
155863095,155991391,156119713,156248061,156376436,156504837,156633264,156761718,156890198,157018704,
157147237,157275796,157404381,157532993,157661630,157790294,157918985,158047701,158176444,158305212,
158434008,158562829,158691676,158820550,158949449,159078375,159207327,159336305,159465310,159594340,
159723396,159852479,159981587,160110722,160239882,160369069,160498282,160627520,160756785,160886076,
161015392,161144735,161274103,161403498,161532918,161662365,161791837,161921335,162050859,162180409,
162309985,162439587,162569215,162698868,162828547,162958252,163087983,163217740,163347523,163477331,
163607165,163737025,163866910,163996822,164126759,164256722,164386710,164516724,164646764,164776830,
164906921,165037038,165167181,165297349,165427543,165557762,165688007,165818278,165948574,166078896,
166209243,166339616,166470015,166600439,166730888,166861363,166991864,167122390,167252942,167383519,
167514122,167644750,167775403,167906082,168036786,168167516,168298271,168429052,168559858,168690689,
168821546,168952428,169083335,169214268,169345226,169476210,169607219,169738253,169869312,170000397,
170131507,170262642,170393802,170524988,170656199,170787435,170918696,171049983,171181295,171312632,
171443994,171575381,171706793,171838231,171969694,172101182,172232695,172364233,172495796,172627384,
172758997,172890636,173022299,173153988,173285702,173417440,173549204,173680993,173812806,173944645,
174076509,174208397,174340311,174472249,174604213,174736201,174868215,175000253,175132316,175264404,
175396517,175528655,175660818,175793005,175925218,176057455,176189717,176322004,176454316,176586653,
176719014,176851400,176983811,177116247,177248708,177381193,177513703,177646237,177778797,177911381,
178043990,178176624,178309282,178441965,178574672,178707405,178840162,178972943,179105749,179238580,
179371435,179504316,179637220,179770149,179903103,180036082,180169084,180302112,180435164,180568240,
180701342,180834467,180967617,181100792,181233991,181367214,181500462,181633735,181767032,181900353,
182033699,182167069,182300464,182433883,182567326,182700794,182834286,182967803,183101344,183234909,
183368499,183502113,183635751,183769414,183903101,184036812,184170548,184304307,184438092,184571900,
184705732,184839589,184973470,185107376,185241305,185375259,185509237,185643239,185777266,185911316,
186045391,186179490,186313613,186447760,186581931,186716126,186850346,186984590,187118857,187253149,
187387465,187521805,187656169,187790557,187924969,188059405,188193866,188328350,188462858,188597390,
188731946,188866527,189001131,189135759,189270411,189405087,189539787,189674511,189809259,189944031,
190078827,190213646,190348490,190483357,190618249,190753164,190888103,191023066,191158052,191293063,
191428097,191563155,191698237,191833343,191968473,192103626,192238803,192374004,192509229,192644477,
192779749,192915045,193050365,193185708,193321075,193456466,193591881,193727319,193862781,193998266,
194133775,194269308,194404864,194540444,194676048,194811675,194947326,195083001,195218699,195354421,
195490166,195625935,195761727,195897543,196033383,196169246,196305132,196441042,196576976,196712933,
196848914,196984918,197120945,197256996,197393071,197529169,197665290,197801435,197937603,198073795,
198210010,198346249,198482510,198618796,198755104,198891437,199027792,199164171,199300573,199436998,
199573447,199709919,199846415,199982934,200119476,200256041,200392630,200529242,200665877,200802535,
200939217,201075922,201212650,201349402,201486176,201622974,201759795,201896639,202033507,202170398,
202307311,202444248,202581209,202718192,202855198,202992228,203129281,203266357,203403456,203540578,
203677723,203814891,203952082,204089297,204226534,204363795,204501078,204638385,204775715,204913067,
205050443,205187842,205325264,205462708,205600176,205737667,205875180,206012717,206150277,206287859,
206425465,206563093,206700745,206838419,206976116,207113836,207251579,207389345,207527134,207664946,
207802780,207940638,208078518,208216421,208354347,208492295,208630267,208768261,208906279,209044319,
209182381,209320467,209458575,209596706,209734860,209873037,210011236,210149458,210287703,210425971,
210564261,210702574,210840910,210979268,211117649,211256053,211394480,211532929,211671400,211809895,
211948412,212086952,212225514,212364099,212502706,212641337,212779989,212918665,213057363,213196083,
213334826,213473592,213612380,213751191,213890024,214028880,214167758,214306659,214445582,214584528,
214723497,214862488,215001501,215140537,215279595,215418676,215557779,215696904,215836053,215975223,
216114416,216253631,216392869,216532129,216671412,216810717,216950044,217089394,217228766,217368160,
217507577,217647016,217786477,217925961,218065467,218204996,218344546,218484119,218623715,218763332,
218902972,219042634,219182319,219322026,219461754,219601506,219741279,219881075,220020893,220160733,
220300595,220440479,220580386,220720315,220860266,221000239,221140235,221280252,221420292,221560354,
221700438,221840544,221980672,222120823,222260995,222401190,222541406,222681645,222821906,222962189,
223102494,223242821,223383170,223523541,223663934,223804350,223944787,224085246,224225728,224366231,
224506756,224647303,224787873,224928464,225069077,225209712,225350370,225491049,225631750,225772473,
225913218,226053985,226194773,226335584,226476417,226617271,226758148,226899046,227039966,227180908,
227321872,227462858,227603865,227744895,227885946,228027019,228168114,228309231,228450369,228591529,
228732712,228873916,229015141,229156389,229297658,229438949,229580262,229721596,229862953,230004331,
230145730,230287152,230428595,230570060,230711546,230853055,230994585,231136136,231277709,231419304,
231560921,231702559,231844219,231985901,232127604,232269329,232411076,232552844,232694633,232836445,
232978278,233120132,233262008,233403906,233545825,233687766,233829728,233971712,234113717,234255744,
234397793,234539863,234681954,234824068,234966202,235108358,235250536,235392735,235534955,235677197,
235819461,235961746,236104052,236246380,236388729,236531100,236673492,236815905,236958340,237100797,
237243274,237385774,237528294,237670836,237813399,237955984,238098590,238241217,238383866,238526536,
238669228,238811940,238954674,239097430,239240207,239383005,239525824,239668664,239811526,239954409,
240097314,240240240,240383187,240526155,240669144,240812155,240955187,241098240,241241314,241384410,
241527527,241670665,241813824,241957005,242100206,242243429,242386673,242529938,242673224,242816532,
242959860,243103210,243246581,243389973,243533386,243676820,243820276,243963752,244107249,244250768,
244394308,244537869,244681450,244825053,244968677,245112322,245255989,245399676,245543384,245687113,
245830863,245974635,246118427,246262240,246406074,246549930,246693806,246837703,246981621,247125560,
247269521,247413502,247557504,247701527,247845571,247989635,248133721,248277828,248421956,248566104,
248710273,248854464,248998675,249142907,249287160,249431434,249575729,249720044,249864381,250008738,
250153116,250297515,250441935,250586375,250730837,250875319,251019822,251164346,251308890,251453456,
251598042,251742649,251887277,252031925,252176594,252321284,252465995,252610727,252755479,252900252,
253045045,253189860,253334695,253479551,253624427,253769324,253914242,254059181,254204140,254349120,
254494121,254639142,254784184,254929246,255074329,255219433,255364558,255509703,255654868,255800054,
255945261,256090489,256235737,256381006,256526295,256671605,256816935,256962286,257107657,257253049,
257398462,257543895,257689349,257834823,257980318,258125833,258271369,258416925,258562502,258708099,
258853717,258999355,259145014,259290693,259436392,259582112,259727853,259873614,260019395,260165197,
260311019,260456862,260602725,260748609,260894513,261040437,261186382,261332347,261478333,261624339,
261770365,261916411,262062478,262208566,262354674,262500802,262646950,262793119,262939308,263085517,
263231747,263377997,263524267,263670558,263816869,263963200,264109551,264255923,264402315,264548728,
264695160,264841613,264988086,265134579,265281093,265427627,265574181,265720755,265867349,266013964,
266160599,266307254,266453929,266600625,266747340,266894076,267040832,267187608,267334404,267481221,
267628057,267774914,267921791,268068688,268215605,268362542,268509500,268656477,268803475,268950493,
269097530,269244588,269391666,269538764,269685882,269833021,269980179,270127357,270274555,270421774,
270569012,270716271,270863549,271010848,271158166,271305505,271452863,271600242,271747640,271895059,
272042497,272189956,272337434,272484933,272632451,272779990,272927548,273075126,273222724,273370342,
273517981,273665639,273813316,273961014,274108732,274256470,274404227,274552005,274699802,274847619,
274995456,275143313,275291190,275439087,275587003,275734940,275882896,276030872,276178868,276326884,
276474919,276622975,276771050,276919145,277067260,277215394,277363549,277511723,277659917,277808130,
277956364,278104617,278252890,278401183,278549496,278697828,278846180,278994552,279142943,279291354,
279439785,279588236,279736706,279885196,280033706,280182236,280330785,280479353,280627942,280776550,
280925178,281073825,281222493,281371179,281519886,281668612,281817358,281966123,282114908,282263713,
282412537,282561381,282710244,282859127,283008030,283156952,283305894,283454855,283603836,283752836,
283901856,284050896,284199955,284349034,284498132,284647250,284796387,284945544,285094721,285243917,
285393132,285542367,285691621,285840895,285990189,286139502,286288834,286438186,286587557,286736948,
286886358,287035788,287185237,287334706,287484194,287633701,287783228,287932774,288082340,288231925,
288381530,288531154,288680797,288830460,288980142,289129844,289279565,289429305,289579065,289728844,
289878642,290028460,290178297,290328153,290478029,290627924,290777839,290927773,291077726,291227698,
291377690,291527701,291677731,291827781,291977850,292127938,292278045,292428172,292578318,292728484,
292878668,293028872,293179095,293329337,293479599,293629880,293780180,293930499,294080837,294231195,
294381572,294531968,294682383,294832818,294983272,295133744,295284237,295434748,295585278,295735828,
295886396,296036984,296187591,296338218,296488863,296639527,296790211,296940914,297091636,297242377,
297393137,297543916,297694714,297845532,297996368,298147224,298298098,298448992,298599905,298750837,
298901788,299052758,299203747,299354755,299505782,299656829,299807894,299958978,300110081,300261204,
300412345,300563505,300714685,300865883,301017101,301168337,301319592,301470867,301622160,301773472,
301924804,302076154,302227523,302378911,302530318,302681744,302833189,302984653,303136136,303287638,
303439159,303590698,303742257,303893834,304045431,304197046,304348680,304500333,304652005,304803696,
304955405,305107134,305258881,305410648,305562433,305714237,305866060,306017901,306169762,306321641,
306473539,306625456,306777392,306929347,307081320,307233312,307385323,307537353,307689402,307841469,
307993555,308145660,308297784,308449927,308602088,308754268,308906467,309058684,309210921,309363176,
309515449,309667742,309820053,309972383,310124732,310277099,310429485,310581890,310734313,310886755,
311039216,311191696,311344194,311496711,311649247,311801801,311954374,312106965,312259575,312412204,
312564852,312717518,312870203,313022906,313175628,313328369,313481128,313633906,313786703,313939518,
314092351,314245204,314398074,314550964,314703872,314856799,315009744,315162708,315315690,315468691,
315621710,315774748,315927805,316080880,316233973,316387086,316540216,316693365,316846533,316999719,
317152924,317306147,317459389,317612649,317765928,317919225,318072541,318225875,318379228,318532599,
318685988,318839396,318992823,319146268,319299731,319453213,319606713,319760232,319913769,320067324,
320220898,320374491,320528101,320681731,320835378,320989044,321142729,321296431,321450153,321603892,
321757650,321911426,322065221,322219034,322372865,322526715,322680583,322834470,322988374,323142297,
323296239,323450199,323604177,323758173,323912188,324066221,324220272,324374342,324528430,324682536,
324836660,324990803,325144964,325299144,325453341,325607557,325761791,325916044,326070314,326224603,
326378910,326533236,326687579,326841941,326996321,327150720,327305136,327459571,327614024,327768495,
327922984,328077492,328232018,328386562,328541124,328695704,328850302,329004919,329159554,329314207,
329468878,329623567,329778275,329933000,330087744,330242506,330397286,330552084,330706900,330861735,
331016587,331171458,331326347,331481254,331636178,331791121,331946083,332101062,332256059,332411074,
332566108,332721159,332876229,333031317,333186422,333341546,333496688,333651848,333807026,333962221,
334117435,334272667,334427917,334583185,334738471,334893776,335049098,335204438,335359796,335515172,
335670566,335825978,335981408,336136856,336292322,336447806,336603308,336758828,336914365,337069921,
337225495,337381087,337536696,337692324,337847969,338003633,338159314,338315013,338470730,338626465,
338782218,338937989,339093778,339249585,339405409,339561252,339717112,339872990,340028886,340184800,
340340732,340496682,340652650,340808635,340964638,341120659,341276698,341432755,341588830,341744922,
341901032,342057161,342213306,342369470,342525652,342681851,342838068,342994303,343150556,343306826,
343463115,343619421,343775745,343932086,344088446,344244823,344401218,344557631,344714061,344870509,
345026975,345183459,345339960,345496480,345653016,345809571,345966143,346122733,346279341,346435967,
346592610,346749271,346905949,347062646,347219359,347376091,347532840,347689607,347846392,348003194,
348160014,348316852,348473707,348630580,348787471,348944379,349101305,349258249,349415210,349572189,
349729185,349886199,350043231,350200280,350357347,350514432,350671534,350828653,350985791,351142946,
351300118,351457308,351614516,351771741,351928984,352086244,352243522,352400817,352558130,352715461,
352872809,353030175,353187558,353344959,353502377,353659813,353817266,353974737,354132225,354289731,
354447254,354604795,354762354,354919929,355077523,355235134,355392762,355550408,355708071,355865752,
356023450,356181166,356338899,356496649,356654418,356812203,356970006,357127826,357285664,357443520,
357601392,357759282,357917190,358075115,358233057,358391017,358548994,358706989,358865001,359023030,
359181077,359339141,359497223,359655322,359813438,359971572,360129723,360287891,360446077,360604280,
360762501,360920738,361078994,361237266,361395556,361553863,361712188,361870530,362028889,362187265,
362345659,362504070,362662499,362820944,362979407,363137888,363296385,363454900,363613432,363771982,
363930549,364089133,364247734,364406353,364564988,364723642,364882312,365041000,365199704,365358426,
365517166,365675922,365834696,365993487,366152296,366311121,366469964,366628824,366787701,366946595,
367105507,367264435,367423381,367582344,367741325,367900322,368059337,368218369,368377418,368536484,
368695567,368854668,369013785,369172920,369332072,369491241,369650428,369809631,369968852,370128089,
370287344,370446616,370605905,370765211,370924535,371083875,371243232,371402607,371561999,371721408,
371880833,372040276,372199737,372359214,372518708,372678219,372837748,372997293,373156856,373316435,
373476032,373635645,373795276,373954924,374114589,374274270,374433969,374593685,374753418,374913168,
375072935,375232719,375392520,375552338,375712173,375872025,376031894,376191780,376351683,376511603,
376671540,376831494,376991465,377151453,377311458,377471479,377631518,377791574,377951647,378111736,
378271843,378431966,378592107,378752264,378912439,379072630,379232838,379393063,379553305,379713564,
379873840,380034133,380194443,380354769,380515113,380675473,380835850,380996244,381156655,381317083,
381477528,381637990,381798468,381958964,382119476,382280005,382440551,382601114,382761694,382922290,
383082903,383243534,383404181,383564844,383725525,383886223,384046937,384207668,384368416,384529181,
384689962,384850761,385011576,385172408,385333256,385494122,385655004,385815903,385976819,386137752,
386298701,386459667,386620650,386781650,386942667,387103700,387264750,387425816,387586900,387748000,
387909117,388070251,388231401,388392568,388553752,388714952,388876170,389037404,389198654,389359922,
389521206,389682507,389843824,390005158,390166509,390327877,390489261,390650662,390812079,390973513,
391134964,391296432,391457916,391619417,391780934,391942469,392104019,392265587,392427171,392588772,
392750389,392912023,393073674,393235341,393397025,393558725,393720442,393882176,394043926,394205693,
394367477,394529277,394691093,394852927,395014776,395176643,395338526,395500425,395662342,395824274,
395986224,396148189,396310172,396472171,396634186,396796218,396958267,397120332,397282414,397444512,
397606627,397768758,397930906,398093070,398255251,398417448,398579662,398741892,398904139,399066402,
399228682,399390979,399553291,399715621,399877966,400040329,400202707,400365103,400527514,400689943,
400852387,401014848,401177326,401339820,401502330,401664857,401827400,401989960,402152536,402315129,
402477738,402640363,402803005,402965664,403128338,403291030,403453737,403616461,403779201,403941958,
404104731,404267521,404430327,404593149,404755988,404918843,405081715,405244602,405407507,405570427,
405733364,405896317,406059287,406222273,406385275,406548294,406711329,406874381,407037448,407200532,
407363633,407526750,407689883,407853032,408016198,408179380,408342578,408505793,408669024,408832271,
408995534,409158814,409322110,409485423,409648751,409812096,409975457,410138835,410302229,410465639,
410629065,410792508,410955967,411119442,411282933,411446441,411609964,411773505,411937061,412100633,
412264222,412427827,412591449,412755086,412918740,413082410,413246096,413409798,413573517,413737251,
413901002,414064769,414228553,414392352,414556168,414720000,414883848,415047712,415211593,415375489,
415539402,415703331,415867276,416031238,416195215,416359209,416523218,416687244,416851286,417015344,
417179419,417343509,417507616,417671738,417835877,418000032,418164203,418328390,418492594,418656813,
418821048,418985300,419149568,419313852,419478151,419642467,419806800,419971148,420135512,420299892,
420464289,420628701,420793130,420957574,421122035,421286511,421451004,421615513,421780038,421944579,
422109136,422273709,422438298,422602903,422767524,422932161,423096814,423261483,423426168,423590870,
423755587,423920320,424085069,424249834,424414616,424579413,424744226,424909055,425073900,425238762,
425403639,425568532,425733441,425898366,426063307,426228264,426393237,426558226,426723231,426888252,
427053288,427218341,427383410,427548494,427713595,427878711,428043844,428208992,428374156,428539337,
428704533,428869745,429034973,429200217,429365476,429530752,429696043,429861351,430026674,430192013,
430357369,430522740,430688126,430853529,431018948,431184382,431349833,431515299,431680781,431846279,
432011793,432177323,432342868,432508430,432674007,432839600,433005209,433170834,433336474,433502131,
433667803,433833491,433999195,434164914,434330650,434496401,434662168,434827951,434993750,435159565,
435325395,435491241,435657103,435822981,435988874,436154784,436320709,436486650,436652606,436818579,
436984567,437150571,437316590,437482626,437648677,437814744,437980827,438146925,438313039,438479169,
438645315,438811476,438977653,439143846,439310055,439476279,439642519,439808775,439975046,440141333,
440307636,440473955,440640289,440806639,440973005,441139386,441305783,441472196,441638624,441805068,
441971528,442138004,442304495,442471002,442637524,442804062,442970616,443137185,443303770,443470371,
443636988,443803620,443970267,444136931,444303610,444470304,444637014,444803740,444970482,445137239,
445304012,445470800,445637604,445804423,445971259,446138109,446304976,446471858,446638755,446805668,
446972597,447139542,447306501,447473477,447640468,447807475,447974497,448141535,448308588,448475657,
448642742,448809842,448976957,449144088,449311235,449478397,449645575,449812768,449979977,450147202,
450314442,450481697,450648968,450816255,450983557,451150874,451318207,451485556,451652920,451820300,
451987695,452155105,452322531,452489973,452657430,452824903,452992391,453159894,453327413,453494948,
453662498,453830063,453997644,454165240,454332852,454500480,454668122,454835781,455003454,455171143,
455338848,455506568,455674303,455842054,456009821,456177602,456345399,456513212,456681040,456848884,
457016742,457184617,457352506,457520411,457688332,457856268,458024219,458192186,458360168,458528165,
458696178,458864207,459032250,459200309,459368384,459536474,459704579,459872699,460040835,460208986,
460377153,460545335,460713532,460881745,461049973,461218216,461386475,461554749,461723039,461891343,
462059663,462227999,462396350,462564716,462733097,462901494,463069906,463238333,463406776,463575234,
463743707,463912196,464080699,464249219,464417753,464586303,464754868,464923448,465092044,465260655,
465429281,465597922,465766579,465935251,466103938,466272641,466441358,466610091,466778840,466947603,
467116382,467285176,467453985,467622810,467791650,467960505,468129375,468298260,468467161,468636077,
468805008,468973954,469142916,469311893,469480885,469649892,469818914,469987952,470157005,470326073,
470495156,470664254,470833368,471002497,471171641,471340800,471509974,471679164,471848368,472017588,
472186823,472356073,472525339,472694619,472863915,473033226,473202552,473371893,473541249,473710620,
473880007,474049409,474218825,474388257,474557704,474727167,474896644,475066136,475235644,475405167,
475574704,475744257,475913825,476083408,476253007,476422620,476592248,476761892,476931550,477101224,
477270913,477440617,477610336,477780070,477949819,478119583,478289362,478459157,478628966,478798790,
478968630,479138484,479308354,479478239,479648138,479818053,479987983,480157928,480327888,480497863,
480667853,480837858,481007878,481177913,481347963,481518028,481688108,481858203,482028313,482198438,
482368578,482538734,482708904,482879089,483049289,483219504,483389734,483559979,483730240,483900515,
484070805,484241110,484411430,484581765,484752115,484922480,485092860,485263254,485433664,485604089,
485774529,485944983,486115453,486285938,486456437,486626952,486797481,486968025,487138585,487309159,
487479748,487650352,487820971,487991605,488162254,488332917,488503596,488674290,488844998,489015721,
489186460,489357213,489527981,489698764,489869562,490040374,490211202,490382044,490552902,490723774,
490894661,491065563,491236480,491407412,491578358,491749320,491920296,492091287,492262294,492433314,
492604350,492775401,492946466,493117547,493288642,493459752,493630876,493802016,493973171,494144340,
494315524,494486723,494657937,494829165,495000409,495171667,495342940,495514228,495685530,495856848,
496028180,496199527,496370889,496542265,496713657,496885063,497056484,497227919,497399370,497570835,
497742315,497913810,498085320,498256844,498428383,498599937,498771506,498943089,499114687,499286300,
499457928,499629570,499801227,499972899,500144586,500316287,500488003,500659734,500831480,501003240,
501175015,501346805,501518609,501690428,501862262,502034111,502205974,502377852,502549745,502721652,
502893574,503065511,503237462,503409429,503581409,503753405,503925415,504097440,504269480,504441534,
504613603,504785686,504957785,505129897,505302025,505474167,505646324,505818496,505990682,506162883,
506335098,506507328,506679573,506851833,507024107,507196395,507368699,507541017,507713349,507885697,
508058058,508230435,508402826,508575232,508747652,508920087,509092536,509265000,509437479,509609972,
509782480,509955003,510127540,510300092,510472658,510645239,510817834,510990444,511163069,511335708,
511508362,511681030,511853713,512026411,512199123,512371849,512544590,512717346,512890116,513062901,
513235701,513408514,513581343,513754186,513927043,514099916,514272802,514445703,514618619,514791549,
514964494,515137453,515310427,515483415,515656418,515829435,516002467,516175513,516348574,516521649,
516694739,516867844,517040962,517214096,517387243,517560406,517733582,517906774,518079979,518253200,
518426434,518599683,518772947,518946225,519119518,519292825,519466146,519639482,519812833,519986197,
520159577,520332970,520506379,520679801,520853238,521026690,521200156,521373636,521547131,521720640,
521894164,522067702,522241255,522414822,522588403,522761999,522935609,523109234,523282873,523456526,
523630194,523803876,523977573,524151284,524325009,524498749,524672503,524846272,525020055,525193852,
525367664,525541490,525715330,525889185,526063054,526236938,526410836,526584748,526758675,526932616,
527106571,527280541,527454525,527628524,527802536,527976563,528150605,528324661,528498731,528672815,
528846914,529021027,529195155,529369297,529543453,529717623,529891808,530066007,530240220,530414448,
530588690,530762946,530937217,531111502,531285801,531460115,531634442,531808785,531983141,532157512,
532331897,532506296,532680709,532855137,533029579,533204036,533378506,533552991,533727490,533902004,
534076531,534251073,534425630,534600200,534774785,534949384,535123997,535298624,535473266,535647922,
535822592,535997276,536171975,536346688,536521415,536696156,536870912,537045682,537220466,537395264,
537570076,537744903,537919744,538094599,538269468,538444352,538619249,538794161,538969087,539144028,
539318982,539493951,539668934,539843931,540018942,540193967,540369007,540544060,540719128,540894210,
541069307,541244417,541419542,541594680,541769833,541945000,542120182,542295377,542470587,542645810,
542821048,542996300,543171566,543346846,543522141,543697449,543872772,544048109,544223460,544398825,
544574204,544749597,544925004,545100426,545275862,545451311,545626775,545802253,545977745,546153251,
546328772,546504306,546679854,546855417,547030994,547206584,547382189,547557808,547733441,547909088,
548084749,548260425,548436114,548611817,548787535,548963266,549139012,549314771,549490545,549666333,
549842135,550017950,550193780,550369624,550545482,550721354,550897241,551073141,551249055,551424983,
551600925,551776882,551952852,552128836,552304835,552480847,552656873,552832914,553008968,553185037,
553361119,553537215,553713326,553889450,554065589,554241741,554417908,554594088,554770283,554946491,
555122714,555298950,555475201,555651465,555827743,556004036,556180342,556356662,556532997,556709345,
556885707,557062083,557238473,557414877,557591295,557767727,557944173,558120633,558297107,558473595,
558650097,558826612,559003142,559179686,559356243,559532814,559709400,559885999,560062612,560239240,
560415881,560592536,560769205,560945887,561122584,561299295,561476019,561652758,561829510,562006276,
562183057,562359851,562536659,562713480,562890316,563067166,563244029,563420907,563597798,563774703,
563951622,564128555,564305502,564482463,564659437,564836426,565013428,565190444,565367474,565544518,
565721576,565898647,566075733,566252832,566429945,566607072,566784213,566961368,567138536,567315719,
567492915,567670125,567847349,568024586,568201838,568379103,568556382,568733675,568910982,569088303,
569265637,569442985,569620347,569797723,569975113,570152516,570329933,570507365,570684809,570862268,
571039740,571217227,571394727,571572240,571749768,571927309,572104865,572282433,572460016,572637613,
572815223,572992847,573170485,573348136,573525802,573703481,573881173,574058880,574236600,574414334,
574592082,574769844,574947619,575125408,575303211,575481028,575658858,575836702,576014560,576192431,
576370316,576548215,576726128,576904054,577081994,577259948,577437916,577615897,577793892,577971901,
578149923,578327959,578506009,578684072,578862149,579040240,579218345,579396463,579574595,579752741,
579930900,580109073,580287260,580465460,580643674,580821902,581000143,581178399,581356667,581534950,
581713246,581891555,582069879,582248216,582426567,582604931,582783309,582961701,583140106,583318525,
583496958,583675404,583853864,584032337,584210825,584389325,584567840,584746368,584924910,585103465,
585282034,585460616,585639213,585817822,585996446,586175083,586353733,586532398,586711076,586889767,
587068472,587247191,587425923,587604669,587783428,587962201,588140988,588319788,588498602,588677429,
588856270,589035125,589213993,589392875,589571770,589750679,589929601,590108537,590287487,590466450,
590645427,590824417,591003421,591182438,591361469,591540513,591719571,591898643,592077728,592256827,
592435939,592615065,592794204,592973357,593152523,593331703,593510896,593690103,593869324,594048558,
594227805,594407066,594586341,594765629,594944930,595124245,595303574,595482916,595662271,595841640,
596021023,596200419,596379829,596559252,596738688,596918138,597097602,597277079,597456569,597636073,
597815591,597995122,598174666,598354224,598533795,598713380,598892979,599072590,599252216,599431854,
599611506,599791172,599970851,600150544,600330250,600509969,600689702,600869448,601049208,601228981,
601408768,601588568,601768381,601948208,602128049,602307902,602487770,602667650,602847544,603027452,
603207373,603387307,603567255,603747216,603927191,604107179,604287180,604467195,604647223,604827265,
605007320,605187388,605367470,605547565,605727674,605907796,606087931,606268080,606448242,606628417,
606808606,606988808,607169024,607349253,607529496,607709751,607890020,608070303,608250599,608430908,
608611231,608791566,608971916,609152278,609332654,609513044,609693446,609873862,610054292,610234735,
610415191,610595660,610776143,610956639,611137148,611317671,611498207,611678756,611859319,612039895,
612220484,612401087,612581703,612762332,612942975,613123631,613304300,613484983,613665679,613846388,
614027110,614207846,614388595,614569357,614750133,614930922,615111724,615292540,615473368,615654210,
615835066,616015934,616196816,616377712,616558620,616739542,616920477,617101425,617282386,617463361,
617644349,617825351,618006365,618187393,618368434,618549488,618730556,618911637,619092731,619273838,
619454959,619636093,619817240,619998400,620179573,620360760,620541960,620723173,620904400,621085639,
621266892,621448158,621629438,621810730,621992036,622173355,622354687,622536032,622717391,622898763,
623080148,623261546,623442957,623624382,623805820,623987271,624168735,624350212,624531703,624713207,
624894724,625076254,625257797,625439354,625620923,625802506,625984102,626165711,626347334,626528969,
626710618,626892280,627073955,627255643,627437344,627619058,627800786,627982527,628164281,628346048,
628527828,628709621,628891428,629073248,629255080,629436926,629618785,629800658,629982543,630164441,
630346353,630528278,630710215,630892166,631074130,631256108,631438098,631620101,631802118,631984147,
632166190,632348246,632530315,632712397,632894492,633076600,633258722,633440856,633623004,633805164,
633987338,634169525,634351725,634533938,634716164,634898403,635080655,635262921,635445199,635627490,
635809795,635992113,636174443,636356787,636539144,636721514,636903896,637086292,637268701,637451123,
637633559,637816007,637998468,638180942,638363430,638545930,638728443,638910970,639093509,639276062,
639458627,639641206,639823797,640006402,640189020,640371650,640554294,640736951,640919621,641102303,
641284999,641467708,641650430,641833165,642015912,642198673,642381447,642564234,642747034,642929846,
643112672,643295511,643478363,643661228,643844105,644026996,644209900,644392817,644575746,644758689,
644941645,645124613,645307595,645490590,645673597,645856618,646039651,646222698,646405757,646588830,
646771915,646955013,647138125,647321249,647504386,647687536,647870699,648053875,648237064,648420266,
648603481,648786709,648969949,649153203,649336470,649519749,649703042,649886347,650069665,650252997,
650436341,650619698,650803068,650986451,651169847,651353255,651536677,651720112,651903559,652087020,
652270493,652453979,652637478,652820990,653004515,653188053,653371604,653555167,653738744,653922333,
654105935,654289550,654473178,654656819,654840473,655024140,655207819,655391512,655575217,655758935,
655942666,656126410,656310167,656493936,656677719,656861514,657045322,657229143,657412977,657596824,
657780683,657964556,658148441,658332339,658516250,658700174,658884111,659068060,659252023,659435998,
659619986,659803987,659988000,660172027,660356066,660540118,660724183,660908261,661092351,661276455,
661460571,661644700,661828842,662012997,662197164,662381344,662565538,662749743,662933962,663118194,
663302438,663486695,663670965,663855247,664039543,664223851,664408172,664592506,664776853,664961212,
665145584,665329969,665514367,665698777,665883200,666067636,666252085,666436547,666621021,666805508,
666990008,667174521,667359046,667543584,667728135,667912699,668097275,668281864,668466466,668651081,
668835708,669020348,669205001,669389667,669574345,669759036,669943740,670128456,670313185,670497927,
670682682,670867450,671052230,671237023,671421828,671606647,671791478,671976321,672161178,672346047,
672530929,672715823,672900731,673085651,673270583,673455529,673640487,673825458,674010441,674195437,
674380446,674565468,674750502,674935549,675120609,675305681,675490766,675675863,675860974,676046097,
676231232,676416381,676601542,676786716,676971902,677157101,677342313,677527537,677712774,677898024,
678083286,678268561,678453849,678639149,678824462,679009787,679195126,679380477,679565840,679751216,
679936605,680122006,680307421,680492847,680678287,680863739,681049203,681234680,681420170,681605673,
681791188,681976716,682162256,682347809,682533374,682718953,682904543,683090147,683275763,683461391,
683647033,683832687,684018353,684204032,684389724,684575428,684761145,684946874,685132616,685318371,
685504138,685689918,685875710,686061515,686247332,686433163,686619005,686804861,686990728,687176609,
687362502,687548407,687734325,687920256,688106199,688292155,688478123,688664104,688850098,689036104,
689222122,689408154,689594197,689780254,689966322,690152404,690338498,690524604,690710723,690896854,
691082998,691269155,691455324,691641506,691827700,692013907,692200126,692386358,692572602,692758859,
692945128,693131410,693317704,693504011,693690330,693876662,694063007,694249364,694435733,694622115,
694808509,694994916,695181336,695367768,695554212,695740669,695927138,696113620,696300115,696486621,
696673141,696859673,697046217,697232774,697419343,697605925,697792519,697979126,698165745,698352377,
698539021,698725677,698912347,699099028,699285722,699472429,699659147,699845879,700032623,700219379,
700406148,700592929,700779723,700966529,701153347,701340178,701527022,701713878,701900746,702087627,
702274520,702461425,702648343,702835274,703022217,703209172,703396140,703583120,703770113,703957118,
704144135,704331165,704518208,704705262,704892329,705079409,705266501,705453605,705640722,705827851,
706014993,706202147,706389313,706576492,706763683,706950887,707138103,707325331,707512572,707699825,
707887090,708074368,708261659,708448961,708636276,708823604,709010944,709198296,709385660,709573037,
709760427,709947828,710135242,710322669,710510107,710697559,710885022,711072498,711259986,711447487,
711635000,711822525,712010063,712197613,712385175,712572750,712760337,712947936,713135548,713323172,
713510808,713698457,713886118,714073791,714261477,714449175,714636885,714824608,715012343,715200090,
715387850,715575622,715763406,715951203,716139012,716326833,716514667,716702513,716890371,717078242,
717266124,717454019,717641927,717829847,718017779,718205723,718393680,718581648,718769630,718957623,
719145629,719333647,719521677,719709720,719897775,720085842,720273922,720462013,720650117,720838234,
721026362,721214503,721402656,721590822,721778999,721967189,722155392,722343606,722531833,722720072,
722908323,723096587,723284862,723473150,723661451,723849763,724038088,724226425,724414774,724603136,
724791509,724979895,725168294,725356704,725545127,725733562,725922009,726110468,726298940,726487424,
726675920,726864428,727052949,727241481,727430026,727618583,727807153,727995734,728184328,728372934,
728561553,728750183,728938826,729127480,729316148,729504827,729693518,729882222,730070938,730259666,
730448406,730637159,730825923,731014700,731203489,731392290,731581104,731769929,731958767,732147617,
732336479,732525353,732714240,732903139,733092049,733280972,733469908,733658855,733847814,734036786,
734225770,734414766,734603774,734792794,734981827,735170871,735359928,735548997,735738078,735927171,
736116277,736305394,736494524,736683666,736872820,737061986,737251164,737440354,737629557,737818771,
738007998,738197237,738386488,738575751,738765026,738954314,739143613,739332925,739522249,739711585,
739900933,740090293,740279665,740469049,740658446,740847854,741037275,741226708,741416152,741605609,
741795078,741984560,742174053,742363558,742553076,742742605,742932147,743121701,743311266,743500844,
743690434,743880036,744069651,744259277,744448915,744638566,744828228,745017903,745207589,745397288,
745586999,745776721,745966456,746156203,746345962,746535733,746725517,746915312,747105119,747294938,
747484770,747674613,747864469,748054336,748244216,748434107,748624011,748813927,749003855,749193794,
749383746,749573710,749763686,749953674,750143674,750333686,750523710,750713746,750903794,751093854,
751283926,751474011,751664107,751854215,752044335,752234467,752424612,752614768,752804936,752995117,
753185309,753375513,753565729,753755958,753946198,754136450,754326715,754516991,754707279,754897580,
755087892,755278216,755468553,755658901,755849261,756039633,756230018,756420414,756610822,756801242,
756991675,757182119,757372575,757563043,757753523,757944015,758134519,758325035,758515563,758706103,
758896655,759087219,759277794,759468382,759658982,759849593,760040217,760230853,760421500,760612160,
760802831,760993514,761184210,761374917,761565636,761756367,761947110,762137866,762328632,762519411,
762710202,762901005,763091820,763282646,763473485,763664335,763855198,764046072,764236958,764427856,
764618767,764809689,765000622,765191568,765382526,765573496,765764477,765955471,766146476,766337493,
766528523,766719564,766910617,767101682,767292758,767483847,767674948,767866060,768057185,768248321,
768439469,768630629,768821801,769012985,769204180,769395388,769586607,769777839,769969082,770160337,
770351604,770542883,770734174,770925476,771116791,771308117,771499455,771690805,771882167,772073541,
772264926,772456324,772647733,772839155,773030588,773222032,773413489,773604958,773796438,773987931,
774179435,774370951,774562479,774754018,774945570,775137133,775328708,775520295,775711894,775903505,
776095127,776286762,776478408,776670066,776861736,777053417,777245111,777436816,777628533,777820262,
778012003,778203755,778395520,778587296,778779084,778970884,779162695,779354519,779546354,779738201,
779930060,780121930,780313813,780505707,780697613,780889531,781081460,781273402,781465355,781657320,
781849297,782041285,782233285,782425297,782617321,782809357,783001404,783193464,783385535,783577617,
783769712,783961818,784153936,784346066,784538208,784730361,784922526,785114703,785306892,785499092,
785691304,785883528,786075764,786268012,786460271,786652542,786844824,787037119,787229425,787421743,
787614073,787806414,787998767,788191132,788383509,788575897,788768297,788960709,789153133,789345568,
789538015,789730474,789922944,790115426,790307920,790500426,790692943,790885472,791078013,791270566,
791463130,791655706,791848294,792040893,792233504,792426127,792618762,792811408,793004066,793196735,
793389417,793582110,793774814,793967531,794160259,794352999,794545750,794738513,794931288,795124075,
795316873,795509683,795702505,795895338,796088183,796281039,796473908,796666788,796859680,797052583,
797245498,797438425,797631363,797824313,798017275,798210248,798403233,798596230,798789238,798982258,
799175290,799368333,799561388,799754455,799947533,800140623,800333725,800526838,800719963,800913099,
801106248,801299407,801492579,801685762,801878957,802072163,802265381,802458611,802651852,802845105,
803038370,803231646,803424934,803618233,803811544,804004867,804198201,804391547,804584905,804778274,
804971654,805165047,805358451,805551866,805745294,805938733,806132183,806325645,806519119,806712604,
806906101,807099609,807293129,807486661,807680204,807873759,808067326,808260904,808454493,808648094,
808841707,809035332,809228968,809422615,809616274,809809945,810003627,810197321,810391027,810584744,
810778472,810972213,811165964,811359728,811553503,811747289,811941087,812134897,812328718,812522551,
812716395,812910251,813104118,813297997,813491888,813685790,813879703,814073628,814267565,814461513,
814655473,814849445,815043427,815237422,815431428,815625445,815819475,816013515,816207567,816401631,
816595706,816789793,816983891,817178001,817372122,817566255,817760400,817954555,818148723,818342902,
818537092,818731294,818925508,819119733,819313969,819508217,819702477,819896748,820091031,820285325,
820479630,820673947,820868276,821062616,821256968,821451331,821645705,821840091,822034489,822228898,
822423319,822617751,822812194,823006649,823201116,823395594,823590083,823784584,823979097,824173621,
824368156,824562703,824757261,824951831,825146413,825341005,825535610,825730225,825924853,826119491,
826314141,826508803,826703476,826898160,827092856,827287564,827482283,827677013,827871755,828066508,
828261273,828456049,828650837,828845636,829040446,829235268,829430102,829624946,829819803,830014670,
830209550,830404440,830599342,830794256,830989181,831184117,831379065,831574024,831768994,831963976,
832158970,832353975,832548991,832744019,832939058,833134109,833329170,833524244,833719329,833914425,
834109533,834304652,834499782,834694924,834890077,835085242,835280418,835475605,835670804,835866015,
836061236,836256469,836451714,836646970,836842237,837037516,837232806,837428107,837623420,837818744,
838014080,838209427,838404785,838600155,838795536,838990928,839186332,839381747,839577174,839772612,
839968061,840163522,840358994,840554478,840749972,840945479,841140996,841336525,841532065,841727617,
841923180,842118754,842314340,842509937,842705546,842901165,843096797,843292439,843488093,843683758,
843879435,844075122,844270822,844466532,844662254,844857987,845053732,845249488,845445255,845641034,
845836823,846032625,846228437,846424261,846620096,846815943,847011801,847207670,847403550,847599442,
847795345,847991260,848187186,848383123,848579071,848775031,848971002,849166984,849362978,849558983,
849754999,849951027,850147065,850343116,850539177,850735250,850931334,851127429,851323536,851519654,
851715783,851911924,852108076,852304239,852500413,852696599,852892796,853089004,853285224,853481454,
853677697,853873950,854070215,854266491,854462778,854659076,854855386,855051707,855248039,855444383,
855640738,855837104,856033481,856229870,856426270,856622681,856819103,857015537,857211982,857408438,
857604905,857801384,857997874,858194375,858390888,858587411,858783946,858980492,859177050,859373619,
859570198,859766790,859963392,860160006,860356630,860553267,860749914,860946572,861143242,861339923,
861536615,861733319,861930034,862126760,862323497,862520245,862717005,862913775,863110557,863307351,
863504155,863700971,863897798,864094636,864291485,864488346,864685217,864882100,865078994,865275900,
865472816,865669744,865866683,866063633,866260595,866457567,866654551,866851546,867048552,867245569,
867442598,867639637,867836688,868033750,868230823,868427908,868625004,868822110,869019228,869216357,
869413498,869610649,869807812,870004986,870202171,870399367,870596574,870793793,870991023,871188264,
871385516,871582779,871780053,871977339,872174635,872371943,872569262,872766592,872963934,873161286,
873358650,873556024,873753410,873950807,874148216,874345635,874543065,874740507,874937960,875135424,
875332899,875530385,875727882,875925391,876122910,876320441,876517983,876715536,876913100,877110675,
877308262,877505859,877703468,877901088,878098719,878296361,878494014,878691678,878889353,879087040,
879284737,879482446,879680166,879877897,880075639,880273392,880471156,880668932,880866718,881064516,
881262324,881460144,881657975,881855817,882053670,882251534,882449409,882647296,882845193,883043102,
883241021,883438952,883636894,883834847,884032811,884230786,884428772,884626769,884824777,885022797,
885220827,885418869,885616921,885814985,886013060,886211145,886409242,886607350,886805469,887003599,
887201741,887399893,887598056,887796230,887994416,888192612,888390820,888589038,888787268,888985509,
889183760,889382023,889580297,889778582,889976878,890175185,890373503,890571832,890770172,890968523,
891166885,891365258,891563643,891762038,891960444,892158862,892357290,892555729,892754180,892952641,
893151114,893349597,893548092,893746597,893945114,894143642,894342180,894540730,894739291,894937862,
895136445,895335039,895533644,895732259,895930886,896129524,896328173,896526833,896725503,896924185,
897122878,897321582,897520297,897719022,897917759,898116507,898315266,898514036,898712816,898911608,
899110411,899309225,899508050,899706885,899905732,900104590,900303458,900502338,900701229,900900130,
901099043,901297967,901496901,901695847,901894803,902093771,902292749,902491739,902690739,902889750,
903088773,903287806,903486850,903685906,903884972,904084049,904283137,904482236,904681346,904880467,
905079599,905278742,905477896,905677061,905876237,906075423,906274621,906473829,906673049,906872279,
907071521,907270773,907470037,907669311,907868596,908067892,908267199,908466517,908665846,908865186,
909064537,909263899,909463271,909662655,909862049,910061455,910260871,910460298,910659737,910859186,
911058646,911258117,911457599,911657091,911856595,912056110,912255635,912455172,912654719,912854277,
913053846,913253426,913453017,913652619,913852232,914051856,914251490,914451136,914650792,914850459,
915050138,915249827,915449527,915649237,915848959,916048692,916248435,916448190,916647955,916847731,
917047518,917247316,917447125,917646945,917846775,918046617,918246469,918446332,918646206,918846091,
919045987,919245894,919445811,919645740,919845679,920045629,920245590,920445562,920645545,920845538,
921045543,921245558,921445584,921645621,921845669,922045728,922245797,922445878,922645969,922846071,
923046184,923246308,923446443,923646588,923846745,924046912,924247090,924447279,924647479,924847689,
925047911,925248143,925448386,925648640,925848904,926049180,926249466,926449764,926650072,926850391,
927050720,927251061,927451412,927651774,927852147,928052531,928252926,928453331,928653747,928854174,
929054612,929255061,929455521,929655991,929856472,930056964,930257467,930457980,930658504,930859040,
931059586,931260142,931460710,931661288,931861877,932062477,932263088,932463709,932664342,932864985,
933065639,933266303,933466979,933667665,933868362,934069070,934269789,934470518,934671258,934872009,
935072771,935273543,935474326,935675120,935875925,936076741,936277567,936478404,936679252,936880111,
937080980,937281861,937482751,937683653,937884566,938085489,938286423,938487368,938688323,938889289,
939090266,939291254,939492253,939693262,939894282,940095313,940296354,940497407,940698470,940899543,
941100628,941301723,941502829,941703946,941905073,942106212,942307361,942508520,942709691,942910872,
943112064,943313266,943514480,943715704,943916938,944118184,944319440,944520707,944721985,944923273,
945124572,945325882,945527203,945728534,945929876,946131229,946332592,946533966,946735351,946936747,
947138153,947339570,947540998,947742436,947943885,948145345,948346815,948548297,948749789,948951291,
949152804,949354328,949555863,949757409,949958965,950160531,950362109,950563697,950765296,950966905,
951168526,951370156,951571798,951773450,951975113,952176787,952378471,952580166,952781872,952983588,
953185315,953387053,953588801,953790560,953992330,954194110,954395901,954597703,954799515,955001338,
955203172,955405016,955606871,955808737,956010613,956212500,956414398,956616306,956818225,957020155,
957222095,957424046,957626008,957827980,958029963,958231956,958433960,958635975,958838001,959040037,
959242083,959444141,959646209,959848287,960050377,960252477,960454587,960656708,960858840,961060983,
961263136,961465299,961667474,961869659,962071854,962274060,962476277,962678505,962880743,963082991,
963285251,963487521,963689801,963892092,964094394,964296707,964499030,964701363,964903707,965106062,
965308428,965510804,965713190,965915588,966117995,966320414,966522843,966725283,966927733,967130194,
967332665,967535147,967737640,967940143,968142657,968345181,968547716,968750262,968952818,969155385,
969357962,969560550,969763149,969965758,970168378,970371008,970573649,970776300,970978962,971181635,
971384318,971587011,971789716,971992431,972195156,972397892,972600639,972803396,973006163,973208942,
973411731,973614530,973817340,974020160,974222991,974425833,974628685,974831548,975034421,975237305,
975440200,975643105,975846020,976048946,976251883,976454830,976657788,976860756,977063735,977266724,
977469724,977672734,977875755,978078787,978281829,978484881,978687944,978891018,979094102,979297197,
979500302,979703418,979906544,980109681,980312828,980515986,980719154,980922333,981125523,981328723,
981531933,981735154,981938386,982141628,982344880,982548143,982751417,982954701,983157995,983361300,
983564616,983767942,983971279,984174626,984377983,984581352,984784730,984988119,985191519,985394929,
985598350,985801781,986005222,986208675,986412137,986615610,986819094,987022588,987226092,987429608,
987633133,987836669,988040216,988243773,988447340,988650918,988854506,989058105,989261715,989465335,
989668965,989872606,990076257,990279919,990483591,990687274,990890967,991094671,991298385,991502109,
991705844,991909590,992113346,992317112,992520889,992724677,992928475,993132283,993336102,993539931,
993743770,993947620,994151481,994355352,994559234,994763125,994967028,995170941,995374864,995578798,
995782742,995986696,996190661,996394637,996598623,996802619,997006626,997210643,997414671,997618709,
997822757,998026816,998230886,998434965,998639056,998843156,999047267,999251389,999455521,999659663,
999863816,1000067979,1000272153,1000476337,1000680531,1000884736,1001088952,1001293177,1001497413,1001701660,
1001905917,1002110184,1002314462,1002518750,1002723049,1002927358,1003131677,1003336007,1003540347,1003744698,
1003949059,1004153430,1004357812,1004562204,1004766607,1004971020,1005175443,1005379877,1005584321,1005788776,
1005993241,1006197716,1006402202,1006606698,1006811205,1007015722,1007220249,1007424787,1007629335,1007833893,
1008038462,1008243041,1008447631,1008652231,1008856841,1009061462,1009266093,1009470734,1009675386,1009880048,
1010084721,1010289404,1010494097,1010698801,1010903515,1011108239,1011312974,1011517719,1011722475,1011927241,
1012132017,1012336803,1012541600,1012746407,1012951225,1013156053,1013360891,1013565740,1013770599,1013975469,
1014180348,1014385238,1014590139,1014795050,1014999971,1015204902,1015409844,1015614796,1015819759,1016024732,
1016229715,1016434708,1016639712,1016844726,1017049751,1017254786,1017459831,1017664886,1017869952,1018075028,
1018280115,1018485212,1018690319,1018895436,1019100564,1019305702,1019510851,1019716009,1019921179,1020126358,
1020331548,1020536748,1020741958,1020947179,1021152410,1021357651,1021562903,1021768165,1021973437,1022178719,
1022384012,1022589315,1022794629,1022999953,1023205287,1023410631,1023615986,1023821351,1024026726,1024232111,
1024437507,1024642913,1024848330,1025053757,1025259194,1025464641,1025670099,1025875566,1026081045,1026286533,
1026492032,1026697541,1026903060,1027108590,1027314130,1027519680,1027725240,1027930811,1028136392,1028341984,
1028547585,1028753197,1028958819,1029164451,1029370094,1029575747,1029781410,1029987084,1030192768,1030398462,
1030604166,1030809880,1031015605,1031221340,1031427086,1031632841,1031838607,1032044383,1032250170,1032455966,
1032661773,1032867590,1033073418,1033279255,1033485103,1033690961,1033896830,1034102708,1034308597,1034514496,
1034720406,1034926325,1035132255,1035338195,1035544146,1035750106,1035956077,1036162058,1036368050,1036574051,
1036780063,1036986085,1037192117,1037398160,1037604212,1037810275,1038016348,1038222432,1038428526,1038634629,
1038840743,1039046868,1039253002,1039459147,1039665302,1039871467,1040077643,1040283828,1040490024,1040696230,
1040902446,1041108673,1041314910,1041521157,1041727414,1041933681,1042139959,1042346246,1042552544,1042758852,
1042965171,1043171499,1043377838,1043584187,1043790546,1043996916,1044203295,1044409685,1044616085,1044822495,
1045028916,1045235346,1045441787,1045648238,1045854699,1046061170,1046267652,1046474144,1046680645,1046887158,
1047093680,1047300212,1047506755,1047713308,1047919871,1048126444,1048333027,1048539621,1048746224,1048952838,
1049159462,1049366097,1049572741,1049779396,1049986060,1050192735,1050399420,1050606116,1050812821,1051019537,
1051226262,1051432998,1051639744,1051846500,1052053267,1052260043,1052466830,1052673627,1052880434,1053087251,
1053294079,1053500916,1053707764,1053914622,1054121489,1054328368,1054535256,1054742154,1054949063,1055155981,
1055362910,1055569849,1055776798,1055983758,1056190727,1056397707,1056604696,1056811696,1057018706,1057225726,
1057432756,1057639797,1057846847,1058053908,1058260979,1058468059,1058675150,1058882252,1059089363,1059296484,
1059503616,1059710757,1059917909,1060125071,1060332243,1060539425,1060746617,1060953820,1061161032,1061368255,
1061575488,1061782730,1061989983,1062197246,1062404520,1062611803,1062819096,1063026400,1063233713,1063441037,
1063648371,1063855715,1064063069,1064270433,1064477807,1064685192,1064892586,1065099990,1065307405,1065514830,
1065722265,1065929709,1066137164,1066344630,1066552105,1066759590,1066967085,1067174591,1067382106,1067589632,
1067797168,1068004714,1068212269,1068419835,1068627411,1068834998,1069042594,1069250200,1069457816,1069665443,
1069873079,1070080726,1070288383,1070496049,1070703726,1070911413,1071119110,1071326817,1071534534,1071742261,
1071949998,1072157746,1072365503,1072573270,1072781048,1072988835,1073196633,1073404441,1073612258,1073820086,
1074027924,1074235772,1074443630,1074651498,1074859376,1075067264,1075275162,1075483070,1075690988,1075898917,
1076106855,1076314803,1076522762,1076730730,1076938709,1077146697,1077354696,1077562705,1077770723,1077978752,
1078186791,1078394839,1078602898,1078810967,1079019046,1079227135,1079435234,1079643343,1079851462,1080059591,
1080267730,1080475879,1080684038,1080892207,1081100386,1081308576,1081516775,1081724984,1081933203,1082141432,
1082349672,1082557921,1082766180,1082974450,1083182729,1083391018,1083599318,1083807627,1084015947,1084224276,
1084432615,1084640965,1084849324,1085057694,1085266073,1085474462,1085682862,1085891271,1086099691,1086308120,
1086516560,1086725009,1086933468,1087141938,1087350417,1087558907,1087767406,1087975915,1088184435,1088392964,
1088601503,1088810053,1089018612,1089227181,1089435761,1089644350,1089852949,1090061559,1090270178,1090478807,
1090687446,1090896095,1091104754,1091313424,1091522103,1091730792,1091939491,1092148200,1092356919,1092565648,
1092774387,1092983136,1093191894,1093400663,1093609442,1093818231,1094027030,1094235838,1094444657,1094653486,
1094862324,1095071173,1095280031,1095488900,1095697778,1095906666,1096115565,1096324473,1096533391,1096742319,
1096951257,1097160206,1097369164,1097578132,1097787109,1097996097,1098205095,1098414103,1098623121,1098832148,
1099041186,1099250233,1099459291,1099668358,1099877435,1100086523,1100295620,1100504727,1100713844,1100922971,
1101132108,1101341255,1101550412,1101759578,1101968755,1102177942,1102387138,1102596345,1102805561,1103014787,
1103224023,1103433270,1103642526,1103851792,1104061067,1104270353,1104479649,1104688955,1104898270,1105107596,
1105316931,1105526276,1105735631,1105944997,1106154372,1106363756,1106573151,1106782556,1106991971,1107201395,
1107410830,1107620274,1107829728,1108039192,1108248667,1108458150,1108667644,1108877148,1109086662,1109296185,
1109505719,1109715262,1109924815,1110134378,1110343951,1110553534,1110763127,1110972730,1111182342,1111391965,
1111601597,1111811239,1112020891,1112230553,1112440225,1112649907,1112859598,1113069300,1113279011,1113488733,
1113698464,1113908205,1114117956,1114327716,1114537487,1114747267,1114957058,1115166858,1115376668,1115586488,
1115796318,1116006157,1116216007,1116425866,1116635736,1116845615,1117055504,1117265403,1117475311,1117685230,
1117895158,1118105097,1118315045,1118525003,1118734971,1118944948,1119154936,1119364933,1119574941,1119784958,
1119994985,1120205022,1120415068,1120625125,1120835191,1121045267,1121255353,1121465449,1121675555,1121885670,
1122095796,1122305931,1122516076,1122726231,1122936396,1123146570,1123356755,1123566949,1123777153,1123987367,
1124197590,1124407824,1124618067,1124828321,1125038584,1125248856,1125459139,1125669432,1125879734,1126090046,
1126300368,1126510700,1126721041,1126931393,1127141754,1127352125,1127562506,1127772897,1127983297,1128193707,
1128404127,1128614557,1128824997,1129035447,1129245906,1129456375,1129666854,1129877343,1130087841,1130298350,
1130508868,1130719396,1130929934,1131140481,1131351039,1131561606,1131772183,1131982769,1132193366,1132403972,
1132614588,1132825214,1133035850,1133246496,1133457151,1133667816,1133878491,1134089176,1134299870,1134510574,
1134721288,1134932012,1135142746,1135353489,1135564242,1135775005,1135985778,1136196560,1136407352,1136618154,
1136828966,1137039788,1137250619,1137461460,1137672311,1137883172,1138094042,1138304922,1138515812,1138726712,
1138937622,1139148541,1139359470,1139570409,1139781357,1139992315,1140203284,1140414261,1140625249,1140836246,
1141047253,1141258270,1141469297,1141680333,1141891379,1142102435,1142313501,1142524576,1142735661,1142946756,
1143157861,1143368975,1143580099,1143791233,1144002377,1144213530,1144424693,1144635866,1144847048,1145058241,
1145269443,1145480655,1145691876,1145903107,1146114348,1146325599,1146536859,1146748130,1146959410,1147170699,
1147381999,1147593308,1147804626,1148015955,1148227293,1148438641,1148649999,1148861367,1149072744,1149284131,
1149495527,1149706934,1149918350,1150129775,1150341211,1150552656,1150764111,1150975576,1151187050,1151398534,
1151610028,1151821531,1152033044,1152244567,1152456100,1152667642,1152879194,1153090756,1153302327,1153513909,
1153725499,1153937100,1154148710,1154360330,1154571960,1154783599,1154995248,1155206907,1155418575,1155630253,
1155841941,1156053639,1156265346,1156477063,1156688789,1156900526,1157112272,1157324027,1157535793,1157747568,
1157959352,1158171147,1158382951,1158594765,1158806588,1159018421,1159230264,1159442116,1159653979,1159865850,
1160077732,1160289623,1160501524,1160713435,1160925355,1161137285,1161349224,1161561173,1161773132,1161985101,
1162197079,1162409067,1162621064,1162833072,1163045089,1163257115,1163469151,1163681197,1163893253,1164105318,
1164317393,1164529477,1164741571,1164953675,1165165789,1165377912,1165590045,1165802187,1166014339,1166226501,
1166438672,1166650853,1166863044,1167075244,1167287454,1167499674,1167711903,1167924142,1168136390,1168348649,
1168560916,1168773194,1168985481,1169197778,1169410084,1169622400,1169834726,1170047061,1170259406,1170471761,
1170684125,1170896499,1171108882,1171321275,1171533678,1171746090,1171958512,1172170944,1172383385,1172595836,
1172808296,1173020766,1173233246,1173445735,1173658234,1173870743,1174083261,1174295789,1174508326,1174720873,
1174933430,1175145996,1175358572,1175571158,1175783753,1175996357,1176208972,1176421596,1176634229,1176846872,
1177059525,1177272187,1177484859,1177697541,1177910232,1178122933,1178335643,1178548363,1178761093,1178973832,
1179186581,1179399339,1179612107,1179824884,1180037672,1180250468,1180463275,1180676090,1180888916,1181101751,
1181314596,1181527450,1181740314,1181953187,1182166070,1182378963,1182591865,1182804777,1183017698,1183230629,
1183443570,1183656520,1183869480,1184082449,1184295428,1184508416,1184721414,1184934422,1185147439,1185360465,
1185573502,1185786548,1185999603,1186212668,1186425743,1186638827,1186851920,1187065024,1187278136,1187491259,
1187704391,1187917532,1188130683,1188343844,1188557014,1188770194,1188983383,1189196582,1189409790,1189623008,
1189836236,1190049473,1190262720,1190475976,1190689242,1190902517,1191115802,1191329096,1191542400,1191755713,
1191969036,1192182369,1192395711,1192609063,1192822424,1193035795,1193249175,1193462565,1193675964,1193889373,
1194102791,1194316219,1194529657,1194743104,1194956561,1195170027,1195383502,1195596987,1195810482,1196023986,
1196237500,1196451023,1196664556,1196878099,1197091650,1197305212,1197518783,1197732363,1197945953,1198159553,
1198373162,1198586780,1198800408,1199014046,1199227693,1199441349,1199655015,1199868691,1200082376,1200296071,
1200509775,1200723489,1200937212,1201150944,1201364687,1201578438,1201792200,1202005970,1202219750,1202433540,
1202647339,1202861148,1203074966,1203288794,1203502631,1203716478,1203930334,1204144200,1204358075,1204571960,
1204785854,1204999758,1205213671,1205427594,1205641526,1205855467,1206069419,1206283379,1206497349,1206711329,
1206925318,1207139317,1207353325,1207567342,1207781369,1207995406,1208209452,1208423507,1208637572,1208851647,
1209065731,1209279824,1209493927,1209708039,1209922161,1210136293,1210350433,1210564584,1210778743,1210992912,
1211207091,1211421279,1211635477,1211849684,1212063900,1212278126,1212492362,1212706607,1212920861,1213135125,
1213349398,1213563681,1213777973,1213992275,1214206586,1214420907,1214635237,1214849576,1215063925,1215278284,
1215492652,1215707029,1215921416,1216135812,1216350218,1216564633,1216779057,1216993491,1217207935,1217422388,
1217636850,1217851322,1218065803,1218280294,1218494794,1218709304,1218923823,1219138351,1219352889,1219567436,
1219781993,1219996559,1220211135,1220425720,1220640314,1220854918,1221069532,1221284154,1221498787,1221713428,
1221928079,1222142740,1222357410,1222572089,1222786778,1223001476,1223216184,1223430901,1223645627,1223860363,
1224075109,1224289863,1224504627,1224719401,1224934184,1225148976,1225363778,1225578589,1225793410,1226008240,
1226223080,1226437928,1226652787,1226867654,1227082531,1227297418,1227512314,1227727219,1227942134,1228157058,
1228371992,1228586934,1228801887,1229016849,1229231820,1229446800,1229661790,1229876789,1230091798,1230306816,
1230521844,1230736881,1230951927,1231166983,1231382048,1231597122,1231812206,1232027299,1232242402,1232457514,
1232672636,1232887766,1233102907,1233318056,1233533215,1233748383,1233963561,1234178748,1234393945,1234609151,
1234824366,1235039590,1235254824,1235470068,1235685321,1235900583,1236115854,1236331135,1236546425,1236761725,
1236977034,1237192352,1237407680,1237623017,1237838364,1238053719,1238269085,1238484459,1238699843,1238915236,
1239130639,1239346051,1239561472,1239776903,1239992343,1240207793,1240423251,1240638720,1240854197,1241069684,
1241285180,1241500686,1241716201,1241931725,1242147259,1242362802,1242578354,1242793916,1243009487,1243225067,
1243440657,1243656256,1243871864,1244087482,1244303109,1244518745,1244734391,1244950046,1245165711,1245381385,
1245597068,1245812760,1246028462,1246244173,1246459894,1246675623,1246891363,1247107111,1247322869,1247538636,
1247754413,1247970198,1248185993,1248401798,1248617612,1248833435,1249049267,1249265109,1249480960,1249696820,
1249912690,1250128569,1250344458,1250560355,1250776262,1250992179,1251208104,1251424039,1251639983,1251855937,
1252071900,1252287872,1252503854,1252719845,1252935845,1253151854,1253367873,1253583901,1253799938,1254015985,
1254232041,1254448106,1254664181,1254880265,1255096358,1255312461,1255528572,1255744693,1255960824,1256176964,
1256393113,1256609271,1256825438,1257041615,1257257802,1257473997,1257690202,1257906416,1258122639,1258338872,
1258555114,1258771365,1258987626,1259203895,1259420174,1259636463,1259852760,1260069067,1260285384,1260501709,
1260718044,1260934388,1261150741,1261367104,1261583476,1261799857,1262016248,1262232647,1262449056,1262665475,
1262881902,1263098339,1263314785,1263531241,1263747705,1263964179,1264180662,1264397155,1264613657,1264830168,
1265046688,1265263217,1265479756,1265696304,1265912861,1266129428,1266346004,1266562589,1266779183,1266995787,
1267212400,1267429022,1267645653,1267862294,1268078944,1268295603,1268512271,1268728949,1268945636,1269162332,
1269379038,1269595752,1269812476,1270029209,1270245952,1270462703,1270679464,1270896234,1271113014,1271329802,
1271546600,1271763407,1271980224,1272197049,1272413884,1272630728,1272847582,1273064444,1273281316,1273498197,
1273715087,1273931987,1274148895,1274365813,1274582740,1274799677,1275016622,1275233577,1275450541,1275667515,
1275884497,1276101489,1276318490,1276535500,1276752520,1276969548,1277186586,1277403633,1277620690,1277837755,
1278054830,1278271914,1278489007,1278706110,1278923221,1279140342,1279357472,1279574611,1279791760,1280008918,
1280226085,1280443261,1280660446,1280877641,1281094844,1281312057,1281529279,1281746511,1281963751,1282181001,
1282398260,1282615528,1282832806,1283050092,1283267388,1283484693,1283702007,1283919331,1284136663,1284354005,
1284571356,1284788716,1285006085,1285223464,1285440852,1285658249,1285875655,1286093070,1286310494,1286527928,
1286745371,1286962823,1287180284,1287397755,1287615234,1287832723,1288050221,1288267728,1288485245,1288702770,
1288920305,1289137849,1289355402,1289572964,1289790535,1290008116,1290225706,1290443305,1290660913,1290878530,
1291096157,1291313792,1291531437,1291749091,1291966754,1292184426,1292402108,1292619799,1292837498,1293055207,
1293272925,1293490653,1293708389,1293926135,1294143890,1294361654,1294579427,1294797209,1295015000,1295232801,
1295450611,1295668430,1295886258,1296104095,1296321941,1296539797,1296757661,1296975535,1297193418,1297411310,
1297629211,1297847122,1298065041,1298282970,1298500908,1298718855,1298936811,1299154776,1299372751,1299590734,
1299808727,1300026729,1300244740,1300462760,1300680789,1300898828,1301116875,1301334932,1301552998,1301771072,
1301989157,1302207250,1302425352,1302643464,1302861584,1303079714,1303297853,1303516001,1303734158,1303952324,
1304170499,1304388684,1304606878,1304825080,1305043292,1305261513,1305479743,1305697982,1305916231,1306134488,
1306352755,1306571030,1306789315,1307007609,1307225912,1307444224,1307662546,1307880876,1308099216,1308317564,
1308535922,1308754289,1308972665,1309191050,1309409444,1309627847,1309846259,1310064681,1310283112,1310501551,
1310720000,1310938458,1311156925,1311375401,1311593886,1311812380,1312030884,1312249396,1312467918,1312686449,
1312904988,1313123537,1313342095,1313560662,1313779238,1313997824,1314216418,1314435021,1314653634,1314872255,
1315090886,1315309526,1315528175,1315746833,1315965500,1316184176,1316402861,1316621555,1316840259,1317058971,
1317277693,1317496423,1317715163,1317933912,1318152669,1318371436,1318590212,1318808997,1319027792,1319246595,
1319465407,1319684228,1319903059,1320121898,1320340747,1320559605,1320778471,1320997347,1321216232,1321435126,
1321654029,1321872941,1322091862,1322310792,1322529731,1322748679,1322967637,1323186603,1323405579,1323624563,
1323843557,1324062559,1324281571,1324500592,1324719622,1324938661,1325157708,1325376765,1325595831,1325814906,
1326033991,1326253084,1326472186,1326691297,1326910418,1327129547,1327348685,1327567833,1327786989,1328006155,
1328225329,1328444513,1328663706,1328882907,1329102118,1329321338,1329540567,1329759804,1329979051,1330198307,
1330417572,1330636846,1330856129,1331075421,1331294722,1331514033,1331733352,1331952680,1332172017,1332391363,
1332610719,1332830083,1333049456,1333268839,1333488230,1333707630,1333927040,1334146458,1334365886,1334585322,
1334804768,1335024222,1335243686,1335463158,1335682640,1335902131,1336121630,1336341139,1336560657,1336780183,
1336999719,1337219264,1337438817,1337658380,1337877952,1338097532,1338317122,1338536721,1338756329,1338975945,
1339195571,1339415206,1339634850,1339854503,1340074164,1340293835,1340513515,1340733204,1340952901,1341172608,
1341392324,1341612049,1341831783,1342051525,1342271277,1342491038,1342710808,1342930586,1343150374,1343370171,
1343589977,1343809791,1344029615,1344249448,1344469289,1344689140,1344909000,1345128868,1345348746,1345568633,
1345788528,1346008433,1346228346,1346448269,1346668200,1346888141,1347108090,1347328049,1347548016,1347767993,
1347987978,1348207972,1348427976,1348647988,1348868009,1349088040,1349308079,1349528127,1349748184,1349968250,
1350188326,1350408410,1350628503,1350848605,1351068716,1351288836,1351508965,1351729102,1351949249,1352169405,
1352389570,1352609744,1352829926,1353050118,1353270318,1353490528,1353710747,1353930974,1354151210,1354371456,
1354591710,1354811973,1355032246,1355252527,1355472817,1355693116,1355913424,
};
 
static real aa_cs[8] =
{
14386344,14793176,15932125,16497281,16702017,16763133,16775525,16777101
};
 
static real aa_ca[8] =
{
-8631806,-7914349,-5257601,-3051997,-1586692,-687288,-238212,-62075
};
 
static real win[4][36] =
{
{
541609,1798624,3379171,5462936,8388608,12881122,20824265,39123649,129925287,-141788570,-50986933,-32687548,
-24744405,-20251891,-17326219,-15242454,-13661907,-12404893,-11366990,-10483150,-9710514,-9019459,-8388608,-7801881,
-7246655,-6712557,-6190623,-5672661,-5150726,-4616628,-4061402,-3474675,-2843824,-2152769,-1380133,-496293
},
{
541609,1798624,3379171,5462936,8388608,12881122,20824265,39123649,129925287,-141788570,-50986933,-32687548,
-24744405,-20251891,-17326219,-15242454,-13661907,-12404893,-11377819,-10573609,-9946281,-9457165,-9079764,-8795700,
-8518771,-7816938,-6661470,-5111526,-3237882,-1121518,
},
{
1798624,8388608,39123649,-50986933,-20251891,-13661907,-10483150,-8388608,-6712557,-5150726,-3474675,-1380133,
},
{
0,0,0,0,0,0,5058839,24594154,117073194,-152572757,-59375541,-38425694,
-27896396,-21920489,-18167045,-15612533,-13779795,-12416710,-11366990,-10483150,-9710514,-9019459,-8388608,-7801881,
-7246655,-6712557,-6190623,-5672661,-5150726,-4616628,-4061402,-3474675,-2843824,-2152769,-1380133,-496293
}
};
 
const real COS9[9] =
{
16777216,16522332,15765426,14529495,12852093,10784187,8388608,5738146,2913333
};
 
static const real COS6_1 = 14529495;
 
static const real COS6_2 = 8388608;
 
const real tfcos36[9] =
{
8420651,8684526,9255805,10240599,11863283,14625092,19849138,32411092,96248483
};
 
static const real tfcos12[3] =
{
8684526,11863283,32411092
};
 
#ifdef NEW_DCT9
static const real cos9[3] =
{
15765426,-2913333,-12852093
};
 
static const real cos18[3] =
{
16522332,-5738146,-10784187
};
#endif
 
static const real tan1_1[16] =
{
0,6925,11994,16384,20774,25843,32768,44762,77530,2147483647,-44762,-11994,0,6925,11994,16384
};
 
static const real tan2_1[16] =
{
32768,25843,20774,16384,11994,6925,0,-11994,-44762,2147483647,77530,44762,32768,25843,20774,16384
};
 
static const real tan1_2[16] =
{
0,9793,16962,23170,29379,36548,46341,63303,109644,2147483647,-63303,-16962,0,9793,16962,23170
};
 
static real tan2_2[16] =
{
46341,36548,29379,23170,16962,9793,0,-16962,-63303,2147483647,109644,63303,46341,36548,29379,23170
};
 
static const real pow1_1[2][16] =
{
{32768,27554,32768,23170,32768,19484,32768,16384,32768,13777,32768,11585,32768,9742,32768,8192},
{32768,23170,32768,16384,32768,11585,32768,8192,32768,5793,32768,4096,32768,2896,32768,2048}
};
 
static const real pow2_1[2][16] =
{
{32768,32768,27554,32768,23170,32768,19484,32768,16384,32768,13777,32768,11585,32768,9742,32768},
{32768,32768,23170,32768,16384,32768,11585,32768,8192,32768,5793,32768,4096,32768,2896,32768}
};
 
static const real pow1_2[2][16] =
{
{46341,38968,46341,32768,46341,27554,46341,23170,46341,19484,46341,16384,46341,13777,46341,11585},
{46341,32768,46341,23170,46341,16384,46341,11585,46341,8192,46341,5793,46341,4096,46341,2896}
};
 
static const real pow2_2[2][16] =
{
{46341,46341,38968,46341,32768,46341,27554,46341,23170,46341,19484,46341,16384,46341,13777,46341},
{46341,46341,32768,46341,23170,46341,16384,46341,11585,46341,8192,46341,5793,46341,4096,46341}
};
 
static const real gainpow2[256+118+4] =
{
1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,
1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,
1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,
1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,
1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,
1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,1518500250,1276901417,1073741824,1805811301,
1518500250,1276901417,1073741824,902905651,759250125,638450708,536870912,451452825,379625062,319225354,
268435456,225726413,189812531,159612677,134217728,112863206,94906266,79806339,67108864,56431603,
47453133,39903169,33554432,28215802,23726566,19951585,16777216,14107901,11863283,9975792,
8388608,7053950,5931642,4987896,4194304,3526975,2965821,2493948,2097152,1763488,
1482910,1246974,1048576,881744,741455,623487,524288,440872,370728,311744,
262144,220436,185364,155872,131072,110218,92682,77936,65536,55109,
46341,38968,32768,27554,23170,19484,16384,13777,11585,9742,
8192,6889,5793,4871,4096,3444,2896,2435,2048,1722,
1448,1218,1024,861,724,609,512,431,362,304,
256,215,181,152,128,108,91,76,64,54,
45,38,32,27,23,19,16,13,11,10,
8,7,6,5,4,3,3,2,2,2,
1,1,1,1,1,1,1,
};
 
#else
static real ispow[8207];
static real aa_ca[8],aa_cs[8];
static real win[4][36];
static real win1[4][36];
real COS9[9]; /* dct36_3dnow wants to use that */
static real COS6_1,COS6_2;
real tfcos36[9]; /* dct36_3dnow wants to use that */
static real tfcos12[3];
#ifdef NEW_DCT9
static real cos9[3],cos18[3];
static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
#endif
#endif
 
static real win1[4][36];
 
static const char gainpow2_scale[256+118+4+1] =
{
19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,
27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,
34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,0
};
 
#endif
/programs/develop/libraries/libmpg123/layer1.c
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;
}
 
 
/programs/develop/libraries/libmpg123/layer2.c
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 */
/programs/develop/libraries/libmpg123/layer3.c
0,0 → 1,2056
/*
leyer3.c: the layer 3 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
 
Dear visitor:
If you feel you don't understand fully the works of this file, your feeling might be correct.
 
Optimize-TODO: put short bands into the band-field without the stride of 3 reals
Length-optimze: unify long and short band code where it is possible
 
The int-vs-pointer situation has to be cleaned up.
*/
 
#include "mpg123lib_intern.h"
#include "huffman.h"
#include "getbits.h"
#include "debug.h"
 
/* define CUT_SFB21 if you want to cut-off the frequency above 16kHz */
#if 0
#define CUT_SFB21
#endif
 
#ifdef REAL_IS_FIXED
#define NEW_DCT9
#include "l3_integer_tables.h"
#else
/* static one-time calculated tables... or so */
static real ispow[8207];
static real aa_ca[8],aa_cs[8];
static real win[4][36];
static real win1[4][36];
real COS9[9]; /* dct36_3dnow wants to use that */
static real COS6_1,COS6_2;
real tfcos36[9]; /* dct36_3dnow wants to use that */
static real tfcos12[3];
#define NEW_DCT9
#ifdef NEW_DCT9
static real cos9[3],cos18[3];
static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
#endif
#endif
 
/* Decoder state data, living on the stack of do_layer3. */
 
struct gr_info_s
{
int scfsi;
unsigned part2_3_length;
unsigned big_values;
unsigned scalefac_compress;
unsigned block_type;
unsigned mixed_block_flag;
unsigned table_select[3];
unsigned subblock_gain[3];
unsigned maxband[3];
unsigned maxbandl;
unsigned maxb;
unsigned region1start;
unsigned region2start;
unsigned preflag;
unsigned scalefac_scale;
unsigned count1table_select;
real *full_gain[3];
real *pow2gain;
};
 
struct III_sideinfo
{
unsigned main_data_begin;
unsigned private_bits;
/* Hm, funny... struct inside struct... */
struct { struct gr_info_s gr[2]; } ch[2];
};
 
struct bandInfoStruct
{
int longIdx[23];
int longDiff[22];
int shortIdx[14];
int shortDiff[13];
};
 
/* Techy details about our friendly MPEG data. Fairly constant over the years;-) */
const struct bandInfoStruct bandInfo[9] =
{
{ /* MPEG 1.0 */
{0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
{4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
{0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
{4,4,4,4,6,8,10,12,14,18,22,30,56}
},
{
{0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
{4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
{0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
{4,4,4,4,6,6,10,12,14,16,20,26,66}
},
{
{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},
{4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26},
{0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3},
{4,4,4,4,6,8,12,16,20,26,34,42,12}
},
{ /* MPEG 2.0 */
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
{0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
{4,4,4,6,6,8,10,14,18,26,32,42,18 }
},
{ /* Twiddling 3 values here (not just 330->332!) fixed bug 1895025. */
{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576},
{6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 },
{0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3},
{4,4,4,6,8,10,12,14,18,24,32,44,12 }
},
{
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
{0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
{4,4,4,6,8,10,12,14,18,24,30,40,18 }
},
{ /* MPEG 2.5 */
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
{4,4,4,6,8,10,12,14,18,24,30,40,18}
},
{
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
{4,4,4,6,8,10,12,14,18,24,30,40,18}
},
{
{0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
{12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
{0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
{8,8,8,12,16,20,24,28,36,2,2,2,26}
}
};
 
static int mapbuf0[9][152];
static int mapbuf1[9][156];
static int mapbuf2[9][44];
static int *map[9][3];
static int *mapend[9][3];
 
static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
 
/* Some helpers used in init_layer3 */
 
#ifdef OPT_MMXORSSE
real init_layer3_gainpow2_mmx(mpg123_handle *fr, int i)
{
if(!fr->p.down_sample) return DOUBLE_TO_REAL(16384.0 * pow((double)2.0,-0.25 * (double) (i+210) ));
else return DOUBLE_TO_REAL(pow((double)2.0,-0.25 * (double) (i+210)));
}
#endif
 
real init_layer3_gainpow2(mpg123_handle *fr, int i)
{
#if defined(REAL_IS_FIXED) && defined(PRECALC_TABLES)
return gainpow2[i+256];
#else
return DOUBLE_TO_REAL_SCALE_LAYER3(pow((double)2.0,-0.25 * (double) (i+210)),i+256);
#endif
}
 
 
/* init tables for layer-3 ... specific with the downsampling... */
void init_layer3(void)
{
int i,j,k,l;
 
#if !defined(REAL_IS_FIXED) || !defined(PRECALC_TABLES)
for(i=0;i<8207;i++)
ispow[i] = DOUBLE_TO_REAL_POW43(pow((double)i,(double)4.0/3.0));
 
for(i=0;i<8;i++)
{
const double Ci[8] = {-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
double sq = sqrt(1.0+Ci[i]*Ci[i]);
aa_cs[i] = DOUBLE_TO_REAL(1.0/sq);
aa_ca[i] = DOUBLE_TO_REAL(Ci[i]/sq);
}
 
for(i=0;i<18;i++)
{
win[0][i] = win[1][i] =
DOUBLE_TO_REAL( 0.5*sin(M_PI/72.0 * (double)(2*(i+0) +1)) / cos(M_PI * (double)(2*(i+0) +19) / 72.0) );
win[0][i+18] = win[3][i+18] =
DOUBLE_TO_REAL( 0.5*sin(M_PI/72.0 * (double)(2*(i+18)+1)) / cos(M_PI * (double)(2*(i+18)+19) / 72.0) );
}
for(i=0;i<6;i++)
{
win[1][i+18] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ));
win[3][i+12] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ));
win[1][i+24] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 ));
win[1][i+30] = win[3][i] = DOUBLE_TO_REAL(0.0);
win[3][i+6 ] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+1 ) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 ));
}
 
for(i=0;i<9;i++)
COS9[i] = DOUBLE_TO_REAL(cos( M_PI / 18.0 * (double) i));
 
for(i=0;i<9;i++)
tfcos36[i] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ));
 
for(i=0;i<3;i++)
tfcos12[i] = DOUBLE_TO_REAL(0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ));
 
COS6_1 = DOUBLE_TO_REAL(cos( M_PI / 6.0 * (double) 1));
COS6_2 = DOUBLE_TO_REAL(cos( M_PI / 6.0 * (double) 2));
 
#ifdef NEW_DCT9
cos9[0] = DOUBLE_TO_REAL(cos(1.0*M_PI/9.0));
cos9[1] = DOUBLE_TO_REAL(cos(5.0*M_PI/9.0));
cos9[2] = DOUBLE_TO_REAL(cos(7.0*M_PI/9.0));
cos18[0] = DOUBLE_TO_REAL(cos(1.0*M_PI/18.0));
cos18[1] = DOUBLE_TO_REAL(cos(11.0*M_PI/18.0));
cos18[2] = DOUBLE_TO_REAL(cos(13.0*M_PI/18.0));
#endif
 
for(i=0;i<12;i++)
{
win[2][i] = DOUBLE_TO_REAL(0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ));
}
 
for(i=0;i<16;i++)
{
double t = tan( (double) i * M_PI / 12.0 );
tan1_1[i] = DOUBLE_TO_REAL_15(t / (1.0+t));
tan2_1[i] = DOUBLE_TO_REAL_15(1.0 / (1.0 + t));
tan1_2[i] = DOUBLE_TO_REAL_15(M_SQRT2 * t / (1.0+t));
tan2_2[i] = DOUBLE_TO_REAL_15(M_SQRT2 / (1.0 + t));
 
for(j=0;j<2;j++)
{
double base = pow(2.0,-0.25*(j+1.0));
double p1=1.0,p2=1.0;
if(i > 0)
{
if( i & 1 ) p1 = pow(base,(i+1.0)*0.5);
else p2 = pow(base,i*0.5);
}
pow1_1[j][i] = DOUBLE_TO_REAL_15(p1);
pow2_1[j][i] = DOUBLE_TO_REAL_15(p2);
pow1_2[j][i] = DOUBLE_TO_REAL_15(M_SQRT2 * p1);
pow2_2[j][i] = DOUBLE_TO_REAL_15(M_SQRT2 * p2);
}
}
#endif
 
for(j=0;j<4;j++)
{
const int len[4] = { 36,36,12,36 };
for(i=0;i<len[j];i+=2) win1[j][i] = + win[j][i];
 
for(i=1;i<len[j];i+=2) win1[j][i] = - win[j][i];
}
 
for(j=0;j<9;j++)
{
const struct bandInfoStruct *bi = &bandInfo[j];
int *mp;
int cb,lwin;
const int *bdf;
 
mp = map[j][0] = mapbuf0[j];
bdf = bi->longDiff;
for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++)
{
*mp++ = (*bdf) >> 1;
*mp++ = i;
*mp++ = 3;
*mp++ = cb;
}
bdf = bi->shortDiff+3;
for(cb=3;cb<13;cb++)
{
int l = (*bdf++) >> 1;
for(lwin=0;lwin<3;lwin++)
{
*mp++ = l;
*mp++ = i + lwin;
*mp++ = lwin;
*mp++ = cb;
}
i += 6*l;
}
mapend[j][0] = mp;
 
mp = map[j][1] = mapbuf1[j];
bdf = bi->shortDiff+0;
for(i=0,cb=0;cb<13;cb++)
{
int l = (*bdf++) >> 1;
for(lwin=0;lwin<3;lwin++)
{
*mp++ = l;
*mp++ = i + lwin;
*mp++ = lwin;
*mp++ = cb;
}
i += 6*l;
}
mapend[j][1] = mp;
 
mp = map[j][2] = mapbuf2[j];
bdf = bi->longDiff;
for(cb = 0; cb < 22 ; cb++)
{
*mp++ = (*bdf++) >> 1;
*mp++ = cb;
}
mapend[j][2] = mp;
}
 
/* Now for some serious loopings! */
for(i=0;i<5;i++)
for(j=0;j<6;j++)
for(k=0;k<6;k++)
{
int n = k + j * 6 + i * 36;
i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
}
for(i=0;i<4;i++)
for(j=0;j<4;j++)
for(k=0;k<4;k++)
{
int n = k + j * 4 + i * 16;
i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
}
for(i=0;i<4;i++)
for(j=0;j<3;j++)
{
int n = j + i * 3;
i_slen2[n+244] = i|(j<<3) | (5<<12);
n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
}
for(i=0;i<5;i++)
for(j=0;j<5;j++)
for(k=0;k<4;k++)
for(l=0;l<4;l++)
{
int n = l + k * 4 + j * 16 + i * 80;
n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
}
for(i=0;i<5;i++)
for(j=0;j<5;j++)
for(k=0;k<4;k++)
{
int n = k + j * 4 + i * 20;
n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
}
}
 
 
void init_layer3_stuff(mpg123_handle *fr, real (*gainpow2)(mpg123_handle *fr, int i))
{
int i,j;
 
for(i=-256;i<118+4;i++) fr->gainpow2[i+256] = gainpow2(fr,i);
 
for(j=0;j<9;j++)
{
for(i=0;i<23;i++)
{
fr->longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
if(fr->longLimit[j][i] > (fr->down_sample_sblimit) )
fr->longLimit[j][i] = fr->down_sample_sblimit;
}
for(i=0;i<14;i++)
{
fr->shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
if(fr->shortLimit[j][i] > (fr->down_sample_sblimit) )
fr->shortLimit[j][i] = fr->down_sample_sblimit;
}
}
}
 
/*
Observe!
Now come the actualy decoding routines.
*/
 
/* read additional side information (for MPEG 1 and MPEG 2) */
static int III_get_side_info(mpg123_handle *fr, struct III_sideinfo *si,int stereo, int ms_stereo,long sfreq,int single)
{
int ch, gr;
int powdiff = (single == SINGLE_MIX) ? 4 : 0;
 
const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
const int *tab = tabs[fr->lsf];
 
si->main_data_begin = getbits(fr, tab[1]);
 
if(si->main_data_begin > fr->bitreservoir)
{
if(VERBOSE2) fprintf(stderr, "Note: missing %d bytes in bit reservoir for frame %li\n", (int)(si->main_data_begin - fr->bitreservoir), (long)fr->num);
 
/* overwrite main_data_begin for the really available bit reservoir */
backbits(fr, tab[1]);
if(fr->lsf == 0)
{
fr->wordpointer[0] = (unsigned char) (fr->bitreservoir >> 1);
fr->wordpointer[1] = (unsigned char) ((fr->bitreservoir & 1) << 7);
}
else fr->wordpointer[0] = (unsigned char) fr->bitreservoir;
 
/* zero "side-info" data for a silence-frame
without touching audio data used as bit reservoir for following frame */
memset(fr->wordpointer+2, 0, fr->ssize-2);
 
/* reread the new bit reservoir offset */
si->main_data_begin = getbits(fr, tab[1]);
}
 
/* Keep track of the available data bytes for the bit reservoir.
Think: Substract the 2 crc bytes in parser already? */
fr->bitreservoir = fr->bitreservoir + fr->framesize - fr->ssize - (fr->error_protection ? 2 : 0);
/* Limit the reservoir to the max for MPEG 1.0 or 2.x . */
if(fr->bitreservoir > (unsigned int) (fr->lsf == 0 ? 511 : 255))
fr->bitreservoir = (fr->lsf == 0 ? 511 : 255);
 
/* Now back into less commented territory. It's code. It works. */
 
if (stereo == 1)
si->private_bits = getbits_fast(fr, tab[2]);
else
si->private_bits = getbits_fast(fr, tab[3]);
 
if(!fr->lsf) for(ch=0; ch<stereo; ch++)
{
si->ch[ch].gr[0].scfsi = -1;
si->ch[ch].gr[1].scfsi = getbits_fast(fr, 4);
}
 
for (gr=0; gr<tab[0]; gr++)
for (ch=0; ch<stereo; ch++)
{
register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
 
gr_info->part2_3_length = getbits(fr, 12);
gr_info->big_values = getbits(fr, 9);
if(gr_info->big_values > 288)
{
error("big_values too large!");
gr_info->big_values = 288;
}
gr_info->pow2gain = fr->gainpow2+256 - getbits_fast(fr, 8) + powdiff;
if(ms_stereo) gr_info->pow2gain += 2;
 
gr_info->scalefac_compress = getbits(fr, tab[4]);
 
if(get1bit(fr))
{ /* window switch flag */
int i;
gr_info->block_type = getbits_fast(fr, 2);
gr_info->mixed_block_flag = get1bit(fr);
gr_info->table_select[0] = getbits_fast(fr, 5);
gr_info->table_select[1] = getbits_fast(fr, 5);
/*
table_select[2] not needed, because there is no region2,
but to satisfy some verification tools we set it either.
*/
gr_info->table_select[2] = 0;
for(i=0;i<3;i++)
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(fr, 3)<<3);
 
if(gr_info->block_type == 0)
{
error("Blocktype == 0 and window-switching == 1 not allowed.");
return 1;
}
 
/* region_count/start parameters are implicit in this case. */
if( (!fr->lsf || (gr_info->block_type == 2)) && !fr->mpeg25)
{
gr_info->region1start = 36>>1;
gr_info->region2start = 576>>1;
}
else
{
if(fr->mpeg25)
{
int r0c,r1c;
if((gr_info->block_type == 2) && (!gr_info->mixed_block_flag) ) r0c = 5;
else r0c = 7;
 
r1c = 20 - r0c;
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
}
else
{
gr_info->region1start = 54>>1;
gr_info->region2start = 576>>1;
}
}
}
else
{
int i,r0c,r1c;
for (i=0; i<3; i++)
gr_info->table_select[i] = getbits_fast(fr, 5);
 
r0c = getbits_fast(fr, 4);
r1c = getbits_fast(fr, 3);
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
 
if(r0c + r1c + 2 > 22) gr_info->region2start = 576>>1;
else gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
 
gr_info->block_type = 0;
gr_info->mixed_block_flag = 0;
}
if(!fr->lsf) gr_info->preflag = get1bit(fr);
 
gr_info->scalefac_scale = get1bit(fr);
gr_info->count1table_select = get1bit(fr);
}
return 0;
}
 
 
/* read scalefactors */
static int III_get_scale_factors_1(mpg123_handle *fr, int *scf,struct gr_info_s *gr_info,int ch,int gr)
{
const unsigned char slen[2][16] =
{
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
};
int numbits;
int num0 = slen[0][gr_info->scalefac_compress];
int num1 = slen[1][gr_info->scalefac_compress];
 
if(gr_info->block_type == 2)
{
int i=18;
numbits = (num0 + num1) * 18;
 
if(gr_info->mixed_block_flag)
{
for (i=8;i;i--)
*scf++ = getbits_fast(fr, num0);
 
i = 9;
numbits -= num0; /* num0 * 17 + num1 * 18 */
}
 
for(;i;i--) *scf++ = getbits_fast(fr, num0);
 
for(i = 18; i; i--) *scf++ = getbits_fast(fr, num1);
 
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
}
else
{
int i;
int scfsi = gr_info->scfsi;
 
if(scfsi < 0)
{ /* scfsi < 0 => granule == 0 */
for(i=11;i;i--) *scf++ = getbits_fast(fr, num0);
 
for(i=10;i;i--) *scf++ = getbits_fast(fr, num1);
 
numbits = (num0 + num1) * 10 + num0;
*scf++ = 0;
}
else
{
numbits = 0;
if(!(scfsi & 0x8))
{
for (i=0;i<6;i++) *scf++ = getbits_fast(fr, num0);
 
numbits += num0 * 6;
}
else scf += 6;
 
if(!(scfsi & 0x4))
{
for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num0);
 
numbits += num0 * 5;
}
else scf += 5;
 
if(!(scfsi & 0x2))
{
for(i=0;i<5;i++) *scf++ = getbits_fast(fr, num1);
 
numbits += num1 * 5;
}
else scf += 5;
 
if(!(scfsi & 0x1))
{
for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num1);
 
numbits += num1 * 5;
}
else scf += 5;
 
*scf++ = 0; /* no l[21] in original sources */
}
}
return numbits;
}
 
 
static int III_get_scale_factors_2(mpg123_handle *fr, int *scf,struct gr_info_s *gr_info,int i_stereo)
{
const unsigned char *pnt;
int i,j,n=0,numbits=0;
unsigned int slen;
 
const unsigned char stab[3][6][4] =
{
{
{ 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0},
{ 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0}
},
{
{ 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0},
{12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0}
},
{
{ 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0},
{ 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0}
}
};
 
if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
slen = i_slen2[gr_info->scalefac_compress>>1];
else
slen = n_slen2[gr_info->scalefac_compress];
 
gr_info->preflag = (slen>>15) & 0x1;
 
n = 0;
if( gr_info->block_type == 2 )
{
n++;
if(gr_info->mixed_block_flag) n++;
}
 
pnt = stab[n][(slen>>12)&0x7];
 
for(i=0;i<4;i++)
{
int num = slen & 0x7;
slen >>= 3;
if(num)
{
for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(fr, num);
 
numbits += pnt[i] * num;
}
else
for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0;
}
n = (n << 1) + 1;
for(i=0;i<n;i++) *scf++ = 0;
 
return numbits;
}
 
static const int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
static const int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
/*
Dequantize samples
...includes Huffman decoding
*/
 
/* 24 is enough because tab13 has max. a 19 bit huffvector */
#define BITSHIFT ((sizeof(long)-1)*8)
#define REFRESH_MASK \
while(num < BITSHIFT) { \
mask |= ((unsigned long)getbyte(fr))<<(BITSHIFT-num); \
num += 8; \
part2remain -= 8; }
 
static int III_dequantize_sample(mpg123_handle *fr, real xr[SBLIMIT][SSLIMIT],int *scf, struct gr_info_s *gr_info,int sfreq,int part2bits)
{
int shift = 1 + gr_info->scalefac_scale;
real *xrpnt = (real *) xr;
int l[3],l3;
int part2remain = gr_info->part2_3_length - part2bits;
int *me;
#ifdef REAL_IS_FIXED
int gainpow2_scale_idx = 378;
#endif
 
/* mhipp tree has this split up a bit... */
int num=getbitoffset(fr);
long mask;
/* We must split this, because for num==0 the shift is undefined if you do it in one step. */
mask = ((unsigned long) getbits(fr, num))<<BITSHIFT;
mask <<= 8-num;
part2remain -= num;
 
{
int bv = gr_info->big_values;
int region1 = gr_info->region1start;
int region2 = gr_info->region2start;
if(region1 > region2)
{
/*
That's not optimal: it fixes a segfault with fuzzed data, but also apparently triggers where it shouldn't, see bug 1641196.
The benefit of not crashing / having this security risk is bigger than these few frames of a lame-3.70 file that aren't audible anyway.
But still, I want to know if indeed this check or the old lame is at fault.
*/
error("You got some really nasty file there... region1>region2!");
return 1;
}
l3 = ((576>>1)-bv)>>1;
 
/* we may lose the 'odd' bit here !! check this later again */
if(bv <= region1)
{
l[0] = bv;
l[1] = 0;
l[2] = 0;
}
else
{
l[0] = region1;
if(bv <= region2)
{
l[1] = bv - l[0];
l[2] = 0;
}
else
{
l[1] = region2 - l[0];
l[2] = bv - region2;
}
}
}
if(gr_info->block_type == 2)
{
/* decoding with short or mixed mode BandIndex table */
int i,max[4];
int step=0,lwin=3,cb=0;
register real v = 0.0;
register int *m,mc;
 
if(gr_info->mixed_block_flag)
{
max[3] = -1;
max[0] = max[1] = max[2] = 2;
m = map[sfreq][0];
me = mapend[sfreq][0];
}
else
{
max[0] = max[1] = max[2] = max[3] = -1;
/* max[3] not really needed in this case */
m = map[sfreq][1];
me = mapend[sfreq][1];
}
 
mc = 0;
for(i=0;i<2;i++)
{
int lp = l[i];
struct newhuff *h = ht+gr_info->table_select[i];
for(;lp;lp--,mc--)
{
register int x,y;
if( (!mc) )
{
mc = *m++;
xrpnt = ((real *) xr) + (*m++);
lwin = *m++;
cb = *m++;
if(lwin == 3)
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->pow2gain[(*scf++) << shift];
step = 1;
}
else
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->full_gain[lwin][(*scf++) << shift];
step = 3;
}
}
{
register short *val = h->table;
REFRESH_MASK;
while((y=*val++)<0)
{
if (mask < 0) val -= y;
 
num--;
mask <<= 1;
}
x = y >> 4;
y &= 0xf;
}
if(x == 15 && h->linbits)
{
max[lwin] = cb;
REFRESH_MASK;
x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
num -= h->linbits+1;
mask <<= h->linbits;
if(mask < 0) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
 
mask <<= 1;
}
else if(x)
{
max[lwin] = cb;
if(mask < 0) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
 
num--;
mask <<= 1;
}
else *xrpnt = DOUBLE_TO_REAL(0.0);
 
xrpnt += step;
if(y == 15 && h->linbits)
{
max[lwin] = cb;
REFRESH_MASK;
y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
num -= h->linbits+1;
mask <<= h->linbits;
if(mask < 0) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
 
mask <<= 1;
}
else if(y)
{
max[lwin] = cb;
if(mask < 0) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
 
num--;
mask <<= 1;
}
else *xrpnt = DOUBLE_TO_REAL(0.0);
 
xrpnt += step;
}
}
 
for(;l3 && (part2remain+num > 0);l3--)
{
struct newhuff* h;
register short* val;
register short a;
/*
This is only a humble hack to prevent a special segfault.
More insight into the real workings is still needed.
Especially why there are (valid?) files that make xrpnt exceed the array with 4 bytes without segfaulting, more seems to be really bad, though.
*/
#ifdef DEBUG
if(!(xrpnt < &xr[SBLIMIT][0]))
{
if(VERBOSE) debug2("attempted soft xrpnt overflow (%p !< %p) ?", (void*) xrpnt, (void*) &xr[SBLIMIT][0]);
}
#endif
if(!(xrpnt < &xr[SBLIMIT][0]+5))
{
if(NOQUIET) error2("attempted xrpnt overflow (%p !< %p)", (void*) xrpnt, (void*) &xr[SBLIMIT][0]);
return 2;
}
h = htc+gr_info->count1table_select;
val = h->table;
 
REFRESH_MASK;
while((a=*val++)<0)
{
if(mask < 0) val -= a;
 
num--;
mask <<= 1;
}
if(part2remain+num <= 0)
{
num -= part2remain+num;
break;
}
 
for(i=0;i<4;i++)
{
if(!(i & 1))
{
if(!mc)
{
mc = *m++;
xrpnt = ((real *) xr) + (*m++);
lwin = *m++;
cb = *m++;
if(lwin == 3)
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->pow2gain[(*scf++) << shift];
step = 1;
}
else
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->full_gain[lwin][(*scf++) << shift];
step = 3;
}
}
mc--;
}
if( (a & (0x8>>i)) )
{
max[lwin] = cb;
if(part2remain+num <= 0)
break;
 
if(mask < 0) *xrpnt = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
else *xrpnt = REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
 
num--;
mask <<= 1;
}
else *xrpnt = DOUBLE_TO_REAL(0.0);
 
xrpnt += step;
}
}
 
if(lwin < 3)
{ /* short band? */
while(1)
{
for(;mc > 0;mc--)
{
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; /* short band -> step=3 */
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3;
}
if(m >= me)
break;
 
mc = *m++;
xrpnt = ((real *) xr) + *m++;
if(*m++ == 0)
break; /* optimize: field will be set to zero at the end of the function */
 
m++; /* cb */
}
}
 
gr_info->maxband[0] = max[0]+1;
gr_info->maxband[1] = max[1]+1;
gr_info->maxband[2] = max[2]+1;
gr_info->maxbandl = max[3]+1;
 
{
int rmax = max[0] > max[1] ? max[0] : max[1];
rmax = (rmax > max[2] ? rmax : max[2]) + 1;
gr_info->maxb = rmax ? fr->shortLimit[sfreq][rmax] : fr->longLimit[sfreq][max[3]+1];
}
 
}
else
{
/* decoding with 'long' BandIndex table (block_type != 2) */
const int *pretab = gr_info->preflag ? pretab1 : pretab2;
int i,max = -1;
int cb = 0;
int *m = map[sfreq][2];
register real v = 0.0;
int mc = 0;
 
/* long hash table values */
for(i=0;i<3;i++)
{
int lp = l[i];
struct newhuff *h = ht+gr_info->table_select[i];
 
for(;lp;lp--,mc--)
{
int x,y;
if(!mc)
{
mc = *m++;
cb = *m++;
#ifdef CUT_SFB21
if(cb == 21)
v = 0.0;
else
#endif
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->pow2gain[(*(scf++) + (*pretab++)) << shift];
}
}
{
register short *val = h->table;
REFRESH_MASK;
while((y=*val++)<0)
{
if (mask < 0) val -= y;
 
num--;
mask <<= 1;
}
x = y >> 4;
y &= 0xf;
}
 
if(x == 15 && h->linbits)
{
max = cb;
REFRESH_MASK;
x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
num -= h->linbits+1;
mask <<= h->linbits;
if(mask < 0) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
 
mask <<= 1;
}
else if(x)
{
max = cb;
if(mask < 0) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
num--;
 
mask <<= 1;
}
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
 
if(y == 15 && h->linbits)
{
max = cb;
REFRESH_MASK;
y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
num -= h->linbits+1;
mask <<= h->linbits;
if(mask < 0) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
 
mask <<= 1;
}
else if(y)
{
max = cb;
if(mask < 0) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
 
num--;
mask <<= 1;
}
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
}
}
 
/* short (count1table) values */
for(;l3 && (part2remain+num > 0);l3--)
{
struct newhuff *h = htc+gr_info->count1table_select;
register short *val = h->table,a;
 
REFRESH_MASK;
while((a=*val++)<0)
{
if (mask < 0) val -= a;
 
num--;
mask <<= 1;
}
if(part2remain+num <= 0)
{
num -= part2remain+num;
break;
}
 
for(i=0;i<4;i++)
{
if(!(i & 1))
{
if(!mc)
{
mc = *m++;
cb = *m++;
#ifdef CUT_SFB21
if(cb == 21)
v = 0.0;
else
#endif
{
#ifdef REAL_IS_FIXED
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
#endif
v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
}
}
mc--;
}
if( (a & (0x8>>i)) )
{
max = cb;
if(part2remain+num <= 0)
break;
 
if(mask < 0) *xrpnt++ = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
else *xrpnt++ = REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
 
num--;
mask <<= 1;
}
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
}
}
 
gr_info->maxbandl = max+1;
gr_info->maxb = fr->longLimit[sfreq][gr_info->maxbandl];
}
 
part2remain += num;
backbits(fr, num);
num = 0;
 
while(xrpnt < &xr[SBLIMIT][0])
*xrpnt++ = DOUBLE_TO_REAL(0.0);
 
while( part2remain > 16 )
{
skipbits(fr, 16); /* Dismiss stuffing Bits */
part2remain -= 16;
}
if(part2remain > 0) skipbits(fr, part2remain);
else if(part2remain < 0)
{
debug1("Can't rewind stream by %d bits!",-part2remain);
return 1; /* -> error */
}
return 0;
}
 
 
/* calculate real channel values for Joint-I-Stereo-mode */
static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
{
real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
const struct bandInfoStruct *bi = &bandInfo[sfreq];
 
const real *tab1,*tab2;
 
#if 1
int tab;
/* TODO: optimize as static */
const real *tabs[3][2][2] =
{
{ { tan1_1,tan2_1 } , { tan1_2,tan2_2 } },
{ { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } },
{ { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } }
};
 
tab = lsf + (gr_info->scalefac_compress & lsf);
tab1 = tabs[tab][ms_stereo][0];
tab2 = tabs[tab][ms_stereo][1];
#else
if(lsf)
{
int p = gr_info->scalefac_compress & 0x1;
if(ms_stereo)
{
tab1 = pow1_2[p];
tab2 = pow2_2[p];
}
else
{
tab1 = pow1_1[p];
tab2 = pow2_1[p];
}
}
else
{
if(ms_stereo)
{
tab1 = tan1_2;
tab2 = tan2_2;
}
else
{
tab1 = tan1_1;
tab2 = tan2_1;
}
}
#endif
 
if(gr_info->block_type == 2)
{
int lwin,do_l = 0;
if( gr_info->mixed_block_flag ) do_l = 1;
 
for(lwin=0;lwin<3;lwin++)
{ /* process each window */
/* get first band with zero values */
int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
if(sfb > 3) do_l = 0;
 
for(;sfb<12;sfb++)
{
is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
if(is_p != 7)
{
real t1,t2;
sb = bi->shortDiff[sfb];
idx = bi->shortIdx[sfb] + lwin;
t1 = tab1[is_p]; t2 = tab2[is_p];
for (; sb > 0; sb--,idx+=3)
{
real v = xr[0][idx];
xr[0][idx] = REAL_MUL_15(v, t1);
xr[1][idx] = REAL_MUL_15(v, t2);
}
}
}
 
#if 1
/* in the original: copy 10 to 11 , here: copy 11 to 12
maybe still wrong??? (copy 12 to 13?) */
is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
sb = bi->shortDiff[12];
idx = bi->shortIdx[12] + lwin;
#else
is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
sb = bi->shortDiff[11];
idx = bi->shortIdx[11] + lwin;
#endif
if(is_p != 7)
{
real t1,t2;
t1 = tab1[is_p]; t2 = tab2[is_p];
for( ; sb > 0; sb--,idx+=3 )
{
real v = xr[0][idx];
xr[0][idx] = REAL_MUL_15(v, t1);
xr[1][idx] = REAL_MUL_15(v, t2);
}
}
} /* end for(lwin; .. ; . ) */
 
/* also check l-part, if ALL bands in the three windows are 'empty' and mode = mixed_mode */
if(do_l)
{
int sfb = gr_info->maxbandl;
int idx;
if(sfb > 21) return; /* similarity fix related to CVE-2006-1655 */
 
idx = bi->longIdx[sfb];
for( ; sfb<8; sfb++ )
{
int sb = bi->longDiff[sfb];
int is_p = scalefac[sfb]; /* scale: 0-15 */
if(is_p != 7)
{
real t1,t2;
t1 = tab1[is_p]; t2 = tab2[is_p];
for( ; sb > 0; sb--,idx++)
{
real v = xr[0][idx];
xr[0][idx] = REAL_MUL_15(v, t1);
xr[1][idx] = REAL_MUL_15(v, t2);
}
}
else idx += sb;
}
}
}
else
{ /* ((gr_info->block_type != 2)) */
int sfb = gr_info->maxbandl;
int is_p,idx;
if(sfb > 21) return; /* tightened fix for CVE-2006-1655 */
 
idx = bi->longIdx[sfb];
for ( ; sfb<21; sfb++)
{
int sb = bi->longDiff[sfb];
is_p = scalefac[sfb]; /* scale: 0-15 */
if(is_p != 7)
{
real t1,t2;
t1 = tab1[is_p]; t2 = tab2[is_p];
for( ; sb > 0; sb--,idx++)
{
real v = xr[0][idx];
xr[0][idx] = REAL_MUL_15(v, t1);
xr[1][idx] = REAL_MUL_15(v, t2);
}
}
else idx += sb;
}
 
is_p = scalefac[20];
if(is_p != 7)
{ /* copy l-band 20 to l-band 21 */
int sb;
real t1 = tab1[is_p],t2 = tab2[is_p];
 
for( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
{
real v = xr[0][idx];
xr[0][idx] = REAL_MUL_15(v, t1);
xr[1][idx] = REAL_MUL_15(v, t2);
}
}
}
}
 
 
static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info)
{
int sblim;
 
if(gr_info->block_type == 2)
{
if(!gr_info->mixed_block_flag) return;
 
sblim = 1;
}
else sblim = gr_info->maxb-1;
 
/* 31 alias-reduction operations between each pair of sub-bands */
/* with 8 butterflies between each pair */
 
{
int sb;
real *xr1=(real *) xr[1];
 
for(sb=sblim; sb; sb--,xr1+=10)
{
int ss;
real *cs=aa_cs,*ca=aa_ca;
real *xr2 = xr1;
 
for(ss=7;ss>=0;ss--)
{ /* upper and lower butterfly inputs */
register real bu = *--xr2,bd = *xr1;
*xr2 = REAL_MUL(bu, *cs) - REAL_MUL(bd, *ca);
*xr1++ = REAL_MUL(bd, *cs++) + REAL_MUL(bu, *ca++);
}
}
}
}
 
/*
This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
Saved one multiplication by doing the 'twiddle factor' stuff
together with the window mul. (MH)
 
This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the
9 point IDCT needs to be reduced further. Unfortunately, I don't
know how to do that, because 9 is not an even number. - Jeff.
 
Original Message:
 
9 Point Inverse Discrete Cosine Transform
 
This piece of code is Copyright 1997 Mikko Tommila and is freely usable
by anybody. The algorithm itself is of course in the public domain.
 
Again derived heuristically from the 9-point WFTA.
 
The algorithm is optimized (?) for speed, not for small rounding errors or
good readability.
 
36 additions, 11 multiplications
 
Again this is very likely sub-optimal.
 
The code is optimized to use a minimum number of temporary variables,
so it should compile quite well even on 8-register Intel x86 processors.
This makes the code quite obfuscated and very difficult to understand.
 
References:
[1] S. Winograd: "On Computing the Discrete Fourier Transform",
Mathematics of Computation, Volume 32, Number 141, January 1978,
Pages 175-199
*/
 
/* Calculation of the inverse MDCT
used to be static without 3dnow - does that really matter? */
void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
{
#ifdef NEW_DCT9
real tmp[18];
#endif
 
{
register real *in = inbuf;
 
in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8];
in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5];
in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2];
in[2] +=in[1]; in[1] +=in[0];
 
in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];
 
 
#ifdef NEW_DCT9
#if 1
{
real t3;
{
real t0, t1, t2;
 
t0 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4]));
t1 = REAL_MUL(COS6_2, in[12]);
 
t3 = in[0];
t2 = t3 - t1 - t1;
tmp[1] = tmp[7] = t2 - t0;
tmp[4] = t2 + t0 + t0;
t3 += t1;
 
t2 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2]));
tmp[1] -= t2;
tmp[7] += t2;
}
{
real t0, t1, t2;
 
t0 = REAL_MUL(cos9[0], (in[4] + in[8] ));
t1 = REAL_MUL(cos9[1], (in[8] - in[16]));
t2 = REAL_MUL(cos9[2], (in[4] + in[16]));
 
tmp[2] = tmp[6] = t3 - t0 - t2;
tmp[0] = tmp[8] = t3 + t0 + t1;
tmp[3] = tmp[5] = t3 - t1 + t2;
}
}
{
real t1, t2, t3;
 
t1 = REAL_MUL(cos18[0], (in[2] + in[10]));
t2 = REAL_MUL(cos18[1], (in[10] - in[14]));
t3 = REAL_MUL(COS6_1, in[6]);
 
{
real t0 = t1 + t2 + t3;
tmp[0] += t0;
tmp[8] -= t0;
}
 
t2 -= t3;
t1 -= t3;
 
t3 = REAL_MUL(cos18[2], (in[2] + in[14]));
 
t1 += t3;
tmp[3] += t1;
tmp[5] -= t1;
 
t2 -= t3;
tmp[2] += t2;
tmp[6] -= t2;
}
 
#else
{
real t0, t1, t2, t3, t4, t5, t6, t7;
 
t1 = REAL_MUL(COS6_2, in[12]);
t2 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4]));
 
t3 = in[0] + t1;
t4 = in[0] - t1 - t1;
t5 = t4 - t2;
tmp[4] = t4 + t2 + t2;
 
t0 = REAL_MUL(cos9[0], (in[4] + in[8]));
t1 = REAL_MUL(cos9[1], (in[8] - in[16]));
 
t2 = REAL_MUL(cos9[2], (in[4] + in[16]));
 
t6 = t3 - t0 - t2;
t0 += t3 + t1;
t3 += t2 - t1;
 
t2 = REAL_MUL(cos18[0], (in[2] + in[10]));
t4 = REAL_MUL(cos18[1], (in[10] - in[14]));
t7 = REAL_MUL(COS6_1, in[6]);
 
t1 = t2 + t4 + t7;
tmp[0] = t0 + t1;
tmp[8] = t0 - t1;
t1 = REAL_MUL(cos18[2], (in[2] + in[14]));
t2 += t1 - t7;
 
tmp[3] = t3 + t2;
t0 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2]));
tmp[5] = t3 - t2;
 
t4 -= t1 + t7;
 
tmp[1] = t5 - t0;
tmp[7] = t5 + t0;
tmp[2] = t6 + t4;
tmp[6] = t6 - t4;
}
#endif
 
{
real t0, t1, t2, t3, t4, t5, t6, t7;
 
t1 = REAL_MUL(COS6_2, in[13]);
t2 = REAL_MUL(COS6_2, (in[9] + in[17] - in[5]));
 
t3 = in[1] + t1;
t4 = in[1] - t1 - t1;
t5 = t4 - t2;
 
t0 = REAL_MUL(cos9[0], (in[5] + in[9]));
t1 = REAL_MUL(cos9[1], (in[9] - in[17]));
 
tmp[13] = REAL_MUL((t4 + t2 + t2), tfcos36[17-13]);
t2 = REAL_MUL(cos9[2], (in[5] + in[17]));
 
t6 = t3 - t0 - t2;
t0 += t3 + t1;
t3 += t2 - t1;
 
t2 = REAL_MUL(cos18[0], (in[3] + in[11]));
t4 = REAL_MUL(cos18[1], (in[11] - in[15]));
t7 = REAL_MUL(COS6_1, in[7]);
 
t1 = t2 + t4 + t7;
tmp[17] = REAL_MUL((t0 + t1), tfcos36[17-17]);
tmp[9] = REAL_MUL((t0 - t1), tfcos36[17-9]);
t1 = REAL_MUL(cos18[2], (in[3] + in[15]));
t2 += t1 - t7;
 
tmp[14] = REAL_MUL((t3 + t2), tfcos36[17-14]);
t0 = REAL_MUL(COS6_1, (in[11] + in[15] - in[3]));
tmp[12] = REAL_MUL((t3 - t2), tfcos36[17-12]);
 
t4 -= t1 + t7;
 
tmp[16] = REAL_MUL((t5 - t0), tfcos36[17-16]);
tmp[10] = REAL_MUL((t5 + t0), tfcos36[17-10]);
tmp[15] = REAL_MUL((t6 + t4), tfcos36[17-15]);
tmp[11] = REAL_MUL((t6 - t4), tfcos36[17-11]);
}
 
#define MACRO(v) { \
real tmpval; \
tmpval = tmp[(v)] + tmp[17-(v)]; \
out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \
out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \
tmpval = tmp[(v)] - tmp[17-(v)]; \
ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \
ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); }
 
{
register real *out2 = o2;
register real *w = wintab;
register real *out1 = o1;
register real *ts = tsbuf;
 
MACRO(0);
MACRO(1);
MACRO(2);
MACRO(3);
MACRO(4);
MACRO(5);
MACRO(6);
MACRO(7);
MACRO(8);
}
 
#else
 
{
 
#define MACRO0(v) { \
real tmp; \
out2[9+(v)] = REAL_MUL((tmp = sum0 + sum1), w[27+(v)]); \
out2[8-(v)] = REAL_MUL(tmp, w[26-(v)]); } \
sum0 -= sum1; \
ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(sum0, w[8-(v)]); \
ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(sum0, w[9+(v)]);
#define MACRO1(v) { \
real sum0,sum1; \
sum0 = tmp1a + tmp2a; \
sum1 = REAL_MUL((tmp1b + tmp2b), tfcos36[(v)]); \
MACRO0(v); }
#define MACRO2(v) { \
real sum0,sum1; \
sum0 = tmp2a - tmp1a; \
sum1 = REAL_MUL((tmp2b - tmp1b), tfcos36[(v)]); \
MACRO0(v); }
 
register const real *c = COS9;
register real *out2 = o2;
register real *w = wintab;
register real *out1 = o1;
register real *ts = tsbuf;
 
real ta33,ta66,tb33,tb66;
 
ta33 = REAL_MUL(in[2*3+0], c[3]);
ta66 = REAL_MUL(in[2*6+0], c[6]);
tb33 = REAL_MUL(in[2*3+1], c[3]);
tb66 = REAL_MUL(in[2*6+1], c[6]);
 
{
real tmp1a,tmp2a,tmp1b,tmp2b;
tmp1a = REAL_MUL(in[2*1+0], c[1]) + ta33 + REAL_MUL(in[2*5+0], c[5]) + REAL_MUL(in[2*7+0], c[7]);
tmp1b = REAL_MUL(in[2*1+1], c[1]) + tb33 + REAL_MUL(in[2*5+1], c[5]) + REAL_MUL(in[2*7+1], c[7]);
tmp2a = REAL_MUL(in[2*2+0], c[2]) + REAL_MUL(in[2*4+0], c[4]) + ta66 + REAL_MUL(in[2*8+0], c[8]);
tmp2b = REAL_MUL(in[2*2+1], c[2]) + REAL_MUL(in[2*4+1], c[4]) + tb66 + REAL_MUL(in[2*8+1], c[8]);
 
MACRO1(0);
MACRO2(8);
}
 
{
real tmp1a,tmp2a,tmp1b,tmp2b;
tmp1a = REAL_MUL(( in[2*1+0] - in[2*5+0] - in[2*7+0] ), c[3]);
tmp1b = REAL_MUL(( in[2*1+1] - in[2*5+1] - in[2*7+1] ), c[3]);
tmp2a = REAL_MUL(( in[2*2+0] - in[2*4+0] - in[2*8+0] ), c[6]) - in[2*6+0] + in[2*0+0];
tmp2b = REAL_MUL(( in[2*2+1] - in[2*4+1] - in[2*8+1] ), c[6]) - in[2*6+1] + in[2*0+1];
 
MACRO1(1);
MACRO2(7);
}
 
{
real tmp1a,tmp2a,tmp1b,tmp2b;
tmp1a = REAL_MUL(in[2*1+0], c[5]) - ta33 - REAL_MUL(in[2*5+0], c[7]) + REAL_MUL(in[2*7+0], c[1]);
tmp1b = REAL_MUL(in[2*1+1], c[5]) - tb33 - REAL_MUL(in[2*5+1], c[7]) + REAL_MUL(in[2*7+1], c[1]);
tmp2a = - REAL_MUL(in[2*2+0], c[8]) - REAL_MUL(in[2*4+0], c[2]) + ta66 + REAL_MUL(in[2*8+0], c[4]);
tmp2b = - REAL_MUL(in[2*2+1], c[8]) - REAL_MUL(in[2*4+1], c[2]) + tb66 + REAL_MUL(in[2*8+1], c[4]);
 
MACRO1(2);
MACRO2(6);
}
 
{
real tmp1a,tmp2a,tmp1b,tmp2b;
tmp1a = REAL_MUL(in[2*1+0], c[7]) - ta33 + REAL_MUL(in[2*5+0], c[1]) - REAL_MUL(in[2*7+0], c[5]);
tmp1b = REAL_MUL(in[2*1+1], c[7]) - tb33 + REAL_MUL(in[2*5+1], c[1]) - REAL_MUL(in[2*7+1], c[5]);
tmp2a = - REAL_MUL(in[2*2+0], c[4]) + REAL_MUL(in[2*4+0], c[8]) + ta66 - REAL_MUL(in[2*8+0], c[2]);
tmp2b = - REAL_MUL(in[2*2+1], c[4]) + REAL_MUL(in[2*4+1], c[8]) + tb66 - REAL_MUL(in[2*8+1], c[2]);
 
MACRO1(3);
MACRO2(5);
}
 
{
real sum0,sum1;
sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
sum1 = REAL_MUL((in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ), tfcos36[4]);
MACRO0(4);
}
}
#endif
 
}
}
 
 
/* new DCT12 */
static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
{
#define DCT12_PART1 \
in5 = in[5*3]; \
in5 += (in4 = in[4*3]); \
in4 += (in3 = in[3*3]); \
in3 += (in2 = in[2*3]); \
in2 += (in1 = in[1*3]); \
in1 += (in0 = in[0*3]); \
\
in5 += in3; in3 += in1; \
\
in2 = REAL_MUL(in2, COS6_1); \
in3 = REAL_MUL(in3, COS6_1);
 
#define DCT12_PART2 \
in0 += REAL_MUL(in4, COS6_2); \
\
in4 = in0 + in2; \
in0 -= in2; \
\
in1 += REAL_MUL(in5, COS6_2); \
\
in5 = REAL_MUL((in1 + in3), tfcos12[0]); \
in1 = REAL_MUL((in1 - in3), tfcos12[2]); \
\
in3 = in4 + in5; \
in4 -= in5; \
\
in2 = in0 + in1; \
in0 -= in1;
 
{
real in0,in1,in2,in3,in4,in5;
register real *out1 = rawout1;
ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
DCT12_PART1
 
{
real tmp0,tmp1 = (in0 - in4);
{
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
tmp0 = tmp1 + tmp2;
tmp1 -= tmp2;
}
ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]);
ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]);
ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]);
ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]);
}
 
DCT12_PART2
 
ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]);
ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]);
ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]);
ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]);
 
ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]);
ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]);
ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]);
ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]);
}
 
in++;
 
{
real in0,in1,in2,in3,in4,in5;
register real *out2 = rawout2;
DCT12_PART1
 
{
real tmp0,tmp1 = (in0 - in4);
{
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
tmp0 = tmp1 + tmp2;
tmp1 -= tmp2;
}
out2[5-1] = REAL_MUL(tmp0, wi[11-1]);
out2[0+1] = REAL_MUL(tmp0, wi[6+1]);
ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]);
ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]);
}
 
DCT12_PART2
 
out2[5-0] = REAL_MUL(in2, wi[11-0]);
out2[0+0] = REAL_MUL(in2, wi[6+0]);
out2[0+2] = REAL_MUL(in3, wi[6+2]);
out2[5-2] = REAL_MUL(in3, wi[11-2]);
 
ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]);
ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]);
ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]);
ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]);
}
 
in++;
 
{
real in0,in1,in2,in3,in4,in5;
register real *out2 = rawout2;
out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
 
DCT12_PART1
 
{
real tmp0,tmp1 = (in0 - in4);
{
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
tmp0 = tmp1 + tmp2;
tmp1 -= tmp2;
}
out2[11-1] = REAL_MUL(tmp0, wi[11-1]);
out2[6 +1] = REAL_MUL(tmp0, wi[6+1]);
out2[0+1] += REAL_MUL(tmp1, wi[1]);
out2[5-1] += REAL_MUL(tmp1, wi[5-1]);
}
 
DCT12_PART2
 
out2[11-0] = REAL_MUL(in2, wi[11-0]);
out2[6 +0] = REAL_MUL(in2, wi[6+0]);
out2[6 +2] = REAL_MUL(in3, wi[6+2]);
out2[11-2] = REAL_MUL(in3, wi[11-2]);
 
out2[0+0] += REAL_MUL(in0, wi[0]);
out2[5-0] += REAL_MUL(in0, wi[5-0]);
out2[0+2] += REAL_MUL(in4, wi[2]);
out2[5-2] += REAL_MUL(in4, wi[5-2]);
}
}
 
 
static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT], real tsOut[SSLIMIT][SBLIMIT], int ch,struct gr_info_s *gr_info, mpg123_handle *fr)
{
real (*block)[2][SBLIMIT*SSLIMIT] = fr->hybrid_block;
int *blc = fr->hybrid_blc;
 
real *tspnt = (real *) tsOut;
real *rawout1,*rawout2;
int bt = 0;
size_t sb = 0;
 
{
int b = blc[ch];
rawout1=block[b][ch];
b=-b+1;
rawout2=block[b][ch];
blc[ch] = b;
}
if(gr_info->mixed_block_flag)
{
sb = 2;
opt_dct36(fr)(fsIn[0],rawout1,rawout2,win[0],tspnt);
opt_dct36(fr)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
rawout1 += 36; rawout2 += 36; tspnt += 2;
}
bt = gr_info->block_type;
if(bt == 2)
{
for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36)
{
dct12(fsIn[sb] ,rawout1 ,rawout2 ,win[2] ,tspnt);
dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
}
}
else
{
for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36)
{
opt_dct36(fr)(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
opt_dct36(fr)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
}
}
 
for(;sb<SBLIMIT;sb++,tspnt++)
{
int i;
for(i=0;i<SSLIMIT;i++)
{
tspnt[i*SBLIMIT] = *rawout1++;
*rawout2++ = DOUBLE_TO_REAL(0.0);
}
}
}
 
 
/* And at the end... the main layer3 handler */
int do_layer3(mpg123_handle *fr)
{
int gr, ch, ss,clip=0;
int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
struct III_sideinfo sideinfo;
int stereo = fr->stereo;
int single = fr->single;
int ms_stereo,i_stereo;
int sfreq = fr->sampling_frequency;
int stereo1,granules;
 
if(stereo == 1)
{ /* stream is mono */
stereo1 = 1;
single = SINGLE_LEFT;
}
else if(single != SINGLE_STEREO) /* stream is stereo, but force to mono */
stereo1 = 1;
else
stereo1 = 2;
 
if(fr->mode == MPG_MD_JOINT_STEREO)
{
ms_stereo = (fr->mode_ext & 0x2)>>1;
i_stereo = fr->mode_ext & 0x1;
}
else ms_stereo = i_stereo = 0;
 
granules = fr->lsf ? 1 : 2;
 
/* quick hack to keep the music playing */
/* after having seen this nasty test file... */
if(III_get_side_info(fr, &sideinfo,stereo,ms_stereo,sfreq,single))
{
if(NOQUIET) error("bad frame - unable to get valid sideinfo");
return clip;
}
 
set_pointer(fr,sideinfo.main_data_begin);
 
for(gr=0;gr<granules;gr++)
{
ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT];
ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT];
 
{
struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
long part2bits;
if(fr->lsf)
part2bits = III_get_scale_factors_2(fr, scalefacs[0],gr_info,0);
else
part2bits = III_get_scale_factors_1(fr, scalefacs[0],gr_info,0,gr);
 
if(III_dequantize_sample(fr, hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
{
if(VERBOSE2) error("dequantization failed!");
return clip;
}
}
 
if(stereo == 2)
{
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
long part2bits;
if(fr->lsf)
part2bits = III_get_scale_factors_2(fr, scalefacs[1],gr_info,i_stereo);
else
part2bits = III_get_scale_factors_1(fr, scalefacs[1],gr_info,1,gr);
 
if(III_dequantize_sample(fr, hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
{
if(VERBOSE2) error("dequantization failed!");
return clip;
}
 
if(ms_stereo)
{
int i;
unsigned int maxb = sideinfo.ch[0].gr[gr].maxb;
if(sideinfo.ch[1].gr[gr].maxb > maxb) maxb = sideinfo.ch[1].gr[gr].maxb;
 
for(i=0;i<SSLIMIT*(int)maxb;i++)
{
real tmp0 = ((real *)hybridIn[0])[i];
real tmp1 = ((real *)hybridIn[1])[i];
((real *)hybridIn[0])[i] = tmp0 + tmp1;
((real *)hybridIn[1])[i] = tmp0 - tmp1;
}
}
 
if(i_stereo) III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
 
if(ms_stereo || i_stereo || (single == SINGLE_MIX) )
{
if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
else
gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
}
 
switch(single)
{
case SINGLE_MIX:
{
register int i;
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++,in0++)
*in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
}
break;
case SINGLE_RIGHT:
{
register int i;
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++)
*in0++ = *in1++;
}
break;
}
}
 
for(ch=0;ch<stereo1;ch++)
{
struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
III_antialias(hybridIn[ch],gr_info);
III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info, fr);
}
 
#ifdef OPT_I486
if(single != SINGLE_STEREO || fr->af.encoding != MPG123_ENC_SIGNED_16 || fr->down_sample != 0)
{
#endif
for(ss=0;ss<SSLIMIT;ss++)
{
if(single != SINGLE_STEREO)
clip += (fr->synth_mono)(hybridOut[0][ss], fr);
else
clip += (fr->synth_stereo)(hybridOut[0][ss], hybridOut[1][ss], fr);
 
}
#ifdef OPT_I486
} else
{
/* Only stereo, 16 bits benefit from the 486 optimization. */
ss=0;
while(ss < SSLIMIT)
{
int n;
n=(fr->buffer.size - fr->buffer.fill) / (2*2*32);
if(n > (SSLIMIT-ss)) n=SSLIMIT-ss;
 
/* Clip counting makes no sense with this function. */
absynth_1to1_i486(hybridOut[0][ss], 0, fr, n);
absynth_1to1_i486(hybridOut[1][ss], 1, fr, n);
ss+=n;
fr->buffer.fill+=(2*2*32)*n;
}
}
#endif
}
return clip;
}
/programs/develop/libraries/libmpg123/libmpg123.c
0,0 → 1,1555
/*
libmpg123: MPEG Audio Decoder library
 
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
 
*/
 
#include "mpg123lib_intern.h"
#include "icy2utf8.h"
#include "debug.h"
 
#ifdef GAPLESS
#define SAMPLE_ADJUST(x) ((x) - ((mh->p.flags & MPG123_GAPLESS) ? mh->begin_os : 0))
#define SAMPLE_UNADJUST(x) ((x) + ((mh->p.flags & MPG123_GAPLESS) ? mh->begin_os : 0))
#else
#define SAMPLE_ADJUST(x) (x)
#define SAMPLE_UNADJUST(x) (x)
#endif
 
#define SEEKFRAME(mh) ((mh)->ignoreframe < 0 ? 0 : (mh)->ignoreframe)
 
static int initialized = 0;
 
#define ALIGNCHECK(mh)
#define ALIGNCHECKK
/* On compilers that support data alignment but not the automatic stack realignment.
We check for properly aligned stack before risking a crash because of badly compiled
client program. */
#if (defined CCALIGN) && (defined NEED_ALIGNCHECK) && ((defined DEBUG) || (defined CHECK_ALIGN))
 
/* Common building block. */
#define ALIGNMAINPART \
/* minimum size of 16 bytes, not all compilers would align a smaller piece of data */ \
double ALIGNED(16) altest[2]; \
debug2("testing alignment, with %lu %% 16 = %lu", \
(unsigned long)altest, (unsigned long)((size_t)altest % 16)); \
if((size_t)altest % 16 != 0)
 
#undef ALIGNCHECK
#define ALIGNCHECK(mh) \
ALIGNMAINPART \
{ \
error("Stack variable is not aligned! Your combination of compiler/library is dangerous!"); \
if(mh != NULL) mh->err = MPG123_BAD_ALIGN; \
\
return MPG123_ERR; \
}
#undef ALIGNCHECKK
#define ALIGNCHECKK \
ALIGNMAINPART \
{ \
error("Stack variable is not aligned! Your combination of compiler/library is dangerous!"); \
return MPG123_BAD_ALIGN; \
}
 
#endif
 
#ifdef GAPLESS
/*
Take the buffer after a frame decode (strictly: it is the data from frame fr->num!) and cut samples out.
fr->buffer.fill may then be smaller than before...
*/
static void frame_buffercheck(mpg123_handle *fr)
{
/* When we have no accurate position, gapless code does not make sense. */
if(!fr->accurate) return;
 
/* The first interesting frame: Skip some leading samples. */
if(fr->firstoff && fr->num == fr->firstframe)
{
off_t byteoff = samples_to_bytes(fr, fr->firstoff);
if((off_t)fr->buffer.fill > byteoff)
{
fr->buffer.fill -= byteoff;
/* buffer.p != buffer.data only for own buffer */
debug6("cutting %li samples/%li bytes on begin, own_buffer=%i at %p=%p, buf[1]=%i",
(long)fr->firstoff, (long)byteoff, fr->own_buffer, (void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
if(fr->own_buffer) fr->buffer.p = fr->buffer.data + byteoff;
else memmove(fr->buffer.data, fr->buffer.data + byteoff, fr->buffer.fill);
debug3("done cutting, buffer at %p =? %p, buf[1]=%i",
(void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
}
else fr->buffer.fill = 0;
fr->firstoff = 0; /* Only enter here once... when you seek, firstoff should be reset. */
}
/* The last interesting (planned) frame: Only use some leading samples. */
if(fr->lastoff && fr->num == fr->lastframe)
{
off_t byteoff = samples_to_bytes(fr, fr->lastoff);
if((off_t)fr->buffer.fill > byteoff)
{
fr->buffer.fill = byteoff;
}
fr->lastoff = 0; /* Only enter here once... when you seek, lastoff should be reset. */
}
}
#endif
 
int attribute_align_arg mpg123_init(void)
{
ALIGNCHECKK
if((sizeof(short) != 2) || (sizeof(long) < 4)) return MPG123_BAD_TYPES;
 
if(initialized) return MPG123_OK; /* no need to initialize twice */
 
#ifndef NO_LAYER12
init_layer12(); /* inits also shared tables with layer1 */
#endif
#ifndef NO_LAYER3
init_layer3();
#endif
prepare_decode_tables();
check_decoders();
initialized = 1;
return MPG123_OK;
}
 
void attribute_align_arg mpg123_exit(void)
{
/* nothing yet, but something later perhaps */
}
 
/* create a new handle with specified decoder, decoder can be "", "auto" or NULL for auto-detection */
mpg123_handle attribute_align_arg *mpg123_new(const char* decoder, int *error)
{
return mpg123_parnew(NULL, decoder, error);
}
 
/* ...the full routine with optional initial parameters to override defaults. */
mpg123_handle attribute_align_arg *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error)
{
mpg123_handle *fr = NULL;
int err = MPG123_OK;
#if (defined CCALIGN) && (defined NEED_ALIGNCHECK) && ((defined DEBUG) || (defined CHECK_ALIGN))
#ifdef CCALIGN
double ALIGNED(16) altest[4];
if(((size_t)altest) % 16 != 0)
{
error("Stack variable is not aligned! Your combination of compiler/library is dangerous!");
*error = MPG123_BAD_ALIGN;
return NULL;
}
#endif
#endif
if(initialized) fr = (mpg123_handle*) malloc(sizeof(mpg123_handle));
else err = MPG123_NOT_INITIALIZED;
if(fr != NULL)
{
frame_init_par(fr, mp);
debug("cpu opt setting");
if(frame_cpu_opt(fr, decoder) != 1)
{
err = MPG123_BAD_DECODER;
frame_exit(fr);
free(fr);
fr = NULL;
}
}
if(fr != NULL)
{
/* Cleanup that mess! ... use mpg123_decoder / decode_update! */
if(frame_outbuffer(fr) != 0)
{
err = MPG123_NO_BUFFERS;
frame_exit(fr);
free(fr);
fr = NULL;
}
else
{
/* I smell cleanup here... with get_next_frame() */
/* if(decode_update(fr) != 0)
{
err = fr->err != MPG123_OK ? fr->err : MPG123_BAD_DECODER;
frame_exit(fr);
free(fr);
fr = NULL;
}
else */
fr->decoder_change = 1;
}
}
else if(err == MPG123_OK) err = MPG123_OUT_OF_MEM;
 
if(error != NULL) *error = err;
return fr;
}
 
int attribute_align_arg mpg123_decoder(mpg123_handle *mh, const char* decoder)
{
enum optdec dt = dectype(decoder);
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
if(dt == nodec)
{
mh->err = MPG123_BAD_DECODER;
return MPG123_ERR;
}
if(dt == mh->cpu_opts.type) return MPG123_OK;
 
/* Now really change. */
/* frame_exit(mh);
frame_init(mh); */
debug("cpu opt setting");
if(frame_cpu_opt(mh, decoder) != 1)
{
mh->err = MPG123_BAD_DECODER;
frame_exit(mh);
return MPG123_ERR;
}
/* New buffers for decoder are created in frame_buffers() */
if((frame_outbuffer(mh) != 0))
{
mh->err = MPG123_NO_BUFFERS;
frame_exit(mh);
return MPG123_ERR;
}
/* I smell cleanup here... with get_next_frame() */
decode_update(mh);
mh->decoder_change = 1;
return MPG123_OK;
}
 
int attribute_align_arg mpg123_param(mpg123_handle *mh, enum mpg123_parms key, long val, double fval)
{
int r;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
r = mpg123_par(&mh->p, key, val, fval);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
else
{ /* Special treatment for some settings. */
#ifdef FRAME_INDEX
if(key == MPG123_INDEX_SIZE)
{ /* Apply frame index size and grow property on the fly. */
r = frame_index_setup(mh);
if(r != MPG123_OK) mh->err = MPG123_INDEX_FAIL;
}
#endif
}
return r;
}
 
int attribute_align_arg mpg123_par(mpg123_pars *mp, enum mpg123_parms key, long val, double fval)
{
int ret = MPG123_OK;
ALIGNCHECKK
if(mp == NULL) return MPG123_BAD_PARS;
switch(key)
{
case MPG123_VERBOSE:
mp->verbose = val;
break;
case MPG123_FLAGS:
#ifndef GAPLESS
if(val & MPG123_GAPLESS) ret = MPG123_NO_GAPLESS;
#endif
if(ret == MPG123_OK) mp->flags = val;
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
break;
case MPG123_ADD_FLAGS:
#ifndef GAPLESS
/* Enabling of gapless mode doesn't work when it's not there, but disabling (below) is no problem. */
if(val & MPG123_GAPLESS) ret = MPG123_NO_GAPLESS;
else
#endif
mp->flags |= val;
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
break;
case MPG123_REMOVE_FLAGS:
mp->flags &= ~val;
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
break;
case MPG123_FORCE_RATE: /* should this trigger something? */
#ifdef NO_NTOM
if(val > 0)
ret = MPG123_BAD_RATE;
#else
if(val > 96000) ret = MPG123_BAD_RATE;
else mp->force_rate = val < 0 ? 0 : val; /* >0 means enable, 0 disable */
#endif
break;
case MPG123_DOWN_SAMPLE:
#ifdef NO_DOWNSAMPLE
if(val != 0) ret = MPG123_BAD_RATE;
#else
if(val < 0 || val > 2) ret = MPG123_BAD_RATE;
else mp->down_sample = (int)val;
#endif
break;
case MPG123_RVA:
if(val < 0 || val > MPG123_RVA_MAX) ret = MPG123_BAD_RVA;
else mp->rva = (int)val;
break;
case MPG123_DOWNSPEED:
mp->halfspeed = val < 0 ? 0 : val;
break;
case MPG123_UPSPEED:
mp->doublespeed = val < 0 ? 0 : val;
break;
case MPG123_ICY_INTERVAL:
#ifndef NO_ICY
mp->icy_interval = val > 0 ? val : 0;
#else
if(val > 0) ret = MPG123_BAD_PARAM;
#endif
break;
case MPG123_OUTSCALE:
/* Choose the value that is non-zero, if any.
Downscaling integers to 1.0 . */
mp->outscale = val == 0 ? fval : (double)val/SHORT_SCALE;
break;
case MPG123_TIMEOUT:
#ifndef WIN32
mp->timeout = val >= 0 ? val : 0;
#else
ret = MPG123_NO_TIMEOUT;
#endif
break;
case MPG123_RESYNC_LIMIT:
mp->resync_limit = val;
break;
case MPG123_INDEX_SIZE:
#ifdef FRAME_INDEX
mp->index_size = val;
#else
ret = MPG123_NO_INDEX;
#endif
break;
case MPG123_PREFRAMES:
if(val >= 0) mp->preframes = val;
else ret = MPG123_BAD_VALUE;
break;
default:
ret = MPG123_BAD_PARAM;
}
return ret;
}
 
int attribute_align_arg mpg123_getparam(mpg123_handle *mh, enum mpg123_parms key, long *val, double *fval)
{
int r;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
r = mpg123_getpar(&mh->p, key, val, fval);
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
return r;
}
 
int attribute_align_arg mpg123_getpar(mpg123_pars *mp, enum mpg123_parms key, long *val, double *fval)
{
int ret = 0;
ALIGNCHECKK
if(mp == NULL) return MPG123_BAD_PARS;
switch(key)
{
case MPG123_VERBOSE:
if(val) *val = mp->verbose;
break;
case MPG123_FLAGS:
case MPG123_ADD_FLAGS:
if(val) *val = mp->flags;
break;
case MPG123_FORCE_RATE:
if(val)
#ifdef NO_NTOM
*val = 0;
#else
*val = mp->force_rate;
#endif
break;
case MPG123_DOWN_SAMPLE:
if(val) *val = mp->down_sample;
break;
case MPG123_RVA:
if(val) *val = mp->rva;
break;
case MPG123_DOWNSPEED:
if(val) *val = mp->halfspeed;
break;
case MPG123_UPSPEED:
if(val) *val = mp->doublespeed;
break;
case MPG123_ICY_INTERVAL:
#ifndef NO_ICY
if(val) *val = (long)mp->icy_interval;
#else
if(val) *val = 0;
#endif
break;
case MPG123_OUTSCALE:
if(fval) *fval = mp->outscale;
if(val) *val = (long)(mp->outscale*SHORT_SCALE);
break;
case MPG123_RESYNC_LIMIT:
if(val) *val = mp->resync_limit;
break;
case MPG123_INDEX_SIZE:
if(val)
#ifdef FRAME_INDEX
*val = mp->index_size;
#else
*val = 0; /* graceful fallback: no index is index of zero size */
#endif
break;
case MPG123_PREFRAMES:
*val = mp->preframes;
break;
default:
ret = MPG123_BAD_PARAM;
}
return ret;
}
 
int attribute_align_arg mpg123_getstate(mpg123_handle *mh, enum mpg123_state key, long *val, double *fval)
{
int ret = MPG123_OK;
long theval = 0;
double thefval = 0.;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
switch(key)
{
case MPG123_ACCURATE:
theval = mh->accurate;
break;
default:
mh->err = MPG123_BAD_KEY;
ret = MPG123_ERR;
}
 
if(val != NULL) *val = theval;
if(fval != NULL) *fval = thefval;
 
return ret;
}
 
int attribute_align_arg mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(band < 0 || band > 31){ mh->err = MPG123_BAD_BAND; return MPG123_ERR; }
switch(channel)
{
case MPG123_LEFT|MPG123_RIGHT:
mh->equalizer[0][band] = mh->equalizer[1][band] = DOUBLE_TO_REAL(val);
break;
case MPG123_LEFT: mh->equalizer[0][band] = DOUBLE_TO_REAL(val); break;
case MPG123_RIGHT: mh->equalizer[1][band] = DOUBLE_TO_REAL(val); break;
default:
mh->err=MPG123_BAD_CHANNEL;
return MPG123_ERR;
}
mh->have_eq_settings = TRUE;
return MPG123_OK;
}
 
double attribute_align_arg mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band)
{
double ret = 0.;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
/* Handle this gracefully. When there is no band, it has no volume. */
if(band > -1 && band < 32)
switch(channel)
{
case MPG123_LEFT|MPG123_RIGHT:
ret = 0.5*(REAL_TO_DOUBLE(mh->equalizer[0][band])+REAL_TO_DOUBLE(mh->equalizer[1][band]));
break;
case MPG123_LEFT: ret = REAL_TO_DOUBLE(mh->equalizer[0][band]); break;
case MPG123_RIGHT: ret = REAL_TO_DOUBLE(mh->equalizer[1][band]); break;
/* Default case is already handled: ret = 0 */
}
 
return ret;
}
 
 
/* plain file access, no http! */
int attribute_align_arg mpg123_open(mpg123_handle *mh, const char *path)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
mpg123_close(mh);
frame_reset(mh);
return open_stream(mh, path, -1);
}
 
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
mpg123_close(mh);
frame_reset(mh);
return open_stream(mh, NULL, fd);
}
 
int attribute_align_arg mpg123_open_feed(mpg123_handle *mh)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
mpg123_close(mh);
frame_reset(mh);
return open_feed(mh);
}
 
int attribute_align_arg mpg123_replace_reader( mpg123_handle *mh,
ssize_t (*r_read) (int, void *, size_t),
off_t (*r_lseek)(int, off_t, int) )
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
mh->rdat.r_read = r_read;
mh->rdat.r_lseek = r_lseek;
return MPG123_OK;
}
 
 
int decode_update(mpg123_handle *mh)
{
long native_rate;
int b;
ALIGNCHECK(mh);
native_rate = frame_freq(mh);
 
b = frame_output_format(mh); /* Select the new output format based on given constraints. */
if(b < 0) return MPG123_ERR;
 
if(b == 1) mh->new_format = 1; /* Store for later... */
 
debug3("updating decoder structure with native rate %li and af.rate %li (new format: %i)", native_rate, mh->af.rate, mh->new_format);
if(mh->af.rate == native_rate) mh->down_sample = 0;
else if(mh->af.rate == native_rate>>1) mh->down_sample = 1;
else if(mh->af.rate == native_rate>>2) mh->down_sample = 2;
else mh->down_sample = 3; /* flexible (fixed) rate */
switch(mh->down_sample)
{
case 0:
case 1:
case 2:
mh->down_sample_sblimit = SBLIMIT>>(mh->down_sample);
/* With downsampling I get less samples per frame */
mh->outblock = samples_to_bytes(mh, (spf(mh)>>mh->down_sample));
break;
#ifndef NO_NTOM
case 3:
{
if(synth_ntom_set_step(mh) != 0) return -1;
if(frame_freq(mh) > mh->af.rate)
{
mh->down_sample_sblimit = SBLIMIT * mh->af.rate;
mh->down_sample_sblimit /= frame_freq(mh);
}
else mh->down_sample_sblimit = SBLIMIT;
mh->outblock = mh->af.encsize * mh->af.channels *
( ( NTOM_MUL-1+spf(mh)
* (((size_t)NTOM_MUL*mh->af.rate)/frame_freq(mh))
)/NTOM_MUL );
}
break;
#endif
}
 
if(!(mh->p.flags & MPG123_FORCE_MONO))
{
if(mh->af.channels == 1) mh->single = SINGLE_MIX;
else mh->single = SINGLE_STEREO;
}
else mh->single = (mh->p.flags & MPG123_FORCE_MONO)-1;
if(set_synth_functions(mh) != 0) return -1;;
 
do_rva(mh);
debug3("done updating decoder structure with native rate %li and af.rate %li and down_sample %i", frame_freq(mh), mh->af.rate, mh->down_sample);
 
return 0;
}
 
size_t attribute_align_arg mpg123_safe_buffer()
{
/* real is the largest possible output (it's 32bit float, 32bit int or 64bit double). */
return sizeof(real)*2*1152*NTOM_MAX;
}
 
size_t attribute_align_arg mpg123_outblock(mpg123_handle *mh)
{
if(mh != NULL) return mh->outblock;
else return mpg123_safe_buffer();
}
 
static int get_next_frame(mpg123_handle *mh)
{
int change = mh->decoder_change;
do
{
int b;
/* Decode & discard some frame(s) before beginning. */
if(mh->to_ignore && mh->num < mh->firstframe && mh->num >= mh->ignoreframe)
{
debug1("ignoring frame %li", (long)mh->num);
/* Decoder structure must be current! decode_update has been called before... */
(mh->do_layer)(mh); mh->buffer.fill = 0;
#ifndef NO_NTOM
/* The ignored decoding may have failed. Make sure ntom stays consistent. */
if(mh->down_sample == 3) ntom_set_ntom(mh, mh->num+1);
#endif
mh->to_ignore = mh->to_decode = FALSE;
}
/* Read new frame data; possibly breaking out here for MPG123_NEED_MORE. */
debug("read frame");
mh->to_decode = FALSE;
b = read_frame(mh); /* That sets to_decode only if a full frame was read. */
debug4("read of frame %li returned %i (to_decode=%i) at sample %li", (long)mh->num, b, mh->to_decode, (long)mpg123_tell(mh));
if(b == MPG123_NEED_MORE) return MPG123_NEED_MORE; /* need another call with data */
else if(b <= 0)
{
/* More sophisticated error control? */
if(b==0 || mh->rdat.filepos == mh->rdat.filelen)
{ /* We simply reached the end. */
mh->track_frames = mh->num + 1;
debug("What about updating/checking gapless sample count here?");
return MPG123_DONE;
}
else return MPG123_ERR; /* Some real error. */
}
/* Now, there should be new data to decode ... and also possibly new stream properties */
if(mh->header_change > 1)
{
debug("big header change");
change = 1;
}
/* Now some accounting: Look at the numbers and decide if we want this frame. */
++mh->playnum;
/* Plain skipping without decoding, only when frame is not ignored on next cycle. */
if(mh->num < mh->firstframe || (mh->p.doublespeed && (mh->playnum % mh->p.doublespeed)))
{
if(!(mh->to_ignore && mh->num < mh->firstframe && mh->num >= mh->ignoreframe))
{
frame_skip(mh);
/* Should one fix NtoM here or not?
It is not work the trouble for doublespeed, but what with leading frames? */
}
}
/* Or, we are finally done and have a new frame. */
else break;
} while(1);
/* When we start actually using the CRC, this could move into the loop... */
/* A question of semantics ... should I fold start_frame and frame_number into firstframe/lastframe? */
if(mh->lastframe >= 0 && mh->num > mh->lastframe)
{
mh->to_decode = mh->to_ignore = FALSE;
return MPG123_DONE;
}
if(change)
{
if(decode_update(mh) < 0) /* dito... */
return MPG123_ERR;
 
debug1("new format: %i", mh->new_format);
 
mh->decoder_change = 0;
#ifdef GAPLESS
if(mh->fresh)
{
int b=0;
/* Prepare offsets for gapless decoding. */
debug1("preparing gapless stuff with native rate %li", frame_freq(mh));
frame_gapless_realinit(mh);
frame_set_frameseek(mh, mh->num);
mh->fresh = 0;
/* Could this possibly happen? With a real big gapless offset... */
if(mh->num < mh->firstframe) b = get_next_frame(mh);
if(b < 0) return b; /* Could be error, need for more, new format... */
}
#endif
}
return MPG123_OK;
}
 
/* Assumption: A buffer full of zero samples can be constructed by repetition of this byte.
Only to be used by decode_the_frame() ... */
static int zero_byte(mpg123_handle *fr)
{
#ifndef NO_8BIT
return fr->af.encoding & MPG123_ENC_8 ? fr->conv16to8[0] : 0;
#else
return 0; /* All normal signed formats have the zero here (even in byte form -- that may be an assumption for your funny machine...). */
#endif
}
 
/*
Not part of the api. This just decodes the frame and fills missing bits with zeroes.
There can be frames that are broken and thus make do_layer() fail.
*/
void decode_the_frame(mpg123_handle *fr)
{
size_t needed_bytes = samples_to_bytes(fr, frame_outs(fr, fr->num+1)-frame_outs(fr, fr->num));
fr->clip += (fr->do_layer)(fr);
/*fprintf(stderr, "frame %"OFF_P": got %"SIZE_P" / %"SIZE_P"\n", fr->num,(size_p)fr->buffer.fill, (size_p)needed_bytes);*/
/* There could be less data than promised.
Also, then debugging, we look out for coding errors that could result in _more_ data than expected. */
#ifdef DEBUG
if(fr->buffer.fill != needed_bytes)
{
#endif
if(fr->buffer.fill < needed_bytes)
{
if(VERBOSE2)
fprintf(stderr, "Note: broken frame %li, filling up with %"SIZE_P" zeroes, from %"SIZE_P"\n", (long)fr->num, (size_p)(needed_bytes-fr->buffer.fill), (size_p)fr->buffer.fill);
 
/*
One could do a loop with individual samples instead... but zero is zero
Actually, that is wrong: zero is mostly a series of null bytes,
but we have funny 8bit formats that have a different opinion on zero...
Unsigned 16 or 32 bit formats are handled later.
*/
memset( fr->buffer.data + fr->buffer.fill, zero_byte(fr), needed_bytes - fr->buffer.fill );
 
fr->buffer.fill = needed_bytes;
#ifndef NO_NTOM
/* ntom_val will be wrong when the decoding wasn't carried out completely */
ntom_set_ntom(fr, fr->num+1);
#endif
}
#ifdef DEBUG
else
{
if(NOQUIET)
error2("I got _more_ bytes than expected (%"SIZE_P" / %"SIZE_P"), that should not be possible!", (size_p)fr->buffer.fill, (size_p)needed_bytes);
}
}
#endif
/* Handle unsigned output formats via reshifting after decode here. */
#ifndef NO_32BIT
if(fr->af.encoding == MPG123_ENC_UNSIGNED_32)
{ /* 32bit signed -> unsigned */
size_t i;
int32_t *ssamples;
uint32_t *usamples;
ssamples = (int32_t*)fr->buffer.data;
usamples = (uint32_t*)fr->buffer.data;
debug("converting output to unsigned 32 bit integer");
for(i=0; i<fr->buffer.fill/sizeof(int32_t); ++i)
{
/* Different strategy since we don't have a larger type at hand.
Also watch out for silly +-1 fun because integer constants are signed in C90! */
if(ssamples[i] >= 0)
usamples[i] = (uint32_t)ssamples[i] + 2147483647+1;
/* The smalles value goes zero. */
else if(ssamples[i] == ((int32_t)-2147483647-1))
usamples[i] = 0;
/* Now -value is in the positive range of signed int ... so it's a possible value at all. */
else
usamples[i] = (uint32_t)2147483647+1 - (uint32_t)(-ssamples[i]);
}
}
#endif
#ifndef NO_16BIT
if(fr->af.encoding == MPG123_ENC_UNSIGNED_16)
{
size_t i;
short *ssamples;
unsigned short *usamples;
ssamples = (short*)fr->buffer.data;
usamples = (unsigned short*)fr->buffer.data;
debug("converting output to unsigned 16 bit integer");
for(i=0; i<fr->buffer.fill/sizeof(short); ++i)
{
long tmp = (long)ssamples[i]+32768;
usamples[i] = (unsigned short)tmp;
}
}
#endif
}
 
/*
Put _one_ decoded frame into the frame structure's buffer, accessible at the location stored in <audio>, with <bytes> bytes available.
The buffer contents will be lost on next call to mpg123_decode_frame.
MPG123_OK -- successfully decoded the frame, you get your output data
MPg123_DONE -- This is it. End.
MPG123_ERR -- some error occured...
MPG123_NEW_FORMAT -- new frame was read, it results in changed output format -> will be decoded on next call
MPG123_NEED_MORE -- that should not happen as this function is intended for in-library stream reader but if you force it...
MPG123_NO_SPACE -- not enough space in buffer for safe decoding, also should not happen
 
num will be updated to the last decoded frame number (may possibly _not_ increase, p.ex. when format changed).
*/
int attribute_align_arg mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes)
{
ALIGNCHECK(mh);
if(bytes != NULL) *bytes = 0;
if(mh == NULL) return MPG123_ERR;
if(mh->buffer.size < mh->outblock) return MPG123_NO_SPACE;
mh->buffer.fill = 0; /* always start fresh */
while(TRUE)
{
/* decode if possible */
if(mh->to_decode)
{
if(mh->new_format)
{
debug("notifiying new format");
mh->new_format = 0;
return MPG123_NEW_FORMAT;
}
if(num != NULL) *num = mh->num;
debug("decoding");
 
decode_the_frame(mh);
 
mh->to_decode = mh->to_ignore = FALSE;
mh->buffer.p = mh->buffer.data;
#ifdef GAPLESS
/* This checks for individual samples to skip, for gapless mode or sample-accurate seek. */
frame_buffercheck(mh);
#endif
if(audio != NULL) *audio = mh->buffer.p;
if(bytes != NULL) *bytes = mh->buffer.fill;
 
return MPG123_OK;
}
else
{
int b = get_next_frame(mh);
if(b < 0) return b;
debug1("got next frame, %i", mh->to_decode);
}
}
}
 
int attribute_align_arg mpg123_read(mpg123_handle *mh, unsigned char *out, size_t size, size_t *done)
{
return mpg123_decode(mh, NULL, 0, out, size, done);
}
 
int attribute_align_arg mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size)
{
if(mh == NULL) return MPG123_ERR;
if(size > 0)
{
if(in != NULL)
{
if(feed_more(mh, in, size) != 0) return MPG123_ERR;
else return MPG123_OK;
}
else
{
mh->err = MPG123_NULL_BUFFER;
return MPG123_ERR;
}
}
return MPG123_OK;
}
 
/*
The old picture:
while(1) {
len = read(0,buf,16384);
if(len <= 0)
break;
ret = decodeMP3(&mp,buf,len,out,8192,&size);
while(ret == MP3_OK) {
write(1,out,size);
ret = decodeMP3(&mp,NULL,0,out,8192,&size);
}
}
*/
 
int attribute_align_arg mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, unsigned char *outmemory, size_t outmemsize, size_t *done)
{
int ret = MPG123_OK;
size_t mdone = 0;
ALIGNCHECK(mh);
if(done != NULL) *done = 0;
if(mh == NULL) return MPG123_ERR;
if(inmemsize > 0 && mpg123_feed(mh, inmemory, inmemsize) != MPG123_OK)
{
ret = MPG123_ERR;
goto decodeend;
}
if(outmemory == NULL) outmemsize = 0; /* Not just give error, give chance to get a status message. */
 
while(ret == MPG123_OK)
{
debug4("decode loop, fill %i (%li vs. %li); to_decode: %i", (int)mh->buffer.fill, (long)mh->num, (long)mh->firstframe, mh->to_decode);
/* Decode a frame that has been read before.
This only happens when buffer is empty! */
if(mh->to_decode)
{
if(mh->new_format)
{
debug("notifiying new format");
mh->new_format = 0;
return MPG123_NEW_FORMAT;
}
if(mh->buffer.size - mh->buffer.fill < mh->outblock)
{
ret = MPG123_NO_SPACE;
goto decodeend;
}
decode_the_frame(mh);
mh->to_decode = mh->to_ignore = FALSE;
mh->buffer.p = mh->buffer.data;
debug2("decoded frame %li, got %li samples in buffer", (long)mh->num, (long)(mh->buffer.fill / (samples_to_bytes(mh, 1))));
#ifdef GAPLESS
frame_buffercheck(mh); /* Seek & gapless. */
#endif
}
if(mh->buffer.fill) /* Copy (part of) the decoded data to the caller's buffer. */
{
/* get what is needed - or just what is there */
int a = mh->buffer.fill > (outmemsize - mdone) ? outmemsize - mdone : mh->buffer.fill;
debug4("buffer fill: %i; copying %i (%i - %li)", (int)mh->buffer.fill, a, (int)outmemsize, (long)mdone);
memcpy(outmemory, mh->buffer.p, a);
/* less data in frame buffer, less needed, output pointer increase, more data given... */
mh->buffer.fill -= a;
outmemory += a;
mdone += a;
mh->buffer.p += a;
if(!(outmemsize > mdone)) goto decodeend;
}
else /* If we didn't have data, get a new frame. */
{
int b = get_next_frame(mh);
if(b < 0){ ret = b; goto decodeend; }
}
}
decodeend:
if(done != NULL) *done = mdone;
return ret;
}
 
long attribute_align_arg mpg123_clip(mpg123_handle *mh)
{
long ret = 0;
ALIGNCHECK(mh);
if(mh != NULL)
{
ret = mh->clip;
mh->clip = 0;
}
return ret;
}
 
#define track_need_init(mh) (!(mh)->to_decode && (mh)->fresh)
 
static int init_track(mpg123_handle *mh)
{
if(track_need_init(mh))
{
/* Fresh track, need first frame for basic info. */
int b = get_next_frame(mh);
if(b < 0) return b;
}
return 0;
}
 
int attribute_align_arg mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(init_track(mh) == MPG123_ERR) return MPG123_ERR;
 
if(rate != NULL) *rate = mh->af.rate;
if(channels != NULL) *channels = mh->af.channels;
if(encoding != NULL) *encoding = mh->af.encoding;
mh->new_format = 0;
return MPG123_OK;
}
 
off_t attribute_align_arg mpg123_timeframe(mpg123_handle *mh, double seconds)
{
off_t b;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
b = init_track(mh);
if(b<0) return b;
return (off_t)(seconds/mpg123_tpf(mh));
}
 
/*
Now, where are we? We need to know the last decoded frame... and what's left of it in buffer.
The current frame number can mean the last decoded frame or the to-be-decoded frame.
If mh->to_decode, then mh->num frames have been decoded, the frame mh->num now coming next.
If not, we have the possibility of mh->num+1 frames being decoded or nothing at all.
Then, there is firstframe...when we didn't reach it yet, then the next data will come from there.
mh->num starts with -1
*/
off_t attribute_align_arg mpg123_tell(mpg123_handle *mh)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(track_need_init(mh)) return 0;
/* Now we have all the info at hand. */
debug5("tell: %li/%i first %li buffer %lu; frame_outs=%li", (long)mh->num, mh->to_decode, (long)mh->firstframe, (unsigned long)mh->buffer.fill, (long)frame_outs(mh, mh->num));
 
{ /* Funny block to keep C89 happy. */
off_t pos = 0;
if((mh->num < mh->firstframe) || (mh->num == mh->firstframe && mh->to_decode))
{ /* We are at the beginning, expect output from firstframe on. */
pos = frame_outs(mh, mh->firstframe);
#ifdef GAPLESS
pos += mh->firstoff;
#endif
}
else if(mh->to_decode)
{ /* We start fresh with this frame. Buffer should be empty, but we make sure to count it in. */
pos = frame_outs(mh, mh->num) - bytes_to_samples(mh, mh->buffer.fill);
}
else
{ /* We serve what we have in buffer and then the beginning of next frame... */
pos = frame_outs(mh, mh->num+1) - bytes_to_samples(mh, mh->buffer.fill);
}
/* Substract padding and delay from the beginning. */
pos = SAMPLE_ADJUST(pos);
/* Negative sample offsets are not right, less than nothing is still nothing. */
return pos>0 ? pos : 0;
}
}
 
off_t attribute_align_arg mpg123_tellframe(mpg123_handle *mh)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(mh->num < mh->firstframe) return mh->firstframe;
if(mh->to_decode) return mh->num;
/* Consider firstoff? */
return mh->buffer.fill ? mh->num : mh->num + 1;
}
 
off_t attribute_align_arg mpg123_tell_stream(mpg123_handle *mh)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
/* mh->rd is at least a bad_reader, so no worry. */
return mh->rd->tell(mh);
}
 
static int do_the_seek(mpg123_handle *mh)
{
int b;
off_t fnum = SEEKFRAME(mh);
mh->buffer.fill = 0;
 
/* If we are inside the ignoreframe - firstframe window, we may get away without actual seeking. */
if(mh->num < mh->firstframe)
{
mh->to_decode = FALSE; /* In any case, don't decode the current frame, perhaps ignore instead. */
if(mh->num > fnum) return MPG123_OK;
}
 
/* If we are already there, we are fine either for decoding or for ignoring. */
if(mh->num == fnum && (mh->to_decode || fnum < mh->firstframe)) return MPG123_OK;
/* We have the frame before... just go ahead as normal. */
if(mh->num == fnum-1)
{
mh->to_decode = FALSE;
return MPG123_OK;
}
 
/* OK, real seeking follows... clear buffers and go for it. */
frame_buffers_reset(mh);
#ifndef NO_NTOM
if(mh->down_sample == 3)
{
ntom_set_ntom(mh, fnum);
debug3("fixed ntom for frame %"OFF_P" to %lu, num=%"OFF_P, fnum, mh->ntom_val[0], mh->num);
}
#endif
b = mh->rd->seek_frame(mh, fnum);
debug1("seek_frame returned: %i", b);
if(b<0) return b;
/* Only mh->to_ignore is TRUE. */
if(mh->num < mh->firstframe) mh->to_decode = FALSE;
 
mh->playnum = mh->num;
return 0;
}
 
off_t attribute_align_arg mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence)
{
int b;
off_t pos;
ALIGNCHECK(mh);
pos = mpg123_tell(mh); /* adjusted samples */
/* pos < 0 also can mean that simply a former seek failed at the lower levels.
In that case, we only allow absolute seeks. */
if(pos < 0 && whence != SEEK_SET)
{ /* Unless we got the obvious error of NULL handle, this is a special seek failure. */
if(mh != NULL) mh->err = MPG123_NO_RELSEEK;
return MPG123_ERR;
}
if((b=init_track(mh)) < 0) return b;
switch(whence)
{
case SEEK_CUR: pos += sampleoff; break;
case SEEK_SET: pos = sampleoff; break;
case SEEK_END:
/* When we do not know the end already, we can try to find it. */
if(mh->track_frames < 1 && (mh->rdat.flags & READER_SEEKABLE))
mpg123_scan(mh);
#ifdef GAPLESS
if(mh->end_os > 0) pos = SAMPLE_ADJUST(mh->end_os) - sampleoff;
#else
if(mh->track_frames > 0) pos = SAMPLE_ADJUST(frame_outs(mh, mh->track_frames)) - sampleoff;
#endif
else
{
mh->err = MPG123_NO_SEEK_FROM_END;
return MPG123_ERR;
}
break;
default: mh->err = MPG123_BAD_WHENCE; return MPG123_ERR;
}
if(pos < 0) pos = 0;
/* pos now holds the wanted sample offset in adjusted samples */
frame_set_seek(mh, SAMPLE_UNADJUST(pos));
pos = do_the_seek(mh);
if(pos < 0) return pos;
 
return mpg123_tell(mh);
}
 
/*
A bit more tricky... libmpg123 does not do the seeking itself.
All it can do is to ignore frames until the wanted one is there.
The caller doesn't know where a specific frame starts and mpg123 also only knows the general region after it scanned the file.
Well, it is tricky...
*/
off_t attribute_align_arg mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset)
{
int b;
off_t pos;
ALIGNCHECK(mh);
pos = mpg123_tell(mh); /* adjusted samples */
debug3("seek from %li to %li (whence=%i)", (long)pos, (long)sampleoff, whence);
/* The special seek error handling does not apply here... there is no lowlevel I/O. */
if(pos < 0) return pos; /* mh == NULL is covered in mpg123_tell() */
if(input_offset == NULL)
{
mh->err = MPG123_NULL_POINTER;
return MPG123_ERR;
}
 
if((b=init_track(mh)) < 0) return b; /* May need more to do anything at all. */
 
switch(whence)
{
case SEEK_CUR: pos += sampleoff; break;
case SEEK_SET: pos = sampleoff; break;
case SEEK_END:
#ifdef GAPLESS
if(mh->end_os >= 0) pos = SAMPLE_ADJUST(mh->end_os) - sampleoff;
#else
if(mh->track_frames > 0) pos = SAMPLE_ADJUST(frame_outs(mh, mh->track_frames)) - sampleoff;
#endif
else
{
mh->err = MPG123_NO_SEEK_FROM_END;
return MPG123_ERR;
}
break;
default: mh->err = MPG123_BAD_WHENCE; return MPG123_ERR;
}
if(pos < 0) pos = 0;
frame_set_seek(mh, SAMPLE_UNADJUST(pos));
pos = SEEKFRAME(mh);
mh->buffer.fill = 0;
 
/* Shortcuts without modifying input stream. */
*input_offset = mh->rdat.buffer.fileoff + mh->rdat.buffer.size;
if(mh->num < mh->firstframe) mh->to_decode = FALSE;
if(mh->num == pos && mh->to_decode) goto feedseekend;
if(mh->num == pos-1) goto feedseekend;
/* Whole way. */
*input_offset = feed_set_pos(mh, frame_index_find(mh, SEEKFRAME(mh), &pos));
mh->num = pos-1; /* The next read frame will have num = pos. */
if(*input_offset < 0) return MPG123_ERR;
 
feedseekend:
return mpg123_tell(mh);
}
 
off_t attribute_align_arg mpg123_seek_frame(mpg123_handle *mh, off_t offset, int whence)
{
int b;
off_t pos = 0;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if((b=init_track(mh)) < 0) return b;
 
/* Could play games here with to_decode... */
pos = mh->num;
switch(whence)
{
case SEEK_CUR: pos += offset; break;
case SEEK_SET: pos = offset; break;
case SEEK_END:
if(mh->track_frames > 0) pos = mh->track_frames - offset;
else
{
mh->err = MPG123_NO_SEEK_FROM_END;
return MPG123_ERR;
}
break;
default:
mh->err = MPG123_BAD_WHENCE;
return MPG123_ERR;
}
if(pos < 0) pos = 0;
/* Hm, do we need to seek right past the end? */
else if(mh->track_frames > 0 && pos >= mh->track_frames) pos = mh->track_frames;
 
frame_set_frameseek(mh, pos);
pos = do_the_seek(mh);
if(pos < 0) return pos;
 
return mpg123_tellframe(mh);
}
 
int attribute_align_arg mpg123_set_filesize(mpg123_handle *mh, off_t size)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
 
mh->rdat.filelen = size;
return MPG123_OK;
}
 
off_t attribute_align_arg mpg123_length(mpg123_handle *mh)
{
int b;
off_t length;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
b = init_track(mh);
if(b<0) return b;
if(mh->track_samples > -1) length = mh->track_samples;
else if(mh->track_frames > 0) length = mh->track_frames*spf(mh);
else if(mh->rdat.filelen > 0) /* Let the case of 0 length just fall through. */
{
/* A bad estimate. Ignoring tags 'n stuff. */
double bpf = mh->mean_framesize ? mh->mean_framesize : compute_bpf(mh);
length = (off_t)((double)(mh->rdat.filelen)/bpf*spf(mh));
}
else if(mh->rdat.filelen == 0) return mpg123_tell(mh); /* we could be in feeder mode */
else return MPG123_ERR; /* No length info there! */
 
length = frame_ins2outs(mh, length);
#ifdef GAPLESS
if(mh->end_os > 0 && length > mh->end_os) length = mh->end_os;
length -= mh->begin_os;
#endif
return length;
}
 
int attribute_align_arg mpg123_scan(mpg123_handle *mh)
{
int b;
off_t backframe;
int to_decode, to_ignore;
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(!(mh->rdat.flags & READER_SEEKABLE)){ mh->err = MPG123_NO_SEEK; return MPG123_ERR; }
/* Scan through the _whole_ file, since the current position is no count but computed assuming constant samples per frame. */
/* Also, we can just keep the current buffer and seek settings. Just operate on input frames here. */
debug("issuing scan");
b = init_track(mh); /* mh->num >= 0 !! */
if(b<0)
{
if(b == MPG123_DONE) return MPG123_OK;
else return MPG123_ERR; /* Must be error here, NEED_MORE is not for seekable streams. */
}
backframe = mh->num;
to_decode = mh->to_decode;
to_ignore = mh->to_ignore;
b = mh->rd->seek_frame(mh, 0);
if(b<0 || mh->num != 0) return MPG123_ERR;
/* One frame must be there now. */
mh->track_frames = 1;
mh->track_samples = spf(mh); /* Internal samples. */
while(read_frame(mh) == 1)
{
++mh->track_frames;
mh->track_samples += spf(mh);
}
#ifdef GAPLESS
/* Also, think about usefulness of that extra value track_samples ... it could be used for consistency checking. */
frame_gapless_update(mh, mh->track_samples);
#endif
b = mh->rd->seek_frame(mh, backframe);
if(b<0 || mh->num != backframe) return MPG123_ERR;
mh->to_decode = to_decode;
mh->to_ignore = to_ignore;
return MPG123_OK;
}
 
int attribute_align_arg mpg123_meta_check(mpg123_handle *mh)
{
if(mh != NULL) return mh->metaflags;
else return 0;
}
 
int attribute_align_arg mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2)
{
ALIGNCHECK(mh);
if(v1 != NULL) *v1 = NULL;
if(v2 != NULL) *v2 = NULL;
if(mh == NULL) return MPG123_ERR;
 
if(mh->metaflags & MPG123_ID3)
{
id3_link(mh);
if(v1 != NULL && mh->rdat.flags & READER_ID3TAG) *v1 = (mpg123_id3v1*) mh->id3buf;
if(v2 != NULL)
#ifdef NO_ID3V2
*v2 = NULL;
#else
*v2 = &mh->id3v2;
#endif
 
mh->metaflags |= MPG123_ID3;
mh->metaflags &= ~MPG123_NEW_ID3;
}
return MPG123_OK;
}
 
int attribute_align_arg mpg123_icy(mpg123_handle *mh, char **icy_meta)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
#ifndef NO_ICY
if(icy_meta == NULL)
{
mh->err = MPG123_NULL_POINTER;
return MPG123_ERR;
}
*icy_meta = NULL;
 
if(mh->metaflags & MPG123_ICY)
{
*icy_meta = mh->icy.data;
mh->metaflags |= MPG123_ICY;
mh->metaflags &= ~MPG123_NEW_ICY;
}
return MPG123_OK;
#else
mh->err = MPG123_MISSING_FEATURE;
return MPG123_ERR;
#endif
}
 
/*
Simple utility functions that do not possibly call code with extra alignment requirements do not use the ALIGNCHECK.
I am aware of the chance that the compiler could have introduced such code outside assembly functions, but such a modern compiler (gcc) can also honour attribute_align_arg.
*/
 
char* attribute_align_arg mpg123_icy2utf8(const char* icy_text)
{
#ifndef NO_ICY
return icy2utf8(icy_text, 0);
#else
return NULL;
#endif
}
 
/* That one is always defined... it's not worth it to remove it for NO_ID3V2. */
enum mpg123_text_encoding attribute_align_arg mpg123_enc_from_id3(unsigned char id3_enc_byte)
{
switch(id3_enc_byte)
{
case mpg123_id3_latin1: return mpg123_text_latin1;
case mpg123_id3_utf16bom: return mpg123_text_utf16bom; /* ID3v2.3 has UCS-2 with BOM here. */
case mpg123_id3_utf16be: return mpg123_text_utf16be;
case mpg123_id3_utf8: return mpg123_text_utf8;
default: return mpg123_text_unknown;
}
}
 
#ifndef NO_STRING
int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size)
{
switch(enc)
{
#ifndef NO_ID3V2
/* The encodings we get from ID3v2 tags. */
case mpg123_text_utf8:
id3_to_utf8(sb, mpg123_id3_utf8, source, source_size, 0);
break;
case mpg123_text_latin1:
id3_to_utf8(sb, mpg123_id3_latin1, source, source_size, 0);
break;
case mpg123_text_utf16bom:
case mpg123_text_utf16:
id3_to_utf8(sb, mpg123_id3_utf16bom, source, source_size, 0);
break;
/* Special because one cannot skip zero bytes here. */
case mpg123_text_utf16be:
id3_to_utf8(sb, mpg123_id3_utf16be, source, source_size, 0);
break;
#endif
#ifndef NO_ICY
/* ICY encoding... */
case mpg123_text_icy:
case mpg123_text_cp1252:
{
mpg123_free_string(sb);
/* Paranoia: Make sure that the string ends inside the buffer... */
if(source[source_size-1] == 0)
{
/* Convert from ICY encoding... with force applied or not. */
char *tmpstring = icy2utf8((const char*)source, enc == mpg123_text_cp1252 ? 1 : 0);
if(tmpstring != NULL)
{
mpg123_set_string(sb, tmpstring);
free(tmpstring);
}
}
}
break;
#endif
default:
mpg123_free_string(sb);
}
/* At least a trailing null of some form should be there... */
return (sb->fill > 0) ? 1 : 0;
}
#endif
 
int attribute_align_arg mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(offsets == NULL || step == NULL || fill == NULL)
{
mh->err = MPG123_BAD_INDEX_PAR;
return MPG123_ERR;
}
#ifdef FRAME_INDEX
*offsets = mh->index.data;
*step = mh->index.step;
*fill = mh->index.fill;
#else
*offsets = NULL;
*step = 0;
*fill = 0;
#endif
return MPG123_OK;
}
 
int attribute_align_arg mpg123_close(mpg123_handle *mh)
{
ALIGNCHECK(mh);
if(mh == NULL) return MPG123_ERR;
if(mh->rd != NULL && mh->rd->close != NULL) mh->rd->close(mh);
mh->rd = NULL;
if(mh->new_format)
{
debug("Hey, we are closing a track before the new format has been queried...");
invalidate_format(&mh->af);
mh->new_format = 0;
}
return MPG123_OK;
}
 
void attribute_align_arg mpg123_delete(mpg123_handle *mh)
{
if(mh != NULL)
{
mpg123_close(mh);
frame_exit(mh); /* free buffers in frame */
free(mh); /* free struct; cast? */
}
}
 
static const char *mpg123_error[] =
{
"No error... (code 0)",
"Unable to set up output format! (code 1)",
"Invalid channel number specified. (code 2)",
"Invalid sample rate specified. (code 3)",
"Unable to allocate memory for 16 to 8 converter table! (code 4)",
"Bad parameter id! (code 5)",
"Bad buffer given -- invalid pointer or too small size. (code 6)",
"Out of memory -- some malloc() failed. (code 7)",
"You didn't initialize the library! (code 8)",
"Invalid decoder choice. (code 9)",
"Invalid mpg123 handle. (code 10)",
"Unable to initialize frame buffers (out of memory?)! (code 11)",
"Invalid RVA mode. (code 12)",
"This build doesn't support gapless decoding. (code 13)",
"Not enough buffer space. (code 14)",
"Incompatible numeric data types. (code 15)",
"Bad equalizer band. (code 16)",
"Null pointer given where valid storage address needed. (code 17)",
"Error reading the stream. (code 18)",
"Cannot seek from end (end is not known). (code 19)",
"Invalid 'whence' for seek function. (code 20)",
"Build does not support stream timeouts. (code 21)",
"File access error. (code 22)",
"Seek not supported by stream. (code 23)",
"No stream opened. (code 24)",
"Bad parameter handle. (code 25)",
"Invalid parameter addresses for index retrieval. (code 26)",
"Lost track in the bytestream and did not attempt resync. (code 27)",
"Failed to find valid MPEG data within limit on resync. (code 28)",
"No 8bit encoding possible. (code 29)",
"Stack alignment is not good. (code 30)",
"You gave me a NULL buffer? (code 31)",
"File position is screwed up, please do an absolute seek (code 32)",
"Inappropriate NULL-pointer provided.",
"Bad key value given.",
"There is no frame index (disabled in this build).",
"Frame index operation failed.",
"Decoder setup failed (invalid combination of settings?)",
"Feature not in this build."
,"Some bad value has been provided."
,"Low-level seeking has failed (call to lseek(), usually)."
};
 
const char* attribute_align_arg mpg123_plain_strerror(int errcode)
{
if(errcode >= 0 && errcode < sizeof(mpg123_error)/sizeof(char*))
return mpg123_error[errcode];
else switch(errcode)
{
case MPG123_ERR:
return "A generic mpg123 error.";
case MPG123_DONE:
return "Message: I am done with this track.";
case MPG123_NEED_MORE:
return "Message: Feed me more input data!";
case MPG123_NEW_FORMAT:
return "Message: Prepare for a changed audio format (query the new one)!";
default:
return "I have no idea - an unknown error code!";
}
}
 
int attribute_align_arg mpg123_errcode(mpg123_handle *mh)
{
if(mh != NULL) return mh->err;
return MPG123_BAD_HANDLE;
}
 
const char* attribute_align_arg mpg123_strerror(mpg123_handle *mh)
{
return mpg123_plain_strerror(mpg123_errcode(mh));
}
/programs/develop/libraries/libmpg123/mangle.h
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 */
 
/programs/develop/libraries/libmpg123/mpg123.h
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
/programs/develop/libraries/libmpg123/mpg123lib_intern.h
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
/programs/develop/libraries/libmpg123/optimize.c
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
}
/programs/develop/libraries/libmpg123/optimize.h
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 */
 
/programs/develop/libraries/libmpg123/parse.c
0,0 → 1,1091
/*
parse: spawned from common; clustering around stream/frame parsing
 
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 & Thomas Orgis
*/
 
#include "mpg123lib_intern.h"
 
#include <sys/stat.h>
#include <fcntl.h>
 
#include "getbits.h"
 
 
/* a limit for number of frames in a track; beyond that unsigned long may not be enough to hold byte addresses */
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef ULONG_MAX
/* hm, is this portable across preprocessors? */
#define ULONG_MAX ((unsigned long)-1)
#endif
#define TRACK_MAX_FRAMES ULONG_MAX/4/1152
 
#include "debug.h"
 
#define bsbufid(fr) (fr)->bsbuf==(fr)->bsspace[0] ? 0 : ((fr)->bsbuf==fr->bsspace[1] ? 1 : ( (fr)->bsbuf==(fr)->bsspace[0]+512 ? 2 : ((fr)->bsbuf==fr->bsspace[1]+512 ? 3 : -1) ) )
 
/*
AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
A: sync
B: mpeg version
C: layer
D: CRC
E: bitrate
F:sampling rate
G: padding
H: private
I: channel mode
J: mode ext
K: copyright
L: original
M: emphasis
 
old compare mask 0xfffffd00:
11111111 11111111 11111101 00000000
 
means: everything must match excluding padding and channel mode, ext mode, ...
But a vbr stream's headers will differ in bitrate!
We are already strict in allowing only frames of same type in stream, we should at least watch out for VBR while being strict.
 
So a better mask is:
11111111 11111111 00001101 00000000
 
Even more, I'll allow varying crc bit.
11111111 11111110 00001101 00000000
 
(still unsure about this private bit)
*/
#define HDRCMPMASK 0xfffe0d00
#define HDRSAMPMASK 0xc00 /* 1100 00000000, FF bits (sample rate) */
 
/* bitrates for [mpeg1/2][layer] */
static const int tabsel_123[2][3][16] =
{
{
{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
{0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
{0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,}
},
{
{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}
}
};
 
const long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 };
 
static int decode_header(mpg123_handle *fr,unsigned long newhead);
 
int read_frame_init(mpg123_handle* fr)
{
if(frame_reset(fr) != 0) return -1;
return 0;
}
 
/* These two are to be replaced by one function that gives all the frame parameters (for outsiders).*/
 
int frame_bitrate(mpg123_handle *fr)
{
return tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
}
 
long frame_freq(mpg123_handle *fr)
{
return freqs[fr->sampling_frequency];
}
 
#define free_format_header(head) ( ((head & 0xffe00000) == 0xffe00000) && ((head>>17)&3) && (((head>>12)&0xf) == 0x0) && (((head>>10)&0x3) != 0x3 ))
 
/* compiler is smart enought to inline this one or should I really do it as macro...? */
int head_check(unsigned long head)
{
if
(
/* first 11 bits are set to 1 for frame sync */
((head & 0xffe00000) != 0xffe00000)
||
/* layer: 01,10,11 is 1,2,3; 00 is reserved */
(!((head>>17)&3))
||
/* 1111 means bad bitrate */
(((head>>12)&0xf) == 0xf)
||
/* sampling freq: 11 is reserved */
(((head>>10)&0x3) == 0x3 )
/* here used to be a mpeg 2.5 check... re-enabled 2.5 decoding due to lack of evidence that it is really not good */
)
{
return FALSE;
}
/* if no check failed, the header is valid (hopefully)*/
else
{
return TRUE;
}
}
 
static int check_lame_tag(mpg123_handle *fr)
{
/*
going to look for Xing or Info at some position after the header
MPEG 1 MPEG 2/2.5 (LSF)
Stereo, Joint Stereo, Dual Channel 32 17
Mono 17 9
 
Also, how to avoid false positives? I guess I should interpret more of the header to rule that out(?).
I hope that ensuring all zeros until tag start is enough.
*/
int lame_offset = (fr->stereo == 2) ? (fr->lsf ? 17 : 32 ) : (fr->lsf ? 9 : 17);
/* At least skip the decoder delay. */
#ifdef GAPLESS
if(fr->begin_s == 0) frame_gapless_init(fr, GAPLESS_DELAY, 0);
#endif
 
if(fr->framesize >= 120+lame_offset) /* traditional Xing header is 120 bytes */
{
int i;
int lame_type = 0;
debug("do we have lame tag?");
/* only search for tag when all zero before it (apart from checksum) */
for(i=2; i < lame_offset; ++i) if(fr->bsbuf[i] != 0) break;
if(i == lame_offset)
{
debug("possibly...");
if
(
(fr->bsbuf[lame_offset] == 'I')
&& (fr->bsbuf[lame_offset+1] == 'n')
&& (fr->bsbuf[lame_offset+2] == 'f')
&& (fr->bsbuf[lame_offset+3] == 'o')
)
{
lame_type = 1; /* We still have to see what there is */
}
else if
(
(fr->bsbuf[lame_offset] == 'X')
&& (fr->bsbuf[lame_offset+1] == 'i')
&& (fr->bsbuf[lame_offset+2] == 'n')
&& (fr->bsbuf[lame_offset+3] == 'g')
)
{
lame_type = 2;
fr->vbr = MPG123_VBR; /* Xing header means always VBR */
}
if(lame_type)
{
unsigned long xing_flags;
 
/* we have one of these headers... */
if(VERBOSE2) fprintf(stderr, "Note: Xing/Lame/Info header detected\n");
/* now interpret the Xing part, I have 120 bytes total for sure */
/* there are 4 bytes for flags, but only the last byte contains known ones */
lame_offset += 4; /* now first byte after Xing/Name */
/* 4 bytes dword for flags */
#define make_long(a, o) ((((unsigned long) a[o]) << 24) | (((unsigned long) a[o+1]) << 16) | (((unsigned long) a[o+2]) << 8) | ((unsigned long) a[o+3]))
/* 16 bit */
#define make_short(a,o) ((((unsigned short) a[o]) << 8) | ((unsigned short) a[o+1]))
xing_flags = make_long(fr->bsbuf, lame_offset);
lame_offset += 4;
debug1("Xing: flags 0x%08lx", xing_flags);
if(xing_flags & 1) /* frames */
{
/*
In theory, one should use that value for skipping...
When I know the exact number of samples I could simply count in flush_output,
but that's problematic with seeking and such.
I still miss the real solution for detecting the end.
*/
fr->track_frames = (off_t) make_long(fr->bsbuf, lame_offset);
if(fr->track_frames > TRACK_MAX_FRAMES) fr->track_frames = 0; /* endless stream? */
#ifdef GAPLESS
/* if no further info there, remove/add at least the decoder delay */
if(fr->p.flags & MPG123_GAPLESS)
{
off_t length = fr->track_frames * spf(fr);
if(length > 1)
frame_gapless_init(fr, GAPLESS_DELAY, length+GAPLESS_DELAY);
}
#endif
if(VERBOSE3) fprintf(stderr, "Note: Xing: %lu frames\n", (long unsigned)fr->track_frames);
lame_offset += 4;
}
if(xing_flags & 0x2) /* bytes */
{
unsigned long xing_bytes = make_long(fr->bsbuf, lame_offset); /* We assume that this is the _total_ size of the file, including Xing frame ... and ID3 frames...
It's not that clearly documented... */
if(fr->rdat.filelen < 1)
fr->rdat.filelen = (off_t) xing_bytes; /* One could start caring for overflow here. */
else
{
if((off_t) xing_bytes != fr->rdat.filelen && NOQUIET)
{
double diff = 1.0/fr->rdat.filelen * (fr->rdat.filelen - (off_t)xing_bytes);
if(diff < 0.) diff = -diff;
 
if(VERBOSE3)
fprintf(stderr, "Note: Xing stream size %lu differs by %f%% from determined/given file size!\n", xing_bytes, diff);
 
if(diff > 1.)
fprintf(stderr, "Warning: Xing stream size off by more than 1%%, fuzzy seeking may be even more fuzzy than by design!\n");
}
}
 
if(VERBOSE3)
fprintf(stderr, "Note: Xing: %lu bytes\n", (long unsigned)xing_bytes);
 
lame_offset += 4;
}
if(xing_flags & 0x4) /* TOC */
{
frame_fill_toc(fr, fr->bsbuf+lame_offset);
lame_offset += 100; /* just skip */
}
if(xing_flags & 0x8) /* VBR quality */
{
if(VERBOSE3)
{
unsigned long xing_quality = make_long(fr->bsbuf, lame_offset);
fprintf(stderr, "Note: Xing: quality = %lu\n", (long unsigned)xing_quality);
}
lame_offset += 4;
}
/* I guess that either 0 or LAME extra data follows */
/* there may this crc16 be floating around... (?) */
if(fr->bsbuf[lame_offset] != 0)
{
unsigned char lame_vbr;
float replay_gain[2] = {0,0};
float peak = 0;
float gain_offset = 0; /* going to be +6 for old lame that used 83dB */
char nb[10];
memcpy(nb, fr->bsbuf+lame_offset, 9);
nb[9] = 0;
if(VERBOSE3) fprintf(stderr, "Note: Info: Encoder: %s\n", nb);
if(!strncmp("LAME", nb, 4))
{
gain_offset = 6;
debug("TODO: finish lame detetcion...");
}
lame_offset += 9;
/* the 4 big bits are tag revision, the small bits vbr method */
lame_vbr = fr->bsbuf[lame_offset] & 15;
if(VERBOSE3)
{
fprintf(stderr, "Note: Info: rev %u\n", fr->bsbuf[lame_offset] >> 4);
fprintf(stderr, "Note: Info: vbr mode %u\n", lame_vbr);
}
lame_offset += 1;
switch(lame_vbr)
{
/* from rev1 proposal... not sure if all good in practice */
case 1:
case 8: fr->vbr = MPG123_CBR; break;
case 2:
case 9: fr->vbr = MPG123_ABR; break;
default: fr->vbr = MPG123_VBR; /* 00==unknown is taken as VBR */
}
/* skipping: lowpass filter value */
lame_offset += 1;
/* replaygain */
/* 32bit float: peak amplitude -- why did I parse it as int before??*/
/* Ah, yes, lame seems to store it as int since some day in 2003; I've only seen zeros anyway until now, bah! */
if
(
(fr->bsbuf[lame_offset] != 0)
|| (fr->bsbuf[lame_offset+1] != 0)
|| (fr->bsbuf[lame_offset+2] != 0)
|| (fr->bsbuf[lame_offset+3] != 0)
)
{
debug("Wow! Is there _really_ a non-zero peak value? Now is it stored as float or int - how should I know?");
/* byte*peak_bytes = (byte*) &peak;
... endianess ... just copy bytes to avoid floating point operation on unaligned memory?
peak_bytes[0] = ...
peak = *(float*) (fr->bsbuf+lame_offset); */
}
if(VERBOSE3) fprintf(stderr, "Note: Info: peak = %f (I won't use this)\n", peak);
peak = 0; /* until better times arrived */
lame_offset += 4;
/*
ReplayGain values - lame only writes radio mode gain...
16bit gain, 3 bits name, 3 bits originator, sign (1=-, 0=+), dB value*10 in 9 bits (fixed point)
ignore the setting if name or originator == 000!
radio 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1
audiophile 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0
*/
 
for(i =0; i < 2; ++i)
{
unsigned char origin = (fr->bsbuf[lame_offset] >> 2) & 0x7; /* the 3 bits after that... */
if(origin != 0)
{
unsigned char gt = fr->bsbuf[lame_offset] >> 5; /* only first 3 bits */
if(gt == 1) gt = 0; /* radio */
else if(gt == 2) gt = 1; /* audiophile */
else continue;
/* get the 9 bits into a number, divide by 10, multiply sign... happy bit banging */
replay_gain[0] = (float) ((fr->bsbuf[lame_offset] & 0x2) ? -0.1 : 0.1) * (make_short(fr->bsbuf, lame_offset) & 0x1f);
}
lame_offset += 2;
}
if(VERBOSE3)
{
fprintf(stderr, "Note: Info: Radio Gain = %03.1fdB\n", replay_gain[0]);
fprintf(stderr, "Note: Info: Audiophile Gain = %03.1fdB\n", replay_gain[1]);
}
for(i=0; i < 2; ++i)
{
if(fr->rva.level[i] <= 0)
{
fr->rva.peak[i] = 0; /* at some time the parsed peak should be used */
fr->rva.gain[i] = replay_gain[i];
fr->rva.level[i] = 0;
}
}
lame_offset += 1; /* skipping encoding flags byte */
if(fr->vbr == MPG123_ABR)
{
fr->abr_rate = fr->bsbuf[lame_offset];
if(VERBOSE3) fprintf(stderr, "Note: Info: ABR rate = %u\n", fr->abr_rate);
}
lame_offset += 1;
/* encoder delay and padding, two 12 bit values... lame does write them from int ...*/
if(VERBOSE3)
fprintf(stderr, "Note: Encoder delay = %i; padding = %i\n",
((((int) fr->bsbuf[lame_offset]) << 4) | (((int) fr->bsbuf[lame_offset+1]) >> 4)),
(((((int) fr->bsbuf[lame_offset+1]) << 8) | (((int) fr->bsbuf[lame_offset+2]))) & 0xfff) );
#ifdef GAPLESS
if(fr->p.flags & MPG123_GAPLESS)
{
off_t length = fr->track_frames * spf(fr);
off_t skipbegin = GAPLESS_DELAY + ((((int) fr->bsbuf[lame_offset]) << 4) | (((int) fr->bsbuf[lame_offset+1]) >> 4));
off_t skipend = -GAPLESS_DELAY + (((((int) fr->bsbuf[lame_offset+1]) << 8) | (((int) fr->bsbuf[lame_offset+2]))) & 0xfff);
debug3("preparing gapless mode for layer3: length %lu, skipbegin %lu, skipend %lu",
(long unsigned)length, (long unsigned)skipbegin, (long unsigned)skipend);
if(length > 1)
frame_gapless_init(fr, skipbegin, (skipend < length) ? length-skipend : length);
}
#endif
}
/* switch buffer back ... */
fr->bsbuf = fr->bsspace[fr->bsnum]+512;
fr->bsnum = (fr->bsnum + 1) & 1;
return 1; /* got it! */
}
}
}
return 0; /* no lame tag */
}
 
/* Just tell if the header is some mono. */
static int header_mono(unsigned long newhead)
{
return ((newhead>>6)&0x3) == MPG_MD_MONO ? TRUE : FALSE;
}
 
/*
That's a big one: read the next frame. 1 is success, <= 0 is some error
Special error READER_MORE means: Please feed more data and try again.
*/
int read_frame(mpg123_handle *fr)
{
/* TODO: rework this thing */
unsigned long newhead;
off_t framepos;
int ret;
/* stuff that needs resetting if complete frame reading fails */
int oldsize = fr->framesize;
int oldphase = fr->halfphase;
fr->fsizeold=fr->framesize; /* for Layer3 */
 
/* Speed-down hack: Play it again, Sam (the frame, I mean). */
if (fr->p.halfspeed)
{
if(fr->halfphase) /* repeat last frame */
{
debug("repeat!");
fr->to_decode = fr->to_ignore = TRUE;
--fr->halfphase;
fr->bitindex = 0;
fr->wordpointer = (unsigned char *) fr->bsbuf;
if(fr->lay == 3) memcpy (fr->bsbuf, fr->ssave, fr->ssize);
if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
return 1;
}
else
{
fr->halfphase = fr->p.halfspeed - 1;
}
}
 
read_again:
debug2("trying to get frame %li at 0x%lx", (long)fr->num+1, (unsigned long)fr->rd->tell(fr));
if((ret = fr->rd->head_read(fr,&newhead)) <= 0){ debug("need more?"); goto read_frame_bad;}
 
init_resync:
 
fr->header_change = 2; /* output format change is possible... */
if(fr->oldhead) /* check a following header for change */
{
if(fr->oldhead == newhead) fr->header_change = 0;
else
/* If they have the same sample rate. Note that only is _not_ the case for the first header, as we enforce sample rate match for following frames.
So, during one stream, only change of stereoness is possible and indicated by header_change == 2. */
if((fr->oldhead & HDRSAMPMASK) == (newhead & HDRSAMPMASK))
{
/* Now if both channel modes are mono or both stereo, it's no big deal. */
if( header_mono(fr->oldhead) == header_mono(newhead))
fr->header_change = 1;
}
}
 
#ifdef SKIP_JUNK
/* watch out for junk/tags on beginning of stream by invalid header */
if(!fr->firsthead && !head_check(newhead)) {
int i;
 
/* check for id3v2; first three bytes (of 4) are "ID3" */
if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
{
int id3ret = 0;
id3ret = parse_new_id3(fr, newhead);
if (id3ret < 0){ debug("need more?"); ret = id3ret; goto read_frame_bad; }
#ifndef NO_ID3V2
else if(id3ret > 0){ debug("got ID3v2"); fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3; }
else debug("no useful ID3v2");
#endif
 
fr->oldhead = 0;
goto read_again; /* Also in case of invalid ID3 tag (ret==0), try to get on track again. */
}
else if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Junk at the beginning (0x%08lx)\n",newhead);
 
/* I even saw RIFF headers at the beginning of MPEG streams ;( */
if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F') {
if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr, "Note: Looks like a RIFF header.\n");
 
if((ret=fr->rd->head_read(fr,&newhead))<=0){ debug("need more?"); goto read_frame_bad; }
 
while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a')
{
if((ret=fr->rd->head_shift(fr,&newhead))<=0){ debug("need more?"); goto read_frame_bad; }
}
if((ret=fr->rd->head_read(fr,&newhead))<=0){ debug("need more?"); goto read_frame_bad; }
 
if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Skipped RIFF header!\n");
 
fr->oldhead = 0;
goto read_again;
}
/* unhandled junk... just continue search for a header */
/* step in byte steps through next 64K */
debug("searching for header...");
for(i=0;i<65536;i++) {
if((ret=fr->rd->head_shift(fr,&newhead))<=0){ debug("need more?"); goto read_frame_bad; }
/* if(head_check(newhead)) */
if(head_check(newhead) && decode_header(fr, newhead))
break;
}
if(i == 65536)
{
if(NOQUIET) error("Giving up searching valid MPEG header after 64K of junk.");
return 0;
}
else debug("hopefully found one...");
/*
* should we additionaly check, whether a new frame starts at
* the next expected position? (some kind of read ahead)
* We could implement this easily, at least for files.
*/
}
#endif
 
/* first attempt of read ahead check to find the real first header; cannot believe what junk is out there! */
/* for now, a spurious first free format header screws up here; need free format support for detecting false free format headers... */
if(!fr->firsthead && fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED) && head_check(newhead) && decode_header(fr, newhead))
{
unsigned long nexthead = 0;
int hd = 0;
off_t start = fr->rd->tell(fr);
debug2("doing ahead check with BPF %d at %li", fr->framesize+4, (long)start);
/* step framesize bytes forward and read next possible header*/
if((ret=fr->rd->skip_bytes(fr, fr->framesize))<0)
{
if(ret==READER_ERROR && NOQUIET) error("cannot seek!");
goto read_frame_bad;
}
hd = fr->rd->head_read(fr,&nexthead);
if(hd==MPG123_NEED_MORE){ debug("need more?"); ret = hd; goto read_frame_bad; }
if((ret=fr->rd->back_bytes(fr, fr->rd->tell(fr)-start))<0)
{
if(ret==READER_ERROR && NOQUIET) error("cannot seek!");
else debug("need more?");
goto read_frame_bad;
}
debug1("After fetching next header, at %li", (long)fr->rd->tell(fr));
if(!hd)
{
if(NOQUIET) warning("cannot read next header, a one-frame stream? Duh...");
}
else
{
debug2("does next header 0x%08lx match first 0x%08lx?", nexthead, newhead);
/* not allowing free format yet */
if(!head_check(nexthead) || (nexthead & HDRCMPMASK) != (newhead & HDRCMPMASK))
{
debug("No, the header was not valid, start from beginning...");
fr->oldhead = 0; /* start over */
/* try next byte for valid header */
if((ret=fr->rd->back_bytes(fr, 3))<0)
{
if(NOQUIET) error("cannot seek!");
else debug("need more?");
goto read_frame_bad;
}
goto read_again;
}
}
}
 
/* why has this head check been avoided here before? */
if(!head_check(newhead))
{
/* and those ugly ID3 tags */
if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8))
{
fr->id3buf[0] = (unsigned char) ((newhead >> 24) & 0xff);
fr->id3buf[1] = (unsigned char) ((newhead >> 16) & 0xff);
fr->id3buf[2] = (unsigned char) ((newhead >> 8) & 0xff);
fr->id3buf[3] = (unsigned char) ( newhead & 0xff);
if((ret=fr->rd->fullread(fr,fr->id3buf+4,124)) < 0){ debug("need more?"); goto read_frame_bad; }
fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3;
fr->rdat.flags |= READER_ID3TAG; /* that marks id3v1 */
if (VERBOSE2) fprintf(stderr,"Note: Skipped ID3 Tag!\n");
goto read_again;
}
/* duplicated code from above! */
/* check for id3v2; first three bytes (of 4) are "ID3" */
if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
{
int id3length = 0;
id3length = parse_new_id3(fr, newhead);
if(id3length < 0){ debug("need more?"); ret = id3length; goto read_frame_bad; }
 
fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3;
goto read_again;
}
else if(NOQUIET && fr->silent_resync == 0)
{
fprintf(stderr,"Note: Illegal Audio-MPEG-Header 0x%08lx at offset 0x%lx.\n",
newhead, (long unsigned int)fr->rd->tell(fr)-4);
}
 
if(NOQUIET && (newhead & 0xffffff00) == ('b'<<24)+('m'<<16)+('p'<<8)) fprintf(stderr,"Note: Could be a BMP album art.\n");
/* Do resync if not forbidden by flag.
I used to have a check for not-icy-meta here, but concluded that the desync issues came from a reader bug, not the stream. */
if( !(fr->p.flags & MPG123_NO_RESYNC) )
{
long try = 0;
long limit = fr->p.resync_limit;
/* If a resync is needed the bitreservoir of previous frames is no longer valid */
fr->bitreservoir = 0;
 
/* TODO: make this more robust, I'd like to cat two mp3 fragments together (in a dirty way) and still have mpg123 beign able to decode all it somehow. */
if(NOQUIET && fr->silent_resync == 0) fprintf(stderr, "Note: Trying to resync...\n");
/* Read more bytes until we find something that looks
reasonably like a valid header. This is not a
perfect strategy, but it should get us back on the
track within a short time (and hopefully without
too much distortion in the audio output). */
do
{
++try;
if(limit >= 0 && try >= limit) break;
 
if((ret=fr->rd->head_shift(fr,&newhead)) <= 0)
{
debug("need more?");
if(NOQUIET) fprintf (stderr, "Note: Hit end of (available) data during resync.\n");
 
goto read_frame_bad;
}
if(VERBOSE3) debug3("resync try %li at 0x%lx, got newhead 0x%08lx", try, (unsigned long)fr->rd->tell(fr), newhead);
 
if(!fr->oldhead)
{
debug("going to init_resync...");
goto init_resync; /* "considered harmful", eh? */
}
/* we should perhaps collect a list of valid headers that occured in file... there can be more */
/* Michael's new resync routine seems to work better with the one frame readahead (and some input buffering?) */
} while
(
!head_check(newhead) /* Simply check for any valid header... we have the readahead to get it straight now(?) */
/* (newhead & HDRCMPMASK) != (fr->oldhead & HDRCMPMASK)
&& (newhead & HDRCMPMASK) != (fr->firsthead & HDRCMPMASK)*/
);
/* too many false positives
}while (!(head_check(newhead) && decode_header(fr, newhead))); */
if(NOQUIET && fr->silent_resync == 0) fprintf (stderr, "Note: Skipped %li bytes in input.\n", try);
 
if(limit >= 0 && try >= limit)
{
if(NOQUIET)
error1("Giving up resync after %li bytes - your stream is not nice... (maybe increasing resync limit could help).", try);
 
fr->err = MPG123_RESYNC_FAIL;
return READER_ERROR;
}
else
{
debug1("Found valid header 0x%lx... unsetting firsthead to reinit stream.", newhead);
fr->firsthead = 0;
goto init_resync;
}
}
else
{
if(NOQUIET) error("not attempting to resync...");
 
fr->err = MPG123_OUT_OF_SYNC;
return READER_ERROR;
}
}
 
if (!fr->firsthead)
{
if(!decode_header(fr,newhead))
{
if(NOQUIET) error("decode header failed before first valid one, going to read again");
 
goto read_again;
}
}
else
if(!decode_header(fr,newhead))
{
if(NOQUIET) error("decode header failed - goto resync");
/* return 0; */
goto init_resync;
}
 
/* if filepos is invalid, so is framepos */
framepos = fr->rd->tell(fr) - 4;
/* flip/init buffer for Layer 3 */
{
unsigned char *newbuf = fr->bsspace[fr->bsnum]+512;
/* read main data into memory */
if((ret=fr->rd->read_frame_body(fr,newbuf,fr->framesize))<0)
{
/* if failed: flip back */
debug("need more?");
goto read_frame_bad;
}
fr->bsbufold = fr->bsbuf;
fr->bsbuf = newbuf;
}
fr->bsnum = (fr->bsnum + 1) & 1;
 
if(!fr->firsthead)
{
fr->firsthead = newhead; /* _now_ it's time to store it... the first real header */
/* This is the first header of our current stream segment.
It is only the actual first header of the whole stream when fr->num is still below zero!
Think of resyncs where firsthead has been reset for format flexibility. */
if(fr->num < 0)
{
fr->audio_start = framepos;
/* Only check for LAME tag at beginning of whole stream
... when there indeed is one in between, it's the user's problem. */
if(fr->lay == 3 && check_lame_tag(fr) == 1)
{ /* ...in practice, Xing/LAME tags are layer 3 only. */
if(fr->rd->forget != NULL) fr->rd->forget(fr);
 
fr->oldhead = 0;
goto read_again;
}
/* now adjust volume */
do_rva(fr);
}
 
debug2("fr->firsthead: %08lx, audio_start: %li", fr->firsthead, (long int)fr->audio_start);
}
 
fr->bitindex = 0;
fr->wordpointer = (unsigned char *) fr->bsbuf;
/* Question: How bad does the floating point value get with repeated recomputation?
Also, considering that we can play the file or parts of many times. */
if(++fr->mean_frames != 0)
{
fr->mean_framesize = ((fr->mean_frames-1)*fr->mean_framesize+compute_bpf(fr)) / fr->mean_frames ;
}
++fr->num; /* 0 for first frame! */
debug4("Frame %li %08lx %i, next filepos=0x%lx",
(long)fr->num, newhead, fr->framesize, (long unsigned)fr->rd->tell(fr));
/* save for repetition */
if(fr->p.halfspeed && fr->lay == 3)
{
debug("halfspeed - reusing old bsbuf ");
memcpy (fr->ssave, fr->bsbuf, fr->ssize);
}
 
/* index the position */
#ifdef FRAME_INDEX
/* Keep track of true frame positions in our frame index.
but only do so when we are sure that the frame number is accurate... */
if(fr->accurate && FI_NEXT(fr->index, fr->num))
fi_add(&fr->index, framepos);
#endif
 
if(fr->silent_resync > 0) --fr->silent_resync;
 
if(fr->rd->forget != NULL) fr->rd->forget(fr);
 
fr->to_decode = fr->to_ignore = TRUE;
if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
 
return 1;
read_frame_bad:
fr->silent_resync = 0;
if(fr->err == MPG123_OK) fr->err = MPG123_ERR_READER;
fr->framesize = oldsize;
fr->halfphase = oldphase;
return ret;
}
 
 
/*
* read ahead and find the next MPEG header, to guess framesize
* return value: guessed framesize
*/
static long guess_freeformat_framesize(mpg123_handle *fr)
{
long i;
int ret;
unsigned long head;
if(!(fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED)))
{
if(NOQUIET) error("Cannot look for freeformat frame size with non-seekable and non-buffered stream!");
return -1;
}
/* FIXME: We need proper handling/passing of MPG123_NEED_MORE! */
if((ret=fr->rd->head_read(fr,&head))<=0)
return -1;
 
/* We are already 4 bytes into it */
for(i=4;i<65536;i++) {
if((ret=fr->rd->head_shift(fr,&head))<=0)
{
return -1;
}
if(head_check(head))
{
int sampling_frequency,mpeg25,lsf;
if(head & (1<<20))
{
lsf = (head & (1<<19)) ? 0x0 : 0x1;
mpeg25 = 0;
}
else
{
lsf = 1;
mpeg25 = 1;
}
if(mpeg25)
sampling_frequency = 6 + ((head>>10)&0x3);
else
sampling_frequency = ((head>>10)&0x3) + (lsf*3);
if((lsf==fr->lsf) && (mpeg25==fr->mpeg25) && (sampling_frequency == fr->sampling_frequency))
{
fr->rd->back_bytes(fr,i+1);
return i-3;
}
}
}
fr->rd->back_bytes(fr,i);
return -1;
}
 
 
/*
* decode a header and write the information
* into the frame structure
*/
static int decode_header(mpg123_handle *fr,unsigned long newhead)
{
if(!head_check(newhead))
{
if(NOQUIET) error("tried to decode obviously invalid header");
 
return 0;
}
if( newhead & (1<<20) )
{
fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
fr->mpeg25 = 0;
}
else
{
fr->lsf = 1;
fr->mpeg25 = 1;
}
 
if( (fr->p.flags & MPG123_NO_RESYNC) || !fr->oldhead
|| (((fr->oldhead>>19)&0x3) ^ ((newhead>>19)&0x3)) )
{
/* If "tryresync" is false, assume that certain
parameters do not change within the stream!
Force an update if lsf or mpeg25 settings
have changed. */
fr->lay = 4-((newhead>>17)&3);
if( ((newhead>>10)&0x3) == 0x3)
{
if(NOQUIET) error("Stream error");
 
return 0; /* exit() here really is too much, isn't it? */
}
if(fr->mpeg25)
fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
else
fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
}
 
#ifdef DEBUG
if((((newhead>>16)&0x1)^0x1) != fr->error_protection) debug("changed crc bit!");
#endif
fr->error_protection = ((newhead>>16)&0x1)^0x1; /* seen a file where this varies (old lame tag without crc, track with crc) */
fr->bitrate_index = ((newhead>>12)&0xf);
fr->padding = ((newhead>>9)&0x1);
fr->extension = ((newhead>>8)&0x1);
fr->mode = ((newhead>>6)&0x3);
fr->mode_ext = ((newhead>>4)&0x3);
fr->copyright = ((newhead>>3)&0x1);
fr->original = ((newhead>>2)&0x1);
fr->emphasis = newhead & 0x3;
fr->freeformat = free_format_header(newhead);
 
fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
 
fr->oldhead = newhead;
/* we can't use tabsel_123 for freeformat, so trying to guess framesize... */
/* FIXME: We need proper handling/passing of MPG123_NEED_MORE! */
if(fr->freeformat)
{
/* when we first encounter the frame with freeformat, guess framesize */
if(fr->freeformat_framesize < 0)
{
fr->framesize = guess_freeformat_framesize(fr);
if(fr->framesize > 0)
{
fr->freeformat_framesize = fr->framesize - fr->padding;
}
else
{
error("encountered free format header, but failed to guess framesize");
return 0;
}
}
/* freeformat should be CBR, so the same framesize can be used at the 2nd reading or later */
else
{
fr->framesize = fr->freeformat_framesize + fr->padding;
}
}
 
switch(fr->lay)
{
#ifndef NO_LAYER1
case 1:
fr->do_layer = do_layer1;
if(!fr->freeformat)
{
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
}
break;
#endif
#ifndef NO_LAYER2
case 2:
fr->do_layer = do_layer2;
if(!fr->freeformat)
{
debug2("bitrate index: %i (%i)", fr->bitrate_index, tabsel_123[fr->lsf][1][fr->bitrate_index] );
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize += fr->padding - 4;
}
break;
#endif
#ifndef NO_LAYER3
case 3:
fr->do_layer = do_layer3;
if(fr->lsf)
fr->ssize = (fr->stereo == 1) ? 9 : 17;
else
fr->ssize = (fr->stereo == 1) ? 17 : 32;
 
if(fr->error_protection)
fr->ssize += 2;
 
if(!fr->freeformat)
{
fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
fr->framesize = fr->framesize + fr->padding - 4;
}
break;
#endif
default:
if(NOQUIET) error1("Layer type %i not supported in this build!", fr->lay);
 
return 0;
}
if (fr->framesize > MAXFRAMESIZE)
{
if(NOQUIET) error1("Frame size too big: %d", fr->framesize+4-fr->padding);
 
return (0);
}
return 1;
}
 
void set_pointer(mpg123_handle *fr, long backstep)
{
fr->wordpointer = fr->bsbuf + fr->ssize - backstep;
if (backstep)
memcpy(fr->wordpointer,fr->bsbufold+fr->fsizeold-backstep,backstep);
 
fr->bitindex = 0;
}
 
/********************************/
 
double compute_bpf(mpg123_handle *fr)
{
double bpf;
 
switch(fr->lay)
{
case 1:
bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
bpf *= 12000.0 * 4.0;
bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
break;
case 2:
case 3:
bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
bpf *= 144000;
bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
break;
default:
bpf = 1.0;
}
 
return bpf;
}
 
double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
{
static int bs[4] = { 0,384,1152,1152 };
double tpf;
if(fr == NULL) return -1;
 
tpf = (double) bs[fr->lay];
tpf /= freqs[fr->sampling_frequency] << (fr->lsf);
return tpf;
}
 
int attribute_align_arg mpg123_position(mpg123_handle *fr, off_t no, off_t buffsize,
off_t *current_frame, off_t *frames_left,
double *current_seconds, double *seconds_left)
{
double tpf;
double dt = 0.0;
off_t cur, left;
double curs, lefts;
 
if(!fr || !fr->rd) /* Isn't this too paranoid? */
{
debug("reader troubles!");
return MPG123_ERR;
}
 
no += fr->num; /* no starts out as offset */
cur = no;
tpf = mpg123_tpf(fr);
if(buffsize > 0 && fr->af.rate > 0 && fr->af.channels > 0)
{
dt = (double) buffsize / fr->af.rate / fr->af.channels;
if(fr->af.encoding & MPG123_ENC_16) dt *= 0.5;
}
 
left = 0;
 
if((fr->track_frames != 0) && (fr->track_frames >= fr->num)) left = no < fr->track_frames ? fr->track_frames - no : 0;
else
if(fr->rdat.filelen >= 0)
{
double bpf;
off_t t = fr->rd->tell(fr);
bpf = fr->mean_framesize ? fr->mean_framesize : compute_bpf(fr);
left = (off_t)((double)(fr->rdat.filelen-t)/bpf);
/* no can be different for prophetic purposes, file pointer is always associated with fr->num! */
if(fr->num != no)
{
if(fr->num > no) left += fr->num - no;
else
{
if(left >= (no - fr->num)) left -= no - fr->num;
else left = 0; /* uh, oh! */
}
}
/* I totally don't understand why we should re-estimate the given correct(?) value */
/* fr->num = (unsigned long)((double)t/bpf); */
}
 
/* beginning with 0 or 1?*/
curs = (double) no*tpf-dt;
lefts = (double)left*tpf+dt;
#if 0
curs = curs < 0 ? 0.0 : curs;
#endif
if(left < 0 || lefts < 0)
{ /* That is the case for non-seekable streams. */
left = 0;
lefts = 0.0;
}
if(current_frame != NULL) *current_frame = cur;
if(frames_left != NULL) *frames_left = left;
if(current_seconds != NULL) *current_seconds = curs;
if(seconds_left != NULL) *seconds_left = lefts;
return MPG123_OK;
}
 
int get_songlen(mpg123_handle *fr,int no)
{
double tpf;
if(!fr)
return 0;
if(no < 0) {
if(!fr->rd || fr->rdat.filelen < 0)
return 0;
no = (int) ((double) fr->rdat.filelen / compute_bpf(fr));
}
 
tpf = mpg123_tpf(fr);
return (int) (no*tpf);
}
/programs/develop/libraries/libmpg123/parse.h
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
/programs/develop/libraries/libmpg123/reader.h
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
/programs/develop/libraries/libmpg123/readers.c
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;
}
/programs/develop/libraries/libmpg123/sample.h
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
/programs/develop/libraries/libmpg123/stringbuf.c
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);
}
/programs/develop/libraries/libmpg123/synth.c
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
/programs/develop/libraries/libmpg123/synth.h
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
}
/programs/develop/libraries/libmpg123/synth_8bit.h
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;
}
 
/programs/develop/libraries/libmpg123/synth_mmx.S
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
 
/programs/develop/libraries/libmpg123/synth_mono.h
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;
}
/programs/develop/libraries/libmpg123/synth_ntom.h
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;
}
 
/programs/develop/libraries/libmpg123/synth_sse3d.h
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
/programs/develop/libraries/libmpg123/synths.h
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
/programs/develop/libraries/libmpg123/tabinit.c
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
 
/programs/develop/libraries/libmpg123/tabinit_mmx.S
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
/programs/develop/libraries/libmpg123/true.h
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
/programs/develop/libraries/libmpg123
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property
/programs/develop/libraries/zlib/Makefile
7,7 → 7,7
 
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
$(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
/programs/develop/libraries/zlib/zlib.def
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