diff options
Diffstat (limited to 'third_party/resample/src')
-rw-r--r-- | third_party/resample/src/Makefile.am | 22 | ||||
-rw-r--r-- | third_party/resample/src/Makefile.in | 478 | ||||
-rw-r--r-- | third_party/resample/src/filterkit.c | 631 | ||||
-rw-r--r-- | third_party/resample/src/filterkit.h | 159 | ||||
-rw-r--r-- | third_party/resample/src/largefilter.h | 16411 | ||||
-rw-r--r-- | third_party/resample/src/resample.c | 238 | ||||
-rw-r--r-- | third_party/resample/src/resample.h | 86 | ||||
-rw-r--r-- | third_party/resample/src/resamplesubs.c | 520 | ||||
-rw-r--r-- | third_party/resample/src/smallfilter.h | 4617 | ||||
-rw-r--r-- | third_party/resample/src/sndlibextra.c | 90 | ||||
-rw-r--r-- | third_party/resample/src/sndlibextra.h | 48 | ||||
-rw-r--r-- | third_party/resample/src/stdefs.h | 59 | ||||
-rw-r--r-- | third_party/resample/src/windowfilter.c | 114 |
13 files changed, 23473 insertions, 0 deletions
diff --git a/third_party/resample/src/Makefile.am b/third_party/resample/src/Makefile.am new file mode 100644 index 00000000..bd3ce51a --- /dev/null +++ b/third_party/resample/src/Makefile.am @@ -0,0 +1,22 @@ +## Process this file with automake to produce Makefile.in + +SNDLIB = ../sndlib-20 + +INCLUDES = -I$(SNDLIB) + +bin_PROGRAMS = resample windowfilter + +resample_SOURCES = resample.c resamplesubs.c sndlibextra.c filterkit.c \ + $(SNDLIB)/audio.c $(SNDLIB)/io.c $(SNDLIB)/headers.c $(SNDLIB)/sound.c \ + resample.h stdefs.h sndlibextra.h filterkit.h smallfilter.h largefilter.h \ + $(SNDLIB)/sndlib.h $(SNDLIB)/mus-config.h $(SNDLIB)/_sndlib.h $(SNDLIB)/sndlib-strings.h $(SNDLIB)/configure + +resample_LDADD = -lm + +windowfilter_SOURCES = windowfilter.c resamplesubs.c sndlibextra.c filterkit.c \ + $(SNDLIB)/audio.c $(SNDLIB)/io.c $(SNDLIB)/headers.c $(SNDLIB)/sound.c + +windowfilter_LDADD = -lm + +EXTRA_DIST = $(man_MANS) + diff --git a/third_party/resample/src/Makefile.in b/third_party/resample/src/Makefile.in new file mode 100644 index 00000000..56da85f2 --- /dev/null +++ b/third_party/resample/src/Makefile.in @@ -0,0 +1,478 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = resample$(EXEEXT) windowfilter$(EXEEXT) +subdir = src +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(bin_PROGRAMS) +am_resample_OBJECTS = resample.$(OBJEXT) resamplesubs.$(OBJEXT) \ + sndlibextra.$(OBJEXT) filterkit.$(OBJEXT) audio.$(OBJEXT) \ + io.$(OBJEXT) headers.$(OBJEXT) sound.$(OBJEXT) +resample_OBJECTS = $(am_resample_OBJECTS) +resample_DEPENDENCIES = +am_windowfilter_OBJECTS = windowfilter.$(OBJEXT) \ + resamplesubs.$(OBJEXT) sndlibextra.$(OBJEXT) \ + filterkit.$(OBJEXT) audio.$(OBJEXT) io.$(OBJEXT) \ + headers.$(OBJEXT) sound.$(OBJEXT) +windowfilter_OBJECTS = $(am_windowfilter_OBJECTS) +windowfilter_DEPENDENCIES = +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(resample_SOURCES) $(windowfilter_SOURCES) +DIST_SOURCES = $(resample_SOURCES) $(windowfilter_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +SNDLIB = ../sndlib-20 +INCLUDES = -I$(SNDLIB) +resample_SOURCES = resample.c resamplesubs.c sndlibextra.c filterkit.c \ + $(SNDLIB)/audio.c $(SNDLIB)/io.c $(SNDLIB)/headers.c $(SNDLIB)/sound.c \ + resample.h stdefs.h sndlibextra.h filterkit.h smallfilter.h largefilter.h \ + $(SNDLIB)/sndlib.h $(SNDLIB)/mus-config.h $(SNDLIB)/_sndlib.h $(SNDLIB)/sndlib-strings.h $(SNDLIB)/configure + +resample_LDADD = -lm +windowfilter_SOURCES = windowfilter.c resamplesubs.c sndlibextra.c filterkit.c \ + $(SNDLIB)/audio.c $(SNDLIB)/io.c $(SNDLIB)/headers.c $(SNDLIB)/sound.c + +windowfilter_LDADD = -lm +EXTRA_DIST = $(man_MANS) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ + done + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) +resample$(EXEEXT): $(resample_OBJECTS) $(resample_DEPENDENCIES) + @rm -f resample$(EXEEXT) + $(LINK) $(resample_LDFLAGS) $(resample_OBJECTS) $(resample_LDADD) $(LIBS) +windowfilter$(EXEEXT): $(windowfilter_OBJECTS) $(windowfilter_DEPENDENCIES) + @rm -f windowfilter$(EXEEXT) + $(LINK) $(windowfilter_LDFLAGS) $(windowfilter_OBJECTS) $(windowfilter_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filterkit.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/headers.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resample.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resamplesubs.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sndlibextra.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowfilter.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +audio.o: $(SNDLIB)/audio.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT audio.o -MD -MP -MF "$(DEPDIR)/audio.Tpo" -c -o audio.o `test -f '$(SNDLIB)/audio.c' || echo '$(srcdir)/'`$(SNDLIB)/audio.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/audio.Tpo" "$(DEPDIR)/audio.Po"; else rm -f "$(DEPDIR)/audio.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/audio.c' object='audio.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o audio.o `test -f '$(SNDLIB)/audio.c' || echo '$(srcdir)/'`$(SNDLIB)/audio.c + +audio.obj: $(SNDLIB)/audio.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT audio.obj -MD -MP -MF "$(DEPDIR)/audio.Tpo" -c -o audio.obj `if test -f '$(SNDLIB)/audio.c'; then $(CYGPATH_W) '$(SNDLIB)/audio.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/audio.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/audio.Tpo" "$(DEPDIR)/audio.Po"; else rm -f "$(DEPDIR)/audio.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/audio.c' object='audio.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o audio.obj `if test -f '$(SNDLIB)/audio.c'; then $(CYGPATH_W) '$(SNDLIB)/audio.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/audio.c'; fi` + +io.o: $(SNDLIB)/io.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT io.o -MD -MP -MF "$(DEPDIR)/io.Tpo" -c -o io.o `test -f '$(SNDLIB)/io.c' || echo '$(srcdir)/'`$(SNDLIB)/io.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/io.Tpo" "$(DEPDIR)/io.Po"; else rm -f "$(DEPDIR)/io.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/io.c' object='io.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o io.o `test -f '$(SNDLIB)/io.c' || echo '$(srcdir)/'`$(SNDLIB)/io.c + +io.obj: $(SNDLIB)/io.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT io.obj -MD -MP -MF "$(DEPDIR)/io.Tpo" -c -o io.obj `if test -f '$(SNDLIB)/io.c'; then $(CYGPATH_W) '$(SNDLIB)/io.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/io.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/io.Tpo" "$(DEPDIR)/io.Po"; else rm -f "$(DEPDIR)/io.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/io.c' object='io.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o io.obj `if test -f '$(SNDLIB)/io.c'; then $(CYGPATH_W) '$(SNDLIB)/io.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/io.c'; fi` + +headers.o: $(SNDLIB)/headers.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT headers.o -MD -MP -MF "$(DEPDIR)/headers.Tpo" -c -o headers.o `test -f '$(SNDLIB)/headers.c' || echo '$(srcdir)/'`$(SNDLIB)/headers.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/headers.Tpo" "$(DEPDIR)/headers.Po"; else rm -f "$(DEPDIR)/headers.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/headers.c' object='headers.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o headers.o `test -f '$(SNDLIB)/headers.c' || echo '$(srcdir)/'`$(SNDLIB)/headers.c + +headers.obj: $(SNDLIB)/headers.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT headers.obj -MD -MP -MF "$(DEPDIR)/headers.Tpo" -c -o headers.obj `if test -f '$(SNDLIB)/headers.c'; then $(CYGPATH_W) '$(SNDLIB)/headers.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/headers.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/headers.Tpo" "$(DEPDIR)/headers.Po"; else rm -f "$(DEPDIR)/headers.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/headers.c' object='headers.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o headers.obj `if test -f '$(SNDLIB)/headers.c'; then $(CYGPATH_W) '$(SNDLIB)/headers.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/headers.c'; fi` + +sound.o: $(SNDLIB)/sound.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sound.o -MD -MP -MF "$(DEPDIR)/sound.Tpo" -c -o sound.o `test -f '$(SNDLIB)/sound.c' || echo '$(srcdir)/'`$(SNDLIB)/sound.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/sound.Tpo" "$(DEPDIR)/sound.Po"; else rm -f "$(DEPDIR)/sound.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/sound.c' object='sound.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sound.o `test -f '$(SNDLIB)/sound.c' || echo '$(srcdir)/'`$(SNDLIB)/sound.c + +sound.obj: $(SNDLIB)/sound.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sound.obj -MD -MP -MF "$(DEPDIR)/sound.Tpo" -c -o sound.obj `if test -f '$(SNDLIB)/sound.c'; then $(CYGPATH_W) '$(SNDLIB)/sound.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/sound.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/sound.Tpo" "$(DEPDIR)/sound.Po"; else rm -f "$(DEPDIR)/sound.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(SNDLIB)/sound.c' object='sound.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sound.obj `if test -f '$(SNDLIB)/sound.c'; then $(CYGPATH_W) '$(SNDLIB)/sound.c'; else $(CYGPATH_W) '$(srcdir)/$(SNDLIB)/sound.c'; fi` +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-binPROGRAMS + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic ctags distclean distclean-compile \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-binPROGRAMS \ + install-data install-data-am install-exec install-exec-am \ + install-info install-info-am install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-binPROGRAMS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/third_party/resample/src/filterkit.c b/third_party/resample/src/filterkit.c new file mode 100644 index 00000000..5171b5ea --- /dev/null +++ b/third_party/resample/src/filterkit.c @@ -0,0 +1,631 @@ +/* + * filterkit.c (library "filterkit.a"): Kaiser-windowed low-pass filter support. + */ + +/* filterkit.c + * + * LpFilter() - Calculates the filter coeffs for a Kaiser-windowed low-pass + * filter with a given roll-off frequency. These coeffs + * are stored into a array of doubles. + * writeFilter() - Writes a filter to a file. + * makeFilter() - Calls LpFilter() to create a filter, then scales the double + * coeffs into an array of half words. + * readFilter() - Reads a filter from a file. + * FilterUp() - Applies a filter to a given sample when up-converting. + * FilterUD() - Applies a filter to a given sample when up- or down- + * converting. + * initZerox() - Initialization routine for the zerox() function. Must + * be called before zerox() is called. This routine loads + * the correct filter so zerox() can use it. + * zerox() - Given a pointer into a sample, finds a zero-crossing on the + * interval [pointer-1:pointer+2] by iteration. + * Query() - Ask the user for a yes/no question with prompt, default, + * and optional help. + * GetUShort() - Ask the user for a unsigned short with prompt, default, + * and optional help. + * GetDouble() - Ask the user for a double with prompt, default, and + * optional help. + * GetString() - Ask the user for a string with prompt, default, and + * optional help. + */ + +#include "resample.h" +#include "filterkit.h" + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <math.h> + +/* + * Getstr() will print the passed "prompt" as a message to the user, and + * wait for the user to type an input string. The string is + * then copied into "answer". If the user types just a carriage + * return, then the string "defaultAnswer" is copied into "answer". + * ??? + * "Answer" and "defaultAnswer" may be the same string, in which case, + * the defaultAnswer value will be the original contents of "answer". + * ??? + */ +static void getstr(char *prompt, char *defaultAnswer, char *answer) +{ + char *p,s[200]; + + printf("%s (defaultAnswer = %s):",prompt,defaultAnswer); + strcpy(s, prompt); + if (!(*s)) + strcpy(s, "input:"); + p = s; + while (*p && *p != '(') + p++; + p--; + while (*p == ' ') + p--; + *(++p) = '\0'; + + /* gets(answer); */ + fgets(answer,sizeof(answer),stdin); + answer[strlen(answer)-1] = '\0'; + + if (answer[0] == '\0') { + strcpy(answer, defaultAnswer); + printf("\t%s = %s\n",s,answer); + } else { + printf("\t%s set to %s\n",s,answer); + } +} + + +/* LpFilter() + * + * reference: "Digital Filters, 2nd edition" + * R.W. Hamming, pp. 178-179 + * + * Izero() computes the 0th order modified bessel function of the first kind. + * (Needed to compute Kaiser window). + * + * LpFilter() computes the coeffs of a Kaiser-windowed low pass filter with + * the following characteristics: + * + * c[] = array in which to store computed coeffs + * frq = roll-off frequency of filter + * N = Half the window length in number of coeffs + * Beta = parameter of Kaiser window + * Num = number of coeffs before 1/frq + * + * Beta trades the rejection of the lowpass filter against the transition + * width from passband to stopband. Larger Beta means a slower + * transition and greater stopband rejection. See Rabiner and Gold + * (Theory and Application of DSP) under Kaiser windows for more about + * Beta. The following table from Rabiner and Gold gives some feel + * for the effect of Beta: + * + * All ripples in dB, width of transition band = D*N where N = window length + * + * BETA D PB RIP SB RIP + * 2.120 1.50 +-0.27 -30 + * 3.384 2.23 0.0864 -40 + * 4.538 2.93 0.0274 -50 + * 5.658 3.62 0.00868 -60 + * 6.764 4.32 0.00275 -70 + * 7.865 5.0 0.000868 -80 + * 8.960 5.7 0.000275 -90 + * 10.056 6.4 0.000087 -100 + */ + + +#define IzeroEPSILON 1E-21 /* Max error acceptable in Izero */ + +static double Izero(double x) +{ + double sum, u, halfx, temp; + int n; + + sum = u = n = 1; + halfx = x/2.0; + do { + temp = halfx/(double)n; + n += 1; + temp *= temp; + u *= temp; + sum += u; + } while (u >= IzeroEPSILON*sum); + return(sum); +} + + +void LpFilter(double c[], int N, double frq, double Beta, int Num) +{ + double IBeta, temp, inm1; + int i; + + /* Calculate ideal lowpass filter impulse response coefficients: */ + c[0] = 2.0*frq; + for (i=1; i<N; i++) { + temp = PI*(double)i/(double)Num; + c[i] = sin(2.0*temp*frq)/temp; /* Analog sinc function, cutoff = frq */ + } + + /* + * Calculate and Apply Kaiser window to ideal lowpass filter. + * Note: last window value is IBeta which is NOT zero. + * You're supposed to really truncate the window here, not ramp + * it to zero. This helps reduce the first sidelobe. + */ + IBeta = 1.0/Izero(Beta); + inm1 = 1.0/((double)(N-1)); + for (i=1; i<N; i++) { + temp = (double)i * inm1; + c[i] *= Izero(Beta*sqrt(1.0-temp*temp)) * IBeta; + } +} + + +/* Write a filter to a file + * Filter file format: + * file name: "F" Nmult "T" Nhc ".filter" + * 1st line: the string "ScaleFactor" followed by its value. + * 2nd line: the string "Length" followed by Nwing's value. + * 3rd line: the string "Nmult" followed by Nmult's value. + * 4th line: the string "Coeffs:" on a separate line. + * following lines: Nwing number of 16-bit impulse response values + * in the right wing of the impulse response (the Imp[] array). + * (Nwing is equal to Npc*(Nmult+1)/2+1, where Npc is defined in the + * file "resample.h".) Each coefficient is on a separate line. + * next line: the string "Differences:" on a separate line. + * following lines: Nwing number of 16-bit impulse-response + * successive differences: ImpD[i] = Imp[i+1] - Imp[i]. + * ERROR codes: + * 0 - no error + * 1 - could not open file + */ + +int writeFilter(HWORD Imp[], HWORD ImpD[], UHWORD LpScl, UHWORD Nmult, + UHWORD Nwing) +{ + char fname[30]; + FILE *fp; + int i; + + sprintf(fname, "F%dT%d.filter", Nmult, Nhc); + fp = fopen(fname, "w"); + if (!fp) + return(1); + fprintf(fp, "ScaleFactor %d\n", LpScl); + fprintf(fp, "Length %d\n", Nwing); + fprintf(fp, "Nmult %d\n", Nmult); + fprintf(fp, "Coeffs:\n"); + for (i=0; i<Nwing; i++) /* Put array of 16-bit filter coefficients */ + fprintf(fp, "%d\n", Imp[i]); + fprintf(fp, "Differences:\n"); + for (i=0; i<Nwing; i++) /* Put array of 16-bit filter coeff differences */ + fprintf(fp, "%d\n", ImpD[i]); + fclose(fp); + printf("Wrote filter file '%s' in current directory.\n",fname); + return(0); +} + + +/* ERROR return codes: + * 0 - no error + * 1 - Nwing too large (Nwing is > MAXNWING) + * 2 - Froll is not in interval [0:1) + * 3 - Beta is < 1.0 + * 4 - LpScl will not fit in 16-bits + * + * Made following global to avoid stack problems in Sun3 compilation: */ + +#define MAXNWING 8192 +static double ImpR[MAXNWING]; + +int makeFilter(HWORD Imp[], HWORD ImpD[], UHWORD *LpScl, UHWORD Nwing, + double Froll, double Beta) +{ + double DCgain, Scl, Maxh; + HWORD Dh; + int i, temp; + + if (Nwing > MAXNWING) /* Check for valid parameters */ + return(1); + if ((Froll<=0) || (Froll>1)) + return(2); + if (Beta < 1) + return(3); + + /* + * Design Kaiser-windowed sinc-function low-pass filter + */ + LpFilter(ImpR, (int)Nwing, 0.5*Froll, Beta, Npc); + + /* Compute the DC gain of the lowpass filter, and its maximum coefficient + * magnitude. Scale the coefficients so that the maximum coeffiecient just + * fits in Nh-bit fixed-point, and compute LpScl as the NLpScl-bit (signed) + * scale factor which when multiplied by the output of the lowpass filter + * gives unity gain. */ + DCgain = 0; + Dh = Npc; /* Filter sampling period for factors>=1 */ + for (i=Dh; i<Nwing; i+=Dh) + DCgain += ImpR[i]; + DCgain = 2*DCgain + ImpR[0]; /* DC gain of real coefficients */ + + for (Maxh=i=0; i<Nwing; i++) + Maxh = MAX(Maxh, fabs(ImpR[i])); + + Scl = ((1<<(Nh-1))-1)/Maxh; /* Map largest coeff to 16-bit maximum */ + temp = fabs((1<<(NLpScl+Nh))/(DCgain*Scl)); + if (temp >= 1<<16) + return(4); /* Filter scale factor overflows UHWORD */ + *LpScl = temp; + + /* Scale filter coefficients for Nh bits and convert to integer */ + if (ImpR[0] < 0) /* Need pos 1st value for LpScl storage */ + Scl = -Scl; + for (i=0; i<Nwing; i++) /* Scale them */ + ImpR[i] *= Scl; + for (i=0; i<Nwing; i++) /* Round them */ + Imp[i] = ImpR[i] + 0.5; + + /* ImpD makes linear interpolation of the filter coefficients faster */ + for (i=0; i<Nwing-1; i++) + ImpD[i] = Imp[i+1] - Imp[i]; + ImpD[Nwing-1] = - Imp[Nwing-1]; /* Last coeff. not interpolated */ + + return(0); +} + + +/* Read-in a filter + * Filter file format: + * file name: "F" Nmult "T" Nhc ".filter" + * 1st line: the string "ScaleFactor" followed by its value. + * 2nd line: the string "Length" followed by Nwing's value. + * 3rd line: the string "Coeffs:" on separate line. + * Nwing number of 16-bit impulse response values in the right + * wing of the impulse response. (Length=Npc*(Nmult+1)/2+1, + * where originally Npc=2^9, and Nmult=13.) Each on separate line. + * The string "Differences:" on separate line. + * Nwing number of 16-bit impulse-response successive differences: + * ImpDiff[i] = Imp[i+1] - Imp[i]. + * + * ERROR return codes: + * 0 - no error + * 1 - file not found + * 2 - invalid ScaleFactor in file + * 3 - invalid Length in file + * 4 - invalid Nmult in file + */ +int readFilter(char *filterFile, HWORD **ImpP, HWORD **ImpDP, UHWORD *LpScl, + UHWORD *Nmult, UHWORD *Nwing) +{ + char *fname; + FILE *fp; + int i, temp; + HWORD *Imp,*ImpD; + + if (!filterFile || !(*filterFile)) { + fname = (char *) malloc(32); + if ((*Nmult)>0 && ((*Nmult)&1)) + sprintf(fname, "F%dT%d.filter", *Nmult, Nhc); + else + sprintf(fname, "F65dT%d.filter", Nhc); + } else + fname = filterFile; + + fp = fopen(fname, "r"); + if (fp == NULL) + return(1); + + fscanf(fp, "ScaleFactor "); + if (1 != fscanf(fp,"%d",&temp)) + return(2); + *LpScl = temp; + + fscanf(fp, "\nLength "); + if (1 != fscanf(fp,"%d",&temp)) + return(3); + *Nwing = temp; + + fscanf(fp, "\nNmult "); + if (1 != fscanf(fp,"%d",&temp)) + return(4); + *Nmult = temp; + + Imp = (HWORD *) malloc(*Nwing * sizeof(HWORD)); + + fscanf(fp, "\nCoeffs:\n"); + for (i=0; i<*Nwing; i++) { /* Get array of 16-bit filter coefficients */ + fscanf(fp, "%d\n", &temp); + Imp[i] = temp; + } + + ImpD = (HWORD *) malloc(*Nwing * sizeof(HWORD)); + + fscanf(fp, "\nDifferences:\n"); + for (i=0; i<*Nwing; i++) { /* Get array of 16bit filter coeff differences */ + fscanf(fp, "%d\n", &temp); + ImpD[i] = temp; + } + + fclose(fp); + if (!filterFile || !(*filterFile)) + free(fname); + *ImpP = Imp; + *ImpDP = ImpD; + return(0); +} + + +WORD FilterUp(HWORD Imp[], HWORD ImpD[], + UHWORD Nwing, BOOL Interp, + HWORD *Xp, HWORD Ph, HWORD Inc) +{ + HWORD *Hp, *Hdp = NULL, *End; + HWORD a = 0; + WORD v, t; + + v=0; + Hp = &Imp[Ph>>Na]; + End = &Imp[Nwing]; + if (Interp) { + Hdp = &ImpD[Ph>>Na]; + a = Ph & Amask; + } + if (Inc == 1) /* If doing right wing... */ + { /* ...drop extra coeff, so when Ph is */ + End--; /* 0.5, we don't do too many mult's */ + if (Ph == 0) /* If the phase is zero... */ + { /* ...then we've already skipped the */ + Hp += Npc; /* first sample, so we must also */ + Hdp += Npc; /* skip ahead in Imp[] and ImpD[] */ + } + } + if (Interp) + while (Hp < End) { + t = *Hp; /* Get filter coeff */ + t += (((WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */ + Hdp += Npc; /* Filter coeff differences step */ + t *= *Xp; /* Mult coeff by input sample */ + if (t & (1<<(Nhxn-1))) /* Round, if needed */ + t += (1<<(Nhxn-1)); + t >>= Nhxn; /* Leave some guard bits, but come back some */ + v += t; /* The filter output */ + Hp += Npc; /* Filter coeff step */ + Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ + } + else + while (Hp < End) { + t = *Hp; /* Get filter coeff */ + t *= *Xp; /* Mult coeff by input sample */ + if (t & (1<<(Nhxn-1))) /* Round, if needed */ + t += (1<<(Nhxn-1)); + t >>= Nhxn; /* Leave some guard bits, but come back some */ + v += t; /* The filter output */ + Hp += Npc; /* Filter coeff step */ + Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ + } + return(v); +} + +WORD FilterUD( HWORD Imp[], HWORD ImpD[], + UHWORD Nwing, BOOL Interp, + HWORD *Xp, HWORD Ph, HWORD Inc, UHWORD dhb) +{ + HWORD a; + HWORD *Hp, *Hdp, *End; + WORD v, t; + UWORD Ho; + + v=0; + Ho = (Ph*(UWORD)dhb)>>Np; + End = &Imp[Nwing]; + if (Inc == 1) /* If doing right wing... */ + { /* ...drop extra coeff, so when Ph is */ + End--; /* 0.5, we don't do too many mult's */ + if (Ph == 0) /* If the phase is zero... */ + Ho += dhb; /* ...then we've already skipped the */ + } /* first sample, so we must also */ + /* skip ahead in Imp[] and ImpD[] */ + if (Interp) + while ((Hp = &Imp[Ho>>Na]) < End) { + t = *Hp; /* Get IR sample */ + Hdp = &ImpD[Ho>>Na]; /* get interp (lower Na) bits from diff table*/ + a = Ho & Amask; /* a is logically between 0 and 1 */ + t += (((WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */ + t *= *Xp; /* Mult coeff by input sample */ + if (t & 1<<(Nhxn-1)) /* Round, if needed */ + t += 1<<(Nhxn-1); + t >>= Nhxn; /* Leave some guard bits, but come back some */ + v += t; /* The filter output */ + Ho += dhb; /* IR step */ + Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ + } + else + while ((Hp = &Imp[Ho>>Na]) < End) { + t = *Hp; /* Get IR sample */ + t *= *Xp; /* Mult coeff by input sample */ + if (t & 1<<(Nhxn-1)) /* Round, if needed */ + t += 1<<(Nhxn-1); + t >>= Nhxn; /* Leave some guard bits, but come back some */ + v += t; /* The filter output */ + Ho += dhb; /* IR step */ + Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ + } + return(v); +} + +/* + * double zerox(Data, Factor) + * HWORD *Data; + * double Factor; + * Given a pointer into a sound sample, this function uses a low-pass + * filter to estimate the x coordinate of the zero-crossing which must ocurr + * between Data[0] and Data[1]. This value is returned as the value of the + * function. A return value of -100 indicates there was no zero-crossing in + * the x interval [-1,2]. Factor is the resampling factor: Rate(out) / + * Rate(in). Nmult (which determines which filter is used) is passed the + * zerox's initialization routine: initZerox(Nmult) + * UHWORD Nmult; + */ + +static UHWORD LpScl, Nmult, Nwing; +static HWORD *Imp; +static HWORD *ImpD; + +/* ERROR return values: + * 0 - no error + * 1 - Nmult is even (should be odd) + * 2 - filter file not found + * 3 - invalid ScaleFactor in input file + * 4 - invalid Length in file + * 5 - invalid Nmult in file + */ +int initZerox(UHWORD tempNmult) +{ + int err; + + /* Check for illegal input values */ + if (!(tempNmult % 2)) + return(1); + err = readFilter(NULL, (HWORD **)&Imp, (HWORD **)&ImpD, + &LpScl, &tempNmult, &Nwing); + if (err) + return(1+err); + + Nmult = tempNmult; + return(0); +} + +#define MAXITER 64 +#define ZeroxEPSILON (1E-4) +#define ZeroxMAXERROR (5.0) + +double zerox(HWORD *Data, double Factor) +{ + double x, out; + double lo, hi; + double dh; + UWORD dhb; + WORD v; + int i; + + if (!Data[0]) + return (0.0); + if (!Data[1]) + return (1.0); + + if (Data[0] < Data[1]) + { + lo = -1.0; + hi = 2.0; + } + else + { + lo = 2.0; + hi = -1.0; + } + dh = (Factor<1) ? (Factor*Npc) : (Npc); + dhb = dh * (1<<Na) + 0.5; + + for (i=0; i<MAXITER; i++) + { + x = (hi+lo)/2.0; + v = FilterUD(Imp,ImpD,Nwing,TRUE,Data, (HWORD)(x*Pmask), -1,dhb); + v += FilterUD(Imp,ImpD,Nwing,TRUE,Data+1,(HWORD)((1-x)*Pmask), 1,dhb); + v >>= Nhg; + v *= LpScl; + out = (double)v / (double)(1<<NLpScl); + if (out < 0.0) + lo = x; + else + hi = x; + if (ABS(out) <= ZeroxEPSILON) + return(x); + } + printf("|ZeroX Error| x:%g, \t Data[x]:%d, \t Data[x+1]:%d\n", + x, *Data, *(Data+1)); + printf("|\tABS(out):%g \t EPSILON:%g\n", ABS(out),ZeroxEPSILON); + if (ABS(out) <= ZeroxMAXERROR) + return(x); + return(-100.0); +} + + +BOOL Query(char *prompt, BOOL deflt, char *help) +{ + char s[80]; + + while (TRUE) + { + sprintf(s,"\n%s%s", prompt, (*help) ? " (Type ? for help)" : ""); + getstr(s,(deflt)?"yes":"no",s); + if (*s=='?' && *help) + printf(help); + if (*s=='Y' || *s=='y') + return(TRUE); + if (*s=='N' || *s=='n') + return(FALSE); + } +} + + +char *GetString(char *prompt, char *deflt, char *help) +{ + static char s[200]; + + while (TRUE) + { + sprintf(s,"\n%s%s",prompt, (*help) ? " (Type ? for Help)" : ""); + getstr(s,deflt,s); + if (*s=='?' && *help) + printf(help); + else + return(s); + } +} + + +double GetDouble(char *title, double deflt, char *help) +{ + char s[80],sdeflt[80]; + double newval; + + while (TRUE) + { + sprintf(s,"\n%s:%s",title, (*help) ? " (Type ? for Help)" : ""); + sprintf(sdeflt,"%g",deflt); + getstr(s,sdeflt,s); + if (*s=='?' && *help) + printf(help); + else + { + if (!sscanf(s,"%lf",&newval)) + return(deflt); + return(newval); + } + } +} + + +unsigned short GetUShort(char *title, unsigned short deflt, char *help) +{ + char s[80],sdeflt[80]; + int newval; + + while (TRUE) + { + sprintf(s,"\n%s:%s",title, (*help) ? " (Type ? for Help)" : ""); + sprintf(sdeflt,"%d",deflt); + getstr(s,sdeflt,s); + if (*s=='?' && *help) + printf(help); + else + { + if (!sscanf(s,"%d",&newval)) + printf("unchanged (%d)\n",(newval=deflt)); + if (newval < 0) + printf("Error: value must be >= zero\n"); + else + return(newval); + } + } +} diff --git a/third_party/resample/src/filterkit.h b/third_party/resample/src/filterkit.h new file mode 100644 index 00000000..c0d5e97c --- /dev/null +++ b/third_party/resample/src/filterkit.h @@ -0,0 +1,159 @@ +/*:filterkit.h */ + +#include "stdefs.h" + +/* + * LpFilter() - Calculates the filter coeffs for a Kaiser-windowed low-pass + * filter with a given roll-off frequency. These coeffs + * are stored into a array of doubles. + * writeFilter() - Writes a filter to a file. + * makeFilter() - Calls LpFilter() to create a filter, then scales the double + * coeffs into an array of half words. + * readFilter() - Reads a filter from a file. + * FilterUp() - Applies a filter to a given sample when up-converting. + * FilterUD() - Applies a filter to a given sample when up- or down- + * converting. + * initZerox() - Initialization routine for the zerox() function. Must + * be called before zerox() is called. This routine loads + * the correct filter so zerox() can use it. + * zerox() - Given a pointer into a sample, finds a zero-crossing on the + * interval [pointer-1:pointer+2] by iteration. + * Query() - Ask the user for a yes/no question with prompt, default, + * and optional help. + * GetUShort() - Ask the user for a unsigned short with prompt, default, + * and optional help. + * GetDouble() - Ask the user for a double with prompt, default, and + * optional help. + * GetString() - Ask the user for a string with prompt, default, and + * optional help. + */ + +void LpFilter(double c[], int N, double frq, double Beta, int Num); +/* + * reference: "Digital Filters, 2nd edition" + * R.W. Hamming, pp. 178-179 + * + * LpFilter() computes the coeffs of a Kaiser-windowed low pass filter with + * the following characteristics: + * + * c[] = array in which to store computed coeffs + * frq = roll-off frequency of filter + * N = Half the window length in number of coeffs + * Beta = parameter of Kaiser window + * Num = number of coeffs before 1/frq + * + * Beta trades the rejection of the lowpass filter against the transition + * width from passband to stopband. Larger Beta means a slower + * transition and greater stopband rejection. See Rabiner and Gold + * (Theory and Application of DSP) under Kaiser windows for more about + * Beta. The following table from Rabiner and Gold gives some feel + * for the effect of Beta: + * + * All ripples in dB, width of transition band = D*N where N = window length + * + * BETA D PB RIP SB RIP + * 2.120 1.50 +-0.27 -30 + * 3.384 2.23 0.0864 -40 + * 4.538 2.93 0.0274 -50 + * 5.658 3.62 0.00868 -60 + * 6.764 4.32 0.00275 -70 + * 7.865 5.0 0.000868 -80 + * 8.960 5.7 0.000275 -90 + * 10.056 6.4 0.000087 -100 + */ + +int writeFilter(HWORD Imp[], HWORD ImpD[], UHWORD LpScl, UHWORD Nmult, UHWORD Nwing); +/* + * Write a filter to a file + * Filter file format: + * file name: "F" Nmult "T" Nhc ".filter" + * 1st line: the string "ScaleFactor" followed by its value. + * 2nd line: the string "Length" followed by Nwing's value. + * 3rd line: the string "Coeffs:" on a separate line. + * following lines: Nwing number of 16-bit impulse response values + * in the right wing of the impulse response (the Imp[] array). + * (Nwing is equal to Npc*(Nmult+1)/2+1, where Npc is defined in the + * file "resample.h".) Each coefficient is on a separate line. + * next line: the string "Differences:" on a separate line. + * following lines: Nwing number of 16-bit impulse-response + * successive differences: ImpD[i] = Imp[i+1] - Imp[i]. + * ERROR codes: + * 0 - no error + * 1 - could not open file + */ + +int makeFilter(HWORD Imp[], HWORD ImpD[], UHWORD *LpScl, UHWORD Nwing, + double Froll, double Beta); +/* + * makeFilter + * ERROR return codes: + * 0 - no error + * 1 - Nwing too large (Nwing is > MAXNWING) + * 2 - Froll is not in interval [0:1) + * 3 - Beta is < 1.0 + * 4 - LpScl will not fit in 16-bits + */ + +int readFilter(char *filterFile, + HWORD **ImpP, HWORD **ImpDP, UHWORD *LpScl, + UHWORD *Nmult, UHWORD *Nwing); +/* + * Read-in a filter + * Filter file format: + * Default file name: "F" Nmult "T" Nhc ".filter" + * 1st line: the string "ScaleFactor" followed by its value. + * 2nd line: the string "Length" followed by Nwing's value. + * 3rd line: the string "Coeffs:" on separate line. + * Nwing number of 16-bit impulse response values in the right + * wing of the impulse response. (Length=Npc*(Nmult+1)/2+1, + * where originally Npc=2^9, and Nmult=13.) Each on separate line. + * The string "Differences:" on separate line. + * Nwing number of 16-bit impulse-response successive differences: + * ImpDiff[i] = Imp[i+1] - Imp[i]. + * + * ERROR return codes: + * 0 - no error + * 1 - file not found + * 2 - invalid ScaleFactor in file + * 3 - invalid Length in file + */ + +WORD FilterUp(HWORD Imp[], HWORD ImpD[], UHWORD Nwing, BOOL Interp, + HWORD *Xp, HWORD Inc, HWORD Ph); + +WORD FilterUD(HWORD Imp[], HWORD ImpD[], UHWORD Nwing, BOOL Interp, + HWORD *Xp, HWORD Ph, HWORD Inc, UHWORD dhb); + +int initZerox(UHWORD tempNmult); +/* + * initZerox + * ERROR return values: + * 0 - no error + * 1 - Nmult is even (should be odd) + * 2 - filter file not found + * 3 - invalid ScaleFactor in input file + * 4 - invalid Length in file + */ + +/* + * zerox + * Given a pointer into a sound sample, this function uses a low-pass + * filter to estimate the x coordinate of the zero-crossing which must ocurr + * between Data[0] and Data[1]. This value is returned as the value of the + * function. A return value of -100 indicates there was no zero-crossing in + * the x interval [-1,2]. Factor is the resampling factor: Rate(out) / + * Rate(in). Nmult (which determines which filter is used) is passed the + * zerox's initialization routine: initZerox(Nmult) + */ +double zerox(HWORD *Data, double Factor); + +BOOL Query(char *prompt, BOOL deflt, char *help); + +unsigned short GetUShort(char *title, unsigned short deflt, char *help); + +double GetDouble(char *title, double deflt, char *help); + +char *GetString(char *prompt, char *deflt, char *help); + +#define GetUHWORD(x,y,z) GetUShort(x,y,z) + diff --git a/third_party/resample/src/largefilter.h b/third_party/resample/src/largefilter.h new file mode 100644 index 00000000..7a86dd40 --- /dev/null +++ b/third_party/resample/src/largefilter.h @@ -0,0 +1,16411 @@ +/* Included by resamplesubs.c */ + +/* + + USAGE: resample -expensiveFilter ... + +The -expensiveFilter option (-e) for resample selects the 'expensive' +preloaded resampling filter. The default filter requires an +oversampling factor of around 20% to avoid aliasing. The expensive +filter is five times more computationally expensive and requires only +about a 5-10% oversampling factor. Both filters have comparable +stop-band attenuations (approximately 80 dB). If both options -f and +-e are present, the last one on the command line takes effect. The +expensive filter is not yet documented because its cut-off frequency +should be retuned slightly for optimal performance. Also, we plan to +compute truly optimized resampling filters sometime in the future. In +the meantime, the default filter is fast, well tuned, and works very +well for its level of computational expense. + +*/ + +#define LARGE_FILTER_NMULT ((HWORD)65) +#define LARGE_FILTER_SCALE 14746 /* Unity-gain scale factor */ +#define LARGE_FILTER_NWING 8192 /* Filter table length */ +static HWORD LARGE_FILTER_IMP[] /* Impulse response */ = { +32767, +32766, +32764, +32761, +32756, +32750, +32743, +32734, +32724, +32713, +32700, +32686, +32671, +32654, +32636, +32617, +32596, +32574, +32551, +32526, +32500, +32473, +32445, +32415, +32383, +32351, +32317, +32282, +32246, +32208, +32169, +32129, +32087, +32044, +32000, +31955, +31908, +31860, +31811, +31760, +31708, +31655, +31601, +31545, +31489, +31431, +31371, +31311, +31249, +31186, +31122, +31056, +30990, +30922, +30853, +30783, +30711, +30639, +30565, +30490, +30414, +30337, +30258, +30179, +30098, +30016, +29933, +29849, +29764, +29677, +29590, +29501, +29411, +29321, +29229, +29136, +29042, +28947, +28851, +28753, +28655, +28556, +28456, +28354, +28252, +28149, +28044, +27939, +27833, +27725, +27617, +27508, +27398, +27287, +27175, +27062, +26948, +26833, +26717, +26601, +26483, +26365, +26246, +26125, +26005, +25883, +25760, +25637, +25512, +25387, +25261, +25135, +25007, +24879, +24750, +24620, +24490, +24358, +24226, +24094, +23960, +23826, +23691, +23556, +23420, +23283, +23146, +23008, +22869, +22730, +22590, +22449, +22308, +22166, +22024, +21881, +21738, +21594, +21449, +21304, +21159, +21013, +20866, +20719, +20572, +20424, +20275, +20127, +19977, +19828, +19678, +19527, +19376, +19225, +19073, +18921, +18769, +18616, +18463, +18310, +18157, +18003, +17849, +17694, +17539, +17384, +17229, +17074, +16918, +16762, +16606, +16450, +16294, +16137, +15980, +15823, +15666, +15509, +15352, +15195, +15037, +14880, +14722, +14564, +14407, +14249, +14091, +13933, +13775, +13618, +13460, +13302, +13144, +12987, +12829, +12671, +12514, +12356, +12199, +12042, +11885, +11728, +11571, +11414, +11257, +11101, +10945, +10789, +10633, +10477, +10322, +10167, +10012, +9857, +9702, +9548, +9394, +9241, +9087, +8934, +8781, +8629, +8477, +8325, +8174, +8023, +7872, +7722, +7572, +7422, +7273, +7124, +6976, +6828, +6681, +6534, +6387, +6241, +6096, +5951, +5806, +5662, +5518, +5375, +5233, +5091, +4949, +4808, +4668, +4528, +4389, +4250, +4112, +3975, +3838, +3702, +3566, +3431, +3297, +3163, +3030, +2898, +2766, +2635, +2505, +2375, +2246, +2118, +1990, +1864, +1738, +1612, +1487, +1364, +1240, +1118, +996, +875, +755, +636, +517, +400, +283, +166, +51, +-63, +-176, +-289, +-401, +-513, +-623, +-733, +-841, +-949, +-1056, +-1162, +-1268, +-1372, +-1476, +-1578, +-1680, +-1781, +-1881, +-1980, +-2078, +-2176, +-2272, +-2367, +-2462, +-2556, +-2648, +-2740, +-2831, +-2921, +-3010, +-3098, +-3185, +-3271, +-3356, +-3441, +-3524, +-3606, +-3688, +-3768, +-3848, +-3926, +-4004, +-4080, +-4156, +-4231, +-4304, +-4377, +-4449, +-4519, +-4589, +-4658, +-4726, +-4792, +-4858, +-4923, +-4987, +-5050, +-5111, +-5172, +-5232, +-5291, +-5349, +-5406, +-5462, +-5517, +-5571, +-5624, +-5675, +-5726, +-5776, +-5825, +-5873, +-5920, +-5966, +-6011, +-6055, +-6098, +-6140, +-6181, +-6222, +-6261, +-6299, +-6336, +-6372, +-6407, +-6441, +-6475, +-6507, +-6538, +-6569, +-6598, +-6626, +-6654, +-6680, +-6706, +-6730, +-6754, +-6777, +-6798, +-6819, +-6839, +-6858, +-6876, +-6893, +-6909, +-6924, +-6938, +-6951, +-6964, +-6975, +-6986, +-6995, +-7004, +-7012, +-7019, +-7025, +-7030, +-7035, +-7038, +-7040, +-7042, +-7043, +-7043, +-7042, +-7040, +-7038, +-7034, +-7030, +-7025, +-7019, +-7012, +-7004, +-6996, +-6986, +-6976, +-6965, +-6954, +-6941, +-6928, +-6914, +-6899, +-6884, +-6867, +-6850, +-6832, +-6814, +-6794, +-6774, +-6753, +-6732, +-6709, +-6686, +-6663, +-6638, +-6613, +-6587, +-6561, +-6534, +-6506, +-6478, +-6448, +-6419, +-6388, +-6357, +-6325, +-6293, +-6260, +-6226, +-6192, +-6157, +-6122, +-6086, +-6049, +-6012, +-5975, +-5936, +-5897, +-5858, +-5818, +-5778, +-5737, +-5695, +-5653, +-5611, +-5568, +-5524, +-5480, +-5436, +-5391, +-5345, +-5300, +-5253, +-5207, +-5159, +-5112, +-5064, +-5015, +-4966, +-4917, +-4868, +-4818, +-4767, +-4716, +-4665, +-4614, +-4562, +-4510, +-4457, +-4404, +-4351, +-4298, +-4244, +-4190, +-4136, +-4081, +-4026, +-3971, +-3916, +-3860, +-3804, +-3748, +-3692, +-3635, +-3578, +-3521, +-3464, +-3406, +-3349, +-3291, +-3233, +-3175, +-3117, +-3058, +-3000, +-2941, +-2882, +-2823, +-2764, +-2705, +-2646, +-2587, +-2527, +-2468, +-2408, +-2349, +-2289, +-2229, +-2169, +-2110, +-2050, +-1990, +-1930, +-1870, +-1811, +-1751, +-1691, +-1631, +-1571, +-1512, +-1452, +-1392, +-1333, +-1273, +-1214, +-1154, +-1095, +-1036, +-977, +-918, +-859, +-800, +-741, +-683, +-624, +-566, +-508, +-450, +-392, +-335, +-277, +-220, +-163, +-106, +-49, +6, +63, +119, +175, +230, +286, +341, +396, +450, +505, +559, +613, +667, +720, +773, +826, +878, +931, +983, +1034, +1086, +1137, +1187, +1238, +1288, +1337, +1387, +1436, +1484, +1533, +1581, +1628, +1675, +1722, +1769, +1815, +1861, +1906, +1951, +1996, +2040, +2084, +2127, +2170, +2212, +2255, +2296, +2338, +2378, +2419, +2459, +2498, +2538, +2576, +2615, +2652, +2690, +2727, +2763, +2799, +2834, +2870, +2904, +2938, +2972, +3005, +3038, +3070, +3102, +3133, +3164, +3194, +3224, +3253, +3282, +3310, +3338, +3365, +3392, +3418, +3444, +3469, +3494, +3518, +3542, +3566, +3588, +3611, +3632, +3653, +3674, +3694, +3714, +3733, +3752, +3770, +3788, +3805, +3821, +3837, +3853, +3868, +3882, +3896, +3910, +3923, +3935, +3947, +3958, +3969, +3980, +3989, +3999, +4007, +4016, +4023, +4031, +4037, +4044, +4049, +4054, +4059, +4063, +4067, +4070, +4073, +4075, +4076, +4077, +4078, +4078, +4078, +4077, +4076, +4074, +4071, +4068, +4065, +4061, +4057, +4052, +4047, +4041, +4035, +4028, +4021, +4013, +4005, +3997, +3988, +3978, +3968, +3958, +3947, +3936, +3924, +3912, +3899, +3886, +3872, +3858, +3844, +3829, +3814, +3798, +3782, +3766, +3749, +3731, +3714, +3696, +3677, +3658, +3639, +3619, +3599, +3578, +3558, +3536, +3515, +3493, +3470, +3448, +3425, +3401, +3378, +3353, +3329, +3304, +3279, +3254, +3228, +3202, +3175, +3149, +3122, +3094, +3067, +3039, +3011, +2982, +2953, +2924, +2895, +2865, +2835, +2805, +2775, +2744, +2713, +2682, +2651, +2619, +2587, +2555, +2523, +2490, +2457, +2424, +2391, +2358, +2324, +2290, +2256, +2222, +2188, +2153, +2119, +2084, +2049, +2014, +1978, +1943, +1907, +1872, +1836, +1800, +1764, +1727, +1691, +1655, +1618, +1581, +1545, +1508, +1471, +1434, +1397, +1360, +1322, +1285, +1248, +1210, +1173, +1135, +1098, +1060, +1023, +985, +947, +910, +872, +834, +797, +759, +721, +684, +646, +608, +571, +533, +496, +458, +421, +383, +346, +308, +271, +234, +197, +160, +123, +86, +49, +12, +-23, +-60, +-96, +-133, +-169, +-205, +-241, +-277, +-313, +-348, +-384, +-419, +-455, +-490, +-525, +-559, +-594, +-628, +-663, +-697, +-731, +-765, +-798, +-832, +-865, +-898, +-931, +-963, +-996, +-1028, +-1060, +-1092, +-1124, +-1155, +-1186, +-1217, +-1248, +-1279, +-1309, +-1339, +-1369, +-1398, +-1428, +-1457, +-1486, +-1514, +-1542, +-1571, +-1598, +-1626, +-1653, +-1680, +-1707, +-1733, +-1760, +-1785, +-1811, +-1836, +-1862, +-1886, +-1911, +-1935, +-1959, +-1982, +-2006, +-2029, +-2051, +-2074, +-2096, +-2118, +-2139, +-2160, +-2181, +-2202, +-2222, +-2242, +-2261, +-2280, +-2299, +-2318, +-2336, +-2354, +-2372, +-2389, +-2406, +-2423, +-2439, +-2455, +-2470, +-2486, +-2500, +-2515, +-2529, +-2543, +-2557, +-2570, +-2583, +-2595, +-2607, +-2619, +-2631, +-2642, +-2652, +-2663, +-2673, +-2683, +-2692, +-2701, +-2710, +-2718, +-2726, +-2734, +-2741, +-2748, +-2754, +-2760, +-2766, +-2772, +-2777, +-2782, +-2786, +-2790, +-2794, +-2797, +-2800, +-2803, +-2805, +-2807, +-2809, +-2810, +-2811, +-2812, +-2812, +-2812, +-2812, +-2811, +-2810, +-2808, +-2807, +-2804, +-2802, +-2799, +-2796, +-2792, +-2789, +-2785, +-2780, +-2775, +-2770, +-2765, +-2759, +-2753, +-2746, +-2740, +-2732, +-2725, +-2717, +-2709, +-2701, +-2692, +-2683, +-2674, +-2664, +-2655, +-2644, +-2634, +-2623, +-2612, +-2601, +-2589, +-2577, +-2565, +-2552, +-2539, +-2526, +-2513, +-2499, +-2485, +-2471, +-2457, +-2442, +-2427, +-2412, +-2396, +-2380, +-2364, +-2348, +-2331, +-2315, +-2297, +-2280, +-2263, +-2245, +-2227, +-2209, +-2190, +-2171, +-2152, +-2133, +-2114, +-2094, +-2075, +-2055, +-2034, +-2014, +-1993, +-1972, +-1951, +-1930, +-1909, +-1887, +-1865, +-1843, +-1821, +-1799, +-1776, +-1754, +-1731, +-1708, +-1685, +-1662, +-1638, +-1614, +-1591, +-1567, +-1543, +-1519, +-1494, +-1470, +-1445, +-1421, +-1396, +-1371, +-1346, +-1321, +-1295, +-1270, +-1244, +-1219, +-1193, +-1167, +-1142, +-1116, +-1090, +-1064, +-1037, +-1011, +-985, +-958, +-932, +-905, +-879, +-852, +-826, +-799, +-772, +-745, +-719, +-692, +-665, +-638, +-611, +-584, +-557, +-530, +-503, +-476, +-449, +-422, +-395, +-368, +-341, +-314, +-287, +-260, +-234, +-207, +-180, +-153, +-126, +-100, +-73, +-46, +-20, +6, +32, +59, +85, +111, +138, +164, +190, +216, +242, +268, +294, +319, +345, +370, +396, +421, +446, +471, +496, +521, +546, +571, +595, +619, +644, +668, +692, +716, +739, +763, +787, +810, +833, +856, +879, +902, +924, +947, +969, +991, +1013, +1035, +1056, +1078, +1099, +1120, +1141, +1162, +1182, +1202, +1223, +1243, +1262, +1282, +1301, +1320, +1339, +1358, +1377, +1395, +1413, +1431, +1449, +1467, +1484, +1501, +1518, +1535, +1551, +1567, +1583, +1599, +1615, +1630, +1645, +1660, +1674, +1689, +1703, +1717, +1731, +1744, +1757, +1770, +1783, +1795, +1808, +1820, +1831, +1843, +1854, +1865, +1876, +1886, +1897, +1907, +1916, +1926, +1935, +1944, +1953, +1961, +1970, +1978, +1985, +1993, +2000, +2007, +2014, +2020, +2026, +2032, +2038, +2043, +2048, +2053, +2058, +2062, +2066, +2070, +2073, +2077, +2080, +2083, +2085, +2087, +2089, +2091, +2093, +2094, +2095, +2095, +2096, +2096, +2096, +2096, +2095, +2094, +2093, +2092, +2090, +2088, +2086, +2084, +2081, +2079, +2075, +2072, +2069, +2065, +2061, +2056, +2052, +2047, +2042, +2037, +2031, +2025, +2019, +2013, +2006, +2000, +1993, +1986, +1978, +1971, +1963, +1955, +1946, +1938, +1929, +1920, +1911, +1901, +1892, +1882, +1872, +1862, +1851, +1841, +1830, +1819, +1807, +1796, +1784, +1772, +1760, +1748, +1735, +1723, +1710, +1697, +1684, +1670, +1657, +1643, +1629, +1615, +1601, +1586, +1572, +1557, +1542, +1527, +1512, +1496, +1481, +1465, +1449, +1433, +1417, +1401, +1384, +1368, +1351, +1334, +1317, +1300, +1283, +1265, +1248, +1230, +1212, +1195, +1177, +1159, +1140, +1122, +1104, +1085, +1067, +1048, +1029, +1010, +991, +972, +953, +934, +915, +895, +876, +856, +837, +817, +797, +777, +758, +738, +718, +698, +678, +658, +637, +617, +597, +577, +556, +536, +516, +495, +475, +454, +434, +414, +393, +373, +352, +332, +311, +291, +270, +250, +229, +208, +188, +168, +147, +127, +106, +86, +65, +45, +25, +5, +-15, +-35, +-55, +-75, +-95, +-115, +-135, +-155, +-175, +-195, +-215, +-234, +-254, +-274, +-293, +-313, +-332, +-351, +-370, +-390, +-409, +-428, +-446, +-465, +-484, +-503, +-521, +-539, +-558, +-576, +-594, +-612, +-630, +-648, +-666, +-683, +-701, +-718, +-735, +-752, +-769, +-786, +-803, +-819, +-836, +-852, +-868, +-885, +-900, +-916, +-932, +-947, +-963, +-978, +-993, +-1008, +-1023, +-1038, +-1052, +-1066, +-1081, +-1095, +-1108, +-1122, +-1136, +-1149, +-1162, +-1175, +-1188, +-1201, +-1214, +-1226, +-1238, +-1250, +-1262, +-1274, +-1285, +-1297, +-1308, +-1319, +-1330, +-1340, +-1351, +-1361, +-1371, +-1381, +-1390, +-1400, +-1409, +-1418, +-1427, +-1436, +-1445, +-1453, +-1461, +-1469, +-1477, +-1485, +-1492, +-1499, +-1506, +-1513, +-1520, +-1526, +-1532, +-1538, +-1544, +-1550, +-1555, +-1560, +-1566, +-1570, +-1575, +-1579, +-1584, +-1588, +-1592, +-1595, +-1599, +-1602, +-1605, +-1608, +-1610, +-1613, +-1615, +-1617, +-1619, +-1620, +-1622, +-1623, +-1624, +-1625, +-1625, +-1626, +-1626, +-1626, +-1626, +-1625, +-1625, +-1624, +-1623, +-1622, +-1621, +-1619, +-1617, +-1615, +-1613, +-1611, +-1608, +-1605, +-1603, +-1599, +-1596, +-1593, +-1589, +-1585, +-1581, +-1577, +-1572, +-1568, +-1563, +-1558, +-1553, +-1547, +-1542, +-1536, +-1530, +-1524, +-1518, +-1511, +-1505, +-1498, +-1491, +-1484, +-1477, +-1469, +-1462, +-1454, +-1446, +-1438, +-1430, +-1421, +-1413, +-1404, +-1395, +-1386, +-1377, +-1367, +-1358, +-1348, +-1338, +-1328, +-1318, +-1308, +-1297, +-1287, +-1276, +-1265, +-1254, +-1243, +-1232, +-1221, +-1209, +-1198, +-1186, +-1174, +-1162, +-1150, +-1138, +-1125, +-1113, +-1100, +-1087, +-1075, +-1062, +-1049, +-1035, +-1022, +-1009, +-995, +-982, +-968, +-954, +-941, +-927, +-913, +-898, +-884, +-870, +-856, +-841, +-827, +-812, +-797, +-783, +-768, +-753, +-738, +-723, +-708, +-692, +-677, +-662, +-647, +-631, +-616, +-600, +-585, +-569, +-554, +-538, +-522, +-506, +-491, +-475, +-459, +-443, +-427, +-411, +-395, +-379, +-363, +-347, +-331, +-315, +-299, +-283, +-267, +-251, +-235, +-218, +-202, +-186, +-170, +-154, +-138, +-122, +-106, +-90, +-74, +-58, +-42, +-26, +-10, +5, +21, +37, +53, +69, +85, +100, +116, +132, +147, +163, +179, +194, +209, +225, +240, +256, +271, +286, +301, +316, +331, +346, +361, +376, +391, +405, +420, +434, +449, +463, +477, +492, +506, +520, +534, +548, +561, +575, +589, +602, +615, +629, +642, +655, +668, +681, +694, +706, +719, +731, +744, +756, +768, +780, +792, +804, +816, +827, +839, +850, +861, +872, +883, +894, +905, +915, +926, +936, +946, +956, +966, +976, +986, +995, +1005, +1014, +1023, +1032, +1041, +1049, +1058, +1066, +1075, +1083, +1091, +1099, +1106, +1114, +1121, +1128, +1135, +1142, +1149, +1156, +1162, +1169, +1175, +1181, +1187, +1192, +1198, +1203, +1208, +1214, +1218, +1223, +1228, +1232, +1237, +1241, +1245, +1249, +1252, +1256, +1259, +1262, +1265, +1268, +1271, +1273, +1276, +1278, +1280, +1282, +1284, +1285, +1287, +1288, +1289, +1290, +1291, +1292, +1292, +1292, +1293, +1293, +1292, +1292, +1292, +1291, +1290, +1289, +1288, +1287, +1285, +1284, +1282, +1280, +1278, +1276, +1274, +1271, +1269, +1266, +1263, +1260, +1257, +1253, +1250, +1246, +1242, +1238, +1234, +1230, +1225, +1221, +1216, +1211, +1206, +1201, +1196, +1190, +1185, +1179, +1173, +1167, +1161, +1155, +1149, +1142, +1136, +1129, +1122, +1115, +1108, +1101, +1094, +1086, +1078, +1071, +1063, +1055, +1047, +1039, +1030, +1022, +1013, +1005, +996, +987, +978, +969, +960, +951, +941, +932, +922, +913, +903, +893, +883, +873, +863, +853, +842, +832, +821, +811, +800, +789, +778, +768, +757, +746, +734, +723, +712, +701, +689, +678, +666, +654, +643, +631, +619, +607, +596, +584, +572, +559, +547, +535, +523, +511, +498, +486, +474, +461, +449, +436, +424, +411, +399, +386, +373, +361, +348, +335, +322, +310, +297, +284, +271, +258, +246, +233, +220, +207, +194, +181, +168, +156, +143, +130, +117, +104, +91, +78, +65, +53, +40, +27, +14, +1, +-10, +-23, +-36, +-48, +-61, +-74, +-86, +-99, +-111, +-124, +-136, +-149, +-161, +-174, +-186, +-198, +-211, +-223, +-235, +-247, +-259, +-271, +-283, +-295, +-307, +-319, +-330, +-342, +-354, +-365, +-377, +-388, +-399, +-411, +-422, +-433, +-444, +-455, +-466, +-477, +-488, +-499, +-509, +-520, +-530, +-541, +-551, +-561, +-571, +-581, +-591, +-601, +-611, +-621, +-631, +-640, +-650, +-659, +-668, +-677, +-686, +-695, +-704, +-713, +-722, +-730, +-739, +-747, +-755, +-763, +-771, +-779, +-787, +-795, +-803, +-810, +-817, +-825, +-832, +-839, +-846, +-853, +-859, +-866, +-873, +-879, +-885, +-891, +-897, +-903, +-909, +-915, +-920, +-926, +-931, +-936, +-941, +-946, +-951, +-955, +-960, +-964, +-969, +-973, +-977, +-981, +-985, +-988, +-992, +-995, +-999, +-1002, +-1005, +-1008, +-1011, +-1013, +-1016, +-1018, +-1020, +-1023, +-1025, +-1026, +-1028, +-1030, +-1031, +-1033, +-1034, +-1035, +-1036, +-1037, +-1038, +-1038, +-1039, +-1039, +-1039, +-1039, +-1039, +-1039, +-1039, +-1038, +-1038, +-1037, +-1036, +-1036, +-1034, +-1033, +-1032, +-1031, +-1029, +-1027, +-1026, +-1024, +-1022, +-1019, +-1017, +-1015, +-1012, +-1010, +-1007, +-1004, +-1001, +-998, +-995, +-991, +-988, +-984, +-980, +-977, +-973, +-969, +-965, +-960, +-956, +-951, +-947, +-942, +-937, +-932, +-927, +-922, +-917, +-912, +-906, +-901, +-895, +-889, +-883, +-877, +-871, +-865, +-859, +-853, +-846, +-840, +-833, +-826, +-819, +-812, +-805, +-798, +-791, +-784, +-777, +-769, +-762, +-754, +-746, +-739, +-731, +-723, +-715, +-707, +-699, +-691, +-682, +-674, +-665, +-657, +-648, +-640, +-631, +-622, +-614, +-605, +-596, +-587, +-578, +-569, +-559, +-550, +-541, +-532, +-522, +-513, +-503, +-494, +-484, +-474, +-465, +-455, +-445, +-436, +-426, +-416, +-406, +-396, +-386, +-376, +-366, +-356, +-346, +-336, +-325, +-315, +-305, +-295, +-285, +-274, +-264, +-254, +-243, +-233, +-223, +-212, +-202, +-192, +-181, +-171, +-161, +-150, +-140, +-129, +-119, +-108, +-98, +-88, +-77, +-67, +-57, +-46, +-36, +-25, +-15, +-5, +5, +15, +25, +35, +46, +56, +66, +76, +86, +97, +107, +117, +127, +137, +147, +157, +167, +177, +186, +196, +206, +216, +225, +235, +245, +254, +264, +273, +283, +292, +301, +311, +320, +329, +338, +347, +356, +365, +374, +383, +392, +400, +409, +418, +426, +435, +443, +451, +460, +468, +476, +484, +492, +500, +508, +515, +523, +531, +538, +546, +553, +560, +568, +575, +582, +589, +596, +602, +609, +616, +622, +629, +635, +642, +648, +654, +660, +666, +672, +678, +683, +689, +694, +700, +705, +710, +715, +720, +725, +730, +735, +739, +744, +748, +753, +757, +761, +765, +769, +773, +777, +780, +784, +787, +791, +794, +797, +800, +803, +806, +809, +811, +814, +816, +818, +821, +823, +825, +827, +828, +830, +832, +833, +835, +836, +837, +838, +839, +840, +841, +841, +842, +842, +843, +843, +843, +843, +843, +843, +843, +842, +842, +841, +840, +840, +839, +838, +837, +835, +834, +833, +831, +830, +828, +826, +824, +822, +820, +818, +816, +813, +811, +808, +806, +803, +800, +797, +794, +791, +788, +784, +781, +777, +774, +770, +766, +763, +759, +755, +750, +746, +742, +738, +733, +729, +724, +719, +714, +710, +705, +700, +694, +689, +684, +679, +673, +668, +662, +657, +651, +645, +639, +633, +627, +621, +615, +609, +603, +596, +590, +584, +577, +571, +564, +557, +551, +544, +537, +530, +523, +516, +509, +502, +495, +487, +480, +473, +465, +458, +450, +443, +435, +428, +420, +413, +405, +397, +389, +381, +374, +366, +358, +350, +342, +334, +326, +318, +310, +301, +293, +285, +277, +269, +260, +252, +244, +236, +227, +219, +211, +202, +194, +185, +177, +169, +160, +152, +143, +135, +126, +118, +110, +101, +93, +84, +76, +67, +59, +50, +42, +34, +25, +17, +8, +0, +-7, +-16, +-24, +-32, +-41, +-49, +-57, +-66, +-74, +-82, +-90, +-98, +-106, +-115, +-123, +-131, +-139, +-147, +-155, +-163, +-171, +-179, +-186, +-194, +-202, +-210, +-217, +-225, +-233, +-240, +-248, +-255, +-263, +-270, +-278, +-285, +-292, +-299, +-307, +-314, +-321, +-328, +-335, +-342, +-349, +-356, +-362, +-369, +-376, +-382, +-389, +-396, +-402, +-408, +-415, +-421, +-427, +-433, +-439, +-445, +-451, +-457, +-463, +-469, +-475, +-480, +-486, +-491, +-497, +-502, +-507, +-513, +-518, +-523, +-528, +-533, +-538, +-542, +-547, +-552, +-556, +-561, +-565, +-570, +-574, +-578, +-582, +-586, +-590, +-594, +-598, +-602, +-605, +-609, +-612, +-616, +-619, +-622, +-625, +-629, +-632, +-634, +-637, +-640, +-643, +-645, +-648, +-650, +-653, +-655, +-657, +-659, +-661, +-663, +-665, +-667, +-668, +-670, +-671, +-673, +-674, +-675, +-676, +-678, +-679, +-679, +-680, +-681, +-682, +-682, +-683, +-683, +-683, +-684, +-684, +-684, +-684, +-684, +-684, +-683, +-683, +-682, +-682, +-681, +-681, +-680, +-679, +-678, +-677, +-676, +-675, +-674, +-672, +-671, +-669, +-668, +-666, +-664, +-662, +-661, +-659, +-657, +-654, +-652, +-650, +-648, +-645, +-643, +-640, +-637, +-635, +-632, +-629, +-626, +-623, +-620, +-617, +-613, +-610, +-607, +-603, +-600, +-596, +-593, +-589, +-585, +-581, +-577, +-573, +-569, +-565, +-561, +-557, +-552, +-548, +-544, +-539, +-534, +-530, +-525, +-520, +-516, +-511, +-506, +-501, +-496, +-491, +-486, +-481, +-475, +-470, +-465, +-460, +-454, +-449, +-443, +-438, +-432, +-426, +-421, +-415, +-409, +-403, +-398, +-392, +-386, +-380, +-374, +-368, +-362, +-355, +-349, +-343, +-337, +-331, +-324, +-318, +-312, +-305, +-299, +-292, +-286, +-280, +-273, +-266, +-260, +-253, +-247, +-240, +-234, +-227, +-220, +-213, +-207, +-200, +-193, +-187, +-180, +-173, +-166, +-159, +-153, +-146, +-139, +-132, +-125, +-118, +-112, +-105, +-98, +-91, +-84, +-77, +-70, +-64, +-57, +-50, +-43, +-36, +-29, +-22, +-16, +-9, +-2, +4, +11, +17, +24, +31, +38, +44, +51, +58, +64, +71, +78, +84, +91, +98, +104, +111, +117, +124, +130, +137, +143, +149, +156, +162, +168, +175, +181, +187, +193, +199, +205, +212, +218, +224, +230, +236, +241, +247, +253, +259, +265, +270, +276, +282, +287, +293, +298, +304, +309, +314, +320, +325, +330, +335, +340, +345, +350, +355, +360, +365, +370, +375, +380, +384, +389, +393, +398, +402, +407, +411, +415, +419, +424, +428, +432, +436, +440, +443, +447, +451, +455, +458, +462, +465, +469, +472, +475, +479, +482, +485, +488, +491, +494, +497, +499, +502, +505, +507, +510, +512, +515, +517, +519, +522, +524, +526, +528, +530, +532, +533, +535, +537, +538, +540, +541, +543, +544, +545, +546, +548, +549, +550, +550, +551, +552, +553, +553, +554, +554, +555, +555, +555, +556, +556, +556, +556, +556, +556, +555, +555, +555, +554, +554, +553, +553, +552, +551, +551, +550, +549, +548, +547, +546, +545, +543, +542, +541, +539, +538, +536, +534, +533, +531, +529, +527, +525, +523, +521, +519, +517, +514, +512, +510, +507, +505, +502, +500, +497, +494, +492, +489, +486, +483, +480, +477, +474, +471, +467, +464, +461, +457, +454, +450, +447, +443, +440, +436, +432, +429, +425, +421, +417, +413, +409, +405, +401, +397, +393, +388, +384, +380, +375, +371, +367, +362, +358, +353, +349, +344, +339, +335, +330, +325, +321, +316, +311, +306, +301, +296, +291, +286, +281, +276, +271, +266, +261, +256, +251, +245, +240, +235, +230, +225, +219, +214, +209, +203, +198, +193, +187, +182, +176, +171, +165, +160, +154, +149, +144, +138, +132, +127, +121, +116, +110, +105, +99, +94, +88, +83, +77, +71, +66, +60, +55, +49, +44, +38, +33, +27, +21, +16, +10, +5, +0, +-5, +-11, +-16, +-22, +-27, +-33, +-38, +-43, +-49, +-54, +-60, +-65, +-70, +-76, +-81, +-86, +-92, +-97, +-102, +-107, +-113, +-118, +-123, +-128, +-133, +-138, +-143, +-148, +-153, +-158, +-163, +-168, +-173, +-178, +-183, +-188, +-192, +-197, +-202, +-207, +-211, +-216, +-221, +-225, +-230, +-234, +-239, +-243, +-247, +-252, +-256, +-260, +-265, +-269, +-273, +-277, +-281, +-285, +-289, +-293, +-297, +-301, +-305, +-308, +-312, +-316, +-319, +-323, +-327, +-330, +-334, +-337, +-340, +-344, +-347, +-350, +-353, +-357, +-360, +-363, +-366, +-369, +-372, +-374, +-377, +-380, +-383, +-385, +-388, +-390, +-393, +-395, +-398, +-400, +-402, +-405, +-407, +-409, +-411, +-413, +-415, +-417, +-419, +-420, +-422, +-424, +-425, +-427, +-429, +-430, +-431, +-433, +-434, +-435, +-436, +-438, +-439, +-440, +-441, +-442, +-442, +-443, +-444, +-445, +-445, +-446, +-446, +-447, +-447, +-448, +-448, +-448, +-448, +-449, +-449, +-449, +-449, +-449, +-448, +-448, +-448, +-448, +-447, +-447, +-446, +-446, +-445, +-445, +-444, +-443, +-442, +-442, +-441, +-440, +-439, +-438, +-437, +-435, +-434, +-433, +-432, +-430, +-429, +-427, +-426, +-424, +-423, +-421, +-419, +-418, +-416, +-414, +-412, +-410, +-408, +-406, +-404, +-402, +-400, +-397, +-395, +-393, +-390, +-388, +-385, +-383, +-380, +-378, +-375, +-373, +-370, +-367, +-364, +-361, +-359, +-356, +-353, +-350, +-347, +-344, +-340, +-337, +-334, +-331, +-328, +-324, +-321, +-318, +-314, +-311, +-307, +-304, +-300, +-297, +-293, +-290, +-286, +-282, +-279, +-275, +-271, +-267, +-263, +-260, +-256, +-252, +-248, +-244, +-240, +-236, +-232, +-228, +-224, +-220, +-216, +-212, +-207, +-203, +-199, +-195, +-191, +-186, +-182, +-178, +-174, +-169, +-165, +-161, +-156, +-152, +-148, +-143, +-139, +-134, +-130, +-126, +-121, +-117, +-112, +-108, +-103, +-99, +-95, +-90, +-86, +-81, +-77, +-72, +-68, +-63, +-59, +-54, +-50, +-45, +-41, +-36, +-32, +-27, +-23, +-18, +-14, +-9, +-5, +0, +3, +7, +12, +16, +21, +25, +29, +34, +38, +43, +47, +51, +56, +60, +64, +69, +73, +77, +81, +85, +90, +94, +98, +102, +106, +110, +115, +119, +123, +127, +131, +135, +139, +143, +146, +150, +154, +158, +162, +166, +169, +173, +177, +181, +184, +188, +192, +195, +199, +202, +206, +209, +212, +216, +219, +223, +226, +229, +232, +236, +239, +242, +245, +248, +251, +254, +257, +260, +263, +266, +268, +271, +274, +277, +279, +282, +284, +287, +289, +292, +294, +297, +299, +301, +304, +306, +308, +310, +312, +314, +316, +318, +320, +322, +324, +326, +328, +329, +331, +333, +334, +336, +337, +339, +340, +341, +343, +344, +345, +346, +348, +349, +350, +351, +352, +353, +354, +354, +355, +356, +357, +357, +358, +358, +359, +359, +360, +360, +361, +361, +361, +361, +362, +362, +362, +362, +362, +362, +362, +361, +361, +361, +361, +360, +360, +360, +359, +359, +358, +358, +357, +356, +356, +355, +354, +353, +352, +351, +350, +349, +348, +347, +346, +345, +344, +343, +341, +340, +339, +337, +336, +334, +333, +331, +330, +328, +326, +324, +323, +321, +319, +317, +315, +313, +311, +309, +307, +305, +303, +301, +299, +297, +294, +292, +290, +288, +285, +283, +280, +278, +275, +273, +270, +268, +265, +263, +260, +257, +254, +252, +249, +246, +243, +240, +238, +235, +232, +229, +226, +223, +220, +217, +214, +211, +208, +204, +201, +198, +195, +192, +188, +185, +182, +179, +175, +172, +169, +165, +162, +159, +155, +152, +149, +145, +142, +138, +135, +131, +128, +124, +121, +117, +114, +110, +107, +103, +100, +96, +93, +89, +85, +82, +78, +75, +71, +67, +64, +60, +57, +53, +49, +46, +42, +39, +35, +31, +28, +24, +21, +17, +14, +10, +6, +3, +0, +-3, +-7, +-10, +-14, +-18, +-21, +-25, +-28, +-32, +-35, +-39, +-42, +-45, +-49, +-52, +-56, +-59, +-63, +-66, +-69, +-73, +-76, +-79, +-83, +-86, +-89, +-93, +-96, +-99, +-102, +-105, +-109, +-112, +-115, +-118, +-121, +-124, +-127, +-130, +-133, +-136, +-139, +-142, +-145, +-148, +-151, +-154, +-157, +-160, +-162, +-165, +-168, +-171, +-173, +-176, +-179, +-181, +-184, +-186, +-189, +-191, +-194, +-196, +-199, +-201, +-204, +-206, +-208, +-211, +-213, +-215, +-217, +-219, +-221, +-224, +-226, +-228, +-230, +-232, +-234, +-236, +-237, +-239, +-241, +-243, +-245, +-246, +-248, +-250, +-251, +-253, +-254, +-256, +-257, +-259, +-260, +-262, +-263, +-264, +-266, +-267, +-268, +-269, +-270, +-271, +-273, +-274, +-275, +-275, +-276, +-277, +-278, +-279, +-280, +-281, +-281, +-282, +-283, +-283, +-284, +-284, +-285, +-285, +-286, +-286, +-286, +-287, +-287, +-287, +-287, +-288, +-288, +-288, +-288, +-288, +-288, +-288, +-288, +-288, +-288, +-287, +-287, +-287, +-287, +-286, +-286, +-286, +-285, +-285, +-284, +-284, +-283, +-283, +-282, +-281, +-281, +-280, +-279, +-278, +-277, +-277, +-276, +-275, +-274, +-273, +-272, +-271, +-270, +-269, +-267, +-266, +-265, +-264, +-262, +-261, +-260, +-258, +-257, +-256, +-254, +-253, +-251, +-250, +-248, +-247, +-245, +-243, +-242, +-240, +-238, +-236, +-235, +-233, +-231, +-229, +-227, +-225, +-223, +-221, +-219, +-217, +-215, +-213, +-211, +-209, +-207, +-205, +-203, +-201, +-198, +-196, +-194, +-192, +-189, +-187, +-185, +-182, +-180, +-178, +-175, +-173, +-170, +-168, +-165, +-163, +-160, +-158, +-155, +-153, +-150, +-148, +-145, +-142, +-140, +-137, +-135, +-132, +-129, +-127, +-124, +-121, +-118, +-116, +-113, +-110, +-108, +-105, +-102, +-99, +-96, +-94, +-91, +-88, +-85, +-82, +-80, +-77, +-74, +-71, +-68, +-65, +-63, +-60, +-57, +-54, +-51, +-48, +-45, +-42, +-40, +-37, +-34, +-31, +-28, +-25, +-22, +-20, +-17, +-14, +-11, +-8, +-5, +-2, +0, +2, +5, +8, +11, +13, +16, +19, +22, +25, +27, +30, +33, +36, +38, +41, +44, +47, +49, +52, +55, +57, +60, +63, +65, +68, +71, +73, +76, +78, +81, +83, +86, +88, +91, +93, +96, +98, +101, +103, +106, +108, +110, +113, +115, +117, +120, +122, +124, +127, +129, +131, +133, +135, +137, +140, +142, +144, +146, +148, +150, +152, +154, +156, +158, +160, +161, +163, +165, +167, +169, +171, +172, +174, +176, +177, +179, +181, +182, +184, +185, +187, +188, +190, +191, +193, +194, +195, +197, +198, +199, +201, +202, +203, +204, +205, +207, +208, +209, +210, +211, +212, +213, +214, +215, +216, +216, +217, +218, +219, +219, +220, +221, +222, +222, +223, +223, +224, +224, +225, +225, +226, +226, +227, +227, +227, +227, +228, +228, +228, +228, +228, +229, +229, +229, +229, +229, +229, +229, +229, +228, +228, +228, +228, +228, +228, +227, +227, +227, +226, +226, +225, +225, +225, +224, +224, +223, +222, +222, +221, +221, +220, +219, +218, +218, +217, +216, +215, +214, +214, +213, +212, +211, +210, +209, +208, +207, +206, +205, +203, +202, +201, +200, +199, +197, +196, +195, +194, +192, +191, +190, +188, +187, +185, +184, +182, +181, +179, +178, +176, +175, +173, +172, +170, +168, +167, +165, +163, +162, +160, +158, +156, +155, +153, +151, +149, +147, +146, +144, +142, +140, +138, +136, +134, +132, +130, +128, +126, +124, +122, +120, +118, +116, +114, +112, +110, +108, +106, +104, +102, +99, +97, +95, +93, +91, +89, +87, +84, +82, +80, +78, +76, +73, +71, +69, +67, +64, +62, +60, +58, +56, +53, +51, +49, +47, +44, +42, +40, +38, +35, +33, +31, +28, +26, +24, +22, +19, +17, +15, +13, +10, +8, +6, +4, +1, +0, +-2, +-4, +-6, +-9, +-11, +-13, +-15, +-17, +-20, +-22, +-24, +-26, +-28, +-30, +-33, +-35, +-37, +-39, +-41, +-43, +-45, +-47, +-49, +-52, +-54, +-56, +-58, +-60, +-62, +-64, +-66, +-68, +-70, +-72, +-74, +-76, +-77, +-79, +-81, +-83, +-85, +-87, +-89, +-90, +-92, +-94, +-96, +-98, +-99, +-101, +-103, +-105, +-106, +-108, +-110, +-111, +-113, +-114, +-116, +-118, +-119, +-121, +-122, +-124, +-125, +-127, +-128, +-130, +-131, +-132, +-134, +-135, +-136, +-138, +-139, +-140, +-142, +-143, +-144, +-145, +-146, +-148, +-149, +-150, +-151, +-152, +-153, +-154, +-155, +-156, +-157, +-158, +-159, +-160, +-161, +-162, +-162, +-163, +-164, +-165, +-166, +-166, +-167, +-168, +-168, +-169, +-170, +-170, +-171, +-171, +-172, +-172, +-173, +-173, +-174, +-174, +-175, +-175, +-175, +-176, +-176, +-176, +-177, +-177, +-177, +-177, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-178, +-177, +-177, +-177, +-177, +-177, +-176, +-176, +-176, +-175, +-175, +-175, +-174, +-174, +-173, +-173, +-172, +-172, +-171, +-171, +-170, +-170, +-169, +-168, +-168, +-167, +-166, +-166, +-165, +-164, +-163, +-163, +-162, +-161, +-160, +-159, +-158, +-158, +-157, +-156, +-155, +-154, +-153, +-152, +-151, +-150, +-149, +-148, +-147, +-145, +-144, +-143, +-142, +-141, +-140, +-139, +-137, +-136, +-135, +-134, +-132, +-131, +-130, +-128, +-127, +-126, +-124, +-123, +-122, +-120, +-119, +-118, +-116, +-115, +-113, +-112, +-110, +-109, +-107, +-106, +-104, +-103, +-101, +-100, +-98, +-97, +-95, +-94, +-92, +-90, +-89, +-87, +-86, +-84, +-82, +-81, +-79, +-77, +-76, +-74, +-72, +-71, +-69, +-67, +-66, +-64, +-62, +-60, +-59, +-57, +-55, +-54, +-52, +-50, +-48, +-47, +-45, +-43, +-41, +-40, +-38, +-36, +-34, +-33, +-31, +-29, +-27, +-25, +-24, +-22, +-20, +-18, +-17, +-15, +-13, +-11, +-10, +-8, +-6, +-4, +-3, +-1, +0, +2, +3, +5, +7, +8, +10, +12, +14, +15, +17, +19, +20, +22, +24, +25, +27, +29, +30, +32, +34, +35, +37, +39, +40, +42, +43, +45, +47, +48, +50, +51, +53, +54, +56, +57, +59, +60, +62, +63, +65, +66, +68, +69, +70, +72, +73, +75, +76, +77, +79, +80, +81, +83, +84, +85, +87, +88, +89, +90, +92, +93, +94, +95, +96, +97, +99, +100, +101, +102, +103, +104, +105, +106, +107, +108, +109, +110, +111, +112, +113, +114, +115, +116, +117, +117, +118, +119, +120, +121, +121, +122, +123, +124, +124, +125, +126, +126, +127, +128, +128, +129, +129, +130, +130, +131, +131, +132, +132, +133, +133, +134, +134, +135, +135, +135, +136, +136, +136, +136, +137, +137, +137, +137, +138, +138, +138, +138, +138, +138, +138, +138, +139, +139, +139, +139, +139, +139, +139, +138, +138, +138, +138, +138, +138, +138, +138, +137, +137, +137, +137, +136, +136, +136, +136, +135, +135, +134, +134, +134, +133, +133, +132, +132, +132, +131, +131, +130, +129, +129, +128, +128, +127, +127, +126, +125, +125, +124, +123, +123, +122, +121, +121, +120, +119, +118, +117, +117, +116, +115, +114, +113, +113, +112, +111, +110, +109, +108, +107, +106, +105, +104, +103, +102, +101, +100, +99, +98, +97, +96, +95, +94, +93, +92, +91, +90, +89, +87, +86, +85, +84, +83, +82, +81, +79, +78, +77, +76, +75, +73, +72, +71, +70, +68, +67, +66, +65, +63, +62, +61, +60, +58, +57, +56, +54, +53, +52, +50, +49, +48, +47, +45, +44, +43, +41, +40, +39, +37, +36, +34, +33, +32, +30, +29, +28, +26, +25, +24, +22, +21, +20, +18, +17, +16, +14, +13, +11, +10, +9, +7, +6, +5, +3, +2, +1, +0, +-1, +-2, +-4, +-5, +-6, +-8, +-9, +-10, +-11, +-13, +-14, +-15, +-17, +-18, +-19, +-20, +-22, +-23, +-24, +-26, +-27, +-28, +-29, +-30, +-32, +-33, +-34, +-35, +-37, +-38, +-39, +-40, +-41, +-42, +-44, +-45, +-46, +-47, +-48, +-49, +-50, +-51, +-53, +-54, +-55, +-56, +-57, +-58, +-59, +-60, +-61, +-62, +-63, +-64, +-65, +-66, +-67, +-68, +-69, +-70, +-71, +-71, +-72, +-73, +-74, +-75, +-76, +-77, +-77, +-78, +-79, +-80, +-81, +-81, +-82, +-83, +-84, +-84, +-85, +-86, +-87, +-87, +-88, +-89, +-89, +-90, +-90, +-91, +-92, +-92, +-93, +-93, +-94, +-94, +-95, +-95, +-96, +-96, +-97, +-97, +-98, +-98, +-99, +-99, +-99, +-100, +-100, +-100, +-101, +-101, +-101, +-102, +-102, +-102, +-102, +-103, +-103, +-103, +-103, +-103, +-104, +-104, +-104, +-104, +-104, +-104, +-104, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-105, +-104, +-104, +-104, +-104, +-104, +-104, +-104, +-104, +-103, +-103, +-103, +-103, +-103, +-102, +-102, +-102, +-102, +-101, +-101, +-101, +-100, +-100, +-100, +-99, +-99, +-99, +-98, +-98, +-97, +-97, +-97, +-96, +-96, +-95, +-95, +-94, +-94, +-93, +-93, +-92, +-92, +-91, +-90, +-90, +-89, +-89, +-88, +-87, +-87, +-86, +-86, +-85, +-84, +-84, +-83, +-82, +-81, +-81, +-80, +-79, +-79, +-78, +-77, +-76, +-76, +-75, +-74, +-73, +-72, +-72, +-71, +-70, +-69, +-68, +-67, +-67, +-66, +-65, +-64, +-63, +-62, +-61, +-61, +-60, +-59, +-58, +-57, +-56, +-55, +-54, +-53, +-52, +-51, +-50, +-49, +-48, +-48, +-47, +-46, +-45, +-44, +-43, +-42, +-41, +-40, +-39, +-38, +-37, +-36, +-35, +-34, +-33, +-32, +-31, +-30, +-29, +-28, +-27, +-26, +-25, +-24, +-23, +-21, +-20, +-19, +-18, +-17, +-16, +-15, +-14, +-13, +-12, +-11, +-10, +-9, +-8, +-7, +-6, +-5, +-4, +-3, +-2, +-1, +0, +0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15, +16, +17, +18, +19, +20, +21, +22, +22, +23, +24, +25, +26, +27, +28, +29, +30, +31, +32, +32, +33, +34, +35, +36, +37, +38, +38, +39, +40, +41, +42, +42, +43, +44, +45, +46, +46, +47, +48, +49, +49, +50, +51, +52, +52, +53, +54, +54, +55, +56, +56, +57, +58, +58, +59, +59, +60, +61, +61, +62, +62, +63, +64, +64, +65, +65, +66, +66, +67, +67, +68, +68, +69, +69, +69, +70, +70, +71, +71, +72, +72, +72, +73, +73, +73, +74, +74, +74, +75, +75, +75, +76, +76, +76, +76, +77, +77, +77, +77, +77, +78, +78, +78, +78, +78, +78, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +79, +78, +78, +78, +78, +78, +78, +77, +77, +77, +77, +77, +76, +76, +76, +76, +75, +75, +75, +74, +74, +74, +74, +73, +73, +72, +72, +72, +71, +71, +71, +70, +70, +69, +69, +69, +68, +68, +67, +67, +66, +66, +65, +65, +64, +64, +63, +63, +62, +62, +61, +61, +60, +60, +59, +59, +58, +57, +57, +56, +56, +55, +55, +54, +53, +53, +52, +51, +51, +50, +50, +49, +48, +48, +47, +46, +46, +45, +44, +44, +43, +42, +41, +41, +40, +39, +39, +38, +37, +37, +36, +35, +34, +34, +33, +32, +31, +31, +30, +29, +28, +28, +27, +26, +25, +25, +24, +23, +22, +22, +21, +20, +19, +19, +18, +17, +16, +16, +15, +14, +13, +12, +12, +11, +10, +9, +9, +8, +7, +6, +6, +5, +4, +3, +3, +2, +1, +0, +0, +0, +-1, +-2, +-2, +-3, +-4, +-5, +-5, +-6, +-7, +-8, +-8, +-9, +-10, +-10, +-11, +-12, +-13, +-13, +-14, +-15, +-15, +-16, +-17, +-17, +-18, +-19, +-19, +-20, +-21, +-21, +-22, +-23, +-23, +-24, +-25, +-25, +-26, +-27, +-27, +-28, +-28, +-29, +-30, +-30, +-31, +-31, +-32, +-33, +-33, +-34, +-34, +-35, +-35, +-36, +-36, +-37, +-37, +-38, +-38, +-39, +-39, +-40, +-40, +-41, +-41, +-42, +-42, +-43, +-43, +-44, +-44, +-45, +-45, +-45, +-46, +-46, +-47, +-47, +-47, +-48, +-48, +-49, +-49, +-49, +-50, +-50, +-50, +-51, +-51, +-51, +-51, +-52, +-52, +-52, +-53, +-53, +-53, +-53, +-54, +-54, +-54, +-54, +-54, +-55, +-55, +-55, +-55, +-55, +-56, +-56, +-56, +-56, +-56, +-56, +-56, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-57, +-56, +-56, +-56, +-56, +-56, +-56, +-56, +-55, +-55, +-55, +-55, +-55, +-54, +-54, +-54, +-54, +-54, +-53, +-53, +-53, +-53, +-52, +-52, +-52, +-52, +-51, +-51, +-51, +-50, +-50, +-50, +-50, +-49, +-49, +-49, +-48, +-48, +-48, +-47, +-47, +-46, +-46, +-46, +-45, +-45, +-45, +-44, +-44, +-43, +-43, +-43, +-42, +-42, +-41, +-41, +-40, +-40, +-40, +-39, +-39, +-38, +-38, +-37, +-37, +-36, +-36, +-35, +-35, +-35, +-34, +-34, +-33, +-33, +-32, +-32, +-31, +-31, +-30, +-30, +-29, +-29, +-28, +-28, +-27, +-26, +-26, +-25, +-25, +-24, +-24, +-23, +-23, +-22, +-22, +-21, +-21, +-20, +-19, +-19, +-18, +-18, +-17, +-17, +-16, +-16, +-15, +-15, +-14, +-13, +-13, +-12, +-12, +-11, +-11, +-10, +-9, +-9, +-8, +-8, +-7, +-7, +-6, +-6, +-5, +-4, +-4, +-3, +-3, +-2, +-2, +-1, +-1, +0, +0, +0, +1, +1, +2, +2, +3, +3, +4, +4, +5, +5, +6, +7, +7, +8, +8, +9, +9, +10, +10, +11, +11, +12, +12, +13, +13, +14, +14, +15, +15, +16, +16, +17, +17, +18, +18, +18, +19, +19, +20, +20, +21, +21, +22, +22, +22, +23, +23, +24, +24, +25, +25, +25, +26, +26, +27, +27, +27, +28, +28, +28, +29, +29, +30, +30, +30, +31, +31, +31, +32, +32, +32, +33, +33, +33, +33, +34, +34, +34, +35, +35, +35, +35, +36, +36, +36, +36, +37, +37, +37, +37, +38, +38, +38, +38, +38, +39, +39, +39, +39, +39, +40, +40, +40, +40, +40, +40, +40, +41, +41, +41, +41, +41, +41, +41, +41, +41, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +42, +41, +41, +41, +41, +41, +41, +41, +41, +41, +41, +40, +40, +40, +40, +40, +40, +40, +39, +39, +39, +39, +39, +38, +38, +38, +38, +38, +37, +37, +37, +37, +37, +36, +36, +36, +36, +35, +35, +35, +35, +34, +34, +34, +34, +33, +33, +33, +33, +32, +32, +32, +31, +31, +31, +30, +30, +30, +30, +29, +29, +29, +28, +28, +28, +27, +27, +27, +26, +26, +26, +25, +25, +25, +24, +24, +23, +23, +23, +22, +22, +22, +21, +21, +21, +20, +20, +19, +19, +19, +18, +18, +18, +17, +17, +16, +16, +16, +15, +15, +14, +14, +14, +13, +13, +12, +12, +12, +11, +11, +10, +10, +10, +9, +9, +8, +8, +8, +7, +7, +6, +6, +6, +5, +5, +4, +4, +4, +3, +3, +2, +2, +2, +1, +1, +1, +0, +0, +0, +0, +0, +-1, +-1, +-2, +-2, +-2, +-3, +-3, +-3, +-4, +-4, +-5, +-5, +-5, +-6, +-6, +-6, +-7, +-7, +-7, +-8, +-8, +-9, +-9, +-9, +-10, +-10, +-10, +-11, +-11, +-11, +-12, +-12, +-12, +-13, +-13, +-13, +-14, +-14, +-14, +-14, +-15, +-15, +-15, +-16, +-16, +-16, +-17, +-17, +-17, +-17, +-18, +-18, +-18, +-19, +-19, +-19, +-19, +-20, +-20, +-20, +-20, +-21, +-21, +-21, +-21, +-21, +-22, +-22, +-22, +-22, +-23, +-23, +-23, +-23, +-23, +-24, +-24, +-24, +-24, +-24, +-25, +-25, +-25, +-25, +-25, +-25, +-26, +-26, +-26, +-26, +-26, +-26, +-26, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-29, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-28, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-27, +-26, +-26, +-26, +-26, +-26, +-26, +-26, +-25, +-25, +-25, +-25, +-25, +-25, +-25, +-24, +-24, +-24, +-24, +-24, +-24, +-23, +-23, +-23, +-23, +-23, +-22, +-22, +-22, +-22, +-22, +-21, +-21, +-21, +-21, +-21, +-20, +-20, +-20, +-20, +-20, +-19, +-19, +-19, +-19, +-18, +-18, +-18, +-18, +-17, +-17, +-17, +-17, +-16, +-16, +-16, +-16, +-15, +-15, +-15, +-15, +-14, +-14, +-14, +-14, +-13, +-13, +-13, +-13, +-12, +-12, +-12, +-12, +-11, +-11, +-11, +-11, +-10, +-10, +-10, +-9, +-9, +-9, +-9, +-8, +-8, +-8, +-7, +-7, +-7, +-7, +-6, +-6, +-6, +-6, +-5, +-5, +-5, +-4, +-4, +-4, +-4, +-3, +-3, +-3, +-2, +-2, +-2, +-2, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +2, +2, +2, +2, +3, +3, +3, +3, +4, +4, +4, +5, +5, +5, +5, +6, +6, +6, +6, +6, +7, +7, +7, +7, +8, +8, +8, +8, +9, +9, +9, +9, +10, +10, +10, +10, +10, +11, +11, +11, +11, +11, +12, +12, +12, +12, +12, +13, +13, +13, +13, +13, +14, +14, +14, +14, +14, +14, +15, +15, +15, +15, +15, +15, +16, +16, +16, +16, +16, +16, +16, +17, +17, +17, +17, +17, +17, +17, +17, +18, +18, +18, +18, +18, +18, +18, +18, +18, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +20, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +19, +18, +18, +18, +18, +18, +18, +18, +18, +18, +18, +17, +17, +17, +17, +17, +17, +17, +17, +16, +16, +16, +16, +16, +16, +16, +16, +15, +15, +15, +15, +15, +15, +15, +14, +14, +14, +14, +14, +14, +14, +13, +13, +13, +13, +13, +13, +12, +12, +12, +12, +12, +12, +11, +11, +11, +11, +11, +11, +10, +10, +10, +10, +10, +9, +9, +9, +9, +9, +9, +8, +8, +8, +8, +8, +7, +7, +7, +7, +7, +7, +6, +6, +6, +6, +6, +5, +5, +5, +5, +5, +4, +4, +4, +4, +4, +4, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +2, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-4, +-4, +-4, +-4, +-4, +-4, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +3, +3, +3, +3, +3, +3, +3, +3, +3, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +8, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +7, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +6, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0}; + +static HWORD LARGE_FILTER_IMPD[] /* Impulse response differences */ = { +-1, +-2, +-3, +-5, +-6, +-7, +-9, +-10, +-11, +-13, +-14, +-15, +-17, +-18, +-19, +-21, +-22, +-23, +-25, +-26, +-27, +-28, +-30, +-32, +-32, +-34, +-35, +-36, +-38, +-39, +-40, +-42, +-43, +-44, +-45, +-47, +-48, +-49, +-51, +-52, +-53, +-54, +-56, +-56, +-58, +-60, +-60, +-62, +-63, +-64, +-66, +-66, +-68, +-69, +-70, +-72, +-72, +-74, +-75, +-76, +-77, +-79, +-79, +-81, +-82, +-83, +-84, +-85, +-87, +-87, +-89, +-90, +-90, +-92, +-93, +-94, +-95, +-96, +-98, +-98, +-99, +-100, +-102, +-102, +-103, +-105, +-105, +-106, +-108, +-108, +-109, +-110, +-111, +-112, +-113, +-114, +-115, +-116, +-116, +-118, +-118, +-119, +-121, +-120, +-122, +-123, +-123, +-125, +-125, +-126, +-126, +-128, +-128, +-129, +-130, +-130, +-132, +-132, +-132, +-134, +-134, +-135, +-135, +-136, +-137, +-137, +-138, +-139, +-139, +-140, +-141, +-141, +-142, +-142, +-143, +-143, +-144, +-145, +-145, +-145, +-146, +-147, +-147, +-147, +-148, +-149, +-148, +-150, +-149, +-150, +-151, +-151, +-151, +-152, +-152, +-152, +-153, +-153, +-153, +-153, +-154, +-154, +-155, +-155, +-155, +-155, +-155, +-156, +-156, +-156, +-156, +-156, +-157, +-157, +-157, +-157, +-157, +-157, +-157, +-158, +-157, +-158, +-158, +-157, +-158, +-158, +-158, +-158, +-157, +-158, +-158, +-158, +-157, +-158, +-158, +-157, +-158, +-157, +-157, +-157, +-157, +-157, +-157, +-157, +-156, +-156, +-156, +-156, +-156, +-155, +-155, +-155, +-155, +-155, +-154, +-154, +-153, +-154, +-153, +-153, +-152, +-152, +-152, +-151, +-151, +-151, +-150, +-150, +-150, +-149, +-149, +-148, +-148, +-147, +-147, +-147, +-146, +-145, +-145, +-145, +-144, +-144, +-143, +-142, +-142, +-142, +-141, +-140, +-140, +-139, +-139, +-138, +-137, +-137, +-136, +-136, +-135, +-134, +-134, +-133, +-132, +-132, +-131, +-130, +-130, +-129, +-128, +-128, +-126, +-126, +-126, +-125, +-123, +-124, +-122, +-122, +-121, +-120, +-119, +-119, +-117, +-117, +-117, +-115, +-114, +-113, +-113, +-112, +-112, +-110, +-110, +-108, +-108, +-107, +-106, +-106, +-104, +-104, +-102, +-102, +-101, +-100, +-99, +-98, +-98, +-96, +-95, +-95, +-94, +-92, +-92, +-91, +-90, +-89, +-88, +-87, +-86, +-85, +-85, +-83, +-82, +-82, +-80, +-80, +-78, +-78, +-76, +-76, +-75, +-73, +-73, +-72, +-70, +-70, +-69, +-68, +-66, +-66, +-65, +-64, +-63, +-61, +-61, +-60, +-59, +-58, +-57, +-56, +-55, +-54, +-53, +-51, +-51, +-50, +-49, +-48, +-47, +-46, +-45, +-44, +-43, +-42, +-41, +-41, +-39, +-38, +-37, +-36, +-35, +-34, +-34, +-32, +-31, +-31, +-29, +-28, +-28, +-26, +-26, +-24, +-24, +-23, +-21, +-21, +-20, +-19, +-18, +-17, +-16, +-15, +-14, +-13, +-13, +-11, +-11, +-9, +-9, +-8, +-7, +-6, +-5, +-5, +-3, +-2, +-2, +-1, +0, +1, +2, +2, +4, +4, +5, +6, +7, +8, +8, +10, +10, +11, +11, +13, +13, +14, +15, +15, +17, +17, +18, +18, +20, +20, +21, +21, +23, +23, +23, +25, +25, +26, +26, +27, +28, +28, +30, +29, +31, +31, +32, +32, +33, +34, +34, +35, +35, +36, +37, +37, +37, +39, +39, +39, +40, +40, +41, +42, +42, +42, +43, +44, +44, +44, +45, +46, +45, +47, +46, +48, +47, +48, +49, +49, +49, +49, +50, +51, +51, +51, +51, +52, +52, +53, +53, +53, +53, +54, +54, +54, +55, +55, +55, +55, +56, +56, +56, +56, +57, +57, +57, +57, +58, +57, +58, +58, +58, +58, +59, +58, +59, +59, +59, +59, +59, +59, +59, +60, +59, +60, +59, +60, +60, +60, +59, +60, +60, +60, +60, +59, +60, +60, +60, +60, +59, +60, +60, +59, +60, +59, +60, +59, +59, +59, +59, +59, +59, +59, +58, +59, +58, +58, +58, +58, +57, +58, +57, +57, +57, +57, +55, +57, +56, +56, +55, +56, +55, +55, +54, +55, +54, +54, +54, +53, +53, +53, +52, +53, +52, +51, +52, +51, +50, +51, +50, +49, +50, +49, +48, +49, +48, +47, +47, +47, +47, +46, +46, +45, +45, +45, +44, +44, +43, +43, +42, +43, +41, +42, +40, +41, +40, +39, +40, +38, +39, +37, +38, +37, +36, +36, +35, +36, +34, +34, +34, +33, +33, +32, +32, +31, +31, +30, +30, +29, +29, +28, +28, +27, +27, +26, +26, +25, +25, +24, +24, +24, +22, +23, +21, +21, +21, +20, +20, +19, +19, +18, +18, +17, +16, +16, +16, +15, +14, +14, +14, +13, +12, +12, +11, +11, +11, +9, +10, +8, +9, +7, +8, +6, +7, +5, +5, +5, +4, +4, +3, +3, +2, +1, +1, +1, +0, +0, +-1, +-1, +-2, +-3, +-3, +-3, +-4, +-4, +-5, +-5, +-6, +-6, +-7, +-7, +-8, +-8, +-8, +-9, +-10, +-10, +-10, +-11, +-11, +-12, +-12, +-13, +-13, +-14, +-14, +-14, +-15, +-15, +-16, +-16, +-16, +-17, +-18, +-17, +-18, +-19, +-19, +-19, +-20, +-20, +-21, +-20, +-22, +-21, +-22, +-23, +-22, +-23, +-24, +-23, +-25, +-24, +-25, +-25, +-25, +-26, +-26, +-27, +-26, +-27, +-28, +-27, +-28, +-28, +-29, +-29, +-29, +-29, +-30, +-30, +-30, +-30, +-31, +-31, +-31, +-31, +-32, +-32, +-32, +-32, +-33, +-33, +-33, +-33, +-33, +-34, +-34, +-34, +-34, +-34, +-35, +-34, +-35, +-35, +-35, +-36, +-35, +-36, +-35, +-36, +-36, +-36, +-37, +-36, +-36, +-37, +-37, +-36, +-37, +-37, +-37, +-37, +-37, +-38, +-37, +-37, +-38, +-37, +-38, +-37, +-38, +-37, +-38, +-38, +-37, +-38, +-38, +-37, +-38, +-38, +-37, +-38, +-38, +-37, +-38, +-37, +-38, +-37, +-38, +-37, +-38, +-37, +-37, +-37, +-37, +-37, +-37, +-37, +-37, +-35, +-37, +-36, +-37, +-36, +-36, +-36, +-36, +-36, +-35, +-36, +-35, +-36, +-35, +-35, +-34, +-35, +-34, +-35, +-34, +-34, +-34, +-33, +-34, +-33, +-33, +-33, +-32, +-33, +-32, +-32, +-32, +-32, +-31, +-31, +-31, +-31, +-31, +-30, +-30, +-30, +-29, +-30, +-29, +-29, +-28, +-28, +-29, +-27, +-28, +-27, +-27, +-27, +-26, +-27, +-25, +-26, +-25, +-26, +-24, +-25, +-24, +-24, +-23, +-24, +-23, +-22, +-23, +-22, +-22, +-21, +-21, +-21, +-21, +-20, +-20, +-19, +-19, +-19, +-19, +-18, +-18, +-18, +-17, +-17, +-17, +-16, +-16, +-15, +-16, +-14, +-15, +-14, +-14, +-14, +-13, +-13, +-12, +-12, +-12, +-12, +-11, +-10, +-11, +-10, +-10, +-9, +-9, +-9, +-8, +-8, +-8, +-7, +-7, +-6, +-6, +-6, +-6, +-5, +-5, +-4, +-4, +-4, +-3, +-3, +-3, +-2, +-2, +-2, +-1, +-1, +-1, +0, +0, +0, +1, +1, +2, +1, +3, +2, +3, +3, +4, +3, +4, +5, +5, +5, +5, +6, +6, +7, +6, +8, +7, +8, +8, +8, +9, +9, +9, +10, +9, +11, +10, +11, +11, +11, +12, +12, +12, +13, +13, +13, +13, +14, +14, +14, +14, +15, +15, +15, +16, +16, +16, +16, +17, +16, +18, +17, +17, +18, +18, +18, +19, +19, +19, +19, +19, +20, +19, +20, +21, +20, +21, +21, +21, +21, +21, +22, +22, +22, +22, +22, +23, +22, +23, +23, +23, +23, +24, +24, +23, +24, +24, +24, +25, +24, +25, +24, +25, +25, +25, +25, +26, +25, +26, +25, +26, +26, +25, +26, +26, +26, +27, +26, +26, +27, +26, +27, +26, +27, +26, +27, +27, +27, +26, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +27, +26, +27, +27, +27, +27, +26, +27, +27, +26, +26, +26, +27, +26, +26, +27, +26, +26, +26, +26, +26, +26, +25, +26, +25, +26, +25, +25, +25, +25, +25, +25, +25, +24, +24, +25, +24, +24, +24, +23, +24, +24, +23, +23, +23, +23, +23, +22, +23, +22, +22, +22, +22, +21, +22, +21, +21, +21, +21, +20, +20, +21, +20, +19, +20, +19, +19, +19, +19, +19, +18, +18, +18, +18, +18, +17, +17, +17, +17, +16, +16, +16, +16, +16, +15, +15, +15, +14, +15, +14, +14, +14, +13, +13, +13, +13, +12, +13, +12, +11, +12, +11, +11, +11, +10, +11, +10, +9, +10, +9, +9, +9, +8, +9, +8, +7, +8, +7, +7, +7, +6, +6, +6, +6, +5, +5, +5, +5, +4, +4, +4, +3, +4, +3, +3, +2, +2, +2, +2, +2, +1, +1, +0, +1, +0, +0, +0, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-3, +-2, +-4, +-3, +-3, +-4, +-4, +-5, +-4, +-5, +-5, +-5, +-6, +-6, +-6, +-6, +-7, +-6, +-7, +-7, +-8, +-7, +-8, +-8, +-9, +-8, +-9, +-9, +-9, +-10, +-9, +-10, +-10, +-10, +-11, +-10, +-11, +-11, +-12, +-11, +-12, +-12, +-12, +-12, +-13, +-12, +-13, +-13, +-13, +-14, +-13, +-14, +-14, +-14, +-14, +-15, +-14, +-15, +-15, +-15, +-15, +-16, +-15, +-16, +-16, +-16, +-16, +-16, +-17, +-16, +-17, +-17, +-17, +-17, +-17, +-18, +-17, +-18, +-18, +-17, +-18, +-18, +-19, +-18, +-18, +-19, +-18, +-19, +-19, +-19, +-19, +-19, +-19, +-19, +-19, +-20, +-19, +-20, +-19, +-20, +-20, +-20, +-19, +-20, +-20, +-20, +-20, +-20, +-21, +-20, +-20, +-20, +-21, +-20, +-20, +-21, +-20, +-21, +-20, +-20, +-21, +-20, +-21, +-20, +-21, +-20, +-21, +-20, +-21, +-21, +-20, +-20, +-21, +-20, +-21, +-20, +-21, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-20, +-19, +-20, +-20, +-19, +-20, +-19, +-19, +-19, +-20, +-19, +-19, +-18, +-19, +-19, +-19, +-18, +-18, +-19, +-18, +-18, +-18, +-18, +-18, +-18, +-17, +-18, +-17, +-17, +-17, +-17, +-17, +-17, +-16, +-17, +-16, +-16, +-17, +-15, +-16, +-16, +-15, +-16, +-15, +-15, +-15, +-15, +-15, +-14, +-14, +-15, +-14, +-13, +-14, +-14, +-13, +-13, +-13, +-13, +-13, +-13, +-12, +-12, +-12, +-12, +-12, +-11, +-12, +-11, +-11, +-11, +-10, +-11, +-10, +-10, +-10, +-9, +-10, +-9, +-9, +-9, +-9, +-9, +-8, +-8, +-8, +-8, +-8, +-7, +-7, +-7, +-7, +-7, +-6, +-6, +-6, +-6, +-6, +-5, +-5, +-6, +-4, +-5, +-4, +-5, +-4, +-4, +-3, +-4, +-3, +-3, +-3, +-2, +-3, +-2, +-2, +-2, +-1, +-2, +-1, +-1, +-1, +0, +-1, +0, +0, +0, +1, +0, +1, +1, +1, +1, +2, +2, +2, +2, +2, +3, +3, +2, +4, +3, +3, +4, +4, +4, +4, +5, +4, +5, +5, +5, +6, +5, +6, +6, +6, +6, +7, +6, +7, +7, +7, +7, +8, +7, +8, +8, +8, +8, +9, +8, +9, +9, +9, +9, +10, +9, +10, +10, +10, +10, +10, +11, +10, +11, +11, +11, +11, +11, +11, +12, +11, +12, +12, +12, +12, +12, +13, +12, +13, +13, +12, +13, +13, +14, +13, +13, +14, +13, +14, +14, +13, +14, +14, +15, +14, +14, +14, +15, +14, +15, +15, +14, +15, +15, +15, +15, +15, +16, +15, +15, +15, +16, +15, +16, +15, +16, +15, +16, +16, +16, +15, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +17, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +16, +15, +16, +16, +16, +16, +16, +15, +16, +16, +15, +16, +16, +15, +15, +16, +15, +16, +15, +15, +15, +15, +15, +15, +15, +15, +15, +14, +15, +14, +15, +14, +14, +15, +14, +14, +14, +14, +13, +14, +14, +13, +13, +14, +13, +13, +13, +13, +13, +12, +13, +12, +13, +12, +12, +12, +12, +12, +12, +11, +12, +11, +11, +11, +11, +11, +11, +10, +11, +10, +10, +10, +10, +10, +10, +9, +10, +9, +9, +9, +9, +8, +9, +8, +9, +8, +8, +8, +7, +8, +7, +7, +7, +7, +7, +7, +6, +7, +6, +6, +6, +5, +6, +5, +5, +6, +4, +5, +5, +4, +5, +4, +4, +4, +3, +4, +3, +3, +3, +3, +3, +2, +3, +2, +2, +2, +2, +1, +2, +1, +1, +1, +1, +1, +0, +0, +1, +0, +-1, +0, +0, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-3, +-3, +-3, +-3, +-4, +-3, +-4, +-4, +-4, +-4, +-4, +-5, +-4, +-5, +-5, +-5, +-5, +-5, +-6, +-5, +-6, +-6, +-6, +-6, +-6, +-6, +-7, +-6, +-7, +-7, +-7, +-7, +-7, +-7, +-8, +-8, +-7, +-8, +-8, +-8, +-8, +-9, +-8, +-9, +-8, +-9, +-9, +-9, +-9, +-9, +-9, +-10, +-9, +-10, +-9, +-10, +-10, +-10, +-10, +-10, +-10, +-11, +-10, +-11, +-10, +-11, +-11, +-11, +-10, +-11, +-11, +-12, +-11, +-11, +-11, +-12, +-11, +-12, +-12, +-11, +-12, +-12, +-12, +-11, +-12, +-12, +-13, +-12, +-12, +-12, +-12, +-13, +-12, +-12, +-13, +-12, +-13, +-12, +-13, +-12, +-13, +-13, +-12, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-11, +-13, +-13, +-12, +-13, +-13, +-12, +-13, +-12, +-13, +-12, +-13, +-12, +-13, +-12, +-12, +-13, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-11, +-12, +-12, +-11, +-12, +-11, +-11, +-12, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-10, +-11, +-10, +-11, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-10, +-9, +-10, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-9, +-8, +-9, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-7, +-7, +-8, +-7, +-7, +-7, +-7, +-6, +-7, +-7, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-5, +-6, +-5, +-5, +-5, +-5, +-5, +-4, +-5, +-4, +-5, +-4, +-4, +-4, +-4, +-3, +-4, +-3, +-4, +-3, +-3, +-3, +-3, +-2, +-3, +-2, +-2, +-3, +-2, +-1, +-2, +-2, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +0, +-1, +0, +0, +0, +0, +0, +0, +1, +0, +1, +1, +0, +2, +1, +1, +1, +2, +2, +1, +2, +2, +3, +2, +2, +3, +2, +3, +3, +3, +3, +3, +4, +3, +4, +4, +3, +4, +4, +4, +5, +4, +5, +4, +5, +5, +5, +5, +5, +5, +5, +6, +5, +6, +6, +6, +6, +6, +6, +6, +6, +7, +6, +7, +7, +7, +7, +7, +7, +7, +7, +7, +8, +7, +8, +8, +7, +8, +8, +8, +8, +8, +8, +9, +8, +9, +8, +9, +8, +9, +9, +8, +9, +9, +9, +9, +9, +10, +9, +9, +9, +10, +9, +10, +9, +10, +10, +9, +10, +10, +9, +10, +10, +10, +10, +10, +10, +10, +10, +10, +10, +11, +10, +10, +10, +10, +11, +10, +10, +11, +10, +10, +11, +10, +10, +11, +10, +10, +11, +10, +11, +10, +11, +10, +10, +11, +10, +10, +11, +10, +11, +10, +10, +10, +10, +10, +10, +11, +10, +10, +10, +10, +11, +10, +10, +10, +10, +10, +10, +10, +10, +9, +10, +10, +10, +9, +10, +10, +9, +10, +9, +10, +9, +9, +10, +9, +9, +9, +9, +9, +9, +9, +9, +9, +8, +9, +9, +8, +9, +8, +8, +9, +8, +8, +8, +8, +8, +8, +7, +8, +8, +7, +8, +7, +7, +8, +7, +7, +7, +7, +6, +7, +7, +6, +7, +6, +7, +6, +6, +6, +6, +6, +6, +5, +6, +5, +6, +5, +5, +5, +5, +5, +5, +5, +4, +5, +4, +5, +4, +4, +4, +4, +4, +4, +3, +4, +3, +4, +3, +3, +3, +3, +3, +3, +2, +3, +2, +2, +3, +2, +2, +2, +1, +2, +2, +1, +2, +1, +1, +1, +1, +1, +1, +0, +1, +0, +1, +0, +0, +0, +0, +0, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-3, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-4, +-5, +-4, +-4, +-4, +-5, +-4, +-5, +-5, +-5, +-4, +-5, +-5, +-6, +-5, +-5, +-5, +-6, +-5, +-6, +-5, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-7, +-6, +-6, +-7, +-6, +-7, +-7, +-6, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-8, +-7, +-7, +-8, +-7, +-8, +-7, +-8, +-7, +-8, +-7, +-8, +-8, +-8, +-8, +-7, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-9, +-8, +-8, +-8, +-8, +-9, +-8, +-8, +-8, +-9, +-8, +-8, +-9, +-8, +-9, +-8, +-8, +-9, +-8, +-9, +-8, +-9, +-8, +-8, +-9, +-8, +-9, +-8, +-9, +-8, +-9, +-8, +-8, +-9, +-8, +-9, +-8, +-7, +-9, +-8, +-8, +-9, +-8, +-8, +-9, +-8, +-8, +-8, +-8, +-8, +-9, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-7, +-8, +-8, +-8, +-7, +-8, +-8, +-7, +-8, +-7, +-8, +-7, +-8, +-7, +-7, +-7, +-8, +-7, +-7, +-7, +-7, +-7, +-7, +-7, +-6, +-7, +-7, +-6, +-7, +-7, +-6, +-6, +-7, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-6, +-5, +-6, +-5, +-6, +-5, +-5, +-6, +-5, +-5, +-5, +-5, +-5, +-4, +-5, +-5, +-4, +-5, +-4, +-5, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-3, +-4, +-3, +-4, +-3, +-3, +-3, +-4, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +0, +-1, +-1, +-1, +0, +-1, +0, +0, +-1, +0, +0, +0, +0, +0, +1, +0, +1, +0, +1, +0, +1, +1, +1, +1, +1, +1, +1, +2, +1, +2, +1, +2, +2, +2, +1, +2, +2, +3, +2, +2, +2, +3, +2, +3, +3, +2, +3, +3, +3, +3, +3, +3, +4, +3, +3, +4, +3, +4, +3, +4, +4, +4, +4, +4, +4, +4, +4, +4, +5, +4, +4, +5, +5, +4, +5, +5, +4, +5, +5, +5, +5, +5, +5, +5, +6, +5, +5, +5, +6, +5, +6, +5, +6, +6, +5, +6, +6, +6, +5, +6, +6, +6, +6, +6, +6, +7, +6, +6, +6, +6, +7, +6, +6, +7, +6, +7, +6, +6, +7, +7, +6, +7, +6, +7, +6, +7, +7, +7, +6, +7, +7, +6, +7, +7, +7, +7, +6, +7, +7, +7, +7, +7, +6, +7, +7, +7, +7, +7, +7, +6, +7, +7, +7, +7, +7, +7, +6, +7, +7, +6, +7, +6, +7, +7, +7, +6, +7, +7, +6, +7, +7, +6, +7, +7, +6, +7, +6, +7, +6, +7, +6, +6, +7, +6, +6, +7, +6, +6, +6, +6, +6, +7, +6, +6, +6, +6, +5, +6, +6, +6, +6, +5, +6, +6, +5, +6, +5, +6, +5, +5, +6, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +5, +4, +5, +4, +5, +4, +5, +4, +4, +4, +5, +4, +4, +4, +4, +3, +4, +4, +4, +3, +4, +3, +4, +3, +3, +4, +3, +3, +3, +3, +3, +3, +2, +3, +3, +2, +3, +2, +3, +2, +2, +3, +2, +2, +2, +2, +2, +1, +2, +2, +1, +2, +1, +2, +1, +1, +1, +2, +1, +1, +0, +1, +1, +1, +0, +1, +0, +1, +0, +0, +1, +0, +0, +0, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-3, +-2, +-3, +-2, +-3, +-3, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-5, +-4, +-4, +-5, +-4, +-4, +-5, +-4, +-5, +-4, +-5, +-5, +-4, +-5, +-5, +-4, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-6, +-5, +-5, +-5, +-5, +-6, +-5, +-5, +-6, +-5, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-5, +-6, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-6, +-6, +-5, +-6, +-5, +-5, +-5, +-6, +-5, +-6, +-5, +-6, +-5, +-5, +-6, +-5, +-6, +-5, +-5, +-6, +-5, +-5, +-6, +-5, +-5, +-5, +-6, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-4, +-5, +-5, +-5, +-4, +-5, +-5, +-4, +-5, +-4, +-5, +-4, +-4, +-5, +-4, +-4, +-5, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-4, +-3, +-4, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-3, +-4, +-3, +-3, +-3, +-3, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-1, +-2, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +1, +0, +1, +0, +1, +1, +1, +0, +1, +1, +1, +1, +1, +2, +1, +1, +1, +2, +1, +2, +1, +2, +1, +2, +2, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +3, +2, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +4, +3, +3, +4, +3, +4, +3, +4, +3, +4, +3, +4, +4, +3, +4, +4, +4, +4, +3, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +4, +5, +4, +4, +4, +4, +5, +4, +4, +4, +5, +4, +4, +5, +4, +4, +5, +4, +5, +4, +4, +5, +4, +5, +4, +5, +4, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +4, +5, +3, +4, +5, +4, +5, +4, +4, +5, +4, +5, +4, +4, +5, +4, +4, +5, +4, +4, +4, +4, +5, +4, +4, +4, +4, +4, +5, +4, +4, +4, +4, +4, +4, +4, +3, +4, +4, +4, +4, +4, +3, +4, +4, +4, +3, +4, +4, +3, +4, +3, +4, +3, +3, +4, +3, +4, +3, +3, +3, +4, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +2, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +2, +2, +1, +2, +1, +2, +1, +1, +2, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-3, +-3, +-3, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-4, +-3, +-3, +-3, +-3, +-4, +-3, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-4, +-3, +-3, +-3, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-3, +-4, +-3, +-4, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-3, +-3, +-4, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-3, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +2, +1, +1, +1, +2, +1, +1, +2, +1, +1, +2, +1, +2, +1, +2, +1, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +3, +2, +2, +2, +3, +2, +2, +3, +2, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +3, +2, +3, +2, +3, +3, +2, +3, +3, +3, +2, +3, +3, +2, +3, +3, +3, +3, +2, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +2, +2, +3, +3, +3, +2, +3, +3, +3, +3, +2, +3, +3, +3, +2, +3, +3, +3, +2, +3, +3, +2, +3, +3, +2, +3, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +3, +2, +2, +3, +2, +2, +3, +2, +2, +3, +2, +2, +2, +2, +2, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +2, +2, +2, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-2, +-1, +-2, +-2, +-1, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-3, +-1, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-2, +-1, +-2, +-2, +-2, +-1, +-2, +-2, +-1, +-2, +-1, +-2, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +2, +1, +1, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +2, +1, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +2, +1, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +1, +2, +2, +2, +1, +2, +1, +2, +1, +2, +2, +1, +2, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +2, +1, +2, +1, +2, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +2, +1, +1, +2, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +1, +2, +1, +1, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +1, +0, +1, +1, +1, +0, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +0, +1, +1, +0, +1, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +0, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +1, +0, +0, +1, +0, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +1, +0, +0, +1, +0, +0, +1, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0}; diff --git a/third_party/resample/src/resample.c b/third_party/resample/src/resample.c new file mode 100644 index 00000000..73122704 --- /dev/null +++ b/third_party/resample/src/resample.c @@ -0,0 +1,238 @@ +/* + * FILE: resample.c + * Sampling-rate-conversion main program (command line usage) + */ + +static char resampleVersion[] + = "\n\tresample version 1.9 (Feb. 1, 2006 - jos@ccrma.stanford.edu)\n\n\ +Copyright 1982-2006 by Julius Smith.\n\ +This is free software. See the Lesser GNU Public License (LGPL) for copying conditions.\n\ +There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\ +PARTICULAR PURPOSE.\n\n\ +"; + +#define USAGE "\ +\n\ +USAGE: One of the following:\n\ +\n\ + resample -to srate [-noFilterInterp] [-linearSignalInterp] [-f filterFile] [-terse] inputSoundFile outputSoundFile\n\ + resample -by factor [options as above] inputSoundFile outputSoundFile\n\ + resample -version\n\ +\n\ +Options can be abbreviated.\n\n\ +Report bugs to <bug-resample@w3k.org>.\n\n\ +" + +#include "filterkit.h" +#include "resample.h" +#include "sndlibextra.h" + +#include <stdio.h> +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <errno.h> + +static int trace = 1; /* controls verbosity of output */ + +static char comment[256] = ""; + +static void fail(char *s) +{ + fprintf(stderr,"\n*** resample: %s \n",s); /* Display error message */ + fprintf(stderr,USAGE); + exit(1); /* Exit, indicating error */ +} + +static void fails(char *s, char *s2) +{ + printf("resample: "); /* Display error message */ + printf(s,s2); + printf("\n\n"); + exit(1); /* Exit, indicating error */ +} + + +int main(int argc, char *argv[]) +{ + double factor = -2.0; /* factor = Sndout/Sndin */ + double newsrate=0; + BOOL interpFilt = TRUE; /* TRUE means interpolate filter coeffs */ + BOOL largeFilter = FALSE; /* TRUE means use 65-tap FIR filter */ + BOOL linearInterp = FALSE; /* TRUE => no filter, linearly interpolate */ + BOOL knowFactor = FALSE; /* Used to detect insufficient command-line spec */ + int inCount, outCount, outCountReal; + int infd, outfd, insrate, nChans, result; + int inType, inFormat; + int outType, outFormat; + + struct stat statbuf; + char *insfname, *outsfname, *argv0; + char filterFile[512] = ""; + + if (argc == 1) { + fprintf(stderr, USAGE); + exit(1); + } + + argv0 = argv[0]; + while (--argc && **(++argv)=='-') { + ++(argv[0]); /* skip over '-' */ + switch (*argv[0]) { + case 'a': /* -aaaQuality (old name) */ + case 'e': /* -expensive */ + largeFilter = TRUE; + if (trace) + printf("Choosing higher quality filter.\n"); + break; + case 'b': /* -by factor */ + if (--argc) + sscanf(*(++argv),"%lf",&factor); + if (trace) + printf("Sampling-rate conversion factor set to %f.\n",factor); + knowFactor = TRUE; + break; + case 'f': /* -filter filterFile */ + if (--argc) + strcpy(filterFile, *++argv); + else + fail("Need to specify filter file name"); + if (trace) + printf("Filter file set to %s.\n",filterFile); + break; + case 'l': /* -linearInpterpolation */ + linearInterp = TRUE; + if (trace) + printf("Using linear instead of bandlimited interpolation\n"); + break; + case 'n': /* -noFilterInterpolation */ + interpFilt = FALSE; + if (trace) + printf("Filter-table interpolation disabled.\n"); + break; + case 't': + if (*(argv[0]+1) == 'e') { /* -terse */ + trace = 0; + break; + } + if (--argc) /* -to srate */ + sscanf(*(++argv),"%lf",&newsrate); + if (trace) + printf("Target sampling-rate set to %f.\n",newsrate); + knowFactor = TRUE; + break; + case 'v': /* -version */ + printf(resampleVersion); + if (argc == 1) + exit(0); + break; + default: + fprintf(stderr,"Unknown switch -%s\n",argv[0]); + fprintf(stderr,USAGE); + exit(1); + } + } + + if (!knowFactor) + fail("Must specify sampling-rate conversion factor via '-to' or '-by' option"); + + if (argc < 1) + fail("Need to specify input soundfile"); + insfname = *argv; + + if (argc < 2) { + fprintf(stderr, USAGE); + exit(1); + } + else + outsfname = *++argv; + + /* Test whether output file name exists. If so, bail... */ + result = stat(outsfname, &statbuf); + if (result != -1) + fails("\"%s\" already exists", outsfname); + if (errno != ENOENT) + fails("Error creating output file (%s)", strerror(errno)); + + if (trace) + printf("Writing output to \"%s\".\n", outsfname); + + /* Open input file and gather info from its header */ + // resample-1.8: infd = sndlib_open_read(insfname); + infd = mus_sound_open_input(insfname); + if (infd == -1) + fails("Could not open input file \"%s\"", insfname); + if (NOT_A_SOUND_FILE(mus_header_type())) + fails("\"%s\" is probably not a sound file.", insfname); + nChans = mus_header_chans(); + insrate = mus_header_srate(); + inCount = mus_header_samples(); + inType = mus_header_type(); /* header type (i.e. aiff, wave, etc) (see sndlib.h) */ + inFormat = mus_header_format(); /* data format (see sndlib.h) */ + inCount /= nChans; /* to get sample frames */ + +/* + * Set output soundfile format. + * See sndlib.h for supported types (e.g., MUS_RIFF). + */ + outType = inType; + outFormat = inFormat; + + /* Compute sampling rate conversion factor, if not specified. */ + if (newsrate>0) { + if (factor>0) + fprintf(stderr, "Command-line sampling-rate conversion factor " + "ignored ... the '-to' option overrides the '-by' option.\n"); + factor = newsrate / (double)insrate; + if (trace) + printf("Sampling rate conversion factor set to %f\n",factor); + } + + if (factor < 0) { + factor = -factor; + factor = GetDouble("Sampling-rate conversion factor",factor,""); + } + + if (newsrate <= 0) + newsrate = (int)((double)insrate * factor + 0.5); /* round */ + + sprintf(comment,"%s -by %f %s%s%s%s%s%s%s %s",argv0,factor, + (largeFilter?"-expensiveFilter ":""), + (strcmp(filterFile,"")==0?"":"-f "), + (strcmp(filterFile,"")==0?"":filterFile), + (strcmp(filterFile,"")==0?"":" "), + (linearInterp? "-linearSigInterp ":""), + (interpFilt? "":"-noFilterInterp "), + insfname, outsfname); + + outfd = sndlib_create(outsfname, inType, inFormat, newsrate, nChans, comment); + if (outfd == -1) + fails("Could not create output file \"%s\"", outsfname); + outCount = (int)(factor * (double)inCount + 0.5); /* output frames */ + + printf("\nStarting Conversion\n"); + outCountReal = resample(factor, infd, outfd, inCount, outCount, nChans, + interpFilt, linearInterp, largeFilter, filterFile); + + if (outCountReal <= 0) + fail("Conversion factor out of range"); + + if (trace && (outCount != outCountReal)) + fprintf(stderr, + "outCount = %d, outCountReal = %d\n",outCount,outCountReal); + + // resample-1.8: sndlib_close(infd, FALSE, 0, 0, 0); + mus_file_close(infd); + + /* Output samps already written; just update header and close file. */ + // resample-1.8: if (sndlib_close(outfd, 1, outType, outFormat, outCountReal * nChans)) + // resample-1.8: fails("Error closing output file (%s)", strerror(errno)); + mus_file_close(outfd); + int sound_bytes = outCountReal * nChans * mus_bytes_per_sample(outFormat); + mus_header_change_data_size(outsfname, inType, sound_bytes); + + printf("\nConversion Finished: %d output samples.\n\n",outCount); + + return(0); +} diff --git a/third_party/resample/src/resample.h b/third_party/resample/src/resample.h new file mode 100644 index 00000000..c09e891b --- /dev/null +++ b/third_party/resample/src/resample.h @@ -0,0 +1,86 @@ +/* + * FILE: resample.h + * + * The configuration constants below govern + * the number of bits in the input sample and filter coefficients, the + * number of bits to the right of the binary-point for fixed-point math, etc. + * + */ + +#include "stdefs.h" + +/* Conversion constants */ +#define Nhc 8 +#define Na 7 +#define Np (Nhc+Na) +#define Npc (1<<Nhc) +#define Amask ((1<<Na)-1) +#define Pmask ((1<<Np)-1) +#define Nh 16 +#define Nb 16 +#define Nhxn 14 +#define Nhg (Nh-Nhxn) +#define NLpScl 13 + +/* Description of constants: + * + * Npc - is the number of look-up values available for the lowpass filter + * between the beginning of its impulse response and the "cutoff time" + * of the filter. The cutoff time is defined as the reciprocal of the + * lowpass-filter cut off frequence in Hz. For example, if the + * lowpass filter were a sinc function, Npc would be the index of the + * impulse-response lookup-table corresponding to the first zero- + * crossing of the sinc function. (The inverse first zero-crossing + * time of a sinc function equals its nominal cutoff frequency in Hz.) + * Npc must be a power of 2 due to the details of the current + * implementation. The default value of 512 is sufficiently high that + * using linear interpolation to fill in between the table entries + * gives approximately 16-bit accuracy in filter coefficients. + * + * Nhc - is log base 2 of Npc. + * + * Na - is the number of bits devoted to linear interpolation of the + * filter coefficients. + * + * Np - is Na + Nhc, the number of bits to the right of the binary point + * in the integer "time" variable. To the left of the point, it indexes + * the input array (X), and to the right, it is interpreted as a number + * between 0 and 1 sample of the input X. Np must be less than 16 in + * this implementation. + * + * Nh - is the number of bits in the filter coefficients. The sum of Nh and + * the number of bits in the input data (typically 16) cannot exceed 32. + * Thus Nh should be 16. The largest filter coefficient should nearly + * fill 16 bits (32767). + * + * Nb - is the number of bits in the input data. The sum of Nb and Nh cannot + * exceed 32. + * + * Nhxn - is the number of bits to right shift after multiplying each input + * sample times a filter coefficient. It can be as great as Nh and as + * small as 0. Nhxn = Nh-2 gives 2 guard bits in the multiply-add + * accumulation. If Nhxn=0, the accumulation will soon overflow 32 bits. + * + * Nhg - is the number of guard bits in mpy-add accumulation (equal to Nh-Nhxn) + * + * NLpScl - is the number of bits allocated to the unity-gain normalization + * factor. The output of the lowpass filter is multiplied by LpScl and + * then right-shifted NLpScl bits. To avoid overflow, we must have + * Nb+Nhg+NLpScl < 32. + */ + + +int resample( /* number of output sample returned */ + double factor, /* factor = Sndout/Sndin */ + int infd, /* input and output file descriptors */ + int outfd, + int inCount, /* number of input samples to convert */ + int outCount, /* number of output samples to compute */ + int nChans, /* number of sound channels (1 or 2) */ + BOOL interpFilt, /* TRUE means interpolate filter coeffs */ + int fastMode, /* 0 = highest quality, slowest speed */ + BOOL largeFilter, /* TRUE means use 65-tap FIR filter */ + char *filterFile /* NULL for internal filter, else filename */ +); + +//#define MUS_SAMPLE_TYPE mus_sample_t; // more incompatible changes to sndlib diff --git a/third_party/resample/src/resamplesubs.c b/third_party/resample/src/resamplesubs.c new file mode 100644 index 00000000..920e56e6 --- /dev/null +++ b/third_party/resample/src/resamplesubs.c @@ -0,0 +1,520 @@ +/* resamplesubs.c - sampling rate conversion subroutines */ +// Altered version + +#include "resample.h" + +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <string.h> + +#define IBUFFSIZE 4096 /* Input buffer size */ + +#include "smallfilter.h" +#include "largefilter.h" + +#include "filterkit.h" +#include "sndlibextra.h" + +#ifdef WITH_PJ +#include "resamplesubs.h" + +unsigned resample_LARGE_FILTER_NMULT = LARGE_FILTER_NMULT; +unsigned resample_LARGE_FILTER_NWING = LARGE_FILTER_NWING; +unsigned resample_LARGE_FILTER_SCALE = LARGE_FILTER_SCALE; +short* resample_LARGE_FILTER_IMP = LARGE_FILTER_IMP; +short* resample_LARGE_FILTER_IMPD = LARGE_FILTER_IMPD; + +unsigned resample_SMALL_FILTER_NMULT = SMALL_FILTER_NMULT; +unsigned resample_SMALL_FILTER_NWING = SMALL_FILTER_NWING; +unsigned resample_SMALL_FILTER_SCALE = SMALL_FILTER_SCALE; +short* resample_SMALL_FILTER_IMP = SMALL_FILTER_IMP; +short* resample_SMALL_FILTER_IMPD = SMALL_FILTER_IMPD; +#endif + + +/* CAUTION: Assumes we call this for only one resample job per program run! */ +/* return: 0 - notDone */ +/* >0 - index of last sample */ +static int +readData(int infd, /* input file descriptor */ + int inCount, /* _total_ number of frames in input file */ + HWORD *outPtr1, /* array receiving left chan samps */ + HWORD *outPtr2, /* array receiving right chan samps */ + int dataArraySize, /* size of these arrays */ + int nChans, + int Xoff) /* read into input array starting at this index */ +{ + int i, Nsamps, nret; + static unsigned int framecount; /* frames previously read */ + static mus_sample_t **ibufs = NULL; + + if (ibufs == NULL) { /* first time called, so allocate it */ + ibufs = sndlib_allocate_buffers(nChans, dataArraySize); + if (ibufs == NULL) { + fprintf(stderr, "readData: Can't allocate input buffers!\n"); + exit(1); + } + framecount = 0; /* init this too */ + } + + Nsamps = dataArraySize - Xoff; /* Calculate number of samples to get */ + outPtr1 += Xoff; /* Start at designated sample number */ + outPtr2 += Xoff; + + nret = mus_file_read(infd, 0, Nsamps - 1, nChans, ibufs); + if (nret < 0) { + fprintf(stderr, "readData: Can't read data!\n"); + exit(1); + } + + /* NB: sndlib pads ibufs with zeros if it reads past EOF. */ + if (nChans == 1) { + for (i = 0; i < Nsamps; i++) + *outPtr1++ = MUS_SAMPLE_TYPE_TO_HWORD(ibufs[0][i]); + } + else { + for (i = 0; i < Nsamps; i++) { + *outPtr1++ = MUS_SAMPLE_TYPE_TO_HWORD(ibufs[0][i]); + *outPtr2++ = MUS_SAMPLE_TYPE_TO_HWORD(ibufs[1][i]); + } + } + + framecount += Nsamps; + + if (framecount >= (unsigned)inCount) /* return index of last samp */ + return (((Nsamps - (framecount - inCount)) - 1) + Xoff); + else + return 0; +} + + +#ifdef DEBUG +static int pof = 0; /* positive overflow count */ +static int nof = 0; /* negative overflow count */ +#endif + +static INLINE HWORD WordToHword(WORD v, int scl) +{ + HWORD out; + WORD llsb = (1<<(scl-1)); + v += llsb; /* round */ + v >>= scl; + if (v>MAX_HWORD) { +#ifdef DEBUG + if (pof == 0) + fprintf(stderr, "*** resample: sound sample overflow\n"); + else if ((pof % 10000) == 0) + fprintf(stderr, "*** resample: another ten thousand overflows\n"); + pof++; +#endif + v = MAX_HWORD; + } else if (v < MIN_HWORD) { +#ifdef DEBUG + if (nof == 0) + fprintf(stderr, "*** resample: sound sample (-) overflow\n"); + else if ((nof % 1000) == 0) + fprintf(stderr, "*** resample: another thousand (-) overflows\n"); + nof++; +#endif + v = MIN_HWORD; + } + out = (HWORD) v; + return out; +} + +/* Sampling rate conversion using linear interpolation for maximum speed. + */ +STATIC int + SrcLinear(HWORD X[], HWORD Y[], double factor, UWORD *Time, UHWORD Nx) +{ + HWORD iconst; + HWORD *Xp, *Ystart; + WORD v,x1,x2; + + double dt; /* Step through input signal */ + UWORD dtb; /* Fixed-point version of Dt */ + UWORD endTime; /* When Time reaches EndTime, return to user */ + + dt = 1.0/factor; /* Output sampling period */ + dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ + + Ystart = Y; + endTime = *Time + (1<<Np)*(WORD)Nx; + while (*Time < endTime) + { + iconst = (*Time) & Pmask; + Xp = &X[(*Time)>>Np]; /* Ptr to current input sample */ + x1 = *Xp++; + x2 = *Xp; + x1 *= ((1<<Np)-iconst); + x2 *= iconst; + v = x1 + x2; + *Y++ = WordToHword(v,Np); /* Deposit output */ + *Time += dtb; /* Move to next sample by time increment */ + } + return (Y - Ystart); /* Return number of output samples */ +} + +/* Sampling rate up-conversion only subroutine; + * Slightly faster than down-conversion; + */ +STATIC int SrcUp(HWORD X[], HWORD Y[], double factor, UWORD *Time, + UHWORD Nx, UHWORD Nwing, UHWORD LpScl, + HWORD Imp[], HWORD ImpD[], BOOL Interp) +{ + HWORD *Xp, *Ystart; + WORD v; + + double dt; /* Step through input signal */ + UWORD dtb; /* Fixed-point version of Dt */ + UWORD endTime; /* When Time reaches EndTime, return to user */ + + dt = 1.0/factor; /* Output sampling period */ + dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ + + Ystart = Y; + endTime = *Time + (1<<Np)*(WORD)Nx; + while (*Time < endTime) + { + Xp = &X[*Time>>Np]; /* Ptr to current input sample */ + /* Perform left-wing inner product */ + v = FilterUp(Imp, ImpD, Nwing, Interp, Xp, (HWORD)(*Time&Pmask),-1); + /* Perform right-wing inner product */ + v += FilterUp(Imp, ImpD, Nwing, Interp, Xp+1, + /* previous (triggers warning): (HWORD)((-*Time)&Pmask),1); */ + (HWORD)((((*Time)^Pmask)+1)&Pmask),1); + v >>= Nhg; /* Make guard bits */ + v *= LpScl; /* Normalize for unity filter gain */ + *Y++ = WordToHword(v,NLpScl); /* strip guard bits, deposit output */ + *Time += dtb; /* Move to next sample by time increment */ + } + return (Y - Ystart); /* Return the number of output samples */ +} + + +/* Sampling rate conversion subroutine */ + +STATIC int SrcUD(HWORD X[], HWORD Y[], double factor, UWORD *Time, + UHWORD Nx, UHWORD Nwing, UHWORD LpScl, + HWORD Imp[], HWORD ImpD[], BOOL Interp) +{ + HWORD *Xp, *Ystart; + WORD v; + + double dh; /* Step through filter impulse response */ + double dt; /* Step through input signal */ + UWORD endTime; /* When Time reaches EndTime, return to user */ + UWORD dhb, dtb; /* Fixed-point versions of Dh,Dt */ + + dt = 1.0/factor; /* Output sampling period */ + dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ + + dh = MIN(Npc, factor*Npc); /* Filter sampling period */ + dhb = dh*(1<<Na) + 0.5; /* Fixed-point representation */ + + Ystart = Y; + endTime = *Time + (1<<Np)*(WORD)Nx; + while (*Time < endTime) + { + Xp = &X[*Time>>Np]; /* Ptr to current input sample */ + v = FilterUD(Imp, ImpD, Nwing, Interp, Xp, (HWORD)(*Time&Pmask), + -1, dhb); /* Perform left-wing inner product */ + v += FilterUD(Imp, ImpD, Nwing, Interp, Xp+1, + /* previous (triggers warning): (HWORD)((-*Time)&Pmask), */ + (HWORD)((((*Time)^Pmask)+1)&Pmask), + 1, dhb); /* Perform right-wing inner product */ + v >>= Nhg; /* Make guard bits */ + v *= LpScl; /* Normalize for unity filter gain */ + *Y++ = WordToHword(v,NLpScl); /* strip guard bits, deposit output */ + *Time += dtb; /* Move to next sample by time increment */ + } + return (Y - Ystart); /* Return the number of output samples */ +} + +#ifndef WITH_PJ +static int err_ret(char *s) +{ + fprintf(stderr,"resample: %s \n\n",s); /* Display error message */ + return -1; +} + +static int resampleFast( /* number of output samples returned */ + double factor, /* factor = Sndout/Sndin */ + int infd, /* input and output file descriptors */ + int outfd, + int inCount, /* number of input samples to convert */ + int outCount, /* number of output samples to compute */ + int nChans) /* number of sound channels (1 or 2) */ +{ + UWORD Time, Time2; /* Current time/pos in input sample */ + UHWORD Xp, Ncreep, Xoff, Xread; + int OBUFFSIZE = (int)(((double)IBUFFSIZE)*factor+2.0); + HWORD X1[IBUFFSIZE], Y1[2]; /* I/O buffers */ + HWORD X2[IBUFFSIZE], Y2[OBUFFSIZE]; /* I/O buffers */ + UHWORD Nout, Nx; + int i, Ycount, last; + + mus_sample_t **obufs = sndlib_allocate_buffers(nChans, OBUFFSIZE); + if (obufs == NULL) + return err_ret("Can't allocate output buffers"); + + Xoff = 10; + + Nx = IBUFFSIZE - 2*Xoff; /* # of samples to process each iteration */ + last = 0; /* Have not read last input sample yet */ + Ycount = 0; /* Current sample and length of output file */ + + Xp = Xoff; /* Current "now"-sample pointer for input */ + Xread = Xoff; /* Position in input array to read into */ + Time = (Xoff<<Np); /* Current-time pointer for converter */ + + for (i=0; i<Xoff; X1[i++]=0); /* Need Xoff zeros at begining of sample */ + for (i=0; i<Xoff; X2[i++]=0); /* Need Xoff zeros at begining of sample */ + + do { + if (!last) /* If haven't read last sample yet */ + { + last = readData(infd, inCount, X1, X2, IBUFFSIZE, + nChans, (int)Xread); + if (last && (last-Xoff<Nx)) { /* If last sample has been read... */ + Nx = last-Xoff; /* ...calc last sample affected by filter */ + if (Nx <= 0) + break; + } + } + + /* Resample stuff in input buffer */ + Time2 = Time; + Nout=SrcLinear(X1,Y1,factor,&Time,Nx); + if (nChans==2) + Nout=SrcLinear(X2,Y2,factor,&Time2,Nx); + + Time -= (Nx<<Np); /* Move converter Nx samples back in time */ + Xp += Nx; /* Advance by number of samples processed */ + Ncreep = (Time>>Np) - Xoff; /* Calc time accumulation in Time */ + if (Ncreep) { + Time -= (Ncreep<<Np); /* Remove time accumulation */ + Xp += Ncreep; /* and add it to read pointer */ + } + for (i=0; i<IBUFFSIZE-Xp+Xoff; i++) { /* Copy part of input signal */ + X1[i] = X1[i+Xp-Xoff]; /* that must be re-used */ + if (nChans==2) + X2[i] = X2[i+Xp-Xoff]; /* that must be re-used */ + } + if (last) { /* If near end of sample... */ + last -= Xp; /* ...keep track were it ends */ + if (!last) /* Lengthen input by 1 sample if... */ + last++; /* ...needed to keep flag TRUE */ + } + Xread = i; /* Pos in input buff to read new data into */ + Xp = Xoff; + + Ycount += Nout; + if (Ycount>outCount) { + Nout -= (Ycount-outCount); + Ycount = outCount; + } + + if (Nout > OBUFFSIZE) /* Check to see if output buff overflowed */ + return err_ret("Output array overflow"); + + if (nChans==1) { + for (i = 0; i < Nout; i++) + obufs[0][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y1[i]); + } else { + for (i = 0; i < Nout; i++) { + obufs[0][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y1[i]); + obufs[1][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y2[i]); + } + } + /* NB: errors reported within sndlib */ + mus_file_write(outfd, 0, Nout - 1, nChans, obufs); + + printf("."); fflush(stdout); + + } while (Ycount<outCount); /* Continue until done */ + + return(Ycount); /* Return # of samples in output file */ +} + + +static int resampleWithFilter( /* number of output samples returned */ + double factor, /* factor = outSampleRate/inSampleRate */ + int infd, /* input and output file descriptors */ + int outfd, + int inCount, /* number of input samples to convert */ + int outCount, /* number of output samples to compute */ + int nChans, /* number of sound channels (1 or 2) */ + BOOL interpFilt, /* TRUE means interpolate filter coeffs */ + HWORD Imp[], HWORD ImpD[], + UHWORD LpScl, UHWORD Nmult, UHWORD Nwing) +{ + UWORD Time, Time2; /* Current time/pos in input sample */ + UHWORD Xp, Ncreep, Xoff, Xread; + int OBUFFSIZE = (int)(((double)IBUFFSIZE)*factor+2.0); + HWORD X1[IBUFFSIZE], Y1[OBUFFSIZE]; /* I/O buffers */ + HWORD X2[IBUFFSIZE], Y2[OBUFFSIZE]; /* I/O buffers */ + UHWORD Nout, Nx; + int i, Ycount, last; + + mus_sample_t **obufs = sndlib_allocate_buffers(nChans, OBUFFSIZE); + if (obufs == NULL) + return err_ret("Can't allocate output buffers"); + + /* Account for increased filter gain when using factors less than 1 */ + if (factor < 1) + LpScl = LpScl*factor + 0.5; + + /* Calc reach of LP filter wing & give some creeping room */ + Xoff = ((Nmult+1)/2.0) * MAX(1.0,1.0/factor) + 10; + + if (IBUFFSIZE < 2*Xoff) /* Check input buffer size */ + return err_ret("IBUFFSIZE (or factor) is too small"); + + Nx = IBUFFSIZE - 2*Xoff; /* # of samples to process each iteration */ + + last = 0; /* Have not read last input sample yet */ + Ycount = 0; /* Current sample and length of output file */ + Xp = Xoff; /* Current "now"-sample pointer for input */ + Xread = Xoff; /* Position in input array to read into */ + Time = (Xoff<<Np); /* Current-time pointer for converter */ + + for (i=0; i<Xoff; X1[i++]=0); /* Need Xoff zeros at begining of sample */ + for (i=0; i<Xoff; X2[i++]=0); /* Need Xoff zeros at begining of sample */ + + do { + if (!last) /* If haven't read last sample yet */ + { + last = readData(infd, inCount, X1, X2, IBUFFSIZE, + nChans, (int)Xread); + if (last && (last-Xoff<Nx)) { /* If last sample has been read... */ + Nx = last-Xoff; /* ...calc last sample affected by filter */ + if (Nx <= 0) + break; + } + } + /* Resample stuff in input buffer */ + Time2 = Time; + if (factor >= 1) { /* SrcUp() is faster if we can use it */ + Nout=SrcUp(X1,Y1,factor,&Time,Nx,Nwing,LpScl,Imp,ImpD,interpFilt); + if (nChans==2) + Nout=SrcUp(X2,Y2,factor,&Time2,Nx,Nwing,LpScl,Imp,ImpD, + interpFilt); + } + else { + Nout=SrcUD(X1,Y1,factor,&Time,Nx,Nwing,LpScl,Imp,ImpD,interpFilt); + if (nChans==2) + Nout=SrcUD(X2,Y2,factor,&Time2,Nx,Nwing,LpScl,Imp,ImpD, + interpFilt); + } + + Time -= (Nx<<Np); /* Move converter Nx samples back in time */ + Xp += Nx; /* Advance by number of samples processed */ + Ncreep = (Time>>Np) - Xoff; /* Calc time accumulation in Time */ + if (Ncreep) { + Time -= (Ncreep<<Np); /* Remove time accumulation */ + Xp += Ncreep; /* and add it to read pointer */ + } + for (i=0; i<IBUFFSIZE-Xp+Xoff; i++) { /* Copy part of input signal */ + X1[i] = X1[i+Xp-Xoff]; /* that must be re-used */ + if (nChans==2) + X2[i] = X2[i+Xp-Xoff]; /* that must be re-used */ + } + if (last) { /* If near end of sample... */ + last -= Xp; /* ...keep track were it ends */ + if (!last) /* Lengthen input by 1 sample if... */ + last++; /* ...needed to keep flag TRUE */ + } + Xread = i; /* Pos in input buff to read new data into */ + Xp = Xoff; + + Ycount += Nout; + if (Ycount>outCount) { + Nout -= (Ycount-outCount); + Ycount = outCount; + } + + if (Nout > OBUFFSIZE) /* Check to see if output buff overflowed */ + return err_ret("Output array overflow"); + + if (nChans==1) { + for (i = 0; i < Nout; i++) + obufs[0][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y1[i]); + } else { + for (i = 0; i < Nout; i++) { + obufs[0][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y1[i]); + obufs[1][i] = HWORD_TO_MUS_SAMPLE_TYPE(Y2[i]); + } + } + /* NB: errors reported within sndlib */ + mus_file_write(outfd, 0, Nout - 1, nChans, obufs); + + printf("."); fflush(stdout); + + } while (Ycount<outCount); /* Continue until done */ + + return(Ycount); /* Return # of samples in output file */ +} + + +int resample( /* number of output samples returned */ + double factor, /* factor = Sndout/Sndin */ + int infd, /* input and output file descriptors */ + int outfd, + int inCount, /* number of input samples to convert */ + int outCount, /* number of output samples to compute */ + int nChans, /* number of sound channels (1 or 2) */ + BOOL interpFilt, /* TRUE means interpolate filter coeffs */ + int fastMode, /* 0 = highest quality, slowest speed */ + BOOL largeFilter, /* TRUE means use 65-tap FIR filter */ + char *filterFile) /* NULL for internal filter, else filename */ +{ + UHWORD LpScl; /* Unity-gain scale factor */ + UHWORD Nwing; /* Filter table size */ + UHWORD Nmult; /* Filter length for up-conversions */ + HWORD *Imp=0; /* Filter coefficients */ + HWORD *ImpD=0; /* ImpD[n] = Imp[n+1]-Imp[n] */ + + if (fastMode) + return resampleFast(factor,infd,outfd,inCount,outCount,nChans); + +#ifdef DEBUG + /* Check for illegal constants */ + if (Np >= 16) + return err_ret("Error: Np>=16"); + if (Nb+Nhg+NLpScl >= 32) + return err_ret("Error: Nb+Nhg+NLpScl>=32"); + if (Nh+Nb > 32) + return err_ret("Error: Nh+Nb>32"); +#endif + + /* Set defaults */ + + if (filterFile != NULL && *filterFile != '\0') { + if (readFilter(filterFile, &Imp, &ImpD, &LpScl, &Nmult, &Nwing)) + return err_ret("could not find filter file, " + "or syntax error in contents of filter file"); + } else if (largeFilter) { + Nmult = LARGE_FILTER_NMULT; + Imp = LARGE_FILTER_IMP; /* Impulse response */ + ImpD = LARGE_FILTER_IMPD; /* Impulse response deltas */ + LpScl = LARGE_FILTER_SCALE; /* Unity-gain scale factor */ + Nwing = LARGE_FILTER_NWING; /* Filter table length */ + } else { + Nmult = SMALL_FILTER_NMULT; + Imp = SMALL_FILTER_IMP; /* Impulse response */ + ImpD = SMALL_FILTER_IMPD; /* Impulse response deltas */ + LpScl = SMALL_FILTER_SCALE; /* Unity-gain scale factor */ + Nwing = SMALL_FILTER_NWING; /* Filter table length */ + } +#if DEBUG + fprintf(stderr,"Attenuating resampler scale factor by 0.95 " + "to reduce probability of clipping\n"); +#endif + LpScl *= 0.95; + return resampleWithFilter(factor,infd,outfd,inCount,outCount,nChans, + interpFilt, Imp, ImpD, LpScl, Nmult, Nwing); +} +#endif /* WITH_PJ */ + diff --git a/third_party/resample/src/smallfilter.h b/third_party/resample/src/smallfilter.h new file mode 100644 index 00000000..6f6f0f84 --- /dev/null +++ b/third_party/resample/src/smallfilter.h @@ -0,0 +1,4617 @@ +/* Included by resamplesubs.c */ +#define SMALL_FILTER_NMULT ((HWORD)13) +#define SMALL_FILTER_SCALE 13128 /* Unity-gain scale factor */ +#define SMALL_FILTER_NWING 1536 /* Filter table length */ +static HWORD SMALL_FILTER_IMP[] /* Impulse response */ = { +32767, +32766, +32764, +32760, +32755, +32749, +32741, +32731, +32721, +32708, +32695, +32679, +32663, +32645, +32625, +32604, +32582, +32558, +32533, +32506, +32478, +32448, +32417, +32385, +32351, +32316, +32279, +32241, +32202, +32161, +32119, +32075, +32030, +31984, +31936, +31887, +31836, +31784, +31731, +31676, +31620, +31563, +31504, +31444, +31383, +31320, +31256, +31191, +31124, +31056, +30987, +30916, +30845, +30771, +30697, +30621, +30544, +30466, +30387, +30306, +30224, +30141, +30057, +29971, +29884, +29796, +29707, +29617, +29525, +29433, +29339, +29244, +29148, +29050, +28952, +28852, +28752, +28650, +28547, +28443, +28338, +28232, +28125, +28017, +27908, +27797, +27686, +27574, +27461, +27346, +27231, +27115, +26998, +26879, +26760, +26640, +26519, +26398, +26275, +26151, +26027, +25901, +25775, +25648, +25520, +25391, +25262, +25131, +25000, +24868, +24735, +24602, +24467, +24332, +24197, +24060, +23923, +23785, +23647, +23507, +23368, +23227, +23086, +22944, +22802, +22659, +22515, +22371, +22226, +22081, +21935, +21789, +21642, +21494, +21346, +21198, +21049, +20900, +20750, +20600, +20449, +20298, +20146, +19995, +19842, +19690, +19537, +19383, +19230, +19076, +18922, +18767, +18612, +18457, +18302, +18146, +17990, +17834, +17678, +17521, +17365, +17208, +17051, +16894, +16737, +16579, +16422, +16264, +16106, +15949, +15791, +15633, +15475, +15317, +15159, +15001, +14843, +14685, +14527, +14369, +14212, +14054, +13896, +13739, +13581, +13424, +13266, +13109, +12952, +12795, +12639, +12482, +12326, +12170, +12014, +11858, +11703, +11548, +11393, +11238, +11084, +10929, +10776, +10622, +10469, +10316, +10164, +10011, +9860, +9708, +9557, +9407, +9256, +9106, +8957, +8808, +8659, +8511, +8364, +8216, +8070, +7924, +7778, +7633, +7488, +7344, +7200, +7057, +6914, +6773, +6631, +6490, +6350, +6210, +6071, +5933, +5795, +5658, +5521, +5385, +5250, +5115, +4981, +4848, +4716, +4584, +4452, +4322, +4192, +4063, +3935, +3807, +3680, +3554, +3429, +3304, +3180, +3057, +2935, +2813, +2692, +2572, +2453, +2335, +2217, +2101, +1985, +1870, +1755, +1642, +1529, +1418, +1307, +1197, +1088, +979, +872, +765, +660, +555, +451, +348, +246, +145, +44, +-54, +-153, +-250, +-347, +-443, +-537, +-631, +-724, +-816, +-908, +-998, +-1087, +-1175, +-1263, +-1349, +-1435, +-1519, +-1603, +-1685, +-1767, +-1848, +-1928, +-2006, +-2084, +-2161, +-2237, +-2312, +-2386, +-2459, +-2531, +-2603, +-2673, +-2742, +-2810, +-2878, +-2944, +-3009, +-3074, +-3137, +-3200, +-3261, +-3322, +-3381, +-3440, +-3498, +-3554, +-3610, +-3665, +-3719, +-3772, +-3824, +-3875, +-3925, +-3974, +-4022, +-4069, +-4116, +-4161, +-4205, +-4249, +-4291, +-4333, +-4374, +-4413, +-4452, +-4490, +-4527, +-4563, +-4599, +-4633, +-4666, +-4699, +-4730, +-4761, +-4791, +-4820, +-4848, +-4875, +-4901, +-4926, +-4951, +-4974, +-4997, +-5019, +-5040, +-5060, +-5080, +-5098, +-5116, +-5133, +-5149, +-5164, +-5178, +-5192, +-5205, +-5217, +-5228, +-5238, +-5248, +-5257, +-5265, +-5272, +-5278, +-5284, +-5289, +-5293, +-5297, +-5299, +-5301, +-5303, +-5303, +-5303, +-5302, +-5300, +-5298, +-5295, +-5291, +-5287, +-5282, +-5276, +-5270, +-5263, +-5255, +-5246, +-5237, +-5228, +-5217, +-5206, +-5195, +-5183, +-5170, +-5157, +-5143, +-5128, +-5113, +-5097, +-5081, +-5064, +-5047, +-5029, +-5010, +-4991, +-4972, +-4952, +-4931, +-4910, +-4889, +-4867, +-4844, +-4821, +-4797, +-4774, +-4749, +-4724, +-4699, +-4673, +-4647, +-4620, +-4593, +-4566, +-4538, +-4510, +-4481, +-4452, +-4422, +-4393, +-4363, +-4332, +-4301, +-4270, +-4238, +-4206, +-4174, +-4142, +-4109, +-4076, +-4042, +-4009, +-3975, +-3940, +-3906, +-3871, +-3836, +-3801, +-3765, +-3729, +-3693, +-3657, +-3620, +-3584, +-3547, +-3510, +-3472, +-3435, +-3397, +-3360, +-3322, +-3283, +-3245, +-3207, +-3168, +-3129, +-3091, +-3052, +-3013, +-2973, +-2934, +-2895, +-2855, +-2816, +-2776, +-2736, +-2697, +-2657, +-2617, +-2577, +-2537, +-2497, +-2457, +-2417, +-2377, +-2337, +-2297, +-2256, +-2216, +-2176, +-2136, +-2096, +-2056, +-2016, +-1976, +-1936, +-1896, +-1856, +-1817, +-1777, +-1737, +-1698, +-1658, +-1619, +-1579, +-1540, +-1501, +-1462, +-1423, +-1384, +-1345, +-1306, +-1268, +-1230, +-1191, +-1153, +-1115, +-1077, +-1040, +-1002, +-965, +-927, +-890, +-854, +-817, +-780, +-744, +-708, +-672, +-636, +-600, +-565, +-530, +-494, +-460, +-425, +-391, +-356, +-322, +-289, +-255, +-222, +-189, +-156, +-123, +-91, +-59, +-27, +4, +35, +66, +97, +127, +158, +188, +218, +247, +277, +306, +334, +363, +391, +419, +447, +474, +501, +528, +554, +581, +606, +632, +657, +683, +707, +732, +756, +780, +803, +827, +850, +872, +895, +917, +939, +960, +981, +1002, +1023, +1043, +1063, +1082, +1102, +1121, +1139, +1158, +1176, +1194, +1211, +1228, +1245, +1262, +1278, +1294, +1309, +1325, +1340, +1354, +1369, +1383, +1397, +1410, +1423, +1436, +1448, +1461, +1473, +1484, +1496, +1507, +1517, +1528, +1538, +1548, +1557, +1566, +1575, +1584, +1592, +1600, +1608, +1616, +1623, +1630, +1636, +1643, +1649, +1654, +1660, +1665, +1670, +1675, +1679, +1683, +1687, +1690, +1694, +1697, +1700, +1702, +1704, +1706, +1708, +1709, +1711, +1712, +1712, +1713, +1713, +1713, +1713, +1712, +1711, +1710, +1709, +1708, +1706, +1704, +1702, +1700, +1697, +1694, +1691, +1688, +1685, +1681, +1677, +1673, +1669, +1664, +1660, +1655, +1650, +1644, +1639, +1633, +1627, +1621, +1615, +1609, +1602, +1596, +1589, +1582, +1575, +1567, +1560, +1552, +1544, +1536, +1528, +1520, +1511, +1503, +1494, +1485, +1476, +1467, +1458, +1448, +1439, +1429, +1419, +1409, +1399, +1389, +1379, +1368, +1358, +1347, +1337, +1326, +1315, +1304, +1293, +1282, +1271, +1260, +1248, +1237, +1225, +1213, +1202, +1190, +1178, +1166, +1154, +1142, +1130, +1118, +1106, +1094, +1081, +1069, +1057, +1044, +1032, +1019, +1007, +994, +981, +969, +956, +943, +931, +918, +905, +892, +879, +867, +854, +841, +828, +815, +802, +790, +777, +764, +751, +738, +725, +713, +700, +687, +674, +662, +649, +636, +623, +611, +598, +585, +573, +560, +548, +535, +523, +510, +498, +486, +473, +461, +449, +437, +425, +413, +401, +389, +377, +365, +353, +341, +330, +318, +307, +295, +284, +272, +261, +250, +239, +228, +217, +206, +195, +184, +173, +163, +152, +141, +131, +121, +110, +100, +90, +80, +70, +60, +51, +41, +31, +22, +12, +3, +-5, +-14, +-23, +-32, +-41, +-50, +-59, +-67, +-76, +-84, +-93, +-101, +-109, +-117, +-125, +-133, +-140, +-148, +-156, +-163, +-170, +-178, +-185, +-192, +-199, +-206, +-212, +-219, +-226, +-232, +-239, +-245, +-251, +-257, +-263, +-269, +-275, +-280, +-286, +-291, +-297, +-302, +-307, +-312, +-317, +-322, +-327, +-332, +-336, +-341, +-345, +-349, +-354, +-358, +-362, +-366, +-369, +-373, +-377, +-380, +-384, +-387, +-390, +-394, +-397, +-400, +-402, +-405, +-408, +-411, +-413, +-416, +-418, +-420, +-422, +-424, +-426, +-428, +-430, +-432, +-433, +-435, +-436, +-438, +-439, +-440, +-442, +-443, +-444, +-445, +-445, +-446, +-447, +-447, +-448, +-448, +-449, +-449, +-449, +-449, +-449, +-449, +-449, +-449, +-449, +-449, +-449, +-448, +-448, +-447, +-447, +-446, +-445, +-444, +-443, +-443, +-442, +-441, +-440, +-438, +-437, +-436, +-435, +-433, +-432, +-430, +-429, +-427, +-426, +-424, +-422, +-420, +-419, +-417, +-415, +-413, +-411, +-409, +-407, +-405, +-403, +-400, +-398, +-396, +-393, +-391, +-389, +-386, +-384, +-381, +-379, +-376, +-374, +-371, +-368, +-366, +-363, +-360, +-357, +-355, +-352, +-349, +-346, +-343, +-340, +-337, +-334, +-331, +-328, +-325, +-322, +-319, +-316, +-313, +-310, +-307, +-304, +-301, +-298, +-294, +-291, +-288, +-285, +-282, +-278, +-275, +-272, +-269, +-265, +-262, +-259, +-256, +-252, +-249, +-246, +-243, +-239, +-236, +-233, +-230, +-226, +-223, +-220, +-217, +-213, +-210, +-207, +-204, +-200, +-197, +-194, +-191, +-187, +-184, +-181, +-178, +-175, +-172, +-168, +-165, +-162, +-159, +-156, +-153, +-150, +-147, +-143, +-140, +-137, +-134, +-131, +-128, +-125, +-122, +-120, +-117, +-114, +-111, +-108, +-105, +-102, +-99, +-97, +-94, +-91, +-88, +-86, +-83, +-80, +-78, +-75, +-72, +-70, +-67, +-65, +-62, +-59, +-57, +-55, +-52, +-50, +-47, +-45, +-43, +-40, +-38, +-36, +-33, +-31, +-29, +-27, +-25, +-22, +-20, +-18, +-16, +-14, +-12, +-10, +-8, +-6, +-4, +-2, +0, +0, +2, +4, +6, +8, +9, +11, +13, +14, +16, +17, +19, +21, +22, +24, +25, +27, +28, +29, +31, +32, +33, +35, +36, +37, +38, +40, +41, +42, +43, +44, +45, +46, +47, +48, +49, +50, +51, +52, +53, +54, +55, +56, +56, +57, +58, +59, +59, +60, +61, +62, +62, +63, +63, +64, +64, +65, +66, +66, +66, +67, +67, +68, +68, +69, +69, +69, +70, +70, +70, +70, +71, +71, +71, +71, +71, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +72, +71, +71, +71, +71, +71, +70, +70, +70, +70, +69, +69, +69, +69, +68, +68, +68, +67, +67, +67, +66, +66, +66, +65, +65, +64, +64, +64, +63, +63, +62, +62, +62, +61, +61, +60, +60, +59, +59, +58, +58, +58, +57, +57, +56, +56, +55, +55, +54, +54, +53, +53, +52, +52, +51, +51, +50, +50, +49, +48, +48, +47, +47, +46, +46, +45, +45, +44, +44, +43, +43, +42, +42, +41, +41, +40, +39, +39, +38, +38, +37, +37, +36, +36, +35, +35, +34, +34, +33, +33, +32, +32, +31, +31, +30, +30, +29, +29, +28, +28, +27, +27, +26, +26, +25, +25, +24, +24, +23, +23, +23, +22, +22, +21, +21, +20, +20, +20, +19, +19, +18, +18, +17, +17, +17, +16, +16, +15, +15, +15, +14, +14, +14, +13, +13, +12, +12, +12, +11, +11, +11, +10, +10, +10, +9, +9, +9, +9, +8, +8, +8, +7, +7, +7, +7, +6, +6, +6, +6, +5, +5, +5, +5, +4, +4, +4, +4, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +1, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1 +}; + +static HWORD SMALL_FILTER_IMPD[] = { +-1, +-2, +-4, +-5, +-6, +-8, +-10, +-10, +-13, +-13, +-16, +-16, +-18, +-20, +-21, +-22, +-24, +-25, +-27, +-28, +-30, +-31, +-32, +-34, +-35, +-37, +-38, +-39, +-41, +-42, +-44, +-45, +-46, +-48, +-49, +-51, +-52, +-53, +-55, +-56, +-57, +-59, +-60, +-61, +-63, +-64, +-65, +-67, +-68, +-69, +-71, +-71, +-74, +-74, +-76, +-77, +-78, +-79, +-81, +-82, +-83, +-84, +-86, +-87, +-88, +-89, +-90, +-92, +-92, +-94, +-95, +-96, +-98, +-98, +-100, +-100, +-102, +-103, +-104, +-105, +-106, +-107, +-108, +-109, +-111, +-111, +-112, +-113, +-115, +-115, +-116, +-117, +-119, +-119, +-120, +-121, +-121, +-123, +-124, +-124, +-126, +-126, +-127, +-128, +-129, +-129, +-131, +-131, +-132, +-133, +-133, +-135, +-135, +-135, +-137, +-137, +-138, +-138, +-140, +-139, +-141, +-141, +-142, +-142, +-143, +-144, +-144, +-145, +-145, +-146, +-146, +-147, +-148, +-148, +-148, +-149, +-149, +-150, +-150, +-151, +-151, +-152, +-151, +-153, +-152, +-153, +-154, +-153, +-154, +-154, +-155, +-155, +-155, +-155, +-156, +-156, +-156, +-156, +-157, +-156, +-157, +-157, +-157, +-157, +-158, +-157, +-158, +-158, +-157, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-157, +-158, +-158, +-157, +-158, +-157, +-158, +-157, +-157, +-157, +-156, +-157, +-156, +-156, +-156, +-156, +-155, +-155, +-155, +-155, +-154, +-155, +-153, +-154, +-153, +-153, +-152, +-153, +-151, +-152, +-151, +-150, +-151, +-150, +-149, +-149, +-149, +-148, +-147, +-148, +-146, +-146, +-146, +-145, +-145, +-144, +-144, +-143, +-143, +-141, +-142, +-141, +-140, +-140, +-139, +-138, +-138, +-137, +-137, +-136, +-135, +-135, +-134, +-133, +-132, +-132, +-132, +-130, +-130, +-129, +-128, +-128, +-127, +-126, +-125, +-125, +-124, +-123, +-122, +-122, +-121, +-120, +-119, +-118, +-118, +-116, +-116, +-115, +-115, +-113, +-113, +-111, +-111, +-110, +-109, +-109, +-107, +-107, +-105, +-105, +-104, +-103, +-102, +-101, +-101, +-98, +-99, +-97, +-97, +-96, +-94, +-94, +-93, +-92, +-92, +-90, +-89, +-88, +-88, +-86, +-86, +-84, +-84, +-82, +-82, +-81, +-80, +-78, +-78, +-77, +-76, +-75, +-74, +-73, +-72, +-72, +-70, +-69, +-68, +-68, +-66, +-65, +-65, +-63, +-63, +-61, +-61, +-59, +-59, +-58, +-56, +-56, +-55, +-54, +-53, +-52, +-51, +-50, +-49, +-48, +-47, +-47, +-45, +-44, +-44, +-42, +-42, +-41, +-39, +-39, +-38, +-37, +-36, +-36, +-34, +-33, +-33, +-31, +-31, +-30, +-29, +-28, +-27, +-26, +-25, +-25, +-23, +-23, +-22, +-21, +-20, +-20, +-18, +-18, +-17, +-16, +-15, +-14, +-14, +-13, +-12, +-11, +-10, +-10, +-9, +-8, +-7, +-6, +-6, +-5, +-4, +-4, +-2, +-2, +-2, +0, +0, +1, +2, +2, +3, +4, +4, +5, +6, +6, +7, +8, +9, +9, +9, +11, +11, +11, +12, +13, +13, +14, +15, +15, +16, +16, +17, +17, +18, +19, +19, +19, +20, +21, +21, +21, +22, +23, +23, +24, +23, +25, +25, +25, +26, +26, +27, +27, +27, +28, +28, +29, +29, +30, +29, +30, +31, +31, +31, +32, +32, +32, +32, +33, +33, +34, +33, +34, +35, +34, +35, +35, +35, +36, +36, +36, +36, +37, +36, +37, +37, +38, +37, +38, +37, +38, +39, +38, +38, +39, +39, +38, +39, +39, +40, +39, +39, +40, +39, +40, +40, +39, +40, +40, +40, +40, +40, +40, +40, +40, +40, +40, +41, +40, +40, +40, +40, +40, +40, +40, +40, +40, +40, +39, +40, +40, +39, +40, +39, +40, +39, +39, +39, +39, +39, +39, +39, +38, +38, +39, +38, +38, +38, +37, +38, +37, +38, +37, +36, +37, +37, +36, +36, +36, +36, +36, +35, +35, +36, +34, +35, +34, +35, +34, +33, +34, +33, +33, +33, +33, +32, +32, +32, +31, +31, +31, +31, +30, +31, +30, +30, +29, +30, +29, +28, +29, +28, +28, +28, +27, +27, +27, +26, +27, +25, +26, +25, +26, +24, +25, +24, +24, +23, +24, +23, +22, +23, +22, +22, +21, +21, +21, +21, +20, +20, +19, +20, +19, +18, +19, +18, +18, +17, +17, +17, +17, +16, +16, +15, +16, +15, +14, +15, +14, +14, +13, +13, +13, +12, +13, +12, +11, +12, +11, +10, +11, +10, +10, +9, +9, +9, +9, +8, +8, +8, +8, +7, +7, +6, +7, +6, +5, +6, +5, +5, +5, +4, +4, +4, +3, +4, +3, +3, +2, +2, +2, +2, +1, +2, +1, +0, +1, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-3, +-3, +-3, +-3, +-3, +-4, +-4, +-4, +-4, +-5, +-4, +-5, +-5, +-6, +-5, +-6, +-6, +-6, +-6, +-6, +-7, +-6, +-7, +-7, +-7, +-8, +-7, +-8, +-8, +-8, +-8, +-8, +-9, +-8, +-9, +-9, +-9, +-9, +-9, +-10, +-9, +-10, +-10, +-10, +-10, +-10, +-10, +-11, +-10, +-11, +-10, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-12, +-11, +-12, +-12, +-11, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-13, +-12, +-12, +-13, +-12, +-13, +-12, +-13, +-13, +-12, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-12, +-13, +-13, +-12, +-13, +-12, +-13, +-12, +-13, +-12, +-12, +-13, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-11, +-12, +-11, +-12, +-11, +-12, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-10, +-11, +-11, +-10, +-10, +-11, +-10, +-10, +-10, +-10, +-10, +-9, +-10, +-10, +-9, +-10, +-9, +-8, +-9, +-9, +-9, +-9, +-9, +-9, +-8, +-9, +-8, +-9, +-8, +-8, +-8, +-8, +-8, +-7, +-8, +-8, +-7, +-7, +-8, +-7, +-7, +-7, +-7, +-6, +-7, +-7, +-6, +-7, +-6, +-6, +-6, +-6, +-6, +-6, +-5, +-6, +-5, +-6, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-4, +-5, +-4, +-4, +-5, +-4, +-4, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +2, +1, +1, +1, +2, +1, +2, +1, +2, +1, +2, +2, +2, +1, +2, +2, +2, +2, +2, +2, +2, +2, +3, +2, +2, +3, +2, +2, +3, +2, +3, +2, +3, +2, +3, +3, +2, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +2, +3, +3, +2, +3, +3, +2, +3, +2, +3, +3, +2, +2, +3, +2, +3, +2, +2, +3, +2, +2, +3, +2, +2, +2, +2, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +0, +2, +2, +2, +2, +1, +2, +2, +1, +2, +1, +2, +2, +1, +2, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +0, +1, +0, +1, +0, +1, +1, +0, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +-1, +-2, +-4, +-5, +-6, +-8, +-10, +-10, +-13, +-13, +-16, +-16, +-18, +-20, +-21, +-22, +-24, +-25, +-27, +-28, +-30, +-31, +-32, +-34, +-35, +-37, +-38, +-39, +-41, +-42, +-44, +-45, +-46, +-48, +-49, +-51, +-52, +-53, +-55, +-56, +-57, +-59, +-60, +-61, +-63, +-64, +-65, +-67, +-68, +-69, +-71, +-71, +-74, +-74, +-76, +-77, +-78, +-79, +-81, +-82, +-83, +-84, +-86, +-87, +-88, +-89, +-90, +-92, +-92, +-94, +-95, +-96, +-98, +-98, +-100, +-100, +-102, +-103, +-104, +-105, +-106, +-107, +-108, +-109, +-111, +-111, +-112, +-113, +-115, +-115, +-116, +-117, +-119, +-119, +-120, +-121, +-121, +-123, +-124, +-124, +-126, +-126, +-127, +-128, +-129, +-129, +-131, +-131, +-132, +-133, +-133, +-135, +-135, +-135, +-137, +-137, +-138, +-138, +-140, +-139, +-141, +-141, +-142, +-142, +-143, +-144, +-144, +-145, +-145, +-146, +-146, +-147, +-148, +-148, +-148, +-149, +-149, +-150, +-150, +-151, +-151, +-152, +-151, +-153, +-152, +-153, +-154, +-153, +-154, +-154, +-155, +-155, +-155, +-155, +-156, +-156, +-156, +-156, +-157, +-156, +-157, +-157, +-157, +-157, +-158, +-157, +-158, +-158, +-157, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-158, +-157, +-158, +-158, +-157, +-158, +-157, +-158, +-157, +-157, +-157, +-156, +-157, +-156, +-156, +-156, +-156, +-155, +-155, +-155, +-155, +-154, +-155, +-153, +-154, +-153, +-153, +-152, +-153, +-151, +-152, +-151, +-150, +-151, +-150, +-149, +-149, +-149, +-148, +-147, +-148, +-146, +-146, +-146, +-145, +-145, +-144, +-144, +-143, +-143, +-141, +-142, +-141, +-140, +-140, +-139, +-138, +-138, +-137, +-137, +-136, +-135, +-135, +-134, +-133, +-132, +-132, +-132, +-130, +-130, +-129, +-128, +-128, +-127, +-126, +-125, +-125, +-124, +-123, +-122, +-122, +-121, +-120, +-119, +-118, +-118, +-116, +-116, +-115, +-115, +-113, +-113, +-111, +-111, +-110, +-109, +-109, +-107, +-107, +-105, +-105, +-104, +-103, +-102, +-101, +-101, +-98, +-99, +-97, +-97, +-96, +-94, +-94, +-93, +-92, +-92, +-90, +-89, +-88, +-88, +-86, +-86, +-84, +-84, +-82, +-82, +-81, +-80, +-78, +-78, +-77, +-76, +-75, +-74, +-73, +-72, +-72, +-70, +-69, +-68, +-68, +-66, +-65, +-65, +-63, +-63, +-61, +-61, +-59, +-59, +-58, +-56, +-56, +-55, +-54, +-53, +-52, +-51, +-50, +-49, +-48, +-47, +-47, +-45, +-44, +-44, +-42, +-42, +-41, +-39, +-39, +-38, +-37, +-36, +-36, +-34, +-33, +-33, +-31, +-31, +-30, +-29, +-28, +-27, +-26, +-25, +-25, +-23, +-23, +-22, +-21, +-20, +-20, +-18, +-18, +-17, +-16, +-15, +-14, +-14, +-13, +-12, +-11, +-10, +-10, +-9, +-8, +-7, +-6, +-6, +-5, +-4, +-4, +-2, +-2, +-2, +0, +0, +1, +2, +2, +3, +4, +4, +5, +6, +6, +7, +8, +9, +9, +9, +11, +11, +11, +12, +13, +13, +14, +15, +15, +16, +16, +17, +17, +18, +19, +19, +19, +20, +21, +21, +21, +22, +23, +23, +24, +23, +25, +25, +25, +26, +26, +27, +27, +27, +28, +28, +29, +29, +30, +29, +30, +31, +31, +31, +32, +32, +32, +32, +33, +33, +34, +33, +34, +35, +34, +35, +35, +35, +36, +36, +36, +36, +37, +36, +37, +37, +38, +37, +38, +37, +38, +39, +38, +38, +39, +39, +38, +39, +39, +40, +39, +39, +40, +39, +40, +40, +39, +40, +40, +40, +40, +40, +40, +40, +40, +40, +40, +41, +40, +40, +40, +40, +40, +40, +40, +40, +40, +40, +39, +40, +40, +39, +40, +39, +40, +39, +39, +39, +39, +39, +39, +39, +38, +38, +39, +38, +38, +38, +37, +38, +37, +38, +37, +36, +37, +37, +36, +36, +36, +36, +36, +35, +35, +36, +34, +35, +34, +35, +34, +33, +34, +33, +33, +33, +33, +32, +32, +32, +31, +31, +31, +31, +30, +31, +30, +30, +29, +30, +29, +28, +29, +28, +28, +28, +27, +27, +27, +26, +27, +25, +26, +25, +26, +24, +25, +24, +24, +23, +24, +23, +22, +23, +22, +22, +21, +21, +21, +21, +20, +20, +19, +20, +19, +18, +19, +18, +18, +17, +17, +17, +17, +16, +16, +15, +16, +15, +14, +15, +14, +14, +13, +13, +13, +12, +13, +12, +11, +12, +11, +10, +11, +10, +10, +9, +9, +9, +9, +8, +8, +8, +8, +7, +7, +6, +7, +6, +5, +6, +5, +5, +5, +4, +4, +4, +3, +4, +3, +3, +2, +2, +2, +2, +1, +2, +1, +0, +1, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +-2, +-2, +-2, +-2, +-3, +-3, +-3, +-3, +-3, +-4, +-4, +-4, +-4, +-5, +-4, +-5, +-5, +-6, +-5, +-6, +-6, +-6, +-6, +-6, +-7, +-6, +-7, +-7, +-7, +-8, +-7, +-8, +-8, +-8, +-8, +-8, +-9, +-8, +-9, +-9, +-9, +-9, +-9, +-10, +-9, +-10, +-10, +-10, +-10, +-10, +-10, +-11, +-10, +-11, +-10, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-12, +-11, +-12, +-12, +-11, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-13, +-12, +-12, +-13, +-12, +-13, +-12, +-13, +-13, +-12, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-12, +-13, +-13, +-13, +-12, +-13, +-13, +-12, +-13, +-12, +-13, +-12, +-13, +-12, +-12, +-13, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-12, +-11, +-12, +-11, +-12, +-11, +-12, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-11, +-10, +-11, +-11, +-10, +-10, +-11, +-10, +-10, +-10, +-10, +-10, +-9, +-10, +-10, +-9, +-10, +-9, +-8, +-9, +-9, +-9, +-9, +-9, +-9, +-8, +-9, +-8, +-9, +-8, +-8, +-8, +-8, +-8, +-7, +-8, +-8, +-7, +-7, +-8, +-7, +-7, +-7, +-7, +-6, +-7, +-7, +-6, +-7, +-6, +-6, +-6, +-6, +-6, +-6, +-5, +-6, +-5, +-6, +-5, +-5, +-5, +-5, +-5, +-5, +-5, +-4, +-5, +-4, +-4, +-5, +-4, +-4, +-4, +-3, +-4, +-4, +-3, +-4, +-3, +-3, +-4, +-3, +-3, +-2, +-3, +-3, +-3, +-2, +-3, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-2, +-1, +-2, +-1, +-2, +-1, +-1, +-2, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +1, +0, +1, +1, +1, +1, +0, +1, +1, +1, +2, +1, +1, +1, +2, +1, +2, +1, +2, +1, +2, +2, +2, +1, +2, +2, +2, +2, +2, +2, +2, +2, +3, +2, +2, +3, +2, +2, +3, +2, +3, +2, +3, +2, +3, +3, +2, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +4, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +3, +3, +3, +4, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +3, +3, +3, +3, +2, +3, +3, +3, +2, +3, +3, +2, +3, +3, +2, +3, +2, +3, +3, +2, +2, +3, +2, +3, +2, +2, +3, +2, +2, +3, +2, +2, +2, +2, +3, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +0, +2, +2, +2, +2, +1, +2, +2, +1, +2, +1, +2, +2, +1, +2, +1, +2, +1, +1, +2, +1, +1, +2, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +1, +1, +1, +0, +1, +1, +1, +0, +1, +0, +1, +0, +1, +1, +0, +0, +1, +0, +1, +0, +1, +0, +0, +1, +0, +0, +0, +1, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1 +}; diff --git a/third_party/resample/src/sndlibextra.c b/third_party/resample/src/sndlibextra.c new file mode 100644 index 00000000..c756cb10 --- /dev/null +++ b/third_party/resample/src/sndlibextra.c @@ -0,0 +1,90 @@ +/* sndlibextra.c + + An interface to the low-level sndlib functions contained in sndlib/headers.c + and sndlib/io.c, designed for use by the resample program. + (sndlibextra.c is a stripped-down version of sndlibsupport.c in RTcmix.) + + - John Gibson (jgg9c@virginia.edu) +*/ +#include <assert.h> +#include <string.h> +#include "sndlibextra.h" + +/* #define NDEBUG */ /* define to disable asserts */ + +/* ---------------------------------------------------- sndlib_create --- */ +/* Creates a new file and writes a header with the given characteristics. + <type> is a sndlib constant for header type (e.g. MUS_AIFF). + <format> is a sndlib constant for sound data format (e.g. snd_16_linear). + (These constants are defined in sndlib.h.) Caller is responsible for + checking that the header type and data format are compatible, and that + the header type is one that sndlib can write (is WRITEABLE_HEADER_TYPE()). + Writes no comment. + + NOTE: This will truncate an existing file with <sfname>, so check first! + + On success, returns a standard file descriptor, and leaves the file + position pointer at the end of the header. + On failure, returns -1. Caller can check errno then. +*/ +int +sndlib_create(char *sfname, /* file name */ + int type, /* file type, e.g. AIFF */ + int format, /* data format, e.g., MU-LAW */ + int srate, /* sampling rate in Hz */ + int chans, /* 1 for mono, 2 for stereo */ + char *comment) +{ + int fd, loc; + assert(sfname != NULL && strlen(sfname) <= FILENAME_MAX); + mus_header_initialize(); // make sure relevant parts of sndlib are initialized + //resample-1.8: sndlib_write_header(fd, 0, type, format, srate, chans, comment, &loc) + //resample-1.8: mus_file_open_descriptors(fd, format, mus_header_data_format_to_bytes_per_sample(),loc); + // int mus_file_open_descriptors(int tfd, const char *arg, int df, int ds, off_t dl, int dc, int dt); + fd = mus_sound_open_output(sfname, srate, chans, format, type, "created by resample"); + return fd; +} + +/* ------------------------------------------ sndlib_allocate_buffers --- */ +/* Allocate the multi-dimensional array required by sndlib I/O functions. + Returns an array of <nchans> arrays of <nframes> integers. The memory + is cleared. If the return value is NULL, check errno. +*/ +int ** +sndlib_allocate_buffers(int nchans, int nframes) +{ + int **bufs, n; + + assert(nchans > 0 && nframes > 0); + + bufs = (int **)calloc(nchans, sizeof(int *)); + if (bufs == NULL) + return NULL; + + for (n = 0; n < nchans; n++) { + bufs[n] = (int *)calloc(nframes, sizeof(int)); + if (bufs[n] == NULL) { + sndlib_free_buffers(bufs, nchans); + return NULL; + } + } + + return bufs; +} + + +/* ---------------------------------------------- sndlib_free_buffers --- */ +/* Free the multi-dimensional array <bufs> with <nchans> elements. +*/ +void +sndlib_free_buffers(int **bufs, int nchans) +{ + int n; + + assert(bufs != NULL); + + for (n = 0; n < nchans; n++) + if (bufs[n]) + free(bufs[n]); + free(bufs); +} diff --git a/third_party/resample/src/sndlibextra.h b/third_party/resample/src/sndlibextra.h new file mode 100644 index 00000000..536ac72c --- /dev/null +++ b/third_party/resample/src/sndlibextra.h @@ -0,0 +1,48 @@ +#include <endian.h> /* so that sndlib.h will get host byte-order right */ +#include <sndlib.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/* for creating, opening and closing files for sndlib I/O */ +int sndlib_create(char *, int, int, int, int, char *); +int sndlib_open_read(char *); +int sndlib_open_write(char *); +int sndlib_close(int, int, int, int, int); + +/* for reading and writing headers */ +int sndlib_read_header(int); +int sndlib_write_header(int, int, int, int, int, int, char *, int *); +int sndlib_set_header_data_size(int, int, int); + +/* helper functions */ +int **sndlib_allocate_buffers(int, int); +void sndlib_free_buffers(int **, int); + + +/* some handy macros */ + +#define IS_FLOAT_FORMAT(format) ( \ + (format) == snd_32_float \ + || (format) == snd_32_float_little_endian ) + +#define NOT_A_SOUND_FILE(header_type) ( \ + (header_type) == MUS_UNSUPPORTED \ + || (header_type) == MUS_RAW ) + +/* The header types that sndlib can write, as of sndlib-5.5. */ +#define WRITEABLE_HEADER_TYPE(type) ( \ + (type) == MUS_AIFF \ + || (type) == MUS_NEXT \ + || (type) == MUS_RIFF \ + || (type) == MUS_IRCAM ) + +#define INVALID_DATA_FORMAT(format) ((format) < 1) + + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + diff --git a/third_party/resample/src/stdefs.h b/third_party/resample/src/stdefs.h new file mode 100644 index 00000000..4672981b --- /dev/null +++ b/third_party/resample/src/stdefs.h @@ -0,0 +1,59 @@ +/* stdefs.h */ +#ifndef _STDEFS_H +#define _STDEFS_H + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef PI +#define PI (3.14159265358979232846) +#endif + +#ifndef PI2 +#define PI2 (6.28318530717958465692) +#endif + +#define D2R (0.01745329348) /* (2*pi)/360 */ +#define R2D (57.29577951) /* 360/(2*pi) */ + +#ifndef MAX +#define MAX(x,y) ((x)>(y) ?(x):(y)) +#endif +#ifndef MIN +#define MIN(x,y) ((x)<(y) ?(x):(y)) +#endif + +#ifndef ABS +#define ABS(x) ((x)<0 ?(-(x)):(x)) +#endif + +#ifndef SGN +#define SGN(x) ((x)<0 ?(-1):((x)==0?(0):(1))) +#endif + +typedef char BOOL; +typedef short HWORD; +typedef unsigned short UHWORD; +typedef int WORD; +typedef unsigned int UWORD; + +#define MUS_SAMPLE_TYPE_TO_HWORD(x) ((HWORD)((x)>>(MUS_SAMPLE_BITS-16))) +#define HWORD_TO_MUS_SAMPLE_TYPE(x) ((mus_sample_t)((x)<<(MUS_SAMPLE_BITS-16))) + +#define MAX_HWORD (32767) +#define MIN_HWORD (-32768) + +#ifdef DEBUG +#define INLINE +#else +#ifndef INLINE +#define INLINE inline +#endif +#endif + +#endif /* _STDEFS_H */ diff --git a/third_party/resample/src/windowfilter.c b/third_party/resample/src/windowfilter.c new file mode 100644 index 00000000..b2b67690 --- /dev/null +++ b/third_party/resample/src/windowfilter.c @@ -0,0 +1,114 @@ +/* makefilter.c */ + +#include <stdio.h> +#include <math.h> +#include "stdefs.h" +#include "filterkit.h" +#include "resample.h" +#define MAXNWING 8192 /* FIXME: flush */ + +/* LIBRARIES needed: + * + * 1. filterkit + * makeFilter() - designs a Kaiser-windowed low-pass filter + * writeFilter() - writes a filter to a standard filter file + * GetUShort() - prompt user for a UHWORD with help + * GetDouble() - prompt user for a double with help + * + * 2. math + */ + +char NmultHelp[] = + "\n Nmult is the length of the symmetric FIR lowpass filter used" + "\n by the sampling rate converter. It must be odd." + "\n This is the number of multiplies per output sample for" + "\n up-conversions (Factor>1), and is the number of multiplies" + "\n per input sample for down-conversions (Factor<1). Thus if" + "\n the rate conversion is Srate2 = Factor*Srate1, then you have" + "\n Nmult*Srate1*MAXof(Factor,1) multiplies per second of real time." + "\n Naturally, higher Nmult gives better lowpass-filtering at the" + "\n expense of longer compute times. Nmult should be odd because" + "\n it is the length of a symmetric FIR filter, and the current" + "\n implementation requires a coefficient at the time origin.\n"; + +char FrollHelp[] = + "\n Froll determines the frequency at which the lowpass filter begins to" + "\n roll-off. If Froll=1, then there is no 'guard zone' and the filter" + "\n roll-off region will be aliased. If Froll is 0.90, for example, then" + "\n the filter begins rolling off at 0.90*Srate/2, so that by Srate/2," + "\n the filter is well down and aliasing is reduced. Since aliasing" + "\n distortion is typically worse than loss of the high-frequency spectral" + "\n amplitude, Froll<1 is highly recommended. The default of 0.90" + "\n sacrifices the upper 10 percent of the spectrum as an anti-aliasing" + "\n guard zone.\n"; + +char BetaHelp[] = + "\n Beta trades the rejection of the lowpass filter against the" + "\n transition width from passband to stopband. Larger Beta means" + "\n a slower transition and greater stopband rejection. See Rabiner" + "\n and Gold (Th. and App. of DSP) under Kaiser windows for more about" + "\n Beta. The following table from Rabiner and Gold (p. 101) gives some" + "\n feel for the effect of Beta:" + "\n" + "\n BETA D PB RIP SB RIP" + "\n 2.120 1.50 +-0.27 -30" + "\n 3.384 2.23 0.0864 -40" + "\n 4.538 2.93 0.0274 -50" + "\n 5.658 3.62 0.00868 -60" + "\n 6.764 4.32 0.00275 -70" + "\n 7.865 5.0 0.000868 -80" + "\n 8.960 5.7 0.000275 -90" + "\n 10.056 6.4 0.000087 -100" + "\n" + "\n Above, ripples are in dB, and the transition band width is " + "\n approximately D*Fs/N, where Fs = sampling rate, " + "\n and N = window length. PB = 'pass band' and SB = 'stop band'." + "\n Alternatively, D is the transition widths in bins given a" + "\n length N DFT (i.e. a window transform with no zero padding." + "\n"; + + +int main(void) +{ + HWORD Imp[MAXNWING]; /* Filter coefficients */ + HWORD ImpD[MAXNWING]; /* ImpD[i] = ImpD[i+1] - ImpD[i] */ + double Froll, Beta; + UHWORD Nmult, Nwing, LpScl; + int err; + + Froll = 0.90; + Beta = 9; + Nmult = 65; + while (1) + { + Froll = GetDouble("Normalized Roll-off freq (0<Froll<=1)", + Froll, FrollHelp); + Beta = GetDouble("Beta", Beta, BetaHelp); + Nmult = GetUHWORD("Odd filter length 'Nmult'", Nmult, NmultHelp); + if ((Nmult&1) == 0) { + Nmult++; + printf("Filter length increased to %d to make it odd.\n",Nmult); + } + Nwing = Npc*(Nmult-1)/2; /* # of filter coeffs in right wing */ + printf("\n"); + if (!(Nmult % 2)) + printf("Error: Nmult must be odd and greater than zero\n"); + else if ((err = makeFilter(Imp, ImpD, &LpScl, Nwing, Froll, Beta))) { + printf("*** Error: Unable to make filter.\n"); + if (err == 1) + printf("\tNmult=%d too large for MAXNWING=%d\n",Nmult,MAXNWING); + else if (err == 2) + printf("\tNormalized roll-off freq Froll must be between 0 and 1\n"); + else if (err == 3) + printf("\tHeisenberg says Beta must be greater or equal to 1\n"); + else if (err == 4) { + printf("\tUnity-gain scale factor overflows 16-bit half-word\n"); + printf("\tFilter design was probably way off. Try relaxing specs.\n"); + } + } else if ((err = writeFilter(Imp, ImpD, LpScl, Nmult, Nwing))) + printf("Error: Unable to write filter, err=%d\n", err); + else + break; + } + return(0); +} |