diff --git a/stepmania/Program/resample.dll b/stepmania/Program/resample.dll index 3541ae0dcc..9f6e3eac58 100644 Binary files a/stepmania/Program/resample.dll and b/stepmania/Program/resample.dll differ diff --git a/stepmania/src/RageSoundReader_Resample_Good.cpp b/stepmania/src/RageSoundReader_Resample_Good.cpp index 8ed093f7d4..2b36c0e99b 100644 --- a/stepmania/src/RageSoundReader_Resample_Good.cpp +++ b/stepmania/src/RageSoundReader_Resample_Good.cpp @@ -3,7 +3,7 @@ #include "RageUtil.h" #include "RageSoundReader_Resample_Good.h" -#include "libresample/include/resample.h" +#include "libresample/include/libresample.h" #ifdef _WINDOWS #pragma comment(lib, "libresample/resample.lib") #endif diff --git a/stepmania/src/libresample/Makefile.in b/stepmania/src/libresample/Makefile.in index baf4a9c21d..febf70aa99 100644 --- a/stepmania/src/libresample/Makefile.in +++ b/stepmania/src/libresample/Makefile.in @@ -10,6 +10,7 @@ LIBS = @LIBS@ -lm AR = @AR@ RANLIB = @RANLIB@ +srcdir=@srcdir@ OBJS = \ src/resample.c.o \ @@ -17,6 +18,7 @@ OBJS = \ src/filterkit.c.o TARGETS = @TARGETS@ +DIRS=tests all: $(TARGETS) @@ -24,21 +26,24 @@ libresample.a: $(OBJS) Makefile $(AR) ruv libresample.a $(OBJS) ranlib libresample.a -tests/testresample: libresample.a tests/testresample.c +tests/testresample: libresample.a $(srcdir)/tests/testresample.c $(DIRS) $(CC) -o tests/testresample \ - $(CFLAGS) tests/testresample.c \ + $(CFLAGS) $(srcdir)/tests/testresample.c \ libresample.a $(LIBS) -tests/compareresample: libresample.a tests/compareresample.c +tests/compareresample: libresample.a $(srcdir)/tests/compareresample.c $(DIRS) $(CC) -o tests/compareresample \ - $(CFLAGS) tests/compareresample.c \ + $(CFLAGS) $(srcdir)/tests/compareresample.c \ libresample.a -lsamplerate $(LIBS) -tests/resample-sndfile: libresample.a tests/resample-sndfile.c +tests/resample-sndfile: libresample.a $(srcdir)/tests/resample-sndfile.c $(DIRS) $(CC) -o tests/resample-sndfile \ - $(CFLAGS) tests/resample-sndfile.c \ + $(CFLAGS) $(srcdir)/tests/resample-sndfile.c \ libresample.a -lsndfile $(LIBS) +$(DIRS): + mkdir $(DIRS) + clean: rm -f $(TARGETS) $(OBJS) @@ -47,6 +52,6 @@ dist: clean rm -f config.status config.cache config.log src/config.h rm -f *~ src/*~ tests/*~ include/*~ -%.c.o: %.c Makefile include/resample.h \ - src/resample_defs.h src/filterkit.h src/config.h +$(OBJS): %.c.o: $(srcdir)/%.c Makefile $(srcdir)/include/libresample.h \ + $(srcdir)/src/resample_defs.h $(srcdir)/src/filterkit.h $(srcdir)/src/config.h $(CC) -c $(CFLAGS) $< -o $@ diff --git a/stepmania/src/libresample/README.txt b/stepmania/src/libresample/README.txt index 989920e086..14be45b833 100644 --- a/stepmania/src/libresample/README.txt +++ b/stepmania/src/libresample/README.txt @@ -31,6 +31,22 @@ I removed all of that code and replaced it with an API that lets you pass samples in small chunks. It should be easy to link to resample-1.7 as a library. +Changes in version 0.1.3: + +* Fixed two bugs that were causing subtle problems + on Intel x86 processors due to differences in roundoff errors. + +* Prefixed most function names with lrs and changed header file + from resample.h to libresample.h, to avoid namespace + collisions with existing programs and libraries. + +* Added resample_dup (thanks to Glenn Maynard) + +* Argument to resample_get_filter_width takes a const void * + (thanks to Glenn Maynard) + +* resample-sndfile clips output to -1...1 (thanks to Glenn Maynard) + Usage notes: - If the output buffer you pass is too small, resample_process diff --git a/stepmania/src/libresample/include/resample.h b/stepmania/src/libresample/include/libresample.h similarity index 100% rename from stepmania/src/libresample/include/resample.h rename to stepmania/src/libresample/include/libresample.h diff --git a/stepmania/src/libresample/resample.def b/stepmania/src/libresample/resample.def new file mode 100644 index 0000000000..9b08d99aa4 --- /dev/null +++ b/stepmania/src/libresample/resample.def @@ -0,0 +1,6 @@ +EXPORTS + resample_open + resample_dup + resample_get_filter_width + resample_process + resample_close diff --git a/stepmania/src/libresample/resample.lib b/stepmania/src/libresample/resample.lib index f1258bb0f4..52493b8620 100644 Binary files a/stepmania/src/libresample/resample.lib and b/stepmania/src/libresample/resample.lib differ diff --git a/stepmania/src/libresample/src/filterkit.c b/stepmania/src/libresample/src/filterkit.c index e30ab82d8f..bc92285f2c 100644 --- a/stepmania/src/libresample/src/filterkit.c +++ b/stepmania/src/libresample/src/filterkit.c @@ -81,9 +81,9 @@ static double Izero(double x) return(sum); } -void LpFilter(double c[], int N, double frq, double Beta, int Num) +void lrsLpFilter(double c[], int N, double frq, double Beta, int Num) { - double IBeta, temp, inm1; + double IBeta, temp, temp1, inm1; int i; /* Calculate ideal lowpass filter impulse response coefficients: */ @@ -103,17 +103,22 @@ void LpFilter(double c[], int N, double frq, double Beta, int Num) inm1 = 1.0/((double)(N-1)); for (i=1; iNwing * sizeof(double)); - LpFilter(Imp64, hp->Nwing, 0.5*Rolloff, Beta, Npc); + lrsLpFilter(Imp64, hp->Nwing, 0.5*Rolloff, Beta, Npc); hp->Imp = (float *)malloc(hp->Nwing * sizeof(float)); hp->ImpD = (float *)malloc(hp->Nwing * sizeof(float)); @@ -269,12 +269,12 @@ int resample_process(void *handle, /* Resample stuff in input buffer */ if (factor >= 1) { /* SrcUp() is faster if we can use it */ - Nout = SrcUp(hp->X, hp->Y, factor, &hp->Time, Nx, - Nwing, LpScl, Imp, ImpD, interpFilt); + Nout = lrsSrcUp(hp->X, hp->Y, factor, &hp->Time, Nx, + Nwing, LpScl, Imp, ImpD, interpFilt); } else { - Nout = SrcUD(hp->X, hp->Y, factor, &hp->Time, Nx, - Nwing, LpScl, Imp, ImpD, interpFilt); + Nout = lrsSrcUD(hp->X, hp->Y, factor, &hp->Time, Nx, + Nwing, LpScl, Imp, ImpD, interpFilt); } #ifdef DEBUG diff --git a/stepmania/src/libresample/src/resample_defs.h b/stepmania/src/libresample/src/resample_defs.h index 8cacd3f18b..576c1bc2e2 100644 --- a/stepmania/src/libresample/src/resample_defs.h +++ b/stepmania/src/libresample/src/resample_defs.h @@ -14,11 +14,9 @@ #ifndef __RESAMPLE_DEFS__ #define __RESAMPLE_DEFS__ -//#ifdef WIN32 -//#include "configwin.h" -//#else +#if !defined(WIN32) && !defined(__CYGWIN__) #include "config.h" -//#endif +#endif #ifndef TRUE #define TRUE 1 @@ -77,12 +75,12 @@ /* Function prototypes */ -int SrcUp(float X[], float Y[], double factor, double *Time, - UWORD Nx, UWORD Nwing, float LpScl, - float Imp[], float ImpD[], BOOL Interp); +int lrsSrcUp(float X[], float Y[], double factor, double *Time, + UWORD Nx, UWORD Nwing, float LpScl, + float Imp[], float ImpD[], BOOL Interp); -int SrcUD(float X[], float Y[], double factor, double *Time, - UWORD Nx, UWORD Nwing, float LpScl, - float Imp[], float ImpD[], BOOL Interp); +int lrsSrcUD(float X[], float Y[], double factor, double *Time, + UWORD Nx, UWORD Nwing, float LpScl, + float Imp[], float ImpD[], BOOL Interp); #endif diff --git a/stepmania/src/libresample/src/resamplesubs.c b/stepmania/src/libresample/src/resamplesubs.c index 33a628dd80..c3c095dc04 100644 --- a/stepmania/src/libresample/src/resamplesubs.c +++ b/stepmania/src/libresample/src/resamplesubs.c @@ -27,61 +27,68 @@ /* Sampling rate up-conversion only subroutine; * Slightly faster than down-conversion; */ -int SrcUp(float X[], - float Y[], - double factor, - double *Time, - UWORD Nx, - UWORD Nwing, - float LpScl, - float Imp[], - float ImpD[], - BOOL Interp) +int lrsSrcUp(float X[], + float Y[], + double factor, + double *TimePtr, + UWORD Nx, + UWORD Nwing, + float LpScl, + float Imp[], + float ImpD[], + BOOL Interp) { float *Xp, *Ystart; float v; + double CurrentTime = *TimePtr; double dt; /* Step through input signal */ double endTime; /* When Time reaches EndTime, return to user */ dt = 1.0/factor; /* Output sampling period */ Ystart = Y; - endTime = *Time + Nx; - while (*Time < endTime) + endTime = CurrentTime + Nx; + while (CurrentTime < endTime) { - Xp = &X[(int)(*Time)]; /* Ptr to current input sample */ + double LeftPhase = CurrentTime-floor(CurrentTime); + double RightPhase = 1.0 - LeftPhase; + + Xp = &X[(int)CurrentTime]; /* Ptr to current input sample */ /* Perform left-wing inner product */ - v = FilterUp(Imp, ImpD, Nwing, Interp, Xp, - (*Time)-floor(*Time), -1); + v = lrsFilterUp(Imp, ImpD, Nwing, Interp, Xp, + LeftPhase, -1); /* Perform right-wing inner product */ - v += FilterUp(Imp, ImpD, Nwing, Interp, Xp+1, - ((-(*Time))-floor(-(*Time))), 1); + v += lrsFilterUp(Imp, ImpD, Nwing, Interp, Xp+1, + RightPhase, 1); v *= LpScl; /* Normalize for unity filter gain */ *Y++ = v; /* Deposit output */ - *Time += dt; /* Move to next sample by time increment */ + CurrentTime += dt; /* Move to next sample by time increment */ } + + *TimePtr = CurrentTime; return (Y - Ystart); /* Return the number of output samples */ } /* Sampling rate conversion subroutine */ -int SrcUD(float X[], - float Y[], - double factor, - double *Time, - UWORD Nx, - UWORD Nwing, - float LpScl, - float Imp[], - float ImpD[], - BOOL Interp) +int lrsSrcUD(float X[], + float Y[], + double factor, + double *TimePtr, + UWORD Nx, + UWORD Nwing, + float LpScl, + float Imp[], + float ImpD[], + BOOL Interp) { float *Xp, *Ystart; float v; - + + double CurrentTime = (*TimePtr); double dh; /* Step through filter impulse response */ double dt; /* Step through input signal */ double endTime; /* When Time reaches EndTime, return to user */ @@ -91,20 +98,26 @@ int SrcUD(float X[], dh = MIN(Npc, factor*Npc); /* Filter sampling period */ Ystart = Y; - endTime = *Time + Nx; - while (*Time < endTime) + endTime = CurrentTime + Nx; + while (CurrentTime < endTime) { - Xp = &X[(int)(*Time)]; /* Ptr to current input sample */ - v = FilterUD(Imp, ImpD, Nwing, Interp, Xp, - (*Time)-floor(*Time), -1, dh); - /* Perform left-wing inner product */ - v += FilterUD(Imp, ImpD, Nwing, Interp, Xp+1, - ((-(*Time))-floor(-(*Time))), 1, dh); + double LeftPhase = CurrentTime-floor(CurrentTime); + double RightPhase = 1.0 - LeftPhase; + + Xp = &X[(int)CurrentTime]; /* Ptr to current input sample */ + /* Perform left-wing inner product */ + v = lrsFilterUD(Imp, ImpD, Nwing, Interp, Xp, + LeftPhase, -1, dh); + /* Perform right-wing inner product */ + v += lrsFilterUD(Imp, ImpD, Nwing, Interp, Xp+1, + RightPhase, 1, dh); v *= LpScl; /* Normalize for unity filter gain */ *Y++ = v; /* Deposit output */ - *Time += dt; /* Move to next sample by time increment */ + CurrentTime += dt; /* Move to next sample by time increment */ } + + *TimePtr = CurrentTime; return (Y - Ystart); /* Return the number of output samples */ } diff --git a/stepmania/src/libresample/tests/compareresample.c b/stepmania/src/libresample/tests/compareresample.c index f2f49a153e..8773c9d4e9 100644 --- a/stepmania/src/libresample/tests/compareresample.c +++ b/stepmania/src/libresample/tests/compareresample.c @@ -11,7 +11,7 @@ **********************************************************************/ -#include "../include/resample.h" +#include "../include/libresample.h" #include diff --git a/stepmania/src/libresample/tests/resample-sndfile.c b/stepmania/src/libresample/tests/resample-sndfile.c index 3eec059a4b..e780228c17 100644 --- a/stepmania/src/libresample/tests/resample-sndfile.c +++ b/stepmania/src/libresample/tests/resample-sndfile.c @@ -11,7 +11,7 @@ **********************************************************************/ -#include "../include/resample.h" +#include "../include/libresample.h" #include @@ -174,7 +174,14 @@ int main(int argc, char **argv) } for(i=0; i= 1) + dsti[i*channels+c] = 1; + else + dsti[i*channels+c] = dst[i]; + } } sf_writef_float(dstfile, dsti, out); diff --git a/stepmania/src/libresample/tests/testresample.c b/stepmania/src/libresample/tests/testresample.c index b61119b7c3..a59aa8bfd5 100644 --- a/stepmania/src/libresample/tests/testresample.c +++ b/stepmania/src/libresample/tests/testresample.c @@ -11,7 +11,7 @@ **********************************************************************/ -#include "../include/resample.h" +#include "../include/libresample.h" #include #include @@ -91,7 +91,7 @@ void runtest(int srclen, double freq, double factor, for(i=0; i 0.05) { + if (fabs(diff) > 0.05) { if (errcount == 0) printf(" First error at i=%d: expected %.3f, got %.3f\n", i, sin((i/freq)/factor), dst[i]); diff --git a/stepmania/src/libresample/win/libresample.dsp b/stepmania/src/libresample/win/libresample.dsp new file mode 100644 index 0000000000..eaf79cb9ab --- /dev/null +++ b/stepmania/src/libresample/win/libresample.dsp @@ -0,0 +1,134 @@ +# Microsoft Developer Studio Project File - Name="libresample" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=libresample - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "libresample.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "libresample.mak" CFG="libresample - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "libresample - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "libresample - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "libresample - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIBRESAMPLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIBRESAMPLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib /nologo /dll /pdb:none /machine:I386 /out:"../resample.dll" /implib:"../resample.lib" + +!ELSEIF "$(CFG)" == "libresample - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIBRESAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LIBRESAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "libresample - Win32 Release" +# Name "libresample - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\src\filterkit.c +# End Source File +# Begin Source File + +SOURCE=..\src\resample.c +# End Source File +# Begin Source File + +SOURCE=..\src\resamplesubs.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\src\config.h +# End Source File +# Begin Source File + +SOURCE=..\src\filterkit.h +# End Source File +# Begin Source File + +SOURCE=..\include\libresample.h +# End Source File +# Begin Source File + +SOURCE=..\src\resample_defs.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=..\resample.def +# End Source File +# End Target +# End Project diff --git a/stepmania/src/libresample/win/libresample.dsw b/stepmania/src/libresample/win/libresample.dsw new file mode 100644 index 0000000000..8e6d18dc3e --- /dev/null +++ b/stepmania/src/libresample/win/libresample.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "libresample"=.\libresample.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### +