# HG changeset patch # User Eugene Zagidullin # Date 1201653382 -10800 # Node ID 74c6f3d3cf1d023dcf484769a4e7f83483644cbf # Parent 704607c1f8584276789a1a71cbda57d0d6c588c3 it buids successfully :) diff -r 704607c1f858 -r 74c6f3d3cf1d configure.ac --- a/configure.ac Wed Jan 30 01:22:37 2008 +0300 +++ b/configure.ac Wed Jan 30 03:36:22 2008 +0300 @@ -282,6 +282,54 @@ [AC_MSG_ERROR([Cannot find libmcs])] ) +dnl AltiVec support + +AC_ARG_ENABLE(altivec, + [ --disable-altivec disable AltiVec support. (default=enabled) ], + [enable_altivec=$enableval], + [enable_altivec=yes] +) +if test "x$enable_altivec" = "xyes"; then + AC_CHECK_HEADERS(altivec.h, + [AC_DEFINE(HAVE_ALTIVEC, 1, [Define to 1 if your system has AltiVec.]) + AC_DEFINE(HAVE_ALTIVEC_H, 1, [Define to 1 if your system has an altivec.h file.]) + AC_DEFINE(ARCH_POWERPC, 1, [Define to 1 if your system is a PowerPC.]) + SIMD_CFLAGS=-maltivec + AC_SUBST(SIMD_CFLAGS)], + [enable_altivec="no"] + ) +fi + +dnl SSE2 support + +AC_ARG_ENABLE(sse2, + [ --disable-sse2 disable SSE2 support. (default=enabled) ], + [enable_sse2=$enableval], + [enable_sse2=yes] +) +if test "x$enable_sse2" = "xyes"; then + AC_MSG_CHECKING(SSE2) + ac_save_CFLAGS="$CFLAGS" + CFLAGS="-msse2" + AC_TRY_RUN([ + #include + int main() + { + _mm_setzero_pd(); + return 0; + } + ], + [AC_MSG_RESULT(SSE2 yes) + AC_DEFINE(HAVE_SSE2, 1, [Define to 1 if your system has SSE2]) + SIMD_CFLAGS=-msse2], + [AC_MSG_RESULT(SSE2 no) + enable_sse2="no"], + ) +fi +AC_SUBST(SIMD_CFLAGS) +CFLAGS="$ac_save_CFLAGS" + + AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(fcntl.h) AC_CHECK_HEADERS(sys/ioctl.h) @@ -464,6 +512,9 @@ echo " Automatic character code detection: $enable_chardet" echo " Sample rate upconversion: $enable_samplerate" echo " D-Bus support: $enable_dbus" +echo +echo " SSE2: $enable_sse2" +echo " AltiVec: $enable_altivec" echo if test "$beep_cv_lib_xlibs_threadsafe" = "no"; then diff -r 704607c1f858 -r 74c6f3d3cf1d extra.mk.in --- a/extra.mk.in Wed Jan 30 01:22:37 2008 +0300 +++ b/extra.mk.in Wed Jan 30 03:36:22 2008 +0300 @@ -338,3 +338,4 @@ TRANSPORT_PLUGINS ?= @TRANSPORT_PLUGINS@ PCH ?= @PCH@ IMPLIB_LIBS = @IMPLIB_LIBS@ +SIMD_CFLAGS ?= @SIMD_CFLAGS@ diff -r 704607c1f858 -r 74c6f3d3cf1d src/Makefile --- a/src/Makefile Wed Jan 30 01:22:37 2008 +0300 +++ b/src/Makefile Wed Jan 30 03:36:22 2008 +0300 @@ -1,4 +1,4 @@ -SUBDIRS = libguess audacious libid3tag libSAD +SUBDIRS = libguess libSAD audacious libid3tag include ../extra.mk diff -r 704607c1f858 -r 74c6f3d3cf1d src/audacious/Makefile --- a/src/audacious/Makefile Wed Jan 30 01:22:37 2008 +0300 +++ b/src/audacious/Makefile Wed Jan 30 03:36:22 2008 +0300 @@ -140,7 +140,8 @@ ui/carbon-menubar.ui CLEAN = build_stamp.c libaudacious.exe.a -EXT_DEPS = ../libguess/libguess.a +EXT_DEPS = ../libguess/libguess.a \ + ../libSAD/libSAD.a include ../../buildsys.mk @@ -161,7 +162,9 @@ ${samplerate_CFLAGS} \ ${REGEX_CFLAGS} \ ${LIBMCS_CFLAGS} \ + ${SIMD_CFLAGS} \ -D_AUDACIOUS_CORE \ + -I../libSAD \ -I.. -I../.. \ -I./intl @@ -169,6 +172,7 @@ ${LIBINTL} \ ${samplerate_LIBS} \ ../libguess/libguess.a \ + ../libSAD/libSAD.a \ ${GTK_LIBS} \ ${DBUS_LIBS} \ ${MOWGLI_LIBS} \ diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/Makefile --- a/src/libSAD/Makefile Wed Jan 30 01:22:37 2008 +0300 +++ b/src/libSAD/Makefile Wed Jan 30 03:36:22 2008 +0300 @@ -1,7 +1,6 @@ STATIC_LIB_NOINST = libSAD.a SRCS = dither.c \ dither_ops.c \ - SFMT.c \ noicegen.c include ../../buildsys.mk diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/dither.c --- a/src/libSAD/dither.c Wed Jan 30 01:22:37 2008 +0300 +++ b/src/libSAD/dither.c Wed Jan 30 03:36:22 2008 +0300 @@ -1,7 +1,7 @@ /* Scale & Dither library (libSAD) * High-precision bit depth converter with ReplayGain support * - * (c)2007 by Eugene Zagidullin (e.asphyx@gmail.com) + * Copyright (c) 2007-2008 Eugene Zagidullin (e.asphyx@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +18,9 @@ */ -#include "common.h" -#include "buffer.h" -#include "noisegen.h" +#include "libSAD.h" +#include "dither_ops.h" +#include "noicegen.h" #include #include @@ -89,11 +89,11 @@ * samples < -1 and > 1 will be clipped */ -static inline sad_sint32 __dither_sample_fixed_to_int (sad_sint32 sample, int inbits, int fracbits, int outbits, float scale, int dither, +static inline int32_t __dither_sample_fixed_to_int (int32_t sample, int inbits, int fracbits, int outbits, float scale, int dither, int hardlimit) { int n_bits_to_loose, bitwidth, precision_loss; - sad_sint32 maxint = MAXINT(outbits); + int32_t maxint = MAXINT(outbits); n_bits_to_loose = 0; bitwidth = inbits; @@ -131,7 +131,7 @@ assert(n_bits_to_loose >=0 ); if (hardlimit) { - sample = (sad_sint32)(compute_hardlimit((double)sample/(double)MAXINT(bitwidth), scale) * (double)MAXINT(bitwidth)); + sample = (int32_t)(compute_hardlimit((double)sample/(double)MAXINT(bitwidth), scale) * (double)MAXINT(bitwidth)); #ifdef PRECISION_DEBUG printf("Precision loss, reason: hard limiter\n", inbits, outbits); #endif @@ -150,11 +150,11 @@ if (precision_loss && (n_bits_to_loose >= 1)) sample += (1L << (n_bits_to_loose - 1)); #ifdef DITHER_DEBUG - sad_sint32 val_wo_dither = sample, >> n_bits_to_loose; + int32_t val_wo_dither = sample, >> n_bits_to_loose; val_wo_dither = CLIP(val_wo_dither, maxint); #endif if (dither && precision_loss && (n_bits_to_loose >= 1)) { - sad_sint32 dither_num = triangular_dither_noise(n_bits_to_loose + 1); + int32_t dither_num = triangular_dither_noise(n_bits_to_loose + 1); sample += dither_num; } @@ -162,7 +162,7 @@ /* Clipping */ #ifdef CLIPPING_DEBUG - sad_sint32 val_wo_clip = sample; + int32_t val_wo_clip = sample; #endif sample = CLIP(sample, maxint); #ifdef CLIPPING_DEBUG @@ -180,13 +180,13 @@ * Dither floating-point normalized sample to n-bits integer * samples < -1 and > 1 will be clipped */ -static inline sad_sint32 __dither_sample_float_to_int (float sample, int nbits, float scale, int dither, int hardlimit) { +static inline int32_t __dither_sample_float_to_int (float sample, int nbits, float scale, int dither, int hardlimit) { #ifdef DEEP_DEBUG printf("f: __dither_sample_float_to_int\n"); #endif - sad_sint32 maxint = MAXINT(nbits); + int32_t maxint = MAXINT(nbits); if (hardlimit) { sample = compute_hardlimit((double)sample, scale); @@ -199,7 +199,7 @@ sample = (sample < 0 ? sample - 0.5 : sample + 0.5); #ifdef DITHER_DEBUG - sad_sint32 val_wo_dither = (sad_sint32) sample; + int32_t val_wo_dither = (int32_t) sample; val_wo_dither = CLIP(val_wo_dither, maxint); #endif if (dither) { @@ -208,9 +208,9 @@ } /* Round and clipping */ - sad_sint32 value = (sad_sint32) sample; + int32_t value = (int32_t) sample; #ifdef CLIPPING_DEBUG - sad_sint32 val_wo_clip = value; + int32_t val_wo_clip = value; #endif value = CLIP(value, maxint); #ifdef CLIPPING_DEBUG @@ -237,7 +237,7 @@ return sample; } -static inline float __dither_sample_fixed_to_float (sad_sint32 sample, int inbits, int fracbits, float scale, int hardlimit) { +static inline float __dither_sample_fixed_to_float (int32_t sample, int inbits, int fracbits, float scale, int hardlimit) { float fsample; #ifdef DEEP_DEBUG @@ -396,7 +396,7 @@ for(i=0; i> 8) +#define EXPAND_24_TO_32(x) (((int32_t)(((x) & 0x00ffffff) << 8)) >> 8) /* signed */ -static sad_sint32 get_s24_i_sample (void *buf, int nch, int ch, int i) { - return (sad_sint32)EXPAND_24_TO_32(((sad_sint32*)buf)[i*nch+ch]); +static int32_t get_s24_i_sample (void *buf, int nch, int ch, int i) { + return (int32_t)EXPAND_24_TO_32(((int32_t*)buf)[i*nch+ch]); } -static sad_sint32 get_s24_s_sample (void *buf, int nch, int ch, int i) { - return (sad_sint32)EXPAND_24_TO_32(((sad_sint32**)buf)[ch][i]); +static int32_t get_s24_s_sample (void *buf, int nch, int ch, int i) { + return (int32_t)EXPAND_24_TO_32(((int32_t**)buf)[ch][i]); } -static void put_s24_i_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_sint32*)buf)[i*nch+ch] = (sad_sint32)sample & 0x00ffffff; +static void put_s24_i_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((int32_t*)buf)[i*nch+ch] = (int32_t)sample & 0x00ffffff; } -static void put_s24_s_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_sint32**)buf)[ch][i] = (sad_sint32)sample & 0x00ffffff; +static void put_s24_s_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((int32_t**)buf)[ch][i] = (int32_t)sample & 0x00ffffff; } /* unsigned */ -static sad_sint32 get_u24_i_sample (void *buf, int nch, int ch, int i) { - return (sad_sint32)EXPAND_24_TO_32(((sad_uint32*)buf)[i*nch+ch]) - 8388608; +static int32_t get_u24_i_sample (void *buf, int nch, int ch, int i) { + return (int32_t)EXPAND_24_TO_32(((u_int32_t*)buf)[i*nch+ch]) - 8388608; } -static sad_sint32 get_u24_s_sample (void *buf, int nch, int ch, int i) { - return (sad_sint32)EXPAND_24_TO_32(((sad_uint32**)buf)[ch][i]) - 8388608; +static int32_t get_u24_s_sample (void *buf, int nch, int ch, int i) { + return (int32_t)EXPAND_24_TO_32(((u_int32_t**)buf)[ch][i]) - 8388608; } -static void put_u24_i_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_uint32*)buf)[i*nch+ch] = ((sad_uint32)sample + 8388608) & 0x00ffffff; +static void put_u24_i_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((u_int32_t*)buf)[i*nch+ch] = ((u_int32_t)sample + 8388608) & 0x00ffffff; } -static void put_u24_s_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_uint32**)buf)[ch][i] = ((sad_uint32)sample + 8388608) & 0x00ffffff; +static void put_u24_s_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((u_int32_t**)buf)[ch][i] = ((u_int32_t)sample + 8388608) & 0x00ffffff; } static SAD_buffer_ops buf_s24_i_ops = { @@ -210,37 +210,37 @@ **********/ /* signed */ -static sad_sint32 get_s32_i_sample (void *buf, int nch, int ch, int i) { - return ((sad_sint32*)buf)[i*nch+ch]; +static int32_t get_s32_i_sample (void *buf, int nch, int ch, int i) { + return ((int32_t*)buf)[i*nch+ch]; } -static sad_sint32 get_s32_s_sample (void *buf, int nch, int ch, int i) { - return ((sad_sint32**)buf)[ch][i]; +static int32_t get_s32_s_sample (void *buf, int nch, int ch, int i) { + return ((int32_t**)buf)[ch][i]; } -static void put_s32_i_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_sint32*)buf)[i*nch+ch] = (sad_sint32)sample; +static void put_s32_i_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((int32_t*)buf)[i*nch+ch] = (int32_t)sample; } -static void put_s32_s_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_sint32**)buf)[ch][i] = (sad_sint32)sample; +static void put_s32_s_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((int32_t**)buf)[ch][i] = (int32_t)sample; } /* unsigned */ -static sad_sint32 get_u32_i_sample (void *buf, int nch, int ch, int i) { - return ((sad_sint32*)buf)[i*nch+ch] - (sad_sint32)(1L<<31); +static int32_t get_u32_i_sample (void *buf, int nch, int ch, int i) { + return ((int32_t*)buf)[i*nch+ch] - (int32_t)(1L<<31); } -static sad_sint32 get_u32_s_sample (void *buf, int nch, int ch, int i) { - return ((sad_sint32**)buf)[ch][i] - (sad_sint32)(1L<<31); +static int32_t get_u32_s_sample (void *buf, int nch, int ch, int i) { + return ((int32_t**)buf)[ch][i] - (int32_t)(1L<<31); } -static void put_u32_i_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_uint32*)buf)[i*nch+ch] = (sad_uint32)(sample + (sad_sint32)(1L<<31)); +static void put_u32_i_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((u_int32_t*)buf)[i*nch+ch] = (u_int32_t)(sample + (int32_t)(1L<<31)); } -static void put_u32_s_sample (void *buf, sad_sint32 sample, int nch, int ch, int i) { - ((sad_uint32**)buf)[ch][i] = (sad_uint32)(sample + (sad_sint32)(1L<<31)); +static void put_u32_s_sample (void *buf, int32_t sample, int nch, int ch, int i) { + ((u_int32_t**)buf)[ch][i] = (u_int32_t)(sample + (int32_t)(1L<<31)); } static SAD_buffer_ops buf_s32_i_ops = { diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/dither_ops.h --- a/src/libSAD/dither_ops.h Wed Jan 30 01:22:37 2008 +0300 +++ b/src/libSAD/dither_ops.h Wed Jan 30 03:36:22 2008 +0300 @@ -1,7 +1,7 @@ /* Scale & Dither library (libSAD) * High-precision bit depth converter with ReplayGain support * - * (c)2007 by Eugene Zagidullin (e.asphyx@gmail.com) + * Copyright (c) 2007-2008 Eugene Zagidullin (e.asphyx@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +17,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef BUFFER_H -#define BUFFER_H +#ifndef DITHER_OPS_H +#define DITHER_OPS_H -#include "common.h" +#include "libSAD.h" #include "dither.h" SAD_buffer_ops* SAD_assign_buf_ops (SAD_buffer_format *format); -#endif /*BUFFER_H*/ +#endif /*DITHER_OPS_H*/ diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/libSAD.h --- a/src/libSAD/libSAD.h Wed Jan 30 01:22:37 2008 +0300 +++ b/src/libSAD/libSAD.h Wed Jan 30 03:36:22 2008 +0300 @@ -1,7 +1,7 @@ /* Scale & Dither library (libSAD) * High-precision bit depth converter with ReplayGain support * - * (c)2007 by Eugene Zagidullin (e.asphyx@gmail.com) + * Copyright (c) 2007-2008 Eugene Zagidullin (e.asphyx@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef COMMON_H -#define COMMON_H +#ifndef LIBSAD_H +#define LIBSAD_H #include #include @@ -33,34 +33,7 @@ #define FALSE 0 #endif -#include "../config.h" - -#ifdef ENABLE_NLS -# include -# include -# define _(String) dgettext(PACKAGE,String) -#else -# define _(String) (String) -#endif - -typedef u_int8_t sad_uint8; -typedef int8_t sad_sint8; - -#if SIZEOF_SHORT == 2 - typedef unsigned short sad_uint16; - typedef short sad_sint16; -#else -# error "Unsupported sizeof(short)" -#endif - -#if SIZEOF_INT == 4 - typedef unsigned int sad_uint32; - typedef int sad_sint32; -#else -# error "Unsupported sizeof(int)" -#endif - -typedef size_t sad_size_t; +#include "../../config.h" typedef int SAD_error; @@ -91,16 +64,16 @@ } SAD_sample_format; /* sample format -> sample size */ -static inline sad_size_t sf2ss(SAD_sample_format fmt) { +static inline unsigned sf2ss(SAD_sample_format fmt) { switch(fmt) { case SAD_SAMPLE_S8: - case SAD_SAMPLE_U8: return sizeof(sad_sint8); + case SAD_SAMPLE_U8: return sizeof(int8_t); case SAD_SAMPLE_S16: case SAD_SAMPLE_S16_LE: case SAD_SAMPLE_S16_BE: case SAD_SAMPLE_U16: case SAD_SAMPLE_U16_LE: - case SAD_SAMPLE_U16_BE: return sizeof(sad_sint16); + case SAD_SAMPLE_U16_BE: return sizeof(int16_t); case SAD_SAMPLE_S24: case SAD_SAMPLE_S24_LE: case SAD_SAMPLE_S24_BE: @@ -113,7 +86,7 @@ case SAD_SAMPLE_U32: case SAD_SAMPLE_U32_LE: case SAD_SAMPLE_U32_BE: - case SAD_SAMPLE_FIXED32: return sizeof(sad_sint32); + case SAD_SAMPLE_FIXED32: return sizeof(int32_t); case SAD_SAMPLE_FLOAT: return sizeof(float); default: return 0; } @@ -133,11 +106,11 @@ int samplerate; } SAD_buffer_format; -static inline sad_size_t bytes2frames(SAD_buffer_format *fmt, sad_size_t bytes) { +static inline unsigned bytes2frames(SAD_buffer_format *fmt, unsigned bytes) { return bytes / sf2ss(fmt->sample_format) / fmt->channels; } -static inline sad_size_t frames2bytes(SAD_buffer_format *fmt, sad_size_t frames) { +static inline unsigned frames2bytes(SAD_buffer_format *fmt, unsigned frames) { return frames * sf2ss(fmt->sample_format) * fmt->channels; } @@ -176,5 +149,5 @@ } SAD_replaygain_mode; -#endif /* COMMON_H */ +#endif /* LIBSAD_H */ diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/noicegen.c --- a/src/libSAD/noicegen.c Wed Jan 30 01:22:37 2008 +0300 +++ b/src/libSAD/noicegen.c Wed Jan 30 03:36:22 2008 +0300 @@ -2,16 +2,17 @@ #include #include "../../config.h" +#ifdef HAVE_SSE2 +# define SSE2 1 +#endif + +#ifdef HAVE_ALTIVEC +# define ALTIVEC 1 +#endif + #define MEXP 19937 -#ifdef HAVE_SSE2 -#define SSE2 1 -#endif -#ifdef HAVE_ALTIVEC -#define ALTIVEC 1 -#endif - -#include "SFMT.h" +/*#include "SFMT.h"*/ #include "SFMT.c" #include "noicegen.h" @@ -33,3 +34,9 @@ return v; } + +float triangular_dither_noise_f() { + // Сonditionally assume we have 16 bits in fractional part + // Please, check it thoroughly: is this assumption correct in floatin-point arithmetic? + return (float) triangular_dither_noise(17) / 65536.0; +} diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/noicegen.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libSAD/noicegen.h Wed Jan 30 03:36:22 2008 +0300 @@ -0,0 +1,7 @@ +#ifndef NOICEGEN_H +#define NOICEGEN_H + +int triangular_dither_noise(int nbits); +float triangular_dither_noise_f(void); + +#endif /*NOICEGEN_H*/ diff -r 704607c1f858 -r 74c6f3d3cf1d src/libSAD/noisegen.h --- a/src/libSAD/noisegen.h Wed Jan 30 01:22:37 2008 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef NOISGEN_H -#define NOISGEN_H - -int triangular_dither_noise(int nbits); -float triangular_dither_noise_f(void); - -#endif /*NOISGEN_H*/