]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@125 d0543943-73ff-0310...
authorMichael Jerris <mike@jerris.com>
Tue, 13 Dec 2005 18:33:02 +0000 (18:33 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 13 Dec 2005 18:33:02 +0000 (18:33 +0000)
114 files changed:
libs/codec/gsm/COPYRIGHT [new file with mode: 0644]
libs/codec/gsm/Makefile [new file with mode: 0644]
libs/codec/gsm/README [new file with mode: 0644]
libs/codec/gsm/inc/config.h [new file with mode: 0644]
libs/codec/gsm/inc/gsm.h [new file with mode: 0644]
libs/codec/gsm/inc/private.h [new file with mode: 0644]
libs/codec/gsm/inc/proto.h [new file with mode: 0644]
libs/codec/gsm/inc/unproto.h [new file with mode: 0644]
libs/codec/gsm/src/add.c [new file with mode: 0644]
libs/codec/gsm/src/code.c [new file with mode: 0644]
libs/codec/gsm/src/debug.c [new file with mode: 0644]
libs/codec/gsm/src/decode.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_create.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_decode.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_destroy.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_encode.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_explode.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_implode.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_option.c [new file with mode: 0644]
libs/codec/gsm/src/gsm_print.c [new file with mode: 0644]
libs/codec/gsm/src/k6opt.h [new file with mode: 0644]
libs/codec/gsm/src/k6opt.s [new file with mode: 0644]
libs/codec/gsm/src/long_term.c [new file with mode: 0644]
libs/codec/gsm/src/lpc.c [new file with mode: 0644]
libs/codec/gsm/src/preprocess.c [new file with mode: 0644]
libs/codec/gsm/src/rpe.c [new file with mode: 0644]
libs/codec/gsm/src/short_term.c [new file with mode: 0644]
libs/codec/gsm/src/table.c [new file with mode: 0644]
libs/codec/ilbc/FrameClassify.c [new file with mode: 0644]
libs/codec/ilbc/FrameClassify.h [new file with mode: 0644]
libs/codec/ilbc/LPCdecode.c [new file with mode: 0644]
libs/codec/ilbc/LPCdecode.h [new file with mode: 0644]
libs/codec/ilbc/LPCencode.c [new file with mode: 0644]
libs/codec/ilbc/LPCencode.h [new file with mode: 0644]
libs/codec/ilbc/Makefile [new file with mode: 0644]
libs/codec/ilbc/StateConstructW.c [new file with mode: 0644]
libs/codec/ilbc/StateConstructW.h [new file with mode: 0644]
libs/codec/ilbc/StateSearchW.c [new file with mode: 0644]
libs/codec/ilbc/StateSearchW.h [new file with mode: 0644]
libs/codec/ilbc/anaFilter.c [new file with mode: 0644]
libs/codec/ilbc/anaFilter.h [new file with mode: 0644]
libs/codec/ilbc/constants.c [new file with mode: 0644]
libs/codec/ilbc/constants.h [new file with mode: 0644]
libs/codec/ilbc/createCB.c [new file with mode: 0644]
libs/codec/ilbc/createCB.h [new file with mode: 0644]
libs/codec/ilbc/doCPLC.c [new file with mode: 0644]
libs/codec/ilbc/doCPLC.h [new file with mode: 0644]
libs/codec/ilbc/enhancer.c [new file with mode: 0644]
libs/codec/ilbc/enhancer.h [new file with mode: 0644]
libs/codec/ilbc/filter.c [new file with mode: 0644]
libs/codec/ilbc/filter.h [new file with mode: 0644]
libs/codec/ilbc/gainquant.c [new file with mode: 0644]
libs/codec/ilbc/gainquant.h [new file with mode: 0644]
libs/codec/ilbc/getCBvec.c [new file with mode: 0644]
libs/codec/ilbc/getCBvec.h [new file with mode: 0644]
libs/codec/ilbc/helpfun.c [new file with mode: 0644]
libs/codec/ilbc/helpfun.h [new file with mode: 0644]
libs/codec/ilbc/hpInput.c [new file with mode: 0644]
libs/codec/ilbc/hpInput.h [new file with mode: 0644]
libs/codec/ilbc/hpOutput.c [new file with mode: 0644]
libs/codec/ilbc/hpOutput.h [new file with mode: 0644]
libs/codec/ilbc/iCBConstruct.c [new file with mode: 0644]
libs/codec/ilbc/iCBConstruct.h [new file with mode: 0644]
libs/codec/ilbc/iCBSearch.c [new file with mode: 0644]
libs/codec/ilbc/iCBSearch.h [new file with mode: 0644]
libs/codec/ilbc/iLBC_decode.c [new file with mode: 0644]
libs/codec/ilbc/iLBC_decode.h [new file with mode: 0644]
libs/codec/ilbc/iLBC_define.h [new file with mode: 0644]
libs/codec/ilbc/iLBC_encode.c [new file with mode: 0644]
libs/codec/ilbc/iLBC_encode.h [new file with mode: 0644]
libs/codec/ilbc/lsf.c [new file with mode: 0644]
libs/codec/ilbc/lsf.h [new file with mode: 0644]
libs/codec/ilbc/packing.c [new file with mode: 0644]
libs/codec/ilbc/packing.h [new file with mode: 0644]
libs/codec/ilbc/syntFilter.c [new file with mode: 0644]
libs/codec/ilbc/syntFilter.h [new file with mode: 0644]
libs/codec/lpc10/Makefile [new file with mode: 0644]
libs/codec/lpc10/README [new file with mode: 0644]
libs/codec/lpc10/analys.c [new file with mode: 0644]
libs/codec/lpc10/bsynz.c [new file with mode: 0644]
libs/codec/lpc10/chanwr.c [new file with mode: 0644]
libs/codec/lpc10/dcbias.c [new file with mode: 0644]
libs/codec/lpc10/decode.c [new file with mode: 0644]
libs/codec/lpc10/deemp.c [new file with mode: 0644]
libs/codec/lpc10/difmag.c [new file with mode: 0644]
libs/codec/lpc10/dyptrk.c [new file with mode: 0644]
libs/codec/lpc10/encode.c [new file with mode: 0644]
libs/codec/lpc10/energy.c [new file with mode: 0644]
libs/codec/lpc10/f2c.h [new file with mode: 0644]
libs/codec/lpc10/f2clib.c [new file with mode: 0644]
libs/codec/lpc10/ham84.c [new file with mode: 0644]
libs/codec/lpc10/hp100.c [new file with mode: 0644]
libs/codec/lpc10/invert.c [new file with mode: 0644]
libs/codec/lpc10/irc2pc.c [new file with mode: 0644]
libs/codec/lpc10/ivfilt.c [new file with mode: 0644]
libs/codec/lpc10/lpc10.h [new file with mode: 0644]
libs/codec/lpc10/lpcdec.c [new file with mode: 0644]
libs/codec/lpc10/lpcenc.c [new file with mode: 0644]
libs/codec/lpc10/lpcini.c [new file with mode: 0644]
libs/codec/lpc10/lpfilt.c [new file with mode: 0644]
libs/codec/lpc10/median.c [new file with mode: 0644]
libs/codec/lpc10/mload.c [new file with mode: 0644]
libs/codec/lpc10/onset.c [new file with mode: 0644]
libs/codec/lpc10/pitsyn.c [new file with mode: 0644]
libs/codec/lpc10/placea.c [new file with mode: 0644]
libs/codec/lpc10/placev.c [new file with mode: 0644]
libs/codec/lpc10/preemp.c [new file with mode: 0644]
libs/codec/lpc10/prepro.c [new file with mode: 0644]
libs/codec/lpc10/random.c [new file with mode: 0644]
libs/codec/lpc10/rcchk.c [new file with mode: 0644]
libs/codec/lpc10/synths.c [new file with mode: 0644]
libs/codec/lpc10/tbdm.c [new file with mode: 0644]
libs/codec/lpc10/voicin.c [new file with mode: 0644]
libs/codec/lpc10/vparms.c [new file with mode: 0644]

diff --git a/libs/codec/gsm/COPYRIGHT b/libs/codec/gsm/COPYRIGHT
new file mode 100644 (file)
index 0000000..504978b
--- /dev/null
@@ -0,0 +1,16 @@
+Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,\r
+Technische Universitaet Berlin\r
+\r
+Any use of this software is permitted provided that this notice is not\r
+removed and that neither the authors nor the Technische Universitaet Berlin\r
+are deemed to have made any representations as to the suitability of this\r
+software for any purpose nor are held responsible for any defects of\r
+this software.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+\r
+As a matter of courtesy, the authors request to be informed about uses\r
+this software has found, about bugs in this software, and about any\r
+improvements that may be of general interest.\r
+\r
+Berlin, 28.11.1994\r
+Jutta Degener\r
+Carsten Bormann\r
diff --git a/libs/codec/gsm/Makefile b/libs/codec/gsm/Makefile
new file mode 100644 (file)
index 0000000..4628464
--- /dev/null
@@ -0,0 +1,583 @@
+# Copyright 1992-1996 by Jutta Degener and Carsten Bormann, Technische\r
+# Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+# details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+\r
+# Machine- or installation dependent flags you should configure to port\r
+\r
+SASR   = -DSASR\r
+######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1)\r
+\r
+#MULHACK = -DUSE_FLOAT_MUL\r
+######### Define this if your host multiplies floats faster than integers,\r
+######### e.g. on a SPARCstation.\r
+\r
+#FAST  = -DFAST\r
+######### Define together with USE_FLOAT_MUL to enable the GSM library's\r
+######### approximation option for incorrect, but good-enough results.\r
+\r
+# LTP_CUT      = -DLTP_CUT\r
+LTP_CUT        =\r
+######### Define to enable the GSM library's long-term correlation \r
+######### approximation option---faster, but worse; works for\r
+######### both integer and floating point multiplications.\r
+######### This flag is still in the experimental stage.\r
+\r
+WAV49  = -DWAV49\r
+#WAV49 =\r
+######### Define to enable the GSM library's option to pack GSM frames \r
+######### in the style used by the WAV #49 format.  If you want to write\r
+######### a tool that produces .WAV files which contain GSM-encoded data,\r
+######### define this, and read about the GSM_OPT_WAV49 option in the\r
+######### manual page on gsm_option(3).\r
+\r
+#K6OPT = -DK6OPT\r
+#K6OPT =\r
+######### Define to enable MMXTM optimizations for x86 architecture CPU's\r
+######### which support MMX instructions.  This should be newer pentiums,\r
+######### ppro's, etc, as well as the AMD K6 and K7.  The compile will\r
+######### probably require gcc. \r
+\r
+ifneq (${OSARCH},Darwin)\r
+ifneq (${OSARCH},SunOS)\r
+ifneq (${PROC},x86_64)\r
+ifneq (${PROC},ultrasparc)\r
+ifneq ($(shell uname -m),ppc)\r
+ifneq ($(shell uname -m),ppc64)\r
+ifneq ($(shell uname -m),alpha)\r
+ifneq ($(shell uname -m),armv4l)\r
+ifneq (${PROC},sparc64)\r
+ifneq (${PROC},arm)\r
+ifneq (${PROC},ppc)\r
+ifneq (${PROC},ppc64)\r
+OPTIMIZE+=-march=$(PROC)\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+\r
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.\r
+#This works for even old (2.96) versions of gcc and provides a small boost either way.\r
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.\r
+#So we go lowest common available by gcc and go a step down, still a step up from\r
+#the default as we now have a better instruction set to work with. - Belgarath\r
+ifeq (${PROC},ultrasparc)\r
+OPTIMIZE+=-mcpu=v8 -mtune=$(PROC) -O3 \r
+endif\r
+\r
+PG =\r
+#PG = -g -pg\r
+######### Profiling flags.  If you don't know what that means, leave it blank.\r
\r
+# Choose a compiler.  The code works both with ANSI and K&R-C.\r
+# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to\r
+# compile without, function prototypes in the header files.\r
+#\r
+# You can use the -DSTUPID_COMPILER to circumvent some compilers'\r
+# static limits regarding the number of subexpressions in a statement.\r
+\r
+# CC           = cc\r
+# CCFLAGS      = -c -DSTUPID_COMPILER\r
+\r
+# CC           = /usr/lang/acc\r
+# CCFLAGS      = -c -O\r
+\r
+CC             ?= gcc\r
+CCFLAGS        += -c -DNeedFunctionPrototypes=1 -funroll-loops $(OPTIMIZE)\r
+ifneq ($(findstring CYGWIN,${OSARCH}),CYGWIN)\r
+CCFLAGS   += -fPIC\r
+endif\r
+\r
+\r
+LD             = $(CC)\r
+\r
+# LD           = gcc\r
+# LDFLAGS      =\r
+\r
+\r
+# If your compiler needs additional flags/libraries, regardless of\r
+# the source compiled, configure them here.\r
+\r
+# CCINC        = -I/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1/include\r
+######### Includes needed by $(CC)\r
+\r
+# LDINC        = -L/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1\r
+######### Library paths needed by $(LD)\r
+\r
+# LDLIB        = -lgcc\r
+######### Additional libraries needed by $(LD)\r
+\r
+\r
+# Where do you want to install libraries, binaries, a header file\r
+# and the manual pages?\r
+#\r
+# Leave INSTALL_ROOT empty (or just don't execute "make install") to\r
+# not install gsm and toast outside of this directory.\r
+\r
+INSTALL_ROOT   =\r
+\r
+# Where do you want to install the gsm library, header file, and manpages?\r
+#\r
+# Leave GSM_INSTALL_ROOT empty to not install the GSM library outside of\r
+# this directory.\r
+\r
+GSM_INSTALL_ROOT = $(INSTALL_ROOT)\r
+GSM_INSTALL_LIB = $(GSM_INSTALL_ROOT)/lib\r
+GSM_INSTALL_INC = $(GSM_INSTALL_ROOT)/inc\r
+GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/man/man3\r
+\r
+\r
+# Where do you want to install the toast binaries and their manpage?\r
+#\r
+# Leave TOAST_INSTALL_ROOT empty to not install the toast binaries outside\r
+# of this directory.\r
+\r
+TOAST_INSTALL_ROOT       = $(INSTALL_ROOT)\r
+TOAST_INSTALL_BIN = $(TOAST_INSTALL_ROOT)/bin\r
+TOAST_INSTALL_MAN = $(TOAST_INSTALL_ROOT)/man/man1\r
+\r
+#  Other tools\r
+\r
+SHELL          = /bin/sh\r
+LN             = ln\r
+BASENAME       = basename\r
+AR             = ar\r
+ARFLAGS                = cr\r
+RMFLAGS                = -f\r
+FIND           = find\r
+COMPRESS       = compress\r
+COMPRESSFLAGS  = \r
+# RANLIB       = true\r
+RANLIB         = ranlib\r
+\r
+#\r
+#    You shouldn't have to configure below this line if you're porting.\r
+# \r
+\r
+\r
+# Local Directories\r
+\r
+ROOT   = .\r
+ADDTST = $(ROOT)/add-test\r
+TST    = $(ROOT)/tst\r
+MAN    = $(ROOT)/man\r
+BIN    = $(ROOT)/bin\r
+SRC    = $(ROOT)/src\r
+LIB    = $(ROOT)/lib\r
+TLS    = $(ROOT)/tls\r
+INC    = $(ROOT)/inc\r
+\r
+# Flags\r
+\r
+DEBUG  = -DNDEBUG\r
+######### Remove -DNDEBUG to enable assertions.\r
+\r
+CFLAGS += $(PG) $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) \\r
+       $(LTP_CUT) $(WAV49) $(K6OPT) $(CCINC) -I$(INC)\r
+######### It's $(CC) $(CFLAGS)\r
+\r
+LFLAGS = $(PG) $(LDFLAGS) $(LDINC)\r
+######### It's $(LD) $(LFLAGS)\r
+\r
+\r
+# Targets\r
+\r
+LIBGSM = $(LIB)/libgsm.a\r
+LIBGSMSO= $(LIB)/libgsm.so\r
+\r
+TOAST  = $(BIN)/toast\r
+UNTOAST        = $(BIN)/untoast\r
+TCAT   = $(BIN)/tcat\r
+\r
+# Headers\r
+\r
+GSM_HEADERS =  $(INC)/gsm.h\r
+\r
+HEADERS        =       $(INC)/proto.h          \\r
+               $(INC)/unproto.h        \\r
+               $(INC)/config.h         \\r
+               $(INC)/private.h        \\r
+               $(INC)/gsm.h            \\r
+               $(INC)/toast.h          \\r
+               $(TLS)/taste.h\r
+\r
+# Sources\r
+\r
+GSM_SOURCES =  $(SRC)/add.c            \\r
+               $(SRC)/code.c           \\r
+               $(SRC)/debug.c          \\r
+               $(SRC)/decode.c         \\r
+               $(SRC)/long_term.c      \\r
+               $(SRC)/lpc.c            \\r
+               $(SRC)/preprocess.c     \\r
+               $(SRC)/rpe.c            \\r
+               $(SRC)/gsm_destroy.c    \\r
+               $(SRC)/gsm_decode.c     \\r
+               $(SRC)/gsm_encode.c     \\r
+               $(SRC)/gsm_explode.c    \\r
+               $(SRC)/gsm_implode.c    \\r
+               $(SRC)/gsm_create.c     \\r
+               $(SRC)/gsm_print.c      \\r
+               $(SRC)/gsm_option.c     \\r
+               $(SRC)/short_term.c     \\r
+               $(SRC)/table.c\r
+ifeq (${OSARCH},Linux)\r
+ifneq ($(shell uname -m),x86_64)\r
+ifneq ($(shell uname -m),ppc)\r
+ifneq ($(shell uname -m),ppc64)\r
+ifneq ($(shell uname -m),alpha)\r
+ifneq ($(shell uname -m),armv4l)\r
+ifneq ($(shell uname -m),sparc64)\r
+ifneq (${PROC},arm)\r
+GSM_SOURCES+= $(SRC)/k6opt.s\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+\r
+TOAST_SOURCES = $(SRC)/toast.c                 \\r
+               $(SRC)/toast_lin.c      \\r
+               $(SRC)/toast_ulaw.c     \\r
+               $(SRC)/toast_alaw.c     \\r
+               $(SRC)/toast_audio.c\r
+\r
+SOURCES        =       $(GSM_SOURCES)          \\r
+               $(TOAST_SOURCES)        \\r
+               $(ADDTST)/add_test.c    \\r
+               $(TLS)/sour.c           \\r
+               $(TLS)/ginger.c         \\r
+               $(TLS)/sour1.dta        \\r
+               $(TLS)/sour2.dta        \\r
+               $(TLS)/bitter.c         \\r
+               $(TLS)/bitter.dta       \\r
+               $(TLS)/taste.c          \\r
+               $(TLS)/sweet.c          \\r
+               $(TST)/cod2lin.c        \\r
+               $(TST)/cod2txt.c        \\r
+               $(TST)/gsm2cod.c        \\r
+               $(TST)/lin2cod.c        \\r
+               $(TST)/lin2txt.c\r
+\r
+# Object files\r
+\r
+GSM_OBJECTS =  $(SRC)/add.o            \\r
+               $(SRC)/code.o           \\r
+               $(SRC)/debug.o          \\r
+               $(SRC)/decode.o         \\r
+               $(SRC)/long_term.o      \\r
+               $(SRC)/lpc.o            \\r
+               $(SRC)/preprocess.o     \\r
+               $(SRC)/rpe.o            \\r
+               $(SRC)/gsm_destroy.o    \\r
+               $(SRC)/gsm_decode.o     \\r
+               $(SRC)/gsm_encode.o     \\r
+               $(SRC)/gsm_explode.o    \\r
+               $(SRC)/gsm_implode.o    \\r
+               $(SRC)/gsm_create.o     \\r
+               $(SRC)/gsm_print.o      \\r
+               $(SRC)/gsm_option.o     \\r
+               $(SRC)/short_term.o     \\r
+               $(SRC)/table.o\r
+\r
+ifeq (${OSARCH},Linux)\r
+ifneq ($(shell uname -m), x86_64)\r
+ifneq ($(shell uname -m), ppc)\r
+ifneq ($(shell uname -m), ppc64)\r
+ifneq ($(shell uname -m), alpha)\r
+ifneq ($(shell uname -m), sparc64)\r
+ifneq ($(shell uname -m), armv4l)\r
+GSM_OBJECTS+= $(SRC)/k6opt.o\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+\r
+TOAST_OBJECTS =        $(SRC)/toast.o          \\r
+               $(SRC)/toast_lin.o      \\r
+               $(SRC)/toast_ulaw.o     \\r
+               $(SRC)/toast_alaw.o     \\r
+               $(SRC)/toast_audio.o\r
+\r
+OBJECTS =       $(GSM_OBJECTS) $(TOAST_OBJECTS)\r
+\r
+# Manuals\r
+\r
+GSM_MANUALS =  $(MAN)/gsm.3            \\r
+               $(MAN)/gsm_explode.3    \\r
+               $(MAN)/gsm_option.3     \\r
+               $(MAN)/gsm_print.3\r
+\r
+TOAST_MANUALS =        $(MAN)/toast.1\r
+\r
+MANUALS        =       $(GSM_MANUALS) $(TOAST_MANUALS) $(MAN)/bitter.1\r
+\r
+# Other stuff in the distribution\r
+\r
+STUFF =        ChangeLog                       \\r
+               INSTALL                 \\r
+               MACHINES                \\r
+               MANIFEST                \\r
+               Makefile                \\r
+               README                  \\r
+               $(ADDTST)/add_test.dta  \\r
+               $(TLS)/bitter.dta       \\r
+               $(TST)/run\r
+\r
+\r
+# Install targets\r
+\r
+GSM_INSTALL_TARGETS =  \\r
+               $(GSM_INSTALL_LIB)/libgsm.a             \\r
+               $(GSM_INSTALL_INC)/gsm.h                \\r
+               $(GSM_INSTALL_MAN)/gsm.3                \\r
+               $(GSM_INSTALL_MAN)/gsm_explode.3        \\r
+               $(GSM_INSTALL_MAN)/gsm_option.3         \\r
+               $(GSM_INSTALL_MAN)/gsm_print.3\r
+\r
+TOAST_INSTALL_TARGETS =        \\r
+               $(TOAST_INSTALL_BIN)/toast              \\r
+               $(TOAST_INSTALL_BIN)/tcat               \\r
+               $(TOAST_INSTALL_BIN)/untoast            \\r
+               $(TOAST_INSTALL_MAN)/toast.1\r
+\r
+\r
+# Default rules\r
+\r
+.c.o:\r
+               $(CC) $(CFLAGS) $?\r
+               @-mv `$(BASENAME) $@` $@ > /dev/null 2>&1\r
+\r
+# Target rules\r
+\r
+all:           $(LIBGSM) $(LIBGSMSO) $(TOAST) $(TCAT) $(UNTOAST)\r
+               @-echo $(ROOT): Done.\r
+\r
+tst:           $(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/test-result\r
+               @-echo tst: Done.\r
+\r
+addtst:                $(ADDTST)/add $(ADDTST)/add_test.dta\r
+               $(ADDTST)/add < $(ADDTST)/add_test.dta > /dev/null\r
+               @-echo addtst: Done.\r
+\r
+misc:          $(TLS)/sweet $(TLS)/bitter $(TLS)/sour $(TLS)/ginger    \\r
+                       $(TST)/lin2txt $(TST)/cod2txt $(TST)/gsm2cod\r
+               @-echo misc: Done.\r
+\r
+install:       toastinstall gsminstall\r
+               @-echo install: Done.\r
+\r
+\r
+# The basic API: libgsm\r
+\r
+$(LIBGSMSO):   $(LIB) $(GSM_OBJECTS)\r
+               $(LD) -o $@.1.0.10 -shared -Xlinker -soname -Xlinker libgsm.so.1 $(GSM_OBJECTS) -lc\r
+               ln -fs libgsm.so.1.0.10 lib/libgsm.so.1\r
+               ln -fs libgsm.so.1.0.10 lib/libgsm.so\r
+\r
+$(LIBGSM):     $(LIB) $(GSM_OBJECTS)\r
+               -rm $(RMFLAGS) $(LIBGSM)\r
+               $(AR) $(ARFLAGS) $(LIBGSM) $(GSM_OBJECTS)\r
+               $(RANLIB) $(LIBGSM)\r
+\r
+\r
+# Toast, Untoast and Tcat -- the compress-like frontends to gsm.\r
+\r
+$(TOAST):      $(BIN) $(TOAST_OBJECTS) $(LIBGSM)\r
+               $(LD) $(LFLAGS) -o $(TOAST) $(TOAST_OBJECTS) $(LIBGSMSO) $(LDLIB)\r
+\r
+$(UNTOAST):    $(BIN) $(TOAST)\r
+               -rm $(RMFLAGS) $(UNTOAST)\r
+               $(LN) toast $(UNTOAST)\r
+\r
+$(TCAT):       $(BIN) $(TOAST)\r
+               -rm $(RMFLAGS) $(TCAT)\r
+               $(LN) toast $(TCAT)\r
+\r
+\r
+# The local bin and lib directories\r
+\r
+$(BIN):\r
+               if [ ! -d $(BIN) ] ; then mkdir $(BIN) ; fi\r
+\r
+$(LIB):\r
+               if [ ! -d $(LIB) ] ; then mkdir $(LIB) ; fi\r
+\r
+\r
+# Installation\r
+\r
+gsminstall:\r
+               -if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then      \\r
+                       $(MAKE) $(GSM_INSTALL_TARGETS) ;        \\r
+               fi\r
+\r
+toastinstall:\r
+               -if [ x"$(TOAST_INSTALL_ROOT)" != x ]; then     \\r
+                       $(MAKE) $(TOAST_INSTALL_TARGETS);       \\r
+               fi\r
+\r
+gsmuninstall:\r
+               -if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then      \\r
+                       rm $(RMFLAGS) $(GSM_INSTALL_TARGETS) ;  \\r
+               fi\r
+\r
+toastuninstall:\r
+               -if [ x"$(TOAST_INSTALL_ROOT)" != x ] ; then    \\r
+                       rm $(RMFLAGS) $(TOAST_INSTALL_TARGETS); \\r
+               fi\r
+\r
+$(TOAST_INSTALL_BIN)/toast:    $(TOAST)\r
+               -rm $@\r
+               cp $(TOAST) $@\r
+               chmod 755 $@\r
+\r
+$(TOAST_INSTALL_BIN)/untoast:  $(TOAST_INSTALL_BIN)/toast\r
+               -rm $@\r
+               ln $? $@\r
+\r
+$(TOAST_INSTALL_BIN)/tcat:     $(TOAST_INSTALL_BIN)/toast\r
+               -rm $@\r
+               ln $? $@\r
+\r
+$(TOAST_INSTALL_MAN)/toast.1:  $(MAN)/toast.1\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_MAN)/gsm.3:      $(MAN)/gsm.3\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_MAN)/gsm_option.3:       $(MAN)/gsm_option.3\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_MAN)/gsm_explode.3:      $(MAN)/gsm_explode.3\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_MAN)/gsm_print.3:        $(MAN)/gsm_print.3\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_INC)/gsm.h:      $(INC)/gsm.h\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+$(GSM_INSTALL_LIB)/libgsm.a:   $(LIBGSM)\r
+               -rm $@\r
+               cp $? $@\r
+               chmod 444 $@\r
+\r
+\r
+# Distribution\r
+\r
+dist:          gsm-1.0.tar.Z\r
+               @echo dist: Done.\r
+\r
+gsm-1.0.tar.Z: $(STUFF) $(SOURCES) $(HEADERS) $(MANUALS)\r
+               (       cd $(ROOT)/..;                          \\r
+                       tar cvf - `cat $(ROOT)/gsm-1.0/MANIFEST \\r
+                               | sed '/^#/d'`                  \\r
+               ) | $(COMPRESS) $(COMPRESSFLAGS) > $(ROOT)/gsm-1.0.tar.Z\r
+\r
+# Clean\r
+\r
+uninstall:     toastuninstall gsmuninstall\r
+               @-echo uninstall: Done.\r
+\r
+semi-clean:\r
+               -rm $(RMFLAGS)  */*.o                   \\r
+                       $(TST)/lin2cod $(TST)/lin2txt   \\r
+                       $(TST)/cod2lin $(TST)/cod2txt   \\r
+                       $(TST)/gsm2cod                  \\r
+                       $(TST)/*.*.*\r
+               -$(FIND) . \( -name core -o -name foo \) \\r
+                       -print | xargs rm $(RMFLAGS)\r
+\r
+clean: semi-clean\r
+               -rm $(RMFLAGS) $(LIBGSM) $(ADDTST)/add          \\r
+                       $(TOAST) $(TCAT) $(UNTOAST)     \\r
+                       $(ROOT)/gsm-1.0.tar.Z\r
+               rm -rf lib\r
+\r
+# Two tools that helped me generate gsm_encode.c and gsm_decode.c,\r
+# but aren't generally needed to port this.\r
+\r
+$(TLS)/sweet:  $(TLS)/sweet.o $(TLS)/taste.o\r
+               $(LD) $(LFLAGS) -o $(TLS)/sweet \\r
+                       $(TLS)/sweet.o $(TLS)/taste.o $(LDLIB)\r
+\r
+$(TLS)/bitter: $(TLS)/bitter.o $(TLS)/taste.o\r
+               $(LD) $(LFLAGS) -o $(TLS)/bitter \\r
+                       $(TLS)/bitter.o $(TLS)/taste.o $(LDLIB)\r
+\r
+# A version of the same family that Jeff Chilton used to implement\r
+# the WAV #49 GSM format.\r
+\r
+$(TLS)/ginger: $(TLS)/ginger.o $(TLS)/taste.o\r
+               $(LD) $(LFLAGS) -o $(TLS)/ginger \\r
+                       $(TLS)/ginger.o $(TLS)/taste.o $(LDLIB)\r
+\r
+$(TLS)/sour:   $(TLS)/sour.o $(TLS)/taste.o\r
+               $(LD) $(LFLAGS) -o $(TLS)/sour \\r
+                       $(TLS)/sour.o $(TLS)/taste.o $(LDLIB)\r
+\r
+# Run $(ADDTST)/add < $(ADDTST)/add_test.dta to make sure the\r
+# basic arithmetic functions work as intended.\r
+\r
+$(ADDTST)/add: $(ADDTST)/add_test.o\r
+               $(LD) $(LFLAGS) -o $(ADDTST)/add $(ADDTST)/add_test.o $(LDLIB)\r
+\r
+\r
+# Various conversion programs between linear, text, .gsm and the code\r
+# format used by the tests we ran (.cod).  We paid for the test data,\r
+# so I guess we can't just provide them with this package.  Still,\r
+# if you happen to have them lying around, here's the code.\r
+# \r
+# You can use gsm2cod | cod2txt independently to look at what's\r
+# coded inside the compressed frames, although this shouldn't be\r
+# hard to roll on your own using the gsm_print() function from\r
+# the API.\r
+\r
+\r
+$(TST)/test-result:    $(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/run\r
+                       ( cd $(TST); ./run ) \r
+\r
+$(TST)/lin2txt:                $(TST)/lin2txt.o $(LIBGSM)\r
+                       $(LD) $(LFLAGS) -o $(TST)/lin2txt \\r
+                               $(TST)/lin2txt.o $(LIBGSM) $(LDLIB)\r
+\r
+$(TST)/lin2cod:                $(TST)/lin2cod.o $(LIBGSM)\r
+                       $(LD) $(LFLAGS) -o $(TST)/lin2cod \\r
+                               $(TST)/lin2cod.o $(LIBGSM) $(LDLIB)\r
+\r
+$(TST)/gsm2cod:                $(TST)/gsm2cod.o $(LIBGSM)\r
+                       $(LD) $(LFLAGS) -o $(TST)/gsm2cod \\r
+                               $(TST)/gsm2cod.o $(LIBGSM) $(LDLIB)\r
+\r
+$(TST)/cod2txt:                $(TST)/cod2txt.o $(LIBGSM)\r
+                       $(LD) $(LFLAGS) -o $(TST)/cod2txt \\r
+                               $(TST)/cod2txt.o $(LIBGSM) $(LDLIB)\r
+\r
+$(TST)/cod2lin:                $(TST)/cod2lin.o $(LIBGSM)\r
+                       $(LD) $(LFLAGS) -o $(TST)/cod2lin \\r
+                               $(TST)/cod2lin.o $(LIBGSM) $(LDLIB)\r
diff --git a/libs/codec/gsm/README b/libs/codec/gsm/README
new file mode 100644 (file)
index 0000000..ebb1f16
--- /dev/null
@@ -0,0 +1,37 @@
+\r
+GSM 06.10 13 kbit/s RPE/LTP speech compression available\r
+--------------------------------------------------------\r
+\r
+The Communications and Operating Systems Research Group (KBS) at the\r
+Technische Universitaet Berlin is currently working on a set of\r
+UNIX-based tools for computer-mediated telecooperation that will be\r
+made freely available.\r
+\r
+As part of this effort we are publishing an implementation of the\r
+European GSM 06.10 provisional standard for full-rate speech\r
+transcoding, prI-ETS 300 036, which uses RPE/LTP (residual pulse\r
+excitation/long term prediction) coding at 13 kbit/s.\r
+\r
+GSM 06.10 compresses frames of 160 13-bit samples (8 kHz sampling\r
+rate, i.e. a frame rate of 50 Hz) into 260 bits; for compatibility\r
+with typical UNIX applications, our implementation turns frames of 160\r
+16-bit linear samples into 33-byte frames (1650 Bytes/s).\r
+The quality of the algorithm is good enough for reliable speaker\r
+recognition; even music often survives transcoding in recognizable \r
+form (given the bandwidth limitations of 8 kHz sampling rate).\r
+\r
+The interfaces offered are a front end modelled after compress(1), and\r
+a library API.  Compression and decompression run faster than realtime\r
+on most SPARCstations.  The implementation has been verified against the\r
+ETSI standard test patterns.\r
+\r
+Jutta Degener (jutta@cs.tu-berlin.de)\r
+Carsten Bormann (cabo@cs.tu-berlin.de)\r
+\r
+Communications and Operating Systems Research Group, TU Berlin\r
+Fax: +49.30.31425156, Phone: +49.30.31424315\r
+\r
+--\r
+Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
diff --git a/libs/codec/gsm/inc/config.h b/libs/codec/gsm/inc/config.h
new file mode 100644 (file)
index 0000000..07b21d1
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/*$Header$*/\r
+\r
+#ifndef        CONFIG_H\r
+#define        CONFIG_H\r
+\r
+#if 0\r
+efine  SIGHANDLER_T    int             /* signal handlers are void     */\r
+efine HAS_SYSV_SIGNAL  1               /* sigs not blocked/reset?      */\r
+#endif\r
+\r
+#define        HAS_STDLIB_H    1               /* /usr/include/stdlib.h        */\r
+#if 0\r
+efine  HAS_LIMITS_H    1               /* /usr/include/limits.h        */\r
+#endif\r
+#define        HAS_FCNTL_H     1               /* /usr/include/fcntl.h         */\r
+#if 0\r
+efine  HAS_ERRNO_DECL  1               /* errno.h declares errno       */\r
+#endif\r
+\r
+#define        HAS_FSTAT       1               /* fstat syscall                */\r
+#define        HAS_FCHMOD      1               /* fchmod syscall               */\r
+#define        HAS_CHMOD       1               /* chmod syscall                */\r
+#define        HAS_FCHOWN      1               /* fchown syscall               */\r
+#define        HAS_CHOWN       1               /* chown syscall                */\r
+#if 0\r
+efine  HAS__FSETMODE   1               /* _fsetmode -- set file mode   */\r
+#endif\r
+\r
+#define        HAS_STRING_H    1               /* /usr/include/string.h        */\r
+#if 0\r
+efine  HAS_STRINGS_H   1               /* /usr/include/strings.h       */\r
+#endif\r
+\r
+#define        HAS_UNISTD_H    1               /* /usr/include/unistd.h        */\r
+#define        HAS_UTIME       1               /* POSIX utime(path, times)     */\r
+#if 0\r
+efine  HAS_UTIMES      1               /* use utimes() syscall instead */\r
+#endif\r
+#define        HAS_UTIME_H     1               /* UTIME header file            */\r
+#if 0\r
+efine  HAS_UTIMBUF     1               /* struct utimbuf               */\r
+efine  HAS_UTIMEUSEC   1               /* microseconds in utimbuf?     */\r
+#endif\r
+\r
+#endif /* CONFIG_H */\r
diff --git a/libs/codec/gsm/inc/gsm.h b/libs/codec/gsm/inc/gsm.h
new file mode 100644 (file)
index 0000000..32a0b48
--- /dev/null
@@ -0,0 +1,71 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/*$Header$*/\r
+\r
+#ifndef        GSM_H\r
+#define        GSM_H\r
+\r
+#ifdef __cplusplus\r
+#      define  NeedFunctionPrototypes  1\r
+#endif\r
+\r
+#if __STDC__\r
+#      define  NeedFunctionPrototypes  1\r
+#endif\r
+\r
+#ifdef _NO_PROTO\r
+#      undef   NeedFunctionPrototypes\r
+#endif\r
+\r
+#ifdef NeedFunctionPrototypes\r
+#   include    <stdio.h>               /* for FILE *   */\r
+#endif\r
+\r
+#undef GSM_P\r
+#if NeedFunctionPrototypes\r
+#      define  GSM_P( protos ) protos\r
+#else\r
+#      define  GSM_P( protos ) ( /* protos */ )\r
+#endif\r
+\r
+/*\r
+ *     Interface\r
+ */\r
+\r
+typedef struct gsm_state *     gsm;\r
+typedef short                  gsm_signal;             /* signed 16 bit */\r
+typedef unsigned char          gsm_byte;\r
+typedef gsm_byte               gsm_frame[33];          /* 33 * 8 bits   */\r
+\r
+#define        GSM_MAGIC               0xD                     /* 13 kbit/s RPE-LTP */\r
+\r
+#define        GSM_PATCHLEVEL          10\r
+#define        GSM_MINOR               0\r
+#define        GSM_MAJOR               1\r
+\r
+#define        GSM_OPT_VERBOSE         1\r
+#define        GSM_OPT_FAST            2\r
+#define        GSM_OPT_LTP_CUT         3\r
+#define        GSM_OPT_WAV49           4\r
+#define        GSM_OPT_FRAME_INDEX     5\r
+#define        GSM_OPT_FRAME_CHAIN     6\r
+\r
+extern gsm  gsm_create         GSM_P((void));\r
+extern void gsm_destroy GSM_P((gsm));  \r
+\r
+extern int  gsm_print   GSM_P((FILE *, gsm, gsm_byte  *));\r
+extern int  gsm_option  GSM_P((gsm, int, int *));\r
+\r
+extern void gsm_encode  GSM_P((gsm, gsm_signal *, gsm_byte  *));\r
+extern int  gsm_decode  GSM_P((gsm, gsm_byte   *, gsm_signal *));\r
+\r
+extern int  gsm_explode GSM_P((gsm, gsm_byte   *, gsm_signal *));\r
+extern void gsm_implode GSM_P((gsm, gsm_signal *, gsm_byte   *));\r
+\r
+#undef GSM_P\r
+\r
+#endif /* GSM_H */\r
diff --git a/libs/codec/gsm/inc/private.h b/libs/codec/gsm/inc/private.h
new file mode 100644 (file)
index 0000000..63a70a0
--- /dev/null
@@ -0,0 +1,313 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/*$Header$*/\r
+\r
+#ifndef        PRIVATE_H\r
+#define        PRIVATE_H\r
+\r
+typedef short                  word;           /* 16 bit signed int    */\r
+typedef long                   longword;       /* 32 bit signed int    */\r
+\r
+typedef unsigned short         uword;          /* unsigned word        */\r
+typedef unsigned long          ulongword;      /* unsigned longword    */\r
+\r
+struct gsm_state {\r
+\r
+       word            dp0[ 280 ];\r
+\r
+       word            z1;             /* preprocessing.c, Offset_com. */\r
+       longword        L_z2;           /*                  Offset_com. */\r
+       int             mp;             /*                  Preemphasis */\r
+\r
+       word            u[8];           /* short_term_aly_filter.c      */\r
+       word            LARpp[2][8];    /*                              */\r
+       word            j;              /*                              */\r
+\r
+       word            ltp_cut;        /* long_term.c, LTP crosscorr.  */\r
+       word            nrp; /* 40 */   /* long_term.c, synthesis       */\r
+       word            v[9];           /* short_term.c, synthesis      */\r
+       word            msr;            /* decoder.c,   Postprocessing  */\r
+\r
+       char            verbose;        /* only used if !NDEBUG         */\r
+       char            fast;           /* only used if FAST            */\r
+\r
+       char            wav_fmt;        /* only used if WAV49 defined   */\r
+       unsigned char   frame_index;    /*            odd/even chaining */\r
+       unsigned char   frame_chain;    /*   half-byte to carry forward */\r
+};\r
+\r
+\r
+#define        MIN_WORD        (-32767 - 1)\r
+#define        MAX_WORD          32767\r
+\r
+#define        MIN_LONGWORD    (-2147483647 - 1)\r
+#define        MAX_LONGWORD      2147483647\r
+\r
+#ifdef SASR            /* flag: >> is a signed arithmetic shift right */\r
+#undef SASR\r
+#define        SASR(x, by)     ((x) >> (by))\r
+#else\r
+#define        SASR(x, by)     ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))\r
+#endif /* SASR */\r
+\r
+#include "proto.h"\r
+\r
+/*\r
+ *     Prototypes from add.c\r
+ */\r
+extern word    gsm_mult        P((word a, word b));\r
+extern longword gsm_L_mult     P((word a, word b));\r
+extern word    gsm_mult_r      P((word a, word b));\r
+\r
+extern word    gsm_div         P((word num, word denum));\r
+\r
+extern word    gsm_add         P(( word a, word b ));\r
+extern longword gsm_L_add      P(( longword a, longword b ));\r
+\r
+extern word    gsm_sub         P((word a, word b));\r
+extern longword gsm_L_sub      P((longword a, longword b));\r
+\r
+extern word    gsm_abs         P((word a));\r
+\r
+extern word    gsm_norm        P(( longword a ));\r
+\r
+extern longword gsm_L_asl      P((longword a, int n));\r
+extern word    gsm_asl         P((word a, int n));\r
+\r
+extern longword gsm_L_asr      P((longword a, int n));\r
+extern word    gsm_asr         P((word a, int n));\r
+\r
+/*\r
+ *  Inlined functions from add.h \r
+ */\r
+\r
+/* \r
+ * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *)        \\r
+ *     (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))\r
+ */\r
+#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */   \\r
+       (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))\r
+\r
+# define GSM_MULT(a,b)  /* word a, word b, !(a == b == MIN_WORD) */    \\r
+       (SASR( ((longword)(a) * (longword)(b)), 15 ))\r
+\r
+# define GSM_L_MULT(a, b) /* word a, word b */ \\r
+       (((longword)(a) * (longword)(b)) << 1)\r
+\r
+#if defined(__GNUC__) && defined(__i386__)\r
+\r
+static __inline__ int GSM_L_ADD(int a, int b)\r
+{\r
+       __asm__ __volatile__(\r
+       \r
+                       "addl %2,%0; jno 0f; movl $0x7fffffff,%0; adcl $0,%0; 0:"\r
+                       : "=r" (a)\r
+                       : "0" (a), "ir" (b)\r
+                       : "cc"\r
+               );\r
+       return(a);\r
+}\r
+\r
+static __inline__ short GSM_ADD(short a, short b)\r
+{\r
+       __asm__ __volatile__(\r
+                       "addw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"\r
+                       : "=r" (a)\r
+                       : "0" (a), "ir" (b)\r
+                       : "cc"\r
+               );\r
+       return(a);\r
+}\r
+\r
+static __inline__ short GSM_SUB(short a, short b)\r
+{\r
+       __asm__ __volatile__(\r
+                       "subw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"\r
+                       : "=r" (a)\r
+                       : "0" (a), "ir" (b)\r
+                       : "cc"\r
+               );\r
+       return(a);\r
+}\r
+\r
+#else\r
+\r
+# define GSM_L_ADD(a, b)       \\r
+       ( (a) <  0 ? ( (b) >= 0 ? (a) + (b)     \\r
+                : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \\r
+                  >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 )   \\r
+       : ((b) <= 0 ? (a) + (b)   \\r
+                 : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \\r
+                   ? MAX_LONGWORD : utmp))\r
+\r
+/*\r
+ * # define GSM_ADD(a, b)      \\r
+ *     ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \\r
+ *     ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)\r
+ */\r
+/* Nonportable, but faster: */\r
+\r
+# define GSM_ADD(a, b) ({ \\r
+               register longword ltmp; \\r
+               ltmp = (longword) (a) + (longword) (b); \\r
+               ((ulongword) (ltmp - MIN_WORD) > MAX_WORD - MIN_WORD ? \\r
+                       (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp); \\r
+       })\r
+\r
+#define GSM_SUB(a, b) ({ \\r
+               register longword ltmp; \\r
+               ltmp = (longword) (a) - (longword) (b); \\r
+               (ltmp >= MAX_WORD ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp); \\r
+       })\r
+\r
+#endif\r
+\r
+# define GSM_ABS(a)    ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))\r
+\r
+/* Use these if necessary:\r
+\r
+# define GSM_MULT_R(a, b)      gsm_mult_r(a, b)\r
+# define GSM_MULT(a, b)                gsm_mult(a, b)\r
+# define GSM_L_MULT(a, b)      gsm_L_mult(a, b)\r
+\r
+# define GSM_L_ADD(a, b)       gsm_L_add(a, b)\r
+# define GSM_ADD(a, b)         gsm_add(a, b)\r
+# define GSM_SUB(a, b)         gsm_sub(a, b)\r
+\r
+# define GSM_ABS(a)            gsm_abs(a)\r
+\r
+*/\r
+\r
+/*\r
+ *  More prototypes from implementations..\r
+ */\r
+extern void Gsm_Coder P((\r
+               struct gsm_state        * S,\r
+               word    * s,    /* [0..159] samples             IN      */\r
+               word    * LARc, /* [0..7] LAR coefficients      OUT     */\r
+               word    * Nc,   /* [0..3] LTP lag               OUT     */\r
+               word    * bc,   /* [0..3] coded LTP gain        OUT     */\r
+               word    * Mc,   /* [0..3] RPE grid selection    OUT     */\r
+               word    * xmaxc,/* [0..3] Coded maximum amplitude OUT   */\r
+               word    * xMc   /* [13*4] normalized RPE samples OUT    */));\r
+\r
+extern void Gsm_Long_Term_Predictor P((                /* 4x for 160 samples */\r
+               struct gsm_state * S,\r
+               word    * d,    /* [0..39]   residual signal    IN      */\r
+               word    * dp,   /* [-120..-1] d'                IN      */\r
+               word    * e,    /* [0..40]                      OUT     */\r
+               word    * dpp,  /* [0..40]                      OUT     */\r
+               word    * Nc,   /* correlation lag              OUT     */\r
+               word    * bc    /* gain factor                  OUT     */));\r
+\r
+extern void Gsm_LPC_Analysis P((\r
+               struct gsm_state * S,\r
+               word * s,        /* 0..159 signals      IN/OUT  */\r
+               word * LARc));   /* 0..7   LARc's       OUT     */\r
+\r
+extern void Gsm_Preprocess P((\r
+               struct gsm_state * S,\r
+               word * s, word * so));\r
+\r
+extern void Gsm_Encoding P((\r
+               struct gsm_state * S,\r
+               word    * e,    \r
+               word    * ep,   \r
+               word    * xmaxc,\r
+               word    * Mc,   \r
+               word    * xMc));\r
+\r
+extern void Gsm_Short_Term_Analysis_Filter P((\r
+               struct gsm_state * S,\r
+               word    * LARc, /* coded log area ratio [0..7]  IN      */\r
+               word    * d     /* st res. signal [0..159]      IN/OUT  */));\r
+\r
+extern void Gsm_Decoder P((\r
+               struct gsm_state * S,\r
+               word    * LARcr,        /* [0..7]               IN      */\r
+               word    * Ncr,          /* [0..3]               IN      */\r
+               word    * bcr,          /* [0..3]               IN      */\r
+               word    * Mcr,          /* [0..3]               IN      */\r
+               word    * xmaxcr,       /* [0..3]               IN      */\r
+               word    * xMcr,         /* [0..13*4]            IN      */\r
+               word    * s));          /* [0..159]             OUT     */\r
+\r
+extern void Gsm_Decoding P((\r
+               struct gsm_state * S,\r
+               word    xmaxcr,\r
+               word    Mcr,\r
+               word    * xMcr,         /* [0..12]              IN      */\r
+               word    * erp));        /* [0..39]              OUT     */\r
+\r
+extern void Gsm_Long_Term_Synthesis_Filtering P((\r
+               struct gsm_state* S,\r
+               word    Ncr,\r
+               word    bcr,\r
+               word    * erp,          /* [0..39]                IN    */\r
+               word    * drp));        /* [-120..-1] IN, [0..40] OUT   */\r
+\r
+void Gsm_RPE_Decoding P((\r
+       struct gsm_state *S,\r
+               word xmaxcr,\r
+               word Mcr,\r
+               word * xMcr,  /* [0..12], 3 bits             IN      */\r
+               word * erp)); /* [0..39]                     OUT     */\r
+\r
+void Gsm_RPE_Encoding P((\r
+               struct gsm_state * S,\r
+               word    * e,            /* -5..-1][0..39][40..44     IN/OUT  */\r
+               word    * xmaxc,        /*                              OUT */\r
+               word    * Mc,           /*                              OUT */\r
+               word    * xMc));        /* [0..12]                      OUT */\r
+\r
+extern void Gsm_Short_Term_Synthesis_Filter P((\r
+               struct gsm_state * S,\r
+               word    * LARcr,        /* log area ratios [0..7]  IN   */\r
+               word    * drp,          /* received d [0...39]     IN   */\r
+               word    * s));          /* signal   s [0..159]    OUT   */\r
+\r
+extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((\r
+               word    * dpp,          /* [0...39]     IN      */\r
+               word    * ep,           /* [0...39]     IN      */\r
+               word    * dp));         /* [-120...-1]  IN/OUT  */\r
+\r
+/*\r
+ *  Tables from table.c\r
+ */\r
+#ifndef        GSM_TABLE_C\r
+\r
+extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];\r
+extern word gsm_INVA[8];\r
+extern word gsm_DLB[4], gsm_QLB[4];\r
+extern word gsm_H[11];\r
+extern word gsm_NRFAC[8];\r
+extern word gsm_FAC[8];\r
+\r
+#endif /* GSM_TABLE_C */\r
+\r
+/*\r
+ *  Debugging\r
+ */\r
+#ifdef NDEBUG\r
+\r
+#      define  gsm_debug_words(a, b, c, d)             /* nil */\r
+#      define  gsm_debug_longwords(a, b, c, d)         /* nil */\r
+#      define  gsm_debug_word(a, b)                    /* nil */\r
+#      define  gsm_debug_longword(a, b)                /* nil */\r
+\r
+#else  /* !NDEBUG => DEBUG */\r
+\r
+       extern void  gsm_debug_words     P((char * name, int, int, word *));\r
+       extern void  gsm_debug_longwords P((char * name, int, int, longword *));\r
+       extern void  gsm_debug_longword  P((char * name, longword));\r
+       extern void  gsm_debug_word      P((char * name, word));\r
+\r
+#endif /* !NDEBUG */\r
+\r
+#include "unproto.h"\r
+\r
+#endif /* PRIVATE_H */\r
diff --git a/libs/codec/gsm/inc/proto.h b/libs/codec/gsm/inc/proto.h
new file mode 100644 (file)
index 0000000..17a5f74
--- /dev/null
@@ -0,0 +1,65 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/*$Header$*/\r
+\r
+#ifndef        PROTO_H\r
+#define        PROTO_H\r
+\r
+#if __cplusplus\r
+#      define  NeedFunctionPrototypes  1\r
+#endif\r
+\r
+#if __STDC__\r
+#      define  NeedFunctionPrototypes  1\r
+#endif\r
+\r
+#ifdef _NO_PROTO\r
+#      undef   NeedFunctionPrototypes\r
+#endif\r
+\r
+#undef P       /* gnu stdio.h actually defines this...         */\r
+#undef P0\r
+#undef P1\r
+#undef P2\r
+#undef P3\r
+#undef P4\r
+#undef P5\r
+#undef P6\r
+#undef P7\r
+#undef P8\r
+\r
+#if NeedFunctionPrototypes\r
+\r
+#      define  P( protos )     protos\r
+\r
+#      define  P0()                            (void)\r
+#      define  P1(x, a)                        (a)\r
+#      define  P2(x, a, b)                     (a, b)\r
+#      define  P3(x, a, b, c)                  (a, b, c)\r
+#      define  P4(x, a, b, c, d)               (a, b, c, d)    \r
+#      define  P5(x, a, b, c, d, e)            (a, b, c, d, e)\r
+#      define  P6(x, a, b, c, d, e, f)         (a, b, c, d, e, f)\r
+#      define  P7(x, a, b, c, d, e, f, g)      (a, b, c, d, e, f, g)\r
+#      define  P8(x, a, b, c, d, e, f, g, h)   (a, b, c, d, e, f, g, h)\r
+\r
+#else /* !NeedFunctionPrototypes */\r
+\r
+#      define  P( protos )     ( /* protos */ )\r
+\r
+#      define  P0()                            ()\r
+#      define  P1(x, a)                        x a;\r
+#      define  P2(x, a, b)                     x a; b;\r
+#      define  P3(x, a, b, c)                  x a; b; c;\r
+#      define  P4(x, a, b, c, d)               x a; b; c; d;\r
+#      define  P5(x, a, b, c, d, e)            x a; b; c; d; e;\r
+#      define  P6(x, a, b, c, d, e, f)         x a; b; c; d; e; f;\r
+#      define  P7(x, a, b, c, d, e, f, g)      x a; b; c; d; e; f; g;\r
+#      define  P8(x, a, b, c, d, e, f, g, h)   x a; b; c; d; e; f; g; h;\r
+\r
+#endif  /* !NeedFunctionPrototypes */\r
+\r
+#endif /* PROTO_H */\r
diff --git a/libs/codec/gsm/inc/unproto.h b/libs/codec/gsm/inc/unproto.h
new file mode 100644 (file)
index 0000000..ce09e1a
--- /dev/null
@@ -0,0 +1,23 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/*$Header$*/\r
+\r
+#ifdef PROTO_H         /* sic */\r
+#undef PROTO_H\r
+\r
+#undef P\r
+#undef P0\r
+#undef P1\r
+#undef P2\r
+#undef P3\r
+#undef P4\r
+#undef P5\r
+#undef P6\r
+#undef P7\r
+#undef P8\r
+\r
+#endif /* PROTO_H */\r
diff --git a/libs/codec/gsm/src/add.c b/libs/codec/gsm/src/add.c
new file mode 100644 (file)
index 0000000..9c5171e
--- /dev/null
@@ -0,0 +1,235 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+/*\r
+ *  See private.h for the more commonly used macro versions.\r
+ */\r
+\r
+#include       <stdio.h>\r
+#include       <assert.h>\r
+\r
+#include       "private.h"\r
+#include       "gsm.h"\r
+#include       "proto.h"\r
+\r
+#define        saturate(x)     \\r
+       ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))\r
+\r
+word gsm_add P2((a,b), word a, word b)\r
+{\r
+       longword sum = (longword)a + (longword)b;\r
+       return saturate(sum);\r
+}\r
+\r
+word gsm_sub P2((a,b), word a, word b)\r
+{\r
+       longword diff = (longword)a - (longword)b;\r
+       return saturate(diff);\r
+}\r
+\r
+word gsm_mult P2((a,b), word a, word b)\r
+{\r
+       if (a == MIN_WORD && b == MIN_WORD) return MAX_WORD;\r
+       else return SASR( (longword)a * (longword)b, 15 );\r
+}\r
+\r
+word gsm_mult_r P2((a,b), word a, word b)\r
+{\r
+       if (b == MIN_WORD && a == MIN_WORD) return MAX_WORD;\r
+       else {\r
+               longword prod = (longword)a * (longword)b + 16384;\r
+               prod >>= 15;\r
+               return prod & 0xFFFF;\r
+       }\r
+}\r
+\r
+word gsm_abs P1((a), word a)\r
+{\r
+       return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;\r
+}\r
+\r
+longword gsm_L_mult P2((a,b),word a, word b)\r
+{\r
+       assert( a != MIN_WORD || b != MIN_WORD );\r
+       return ((longword)a * (longword)b) << 1;\r
+}\r
+\r
+longword gsm_L_add P2((a,b), longword a, longword b)\r
+{\r
+       if (a < 0) {\r
+               if (b >= 0) return a + b;\r
+               else {\r
+                       ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);\r
+                       return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;\r
+               }\r
+       }\r
+       else if (b <= 0) return a + b;\r
+       else {\r
+               ulongword A = (ulongword)a + (ulongword)b;\r
+               return A > MAX_LONGWORD ? MAX_LONGWORD : A;\r
+       }\r
+}\r
+\r
+longword gsm_L_sub P2((a,b), longword a, longword b)\r
+{\r
+       if (a >= 0) {\r
+               if (b >= 0) return a - b;\r
+               else {\r
+                       /* a>=0, b<0 */\r
+\r
+                       ulongword A = (ulongword)a + -(b + 1);\r
+                       return A >= MAX_LONGWORD ? MAX_LONGWORD : (A + 1);\r
+               }\r
+       }\r
+       else if (b <= 0) return a - b;\r
+       else {\r
+               /* a<0, b>0 */  \r
+\r
+               ulongword A = (ulongword)-(a + 1) + b;\r
+               return A >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)A - 1;\r
+       }\r
+}\r
+\r
+static unsigned char const bitoff[ 256 ] = {\r
+        8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,\r
+        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
+};\r
+\r
+word gsm_norm P1((a), longword a )\r
+/*\r
+ * the number of left shifts needed to normalize the 32 bit\r
+ * variable L_var1 for positive values on the interval\r
+ *\r
+ * with minimum of\r
+ * minimum of 1073741824  (01000000000000000000000000000000) and \r
+ * maximum of 2147483647  (01111111111111111111111111111111)\r
+ *\r
+ *\r
+ * and for negative values on the interval with\r
+ * minimum of -2147483648 (-10000000000000000000000000000000) and\r
+ * maximum of -1073741824 ( -1000000000000000000000000000000).\r
+ *\r
+ * in order to normalize the result, the following\r
+ * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 );\r
+ *\r
+ * (That's 'ffs', only from the left, not the right..)\r
+ */\r
+{\r
+       assert(a != 0);\r
+\r
+       if (a < 0) {\r
+               if (a <= -1073741824) return 0;\r
+               a = ~a;\r
+       }\r
+\r
+       return    a & 0xffff0000 \r
+               ? ( a & 0xff000000\r
+                 ?  -1 + bitoff[ 0xFF & (a >> 24) ]\r
+                 :   7 + bitoff[ 0xFF & (a >> 16) ] )\r
+               : ( a & 0xff00\r
+                 ?  15 + bitoff[ 0xFF & (a >> 8) ]\r
+                 :  23 + bitoff[ 0xFF & a ] );\r
+}\r
+\r
+longword gsm_L_asl P2((a,n), longword a, int n)\r
+{\r
+       if (n >= 32) return 0;\r
+       if (n <= -32) return -(a < 0);\r
+       if (n < 0) return gsm_L_asr(a, -n);\r
+       return a << n;\r
+}\r
+\r
+word gsm_asl P2((a,n), word a, int n)\r
+{\r
+       if (n >= 16) return 0;\r
+       if (n <= -16) return -(a < 0);\r
+       if (n < 0) return gsm_asr(a, -n);\r
+       return a << n;\r
+}\r
+\r
+longword gsm_L_asr P2((a,n), longword a, int n)\r
+{\r
+       if (n >= 32) return -(a < 0);\r
+       if (n <= -32) return 0;\r
+       if (n < 0) return a << -n;\r
+\r
+#      ifdef   SASR\r
+               return a >> n;\r
+#      else\r
+               if (a >= 0) return a >> n;\r
+               else return -(longword)( -(ulongword)a >> n );\r
+#      endif\r
+}\r
+\r
+word gsm_asr P2((a,n), word a, int n)\r
+{\r
+       if (n >= 16) return -(a < 0);\r
+       if (n <= -16) return 0;\r
+       if (n < 0) return a << -n;\r
+\r
+#      ifdef   SASR\r
+               return a >> n;\r
+#      else\r
+               if (a >= 0) return a >> n;\r
+               else return -(word)( -(uword)a >> n );\r
+#      endif\r
+}\r
+\r
+/* \r
+ *  (From p. 46, end of section 4.2.5)\r
+ *\r
+ *  NOTE: The following lines gives [sic] one correct implementation\r
+ *       of the div(num, denum) arithmetic operation.  Compute div\r
+ *        which is the integer division of num by denum: with denum\r
+ *       >= num > 0\r
+ */\r
+\r
+word gsm_div P2((num,denum), word num, word denum)\r
+{\r
+       longword        L_num   = num;\r
+       longword        L_denum = denum;\r
+       word            div     = 0;\r
+       int             k       = 15;\r
+\r
+       /* The parameter num sometimes becomes zero.\r
+        * Although this is explicitly guarded against in 4.2.5,\r
+        * we assume that the result should then be zero as well.\r
+        */\r
+\r
+       /* assert(num != 0); */\r
+\r
+       assert(num >= 0 && denum >= num);\r
+       if (num == 0)\r
+           return 0;\r
+\r
+       while (k--) {\r
+               div   <<= 1;\r
+               L_num <<= 1;\r
+\r
+               if (L_num >= L_denum) {\r
+                       L_num -= L_denum;\r
+                       div++;\r
+               }\r
+       }\r
+\r
+       return div;\r
+}\r
diff --git a/libs/codec/gsm/src/code.c b/libs/codec/gsm/src/code.c
new file mode 100644 (file)
index 0000000..14c5f6c
--- /dev/null
@@ -0,0 +1,101 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include       "config.h"\r
+\r
+#ifdef HAS_STRING_H\r
+#include       <string.h>\r
+#else\r
+#      include "proto.h"\r
+       extern char     * memcpy P((char *, char *, int));\r
+#endif\r
+\r
+#include       "private.h"\r
+#include       "gsm.h"\r
+#include       "proto.h"\r
+\r
+/* \r
+ *  4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER \r
+ */\r
+\r
+void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc),\r
+\r
+       struct gsm_state        * S,\r
+\r
+       word    * s,    /* [0..159] samples                     IN      */\r
+\r
+/*\r
+ * The RPE-LTD coder works on a frame by frame basis.  The length of\r
+ * the frame is equal to 160 samples.  Some computations are done\r
+ * once per frame to produce at the output of the coder the\r
+ * LARc[1..8] parameters which are the coded LAR coefficients and \r
+ * also to realize the inverse filtering operation for the entire\r
+ * frame (160 samples of signal d[0..159]).  These parts produce at\r
+ * the output of the coder:\r
+ */\r
+\r
+       word    * LARc, /* [0..7] LAR coefficients              OUT     */\r
+\r
+/*\r
+ * Procedure 4.2.11 to 4.2.18 are to be executed four times per\r
+ * frame.  That means once for each sub-segment RPE-LTP analysis of\r
+ * 40 samples.  These parts produce at the output of the coder:\r
+ */\r
+\r
+       word    * Nc,   /* [0..3] LTP lag                       OUT     */\r
+       word    * bc,   /* [0..3] coded LTP gain                OUT     */\r
+       word    * Mc,   /* [0..3] RPE grid selection            OUT     */\r
+       word    * xmaxc,/* [0..3] Coded maximum amplitude       OUT     */\r
+       word    * xMc   /* [13*4] normalized RPE samples        OUT     */\r
+)\r
+{\r
+       int     k;\r
+       word    * dp  = S->dp0 + 120;   /* [ -120...-1 ] */\r
+       word    * dpp = dp;             /* [ 0...39 ]    */\r
+\r
+       static word e[50];\r
+\r
+       word    so[160];\r
+\r
+#if !(defined(__GNUC__) && defined(__i386__))\r
+       longword ltmp;\r
+#endif\r
+\r
+       Gsm_Preprocess                  (S, s, so);\r
+       Gsm_LPC_Analysis                (S, so, LARc);\r
+       Gsm_Short_Term_Analysis_Filter  (S, LARc, so);\r
+\r
+       for (k = 0; k <= 3; k++, xMc += 13) {\r
+\r
+               Gsm_Long_Term_Predictor ( S,\r
+                                        so+k*40, /* d      [0..39] IN  */\r
+                                        dp,      /* dp  [-120..-1] IN  */\r
+                                       e + 5,    /* e      [0..39] OUT */\r
+                                       dpp,      /* dpp    [0..39] OUT */\r
+                                        Nc++,\r
+                                        bc++);\r
+\r
+               Gsm_RPE_Encoding        ( S,\r
+                                       e + 5,  /* e      ][0..39][ IN/OUT */\r
+                                         xmaxc++, Mc++, xMc );\r
+               /*\r
+                * Gsm_Update_of_reconstructed_short_time_residual_signal\r
+                *                      ( dpp, e + 5, dp );\r
+                */\r
+\r
+               { register int i;\r
+                 for (i = 0; i <= 39; i++)\r
+                       dp[ i ] = GSM_ADD( e[5 + i], dpp[i] );\r
+               }\r
+               dp  += 40;\r
+               dpp += 40;\r
+\r
+       }\r
+       (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),\r
+               120 * sizeof(*S->dp0) );\r
+}\r
diff --git a/libs/codec/gsm/src/debug.c b/libs/codec/gsm/src/debug.c
new file mode 100644 (file)
index 0000000..031a7f8
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+\r
+#ifndef        NDEBUG\r
+\r
+/* If NDEBUG _is_ defined and no debugging should be performed,\r
+ * calls to functions in this module are #defined to nothing\r
+ * in private.h.\r
+ */\r
+\r
+#include <stdio.h>\r
+#include "proto.h"\r
+\r
+void gsm_debug_words P4( (name, from, to, ptr), \r
+       char          * name,\r
+       int             from,\r
+       int             to,\r
+       word            * ptr)\r
+{\r
+       int     nprinted = 0;\r
+\r
+       fprintf( stderr, "%s [%d .. %d]: ", name, from, to );\r
+       while (from <= to) {\r
+               fprintf(stderr, "%d ", ptr[ from ] );\r
+               from++;\r
+               if (nprinted++ >= 7) {\r
+                       nprinted = 0;\r
+                       if (from < to) putc('\n', stderr);\r
+               }\r
+       }\r
+       putc('\n', stderr);\r
+}\r
+\r
+void gsm_debug_longwords P4( (name, from, to, ptr),\r
+       char          * name,\r
+       int             from,\r
+       int             to,\r
+       longword      * ptr)\r
+{\r
+       int     nprinted = 0;\r
+\r
+       fprintf( stderr, "%s [%d .. %d]: ", name, from, to );\r
+       while (from <= to) {\r
+\r
+               fprintf(stderr, "%d ", ptr[ from ] );\r
+               from++;\r
+               if (nprinted++ >= 7) {\r
+                       nprinted = 0;\r
+                       if (from < to) putc('\n', stderr);\r
+               }\r
+       }\r
+       putc('\n', stderr);\r
+}\r
+\r
+void gsm_debug_longword P2(  (name, value),\r
+       char            * name,\r
+       longword          value )\r
+{\r
+       fprintf(stderr, "%s: %d\n", name, (long)value );\r
+}\r
+\r
+void gsm_debug_word P2(  (name, value),\r
+       char    * name,\r
+       word      value )\r
+{\r
+       fprintf(stderr, "%s: %d\n", name, (long)value);\r
+}\r
+\r
+#endif\r
diff --git a/libs/codec/gsm/src/decode.c b/libs/codec/gsm/src/decode.c
new file mode 100644 (file)
index 0000000..7039b5b
--- /dev/null
@@ -0,0 +1,62 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include <stdio.h>\r
+\r
+#include       "private.h"\r
+#include       "gsm.h"\r
+#include       "proto.h"\r
+\r
+/*\r
+ *  4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER\r
+ */\r
+\r
+static void Postprocessing P2((S,s),\r
+       struct gsm_state        * S,\r
+       register word           * s)\r
+{\r
+       register int            k;\r
+       register word           msr = S->msr;\r
+       register word           tmp;\r
+\r
+       for (k = 160; k--; s++) {\r
+               tmp = GSM_MULT_R( msr, 28180 );\r
+               msr = GSM_ADD(*s, tmp);            /* Deemphasis             */\r
+               *s  = GSM_ADD(msr, msr) & 0xFFF8;  /* Truncation & Upscaling */\r
+       }\r
+       S->msr = msr;\r
+}\r
+\r
+void Gsm_Decoder P8((S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s),\r
+       struct gsm_state        * S,\r
+\r
+       word            * LARcr,        /* [0..7]               IN      */\r
+\r
+       word            * Ncr,          /* [0..3]               IN      */\r
+       word            * bcr,          /* [0..3]               IN      */\r
+       word            * Mcr,          /* [0..3]               IN      */\r
+       word            * xmaxcr,       /* [0..3]               IN      */\r
+       word            * xMcr,         /* [0..13*4]            IN      */\r
+\r
+       word            * s)            /* [0..159]             OUT     */\r
+{\r
+       int             j, k;\r
+       word            erp[40], wt[160];\r
+       word            * drp = S->dp0 + 120;\r
+\r
+       for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {\r
+\r
+               Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );\r
+               Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );\r
+\r
+               for (k = 0; k <= 39; k++) wt[ j * 40 + k ] =  drp[ k ];\r
+       }\r
+\r
+       Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );\r
+       Postprocessing(S, s);\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_create.c b/libs/codec/gsm/src/gsm_create.c
new file mode 100644 (file)
index 0000000..884549e
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+static char const      ident[] = "$Header$";\r
+\r
+#include       "config.h"\r
+\r
+#ifdef HAS_STRING_H\r
+#include       <string.h>\r
+#else\r
+#      include "proto.h"\r
+       extern char     * memset P((char *, int, int));\r
+#endif\r
+\r
+#ifdef HAS_STDLIB_H\r
+#      include <stdlib.h>\r
+#else\r
+#      ifdef   HAS_MALLOC_H\r
+#              include         <malloc.h>\r
+#      else\r
+               extern char * malloc();\r
+#      endif\r
+#endif\r
+\r
+#include <stdio.h>\r
+\r
+#include "gsm.h"\r
+#include "private.h"\r
+#include "proto.h"\r
+\r
+gsm gsm_create P0()\r
+{\r
+       gsm  r;\r
+\r
+       r = (gsm)malloc(sizeof(struct gsm_state));\r
+       if (!r) return r;\r
+\r
+       memset((char *)r, 0, sizeof(*r));\r
+       r->nrp = 40;\r
+\r
+       return r;\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_decode.c b/libs/codec/gsm/src/gsm_decode.c
new file mode 100644 (file)
index 0000000..0fa6d3e
--- /dev/null
@@ -0,0 +1,361 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+int gsm_decode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target)\r
+{\r
+       word    LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];\r
+\r
+#ifdef WAV49\r
+       if (s->wav_fmt) {\r
+\r
+               uword sr = 0;\r
+\r
+               s->frame_index = !s->frame_index;\r
+               if (s->frame_index) {\r
+\r
+                       sr = *c++;\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 4;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;                 /* 5 */\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 10 */\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 15 */\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;                 /* 20 */\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 25 */\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 30 */\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+\r
+                       s->frame_chain = sr & 0xf;\r
+               }\r
+               else {\r
+                       sr = s->frame_chain;\r
+                       sr |= (uword)*c++ << 4;                 /* 1 */\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr = *c++;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 3;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 5 */\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 10 */\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 15 */\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;                 /* 20 */\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1; \r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 25 */\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;         \r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 30 */\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+               }\r
+       }\r
+       else\r
+#endif\r
+       {\r
+               /* GSM_MAGIC  = (*c >> 4) & 0xF; */\r
+\r
+               if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;\r
+\r
+               LARc[0]  = (*c++ & 0xF) << 2;           /* 1 */\r
+               LARc[0] |= (*c >> 6) & 0x3;\r
+               LARc[1]  = *c++ & 0x3F;\r
+               LARc[2]  = (*c >> 3) & 0x1F;\r
+               LARc[3]  = (*c++ & 0x7) << 2;\r
+               LARc[3] |= (*c >> 6) & 0x3;\r
+               LARc[4]  = (*c >> 2) & 0xF;\r
+               LARc[5]  = (*c++ & 0x3) << 2;\r
+               LARc[5] |= (*c >> 6) & 0x3;\r
+               LARc[6]  = (*c >> 3) & 0x7;\r
+               LARc[7]  = *c++ & 0x7;\r
+               Nc[0]  = (*c >> 1) & 0x7F;\r
+               bc[0]  = (*c++ & 0x1) << 1;\r
+               bc[0] |= (*c >> 7) & 0x1;\r
+               Mc[0]  = (*c >> 5) & 0x3;\r
+               xmaxc[0]  = (*c++ & 0x1F) << 1;\r
+               xmaxc[0] |= (*c >> 7) & 0x1;\r
+               xmc[0]  = (*c >> 4) & 0x7;\r
+               xmc[1]  = (*c >> 1) & 0x7;\r
+               xmc[2]  = (*c++ & 0x1) << 2;\r
+               xmc[2] |= (*c >> 6) & 0x3;\r
+               xmc[3]  = (*c >> 3) & 0x7;\r
+               xmc[4]  = *c++ & 0x7;\r
+               xmc[5]  = (*c >> 5) & 0x7;\r
+               xmc[6]  = (*c >> 2) & 0x7;\r
+               xmc[7]  = (*c++ & 0x3) << 1;            /* 10 */\r
+               xmc[7] |= (*c >> 7) & 0x1;\r
+               xmc[8]  = (*c >> 4) & 0x7;\r
+               xmc[9]  = (*c >> 1) & 0x7;\r
+               xmc[10]  = (*c++ & 0x1) << 2;\r
+               xmc[10] |= (*c >> 6) & 0x3;\r
+               xmc[11]  = (*c >> 3) & 0x7;\r
+               xmc[12]  = *c++ & 0x7;\r
+               Nc[1]  = (*c >> 1) & 0x7F;\r
+               bc[1]  = (*c++ & 0x1) << 1;\r
+               bc[1] |= (*c >> 7) & 0x1;\r
+               Mc[1]  = (*c >> 5) & 0x3;\r
+               xmaxc[1]  = (*c++ & 0x1F) << 1;\r
+               xmaxc[1] |= (*c >> 7) & 0x1;\r
+               xmc[13]  = (*c >> 4) & 0x7;\r
+               xmc[14]  = (*c >> 1) & 0x7;\r
+               xmc[15]  = (*c++ & 0x1) << 2;\r
+               xmc[15] |= (*c >> 6) & 0x3;\r
+               xmc[16]  = (*c >> 3) & 0x7;\r
+               xmc[17]  = *c++ & 0x7;\r
+               xmc[18]  = (*c >> 5) & 0x7;\r
+               xmc[19]  = (*c >> 2) & 0x7;\r
+               xmc[20]  = (*c++ & 0x3) << 1;\r
+               xmc[20] |= (*c >> 7) & 0x1;\r
+               xmc[21]  = (*c >> 4) & 0x7;\r
+               xmc[22]  = (*c >> 1) & 0x7;\r
+               xmc[23]  = (*c++ & 0x1) << 2;\r
+               xmc[23] |= (*c >> 6) & 0x3;\r
+               xmc[24]  = (*c >> 3) & 0x7;\r
+               xmc[25]  = *c++ & 0x7;\r
+               Nc[2]  = (*c >> 1) & 0x7F;\r
+               bc[2]  = (*c++ & 0x1) << 1;             /* 20 */\r
+               bc[2] |= (*c >> 7) & 0x1;\r
+               Mc[2]  = (*c >> 5) & 0x3;\r
+               xmaxc[2]  = (*c++ & 0x1F) << 1;\r
+               xmaxc[2] |= (*c >> 7) & 0x1;\r
+               xmc[26]  = (*c >> 4) & 0x7;\r
+               xmc[27]  = (*c >> 1) & 0x7;\r
+               xmc[28]  = (*c++ & 0x1) << 2;\r
+               xmc[28] |= (*c >> 6) & 0x3;\r
+               xmc[29]  = (*c >> 3) & 0x7;\r
+               xmc[30]  = *c++ & 0x7;\r
+               xmc[31]  = (*c >> 5) & 0x7;\r
+               xmc[32]  = (*c >> 2) & 0x7;\r
+               xmc[33]  = (*c++ & 0x3) << 1;\r
+               xmc[33] |= (*c >> 7) & 0x1;\r
+               xmc[34]  = (*c >> 4) & 0x7;\r
+               xmc[35]  = (*c >> 1) & 0x7;\r
+               xmc[36]  = (*c++ & 0x1) << 2;\r
+               xmc[36] |= (*c >> 6) & 0x3;\r
+               xmc[37]  = (*c >> 3) & 0x7;\r
+               xmc[38]  = *c++ & 0x7;\r
+               Nc[3]  = (*c >> 1) & 0x7F;\r
+               bc[3]  = (*c++ & 0x1) << 1;\r
+               bc[3] |= (*c >> 7) & 0x1;\r
+               Mc[3]  = (*c >> 5) & 0x3;\r
+               xmaxc[3]  = (*c++ & 0x1F) << 1;\r
+               xmaxc[3] |= (*c >> 7) & 0x1;\r
+               xmc[39]  = (*c >> 4) & 0x7;\r
+               xmc[40]  = (*c >> 1) & 0x7;\r
+               xmc[41]  = (*c++ & 0x1) << 2;\r
+               xmc[41] |= (*c >> 6) & 0x3;\r
+               xmc[42]  = (*c >> 3) & 0x7;\r
+               xmc[43]  = *c++ & 0x7;                  /* 30  */\r
+               xmc[44]  = (*c >> 5) & 0x7;\r
+               xmc[45]  = (*c >> 2) & 0x7;\r
+               xmc[46]  = (*c++ & 0x3) << 1;\r
+               xmc[46] |= (*c >> 7) & 0x1;\r
+               xmc[47]  = (*c >> 4) & 0x7;\r
+               xmc[48]  = (*c >> 1) & 0x7;\r
+               xmc[49]  = (*c++ & 0x1) << 2;\r
+               xmc[49] |= (*c >> 6) & 0x3;\r
+               xmc[50]  = (*c >> 3) & 0x7;\r
+               xmc[51]  = *c & 0x7;                    /* 33 */\r
+       }\r
+\r
+       Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target);\r
+\r
+       return 0;\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_destroy.c b/libs/codec/gsm/src/gsm_destroy.c
new file mode 100644 (file)
index 0000000..a92c006
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "gsm.h"\r
+#include "config.h"\r
+#include "proto.h"\r
+\r
+#ifdef HAS_STDLIB_H\r
+#      include <stdlib.h>\r
+#else\r
+#      ifdef   HAS_MALLOC_H\r
+#              include         <malloc.h>\r
+#      else\r
+               extern void free();\r
+#      endif\r
+#endif\r
+\r
+void gsm_destroy P1((S), gsm S)\r
+{\r
+       if (S) free((char *)S);\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_encode.c b/libs/codec/gsm/src/gsm_encode.c
new file mode 100644 (file)
index 0000000..4a2392e
--- /dev/null
@@ -0,0 +1,451 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+void gsm_encode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)\r
+{\r
+       word            LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];\r
+\r
+       Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc);\r
+\r
+\r
+       /*      variable        size\r
+\r
+               GSM_MAGIC       4\r
+\r
+               LARc[0]         6\r
+               LARc[1]         6\r
+               LARc[2]         5\r
+               LARc[3]         5\r
+               LARc[4]         4\r
+               LARc[5]         4\r
+               LARc[6]         3\r
+               LARc[7]         3\r
+\r
+               Nc[0]           7\r
+               bc[0]           2\r
+               Mc[0]           2\r
+               xmaxc[0]        6\r
+               xmc[0]          3\r
+               xmc[1]          3\r
+               xmc[2]          3\r
+               xmc[3]          3\r
+               xmc[4]          3\r
+               xmc[5]          3\r
+               xmc[6]          3\r
+               xmc[7]          3\r
+               xmc[8]          3\r
+               xmc[9]          3\r
+               xmc[10]         3\r
+               xmc[11]         3\r
+               xmc[12]         3\r
+\r
+               Nc[1]           7\r
+               bc[1]           2\r
+               Mc[1]           2\r
+               xmaxc[1]        6\r
+               xmc[13]         3\r
+               xmc[14]         3\r
+               xmc[15]         3\r
+               xmc[16]         3\r
+               xmc[17]         3\r
+               xmc[18]         3\r
+               xmc[19]         3\r
+               xmc[20]         3\r
+               xmc[21]         3\r
+               xmc[22]         3\r
+               xmc[23]         3\r
+               xmc[24]         3\r
+               xmc[25]         3\r
+\r
+               Nc[2]           7\r
+               bc[2]           2\r
+               Mc[2]           2\r
+               xmaxc[2]        6\r
+               xmc[26]         3\r
+               xmc[27]         3\r
+               xmc[28]         3\r
+               xmc[29]         3\r
+               xmc[30]         3\r
+               xmc[31]         3\r
+               xmc[32]         3\r
+               xmc[33]         3\r
+               xmc[34]         3\r
+               xmc[35]         3\r
+               xmc[36]         3\r
+               xmc[37]         3\r
+               xmc[38]         3\r
+\r
+               Nc[3]           7\r
+               bc[3]           2\r
+               Mc[3]           2\r
+               xmaxc[3]        6\r
+               xmc[39]         3\r
+               xmc[40]         3\r
+               xmc[41]         3\r
+               xmc[42]         3\r
+               xmc[43]         3\r
+               xmc[44]         3\r
+               xmc[45]         3\r
+               xmc[46]         3\r
+               xmc[47]         3\r
+               xmc[48]         3\r
+               xmc[49]         3\r
+               xmc[50]         3\r
+               xmc[51]         3\r
+       */\r
+\r
+#ifdef WAV49\r
+\r
+       if (s->wav_fmt) {\r
+               s->frame_index = !s->frame_index;\r
+               if (s->frame_index) {\r
+\r
+                       uword sr;\r
+\r
+                       sr = 0;\r
+                       sr = sr >> 6 | LARc[0] << 10;\r
+                       sr = sr >> 6 | LARc[1] << 10;\r
+                       *c++ = sr >> 4;\r
+                       sr = sr >> 5 | LARc[2] << 11;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 5 | LARc[3] << 11;\r
+                       sr = sr >> 4 | LARc[4] << 12;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 4 | LARc[5] << 12;\r
+                       sr = sr >> 3 | LARc[6] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | LARc[7] << 13;\r
+                       sr = sr >> 7 | Nc[0] << 9;\r
+                       *c++ = sr >> 5;\r
+                       sr = sr >> 2 | bc[0] << 14;\r
+                       sr = sr >> 2 | Mc[0] << 14;\r
+                       sr = sr >> 6 | xmaxc[0] << 10;\r
+                       *c++ = sr >> 3;\r
+                       sr = sr >> 3 | xmc[0] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[1] << 13;\r
+                       sr = sr >> 3 | xmc[2] << 13;\r
+                       sr = sr >> 3 | xmc[3] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[4] << 13;\r
+                       sr = sr >> 3 | xmc[5] << 13;\r
+                       sr = sr >> 3 | xmc[6] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[7] << 13;\r
+                       sr = sr >> 3 | xmc[8] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[9] << 13;\r
+                       sr = sr >> 3 | xmc[10] << 13;\r
+                       sr = sr >> 3 | xmc[11] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[12] << 13;\r
+                       sr = sr >> 7 | Nc[1] << 9;\r
+                       *c++ = sr >> 5;\r
+                       sr = sr >> 2 | bc[1] << 14;\r
+                       sr = sr >> 2 | Mc[1] << 14;\r
+                       sr = sr >> 6 | xmaxc[1] << 10;\r
+                       *c++ = sr >> 3;\r
+                       sr = sr >> 3 | xmc[13] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[14] << 13;\r
+                       sr = sr >> 3 | xmc[15] << 13;\r
+                       sr = sr >> 3 | xmc[16] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[17] << 13;\r
+                       sr = sr >> 3 | xmc[18] << 13;\r
+                       sr = sr >> 3 | xmc[19] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[20] << 13;\r
+                       sr = sr >> 3 | xmc[21] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[22] << 13;\r
+                       sr = sr >> 3 | xmc[23] << 13;\r
+                       sr = sr >> 3 | xmc[24] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[25] << 13;\r
+                       sr = sr >> 7 | Nc[2] << 9;\r
+                       *c++ = sr >> 5;\r
+                       sr = sr >> 2 | bc[2] << 14;\r
+                       sr = sr >> 2 | Mc[2] << 14;\r
+                       sr = sr >> 6 | xmaxc[2] << 10;\r
+                       *c++ = sr >> 3;\r
+                       sr = sr >> 3 | xmc[26] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[27] << 13;\r
+                       sr = sr >> 3 | xmc[28] << 13;\r
+                       sr = sr >> 3 | xmc[29] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[30] << 13;\r
+                       sr = sr >> 3 | xmc[31] << 13;\r
+                       sr = sr >> 3 | xmc[32] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[33] << 13;\r
+                       sr = sr >> 3 | xmc[34] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[35] << 13;\r
+                       sr = sr >> 3 | xmc[36] << 13;\r
+                       sr = sr >> 3 | xmc[37] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[38] << 13;\r
+                       sr = sr >> 7 | Nc[3] << 9;\r
+                       *c++ = sr >> 5;\r
+                       sr = sr >> 2 | bc[3] << 14;\r
+                       sr = sr >> 2 | Mc[3] << 14;\r
+                       sr = sr >> 6 | xmaxc[3] << 10;\r
+                       *c++ = sr >> 3;\r
+                       sr = sr >> 3 | xmc[39] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[40] << 13;\r
+                       sr = sr >> 3 | xmc[41] << 13;\r
+                       sr = sr >> 3 | xmc[42] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[43] << 13;\r
+                       sr = sr >> 3 | xmc[44] << 13;\r
+                       sr = sr >> 3 | xmc[45] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[46] << 13;\r
+                       sr = sr >> 3 | xmc[47] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[48] << 13;\r
+                       sr = sr >> 3 | xmc[49] << 13;\r
+                       sr = sr >> 3 | xmc[50] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[51] << 13;\r
+                       sr = sr >> 4;\r
+                       *c = sr >> 8;\r
+                       s->frame_chain = *c;\r
+               }\r
+               else {\r
+                       uword sr;\r
+\r
+                       sr = 0;\r
+                       sr = sr >> 4 | s->frame_chain << 12;\r
+                       sr = sr >> 6 | LARc[0] << 10;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 6 | LARc[1] << 10;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 5 | LARc[2] << 11;\r
+                       sr = sr >> 5 | LARc[3] << 11;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 4 | LARc[4] << 12;\r
+                       sr = sr >> 4 | LARc[5] << 12;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | LARc[6] << 13;\r
+                       sr = sr >> 3 | LARc[7] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 7 | Nc[0] << 9;\r
+                       sr = sr >> 2 | bc[0] << 14;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 2 | Mc[0] << 14;\r
+                       sr = sr >> 6 | xmaxc[0] << 10;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[0] << 13;\r
+                       sr = sr >> 3 | xmc[1] << 13;\r
+                       sr = sr >> 3 | xmc[2] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[3] << 13;\r
+                       sr = sr >> 3 | xmc[4] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[5] << 13;\r
+                       sr = sr >> 3 | xmc[6] << 13;\r
+                       sr = sr >> 3 | xmc[7] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[8] << 13;\r
+                       sr = sr >> 3 | xmc[9] << 13;\r
+                       sr = sr >> 3 | xmc[10] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[11] << 13;\r
+                       sr = sr >> 3 | xmc[12] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 7 | Nc[1] << 9;\r
+                       sr = sr >> 2 | bc[1] << 14;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 2 | Mc[1] << 14;\r
+                       sr = sr >> 6 | xmaxc[1] << 10;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[13] << 13;\r
+                       sr = sr >> 3 | xmc[14] << 13;\r
+                       sr = sr >> 3 | xmc[15] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[16] << 13;\r
+                       sr = sr >> 3 | xmc[17] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[18] << 13;\r
+                       sr = sr >> 3 | xmc[19] << 13;\r
+                       sr = sr >> 3 | xmc[20] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[21] << 13;\r
+                       sr = sr >> 3 | xmc[22] << 13;\r
+                       sr = sr >> 3 | xmc[23] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[24] << 13;\r
+                       sr = sr >> 3 | xmc[25] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 7 | Nc[2] << 9;\r
+                       sr = sr >> 2 | bc[2] << 14;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 2 | Mc[2] << 14;\r
+                       sr = sr >> 6 | xmaxc[2] << 10;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[26] << 13;\r
+                       sr = sr >> 3 | xmc[27] << 13;\r
+                       sr = sr >> 3 | xmc[28] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[29] << 13;\r
+                       sr = sr >> 3 | xmc[30] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[31] << 13;\r
+                       sr = sr >> 3 | xmc[32] << 13;\r
+                       sr = sr >> 3 | xmc[33] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[34] << 13;\r
+                       sr = sr >> 3 | xmc[35] << 13;\r
+                       sr = sr >> 3 | xmc[36] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[37] << 13;\r
+                       sr = sr >> 3 | xmc[38] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 7 | Nc[3] << 9;\r
+                       sr = sr >> 2 | bc[3] << 14;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 2 | Mc[3] << 14;\r
+                       sr = sr >> 6 | xmaxc[3] << 10;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[39] << 13;\r
+                       sr = sr >> 3 | xmc[40] << 13;\r
+                       sr = sr >> 3 | xmc[41] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[42] << 13;\r
+                       sr = sr >> 3 | xmc[43] << 13;\r
+                       *c++ = sr >> 8;\r
+                       sr = sr >> 3 | xmc[44] << 13;\r
+                       sr = sr >> 3 | xmc[45] << 13;\r
+                       sr = sr >> 3 | xmc[46] << 13;\r
+                       *c++ = sr >> 7;\r
+                       sr = sr >> 3 | xmc[47] << 13;\r
+                       sr = sr >> 3 | xmc[48] << 13;\r
+                       sr = sr >> 3 | xmc[49] << 13;\r
+                       *c++ = sr >> 6;\r
+                       sr = sr >> 3 | xmc[50] << 13;\r
+                       sr = sr >> 3 | xmc[51] << 13;\r
+                       *c++ = sr >> 8;\r
+               }\r
+       }\r
+\r
+       else\r
+\r
+#endif /* WAV49 */\r
+       {\r
+\r
+               *c++ =   ((GSM_MAGIC & 0xF) << 4)               /* 1 */\r
+                      | ((LARc[0] >> 2) & 0xF);\r
+               *c++ =   ((LARc[0] & 0x3) << 6)\r
+                      | (LARc[1] & 0x3F);\r
+               *c++ =   ((LARc[2] & 0x1F) << 3)\r
+                      | ((LARc[3] >> 2) & 0x7);\r
+               *c++ =   ((LARc[3] & 0x3) << 6)\r
+                      | ((LARc[4] & 0xF) << 2)\r
+                      | ((LARc[5] >> 2) & 0x3);\r
+               *c++ =   ((LARc[5] & 0x3) << 6)\r
+                      | ((LARc[6] & 0x7) << 3)\r
+                      | (LARc[7] & 0x7);\r
+               *c++ =   ((Nc[0] & 0x7F) << 1)\r
+                      | ((bc[0] >> 1) & 0x1);\r
+               *c++ =   ((bc[0] & 0x1) << 7)\r
+                      | ((Mc[0] & 0x3) << 5)\r
+                      | ((xmaxc[0] >> 1) & 0x1F);\r
+               *c++ =   ((xmaxc[0] & 0x1) << 7)\r
+                      | ((xmc[0] & 0x7) << 4)\r
+                      | ((xmc[1] & 0x7) << 1)\r
+                      | ((xmc[2] >> 2) & 0x1);\r
+               *c++ =   ((xmc[2] & 0x3) << 6)\r
+                      | ((xmc[3] & 0x7) << 3)\r
+                      | (xmc[4] & 0x7);\r
+               *c++ =   ((xmc[5] & 0x7) << 5)                  /* 10 */\r
+                      | ((xmc[6] & 0x7) << 2)\r
+                      | ((xmc[7] >> 1) & 0x3);\r
+               *c++ =   ((xmc[7] & 0x1) << 7)\r
+                      | ((xmc[8] & 0x7) << 4)\r
+                      | ((xmc[9] & 0x7) << 1)\r
+                      | ((xmc[10] >> 2) & 0x1);\r
+               *c++ =   ((xmc[10] & 0x3) << 6)\r
+                      | ((xmc[11] & 0x7) << 3)\r
+                      | (xmc[12] & 0x7);\r
+               *c++ =   ((Nc[1] & 0x7F) << 1)\r
+                      | ((bc[1] >> 1) & 0x1);\r
+               *c++ =   ((bc[1] & 0x1) << 7)\r
+                      | ((Mc[1] & 0x3) << 5)\r
+                      | ((xmaxc[1] >> 1) & 0x1F);\r
+               *c++ =   ((xmaxc[1] & 0x1) << 7)\r
+                      | ((xmc[13] & 0x7) << 4)\r
+                      | ((xmc[14] & 0x7) << 1)\r
+                      | ((xmc[15] >> 2) & 0x1);\r
+               *c++ =   ((xmc[15] & 0x3) << 6)\r
+                      | ((xmc[16] & 0x7) << 3)\r
+                      | (xmc[17] & 0x7);\r
+               *c++ =   ((xmc[18] & 0x7) << 5)\r
+                      | ((xmc[19] & 0x7) << 2)\r
+                      | ((xmc[20] >> 1) & 0x3);\r
+               *c++ =   ((xmc[20] & 0x1) << 7)\r
+                      | ((xmc[21] & 0x7) << 4)\r
+                      | ((xmc[22] & 0x7) << 1)\r
+                      | ((xmc[23] >> 2) & 0x1);\r
+               *c++ =   ((xmc[23] & 0x3) << 6)\r
+                      | ((xmc[24] & 0x7) << 3)\r
+                      | (xmc[25] & 0x7);\r
+               *c++ =   ((Nc[2] & 0x7F) << 1)                  /* 20 */\r
+                      | ((bc[2] >> 1) & 0x1);\r
+               *c++ =   ((bc[2] & 0x1) << 7)\r
+                      | ((Mc[2] & 0x3) << 5)\r
+                      | ((xmaxc[2] >> 1) & 0x1F);\r
+               *c++ =   ((xmaxc[2] & 0x1) << 7)\r
+                      | ((xmc[26] & 0x7) << 4)\r
+                      | ((xmc[27] & 0x7) << 1)\r
+                      | ((xmc[28] >> 2) & 0x1);\r
+               *c++ =   ((xmc[28] & 0x3) << 6)\r
+                      | ((xmc[29] & 0x7) << 3)\r
+                      | (xmc[30] & 0x7);\r
+               *c++ =   ((xmc[31] & 0x7) << 5)\r
+                      | ((xmc[32] & 0x7) << 2)\r
+                      | ((xmc[33] >> 1) & 0x3);\r
+               *c++ =   ((xmc[33] & 0x1) << 7)\r
+                      | ((xmc[34] & 0x7) << 4)\r
+                      | ((xmc[35] & 0x7) << 1)\r
+                      | ((xmc[36] >> 2) & 0x1);\r
+               *c++ =   ((xmc[36] & 0x3) << 6)\r
+                      | ((xmc[37] & 0x7) << 3)\r
+                      | (xmc[38] & 0x7);\r
+               *c++ =   ((Nc[3] & 0x7F) << 1)\r
+                      | ((bc[3] >> 1) & 0x1);\r
+               *c++ =   ((bc[3] & 0x1) << 7)\r
+                      | ((Mc[3] & 0x3) << 5)\r
+                      | ((xmaxc[3] >> 1) & 0x1F);\r
+               *c++ =   ((xmaxc[3] & 0x1) << 7)\r
+                      | ((xmc[39] & 0x7) << 4)\r
+                      | ((xmc[40] & 0x7) << 1)\r
+                      | ((xmc[41] >> 2) & 0x1);\r
+               *c++ =   ((xmc[41] & 0x3) << 6)                 /* 30 */\r
+                      | ((xmc[42] & 0x7) << 3)\r
+                      | (xmc[43] & 0x7);\r
+               *c++ =   ((xmc[44] & 0x7) << 5)\r
+                      | ((xmc[45] & 0x7) << 2)\r
+                      | ((xmc[46] >> 1) & 0x3);\r
+               *c++ =   ((xmc[46] & 0x1) << 7)\r
+                      | ((xmc[47] & 0x7) << 4)\r
+                      | ((xmc[48] & 0x7) << 1)\r
+                      | ((xmc[49] >> 2) & 0x1);\r
+               *c++ =   ((xmc[49] & 0x3) << 6)\r
+                      | ((xmc[50] & 0x7) << 3)\r
+                      | (xmc[51] & 0x7);\r
+\r
+       }\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_explode.c b/libs/codec/gsm/src/gsm_explode.c
new file mode 100644 (file)
index 0000000..9c831a7
--- /dev/null
@@ -0,0 +1,417 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+int gsm_explode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target)\r
+{\r
+#      define  LARc    target\r
+#      define  Nc      *((gsm_signal (*) [17])(target + 8))\r
+#      define  bc      *((gsm_signal (*) [17])(target + 9))\r
+#      define  Mc      *((gsm_signal (*) [17])(target + 10))\r
+#      define  xmaxc   *((gsm_signal (*) [17])(target + 11))\r
+\r
+\r
+#ifdef WAV49\r
+       if (s->wav_fmt) {\r
+\r
+               uword sr = 0;\r
+\r
+               if (s->frame_index == 1) {\r
+\r
+                       sr = *c++;\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 4;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;                 /* 5 */\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 12)\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 10 */\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 29 - 13)\r
+\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 15 */\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;                 /* 20 */\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 46 - 26)\r
+\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 25 */\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 63 - 39)\r
+\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 30 */\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+\r
+                       s->frame_chain = sr & 0xf;\r
+               }\r
+               else {\r
+                       sr = s->frame_chain;\r
+                       sr |= (uword)*c++ << 4;                 /* 1 */\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr = *c++;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 3;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 5 */\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 12)\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 10 */\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 29 - 13)\r
+\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 15 */\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;                 /* 20 */\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (target + 46 - 26)\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1; \r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 25 */\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;         \r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 63 - 39)\r
+\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 30 */\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+               }\r
+       }\r
+       else \r
+#endif\r
+       {\r
+       /* GSM_MAGIC  = (*c >> 4) & 0xF; */\r
+\r
+       if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;\r
+\r
+       LARc[0]  = (*c++ & 0xF) << 2;           /* 1 */\r
+       LARc[0] |= (*c >> 6) & 0x3;\r
+       LARc[1]  = *c++ & 0x3F;\r
+       LARc[2]  = (*c >> 3) & 0x1F;\r
+       LARc[3]  = (*c++ & 0x7) << 2;\r
+       LARc[3] |= (*c >> 6) & 0x3;\r
+       LARc[4]  = (*c >> 2) & 0xF;\r
+       LARc[5]  = (*c++ & 0x3) << 2;\r
+       LARc[5] |= (*c >> 6) & 0x3;\r
+       LARc[6]  = (*c >> 3) & 0x7;\r
+       LARc[7]  = *c++ & 0x7;\r
+\r
+       Nc[0]  = (*c >> 1) & 0x7F;\r
+\r
+       bc[0]  = (*c++ & 0x1) << 1;\r
+       bc[0] |= (*c >> 7) & 0x1;\r
+\r
+       Mc[0]  = (*c >> 5) & 0x3;\r
+\r
+       xmaxc[0]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[0] |= (*c >> 7) & 0x1;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 12)\r
+\r
+       xmc[0]  = (*c >> 4) & 0x7;\r
+       xmc[1]  = (*c >> 1) & 0x7;\r
+       xmc[2]  = (*c++ & 0x1) << 2;\r
+       xmc[2] |= (*c >> 6) & 0x3;\r
+       xmc[3]  = (*c >> 3) & 0x7;\r
+       xmc[4]  = *c++ & 0x7;\r
+       xmc[5]  = (*c >> 5) & 0x7;\r
+       xmc[6]  = (*c >> 2) & 0x7;\r
+       xmc[7]  = (*c++ & 0x3) << 1;            /* 10 */\r
+       xmc[7] |= (*c >> 7) & 0x1;\r
+       xmc[8]  = (*c >> 4) & 0x7;\r
+       xmc[9]  = (*c >> 1) & 0x7;\r
+       xmc[10]  = (*c++ & 0x1) << 2;\r
+       xmc[10] |= (*c >> 6) & 0x3;\r
+       xmc[11]  = (*c >> 3) & 0x7;\r
+       xmc[12]  = *c++ & 0x7;\r
+\r
+       Nc[1]  = (*c >> 1) & 0x7F;\r
+\r
+       bc[1]  = (*c++ & 0x1) << 1;\r
+       bc[1] |= (*c >> 7) & 0x1;\r
+\r
+       Mc[1]  = (*c >> 5) & 0x3;\r
+\r
+       xmaxc[1]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[1] |= (*c >> 7) & 0x1;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 29 - 13)\r
+\r
+       xmc[13]  = (*c >> 4) & 0x7;\r
+       xmc[14]  = (*c >> 1) & 0x7;\r
+       xmc[15]  = (*c++ & 0x1) << 2;\r
+       xmc[15] |= (*c >> 6) & 0x3;\r
+       xmc[16]  = (*c >> 3) & 0x7;\r
+       xmc[17]  = *c++ & 0x7;\r
+       xmc[18]  = (*c >> 5) & 0x7;\r
+       xmc[19]  = (*c >> 2) & 0x7;\r
+       xmc[20]  = (*c++ & 0x3) << 1;\r
+       xmc[20] |= (*c >> 7) & 0x1;\r
+       xmc[21]  = (*c >> 4) & 0x7;\r
+       xmc[22]  = (*c >> 1) & 0x7;\r
+       xmc[23]  = (*c++ & 0x1) << 2;\r
+       xmc[23] |= (*c >> 6) & 0x3;\r
+       xmc[24]  = (*c >> 3) & 0x7;\r
+       xmc[25]  = *c++ & 0x7;\r
+\r
+       Nc[2]  = (*c >> 1) & 0x7F;\r
+\r
+       bc[2]  = (*c++ & 0x1) << 1;             /* 20 */\r
+       bc[2] |= (*c >> 7) & 0x1;\r
+\r
+       Mc[2]  = (*c >> 5) & 0x3;\r
+\r
+       xmaxc[2]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[2] |= (*c >> 7) & 0x1;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 46 - 26)\r
+\r
+       xmc[26]  = (*c >> 4) & 0x7;\r
+       xmc[27]  = (*c >> 1) & 0x7;\r
+       xmc[28]  = (*c++ & 0x1) << 2;\r
+       xmc[28] |= (*c >> 6) & 0x3;\r
+       xmc[29]  = (*c >> 3) & 0x7;\r
+       xmc[30]  = *c++ & 0x7;\r
+       xmc[31]  = (*c >> 5) & 0x7;\r
+       xmc[32]  = (*c >> 2) & 0x7;\r
+       xmc[33]  = (*c++ & 0x3) << 1;\r
+       xmc[33] |= (*c >> 7) & 0x1;\r
+       xmc[34]  = (*c >> 4) & 0x7;\r
+       xmc[35]  = (*c >> 1) & 0x7;\r
+       xmc[36]  = (*c++ & 0x1) << 2;\r
+       xmc[36] |= (*c >> 6) & 0x3;\r
+       xmc[37]  = (*c >> 3) & 0x7;\r
+       xmc[38]  = *c++ & 0x7;\r
+\r
+       Nc[3]  = (*c >> 1) & 0x7F;\r
+\r
+       bc[3]  = (*c++ & 0x1) << 1;\r
+       bc[3] |= (*c >> 7) & 0x1;\r
+\r
+       Mc[3]  = (*c >> 5) & 0x3;\r
+\r
+       xmaxc[3]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[3] |= (*c >> 7) & 0x1;\r
+\r
+#undef xmc\r
+#define        xmc     (target + 63 - 39)\r
+\r
+       xmc[39]  = (*c >> 4) & 0x7;\r
+       xmc[40]  = (*c >> 1) & 0x7;\r
+       xmc[41]  = (*c++ & 0x1) << 2;\r
+       xmc[41] |= (*c >> 6) & 0x3;\r
+       xmc[42]  = (*c >> 3) & 0x7;\r
+       xmc[43]  = *c++ & 0x7;                  /* 30  */\r
+       xmc[44]  = (*c >> 5) & 0x7;\r
+       xmc[45]  = (*c >> 2) & 0x7;\r
+       xmc[46]  = (*c++ & 0x3) << 1;\r
+       xmc[46] |= (*c >> 7) & 0x1;\r
+       xmc[47]  = (*c >> 4) & 0x7;\r
+       xmc[48]  = (*c >> 1) & 0x7;\r
+       xmc[49]  = (*c++ & 0x1) << 2;\r
+       xmc[49] |= (*c >> 6) & 0x3;\r
+       xmc[50]  = (*c >> 3) & 0x7;\r
+       xmc[51]  = *c & 0x7;                    /* 33 */\r
+       }\r
+\r
+       return 0;\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_implode.c b/libs/codec/gsm/src/gsm_implode.c
new file mode 100644 (file)
index 0000000..171836d
--- /dev/null
@@ -0,0 +1,515 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+void gsm_implode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)\r
+{\r
+       /*      variable        size    index\r
+\r
+               GSM_MAGIC       4       -\r
+\r
+               LARc[0]         6       0\r
+               LARc[1]         6       1\r
+               LARc[2]         5       2\r
+               LARc[3]         5       3\r
+               LARc[4]         4       4\r
+               LARc[5]         4       5\r
+               LARc[6]         3       6\r
+               LARc[7]         3       7\r
+\r
+               Nc[0]           7       8\r
+               bc[0]           2       9\r
+               Mc[0]           2       10\r
+               xmaxc[0]        6       11\r
+               xmc[0]          3       12\r
+               xmc[1]          3       13\r
+               xmc[2]          3       14\r
+               xmc[3]          3       15\r
+               xmc[4]          3       16\r
+               xmc[5]          3       17\r
+               xmc[6]          3       18\r
+               xmc[7]          3       19\r
+               xmc[8]          3       20\r
+               xmc[9]          3       21\r
+               xmc[10]         3       22\r
+               xmc[11]         3       23\r
+               xmc[12]         3       24\r
+\r
+               Nc[1]           7       25\r
+               bc[1]           2       26\r
+               Mc[1]           2       27\r
+               xmaxc[1]        6       28\r
+               xmc[13]         3       29\r
+               xmc[14]         3       30\r
+               xmc[15]         3       31\r
+               xmc[16]         3       32\r
+               xmc[17]         3       33\r
+               xmc[18]         3       34\r
+               xmc[19]         3       35\r
+               xmc[20]         3       36\r
+               xmc[21]         3       37\r
+               xmc[22]         3       38\r
+               xmc[23]         3       39\r
+               xmc[24]         3       40\r
+               xmc[25]         3       41\r
+\r
+               Nc[2]           7       42\r
+               bc[2]           2       43\r
+               Mc[2]           2       44\r
+               xmaxc[2]        6       45\r
+               xmc[26]         3       46\r
+               xmc[27]         3       47\r
+               xmc[28]         3       48\r
+               xmc[29]         3       49\r
+               xmc[30]         3       50\r
+               xmc[31]         3       51\r
+               xmc[32]         3       52\r
+               xmc[33]         3       53\r
+               xmc[34]         3       54\r
+               xmc[35]         3       55\r
+               xmc[36]         3       56\r
+               xmc[37]         3       57\r
+               xmc[38]         3       58\r
+\r
+               Nc[3]           7       59\r
+               bc[3]           2       60\r
+               Mc[3]           2       61\r
+               xmaxc[3]        6       62\r
+               xmc[39]         3       63\r
+               xmc[40]         3       64\r
+               xmc[41]         3       65\r
+               xmc[42]         3       66\r
+               xmc[43]         3       67\r
+               xmc[44]         3       68\r
+               xmc[45]         3       69\r
+               xmc[46]         3       70\r
+               xmc[47]         3       71\r
+               xmc[48]         3       72\r
+               xmc[49]         3       73\r
+               xmc[50]         3       74\r
+               xmc[51]         3       75\r
+       */\r
+\r
+       /*      There are 76 parameters per frame.  The first eight are\r
+        *      unique.  The remaining 68 are four identical subframes of\r
+        *      17 parameters each.  gsm_implode converts from a representation\r
+        *      of these parameters as values in one array of signed words\r
+        *      to the "packed" version of a GSM frame.\r
+        */\r
+\r
+#      define  LARc    source\r
+#      define  Nc      *((gsm_signal (*) [17])(source + 8))\r
+#      define  bc      *((gsm_signal (*) [17])(source + 9))\r
+#      define  Mc      *((gsm_signal (*) [17])(source + 10))\r
+#      define  xmaxc   *((gsm_signal (*) [17])(source + 11))\r
+\r
+#ifdef WAV49\r
+       if (s->wav_fmt) {\r
+\r
+               uword sr = 0;\r
+               if (s->frame_index == 0) {\r
+\r
+                       sr = *c++;\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr |= (uword)*c++ << 4;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;                 /* 5 */\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 12)\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 10 */\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 29 - 13)\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 15 */\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;                 /* 20 */\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 46 - 26)\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 25 */\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 4;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 63 - 39)\r
+\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 30 */\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+\r
+                       s->frame_chain = sr & 0xf;\r
+               }\r
+               else {\r
+                       sr = s->frame_chain;\r
+                       sr |= (uword)*c++ << 4;                 /* 1 */\r
+                       LARc[0] = sr & 0x3f;  sr >>= 6;\r
+                       LARc[1] = sr & 0x3f;  sr >>= 6;\r
+                       sr = *c++;\r
+                       LARc[2] = sr & 0x1f;  sr >>= 5;\r
+                       sr |= (uword)*c++ << 3;\r
+                       LARc[3] = sr & 0x1f;  sr >>= 5;\r
+                       LARc[4] = sr & 0xf;  sr >>= 4;\r
+                       sr |= (uword)*c++ << 2;\r
+                       LARc[5] = sr & 0xf;  sr >>= 4;\r
+                       LARc[6] = sr & 0x7;  sr >>= 3;\r
+                       LARc[7] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 5 */\r
+                       Nc[0] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[0] = sr & 0x3;  sr >>= 2;\r
+                       Mc[0] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[0] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 12)\r
+                       xmc[0] = sr & 0x7;  sr >>= 3;\r
+                       xmc[1] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[2] = sr & 0x7;  sr >>= 3;\r
+                       xmc[3] = sr & 0x7;  sr >>= 3;\r
+                       xmc[4] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[5] = sr & 0x7;  sr >>= 3;\r
+                       xmc[6] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;                 /* 10 */\r
+                       xmc[7] = sr & 0x7;  sr >>= 3;\r
+                       xmc[8] = sr & 0x7;  sr >>= 3;\r
+                       xmc[9] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[10] = sr & 0x7;  sr >>= 3;\r
+                       xmc[11] = sr & 0x7;  sr >>= 3;\r
+                       xmc[12] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[1] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;\r
+                       bc[1] = sr & 0x3;  sr >>= 2;\r
+                       Mc[1] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[1] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 29 - 13)\r
+                       xmc[13] = sr & 0x7;  sr >>= 3;\r
+                       xmc[14] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 15 */\r
+                       xmc[15] = sr & 0x7;  sr >>= 3;\r
+                       xmc[16] = sr & 0x7;  sr >>= 3;\r
+                       xmc[17] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[18] = sr & 0x7;  sr >>= 3;\r
+                       xmc[19] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[20] = sr & 0x7;  sr >>= 3;\r
+                       xmc[21] = sr & 0x7;  sr >>= 3;\r
+                       xmc[22] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[23] = sr & 0x7;  sr >>= 3;\r
+                       xmc[24] = sr & 0x7;  sr >>= 3;\r
+                       xmc[25] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[2] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;                 /* 20 */\r
+                       bc[2] = sr & 0x3;  sr >>= 2;\r
+                       Mc[2] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[2] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 46 - 26)\r
+                       xmc[26] = sr & 0x7;  sr >>= 3;\r
+                       xmc[27] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1; \r
+                       xmc[28] = sr & 0x7;  sr >>= 3;\r
+                       xmc[29] = sr & 0x7;  sr >>= 3;\r
+                       xmc[30] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       xmc[31] = sr & 0x7;  sr >>= 3;\r
+                       xmc[32] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[33] = sr & 0x7;  sr >>= 3;\r
+                       xmc[34] = sr & 0x7;  sr >>= 3;\r
+                       xmc[35] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;                 /* 25 */\r
+                       xmc[36] = sr & 0x7;  sr >>= 3;\r
+                       xmc[37] = sr & 0x7;  sr >>= 3;\r
+                       xmc[38] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;\r
+                       Nc[3] = sr & 0x7f;  sr >>= 7;\r
+                       sr |= (uword)*c++ << 1;         \r
+                       bc[3] = sr & 0x3;  sr >>= 2;\r
+                       Mc[3] = sr & 0x3;  sr >>= 2;\r
+                       sr |= (uword)*c++ << 5;\r
+                       xmaxc[3] = sr & 0x3f;  sr >>= 6;\r
+#undef xmc\r
+#define        xmc     (source + 63 - 39)\r
+\r
+                       xmc[39] = sr & 0x7;  sr >>= 3;\r
+                       xmc[40] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[41] = sr & 0x7;  sr >>= 3;\r
+                       xmc[42] = sr & 0x7;  sr >>= 3;\r
+                       xmc[43] = sr & 0x7;  sr >>= 3;\r
+                       sr = *c++;                              /* 30 */\r
+                       xmc[44] = sr & 0x7;  sr >>= 3;\r
+                       xmc[45] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 2;\r
+                       xmc[46] = sr & 0x7;  sr >>= 3;\r
+                       xmc[47] = sr & 0x7;  sr >>= 3;\r
+                       xmc[48] = sr & 0x7;  sr >>= 3;\r
+                       sr |= (uword)*c++ << 1;\r
+                       xmc[49] = sr & 0x7;  sr >>= 3;\r
+                       xmc[50] = sr & 0x7;  sr >>= 3;\r
+                       xmc[51] = sr & 0x7;  sr >>= 3;\r
+               }\r
+       }\r
+       else\r
+#endif \r
+       {\r
+\r
+       *c++ =   ((GSM_MAGIC & 0xF) << 4)               /* 1 */\r
+              | ((LARc[0] >> 2) & 0xF);\r
+       *c++ =   ((LARc[0] & 0x3) << 6)\r
+              | (LARc[1] & 0x3F);\r
+       *c++ =   ((LARc[2] & 0x1F) << 3)\r
+              | ((LARc[3] >> 2) & 0x7);\r
+       *c++ =   ((LARc[3] & 0x3) << 6)\r
+              | ((LARc[4] & 0xF) << 2)\r
+              | ((LARc[5] >> 2) & 0x3);\r
+       *c++ =   ((LARc[5] & 0x3) << 6)\r
+              | ((LARc[6] & 0x7) << 3)\r
+              | (LARc[7] & 0x7);\r
+\r
+\r
+       *c++ =   ((Nc[0] & 0x7F) << 1)\r
+\r
+\r
+              | ((bc[0] >> 1) & 0x1);\r
+       *c++ =   ((bc[0] & 0x1) << 7)\r
+\r
+\r
+              | ((Mc[0] & 0x3) << 5)\r
+\r
+              | ((xmaxc[0] >> 1) & 0x1F);\r
+       *c++ =   ((xmaxc[0] & 0x1) << 7)\r
+\r
+#undef xmc\r
+#define        xmc     (source + 12)\r
+\r
+              | ((xmc[0] & 0x7) << 4)\r
+              | ((xmc[1] & 0x7) << 1)\r
+              | ((xmc[2] >> 2) & 0x1);\r
+       *c++ =   ((xmc[2] & 0x3) << 6)\r
+              | ((xmc[3] & 0x7) << 3)\r
+              | (xmc[4] & 0x7);\r
+       *c++ =   ((xmc[5] & 0x7) << 5)                  /* 10 */\r
+              | ((xmc[6] & 0x7) << 2)\r
+              | ((xmc[7] >> 1) & 0x3);\r
+       *c++ =   ((xmc[7] & 0x1) << 7)\r
+              | ((xmc[8] & 0x7) << 4)\r
+              | ((xmc[9] & 0x7) << 1)\r
+              | ((xmc[10] >> 2) & 0x1);\r
+       *c++ =   ((xmc[10] & 0x3) << 6)\r
+              | ((xmc[11] & 0x7) << 3)\r
+              | (xmc[12] & 0x7);\r
+\r
+\r
+       *c++ =   ((Nc[1] & 0x7F) << 1)\r
+\r
+\r
+              | ((bc[1] >> 1) & 0x1);\r
+       *c++ =   ((bc[1] & 0x1) << 7)\r
+\r
+\r
+              | ((Mc[1] & 0x3) << 5)\r
+\r
+\r
+              | ((xmaxc[1] >> 1) & 0x1F);\r
+       *c++ =   ((xmaxc[1] & 0x1) << 7)\r
+\r
+#undef xmc\r
+#define        xmc     (source + 29 - 13)\r
+\r
+              | ((xmc[13] & 0x7) << 4)\r
+              | ((xmc[14] & 0x7) << 1)\r
+              | ((xmc[15] >> 2) & 0x1);\r
+       *c++ =   ((xmc[15] & 0x3) << 6)\r
+              | ((xmc[16] & 0x7) << 3)\r
+              | (xmc[17] & 0x7);\r
+       *c++ =   ((xmc[18] & 0x7) << 5)\r
+              | ((xmc[19] & 0x7) << 2)\r
+              | ((xmc[20] >> 1) & 0x3);\r
+       *c++ =   ((xmc[20] & 0x1) << 7)\r
+              | ((xmc[21] & 0x7) << 4)\r
+              | ((xmc[22] & 0x7) << 1)\r
+              | ((xmc[23] >> 2) & 0x1);\r
+       *c++ =   ((xmc[23] & 0x3) << 6)\r
+              | ((xmc[24] & 0x7) << 3)\r
+              | (xmc[25] & 0x7);\r
+\r
+\r
+       *c++ =   ((Nc[2] & 0x7F) << 1)                  /* 20 */\r
+\r
+\r
+              | ((bc[2] >> 1) & 0x1);\r
+       *c++ =   ((bc[2] & 0x1) << 7)\r
+\r
+\r
+              | ((Mc[2] & 0x3) << 5)\r
+\r
+\r
+              | ((xmaxc[2] >> 1) & 0x1F);\r
+       *c++ =   ((xmaxc[2] & 0x1) << 7)\r
+\r
+#undef xmc\r
+#define        xmc     (source + 46 - 26)\r
+\r
+              | ((xmc[26] & 0x7) << 4)\r
+              | ((xmc[27] & 0x7) << 1)\r
+              | ((xmc[28] >> 2) & 0x1);\r
+       *c++ =   ((xmc[28] & 0x3) << 6)\r
+              | ((xmc[29] & 0x7) << 3)\r
+              | (xmc[30] & 0x7);\r
+       *c++ =   ((xmc[31] & 0x7) << 5)\r
+              | ((xmc[32] & 0x7) << 2)\r
+              | ((xmc[33] >> 1) & 0x3);\r
+       *c++ =   ((xmc[33] & 0x1) << 7)\r
+              | ((xmc[34] & 0x7) << 4)\r
+              | ((xmc[35] & 0x7) << 1)\r
+              | ((xmc[36] >> 2) & 0x1);\r
+       *c++ =   ((xmc[36] & 0x3) << 6)\r
+              | ((xmc[37] & 0x7) << 3)\r
+              | (xmc[38] & 0x7);\r
+\r
+\r
+       *c++ =   ((Nc[3] & 0x7F) << 1)\r
+\r
+\r
+              | ((bc[3] >> 1) & 0x1);\r
+       *c++ =   ((bc[3] & 0x1) << 7)\r
+\r
+\r
+              | ((Mc[3] & 0x3) << 5)\r
+\r
+\r
+              | ((xmaxc[3] >> 1) & 0x1F);\r
+       *c++ =   ((xmaxc[3] & 0x1) << 7)\r
+\r
+#undef xmc\r
+#define        xmc     (source + 63 - 39)\r
+\r
+              | ((xmc[39] & 0x7) << 4)\r
+              | ((xmc[40] & 0x7) << 1)\r
+              | ((xmc[41] >> 2) & 0x1);\r
+       *c++ =   ((xmc[41] & 0x3) << 6)                 /* 30 */\r
+              | ((xmc[42] & 0x7) << 3)\r
+              | (xmc[43] & 0x7);\r
+       *c++ =   ((xmc[44] & 0x7) << 5)\r
+              | ((xmc[45] & 0x7) << 2)\r
+              | ((xmc[46] >> 1) & 0x3);\r
+       *c++ =   ((xmc[46] & 0x1) << 7)\r
+              | ((xmc[47] & 0x7) << 4)\r
+              | ((xmc[48] & 0x7) << 1)\r
+              | ((xmc[49] >> 2) & 0x1);\r
+       *c++ =   ((xmc[49] & 0x3) << 6)\r
+              | ((xmc[50] & 0x7) << 3)\r
+              | (xmc[51] & 0x7);\r
+       }\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_option.c b/libs/codec/gsm/src/gsm_option.c
new file mode 100644 (file)
index 0000000..7f33278
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+int gsm_option P3((r, opt, val), gsm r, int opt, int * val)\r
+{\r
+       int     result = -1;\r
+\r
+       switch (opt) {\r
+       case GSM_OPT_LTP_CUT:\r
+#ifdef         LTP_CUT\r
+               result = r->ltp_cut;\r
+               if (val) r->ltp_cut = *val;\r
+#endif\r
+               break;\r
+\r
+       case GSM_OPT_VERBOSE:\r
+#ifndef        NDEBUG\r
+               result = r->verbose;\r
+               if (val) r->verbose = *val;\r
+#endif\r
+               break;\r
+\r
+       case GSM_OPT_FAST:\r
+\r
+#if    defined(FAST) && defined(USE_FLOAT_MUL)\r
+               result = r->fast;\r
+               if (val) r->fast = !!*val;\r
+#endif\r
+               break;\r
+\r
+       case GSM_OPT_FRAME_CHAIN:\r
+\r
+#ifdef WAV49\r
+               result = r->frame_chain;\r
+               if (val) r->frame_chain = *val;\r
+#endif\r
+               break;\r
+\r
+       case GSM_OPT_FRAME_INDEX:\r
+\r
+#ifdef WAV49\r
+               result = r->frame_index;\r
+               if (val) r->frame_index = *val;\r
+#endif\r
+               break;\r
+\r
+       case GSM_OPT_WAV49:\r
+\r
+#ifdef WAV49 \r
+               result = r->wav_fmt;\r
+               if (val) r->wav_fmt = !!*val;\r
+#endif\r
+               break;\r
+\r
+       default:\r
+               break;\r
+       }\r
+       return result;\r
+}\r
diff --git a/libs/codec/gsm/src/gsm_print.c b/libs/codec/gsm/src/gsm_print.c
new file mode 100644 (file)
index 0000000..41657a0
--- /dev/null
@@ -0,0 +1,167 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include       <stdio.h>\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+int gsm_print P3((f, s, c), FILE * f, gsm s, gsm_byte * c)\r
+{\r
+       word    LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];\r
+\r
+       /* GSM_MAGIC  = (*c >> 4) & 0xF; */\r
+\r
+       if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;\r
+\r
+       LARc[0]  = (*c++ & 0xF) << 2;           /* 1 */\r
+       LARc[0] |= (*c >> 6) & 0x3;\r
+       LARc[1]  = *c++ & 0x3F;\r
+       LARc[2]  = (*c >> 3) & 0x1F;\r
+       LARc[3]  = (*c++ & 0x7) << 2;\r
+       LARc[3] |= (*c >> 6) & 0x3;\r
+       LARc[4]  = (*c >> 2) & 0xF;\r
+       LARc[5]  = (*c++ & 0x3) << 2;\r
+       LARc[5] |= (*c >> 6) & 0x3;\r
+       LARc[6]  = (*c >> 3) & 0x7;\r
+       LARc[7]  = *c++ & 0x7;\r
+\r
+\r
+       Nc[0]  = (*c >> 1) & 0x7F;\r
+       bc[0]  = (*c++ & 0x1) << 1;\r
+       bc[0] |= (*c >> 7) & 0x1;\r
+       Mc[0]  = (*c >> 5) & 0x3;\r
+       xmaxc[0]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[0] |= (*c >> 7) & 0x1;\r
+       xmc[0]  = (*c >> 4) & 0x7;\r
+       xmc[1]  = (*c >> 1) & 0x7;\r
+       xmc[2]  = (*c++ & 0x1) << 2;\r
+       xmc[2] |= (*c >> 6) & 0x3;\r
+       xmc[3]  = (*c >> 3) & 0x7;\r
+       xmc[4]  = *c++ & 0x7;\r
+       xmc[5]  = (*c >> 5) & 0x7;\r
+       xmc[6]  = (*c >> 2) & 0x7;\r
+       xmc[7]  = (*c++ & 0x3) << 1;            /* 10 */\r
+       xmc[7] |= (*c >> 7) & 0x1;\r
+       xmc[8]  = (*c >> 4) & 0x7;\r
+       xmc[9]  = (*c >> 1) & 0x7;\r
+       xmc[10]  = (*c++ & 0x1) << 2;\r
+       xmc[10] |= (*c >> 6) & 0x3;\r
+       xmc[11]  = (*c >> 3) & 0x7;\r
+       xmc[12]  = *c++ & 0x7;\r
+\r
+       Nc[1]  = (*c >> 1) & 0x7F;\r
+       bc[1]  = (*c++ & 0x1) << 1;\r
+       bc[1] |= (*c >> 7) & 0x1;\r
+       Mc[1]  = (*c >> 5) & 0x3;\r
+       xmaxc[1]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[1] |= (*c >> 7) & 0x1;\r
+       xmc[13]  = (*c >> 4) & 0x7;\r
+       xmc[14]  = (*c >> 1) & 0x7;\r
+       xmc[15]  = (*c++ & 0x1) << 2;\r
+       xmc[15] |= (*c >> 6) & 0x3;\r
+       xmc[16]  = (*c >> 3) & 0x7;\r
+       xmc[17]  = *c++ & 0x7;\r
+       xmc[18]  = (*c >> 5) & 0x7;\r
+       xmc[19]  = (*c >> 2) & 0x7;\r
+       xmc[20]  = (*c++ & 0x3) << 1;\r
+       xmc[20] |= (*c >> 7) & 0x1;\r
+       xmc[21]  = (*c >> 4) & 0x7;\r
+       xmc[22]  = (*c >> 1) & 0x7;\r
+       xmc[23]  = (*c++ & 0x1) << 2;\r
+       xmc[23] |= (*c >> 6) & 0x3;\r
+       xmc[24]  = (*c >> 3) & 0x7;\r
+       xmc[25]  = *c++ & 0x7;\r
+\r
+\r
+       Nc[2]  = (*c >> 1) & 0x7F;\r
+       bc[2]  = (*c++ & 0x1) << 1;             /* 20 */\r
+       bc[2] |= (*c >> 7) & 0x1;\r
+       Mc[2]  = (*c >> 5) & 0x3;\r
+       xmaxc[2]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[2] |= (*c >> 7) & 0x1;\r
+       xmc[26]  = (*c >> 4) & 0x7;\r
+       xmc[27]  = (*c >> 1) & 0x7;\r
+       xmc[28]  = (*c++ & 0x1) << 2;\r
+       xmc[28] |= (*c >> 6) & 0x3;\r
+       xmc[29]  = (*c >> 3) & 0x7;\r
+       xmc[30]  = *c++ & 0x7;\r
+       xmc[31]  = (*c >> 5) & 0x7;\r
+       xmc[32]  = (*c >> 2) & 0x7;\r
+       xmc[33]  = (*c++ & 0x3) << 1;\r
+       xmc[33] |= (*c >> 7) & 0x1;\r
+       xmc[34]  = (*c >> 4) & 0x7;\r
+       xmc[35]  = (*c >> 1) & 0x7;\r
+       xmc[36]  = (*c++ & 0x1) << 2;\r
+       xmc[36] |= (*c >> 6) & 0x3;\r
+       xmc[37]  = (*c >> 3) & 0x7;\r
+       xmc[38]  = *c++ & 0x7;\r
+\r
+       Nc[3]  = (*c >> 1) & 0x7F;\r
+       bc[3]  = (*c++ & 0x1) << 1;\r
+       bc[3] |= (*c >> 7) & 0x1;\r
+       Mc[3]  = (*c >> 5) & 0x3;\r
+       xmaxc[3]  = (*c++ & 0x1F) << 1;\r
+       xmaxc[3] |= (*c >> 7) & 0x1;\r
+\r
+       xmc[39]  = (*c >> 4) & 0x7;\r
+       xmc[40]  = (*c >> 1) & 0x7;\r
+       xmc[41]  = (*c++ & 0x1) << 2;\r
+       xmc[41] |= (*c >> 6) & 0x3;\r
+       xmc[42]  = (*c >> 3) & 0x7;\r
+       xmc[43]  = *c++ & 0x7;                  /* 30  */\r
+       xmc[44]  = (*c >> 5) & 0x7;\r
+       xmc[45]  = (*c >> 2) & 0x7;\r
+       xmc[46]  = (*c++ & 0x3) << 1;\r
+       xmc[46] |= (*c >> 7) & 0x1;\r
+       xmc[47]  = (*c >> 4) & 0x7;\r
+       xmc[48]  = (*c >> 1) & 0x7;\r
+       xmc[49]  = (*c++ & 0x1) << 2;\r
+       xmc[49] |= (*c >> 6) & 0x3;\r
+       xmc[50]  = (*c >> 3) & 0x7;\r
+       xmc[51]  = *c & 0x7;                    /* 33 */\r
+\r
+       fprintf(f,\r
+             "LARc:\t%2.2d  %2.2d  %2.2d  %2.2d  %2.2d  %2.2d  %2.2d  %2.2d\n",\r
+              LARc[0],LARc[1],LARc[2],LARc[3],LARc[4],LARc[5],LARc[6],LARc[7]);\r
+\r
+       fprintf(f, "#1:         Nc %4.4d    bc %d    Mc %d    xmaxc %d\n",\r
+               Nc[0], bc[0], Mc[0], xmaxc[0]);\r
+       fprintf(f,\r
+"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",\r
+               xmc[0],xmc[1],xmc[2],xmc[3],xmc[4],xmc[5],xmc[6],\r
+               xmc[7],xmc[8],xmc[9],xmc[10],xmc[11],xmc[12] );\r
+\r
+       fprintf(f, "#2:         Nc %4.4d    bc %d    Mc %d    xmaxc %d\n",\r
+               Nc[1], bc[1], Mc[1], xmaxc[1]);\r
+       fprintf(f,\r
+"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",\r
+               xmc[13+0],xmc[13+1],xmc[13+2],xmc[13+3],xmc[13+4],xmc[13+5],\r
+               xmc[13+6], xmc[13+7],xmc[13+8],xmc[13+9],xmc[13+10],xmc[13+11],\r
+               xmc[13+12] );\r
+\r
+       fprintf(f, "#3:         Nc %4.4d    bc %d    Mc %d    xmaxc %d\n",\r
+               Nc[2], bc[2], Mc[2], xmaxc[2]);\r
+       fprintf(f,\r
+"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",\r
+               xmc[26+0],xmc[26+1],xmc[26+2],xmc[26+3],xmc[26+4],xmc[26+5],\r
+               xmc[26+6], xmc[26+7],xmc[26+8],xmc[26+9],xmc[26+10],xmc[26+11],\r
+               xmc[26+12] );\r
+\r
+       fprintf(f, "#4:         Nc %4.4d    bc %d    Mc %d    xmaxc %d\n",\r
+               Nc[3], bc[3], Mc[3], xmaxc[3]);\r
+       fprintf(f,\r
+"\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n",\r
+               xmc[39+0],xmc[39+1],xmc[39+2],xmc[39+3],xmc[39+4],xmc[39+5],\r
+               xmc[39+6], xmc[39+7],xmc[39+8],xmc[39+9],xmc[39+10],xmc[39+11],\r
+               xmc[39+12] );\r
+\r
+       return 0;\r
+}\r
diff --git a/libs/codec/gsm/src/k6opt.h b/libs/codec/gsm/src/k6opt.h
new file mode 100644 (file)
index 0000000..2a4b118
--- /dev/null
@@ -0,0 +1,84 @@
+/* k6opt.h  vector functions optimized for MMX extensions to x86\r
+ *\r
+ * Copyright (C) 1999 by Stanley J. Brooks <stabro@megsinet.net>\r
+ * \r
+ * Any use of this software is permitted provided that this notice is not\r
+ * removed and that neither the authors nor the Technische Universitaet Berlin\r
+ * are deemed to have made any representations as to the suitability of this\r
+ * software for any purpose nor are held responsible for any defects of\r
+ * this software.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE;\r
+ * not even the implied warranty of MERCHANTABILITY or FITNESS FOR\r
+ * A PARTICULAR PURPOSE.\r
+ * \r
+ * Chicago, 03.12.1999\r
+ * Stanley J. Brooks\r
+ */\r
+\r
+extern void Weighting_filter P2((e, x),\r
+       const word      * e,    /* signal [-5..0.39.44] IN  */\r
+       word    * x             /* signal [0..39]       OUT */\r
+)\r
+;\r
+\r
+extern longword k6maxcc P3((wt,dp,Nc_out),\r
+       const word *wt,\r
+       const word *dp, \r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+;\r
+/*\r
+ * k6maxmin(p,n,out[])\r
+ *  input p[n] is array of shorts (require n>0)\r
+ *  returns (long) maximum absolute value..\r
+ *  if out!=NULL, also returns out[0] the maximum and out[1] the minimum\r
+ */\r
+extern longword k6maxmin P3((p,n,out),\r
+       const word *p,\r
+       int n, \r
+       word *out       /*              out[0] is max, out[1] is min */\r
+)\r
+;\r
+\r
+extern longword k6iprod P3((p,q,n),\r
+       const word *p,\r
+       const word *q,\r
+       int n\r
+)\r
+;\r
+\r
+/*\r
+ * k6vsraw(p,n,bits)\r
+ *  input p[n] is array of shorts (require n>0)\r
+ *  shift/round each to the right by bits>=0 bits.\r
+ */\r
+extern void k6vsraw P3((p,n,bits),\r
+       const word *p,\r
+       int n, \r
+       int bits\r
+)\r
+;\r
+\r
+/*\r
+ * k6vsllw(p,n,bits)\r
+ *  input p[n] is array of shorts (require n>0)\r
+ *  shift each to the left by bits>=0 bits.\r
+ */\r
+extern void k6vsllw P3((p,n,bits),\r
+       const word *p,\r
+       int n, \r
+       int bits\r
+)\r
+;\r
+\r
+#if 1  /* there isn't any significant speed gain from mmx here: */\r
+extern void Short_term_analysis_filteringx P4((u0,rp0,k_n,s),\r
+       register word * u0,\r
+       register word   * rp0,  /* [0..7]       IN      */\r
+       register int    k_n,    /*   k_end - k_start    */\r
+       register word   * s     /* [0..n-1]     IN/OUT  */\r
+)\r
+;\r
+/*\r
+#define Short_term_analysis_filtering Short_term_analysis_filteringx\r
+*/\r
+#endif\r
diff --git a/libs/codec/gsm/src/k6opt.s b/libs/codec/gsm/src/k6opt.s
new file mode 100644 (file)
index 0000000..85d28e1
--- /dev/null
@@ -0,0 +1,739 @@
+       .file   "k6opt.s"\r
+       .version        "01.01"\r
+/* gcc2_compiled.: */\r
+.section       .rodata\r
+       .align 4\r
+       .type    coefs,@object\r
+       .size    coefs,24\r
+coefs:\r
+       .value -134\r
+       .value -374\r
+       .value 0\r
+       .value 2054\r
+       .value 5741\r
+       .value 8192\r
+       .value 5741\r
+       .value 2054\r
+       .value 0\r
+       .value -374\r
+       .value -134\r
+       .value 0\r
+.text\r
+       .align 4\r
+/* void Weighting_filter (const short *e, short *x) */\r
+.globl Weighting_filter\r
+       .type    Weighting_filter,@function\r
+Weighting_filter:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %edi\r
+       pushl %esi\r
+       pushl %ebx\r
+       movl 12(%ebp),%edi\r
+       movl 8(%ebp),%ebx\r
+       addl $-10,%ebx\r
+       emms\r
+       movl $0x1000,%eax; movd %eax,%mm5  /* for rounding */\r
+       movq coefs,%mm1\r
+       movq coefs+8,%mm2\r
+       movq coefs+16,%mm3\r
+       xorl %esi,%esi\r
+       .p2align 2\r
+.L21:\r
+       movq (%ebx,%esi,2),%mm0\r
+       pmaddwd %mm1,%mm0\r
+\r
+       movq 8(%ebx,%esi,2),%mm4\r
+       pmaddwd %mm2,%mm4\r
+       paddd %mm4,%mm0\r
+\r
+       movq 16(%ebx,%esi,2),%mm4\r
+       pmaddwd %mm3,%mm4\r
+       paddd %mm4,%mm0\r
+\r
+       movq %mm0,%mm4\r
+       punpckhdq %mm0,%mm4  /* mm4 has high int32 of mm0 dup'd */\r
+       paddd %mm4,%mm0;\r
+\r
+       paddd %mm5,%mm0 /* add for roundoff */\r
+       psrad $13,%mm0\r
+       packssdw %mm0,%mm0      \r
+       movd %mm0,%eax  /* ax has result */\r
+       movw %ax,(%edi,%esi,2)\r
+       incl %esi\r
+       cmpl $39,%esi\r
+       jle .L21\r
+       emms\r
+       popl %ebx\r
+       popl %esi\r
+       popl %edi\r
+       leave\r
+       ret\r
+.Lfe1:\r
+       .size    Weighting_filter,.Lfe1-Weighting_filter\r
+\r
+.macro ccstep n\r
+.if \n\r
+       movq \n(%edi),%mm1\r
+       movq \n(%esi),%mm2\r
+.else\r
+       movq (%edi),%mm1\r
+       movq (%esi),%mm2\r
+.endif\r
+       pmaddwd %mm2,%mm1\r
+       paddd %mm1,%mm0\r
+.endm\r
+\r
+       .align 4\r
+/* long k6maxcc(const short *wt, const short *dp, short *Nc_out) */\r
+.globl k6maxcc\r
+       .type    k6maxcc,@function\r
+k6maxcc:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %edi\r
+       pushl %esi\r
+       pushl %ebx\r
+       emms\r
+       movl 8(%ebp),%edi\r
+       movl 12(%ebp),%esi\r
+       movl $0,%edx  /* will be maximum inner-product */\r
+       movl $40,%ebx\r
+       movl %ebx,%ecx /* will be index of max inner-product */\r
+       subl $80,%esi\r
+       .p2align 2\r
+.L41:\r
+       movq (%edi),%mm0\r
+       movq (%esi),%mm2\r
+       pmaddwd %mm2,%mm0\r
+       ccstep 8\r
+       ccstep 16\r
+       ccstep 24\r
+       ccstep 32\r
+       ccstep 40\r
+       ccstep 48\r
+       ccstep 56\r
+       ccstep 64\r
+       ccstep 72\r
+\r
+       movq %mm0,%mm1\r
+       punpckhdq %mm0,%mm1  /* mm1 has high int32 of mm0 dup'd */\r
+       paddd %mm1,%mm0;\r
+       movd %mm0,%eax  /* eax has result */\r
+\r
+       cmpl %edx,%eax\r
+       jle .L40\r
+       movl %eax,%edx\r
+       movl %ebx,%ecx\r
+       .p2align 2\r
+.L40:\r
+       subl $2,%esi\r
+       incl %ebx\r
+       cmpl $120,%ebx\r
+       jle .L41\r
+       movl 16(%ebp),%eax\r
+       movw %cx,(%eax)\r
+       movl %edx,%eax\r
+       emms\r
+       popl %ebx\r
+       popl %esi\r
+       popl %edi\r
+       leave\r
+       ret\r
+.Lfe2:\r
+       .size    k6maxcc,.Lfe2-k6maxcc\r
+\r
+\r
+       .align 4\r
+/* long k6iprod (const short *p, const short *q, int n) */\r
+.globl k6iprod\r
+       .type    k6iprod,@function\r
+k6iprod:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %edi\r
+       pushl %esi\r
+       emms\r
+       pxor %mm0,%mm0\r
+       movl 8(%ebp),%esi\r
+       movl 12(%ebp),%edi\r
+       movl 16(%ebp),%eax\r
+       leal -32(%esi,%eax,2),%edx /* edx = top - 32 */\r
+\r
+       cmpl %edx,%esi; ja .L202\r
+\r
+       .p2align 2\r
+.L201:\r
+       ccstep 0\r
+       ccstep 8\r
+       ccstep 16\r
+       ccstep 24\r
+\r
+       addl $32,%esi\r
+       addl $32,%edi\r
+       cmpl %edx,%esi; jbe .L201\r
+\r
+       .p2align 2\r
+.L202:\r
+       addl $24,%edx  /* now edx = top-8 */\r
+       cmpl %edx,%esi; ja .L205\r
+\r
+       .p2align 2\r
+.L203:\r
+       ccstep 0\r
+\r
+       addl $8,%esi\r
+       addl $8,%edi\r
+       cmpl %edx,%esi; jbe .L203\r
+\r
+       .p2align 2\r
+.L205:\r
+       addl $4,%edx  /* now edx = top-4 */\r
+       cmpl %edx,%esi; ja .L207\r
+\r
+       movd (%edi),%mm1\r
+       movd (%esi),%mm2\r
+       pmaddwd %mm2,%mm1\r
+       paddd %mm1,%mm0\r
+\r
+       addl $4,%esi\r
+       addl $4,%edi\r
+\r
+       .p2align 2\r
+.L207:\r
+       addl $2,%edx  /* now edx = top-2 */\r
+       cmpl %edx,%esi; ja .L209\r
+\r
+       movswl (%edi),%eax\r
+       movd %eax,%mm1\r
+       movswl (%esi),%eax\r
+       movd %eax,%mm2\r
+       pmaddwd %mm2,%mm1\r
+       paddd %mm1,%mm0\r
+\r
+       .p2align 2\r
+.L209:\r
+       movq %mm0,%mm1\r
+       punpckhdq %mm0,%mm1  /* mm1 has high int32 of mm0 dup'd */\r
+       paddd %mm1,%mm0;\r
+       movd %mm0,%eax  /* eax has result */\r
+\r
+       emms\r
+       popl %esi\r
+       popl %edi\r
+       leave\r
+       ret\r
+.Lfe3:\r
+       .size    k6iprod,.Lfe3-k6iprod\r
+\r
+\r
+       .align 4\r
+/* void k6vsraw P3((short *p, int n, int bits) */\r
+.globl k6vsraw\r
+       .type    k6vsraw,@function\r
+k6vsraw:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %esi\r
+       movl 8(%ebp),%esi\r
+       movl 16(%ebp),%ecx\r
+       andl %ecx,%ecx; jle .L399\r
+       movl 12(%ebp),%eax\r
+       leal -16(%esi,%eax,2),%edx /* edx = top - 16 */\r
+       emms\r
+       movd %ecx,%mm3\r
+       movq ones,%mm2\r
+       psllw %mm3,%mm2; psrlw $1,%mm2\r
+       cmpl %edx,%esi; ja .L306\r
+\r
+       .p2align 2\r
+.L302: /* 8 words per iteration */\r
+       movq (%esi),%mm0\r
+       movq 8(%esi),%mm1\r
+       paddsw %mm2,%mm0\r
+       psraw %mm3,%mm0;\r
+       paddsw %mm2,%mm1\r
+       psraw %mm3,%mm1;\r
+       movq %mm0,(%esi)\r
+       movq %mm1,8(%esi)\r
+       addl $16,%esi\r
+       cmpl %edx,%esi\r
+       jbe .L302\r
+\r
+       .p2align 2\r
+.L306:\r
+       addl $12,%edx /* now edx = top-4 */\r
+       cmpl %edx,%esi; ja .L310\r
+\r
+       .p2align 2\r
+.L308: /* do up to 6 words, two at a time */\r
+       movd  (%esi),%mm0\r
+       paddsw %mm2,%mm0\r
+       psraw %mm3,%mm0;\r
+       movd %mm0,(%esi)\r
+       addl $4,%esi\r
+       cmpl %edx,%esi\r
+       jbe .L308\r
+\r
+       .p2align 2\r
+.L310:\r
+       addl $2,%edx /* now edx = top-2 */\r
+       cmpl %edx,%esi; ja .L315\r
+       \r
+       movzwl (%esi),%eax\r
+       movd %eax,%mm0\r
+       paddsw %mm2,%mm0\r
+       psraw %mm3,%mm0;\r
+       movd %mm0,%eax\r
+       movw %ax,(%esi)\r
+\r
+       .p2align 2\r
+.L315:\r
+       emms\r
+.L399:\r
+       popl %esi\r
+       leave\r
+       ret\r
+.Lfe4:\r
+       .size    k6vsraw,.Lfe4-k6vsraw\r
+       \r
+       .align 4\r
+/* void k6vsllw P3((short *p, int n, int bits) */\r
+.globl k6vsllw\r
+       .type    k6vsllw,@function\r
+k6vsllw:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %esi\r
+       movl 8(%ebp),%esi\r
+       movl 16(%ebp),%ecx\r
+       andl %ecx,%ecx; jle .L499\r
+       movl 12(%ebp),%eax\r
+       leal -16(%esi,%eax,2),%edx /* edx = top - 16 */\r
+       emms\r
+       movd %ecx,%mm3\r
+       cmpl %edx,%esi; ja .L406\r
+\r
+       .p2align 2\r
+.L402: /* 8 words per iteration */\r
+       movq (%esi),%mm0\r
+       movq 8(%esi),%mm1\r
+       psllw %mm3,%mm0;\r
+       psllw %mm3,%mm1;\r
+       movq %mm0,(%esi)\r
+       movq %mm1,8(%esi)\r
+       addl $16,%esi\r
+       cmpl %edx,%esi\r
+       jbe .L402\r
+\r
+       .p2align 2\r
+.L406:\r
+       addl $12,%edx /* now edx = top-4 */\r
+       cmpl %edx,%esi; ja .L410\r
+\r
+       .p2align 2\r
+.L408: /* do up to 6 words, two at a time */\r
+       movd (%esi),%mm0\r
+       psllw %mm3,%mm0;\r
+       movd %mm0,(%esi)\r
+       addl $4,%esi\r
+       cmpl %edx,%esi\r
+       jbe .L408\r
+\r
+       .p2align 2\r
+.L410:\r
+       addl $2,%edx /* now edx = top-2 */\r
+       cmpl %edx,%esi; ja .L415\r
+       \r
+       movzwl (%esi),%eax\r
+       movd %eax,%mm0\r
+       psllw %mm3,%mm0;\r
+       movd %mm0,%eax\r
+       movw %ax,(%esi)\r
+\r
+       .p2align 2\r
+.L415:\r
+       emms\r
+.L499:\r
+       popl %esi\r
+       leave\r
+       ret\r
+.Lfe5:\r
+       .size    k6vsllw,.Lfe5-k6vsllw\r
+\r
+\r
+.section       .rodata\r
+       .align 4\r
+       .type    extremes,@object\r
+       .size    extremes,8\r
+extremes:\r
+       .long 0x80008000\r
+       .long 0x7fff7fff\r
+       .type    ones,@object\r
+       .size    ones,8\r
+ones:\r
+       .long 0x00010001\r
+       .long 0x00010001\r
+\r
+.text\r
+       .align 4\r
+/* long k6maxmin (const short *p, int n, short *out) */\r
+.globl k6maxmin\r
+       .type    k6maxmin,@function\r
+k6maxmin:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       pushl %esi\r
+       emms\r
+       movl 8(%ebp),%esi\r
+       movl 12(%ebp),%eax\r
+       leal -8(%esi,%eax,2),%edx\r
+\r
+       cmpl %edx,%esi\r
+       jbe .L52\r
+       movd extremes,%mm0\r
+       movd extremes+4,%mm1\r
+       jmp .L58\r
+\r
+       .p2align 2\r
+.L52:\r
+       movq (%esi),%mm0   /* mm0 will be max's */\r
+       movq %mm0,%mm1     /* mm1 will be min's */\r
+       addl $8,%esi\r
+       cmpl %edx,%esi\r
+       ja .L56\r
+\r
+       .p2align 2\r
+.L54:\r
+       movq (%esi),%mm2\r
+\r
+       movq %mm2,%mm3\r
+       pcmpgtw %mm0,%mm3  /* mm3 is bitmask for words where mm2 > mm0 */ \r
+       movq %mm3,%mm4\r
+       pand %mm2,%mm3     /* mm3 is mm2 masked to new max's */\r
+       pandn %mm0,%mm4    /* mm4 is mm0 masked to its max's */\r
+       por %mm3,%mm4\r
+       movq %mm4,%mm0     /* now mm0 is updated max's */\r
+       \r
+       movq %mm1,%mm3\r
+       pcmpgtw %mm2,%mm3  /* mm3 is bitmask for words where mm2 < mm1 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new min's */\r
+       pandn %mm1,%mm3    /* mm3 is mm1 masked to its min's */\r
+       por %mm3,%mm2\r
+       movq %mm2,%mm1     /* now mm1 is updated min's */\r
+\r
+       addl $8,%esi\r
+       cmpl %edx,%esi\r
+       jbe .L54\r
+\r
+       .p2align 2\r
+.L56: /* merge down the 4-word max/mins to lower 2 words */\r
+\r
+       movq %mm0,%mm2\r
+       psrlq $32,%mm2\r
+       movq %mm2,%mm3\r
+       pcmpgtw %mm0,%mm3  /* mm3 is bitmask for words where mm2 > mm0 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new max's */\r
+       pandn %mm0,%mm3    /* mm3 is mm0 masked to its max's */\r
+       por %mm3,%mm2\r
+       movq %mm2,%mm0     /* now mm0 is updated max's */\r
+\r
+       movq %mm1,%mm2\r
+       psrlq $32,%mm2\r
+       movq %mm1,%mm3\r
+       pcmpgtw %mm2,%mm3  /* mm3 is bitmask for words where mm2 < mm1 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new min's */\r
+       pandn %mm1,%mm3    /* mm3 is mm1 masked to its min's */\r
+       por %mm3,%mm2\r
+       movq %mm2,%mm1     /* now mm1 is updated min's */\r
+\r
+       .p2align 2\r
+.L58:\r
+       addl $4,%edx       /* now dx = top-4 */\r
+       cmpl %edx,%esi\r
+       ja .L62\r
+       /* here, there are >= 2 words of input remaining */\r
+       movd (%esi),%mm2\r
+\r
+       movq %mm2,%mm3\r
+       pcmpgtw %mm0,%mm3  /* mm3 is bitmask for words where mm2 > mm0 */ \r
+       movq %mm3,%mm4\r
+       pand %mm2,%mm3     /* mm3 is mm2 masked to new max's */\r
+       pandn %mm0,%mm4    /* mm4 is mm0 masked to its max's */\r
+       por %mm3,%mm4\r
+       movq %mm4,%mm0     /* now mm0 is updated max's */\r
+       \r
+       movq %mm1,%mm3\r
+       pcmpgtw %mm2,%mm3  /* mm3 is bitmask for words where mm2 < mm1 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new min's */\r
+       pandn %mm1,%mm3    /* mm3 is mm1 masked to its min's */\r
+       por %mm3,%mm2\r
+       movq %mm2,%mm1     /* now mm1 is updated min's */\r
+\r
+       addl $4,%esi\r
+\r
+       .p2align 2\r
+.L62:\r
+       /* merge down the 2-word max/mins to 1 word */\r
+\r
+       movq %mm0,%mm2\r
+       psrlq $16,%mm2\r
+       movq %mm2,%mm3\r
+       pcmpgtw %mm0,%mm3  /* mm3 is bitmask for words where mm2 > mm0 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new max's */\r
+       pandn %mm0,%mm3    /* mm3 is mm0 masked to its max's */\r
+       por %mm3,%mm2\r
+       movd %mm2,%ecx     /* cx is max so far */\r
+\r
+       movq %mm1,%mm2\r
+       psrlq $16,%mm2\r
+       movq %mm1,%mm3\r
+       pcmpgtw %mm2,%mm3  /* mm3 is bitmask for words where mm2 < mm1 */ \r
+       pand %mm3,%mm2     /* mm2 is mm2 masked to new min's */\r
+       pandn %mm1,%mm3    /* mm3 is mm1 masked to its min's */\r
+       por %mm3,%mm2\r
+       movd %mm2,%eax     /* ax is min so far */\r
+       \r
+       addl $2,%edx       /* now dx = top-2 */\r
+       cmpl %edx,%esi\r
+       ja .L65\r
+\r
+       /* here, there is one word of input left */\r
+       cmpw (%esi),%cx\r
+       jge .L64\r
+       movw (%esi),%cx\r
+       .p2align 2\r
+.L64:\r
+       cmpw (%esi),%ax\r
+       jle .L65\r
+       movw (%esi),%ax\r
+\r
+       .p2align 2\r
+.L65:  /* (finally!) cx is the max, ax the min */\r
+       movswl %cx,%ecx\r
+       movswl %ax,%eax\r
+\r
+       movl 16(%ebp),%edx /* ptr to output max,min vals */\r
+       andl %edx,%edx; jz .L77\r
+       movw %cx,(%edx)  /* max */\r
+       movw %ax,2(%edx) /* min */\r
+       .p2align 2\r
+.L77:\r
+       /* now calculate max absolute val */\r
+       negl %eax\r
+       cmpl %ecx,%eax\r
+       jge .L81\r
+       movl %ecx,%eax\r
+       .p2align 2\r
+.L81:\r
+       emms\r
+       popl %esi\r
+       leave\r
+       ret\r
+.Lfe6:\r
+       .size    k6maxmin,.Lfe6-k6maxmin\r
+\r
+/* void Short_term_analysis_filtering (short *u0, const short *rp0, int kn, short *s) */\r
+       .equiv pm_u0,8\r
+       .equiv pm_rp0,12\r
+       .equiv pm_kn,16\r
+       .equiv pm_s,20\r
+       .equiv lv_u_top,-4\r
+       .equiv lv_s_top,-8\r
+       .equiv lv_rp,-40 /* local version of rp0 with each word twice */\r
+       .align 4\r
+.globl Short_term_analysis_filteringx\r
+       .type    Short_term_analysis_filteringx,@function\r
+Short_term_analysis_filteringx:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       subl $40,%esp\r
+       pushl %edi\r
+       pushl %esi\r
+\r
+       movl pm_rp0(%ebp),%esi;\r
+       leal lv_rp(%ebp),%edi;\r
+       cld\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       emms\r
+       movl $0x4000,%eax;\r
+       movd %eax,%mm4;\r
+       punpckldq %mm4,%mm4 /* (0x00004000,0x00004000) for rounding dword product pairs */\r
+\r
+       movl pm_u0(%ebp),%eax\r
+       addl $16,%eax\r
+       movl %eax,lv_u_top(%ebp) /* UTOP */\r
+       movl pm_s(%ebp),%edx  /* edx is local s ptr throughout below */\r
+       movl pm_kn(%ebp),%eax\r
+       leal (%edx,%eax,2),%eax\r
+       movl %eax,lv_s_top(%ebp)\r
+       cmpl %eax,%edx\r
+       jae .L179\r
+       .p2align 2\r
+.L181:\r
+       leal lv_rp(%ebp),%esi  /* RP */\r
+       movl pm_u0(%ebp),%edi  /* U  */\r
+       movw (%edx),%ax /* (0,DI) */\r
+       roll $16,%eax\r
+       movw (%edx),%ax /* (DI,DI) */\r
+       .p2align 2\r
+.L185: /* RP is %esi */\r
+       movl %eax,%ecx\r
+       movw (%edi),%ax  /* (DI,U) */\r
+       movd (%esi),%mm3 /* mm3 is (0,0,RP,RP) */\r
+       movw %cx,(%edi)\r
+\r
+       movd %eax,%mm2   /* mm2 is (0,0,DI,U) */\r
+       rorl $16,%eax \r
+       movd %eax,%mm1   /* mm1 is (0,0,U,DI) */\r
+\r
+       movq %mm1,%mm0\r
+       pmullw %mm3,%mm0\r
+       pmulhw %mm3,%mm1\r
+       punpcklwd %mm1,%mm0 /* mm0 is (RP*U,RP*DI) */\r
+       paddd %mm4,%mm0     /* mm4 is 0x00004000,0x00004000 */\r
+       psrad $15,%mm0      /* (RP*U,RP*DI) adjusted */\r
+       packssdw %mm0,%mm0  /* (*,*,RP*U,RP*DI) adjusted and saturated to word */\r
+       paddsw %mm2,%mm0    /* mm0 is (?,?, DI', U') */\r
+       movd %mm0,%eax      /* (DI,U') */\r
+\r
+       addl $2,%edi\r
+       addl $4,%esi\r
+       cmpl lv_u_top(%ebp),%edi\r
+       jb .L185\r
+\r
+       rorl $16,%eax\r
+       movw %ax,(%edx) /* last DI goes to *s */\r
+       addl $2,%edx    /* next s */\r
+       cmpl lv_s_top(%ebp),%edx\r
+       jb .L181\r
+       .p2align 2\r
+.L179:\r
+       emms\r
+       popl %esi\r
+       popl %edi\r
+       leave\r
+       ret\r
+.Lfe7:\r
+       .size    Short_term_analysis_filteringx,.Lfe7-Short_term_analysis_filteringx\r
+\r
+.end\r
+\r
+/* 'as' macro's seem to be case-insensitive */\r
+.macro STEP n\r
+.if \n\r
+       movd \n(%esi),%mm3 /* mm3 is (0,0,RP,RP) */\r
+.else\r
+       movd (%esi),%mm3 /* mm3 is (0,0,RP,RP) */\r
+.endif\r
+       movq %mm5,%mm1;\r
+       movd %mm4,%ecx; movw %cx,%ax  /* (DI,U) */\r
+       psllq $48,%mm1; psrlq $16,%mm4; por %mm1,%mm4\r
+       psllq $48,%mm0; psrlq $16,%mm5; por %mm0,%mm5\r
+\r
+       movd %eax,%mm2   /* mm2 is (0,0,DI,U) */\r
+       rorl $16,%eax \r
+       movd %eax,%mm1   /* mm1 is (0,0,U,DI) */\r
+\r
+       movq %mm1,%mm0\r
+       pmullw %mm3,%mm0\r
+       pmulhw %mm3,%mm1\r
+       punpcklwd %mm1,%mm0 /* mm0 is (RP*U,RP*DI) */\r
+       paddd %mm6,%mm0     /* mm6 is 0x00004000,0x00004000 */\r
+       psrad $15,%mm0      /* (RP*U,RP*DI) adjusted */\r
+       packssdw %mm0,%mm0  /* (*,*,RP*U,RP*DI) adjusted and saturated to word */\r
+       paddsw %mm2,%mm0    /* mm0 is (?,?, DI', U') */\r
+       movd %mm0,%eax      /* (DI,U') */\r
+.endm\r
+\r
+/* void Short_term_analysis_filtering (short *u0, const short *rp0, int kn, short *s) */\r
+       .equiv pm_u0,8\r
+       .equiv pm_rp0,12\r
+       .equiv pm_kn,16\r
+       .equiv pm_s,20\r
+       .equiv lv_rp_top,-4\r
+       .equiv lv_s_top,-8\r
+       .equiv lv_rp,-40 /* local version of rp0 with each word twice */\r
+       .align 4\r
+.globl Short_term_analysis_filteringx\r
+       .type    Short_term_analysis_filteringx,@function\r
+Short_term_analysis_filteringx:\r
+       pushl %ebp\r
+       movl %esp,%ebp\r
+       subl $56,%esp\r
+       pushl %edi\r
+       pushl %esi\r
+       pushl %ebx\r
+\r
+       movl pm_rp0(%ebp),%esi;\r
+       leal lv_rp(%ebp),%edi;\r
+       cld\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       lodsw; stosw; stosw\r
+       movl %edi,lv_rp_top(%ebp)\r
+       emms\r
+\r
+       movl $0x4000,%eax;\r
+       movd %eax,%mm6;\r
+       punpckldq %mm6,%mm6 /* (0x00004000,0x00004000) for rounding dword product pairs */\r
+\r
+       movl pm_u0(%ebp),%ebx\r
+       movq (%ebx),%mm4; movq 8(%ebx),%mm5 /* the 8 u's */\r
+       movl pm_s(%ebp),%edx  /* edx is local s ptr throughout below */\r
+       movl pm_kn(%ebp),%eax\r
+       leal (%edx,%eax,2),%eax\r
+       movl %eax,lv_s_top(%ebp)\r
+       cmpl %eax,%edx\r
+       jae .L179\r
+       .p2align 2\r
+.L181:\r
+       leal lv_rp(%ebp),%esi  /* RP */\r
+       movw (%edx),%ax /* (0,DI) */\r
+       roll $16,%eax\r
+       movw (%edx),%ax /* (DI,DI) */\r
+       movd %eax,%mm0\r
+       .p2align 2\r
+.L185: /* RP is %esi */\r
+       step 0\r
+       step 4\r
+       step 8\r
+       step 12\r
+/*\r
+       step 16\r
+       step 20\r
+       step 24\r
+       step 28\r
+*/\r
+       addl $16,%esi\r
+       cmpl lv_rp_top(%ebp),%esi \r
+       jb .L185\r
+\r
+       rorl $16,%eax\r
+       movw %ax,(%edx) /* last DI goes to *s */\r
+       addl $2,%edx    /* next s */\r
+       cmpl lv_s_top(%ebp),%edx\r
+       jb .L181\r
+.L179:\r
+       movq %mm4,(%ebx); movq %mm5,8(%ebx) /* the 8 u's */\r
+       emms\r
+       popl %ebx\r
+       popl %esi\r
+       popl %edi\r
+       leave\r
+       ret\r
+.Lfe7:\r
+       .size    Short_term_analysis_filteringx,.Lfe7-Short_term_analysis_filteringx\r
+       .ident  "GCC: (GNU) 2.95.2 19991109 (Debian GNU/Linux)"\r
diff --git a/libs/codec/gsm/src/long_term.c b/libs/codec/gsm/src/long_term.c
new file mode 100644 (file)
index 0000000..b8d6601
--- /dev/null
@@ -0,0 +1,952 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+#ifdef K6OPT\r
+#include "k6opt.h"\r
+#endif\r
+/*\r
+ *  4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION\r
+ */\r
+\r
+\r
+/*\r
+ * This module computes the LTP gain (bc) and the LTP lag (Nc)\r
+ * for the long term analysis filter.   This is done by calculating a\r
+ * maximum of the cross-correlation function between the current\r
+ * sub-segment short term residual signal d[0..39] (output of\r
+ * the short term analysis filter; for simplification the index\r
+ * of this array begins at 0 and ends at 39 for each sub-segment of the\r
+ * RPE-LTP analysis) and the previous reconstructed short term\r
+ * residual signal dp[ -120 .. -1 ].  A dynamic scaling must be\r
+ * performed to avoid overflow.\r
+ */\r
+\r
+ /* The next procedure exists in six versions.  First two integer\r
+  * version (if USE_FLOAT_MUL is not defined); then four floating\r
+  * point versions, twice with proper scaling (USE_FLOAT_MUL defined),\r
+  * once without (USE_FLOAT_MUL and FAST defined, and fast run-time\r
+  * option used).  Every pair has first a Cut version (see the -C\r
+  * option to toast or the LTP_CUT option to gsm_option()), then the\r
+  * uncut one.  (For a detailed explanation of why this is altogether\r
+  * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered\r
+  * Harmful''.)\r
+  */\r
+\r
+#ifndef  USE_FLOAT_MUL\r
+\r
+#ifdef LTP_CUT\r
+\r
+static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),\r
+\r
+       struct gsm_state * st,\r
+\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       word            Nc, bc;\r
+       word            wt[40];\r
+\r
+       longword        L_result;\r
+       longword        L_max, L_power;\r
+       word            R, S, dmax, scal, best_k;\r
+       word            ltp_cut;\r
+\r
+       register word   temp, wt_k;\r
+\r
+       /*  Search of the optimum scaling of d[0..39].\r
+        */\r
+       dmax = 0;\r
+       for (k = 0; k <= 39; k++) {\r
+               temp = d[k];\r
+               temp = GSM_ABS( temp );\r
+               if (temp > dmax) {\r
+                       dmax = temp;\r
+                       best_k = k;\r
+               }\r
+       }\r
+       temp = 0;\r
+       if (dmax == 0) scal = 0;\r
+       else {\r
+               assert(dmax > 0);\r
+               temp = gsm_norm( (longword)dmax << 16 );\r
+       }\r
+       if (temp > 6) scal = 0;\r
+       else scal = 6 - temp;\r
+       assert(scal >= 0);\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+       wt_k  = SASR(d[best_k], scal);\r
+\r
+       for (lambda = 40; lambda <= 120; lambda++) {\r
+               L_result = (longword)wt_k * dp[best_k - lambda];\r
+               if (L_result > L_max) {\r
+                       Nc    = lambda;\r
+                       L_max = L_result;\r
+               }\r
+       }\r
+       *Nc_out = Nc;\r
+       L_max <<= 1;\r
+\r
+       /*  Rescaling of L_max\r
+        */\r
+       assert(scal <= 100 && scal >= -100);\r
+       L_max = L_max >> (6 - scal);    /* sub(6, scal) */\r
+\r
+       assert( Nc <= 120 && Nc >= 40);\r
+\r
+       /*   Compute the power of the reconstructed short term residual\r
+        *   signal dp[..]\r
+        */\r
+       L_power = 0;\r
+       for (k = 0; k <= 39; k++) {\r
+\r
+               register longword L_temp;\r
+\r
+               L_temp   = SASR( dp[k - Nc], 3 );\r
+               L_power += L_temp * L_temp;\r
+       }\r
+       L_power <<= 1;  /* from L_MULT */\r
+\r
+       /*  Normalization of L_max and L_power\r
+        */\r
+\r
+       if (L_max <= 0)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       temp = gsm_norm( L_power );\r
+\r
+       R = SASR( L_max   << temp, 16 );\r
+       S = SASR( L_power << temp, 16 );\r
+\r
+       /*  Coding of the LTP gain\r
+        */\r
+\r
+       /*  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#endif         /* LTP_CUT */\r
+\r
+static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       word            Nc, bc;\r
+       word            wt[40];\r
+\r
+       longword        L_max, L_power;\r
+       word            R, S, dmax, scal;\r
+       register word   temp;\r
+\r
+       /*  Search of the optimum scaling of d[0..39].\r
+        */\r
+       dmax = 0;\r
+\r
+       for (k = 0; k <= 39; k++) {\r
+               temp = d[k];\r
+               temp = GSM_ABS( temp );\r
+               if (temp > dmax) dmax = temp;\r
+       }\r
+\r
+       temp = 0;\r
+       if (dmax == 0) scal = 0;\r
+       else {\r
+               assert(dmax > 0);\r
+               temp = gsm_norm( (longword)dmax << 16 );\r
+       }\r
+\r
+       if (temp > 6) scal = 0;\r
+       else scal = 6 - temp;\r
+\r
+       assert(scal >= 0);\r
+\r
+       /*  Initialization of a working array wt\r
+        */\r
+\r
+       for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+# ifdef K6OPT\r
+       L_max = k6maxcc(wt,dp,&Nc);\r
+#      else\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+\r
+       for (lambda = 40; lambda <= 120; lambda++) {\r
+\r
+# undef STEP\r
+#              define STEP(k)  (longword)wt[k] * dp[k - lambda]\r
+\r
+               register longword L_result;\r
+\r
+               L_result  = STEP(0)  ; L_result += STEP(1) ;\r
+               L_result += STEP(2)  ; L_result += STEP(3) ;\r
+               L_result += STEP(4)  ; L_result += STEP(5)  ;\r
+               L_result += STEP(6)  ; L_result += STEP(7)  ;\r
+               L_result += STEP(8)  ; L_result += STEP(9)  ;\r
+               L_result += STEP(10) ; L_result += STEP(11) ;\r
+               L_result += STEP(12) ; L_result += STEP(13) ;\r
+               L_result += STEP(14) ; L_result += STEP(15) ;\r
+               L_result += STEP(16) ; L_result += STEP(17) ;\r
+               L_result += STEP(18) ; L_result += STEP(19) ;\r
+               L_result += STEP(20) ; L_result += STEP(21) ;\r
+               L_result += STEP(22) ; L_result += STEP(23) ;\r
+               L_result += STEP(24) ; L_result += STEP(25) ;\r
+               L_result += STEP(26) ; L_result += STEP(27) ;\r
+               L_result += STEP(28) ; L_result += STEP(29) ;\r
+               L_result += STEP(30) ; L_result += STEP(31) ;\r
+               L_result += STEP(32) ; L_result += STEP(33) ;\r
+               L_result += STEP(34) ; L_result += STEP(35) ;\r
+               L_result += STEP(36) ; L_result += STEP(37) ;\r
+               L_result += STEP(38) ; L_result += STEP(39) ;\r
+\r
+               if (L_result > L_max) {\r
+\r
+                       Nc    = lambda;\r
+                       L_max = L_result;\r
+               }\r
+       }\r
+#      endif\r
+       *Nc_out = Nc;\r
+\r
+       L_max <<= 1;\r
+\r
+       /*  Rescaling of L_max\r
+        */\r
+       assert(scal <= 100 && scal >=  -100);\r
+       L_max = L_max >> (6 - scal);    /* sub(6, scal) */\r
+\r
+       assert( Nc <= 120 && Nc >= 40);\r
+\r
+       /*   Compute the power of the reconstructed short term residual\r
+        *   signal dp[..]\r
+        */\r
+       L_power = 0;\r
+       for (k = 0; k <= 39; k++) {\r
+\r
+               register longword L_temp;\r
+\r
+               L_temp   = SASR( dp[k - Nc], 3 );\r
+               L_power += L_temp * L_temp;\r
+       }\r
+       L_power <<= 1;  /* from L_MULT */\r
+\r
+       /*  Normalization of L_max and L_power\r
+        */\r
+\r
+       if (L_max <= 0)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       temp = gsm_norm( L_power );\r
+\r
+       R = SASR( L_max   << temp, 16 );\r
+       S = SASR( L_power << temp, 16 );\r
+\r
+       /*  Coding of the LTP gain\r
+        */\r
+\r
+       /*  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#else  /* USE_FLOAT_MUL */\r
+\r
+#ifdef LTP_CUT\r
+\r
+static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),\r
+       struct gsm_state * st,          /*              IN      */\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       word            Nc, bc;\r
+       word            ltp_cut;\r
+\r
+       float           wt_float[40];\r
+       float           dp_float_base[120], * dp_float = dp_float_base + 120;\r
+\r
+       longword        L_max, L_power;\r
+       word            R, S, dmax, scal;\r
+       register word   temp;\r
+\r
+       /*  Search of the optimum scaling of d[0..39].\r
+        */\r
+       dmax = 0;\r
+\r
+       for (k = 0; k <= 39; k++) {\r
+               temp = d[k];\r
+               temp = GSM_ABS( temp );\r
+               if (temp > dmax) dmax = temp;\r
+       }\r
+\r
+       temp = 0;\r
+       if (dmax == 0) scal = 0;\r
+       else {\r
+               assert(dmax > 0);\r
+               temp = gsm_norm( (longword)dmax << 16 );\r
+       }\r
+\r
+       if (temp > 6) scal = 0;\r
+       else scal = 6 - temp;\r
+\r
+       assert(scal >= 0);\r
+       ltp_cut = (longword)SASR(dmax, scal) * st->ltp_cut / 100; \r
+\r
+\r
+       /*  Initialization of a working array wt\r
+        */\r
+\r
+       for (k = 0; k < 40; k++) {\r
+               register word w = SASR( d[k], scal );\r
+               if (w < 0 ? w > -ltp_cut : w < ltp_cut) {\r
+                       wt_float[k] = 0.0;\r
+               }\r
+               else {\r
+                       wt_float[k] =  w;\r
+               }\r
+       }\r
+       for (k = -120; k <  0; k++) dp_float[k] =  dp[k];\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+\r
+       for (lambda = 40; lambda <= 120; lambda += 9) {\r
+\r
+               /*  Calculate L_result for l = lambda .. lambda + 9.\r
+                */\r
+               register float *lp = dp_float - lambda;\r
+\r
+               register float  W;\r
+               register float  a = lp[-8], b = lp[-7], c = lp[-6],\r
+                               d = lp[-5], e = lp[-4], f = lp[-3],\r
+                               g = lp[-2], h = lp[-1];\r
+               register float  E; \r
+               register float  S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,\r
+                               S5 = 0, S6 = 0, S7 = 0, S8 = 0;\r
+\r
+#              undef STEP\r
+#              define  STEP(K, a, b, c, d, e, f, g, h) \\r
+                       if ((W = wt_float[K]) != 0.0) { \\r
+                       E = W * a; S8 += E;             \\r
+                       E = W * b; S7 += E;             \\r
+                       E = W * c; S6 += E;             \\r
+                       E = W * d; S5 += E;             \\r
+                       E = W * e; S4 += E;             \\r
+                       E = W * f; S3 += E;             \\r
+                       E = W * g; S2 += E;             \\r
+                       E = W * h; S1 += E;             \\r
+                       a  = lp[K];                     \\r
+                       E = W * a; S0 += E; } else (a = lp[K])\r
+\r
+#              define  STEP_A(K)       STEP(K, a, b, c, d, e, f, g, h)\r
+#              define  STEP_B(K)       STEP(K, b, c, d, e, f, g, h, a)\r
+#              define  STEP_C(K)       STEP(K, c, d, e, f, g, h, a, b)\r
+#              define  STEP_D(K)       STEP(K, d, e, f, g, h, a, b, c)\r
+#              define  STEP_E(K)       STEP(K, e, f, g, h, a, b, c, d)\r
+#              define  STEP_F(K)       STEP(K, f, g, h, a, b, c, d, e)\r
+#              define  STEP_G(K)       STEP(K, g, h, a, b, c, d, e, f)\r
+#              define  STEP_H(K)       STEP(K, h, a, b, c, d, e, f, g)\r
+\r
+               STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);\r
+               STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);\r
+\r
+               STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);\r
+               STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);\r
+\r
+               STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);\r
+               STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);\r
+\r
+               STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);\r
+               STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);\r
+\r
+               STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);\r
+               STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);\r
+\r
+               if (S0 > L_max) { L_max = S0; Nc = lambda;     }\r
+               if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }\r
+               if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }\r
+               if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }\r
+               if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }\r
+               if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }\r
+               if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }\r
+               if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }\r
+               if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }\r
+\r
+       }\r
+       *Nc_out = Nc;\r
+\r
+       L_max <<= 1;\r
+\r
+       /*  Rescaling of L_max\r
+        */\r
+       assert(scal <= 100 && scal >=  -100);\r
+       L_max = L_max >> (6 - scal);    /* sub(6, scal) */\r
+\r
+       assert( Nc <= 120 && Nc >= 40);\r
+\r
+       /*   Compute the power of the reconstructed short term residual\r
+        *   signal dp[..]\r
+        */\r
+       L_power = 0;\r
+       for (k = 0; k <= 39; k++) {\r
+\r
+               register longword L_temp;\r
+\r
+               L_temp   = SASR( dp[k - Nc], 3 );\r
+               L_power += L_temp * L_temp;\r
+       }\r
+       L_power <<= 1;  /* from L_MULT */\r
+\r
+       /*  Normalization of L_max and L_power\r
+        */\r
+\r
+       if (L_max <= 0)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       temp = gsm_norm( L_power );\r
+\r
+       R = SASR( L_max   << temp, 16 );\r
+       S = SASR( L_power << temp, 16 );\r
+\r
+       /*  Coding of the LTP gain\r
+        */\r
+\r
+       /*  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#endif /* LTP_CUT */\r
+\r
+static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       word            Nc, bc;\r
+\r
+       float           wt_float[40];\r
+       float           dp_float_base[120], * dp_float = dp_float_base + 120;\r
+\r
+       longword        L_max, L_power;\r
+       word            R, S, dmax, scal;\r
+       register word   temp;\r
+\r
+       /*  Search of the optimum scaling of d[0..39].\r
+        */\r
+       dmax = 0;\r
+\r
+       for (k = 0; k <= 39; k++) {\r
+               temp = d[k];\r
+               temp = GSM_ABS( temp );\r
+               if (temp > dmax) dmax = temp;\r
+       }\r
+\r
+       temp = 0;\r
+       if (dmax == 0) scal = 0;\r
+       else {\r
+               assert(dmax > 0);\r
+               temp = gsm_norm( (longword)dmax << 16 );\r
+       }\r
+\r
+       if (temp > 6) scal = 0;\r
+       else scal = 6 - temp;\r
+\r
+       assert(scal >= 0);\r
+\r
+       /*  Initialization of a working array wt\r
+        */\r
+\r
+       for (k =    0; k < 40; k++) wt_float[k] =  SASR( d[k], scal );\r
+       for (k = -120; k <  0; k++) dp_float[k] =  dp[k];\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+\r
+       for (lambda = 40; lambda <= 120; lambda += 9) {\r
+\r
+               /*  Calculate L_result for l = lambda .. lambda + 9.\r
+                */\r
+               register float *lp = dp_float - lambda;\r
+\r
+               register float  W;\r
+               register float  a = lp[-8], b = lp[-7], c = lp[-6],\r
+                               d = lp[-5], e = lp[-4], f = lp[-3],\r
+                               g = lp[-2], h = lp[-1];\r
+               register float  E; \r
+               register float  S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,\r
+                               S5 = 0, S6 = 0, S7 = 0, S8 = 0;\r
+\r
+#              undef STEP\r
+#              define  STEP(K, a, b, c, d, e, f, g, h) \\r
+                       W = wt_float[K];                \\r
+                       E = W * a; S8 += E;             \\r
+                       E = W * b; S7 += E;             \\r
+                       E = W * c; S6 += E;             \\r
+                       E = W * d; S5 += E;             \\r
+                       E = W * e; S4 += E;             \\r
+                       E = W * f; S3 += E;             \\r
+                       E = W * g; S2 += E;             \\r
+                       E = W * h; S1 += E;             \\r
+                       a  = lp[K];                     \\r
+                       E = W * a; S0 += E\r
+\r
+#              define  STEP_A(K)       STEP(K, a, b, c, d, e, f, g, h)\r
+#              define  STEP_B(K)       STEP(K, b, c, d, e, f, g, h, a)\r
+#              define  STEP_C(K)       STEP(K, c, d, e, f, g, h, a, b)\r
+#              define  STEP_D(K)       STEP(K, d, e, f, g, h, a, b, c)\r
+#              define  STEP_E(K)       STEP(K, e, f, g, h, a, b, c, d)\r
+#              define  STEP_F(K)       STEP(K, f, g, h, a, b, c, d, e)\r
+#              define  STEP_G(K)       STEP(K, g, h, a, b, c, d, e, f)\r
+#              define  STEP_H(K)       STEP(K, h, a, b, c, d, e, f, g)\r
+\r
+               STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);\r
+               STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);\r
+\r
+               STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);\r
+               STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);\r
+\r
+               STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);\r
+               STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);\r
+\r
+               STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);\r
+               STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);\r
+\r
+               STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);\r
+               STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);\r
+\r
+               if (S0 > L_max) { L_max = S0; Nc = lambda;     }\r
+               if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }\r
+               if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }\r
+               if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }\r
+               if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }\r
+               if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }\r
+               if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }\r
+               if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }\r
+               if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }\r
+       }\r
+       *Nc_out = Nc;\r
+\r
+       L_max <<= 1;\r
+\r
+       /*  Rescaling of L_max\r
+        */\r
+       assert(scal <= 100 && scal >=  -100);\r
+       L_max = L_max >> (6 - scal);    /* sub(6, scal) */\r
+\r
+       assert( Nc <= 120 && Nc >= 40);\r
+\r
+       /*   Compute the power of the reconstructed short term residual\r
+        *   signal dp[..]\r
+        */\r
+       L_power = 0;\r
+       for (k = 0; k <= 39; k++) {\r
+\r
+               register longword L_temp;\r
+\r
+               L_temp   = SASR( dp[k - Nc], 3 );\r
+               L_power += L_temp * L_temp;\r
+       }\r
+       L_power <<= 1;  /* from L_MULT */\r
+\r
+       /*  Normalization of L_max and L_power\r
+        */\r
+\r
+       if (L_max <= 0)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       temp = gsm_norm( L_power );\r
+\r
+       R = SASR( L_max   << temp, 16 );\r
+       S = SASR( L_power << temp, 16 );\r
+\r
+       /*  Coding of the LTP gain\r
+        */\r
+\r
+       /*  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#ifdef FAST\r
+#ifdef LTP_CUT\r
+\r
+static void Cut_Fast_Calculation_of_the_LTP_parameters P5((st,\r
+                                                       d,dp,bc_out,Nc_out),\r
+       struct gsm_state * st,          /*              IN      */\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       register float  wt_float;\r
+       word            Nc, bc;\r
+       word            wt_max, best_k, ltp_cut;\r
+\r
+       float           dp_float_base[120], * dp_float = dp_float_base + 120;\r
+\r
+       register float  L_result, L_max, L_power;\r
+\r
+       wt_max = 0;\r
+\r
+       for (k = 0; k < 40; ++k) {\r
+               if      ( d[k] > wt_max) wt_max =  d[best_k = k];\r
+               else if (-d[k] > wt_max) wt_max = -d[best_k = k];\r
+       }\r
+\r
+       assert(wt_max >= 0);\r
+       wt_float = (float)wt_max;\r
+\r
+       for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+\r
+       for (lambda = 40; lambda <= 120; lambda++) {\r
+               L_result = wt_float * dp_float[best_k - lambda];\r
+               if (L_result > L_max) {\r
+                       Nc    = lambda;\r
+                       L_max = L_result;\r
+               }\r
+       }\r
+\r
+       *Nc_out = Nc;\r
+       if (L_max <= 0.)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+\r
+       /*  Compute the power of the reconstructed short term residual\r
+        *  signal dp[..]\r
+        */\r
+       dp_float -= Nc;\r
+       L_power = 0;\r
+       for (k = 0; k < 40; ++k) {\r
+               register float f = dp_float[k];\r
+               L_power += f * f;\r
+       }\r
+\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       /*  Coding of the LTP gain\r
+        *  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       lambda = L_max / L_power * 32768.;\r
+       for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#endif /* LTP_CUT */\r
+\r
+static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),\r
+       register word   * d,            /* [0..39]      IN      */\r
+       register word   * dp,           /* [-120..-1]   IN      */\r
+       word            * bc_out,       /*              OUT     */\r
+       word            * Nc_out        /*              OUT     */\r
+)\r
+{\r
+       register int    k, lambda;\r
+       word            Nc, bc;\r
+\r
+       float           wt_float[40];\r
+       float           dp_float_base[120], * dp_float = dp_float_base + 120;\r
+\r
+       register float  L_max, L_power;\r
+\r
+       for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];\r
+       for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];\r
+\r
+       /* Search for the maximum cross-correlation and coding of the LTP lag\r
+        */\r
+       L_max = 0;\r
+       Nc    = 40;     /* index for the maximum cross-correlation */\r
+\r
+       for (lambda = 40; lambda <= 120; lambda += 9) {\r
+\r
+               /*  Calculate L_result for l = lambda .. lambda + 9.\r
+                */\r
+               register float *lp = dp_float - lambda;\r
+\r
+               register float  W;\r
+               register float  a = lp[-8], b = lp[-7], c = lp[-6],\r
+                               d = lp[-5], e = lp[-4], f = lp[-3],\r
+                               g = lp[-2], h = lp[-1];\r
+               register float  E; \r
+               register float  S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,\r
+                               S5 = 0, S6 = 0, S7 = 0, S8 = 0;\r
+\r
+#              undef STEP\r
+#              define  STEP(K, a, b, c, d, e, f, g, h) \\r
+                       W = wt_float[K];                \\r
+                       E = W * a; S8 += E;             \\r
+                       E = W * b; S7 += E;             \\r
+                       E = W * c; S6 += E;             \\r
+                       E = W * d; S5 += E;             \\r
+                       E = W * e; S4 += E;             \\r
+                       E = W * f; S3 += E;             \\r
+                       E = W * g; S2 += E;             \\r
+                       E = W * h; S1 += E;             \\r
+                       a  = lp[K];                     \\r
+                       E = W * a; S0 += E\r
+\r
+#              define  STEP_A(K)       STEP(K, a, b, c, d, e, f, g, h)\r
+#              define  STEP_B(K)       STEP(K, b, c, d, e, f, g, h, a)\r
+#              define  STEP_C(K)       STEP(K, c, d, e, f, g, h, a, b)\r
+#              define  STEP_D(K)       STEP(K, d, e, f, g, h, a, b, c)\r
+#              define  STEP_E(K)       STEP(K, e, f, g, h, a, b, c, d)\r
+#              define  STEP_F(K)       STEP(K, f, g, h, a, b, c, d, e)\r
+#              define  STEP_G(K)       STEP(K, g, h, a, b, c, d, e, f)\r
+#              define  STEP_H(K)       STEP(K, h, a, b, c, d, e, f, g)\r
+\r
+               STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);\r
+               STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);\r
+\r
+               STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);\r
+               STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);\r
+\r
+               STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);\r
+               STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);\r
+\r
+               STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);\r
+               STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);\r
+\r
+               STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);\r
+               STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);\r
+\r
+               if (S0 > L_max) { L_max = S0; Nc = lambda;     }\r
+               if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }\r
+               if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }\r
+               if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }\r
+               if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }\r
+               if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }\r
+               if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }\r
+               if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }\r
+               if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }\r
+       }\r
+       *Nc_out = Nc;\r
+\r
+       if (L_max <= 0.)  {\r
+               *bc_out = 0;\r
+               return;\r
+       }\r
+\r
+       /*  Compute the power of the reconstructed short term residual\r
+        *  signal dp[..]\r
+        */\r
+       dp_float -= Nc;\r
+       L_power = 0;\r
+       for (k = 0; k < 40; ++k) {\r
+               register float f = dp_float[k];\r
+               L_power += f * f;\r
+       }\r
+\r
+       if (L_max >= L_power) {\r
+               *bc_out = 3;\r
+               return;\r
+       }\r
+\r
+       /*  Coding of the LTP gain\r
+        *  Table 4.3a must be used to obtain the level DLB[i] for the\r
+        *  quantization of the LTP gain b to get the coded version bc.\r
+        */\r
+       lambda = L_max / L_power * 32768.;\r
+       for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;\r
+       *bc_out = bc;\r
+}\r
+\r
+#endif /* FAST          */\r
+#endif /* USE_FLOAT_MUL */\r
+\r
+\r
+/* 4.2.12 */\r
+\r
+static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e),\r
+       word            bc,     /*                                      IN  */\r
+       word            Nc,     /*                                      IN  */\r
+       register word   * dp,   /* previous d   [-120..-1]              IN  */\r
+       register word   * d,    /* d            [0..39]                 IN  */\r
+       register word   * dpp,  /* estimate     [0..39]                 OUT */\r
+       register word   * e     /* long term res. signal [0..39]        OUT */\r
+)\r
+/*\r
+ *  In this part, we have to decode the bc parameter to compute\r
+ *  the samples of the estimate dpp[0..39].  The decoding of bc needs the\r
+ *  use of table 4.3b.  The long term residual signal e[0..39]\r
+ *  is then calculated to be fed to the RPE encoding section.\r
+ */\r
+{\r
+       register int      k;\r
+\r
+#      undef STEP\r
+#      define STEP(BP)                                 \\r
+       for (k = 0; k <= 39; k++) {                     \\r
+               dpp[k]  = GSM_MULT_R( BP, dp[k - Nc]);  \\r
+               e[k]    = GSM_SUB( d[k], dpp[k] );      \\r
+       }\r
+\r
+       switch (bc) {\r
+       case 0: STEP(  3277 ); break;\r
+       case 1: STEP( 11469 ); break;\r
+       case 2: STEP( 21299 ); break;\r
+       case 3: STEP( 32767 ); break; \r
+       }\r
+}\r
+\r
+void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc),  /* 4x for 160 samples */\r
+\r
+       struct gsm_state        * S,\r
+\r
+       word    * d,    /* [0..39]   residual signal    IN      */\r
+       word    * dp,   /* [-120..-1] d'                IN      */\r
+\r
+       word    * e,    /* [0..39]                      OUT     */\r
+       word    * dpp,  /* [0..39]                      OUT     */\r
+       word    * Nc,   /* correlation lag              OUT     */\r
+       word    * bc    /* gain factor                  OUT     */\r
+)\r
+{\r
+       assert( d  ); assert( dp ); assert( e  );\r
+       assert( dpp); assert( Nc ); assert( bc );\r
+\r
+#if defined(FAST) && defined(USE_FLOAT_MUL)\r
+       if (S->fast) \r
+#if   defined (LTP_CUT)\r
+               if (S->ltp_cut)\r
+                       Cut_Fast_Calculation_of_the_LTP_parameters(S,\r
+                               d, dp, bc, Nc);\r
+               else\r
+#endif /* LTP_CUT */\r
+                       Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );\r
+       else \r
+#endif /* FAST & USE_FLOAT_MUL */\r
+#ifdef LTP_CUT\r
+               if (S->ltp_cut)\r
+                       Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);\r
+               else\r
+#endif\r
+                       Calculation_of_the_LTP_parameters(d, dp, bc, Nc);\r
+\r
+       Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );\r
+}\r
+\r
+/* 4.3.2 */\r
+void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp),\r
+       struct gsm_state        * S,\r
+\r
+       word                    Ncr,\r
+       word                    bcr,\r
+       register word           * erp,     /* [0..39]                    IN */\r
+       register word           * drp      /* [-120..-1] IN, [-120..40] OUT */\r
+)\r
+/*\r
+ *  This procedure uses the bcr and Ncr parameter to realize the\r
+ *  long term synthesis filtering.  The decoding of bcr needs\r
+ *  table 4.3b.\r
+ */\r
+{\r
+       register int            k;\r
+       word                    brp, drpp, Nr;\r
+\r
+       /*  Check the limits of Nr.\r
+        */\r
+       Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;\r
+       S->nrp = Nr;\r
+       assert(Nr >= 40 && Nr <= 120);\r
+\r
+       /*  Decoding of the LTP gain bcr\r
+        */\r
+       brp = gsm_QLB[ bcr ];\r
+\r
+       /*  Computation of the reconstructed short term residual \r
+        *  signal drp[0..39]\r
+        */\r
+       assert(brp != MIN_WORD);\r
+\r
+       for (k = 0; k <= 39; k++) {\r
+               drpp   = GSM_MULT_R( brp, drp[ k - Nr ] );\r
+               drp[k] = GSM_ADD( erp[k], drpp );\r
+       }\r
+\r
+       /*\r
+        *  Update of the reconstructed short term residual signal\r
+        *  drp[ -1..-120 ]\r
+        */\r
+\r
+       for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];\r
+}\r
diff --git a/libs/codec/gsm/src/lpc.c b/libs/codec/gsm/src/lpc.c
new file mode 100644 (file)
index 0000000..9e2e153
--- /dev/null
@@ -0,0 +1,369 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+#ifdef K6OPT\r
+#include "k6opt.h"\r
+#endif\r
+\r
+#undef P\r
+\r
+/*\r
+ *  4.2.4 .. 4.2.7 LPC ANALYSIS SECTION\r
+ */\r
+\r
+/* 4.2.4 */\r
+\r
+\r
+static void Autocorrelation P2((s, L_ACF),\r
+       word     * s,           /* [0..159]     IN/OUT  */\r
+       longword * L_ACF)       /* [0..8]       OUT     */\r
+/*\r
+ *  The goal is to compute the array L_ACF[k].  The signal s[i] must\r
+ *  be scaled in order to avoid an overflow situation.\r
+ */\r
+{\r
+       register int    k, i;\r
+\r
+       word            temp, smax, scalauto;\r
+\r
+#ifdef USE_FLOAT_MUL\r
+       float           float_s[160];\r
+#endif\r
+\r
+       /*  Dynamic scaling of the array  s[0..159]\r
+        */\r
+\r
+       /*  Search for the maximum.\r
+        */\r
+#ifndef K6OPT\r
+       smax = 0;\r
+       for (k = 0; k <= 159; k++) {\r
+               temp = GSM_ABS( s[k] );\r
+               if (temp > smax) smax = temp;\r
+       }\r
+#else\r
+       {\r
+               longword lmax;\r
+               lmax = k6maxmin(s,160,NULL);\r
+               smax = (lmax > MAX_WORD) ? MAX_WORD : lmax;\r
+       }\r
+#endif\r
+       /*  Computation of the scaling factor.\r
+        */\r
+       if (smax == 0) scalauto = 0;\r
+       else {\r
+               assert(smax > 0);\r
+               scalauto = 4 - gsm_norm( (longword)smax << 16 );/* sub(4,..) */\r
+       }\r
+\r
+       /*  Scaling of the array s[0...159]\r
+        */\r
+\r
+       if (scalauto > 0) {\r
+#      ifndef K6OPT\r
+\r
+# ifdef USE_FLOAT_MUL\r
+#   define SCALE(n)    \\r
+       case n: for (k = 0; k <= 159; k++) \\r
+                       float_s[k] = (float)    \\r
+                               (s[k] = GSM_MULT_R(s[k], 16384 >> (n-1)));\\r
+               break;\r
+# else \r
+#   define SCALE(n)    \\r
+       case n: for (k = 0; k <= 159; k++) \\r
+                       s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\\r
+               break;\r
+# endif /* USE_FLOAT_MUL */\r
+\r
+               switch (scalauto) {\r
+               SCALE(1)\r
+               SCALE(2)\r
+               SCALE(3)\r
+               SCALE(4)\r
+               }\r
+# undef        SCALE\r
+\r
+#      else /* K6OPT */\r
+               k6vsraw(s,160,scalauto);\r
+#      endif\r
+       }\r
+# ifdef        USE_FLOAT_MUL\r
+       else for (k = 0; k <= 159; k++) float_s[k] = (float) s[k];\r
+# endif\r
+\r
+       /*  Compute the L_ACF[..].\r
+        */\r
+#ifndef K6OPT\r
+       {\r
+# ifdef        USE_FLOAT_MUL\r
+               register float * sp = float_s;\r
+               register float   sl = *sp;\r
+\r
+#              define STEP(k)   L_ACF[k] += (longword)(sl * sp[ -(k) ]);\r
+# else\r
+               word  * sp = s;\r
+               word    sl = *sp;\r
+\r
+#              define STEP(k)   L_ACF[k] += ((longword)sl * sp[ -(k) ]);\r
+# endif\r
+\r
+#      define NEXTI     sl = *++sp\r
+\r
+\r
+       for (k = 9; k--; L_ACF[k] = 0) ;\r
+\r
+       STEP (0);\r
+       NEXTI;\r
+       STEP(0); STEP(1);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2); STEP(3);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2); STEP(3); STEP(4);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6);\r
+       NEXTI;\r
+       STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); STEP(7);\r
+\r
+       for (i = 8; i <= 159; i++) {\r
+\r
+               NEXTI;\r
+\r
+               STEP(0);\r
+               STEP(1); STEP(2); STEP(3); STEP(4);\r
+               STEP(5); STEP(6); STEP(7); STEP(8);\r
+       }\r
+\r
+       for (k = 9; k--; L_ACF[k] <<= 1) ; \r
+\r
+       }\r
+\r
+#else\r
+       {\r
+               int k;\r
+               for (k=0; k<9; k++) {\r
+                       L_ACF[k] = 2*k6iprod(s,s+k,160-k);\r
+               }\r
+       }\r
+#endif\r
+       /*   Rescaling of the array s[0..159]\r
+        */\r
+       if (scalauto > 0) {\r
+               assert(scalauto <= 4); \r
+#ifndef K6OPT\r
+               for (k = 160; k--; *s++ <<= scalauto) ;\r
+#      else /* K6OPT */\r
+               k6vsllw(s,160,scalauto);\r
+#      endif\r
+       }\r
+}\r
+\r
+#if defined(USE_FLOAT_MUL) && defined(FAST)\r
+\r
+static void Fast_Autocorrelation P2((s, L_ACF),\r
+       word * s,               /* [0..159]     IN/OUT  */\r
+       longword * L_ACF)       /* [0..8]       OUT     */\r
+{\r
+       register int    k, i;\r
+       float f_L_ACF[9];\r
+       float scale;\r
+\r
+       float          s_f[160];\r
+       register float *sf = s_f;\r
+\r
+       for (i = 0; i < 160; ++i) sf[i] = s[i];\r
+       for (k = 0; k <= 8; k++) {\r
+               register float L_temp2 = 0;\r
+               register float *sfl = sf - k;\r
+               for (i = k; i < 160; ++i) L_temp2 += sf[i] * sfl[i];\r
+               f_L_ACF[k] = L_temp2;\r
+       }\r
+       scale = MAX_LONGWORD / f_L_ACF[0];\r
+\r
+       for (k = 0; k <= 8; k++) {\r
+               L_ACF[k] = f_L_ACF[k] * scale;\r
+       }\r
+}\r
+#endif /* defined (USE_FLOAT_MUL) && defined (FAST) */\r
+\r
+/* 4.2.5 */\r
+\r
+static void Reflection_coefficients P2( (L_ACF, r),\r
+       longword        * L_ACF,                /* 0...8        IN      */\r
+       register word   * r                     /* 0...7        OUT     */\r
+)\r
+{\r
+       register int    i, m, n;\r
+       register word   temp;\r
+       word            ACF[9]; /* 0..8 */\r
+       word            P[  9]; /* 0..8 */\r
+       word            K[  9]; /* 2..8 */\r
+\r
+       /*  Schur recursion with 16 bits arithmetic.\r
+        */\r
+\r
+       if (L_ACF[0] == 0) {\r
+               for (i = 8; i--; *r++ = 0) ;\r
+               return;\r
+       }\r
+\r
+       assert( L_ACF[0] != 0 );\r
+       temp = gsm_norm( L_ACF[0] );\r
+\r
+       assert(temp >= 0 && temp < 32);\r
+\r
+       /* ? overflow ? */\r
+       for (i = 0; i <= 8; i++) ACF[i] = SASR( L_ACF[i] << temp, 16 );\r
+\r
+       /*   Initialize array P[..] and K[..] for the recursion.\r
+        */\r
+\r
+       for (i = 1; i <= 7; i++) K[ i ] = ACF[ i ];\r
+       for (i = 0; i <= 8; i++) P[ i ] = ACF[ i ];\r
+\r
+       /*   Compute reflection coefficients\r
+        */\r
+       for (n = 1; n <= 8; n++, r++) {\r
+\r
+               temp = P[1];\r
+               temp = GSM_ABS(temp);\r
+               if (P[0] < temp) {\r
+                       for (i = n; i <= 8; i++) *r++ = 0;\r
+                       return;\r
+               }\r
+\r
+               *r = gsm_div( temp, P[0] );\r
+\r
+               assert(*r >= 0);\r
+               if (P[1] > 0) *r = -*r;         /* r[n] = sub(0, r[n]) */\r
+               assert (*r != MIN_WORD);\r
+               if (n == 8) return; \r
+\r
+               /*  Schur recursion\r
+                */\r
+               temp = GSM_MULT_R( P[1], *r );\r
+               P[0] = GSM_ADD( P[0], temp );\r
+\r
+               for (m = 1; m <= 8 - n; m++) {\r
+                       temp     = GSM_MULT_R( K[ m   ],    *r );\r
+                       P[m]     = GSM_ADD(    P[ m+1 ],  temp );\r
+\r
+                       temp     = GSM_MULT_R( P[ m+1 ],    *r );\r
+                       K[m]     = GSM_ADD(    K[ m   ],  temp );\r
+               }\r
+       }\r
+}\r
+\r
+/* 4.2.6 */\r
+\r
+static void Transformation_to_Log_Area_Ratios P1((r),\r
+       register word   * r                     /* 0..7    IN/OUT */\r
+)\r
+/*\r
+ *  The following scaling for r[..] and LAR[..] has been used:\r
+ *\r
+ *  r[..]   = integer( real_r[..]*32768. ); -1 <= real_r < 1.\r
+ *  LAR[..] = integer( real_LAR[..] * 16384 );\r
+ *  with -1.625 <= real_LAR <= 1.625\r
+ */\r
+{\r
+       register word   temp;\r
+       register int    i;\r
+\r
+\r
+       /* Computation of the LAR[0..7] from the r[0..7]\r
+        */\r
+       for (i = 1; i <= 8; i++, r++) {\r
+\r
+               temp = *r;\r
+               temp = GSM_ABS(temp);\r
+               assert(temp >= 0);\r
+\r
+               if (temp < 22118) {\r
+                       temp >>= 1;\r
+               } else if (temp < 31130) {\r
+                       assert( temp >= 11059 );\r
+                       temp -= 11059;\r
+               } else {\r
+                       assert( temp >= 26112 );\r
+                       temp -= 26112;\r
+                       temp <<= 2;\r
+               }\r
+\r
+               *r = *r < 0 ? -temp : temp;\r
+               assert( *r != MIN_WORD );\r
+       }\r
+}\r
+\r
+/* 4.2.7 */\r
+\r
+static void Quantization_and_coding P1((LAR),\r
+       register word * LAR     /* [0..7]       IN/OUT  */\r
+)\r
+{\r
+       register word   temp;\r
+\r
+\r
+       /*  This procedure needs four tables; the following equations\r
+        *  give the optimum scaling for the constants:\r
+        *  \r
+        *  A[0..7] = integer( real_A[0..7] * 1024 )\r
+        *  B[0..7] = integer( real_B[0..7] *  512 )\r
+        *  MAC[0..7] = maximum of the LARc[0..7]\r
+        *  MIC[0..7] = minimum of the LARc[0..7]\r
+        */\r
+\r
+#      undef STEP\r
+#      define  STEP( A, B, MAC, MIC )          \\r
+               temp = GSM_MULT( A,   *LAR );   \\r
+               temp = GSM_ADD(  temp,   B );   \\r
+               temp = GSM_ADD(  temp, 256 );   \\r
+               temp = SASR(     temp,   9 );   \\r
+               *LAR  =  temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \\r
+               LAR++;\r
+\r
+       STEP(  20480,     0,  31, -32 );\r
+       STEP(  20480,     0,  31, -32 );\r
+       STEP(  20480,  2048,  15, -16 );\r
+       STEP(  20480, -2560,  15, -16 );\r
+\r
+       STEP(  13964,    94,   7,  -8 );\r
+       STEP(  15360, -1792,   7,  -8 );\r
+       STEP(   8534,  -341,   3,  -4 );\r
+       STEP(   9036, -1144,   3,  -4 );\r
+\r
+#      undef   STEP\r
+}\r
+\r
+void Gsm_LPC_Analysis P3((S, s,LARc),\r
+       struct gsm_state *S,\r
+       word             * s,           /* 0..159 signals       IN/OUT  */\r
+        word            * LARc)        /* 0..7   LARc's        OUT     */\r
+{\r
+       longword        L_ACF[9];\r
+\r
+#if defined(USE_FLOAT_MUL) && defined(FAST)\r
+       if (S->fast) Fast_Autocorrelation (s,     L_ACF );\r
+       else\r
+#endif\r
+       Autocorrelation                   (s,     L_ACF );\r
+       Reflection_coefficients           (L_ACF, LARc  );\r
+       Transformation_to_Log_Area_Ratios (LARc);\r
+       Quantization_and_coding           (LARc);\r
+}\r
diff --git a/libs/codec/gsm/src/preprocess.c b/libs/codec/gsm/src/preprocess.c
new file mode 100644 (file)
index 0000000..ed12ad2
--- /dev/null
@@ -0,0 +1,131 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include       <stdio.h>\r
+#include       <assert.h>\r
+\r
+#include "private.h"\r
+\r
+#include       "gsm.h"\r
+#include       "proto.h"\r
+\r
+/*     4.2.0 .. 4.2.3  PREPROCESSING SECTION\r
+ *  \r
+ *     After A-law to linear conversion (or directly from the\r
+ *     Ato D converter) the following scaling is assumed for\r
+ *     input to the RPE-LTP algorithm:\r
+ *\r
+ *      in:  0.1.....................12\r
+ *          S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*\r
+ *\r
+ *     Where S is the sign bit, v a valid bit, and * a "don't care" bit.\r
+ *     The original signal is called sop[..]\r
+ *\r
+ *      out:   0.1................... 12 \r
+ *          S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0\r
+ */\r
+\r
+\r
+void Gsm_Preprocess P3((S, s, so),\r
+       struct gsm_state * S,\r
+       word             * s,\r
+       word             * so )         /* [0..159]     IN/OUT  */\r
+{\r
+\r
+       word       z1 = S->z1;\r
+       longword L_z2 = S->L_z2;\r
+       word       mp = S->mp;\r
+\r
+       word            s1;\r
+\r
+\r
+       word            SO;\r
+\r
+       ulongword       utmp;           /* for L_ADD */\r
+\r
+       register int            k = 160;\r
+\r
+       while (k--) {\r
+\r
+       /*  4.2.1   Downscaling of the input signal\r
+        */\r
+               /* SO = SASR( *s, 3 ) << 2;*/\r
+               SO = SASR( *s, 1 ) & ~3;\r
+               s++;\r
+\r
+               assert (SO >= -0x4000); /* downscaled by     */\r
+               assert (SO <=  0x3FFC); /* previous routine. */\r
+\r
+\r
+       /*  4.2.2   Offset compensation\r
+        * \r
+        *  This part implements a high-pass filter and requires extended\r
+        *  arithmetic precision for the recursive part of this filter.\r
+        *  The input of this procedure is the array so[0...159] and the\r
+        *  output the array sof[ 0...159 ].\r
+        */\r
+               /*   Compute the non-recursive part\r
+                */\r
+\r
+               s1 = SO - z1;                   /* s1 = gsm_sub( *so, z1 ); */\r
+               z1 = SO;\r
+\r
+               assert(s1 != MIN_WORD);\r
+\r
+       /* SJB Remark: float might be faster than the mess that follows */\r
+\r
+               /*   Compute the recursive part\r
+                */\r
+\r
+               /*   Execution of a 31 bv 16 bits multiplication\r
+                */\r
+               {\r
+               word            msp;\r
+#ifndef __GNUC__ \r
+               word            lsp;\r
+#endif\r
+               longword L_s2;\r
+               longword L_temp;\r
+               \r
+               L_s2 = s1;\r
+               L_s2 <<= 15;\r
+#ifndef __GNUC__ \r
+               msp = SASR( L_z2, 15 );\r
+               lsp = L_z2 & 0x7fff; /* gsm_L_sub(L_z2,(msp<<15)); */\r
+\r
+               L_s2  += GSM_MULT_R( lsp, 32735 );\r
+               L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/\r
+               L_z2   = GSM_L_ADD( L_temp, L_s2 );\r
+               /* above does L_z2  = L_z2 * 0x7fd5/0x8000 + L_s2 */\r
+#else\r
+               L_z2 = ((long long)L_z2*32735 + 0x4000)>>15;\r
+               /* alternate (ansi) version of above line does slightly different rounding:\r
+                * L_temp = L_z2 >> 9;\r
+                * L_temp += L_temp >> 5;\r
+                * L_temp = (++L_temp) >> 1;\r
+                * L_z2 = L_z2 - L_temp;\r
+                */\r
+               L_z2 = GSM_L_ADD(L_z2,L_s2);\r
+#endif\r
+               /*    Compute sof[k] with rounding\r
+                */\r
+               L_temp = GSM_L_ADD( L_z2, 16384 );\r
+\r
+       /*   4.2.3  Preemphasis\r
+        */\r
+\r
+               msp   = GSM_MULT_R( mp, -28180 );\r
+               mp    = SASR( L_temp, 15 );\r
+               *so++ = GSM_ADD( mp, msp );\r
+               }\r
+       }\r
+\r
+       S->z1   = z1;\r
+       S->L_z2 = L_z2;\r
+       S->mp   = mp;\r
+}\r
diff --git a/libs/codec/gsm/src/rpe.c b/libs/codec/gsm/src/rpe.c
new file mode 100644 (file)
index 0000000..7f3b7eb
--- /dev/null
@@ -0,0 +1,490 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+\r
+/*  4.2.13 .. 4.2.17  RPE ENCODING SECTION\r
+ */\r
+\r
+/* 4.2.13 */\r
+#ifdef K6OPT\r
+#include "k6opt.h"\r
+#else\r
+static void Weighting_filter P2((e, x),\r
+       register word   * e,            /* signal [-5..0.39.44] IN  */\r
+       word            * x             /* signal [0..39]       OUT */\r
+)\r
+/*\r
+ *  The coefficients of the weighting filter are stored in a table\r
+ *  (see table 4.4).  The following scaling is used:\r
+ *\r
+ *     H[0..10] = integer( real_H[ 0..10] * 8192 ); \r
+ */\r
+{\r
+       /* word                 wt[ 50 ]; */\r
+\r
+       register longword       L_result;\r
+       register int            k /* , i */ ;\r
+\r
+       /*  Initialization of a temporary working array wt[0...49]\r
+        */\r
+\r
+       /* for (k =  0; k <=  4; k++) wt[k] = 0;\r
+        * for (k =  5; k <= 44; k++) wt[k] = *e++;\r
+        * for (k = 45; k <= 49; k++) wt[k] = 0;\r
+        *\r
+        *  (e[-5..-1] and e[40..44] are allocated by the caller,\r
+        *  are initially zero and are not written anywhere.)\r
+        */\r
+       e -= 5;\r
+\r
+       /*  Compute the signal x[0..39]\r
+        */ \r
+       for (k = 0; k <= 39; k++) {\r
+\r
+               L_result = 8192 >> 1;\r
+\r
+               /* for (i = 0; i <= 10; i++) {\r
+                *      L_temp   = GSM_L_MULT( wt[k+i], gsm_H[i] );\r
+                *      L_result = GSM_L_ADD( L_result, L_temp );\r
+                * }\r
+                */\r
+\r
+#undef STEP\r
+#define        STEP( i, H )    (e[ k + i ] * (longword)H)\r
+\r
+               /*  Every one of these multiplications is done twice --\r
+                *  but I don't see an elegant way to optimize this. \r
+                *  Do you?\r
+                */\r
+\r
+#ifdef STUPID_COMPILER\r
+               L_result += STEP(       0,      -134 ) ;\r
+               L_result += STEP(       1,      -374 )  ;\r
+                      /* + STEP(       2,      0    )  */\r
+               L_result += STEP(       3,      2054 ) ;\r
+               L_result += STEP(       4,      5741 ) ;\r
+               L_result += STEP(       5,      8192 ) ;\r
+               L_result += STEP(       6,      5741 ) ;\r
+               L_result += STEP(       7,      2054 ) ;\r
+                      /* + STEP(       8,      0    )  */\r
+               L_result += STEP(       9,      -374 ) ;\r
+               L_result += STEP(       10,     -134 ) ;\r
+#else\r
+               L_result +=\r
+                 STEP( 0,      -134 ) \r
+               + STEP( 1,      -374 ) \r
+            /* + STEP( 2,      0    )  */\r
+               + STEP( 3,      2054 ) \r
+               + STEP( 4,      5741 ) \r
+               + STEP( 5,      8192 ) \r
+               + STEP( 6,      5741 ) \r
+               + STEP( 7,      2054 ) \r
+            /* + STEP( 8,      0    )  */\r
+               + STEP( 9,      -374 ) \r
+               + STEP(10,      -134 )\r
+               ;\r
+#endif\r
+\r
+               /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *)\r
+                * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *)\r
+                *\r
+                * x[k] = SASR( L_result, 16 );\r
+                */\r
+\r
+               /* 2 adds vs. >>16 => 14, minus one shift to compensate for\r
+                * those we lost when replacing L_MULT by '*'.\r
+                */\r
+\r
+               L_result = SASR( L_result, 13 );\r
+               x[k] =  (  L_result < MIN_WORD ? MIN_WORD\r
+                       : (L_result > MAX_WORD ? MAX_WORD : L_result ));\r
+       }\r
+}\r
+#endif /* K6OPT */\r
+\r
+/* 4.2.14 */\r
+\r
+static void RPE_grid_selection P3((x,xM,Mc_out),\r
+       word            * x,            /* [0..39]              IN  */ \r
+       word            * xM,           /* [0..12]              OUT */\r
+       word            * Mc_out        /*                      OUT */\r
+)\r
+/*\r
+ *  The signal x[0..39] is used to select the RPE grid which is\r
+ *  represented by Mc.\r
+ */\r
+{\r
+       /* register word        temp1;  */\r
+       register int            /* m, */  i;\r
+       register longword       L_result, L_temp;\r
+       longword                EM;     /* xxx should be L_EM? */\r
+       word                    Mc;\r
+\r
+       longword                L_common_0_3;\r
+\r
+       EM = 0;\r
+       Mc = 0;\r
+\r
+       /* for (m = 0; m <= 3; m++) {\r
+        *      L_result = 0;\r
+        *\r
+        *\r
+        *      for (i = 0; i <= 12; i++) {\r
+        *\r
+        *              temp1    = SASR( x[m + 3*i], 2 );\r
+        *\r
+        *              assert(temp1 != MIN_WORD);\r
+        *\r
+        *              L_temp   = GSM_L_MULT( temp1, temp1 );\r
+        *              L_result = GSM_L_ADD( L_temp, L_result );\r
+        *      }\r
+        * \r
+        *      if (L_result > EM) {\r
+        *              Mc = m;\r
+        *              EM = L_result;\r
+        *      }\r
+        * }\r
+        */\r
+\r
+#undef STEP\r
+#define        STEP( m, i )            L_temp = SASR( x[m + 3 * i], 2 );       \\r
+                               L_result += L_temp * L_temp;\r
+\r
+       /* common part of 0 and 3 */\r
+\r
+       L_result = 0;\r
+       STEP( 0, 1 ); STEP( 0, 2 ); STEP( 0, 3 ); STEP( 0, 4 );\r
+       STEP( 0, 5 ); STEP( 0, 6 ); STEP( 0, 7 ); STEP( 0, 8 );\r
+       STEP( 0, 9 ); STEP( 0, 10); STEP( 0, 11); STEP( 0, 12);\r
+       L_common_0_3 = L_result;\r
+\r
+       /* i = 0 */\r
+\r
+       STEP( 0, 0 );\r
+       L_result <<= 1; /* implicit in L_MULT */\r
+       EM = L_result;\r
+\r
+       /* i = 1 */\r
+\r
+       L_result = 0;\r
+       STEP( 1, 0 );\r
+       STEP( 1, 1 ); STEP( 1, 2 ); STEP( 1, 3 ); STEP( 1, 4 );\r
+       STEP( 1, 5 ); STEP( 1, 6 ); STEP( 1, 7 ); STEP( 1, 8 );\r
+       STEP( 1, 9 ); STEP( 1, 10); STEP( 1, 11); STEP( 1, 12);\r
+       L_result <<= 1;\r
+       if (L_result > EM) {\r
+               Mc = 1;\r
+               EM = L_result;\r
+       }\r
+\r
+       /* i = 2 */\r
+\r
+       L_result = 0;\r
+       STEP( 2, 0 );\r
+       STEP( 2, 1 ); STEP( 2, 2 ); STEP( 2, 3 ); STEP( 2, 4 );\r
+       STEP( 2, 5 ); STEP( 2, 6 ); STEP( 2, 7 ); STEP( 2, 8 );\r
+       STEP( 2, 9 ); STEP( 2, 10); STEP( 2, 11); STEP( 2, 12);\r
+       L_result <<= 1;\r
+       if (L_result > EM) {\r
+               Mc = 2;\r
+               EM = L_result;\r
+       }\r
+\r
+       /* i = 3 */\r
+\r
+       L_result = L_common_0_3;\r
+       STEP( 3, 12 );\r
+       L_result <<= 1;\r
+       if (L_result > EM) {\r
+               Mc = 3;\r
+               EM = L_result;\r
+       }\r
+\r
+       /**/\r
+\r
+       /*  Down-sampling by a factor 3 to get the selected xM[0..12]\r
+        *  RPE sequence.\r
+        */\r
+       for (i = 0; i <= 12; i ++) xM[i] = x[Mc + 3*i];\r
+       *Mc_out = Mc;\r
+}\r
+\r
+/* 4.12.15 */\r
+\r
+static void APCM_quantization_xmaxc_to_exp_mant P3((xmaxc,exp_out,mant_out),\r
+       word            xmaxc,          /* IN   */\r
+       word            * exp_out,      /* OUT  */\r
+       word            * mant_out )    /* OUT  */\r
+{\r
+       word    exp, mant;\r
+\r
+       /* Compute exponent and mantissa of the decoded version of xmaxc\r
+        */\r
+\r
+       exp = 0;\r
+       if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1;\r
+       mant = xmaxc - (exp << 3);\r
+\r
+       if (mant == 0) {\r
+               exp  = -4;\r
+               mant = 7;\r
+       }\r
+       else {\r
+               while (mant <= 7) {\r
+                       mant = mant << 1 | 1;\r
+                       exp--;\r
+               }\r
+               mant -= 8;\r
+       }\r
+\r
+       assert( exp  >= -4 && exp <= 6 );\r
+       assert( mant >= 0 && mant <= 7 );\r
+\r
+       *exp_out  = exp;\r
+       *mant_out = mant;\r
+}\r
+\r
+static void APCM_quantization P5((xM,xMc,mant_out,exp_out,xmaxc_out),\r
+       word            * xM,           /* [0..12]              IN      */\r
+\r
+       word            * xMc,          /* [0..12]              OUT     */\r
+       word            * mant_out,     /*                      OUT     */\r
+       word            * exp_out,      /*                      OUT     */\r
+       word            * xmaxc_out     /*                      OUT     */\r
+)\r
+{\r
+       int     i, itest;\r
+\r
+       word    xmax, xmaxc, temp, temp1, temp2;\r
+       word    exp, mant;\r
+\r
+\r
+       /*  Find the maximum absolute value xmax of xM[0..12].\r
+        */\r
+\r
+       xmax = 0;\r
+       for (i = 0; i <= 12; i++) {\r
+               temp = xM[i];\r
+               temp = GSM_ABS(temp);\r
+               if (temp > xmax) xmax = temp;\r
+       }\r
+\r
+       /*  Qantizing and coding of xmax to get xmaxc.\r
+        */\r
+\r
+       exp   = 0;\r
+       temp  = SASR( xmax, 9 );\r
+       itest = 0;\r
+\r
+       for (i = 0; i <= 5; i++) {\r
+\r
+               itest |= (temp <= 0);\r
+               temp = SASR( temp, 1 );\r
+\r
+               assert(exp <= 5);\r
+               if (itest == 0) exp++;          /* exp = add (exp, 1) */\r
+       }\r
+\r
+       assert(exp <= 6 && exp >= 0);\r
+       temp = exp + 5;\r
+\r
+       assert(temp <= 11 && temp >= 0);\r
+       xmaxc = gsm_add( SASR(xmax, temp), exp << 3 );\r
+\r
+       /*   Quantizing and coding of the xM[0..12] RPE sequence\r
+        *   to get the xMc[0..12]\r
+        */\r
+\r
+       APCM_quantization_xmaxc_to_exp_mant( xmaxc, &exp, &mant );\r
+\r
+       /*  This computation uses the fact that the decoded version of xmaxc\r
+        *  can be calculated by using the exponent and the mantissa part of\r
+        *  xmaxc (logarithmic table).\r
+        *  So, this method avoids any division and uses only a scaling\r
+        *  of the RPE samples by a function of the exponent.  A direct \r
+        *  multiplication by the inverse of the mantissa (NRFAC[0..7]\r
+        *  found in table 4.5) gives the 3 bit coded version xMc[0..12]\r
+        *  of the RPE samples.\r
+        */\r
+\r
+\r
+       /* Direct computation of xMc[0..12] using table 4.5\r
+        */\r
+\r
+       assert( exp <= 4096 && exp >= -4096);\r
+       assert( mant >= 0 && mant <= 7 ); \r
+\r
+       temp1 = 6 - exp;                /* normalization by the exponent */\r
+       temp2 = gsm_NRFAC[ mant ];      /* inverse mantissa              */\r
+\r
+       for (i = 0; i <= 12; i++) {\r
+\r
+               assert(temp1 >= 0 && temp1 < 16);\r
+\r
+               temp = xM[i] << temp1;\r
+               temp = GSM_MULT( temp, temp2 );\r
+               temp = SASR(temp, 12);\r
+               xMc[i] = temp + 4;              /* see note below */\r
+       }\r
+\r
+       /*  NOTE: This equation is used to make all the xMc[i] positive.\r
+        */\r
+\r
+       *mant_out  = mant;\r
+       *exp_out   = exp;\r
+       *xmaxc_out = xmaxc;\r
+}\r
+\r
+/* 4.2.16 */\r
+\r
+static void APCM_inverse_quantization P4((xMc,mant,exp,xMp),\r
+       register word   * xMc,  /* [0..12]                      IN      */\r
+       word            mant,\r
+       word            exp,\r
+       register word   * xMp)  /* [0..12]                      OUT     */\r
+/* \r
+ *  This part is for decoding the RPE sequence of coded xMc[0..12]\r
+ *  samples to obtain the xMp[0..12] array.  Table 4.6 is used to get\r
+ *  the mantissa of xmaxc (FAC[0..7]).\r
+ */\r
+{\r
+       int     i;\r
+       word    temp, temp1, temp2, temp3;\r
+\r
+       assert( mant >= 0 && mant <= 7 ); \r
+\r
+       temp1 = gsm_FAC[ mant ];        /* see 4.2-15 for mant */\r
+       temp2 = gsm_sub( 6, exp );      /* see 4.2-15 for exp  */\r
+       temp3 = gsm_asl( 1, gsm_sub( temp2, 1 ));\r
+\r
+       for (i = 13; i--;) {\r
+\r
+               assert( *xMc <= 7 && *xMc >= 0 );       /* 3 bit unsigned */\r
+\r
+               /* temp = gsm_sub( *xMc++ << 1, 7 ); */\r
+               temp = (*xMc++ << 1) - 7;               /* restore sign   */\r
+               assert( temp <= 7 && temp >= -7 );      /* 4 bit signed   */\r
+\r
+               temp <<= 12;                            /* 16 bit signed  */\r
+               temp = GSM_MULT_R( temp1, temp );\r
+               temp = GSM_ADD( temp, temp3 );\r
+               *xMp++ = gsm_asr( temp, temp2 );\r
+       }\r
+}\r
+\r
+/* 4.2.17 */\r
+\r
+static void RPE_grid_positioning P3((Mc,xMp,ep),\r
+       word            Mc,             /* grid position        IN      */\r
+       register word   * xMp,          /* [0..12]              IN      */\r
+       register word   * ep            /* [0..39]              OUT     */\r
+)\r
+/*\r
+ *  This procedure computes the reconstructed long term residual signal\r
+ *  ep[0..39] for the LTP analysis filter.  The inputs are the Mc\r
+ *  which is the grid position selection and the xMp[0..12] decoded\r
+ *  RPE samples which are upsampled by a factor of 3 by inserting zero\r
+ *  values.\r
+ */\r
+{\r
+       int     i = 13;\r
+\r
+       assert(0 <= Mc && Mc <= 3);\r
+\r
+        switch (Mc) {\r
+                case 3: *ep++ = 0;\r
+                case 2:  do {\r
+                                *ep++ = 0;\r
+                case 1:         *ep++ = 0;\r
+                case 0:         *ep++ = *xMp++;\r
+                         } while (--i);\r
+        }\r
+        while (++Mc < 4) *ep++ = 0;\r
+\r
+       /*\r
+\r
+       int i, k;\r
+       for (k = 0; k <= 39; k++) ep[k] = 0;\r
+       for (i = 0; i <= 12; i++) {\r
+               ep[ Mc + (3*i) ] = xMp[i];\r
+       }\r
+       */\r
+}\r
+\r
+/* 4.2.18 */\r
+\r
+/*  This procedure adds the reconstructed long term residual signal\r
+ *  ep[0..39] to the estimated signal dpp[0..39] from the long term\r
+ *  analysis filter to compute the reconstructed short term residual\r
+ *  signal dp[-40..-1]; also the reconstructed short term residual\r
+ *  array dp[-120..-41] is updated.\r
+ */\r
+\r
+#if 0  /* Has been inlined in code.c */\r
+void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp),\r
+       word    * dpp,          /* [0...39]     IN      */\r
+       word    * ep,           /* [0...39]     IN      */\r
+       word    * dp)           /* [-120...-1]  IN/OUT  */\r
+{\r
+       int             k;\r
+\r
+       for (k = 0; k <= 79; k++) \r
+               dp[ -120 + k ] = dp[ -80 + k ];\r
+\r
+       for (k = 0; k <= 39; k++)\r
+               dp[ -40 + k ] = gsm_add( ep[k], dpp[k] );\r
+}\r
+#endif /* Has been inlined in code.c */\r
+\r
+void Gsm_RPE_Encoding P5((S,e,xmaxc,Mc,xMc),\r
+\r
+       struct gsm_state * S,\r
+\r
+       word    * e,            /* -5..-1][0..39][40..44        IN/OUT  */\r
+       word    * xmaxc,        /*                              OUT */\r
+       word    * Mc,           /*                              OUT */\r
+       word    * xMc)          /* [0..12]                      OUT */\r
+{\r
+       word    x[40];\r
+       word    xM[13], xMp[13];\r
+       word    mant, exp;\r
+\r
+       Weighting_filter(e, x);\r
+       RPE_grid_selection(x, xM, Mc);\r
+\r
+       APCM_quantization(      xM, xMc, &mant, &exp, xmaxc);\r
+       APCM_inverse_quantization(  xMc,  mant,  exp, xMp);\r
+\r
+       RPE_grid_positioning( *Mc, xMp, e );\r
+\r
+}\r
+\r
+void Gsm_RPE_Decoding P5((S, xmaxcr, Mcr, xMcr, erp),\r
+       struct gsm_state        * S,\r
+\r
+       word            xmaxcr,\r
+       word            Mcr,\r
+       word            * xMcr,  /* [0..12], 3 bits             IN      */\r
+       word            * erp    /* [0..39]                     OUT     */\r
+)\r
+{\r
+       word    exp, mant;\r
+       word    xMp[ 13 ];\r
+\r
+       APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant );\r
+       APCM_inverse_quantization( xMcr, mant, exp, xMp );\r
+       RPE_grid_positioning( Mcr, xMp, erp );\r
+\r
+}\r
diff --git a/libs/codec/gsm/src/short_term.c b/libs/codec/gsm/src/short_term.c
new file mode 100644 (file)
index 0000000..9398df1
--- /dev/null
@@ -0,0 +1,448 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+#include "private.h"\r
+\r
+#include "gsm.h"\r
+#include "proto.h"\r
+#ifdef K6OPT\r
+#include "k6opt.h"\r
+\r
+#define Short_term_analysis_filtering Short_term_analysis_filteringx\r
+\r
+#endif\r
+/*\r
+ *  SHORT TERM ANALYSIS FILTERING SECTION\r
+ */\r
+\r
+/* 4.2.8 */\r
+\r
+static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp),\r
+       word    * LARc,         /* coded log area ratio [0..7]  IN      */\r
+       word    * LARpp)        /* out: decoded ..                      */\r
+{\r
+       register word   temp1 /* , temp2 */;\r
+\r
+       /*  This procedure requires for efficient implementation\r
+        *  two tables.\r
+        *\r
+        *  INVA[1..8] = integer( (32768 * 8) / real_A[1..8])\r
+        *  MIC[1..8]  = minimum value of the LARc[1..8]\r
+        */\r
+\r
+       /*  Compute the LARpp[1..8]\r
+        */\r
+\r
+       /*      for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {\r
+        *\r
+        *              temp1  = GSM_ADD( *LARc, *MIC ) << 10;\r
+        *              temp2  = *B << 1;\r
+        *              temp1  = GSM_SUB( temp1, temp2 );\r
+        *\r
+        *              assert(*INVA != MIN_WORD);\r
+        *\r
+        *              temp1  = GSM_MULT_R( *INVA, temp1 );\r
+        *              *LARpp = GSM_ADD( temp1, temp1 );\r
+        *      }\r
+        */\r
+\r
+#undef STEP\r
+#define        STEP( B, MIC, INVA )    \\r
+               temp1    = GSM_ADD( *LARc++, MIC ) << 10;       \\r
+               temp1    = GSM_SUB( temp1, B << 1 );            \\r
+               temp1    = GSM_MULT_R( INVA, temp1 );           \\r
+               *LARpp++ = GSM_ADD( temp1, temp1 );\r
+\r
+       STEP(      0,  -32,  13107 );\r
+       STEP(      0,  -32,  13107 );\r
+       STEP(   2048,  -16,  13107 );\r
+       STEP(  -2560,  -16,  13107 );\r
+\r
+       STEP(     94,   -8,  19223 );\r
+       STEP(  -1792,   -8,  17476 );\r
+       STEP(   -341,   -4,  31454 );\r
+       STEP(  -1144,   -4,  29708 );\r
+\r
+       /* NOTE: the addition of *MIC is used to restore\r
+        *       the sign of *LARc.\r
+        */\r
+}\r
+\r
+/* 4.2.9 */\r
+/* Computation of the quantized reflection coefficients \r
+ */\r
+\r
+/* 4.2.9.1  Interpolation of the LARpp[1..8] to get the LARp[1..8]\r
+ */\r
+\r
+/*\r
+ *  Within each frame of 160 analyzed speech samples the short term\r
+ *  analysis and synthesis filters operate with four different sets of\r
+ *  coefficients, derived from the previous set of decoded LARs(LARpp(j-1))\r
+ *  and the actual set of decoded LARs (LARpp(j))\r
+ *\r
+ * (Initial value: LARpp(j-1)[1..8] = 0.)\r
+ */\r
+\r
+static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp),\r
+       register word * LARpp_j_1,\r
+       register word * LARpp_j,\r
+       register word * LARp)\r
+{\r
+       register int    i;\r
+\r
+       for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {\r
+               *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));\r
+               *LARp = GSM_ADD( *LARp,  SASR( *LARpp_j_1, 1));\r
+       }\r
+}\r
+\r
+static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp),\r
+       register word * LARpp_j_1,\r
+       register word * LARpp_j,\r
+       register word * LARp)\r
+{\r
+       register int i;\r
+       for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {\r
+               *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));\r
+       }\r
+}\r
+\r
+static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp),\r
+       register word * LARpp_j_1,\r
+       register word * LARpp_j,\r
+       register word * LARp)\r
+{\r
+       register int i;\r
+\r
+       for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {\r
+               *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));\r
+               *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));\r
+       }\r
+}\r
+\r
+\r
+static void Coefficients_40_159 P2((LARpp_j, LARp),\r
+       register word * LARpp_j,\r
+       register word * LARp)\r
+{\r
+       register int i;\r
+\r
+       for (i = 1; i <= 8; i++, LARp++, LARpp_j++)\r
+               *LARp = *LARpp_j;\r
+}\r
+\r
+/* 4.2.9.2 */\r
+\r
+static void LARp_to_rp P1((LARp),\r
+       register word * LARp)   /* [0..7] IN/OUT  */\r
+/*\r
+ *  The input of this procedure is the interpolated LARp[0..7] array.\r
+ *  The reflection coefficients, rp[i], are used in the analysis\r
+ *  filter and in the synthesis filter.\r
+ */\r
+{\r
+       register int            i;\r
+       register word           temp;\r
+\r
+       for (i = 1; i <= 8; i++, LARp++) {\r
+\r
+               /* temp = GSM_ABS( *LARp );\r
+                *\r
+                * if (temp < 11059) temp <<= 1;\r
+                * else if (temp < 20070) temp += 11059;\r
+                * else temp = GSM_ADD( temp >> 2, 26112 );\r
+                *\r
+                * *LARp = *LARp < 0 ? -temp : temp;\r
+                */\r
+\r
+               if (*LARp < 0) {\r
+                       temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);\r
+                       *LARp = - ((temp < 11059) ? temp << 1\r
+                               : ((temp < 20070) ? temp + 11059\r
+                               :  GSM_ADD( temp >> 2, 26112 )));\r
+               } else {\r
+                       temp  = *LARp;\r
+                       *LARp =    (temp < 11059) ? temp << 1\r
+                               : ((temp < 20070) ? temp + 11059\r
+                               :  GSM_ADD( temp >> 2, 26112 ));\r
+               }\r
+       }\r
+}\r
+\r
+\r
+/* 4.2.10 */\r
+#ifndef Short_term_analysis_filtering\r
+\r
+/* SJB Remark:\r
+ * I tried 2 MMX versions of this function, neither is significantly\r
+ * faster than the C version which follows.  MMX might be useful if\r
+ * one were processing 2 input streams in parallel.\r
+ */\r
+static void Short_term_analysis_filtering P4((u0,rp0,k_n,s),\r
+       register word * u0,\r
+       register word   * rp0,  /* [0..7]       IN      */\r
+       register int    k_n,    /*   k_end - k_start    */\r
+       register word   * s     /* [0..n-1]     IN/OUT  */\r
+)\r
+/*\r
+ *  This procedure computes the short term residual signal d[..] to be fed\r
+ *  to the RPE-LTP loop from the s[..] signal and from the local rp[..]\r
+ *  array (quantized reflection coefficients).  As the call of this\r
+ *  procedure can be done in many ways (see the interpolation of the LAR\r
+ *  coefficient), it is assumed that the computation begins with index\r
+ *  k_start (for arrays d[..] and s[..]) and stops with index k_end\r
+ *  (k_start and k_end are defined in 4.2.9.1).  This procedure also\r
+ *  needs to keep the array u0[0..7] in memory for each call.\r
+ */\r
+{\r
+       register word           * u_top = u0 + 8;\r
+       register word           * s_top = s + k_n;\r
+\r
+       while (s < s_top) {\r
+               register word           *u, *rp ;\r
+               register longword               di, u_out;\r
+               di = u_out = *s;\r
+               for (rp=rp0, u=u0; u<u_top;) {\r
+                       register longword       ui, rpi;\r
+                       ui    = *u;\r
+                       *u++  = u_out;\r
+                       rpi   = *rp++;\r
+                       u_out = ui + (((rpi*di)+0x4000)>>15);\r
+                       di    = di + (((rpi*ui)+0x4000)>>15);\r
+                       /* make the common case fastest: */\r
+                       if ((u_out == (word)u_out) && (di == (word)di)) continue;\r
+                       /* otherwise do slower fixup (saturation) */\r
+                       if (u_out>MAX_WORD) u_out=MAX_WORD;\r
+                       else if (u_out<MIN_WORD) u_out=MIN_WORD;\r
+                       if (di>MAX_WORD) di=MAX_WORD;\r
+                       else if (di<MIN_WORD) di=MIN_WORD;\r
+               }\r
+               *s++ = di;\r
+       }\r
+}\r
+#endif\r
+\r
+#if defined(USE_FLOAT_MUL) && defined(FAST)\r
+\r
+static void Fast_Short_term_analysis_filtering P4((u,rp,k_n,s),\r
+       register word * u;\r
+       register word   * rp,   /* [0..7]       IN      */\r
+       register int    k_n,    /*   k_end - k_start    */\r
+       register word   * s     /* [0..n-1]     IN/OUT  */\r
+)\r
+{\r
+       register int            i;\r
+\r
+       float     uf[8],\r
+                rpf[8];\r
+\r
+       register float scalef = 3.0517578125e-5;\r
+       register float          sav, di, temp;\r
+\r
+       for (i = 0; i < 8; ++i) {\r
+               uf[i]  = u[i];\r
+               rpf[i] = rp[i] * scalef;\r
+       }\r
+       for (; k_n--; s++) {\r
+               sav = di = *s;\r
+               for (i = 0; i < 8; ++i) {\r
+                       register float rpfi = rpf[i];\r
+                       register float ufi  = uf[i];\r
+\r
+                       uf[i] = sav;\r
+                       temp  = rpfi * di + ufi;\r
+                       di   += rpfi * ufi;\r
+                       sav   = temp;\r
+               }\r
+               *s = di;\r
+       }\r
+       for (i = 0; i < 8; ++i) u[i] = uf[i];\r
+}\r
+#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */\r
+\r
+/*\r
+ * SJB Remark: modified Short_term_synthesis_filtering() below\r
+ *  for significant (abt 35%) speedup of decompression.\r
+ *    (gcc-2.95, k6 cpu)\r
+ *  Please don't change this without benchmarking decompression\r
+ *  to see that you haven't harmed speed.\r
+ *  This function burns most of CPU time for untoasting.\r
+ *  Unfortunately, didn't see any good way to benefit from mmx.\r
+ */\r
+static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),\r
+       struct gsm_state * S,\r
+       register word   * rrp,  /* [0..7]       IN      */\r
+       register int    k,      /* k_end - k_start      */\r
+       register word   * wt,   /* [0..k-1]     IN      */\r
+       register word   * sr    /* [0..k-1]     OUT     */\r
+)\r
+{\r
+       register word           * v = S->v;\r
+       register int            i;\r
+       register longword               sri;\r
+\r
+       while (k--) {\r
+               sri = *wt++;\r
+               for (i = 8; i--;) {\r
+                       register longword               tmp1, tmp2;\r
+\r
+                       /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );\r
+                        */\r
+                       tmp1 = rrp[i];\r
+                       tmp2 = v[i];\r
+\r
+                       tmp2 = (( tmp1 * tmp2 + 16384) >> 15) ;\r
+                       /* saturation done below */\r
+                       sri  -= tmp2;\r
+                       if (sri != (word)sri) {\r
+                               sri = (sri<0)? MIN_WORD:MAX_WORD;\r
+                       }\r
+                       /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );\r
+                        */\r
+\r
+                       tmp1 = (( tmp1 * sri + 16384) >> 15) ;\r
+                       /* saturation done below */\r
+                       tmp1 += v[i];\r
+                       if (tmp1 != (word)tmp1) {\r
+                               tmp1 = (tmp1<0)? MIN_WORD:MAX_WORD;\r
+                       }\r
+                       v[i+1] = tmp1;\r
+               }\r
+               *sr++ = v[0] = sri;\r
+       }\r
+}\r
+\r
+\r
+#if defined(FAST) && defined(USE_FLOAT_MUL)\r
+\r
+static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),\r
+       struct gsm_state * S,\r
+       register word   * rrp,  /* [0..7]       IN      */\r
+       register int    k,      /* k_end - k_start      */\r
+       register word   * wt,   /* [0..k-1]     IN      */\r
+       register word   * sr    /* [0..k-1]     OUT     */\r
+)\r
+{\r
+       register word           * v = S->v;\r
+       register int            i;\r
+\r
+       float va[9], rrpa[8];\r
+       register float scalef = 3.0517578125e-5, temp;\r
+\r
+       for (i = 0; i < 8; ++i) {\r
+               va[i]   = v[i];\r
+               rrpa[i] = (float)rrp[i] * scalef;\r
+       }\r
+       while (k--) {\r
+               register float sri = *wt++;\r
+               for (i = 8; i--;) {\r
+                       sri -= rrpa[i] * va[i];\r
+                       if     (sri < -32768.) sri = -32768.;\r
+                       else if (sri > 32767.) sri =  32767.;\r
+\r
+                       temp = va[i] + rrpa[i] * sri;\r
+                       if     (temp < -32768.) temp = -32768.;\r
+                       else if (temp > 32767.) temp =  32767.;\r
+                       va[i+1] = temp;\r
+               }\r
+               *sr++ = va[0] = sri;\r
+       }\r
+       for (i = 0; i < 9; ++i) v[i] = va[i];\r
+}\r
+\r
+#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */\r
+\r
+void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s),\r
+\r
+       struct gsm_state * S,\r
+\r
+       word    * LARc,         /* coded log area ratio [0..7]  IN      */\r
+       word    * s             /* signal [0..159]              IN/OUT  */\r
+)\r
+{\r
+       word            * LARpp_j       = S->LARpp[ S->j      ];\r
+       word            * LARpp_j_1     = S->LARpp[ S->j ^= 1 ];\r
+\r
+       word            LARp[8];\r
+int i;\r
+#undef FILTER\r
+#if    defined(FAST) && defined(USE_FLOAT_MUL)\r
+#      define  FILTER  (* (S->fast                     \\r
+                          ? Fast_Short_term_analysis_filtering \\r
+                          : Short_term_analysis_filtering      ))\r
+\r
+#else\r
+#      define  FILTER  Short_term_analysis_filtering\r
+#endif\r
+\r
+       Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );\r
+\r
+       Coefficients_0_12(  LARpp_j_1, LARpp_j, LARp );\r
+       LARp_to_rp( LARp );\r
+       FILTER( S->u, LARp, 13, s);\r
+\r
+       Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);\r
+       LARp_to_rp( LARp );\r
+       FILTER( S->u, LARp, 14, s + 13);\r
+\r
+       Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);\r
+       LARp_to_rp( LARp );\r
+       FILTER( S->u, LARp, 13, s + 27);\r
+\r
+       Coefficients_40_159( LARpp_j, LARp);\r
+       LARp_to_rp( LARp );\r
+       FILTER( S->u, LARp, 120, s + 40);\r
+       \r
+}\r
+\r
+void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s),\r
+       struct gsm_state * S,\r
+\r
+       word    * LARcr,        /* received log area ratios [0..7] IN  */\r
+       word    * wt,           /* received d [0..159]             IN  */\r
+\r
+       word    * s             /* signal   s [0..159]            OUT  */\r
+)\r
+{\r
+       word            * LARpp_j       = S->LARpp[ S->j     ];\r
+       word            * LARpp_j_1     = S->LARpp[ S->j ^=1 ];\r
+\r
+       word            LARp[8];\r
+\r
+#undef FILTER\r
+#if    defined(FAST) && defined(USE_FLOAT_MUL)\r
+\r
+#      define  FILTER  (* (S->fast                     \\r
+                          ? Fast_Short_term_synthesis_filtering        \\r
+                          : Short_term_synthesis_filtering     ))\r
+#else\r
+#      define  FILTER  Short_term_synthesis_filtering\r
+#endif\r
+\r
+       Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );\r
+\r
+       Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );\r
+       LARp_to_rp( LARp );\r
+       FILTER( S, LARp, 13, wt, s );\r
+\r
+       Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);\r
+       LARp_to_rp( LARp );\r
+       FILTER( S, LARp, 14, wt + 13, s + 13 );\r
+\r
+       Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);\r
+       LARp_to_rp( LARp );\r
+       FILTER( S, LARp, 13, wt + 27, s + 27 );\r
+\r
+       Coefficients_40_159( LARpp_j, LARp );\r
+       LARp_to_rp( LARp );\r
+       FILTER(S, LARp, 120, wt + 40, s + 40);\r
+}\r
diff --git a/libs/codec/gsm/src/table.c b/libs/codec/gsm/src/table.c
new file mode 100644 (file)
index 0000000..bdca9fa
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische\r
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for\r
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.\r
+ */\r
+\r
+/* $Header$ */\r
+\r
+/*  Most of these tables are inlined at their point of use.\r
+ */\r
+\r
+/*  4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP\r
+ *      CODER AND DECODER\r
+ *\r
+ *     (Most of them inlined, so watch out.)\r
+ */\r
+\r
+#define        GSM_TABLE_C\r
+#include "private.h"\r
+#include       "gsm.h"\r
+\r
+/*  Table 4.1  Quantization of the Log.-Area Ratios\r
+ */\r
+/* i                1      2      3        4      5      6        7       8 */\r
+word gsm_A[8]   = {20480, 20480, 20480,  20480,  13964,  15360,   8534,  9036};\r
+word gsm_B[8]   = {    0,     0,  2048,  -2560,     94,  -1792,   -341, -1144};\r
+word gsm_MIC[8] = { -32,   -32,   -16,    -16,     -8,     -8,     -4,    -4 };\r
+word gsm_MAC[8] = {  31,    31,    15,     15,      7,      7,      3,     3 };\r
+\r
+\r
+/*  Table 4.2  Tabulation  of 1/A[1..8]\r
+ */\r
+word gsm_INVA[8]={ 13107, 13107,  13107, 13107,  19223, 17476,  31454, 29708 };\r
+\r
+\r
+/*   Table 4.3a  Decision level of the LTP gain quantizer\r
+ */\r
+/*  bc               0         1         2          3                  */\r
+word gsm_DLB[4] = {  6554,    16384,   26214,     32767        };\r
+\r
+\r
+/*   Table 4.3b   Quantization levels of the LTP gain quantizer\r
+ */\r
+/* bc                0          1        2          3                  */\r
+word gsm_QLB[4] = {  3277,    11469,   21299,     32767        };\r
+\r
+\r
+/*   Table 4.4  Coefficients of the weighting filter\r
+ */\r
+/* i               0      1   2    3   4      5      6     7   8   9    10  */\r
+word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 };\r
+\r
+\r
+/*   Table 4.5          Normalized inverse mantissa used to compute xM/xmax \r
+ */\r
+/* i                   0        1    2      3      4      5     6      7   */\r
+word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 };\r
+\r
+\r
+/*   Table 4.6  Normalized direct mantissa used to compute xM/xmax\r
+ */\r
+/* i                  0      1       2      3      4      5      6      7   */\r
+word gsm_FAC[8]        = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 };\r
diff --git a/libs/codec/ilbc/FrameClassify.c b/libs/codec/ilbc/FrameClassify.c
new file mode 100644 (file)
index 0000000..9a6f029
--- /dev/null
@@ -0,0 +1,110 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    FrameClassify.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "iLBC_define.h"\r
+#include "FrameClassify.h"\r
+\r
+/*---------------------------------------------------------------*\r
+ *  Classification of subframes to localize start state\r
+ *--------------------------------------------------------------*/\r
+\r
+int FrameClassify(      /* index to the max-energy sub-frame */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                        /* (i/o) the encoder state structure */\r
+    float *residual     /* (i) lpc residual signal */\r
+) {\r
+    float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;\r
+    int n, l, max_ssqEn_n;\r
+    const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,\r
+        (float)1.0,(float)0.9,(float)0.8};\r
+    const float sampEn_win[5]={(float)1.0/(float)6.0, \r
+        (float)2.0/(float)6.0, (float)3.0/(float)6.0,\r
+        (float)4.0/(float)6.0, (float)5.0/(float)6.0};\r
+    \r
+    /* init the front and back energies to zero */\r
+\r
+    memset(fssqEn, 0, NSUB_MAX*sizeof(float));\r
+    memset(bssqEn, 0, NSUB_MAX*sizeof(float));\r
+\r
+    /* Calculate front of first seqence */\r
+\r
+    n=0;\r
+    pp=residual;\r
+\r
+\r
+    for (l=0; l<5; l++) {\r
+        fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+        pp++;\r
+    }\r
+    for (l=5; l<SUBL; l++) {\r
+        fssqEn[n] += (*pp) * (*pp);\r
+        pp++;\r
+    }\r
+\r
+    /* Calculate front and back of all middle sequences */\r
+\r
+    for (n=1; n<iLBCenc_inst->nsub-1; n++) {\r
+        pp=residual+n*SUBL;\r
+        for (l=0; l<5; l++) {\r
+            fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+            bssqEn[n] += (*pp) * (*pp);\r
+            pp++;\r
+        }\r
+        for (l=5; l<SUBL-5; l++) {\r
+            fssqEn[n] += (*pp) * (*pp);\r
+            bssqEn[n] += (*pp) * (*pp);\r
+            pp++;\r
+        }\r
+        for (l=SUBL-5; l<SUBL; l++) {\r
+            fssqEn[n] += (*pp) * (*pp);\r
+            bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+            pp++;\r
+        }\r
+    }\r
+\r
+    /* Calculate back of last seqence */\r
+\r
+    n=iLBCenc_inst->nsub-1;\r
+    pp=residual+n*SUBL;\r
+    for (l=0; l<SUBL-5; l++) {\r
+        bssqEn[n] += (*pp) * (*pp);\r
+        pp++;\r
+    }\r
+    for (l=SUBL-5; l<SUBL; l++) {\r
+        bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+        pp++;\r
+    }\r
+\r
+    /* find the index to the weighted 80 sample with \r
+       most energy */\r
+\r
+    if (iLBCenc_inst->mode==20) l=1;\r
+    else                        l=0;\r
+\r
+    max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];\r
+    max_ssqEn_n=1;\r
+    for (n=2; n<iLBCenc_inst->nsub; n++) {\r
+\r
+        l++;\r
+\r
+\r
+        if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {\r
+            max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *\r
+                            ssqEn_win[l];\r
+            max_ssqEn_n=n;\r
+        }\r
+    }\r
+\r
+    return max_ssqEn_n;\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/FrameClassify.h b/libs/codec/ilbc/FrameClassify.h
new file mode 100644 (file)
index 0000000..6b58370
--- /dev/null
@@ -0,0 +1,26 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    FrameClassify.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+\r
+\r
+#ifndef __iLBC_FRAMECLASSIFY_H\r
+#define __iLBC_FRAMECLASSIFY_H\r
+\r
+int FrameClassify(      /* index to the max-energy sub-frame */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                        /* (i/o) the encoder state structure */\r
+    float *residual     /* (i) lpc residual signal */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/LPCdecode.c b/libs/codec/ilbc/LPCdecode.c
new file mode 100644 (file)
index 0000000..741c731
--- /dev/null
@@ -0,0 +1,152 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    LPC_decode.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <string.h>\r
+\r
+#include "helpfun.h"\r
+#include "lsf.h"\r
+#include "iLBC_define.h"\r
+#include "LPCdecode.h"\r
+#include "constants.h"\r
+\r
+/*---------------------------------------------------------------*\r
+ *  interpolation of lsf coefficients for the decoder\r
+ *--------------------------------------------------------------*/\r
+\r
+void LSFinterpolate2a_dec( \r
+    float *a,           /* (o) lpc coefficients for a sub-frame */\r
+    float *lsf1,    /* (i) first lsf coefficient vector */\r
+\r
+\r
+    float *lsf2,    /* (i) second lsf coefficient vector */\r
+    float coef,         /* (i) interpolation weight */\r
+    int length          /* (i) length of lsf vectors */\r
+){\r
+    float  lsftmp[LPC_FILTERORDER];\r
+    \r
+    interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+    lsf2a(a, lsftmp);\r
+}\r
+\r
+/*---------------------------------------------------------------*\r
+ *  obtain dequantized lsf coefficients from quantization index \r
+ *--------------------------------------------------------------*/\r
+\r
+void SimplelsfDEQ(\r
+    float *lsfdeq,    /* (o) dequantized lsf coefficients */\r
+    int *index,         /* (i) quantization index */\r
+    int lpc_n           /* (i) number of LPCs */\r
+){  \r
+    int i, j, pos, cb_pos;\r
+\r
+    /* decode first LSF */\r
+    \r
+    pos = 0;\r
+    cb_pos = 0;\r
+    for (i = 0; i < LSF_NSPLIT; i++) {\r
+        for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+            lsfdeq[pos + j] = lsfCbTbl[cb_pos + \r
+                (long)(index[i])*dim_lsfCbTbl[i] + j];\r
+        }       \r
+        pos += dim_lsfCbTbl[i];\r
+        cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+    }\r
+\r
+    if (lpc_n>1) {\r
+\r
+        /* decode last LSF */\r
+\r
+        pos = 0;\r
+        cb_pos = 0;\r
+        for (i = 0; i < LSF_NSPLIT; i++) {\r
+            for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+                lsfdeq[LPC_FILTERORDER + pos + j] = \r
+                    lsfCbTbl[cb_pos + \r
+                    (long)(index[LSF_NSPLIT + i])*\r
+                    dim_lsfCbTbl[i] + j];\r
+            }       \r
+            pos += dim_lsfCbTbl[i];\r
+            cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+\r
+\r
+ *  obtain synthesis and weighting filters form lsf coefficients \r
+ *---------------------------------------------------------------*/\r
+\r
+void DecoderInterpolateLSF( \r
+    float *syntdenum, /* (o) synthesis filter coefficients */\r
+    float *weightdenum, /* (o) weighting denumerator \r
+                               coefficients */\r
+    float *lsfdeq,       /* (i) dequantized lsf coefficients */\r
+    int length,         /* (i) length of lsf coefficient vector */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst \r
+                        /* (i) the decoder state structure */\r
+){\r
+    int    i, pos, lp_length;\r
+    float  lp[LPC_FILTERORDER + 1], *lsfdeq2;\r
+        \r
+    lsfdeq2 = lsfdeq + length;\r
+    lp_length = length + 1;\r
+    \r
+    if (iLBCdec_inst->mode==30) {\r
+        /* sub-frame 1: Interpolation between old and first */\r
+\r
+        LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, \r
+            lsf_weightTbl_30ms[0], length);\r
+        memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+        bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, \r
+            lp_length);\r
+\r
+        /* sub-frames 2 to 6: interpolation between first \r
+           and last LSF */\r
+    \r
+        pos = lp_length;\r
+        for (i = 1; i < 6; i++) {\r
+            LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, \r
+                lsf_weightTbl_30ms[i], length);\r
+            memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+            bwexpand(weightdenum + pos, lp, \r
+                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+            pos += lp_length;\r
+        }\r
+    }\r
+    else {\r
+        pos = 0;\r
+        for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+            LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, \r
+                lsfdeq, lsf_weightTbl_20ms[i], length);\r
+            memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+            bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, \r
+                lp_length);\r
+            pos += lp_length;\r
+        }\r
+    }\r
+    \r
+    /* update memory */\r
+\r
+\r
+\r
+    if (iLBCdec_inst->mode==30)\r
+        memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, \r
+                    length*sizeof(float));\r
+    else\r
+        memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, \r
+                    length*sizeof(float));\r
+\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/LPCdecode.h b/libs/codec/ilbc/LPCdecode.h
new file mode 100644 (file)
index 0000000..84116e0
--- /dev/null
@@ -0,0 +1,44 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    LPC_decode.h     \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_LPC_DECODE_H\r
+#define __iLBC_LPC_DECODE_H\r
+\r
+void LSFinterpolate2a_dec( \r
+\r
+\r
+    float *a,           /* (o) lpc coefficients for a sub-frame */\r
+    float *lsf1,    /* (i) first lsf coefficient vector */\r
+    float *lsf2,    /* (i) second lsf coefficient vector */\r
+    float coef,         /* (i) interpolation weight */\r
+    int length          /* (i) length of lsf vectors */\r
+);\r
+      \r
+void SimplelsfDEQ( \r
+    float *lsfdeq,      /* (o) dequantized lsf coefficients */\r
+    int *index,         /* (i) quantization index */\r
+    int lpc_n           /* (i) number of LPCs */\r
+);\r
+\r
+void DecoderInterpolateLSF( \r
+    float *syntdenum,   /* (o) synthesis filter coefficients */\r
+    float *weightdenum, /* (o) weighting denumerator \r
+                               coefficients */\r
+    float *lsfdeq,      /* (i) dequantized lsf coefficients */\r
+    int length,         /* (i) length of lsf coefficient vector */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst \r
+                        /* (i) the decoder state structure */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/LPCencode.c b/libs/codec/ilbc/LPCencode.c
new file mode 100644 (file)
index 0000000..d1286e2
--- /dev/null
@@ -0,0 +1,228 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    LPCencode.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <string.h>\r
+\r
+\r
+\r
+#include "iLBC_define.h"\r
+#include "LPCencode.h"\r
+#include "helpfun.h"\r
+#include "lsf.h"\r
+#include "constants.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  lpc analysis (subrutine to LPCencode)\r
+ *---------------------------------------------------------------*/\r
+\r
+static void SimpleAnalysis(\r
+    float *lsf,         /* (o) lsf coefficients */\r
+    float *data,    /* (i) new data vector */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst \r
+                        /* (i/o) the encoder state structure */\r
+){\r
+    int k, is;\r
+    float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];\r
+    float lp2[LPC_FILTERORDER + 1];\r
+    float r[LPC_FILTERORDER + 1];\r
+\r
+    is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+    memcpy(iLBCenc_inst->lpc_buffer+is,data,\r
+        iLBCenc_inst->blockl*sizeof(float));\r
+    \r
+    /* No lookahead, last window is asymmetric */\r
+    \r
+    for (k = 0; k < iLBCenc_inst->lpc_n; k++) {\r
+        \r
+        is = LPC_LOOKBACK;\r
+\r
+        if (k < (iLBCenc_inst->lpc_n - 1)) {\r
+            window(temp, lpc_winTbl, \r
+                iLBCenc_inst->lpc_buffer, BLOCKL_MAX);\r
+        } else {\r
+            window(temp, lpc_asymwinTbl, \r
+                iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);\r
+        }\r
+        \r
+        autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);\r
+        window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);\r
+        \r
+        levdurb(lp, temp, r, LPC_FILTERORDER);\r
+        bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);\r
+\r
+        a2lsf(lsf + k*LPC_FILTERORDER, lp2);\r
+    }\r
+    is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+    memmove(iLBCenc_inst->lpc_buffer, \r
+        iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, \r
+        is*sizeof(float));\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+\r
+\r
+ *  lsf interpolator and conversion from lsf to a coefficients\r
+ *  (subrutine to SimpleInterpolateLSF)\r
+ *---------------------------------------------------------------*/\r
+\r
+static void LSFinterpolate2a_enc(\r
+    float *a,       /* (o) lpc coefficients */ \r
+    float *lsf1,/* (i) first set of lsf coefficients */\r
+    float *lsf2,/* (i) second set of lsf coefficients */\r
+    float coef,     /* (i) weighting coefficient to use between \r
+                           lsf1 and lsf2 */\r
+    long length      /* (i) length of coefficient vectors */\r
+){  \r
+    float  lsftmp[LPC_FILTERORDER];\r
+    \r
+    interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+    lsf2a(a, lsftmp);\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  lsf interpolator (subrutine to LPCencode)\r
+ *---------------------------------------------------------------*/\r
+\r
+static void SimpleInterpolateLSF(\r
+    float *syntdenum,   /* (o) the synthesis filter denominator \r
+                               resulting from the quantized \r
+                               interpolated lsf */\r
+    float *weightdenum, /* (o) the weighting filter denominator \r
+                               resulting from the unquantized \r
+                               interpolated lsf */\r
+    float *lsf,         /* (i) the unquantized lsf coefficients */\r
+    float *lsfdeq,      /* (i) the dequantized lsf coefficients */\r
+    float *lsfold,      /* (i) the unquantized lsf coefficients of \r
+                               the previous signal frame */\r
+    float *lsfdeqold, /* (i) the dequantized lsf coefficients of \r
+                               the previous signal frame */\r
+    int length,         /* (i) should equate LPC_FILTERORDER */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst \r
+                        /* (i/o) the encoder state structure */\r
+){\r
+    int    i, pos, lp_length;\r
+    float  lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;\r
+    \r
+    lsf2 = lsf + length;\r
+    lsfdeq2 = lsfdeq + length;\r
+    lp_length = length + 1; \r
\r
+    if (iLBCenc_inst->mode==30) {\r
+        /* sub-frame 1: Interpolation between old and first \r
+           set of lsf coefficients */\r
+\r
+        LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+            lsf_weightTbl_30ms[0], length);\r
+        memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+        LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+\r
+\r
+            lsf_weightTbl_30ms[0], length);\r
+        bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+\r
+        /* sub-frame 2 to 6: Interpolation between first \r
+           and second set of lsf coefficients */\r
+    \r
+        pos = lp_length;\r
+        for (i = 1; i < iLBCenc_inst->nsub; i++) {\r
+            LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, \r
+                lsf_weightTbl_30ms[i], length);\r
+            memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+        \r
+            LSFinterpolate2a_enc(lp, lsf, lsf2, \r
+                lsf_weightTbl_30ms[i], length);\r
+            bwexpand(weightdenum + pos, lp, \r
+                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+            pos += lp_length;\r
+        }\r
+    }\r
+    else {\r
+        pos = 0;\r
+        for (i = 0; i < iLBCenc_inst->nsub; i++) {\r
+            LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+                lsf_weightTbl_20ms[i], length);\r
+            memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+            LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+                lsf_weightTbl_20ms[i], length);\r
+            bwexpand(weightdenum+pos, lp, \r
+                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+            pos += lp_length;\r
+        }\r
+    }\r
+    \r
+    /* update memory */\r
+\r
+    if (iLBCenc_inst->mode==30) {\r
+        memcpy(lsfold, lsf2, length*sizeof(float));\r
+        memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));\r
+    }\r
+    else {\r
+        memcpy(lsfold, lsf, length*sizeof(float));\r
+        memcpy(lsfdeqold, lsfdeq, length*sizeof(float));\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  lsf quantizer (subrutine to LPCencode)\r
+ *---------------------------------------------------------------*/\r
+\r
+static void SimplelsfQ(\r
+    float *lsfdeq,    /* (o) dequantized lsf coefficients\r
+                           (dimension FILTERORDER) */\r
+    int *index,     /* (o) quantization index */\r
+    float *lsf,      /* (i) the lsf coefficient vector to be \r
+\r
+\r
+                           quantized (dimension FILTERORDER ) */\r
+    int lpc_n     /* (i) number of lsf sets to quantize */\r
+){    \r
+    /* Quantize first LSF with memoryless split VQ */\r
+    SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, \r
+        dim_lsfCbTbl, size_lsfCbTbl);\r
+\r
+    if (lpc_n==2) {\r
+        /* Quantize second LSF with memoryless split VQ */\r
+        SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, \r
+            lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, \r
+            dim_lsfCbTbl, size_lsfCbTbl);\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  lpc encoder\r
+ *---------------------------------------------------------------*/\r
+\r
+void LPCencode( \r
+    float *syntdenum, /* (i/o) synthesis filter coefficients \r
+                               before/after encoding */\r
+    float *weightdenum, /* (i/o) weighting denumerator \r
+                               coefficients before/after \r
+                               encoding */\r
+    int *lsf_index,     /* (o) lsf quantization index */\r
+    float *data,    /* (i) lsf coefficients to quantize */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst \r
+                        /* (i/o) the encoder state structure */\r
+){\r
+    float lsf[LPC_FILTERORDER * LPC_N_MAX];\r
+    float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];\r
+    int change=0;\r
+    \r
+    SimpleAnalysis(lsf, data, iLBCenc_inst);\r
+    SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);\r
+    change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);\r
+    SimpleInterpolateLSF(syntdenum, weightdenum, \r
+        lsf, lsfdeq, iLBCenc_inst->lsfold, \r
+        iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);\r
+}\r
+\r
+\r
+\r
diff --git a/libs/codec/ilbc/LPCencode.h b/libs/codec/ilbc/LPCencode.h
new file mode 100644 (file)
index 0000000..464282e
--- /dev/null
@@ -0,0 +1,29 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    LPCencode.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_LPCENCOD_H\r
+#define __iLBC_LPCENCOD_H\r
+\r
+void LPCencode( \r
+    float *syntdenum,   /* (i/o) synthesis filter coefficients \r
+                               before/after encoding */\r
+    float *weightdenum, /* (i/o) weighting denumerator coefficients\r
+                               before/after encoding */\r
+    int *lsf_index,     /* (o) lsf quantization index */\r
+    float *data,    /* (i) lsf coefficients to quantize */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst \r
+                        /* (i/o) the encoder state structure */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/Makefile b/libs/codec/ilbc/Makefile
new file mode 100644 (file)
index 0000000..5ef581e
--- /dev/null
@@ -0,0 +1,25 @@
+ARCH=$(PROC)\r
+CFLAGS+=-Wall -O3 -funroll-loops\r
+ifneq (${OSARCH},CYGWIN)\r
+CFLAGS += -fPIC\r
+endif\r
+LIB=libilbc.a\r
+\r
+OBJS= anaFilter.o iCBSearch.o packing.o \\r
+        constants.o gainquant.o iLBC_decode.o StateConstructW.o \\r
+        createCB.o getCBvec.o iLBC_encode.o StateSearchW.o doCPLC.o \\r
+        helpfun.o syntFilter.o enhancer.o hpInput.o LPCdecode.o \\r
+        filter.o hpOutput.o LPCencode.o FrameClassify.o  iCBConstruct.o lsf.o\r
+\r
+all: $(LIB)\r
+\r
+\r
+$(LIB): $(OBJS)\r
+       ar cr $(LIB) $(OBJS)\r
+       ranlib $(LIB)\r
+\r
+clean:\r
+       rm -f $(LIB) *.o\r
+\r
+install:\r
+\r
diff --git a/libs/codec/ilbc/StateConstructW.c b/libs/codec/ilbc/StateConstructW.c
new file mode 100644 (file)
index 0000000..31d997d
--- /dev/null
@@ -0,0 +1,76 @@
+\r
+/******************************************************************\r
+\r
+\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    StateConstructW.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h> \r
+#include <string.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "StateConstructW.h"\r
+#include "constants.h"\r
+#include "filter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  decoding of the start state\r
+ *---------------------------------------------------------------*/\r
+\r
+void StateConstructW( \r
+    int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                               max amplitude */\r
+    int *idxVec,    /* (i) vector of quantization indexes */\r
+    float *syntDenum,   /* (i) synthesis filter denumerator */\r
+    float *out,         /* (o) the decoded state vector */\r
+    int len             /* (i) length of a state vector */\r
+){\r
+    float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, \r
+        numerator[LPC_FILTERORDER+1];\r
+    float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;\r
+    int k,tmpi;\r
+    \r
+    /* decoding of the maximum value */\r
+\r
+    maxVal = state_frgqTbl[idxForMax];\r
+    maxVal = (float)pow(10,maxVal)/(float)4.5;\r
+        \r
+    /* initialization of buffers and coefficients */\r
+    \r
+    memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+    memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+    for (k=0; k<LPC_FILTERORDER; k++) {\r
+        numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+    }\r
+    numerator[LPC_FILTERORDER]=syntDenum[0];\r
+    tmp = &tmpbuf[LPC_FILTERORDER];\r
+    fout = &foutbuf[LPC_FILTERORDER];\r
+\r
+    /* decoding of the sample values */\r
+    \r
+    for (k=0; k<len; k++) {\r
+        tmpi = len-1-k;\r
+        /* maxVal = 1/scal */\r
+\r
+\r
+        tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];\r
+    }\r
+\r
+    /* circular convolution with all-pass filter */\r
+\r
+    memset(tmp+len, 0, len*sizeof(float));\r
+    ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+        LPC_FILTERORDER, fout);\r
+    for (k=0;k<len;k++) {\r
+        out[k] = fout[len-1-k]+fout[2*len-1-k];\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/StateConstructW.h b/libs/codec/ilbc/StateConstructW.h
new file mode 100644 (file)
index 0000000..b8727de
--- /dev/null
@@ -0,0 +1,27 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    StateConstructW.h  \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_STATECONSTRUCTW_H\r
+#define __iLBC_STATECONSTRUCTW_H\r
+\r
+void StateConstructW( \r
+    int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                               max amplitude */\r
+    int *idxVec,    /* (i) vector of quantization indexes */\r
+    float *syntDenum,   /* (i) synthesis filter denumerator */\r
+    float *out,         /* (o) the decoded state vector */\r
+    int len             /* (i) length of a state vector */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/StateSearchW.c b/libs/codec/ilbc/StateSearchW.c
new file mode 100644 (file)
index 0000000..fd63916
--- /dev/null
@@ -0,0 +1,194 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    StateSearchW.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h> \r
+#include <string.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "StateSearchW.h"\r
+#include "constants.h"\r
+#include "filter.h"\r
+#include "helpfun.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  predictive noise shaping encoding of scaled start state \r
+ *  (subrutine for StateSearchW) \r
+ *---------------------------------------------------------------*/\r
+\r
+void AbsQuantW(\r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                        /* (i) Encoder instance */\r
+    float *in,          /* (i) vector to encode */\r
+    float *syntDenum,   /* (i) denominator of synthesis filter */\r
+    float *weightDenum, /* (i) denominator of weighting filter */\r
+    int *out,           /* (o) vector of quantizer indexes */\r
+    int len,        /* (i) length of vector to encode and \r
+                               vector of quantizer indexes */\r
+    int state_first     /* (i) position of start state in the \r
+                               80 vec */\r
+){\r
+    float *syntOut;\r
+    float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];\r
+    float toQ, xq;\r
+    int n;\r
+    int index;\r
+\r
+    /* initialization of buffer for filtering */\r
+            \r
+    memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+\r
+\r
+    /* initialization of pointer for filtering */\r
+\r
+    syntOut = &syntOutBuf[LPC_FILTERORDER];\r
+    \r
+    /* synthesis and weighting filters on input */\r
+    \r
+    if (state_first) {\r
+        AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);\r
+    } else {\r
+        AllPoleFilter (in, weightDenum, \r
+            iLBCenc_inst->state_short_len-SUBL, \r
+            LPC_FILTERORDER);\r
+    }\r
+\r
+    /* encoding loop */\r
+\r
+    for (n=0; n<len; n++) {\r
+        \r
+        /* time update of filter coefficients */  \r
+        \r
+        if ((state_first)&&(n==SUBL)){\r
+            syntDenum += (LPC_FILTERORDER+1);\r
+            weightDenum += (LPC_FILTERORDER+1);\r
+\r
+            /* synthesis and weighting filters on input */\r
+            AllPoleFilter (&in[n], weightDenum, len-n, \r
+                LPC_FILTERORDER);\r
+\r
+        } else if ((state_first==0)&&\r
+            (n==(iLBCenc_inst->state_short_len-SUBL))) {\r
+            syntDenum += (LPC_FILTERORDER+1);\r
+            weightDenum += (LPC_FILTERORDER+1);\r
+\r
+            /* synthesis and weighting filters on input */\r
+            AllPoleFilter (&in[n], weightDenum, len-n, \r
+                LPC_FILTERORDER);\r
+            \r
+        }\r
+        \r
+        /* prediction of synthesized and weighted input */\r
+\r
+        syntOut[n] = 0.0;\r
+        AllPoleFilter (&syntOut[n], weightDenum, 1, \r
+            LPC_FILTERORDER);\r
+        \r
+        /* quantization */      \r
+\r
+        toQ = in[n]-syntOut[n];\r
+        sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);\r
+        out[n]=index;\r
+        syntOut[n] = state_sq3Tbl[out[n]];\r
+\r
+        /* update of the prediction filter */\r
+\r
+\r
+\r
+        AllPoleFilter(&syntOut[n], weightDenum, 1, \r
+            LPC_FILTERORDER);\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  encoding of start state                          \r
+ *---------------------------------------------------------------*/\r
+\r
+void StateSearchW( \r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                        /* (i) Encoder instance */\r
+    float *residual,/* (i) target residual vector */\r
+    float *syntDenum,   /* (i) lpc synthesis filter */\r
+    float *weightDenum, /* (i) weighting filter denuminator */\r
+    int *idxForMax,     /* (o) quantizer index for maximum \r
+                               amplitude */\r
+    int *idxVec,    /* (o) vector of quantization indexes */\r
+    int len,        /* (i) length of all vectors */\r
+    int state_first     /* (i) position of start state in the \r
+                               80 vec */\r
+){  \r
+    float dtmp, maxVal;\r
+    float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];\r
+    float *tmp, numerator[1+LPC_FILTERORDER]; \r
+    float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;\r
+    int k;\r
+    float qmax, scal;\r
+    \r
+    /* initialization of buffers and filter coefficients */\r
+\r
+    memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+    memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+    for (k=0; k<LPC_FILTERORDER; k++) {\r
+        numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+    }\r
+    numerator[LPC_FILTERORDER]=syntDenum[0];\r
+    tmp = &tmpbuf[LPC_FILTERORDER];\r
+    fout = &foutbuf[LPC_FILTERORDER];\r
+\r
+    /* circular convolution with the all-pass filter */\r
+    \r
+    memcpy(tmp, residual, len*sizeof(float));\r
+    memset(tmp+len, 0, len*sizeof(float));\r
+    ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+        LPC_FILTERORDER, fout);\r
+    for (k=0; k<len; k++) {\r
+        fout[k] += fout[k+len];\r
+    }   \r
+        \r
+    /* identification of the maximum amplitude value */\r
+    \r
+    maxVal = fout[0];\r
+\r
+\r
+    for (k=1; k<len; k++) {\r
+        \r
+        if (fout[k]*fout[k] > maxVal*maxVal){\r
+            maxVal = fout[k];\r
+        }\r
+    }\r
+    maxVal=(float)fabs(maxVal);\r
+        \r
+    /* encoding of the maximum amplitude value */\r
+    \r
+    if (maxVal < 10.0) {\r
+        maxVal = 10.0;\r
+    }\r
+    maxVal = (float)log10(maxVal);\r
+    sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);\r
+\r
+    /* decoding of the maximum amplitude representation value,\r
+       and corresponding scaling of start state */\r
+\r
+    maxVal=state_frgqTbl[*idxForMax];\r
+    qmax = (float)pow(10,maxVal);\r
+    scal = (float)(4.5)/qmax;\r
+    for (k=0; k<len; k++){\r
+        fout[k] *= scal;\r
+    }\r
+\r
+    /* predictive noise shaping encoding of scaled start state */\r
+\r
+    AbsQuantW(iLBCenc_inst, fout,syntDenum, \r
+        weightDenum,idxVec, len, state_first);\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/StateSearchW.h b/libs/codec/ilbc/StateSearchW.h
new file mode 100644 (file)
index 0000000..3d53077
--- /dev/null
@@ -0,0 +1,48 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    StateSearchW.h     \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_STATESEARCHW_H\r
+#define __iLBC_STATESEARCHW_H\r
+\r
+void AbsQuantW(\r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                        /* (i) Encoder instance */\r
+    float *in,          /* (i) vector to encode */\r
+    float *syntDenum,   /* (i) denominator of synthesis filter */\r
+    float *weightDenum, /* (i) denominator of weighting filter */\r
+    int *out,           /* (o) vector of quantizer indexes */\r
+    int len,        /* (i) length of vector to encode and \r
+                               vector of quantizer indexes */\r
+    int state_first     /* (i) position of start state in the \r
+                               80 vec */\r
+);\r
+\r
+void StateSearchW( \r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                        /* (i) Encoder instance */\r
+    float *residual,/* (i) target residual vector */\r
+    float *syntDenum,   /* (i) lpc synthesis filter */\r
+    float *weightDenum, /* (i) weighting filter denuminator */\r
+    int *idxForMax,     /* (o) quantizer index for maximum \r
+                               amplitude */\r
+    int *idxVec,    /* (o) vector of quantization indexes */\r
+    int len,        /* (i) length of all vectors */\r
+    int state_first     /* (i) position of start state in the \r
+\r
+\r
+                               80 vec */\r
+);\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/anaFilter.c b/libs/codec/ilbc/anaFilter.c
new file mode 100644 (file)
index 0000000..bdaee18
--- /dev/null
@@ -0,0 +1,71 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    anaFilter.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <string.h>\r
+#include "anaFilter.h"\r
+#include "iLBC_define.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  LP analysis filter.\r
+\r
+\r
+ *---------------------------------------------------------------*/\r
+    \r
+void anaFilter(\r
+    float *In,  /* (i) Signal to be filtered */\r
+    float *a,   /* (i) LP parameters */\r
+    int len,/* (i) Length of signal */\r
+    float *Out, /* (o) Filtered signal */\r
+    float *mem  /* (i/o) Filter state */\r
+){\r
+    int i, j;\r
+    float *po, *pi, *pm, *pa;\r
+\r
+    po = Out;\r
+\r
+    /* Filter first part using memory from past */\r
+    \r
+    for (i=0; i<LPC_FILTERORDER; i++) {\r
+        pi = &In[i];\r
+        pm = &mem[LPC_FILTERORDER-1];\r
+        pa = a;\r
+        *po=0.0;\r
+        for (j=0; j<=i; j++) {\r
+            *po+=(*pa++)*(*pi--);\r
+        }\r
+        for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+\r
+            *po+=(*pa++)*(*pm--);\r
+        }\r
+        po++;\r
+    }\r
+\r
+    /* Filter last part where the state is entierly \r
+       in the input vector */\r
+\r
+    for (i=LPC_FILTERORDER; i<len; i++) {\r
+        pi = &In[i];\r
+        pa = a;\r
+        *po=0.0;\r
+        for (j=0; j<LPC_FILTERORDER+1; j++) {\r
+            *po+=(*pa++)*(*pi--);\r
+        }\r
+        po++;\r
+    }\r
+\r
+    /* Update state vector */\r
+\r
+    memcpy(mem, &In[len-LPC_FILTERORDER], \r
+        LPC_FILTERORDER*sizeof(float));\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/anaFilter.h b/libs/codec/ilbc/anaFilter.h
new file mode 100644 (file)
index 0000000..e1afd55
--- /dev/null
@@ -0,0 +1,26 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    anaFilter.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_ANAFILTER_H\r
+#define __iLBC_ANAFILTER_H\r
+\r
+void anaFilter(\r
+    float *In,  /* (i) Signal to be filtered */\r
+    float *a,   /* (i) LP parameters */\r
+    int len,/* (i) Length of signal */\r
+    float *Out, /* (o) Filtered signal */\r
+    float *mem  /* (i/o) Filter state */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/constants.c b/libs/codec/ilbc/constants.c
new file mode 100644 (file)
index 0000000..ee8cb0e
--- /dev/null
@@ -0,0 +1,729 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    constants.c\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "iLBC_define.h"\r
+\r
+/* ULP bit allocation */\r
+\r
+    /* 20 ms frame */\r
+\r
+const iLBC_ULP_Inst_t ULP_20msTbl = {\r
+    /* LSF */\r
+    {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+        {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+    /* Start state location, gain and samples */\r
+    {2,0,0,0,0},\r
+    {1,0,0,0,0},\r
+    {6,0,0,0,0},\r
+    {0,1,2,0,0},\r
+    /* extra CB index and extra CB gain */\r
+    {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+    {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+    /* CB index and CB gain */\r
+    {   {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+        {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},\r
+    {   {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+        {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}\r
+};\r
+\r
+    /* 30 ms frame */\r
+\r
+const iLBC_ULP_Inst_t ULP_30msTbl = {\r
+    /* LSF */\r
+    {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+\r
+\r
+        {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},\r
+    /* Start state location, gain and samples */\r
+    {3,0,0,0,0},\r
+    {1,0,0,0,0},\r
+    {6,0,0,0,0},\r
+    {0,1,2,0,0},\r
+    /* extra CB index and extra CB gain */\r
+    {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+    {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+    /* CB index and CB gain */\r
+    {   {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},\r
+    {   {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},\r
+        {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+        {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},\r
+        {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}\r
+};\r
+\r
+/* HP Filters */\r
+\r
+float hpi_zero_coefsTbl[3] = {\r
+    (float)0.92727436, (float)-1.8544941, (float)0.92727436\r
+};\r
+float hpi_pole_coefsTbl[3] = {\r
+    (float)1.0, (float)-1.9059465, (float)0.9114024\r
+};\r
+float hpo_zero_coefsTbl[3] = {\r
+    (float)0.93980581, (float)-1.8795834, (float)0.93980581\r
+};\r
+float hpo_pole_coefsTbl[3] = {\r
+    (float)1.0, (float)-1.9330735, (float)0.93589199\r
+};\r
+\r
+/* LP Filter */\r
+\r
+float lpFilt_coefsTbl[FILTERORDER_DS]={\r
+    (float)-0.066650, (float)0.125000, (float)0.316650, \r
+    (float)0.414063, (float)0.316650, \r
+    (float)0.125000, (float)-0.066650\r
+};\r
+\r
+/* State quantization tables */\r
+\r
+float state_sq3Tbl[8] = {\r
+    (float)-3.719849, (float)-2.177490, (float)-1.130005, \r
+    (float)-0.309692, (float)0.444214, (float)1.329712, \r
+    (float)2.436279, (float)3.983887\r
+};\r
+\r
+float state_frgqTbl[64] = {\r
+    (float)1.000085, (float)1.071695, (float)1.140395, \r
+    (float)1.206868, (float)1.277188, (float)1.351503, \r
+\r
+\r
+    (float)1.429380, (float)1.500727, (float)1.569049, \r
+    (float)1.639599, (float)1.707071, (float)1.781531, \r
+    (float)1.840799, (float)1.901550, (float)1.956695, \r
+    (float)2.006750, (float)2.055474, (float)2.102787, \r
+    (float)2.142819, (float)2.183592, (float)2.217962, \r
+    (float)2.257177, (float)2.295739, (float)2.332967, \r
+    (float)2.369248, (float)2.402792, (float)2.435080, \r
+    (float)2.468598, (float)2.503394, (float)2.539284, \r
+    (float)2.572944, (float)2.605036, (float)2.636331, \r
+    (float)2.668939, (float)2.698780, (float)2.729101, \r
+    (float)2.759786, (float)2.789834, (float)2.818679, \r
+    (float)2.848074, (float)2.877470, (float)2.906899, \r
+    (float)2.936655, (float)2.967804, (float)3.000115, \r
+    (float)3.033367, (float)3.066355, (float)3.104231, \r
+    (float)3.141499, (float)3.183012, (float)3.222952, \r
+    (float)3.265433, (float)3.308441, (float)3.350823, \r
+    (float)3.395275, (float)3.442793, (float)3.490801, \r
+    (float)3.542514, (float)3.604064, (float)3.666050, \r
+    (float)3.740994, (float)3.830749, (float)3.938770, \r
+    (float)4.101764\r
+};\r
+\r
+/* CB tables */\r
+\r
+int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, \r
+            {108,108,108}, {108,108,108}, {108,108,108}};\r
+int stMemLTbl=85;\r
+int memLfTbl[NASUB_MAX]={147,147,147,147};\r
+\r
+/* expansion filter(s) */\r
+\r
+float cbfiltersTbl[CB_FILTERLEN]={\r
+    (float)-0.034180, (float)0.108887, (float)-0.184326,\r
+    (float)0.806152,  (float)0.713379, (float)-0.144043,\r
+    (float)0.083740,  (float)-0.033691\r
+};\r
+\r
+/* Gain Quantization */\r
+\r
+float gain_sq3Tbl[8]={\r
+    (float)-1.000000,  (float)-0.659973,  (float)-0.330017,\r
+    (float)0.000000, (float)0.250000, (float)0.500000, \r
+    (float)0.750000, (float)1.00000};\r
+\r
+float gain_sq4Tbl[16]={\r
+    (float)-1.049988, (float)-0.900024, (float)-0.750000, \r
+    (float)-0.599976, (float)-0.450012, (float)-0.299988, \r
+    (float)-0.150024, (float)0.000000, (float)0.150024, \r
+    (float)0.299988, (float)0.450012, (float)0.599976, \r
+    (float)0.750000, (float)0.900024, (float)1.049988, \r
+    (float)1.200012};\r
+\r
+float gain_sq5Tbl[32]={\r
+    (float)0.037476, (float)0.075012, (float)0.112488, \r
+\r
+\r
+    (float)0.150024, (float)0.187500, (float)0.224976, \r
+    (float)0.262512, (float)0.299988, (float)0.337524, \r
+    (float)0.375000, (float)0.412476, (float)0.450012, \r
+    (float)0.487488, (float)0.525024, (float)0.562500, \r
+    (float)0.599976, (float)0.637512, (float)0.674988, \r
+    (float)0.712524, (float)0.750000, (float)0.787476, \r
+    (float)0.825012, (float)0.862488, (float)0.900024, \r
+    (float)0.937500, (float)0.974976, (float)1.012512, \r
+    (float)1.049988, (float)1.087524, (float)1.125000, \r
+    (float)1.162476, (float)1.200012};\r
+\r
+/* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */\r
+float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ \r
+    (float)0.000000, (float)0.000000, (float)0.000000,\r
+(float)1.000000, \r
+        (float)0.000000, (float)0.000000, (float)0.000000, \r
+    (float)0.015625, (float)-0.076904, (float)0.288330,\r
+(float)0.862061, \r
+        (float)-0.106445, (float)0.018799, (float)-0.015625, \r
+    (float)0.023682, (float)-0.124268, (float)0.601563,\r
+(float)0.601563, \r
+        (float)-0.124268, (float)0.023682, (float)-0.023682, \r
+    (float)0.018799, (float)-0.106445, (float)0.862061,\r
+(float)0.288330, \r
+        (float)-0.076904, (float)0.015625, (float)-0.018799};\r
+\r
+float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, \r
+            (float)200.0, (float)280.0, (float)360.0, \r
+            (float)440.0, (float)520.0, (float)600.0};\r
+\r
+/* LPC analysis and quantization */ \r
+\r
+int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};\r
+int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};\r
+\r
+\r
+float lsfmeanTbl[LPC_FILTERORDER] = { \r
+    (float)0.281738, (float)0.445801, (float)0.663330, \r
+    (float)0.962524, (float)1.251831, (float)1.533081, \r
+    (float)1.850586, (float)2.137817, (float)2.481445, \r
+    (float)2.777344};\r
+\r
+float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,\r
+(float)(2.0/3.0), \r
+    (float)(1.0/3.0), (float)0.0, (float)0.0};\r
+\r
+float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), \r
+    (float)(1.0/4.0), (float)(0.0)};\r
+\r
+/* Hanning LPC window */\r
+float lpc_winTbl[BLOCKL_MAX]={\r
+    (float)0.000183, (float)0.000671, (float)0.001526,\r
+    (float)0.002716, (float)0.004242, (float)0.006104,\r
+    (float)0.008301, (float)0.010834, (float)0.013702,\r
+\r
+\r
+    (float)0.016907, (float)0.020416, (float)0.024261,\r
+    (float)0.028442, (float)0.032928, (float)0.037750,\r
+    (float)0.042877, (float)0.048309, (float)0.054047,\r
+    (float)0.060089, (float)0.066437, (float)0.073090,\r
+    (float)0.080017, (float)0.087219, (float)0.094727,\r
+    (float)0.102509, (float)0.110535, (float)0.118835,\r
+    (float)0.127411, (float)0.136230, (float)0.145294,\r
+    (float)0.154602, (float)0.164154, (float)0.173920,\r
+    (float)0.183899, (float)0.194122, (float)0.204529,\r
+    (float)0.215149, (float)0.225952, (float)0.236938,\r
+    (float)0.248108, (float)0.259460, (float)0.270966,\r
+    (float)0.282654, (float)0.294464, (float)0.306396,\r
+    (float)0.318481, (float)0.330688, (float)0.343018,\r
+    (float)0.355438, (float)0.367981, (float)0.380585,\r
+    (float)0.393280, (float)0.406067, (float)0.418884,\r
+    (float)0.431763, (float)0.444702, (float)0.457672,\r
+    (float)0.470673, (float)0.483704, (float)0.496735,\r
+    (float)0.509766, (float)0.522797, (float)0.535828,\r
+    (float)0.548798, (float)0.561768, (float)0.574677,\r
+    (float)0.587524, (float)0.600342, (float)0.613068,\r
+    (float)0.625732, (float)0.638306, (float)0.650787,\r
+    (float)0.663147, (float)0.675415, (float)0.687561,\r
+    (float)0.699585, (float)0.711487, (float)0.723206,\r
+    (float)0.734802, (float)0.746216, (float)0.757477,\r
+    (float)0.768585, (float)0.779480, (float)0.790192,\r
+    (float)0.800720, (float)0.811005, (float)0.821106,\r
+    (float)0.830994, (float)0.840668, (float)0.850067,\r
+    (float)0.859253, (float)0.868225, (float)0.876892,\r
+    (float)0.885345, (float)0.893524, (float)0.901428,\r
+    (float)0.909058, (float)0.916412, (float)0.923492,\r
+    (float)0.930267, (float)0.936768, (float)0.942963,\r
+    (float)0.948853, (float)0.954437, (float)0.959717,\r
+    (float)0.964691, (float)0.969360, (float)0.973694,\r
+    (float)0.977692, (float)0.981384, (float)0.984741,\r
+    (float)0.987762, (float)0.990479, (float)0.992828,\r
+    (float)0.994873, (float)0.996552, (float)0.997925,\r
+    (float)0.998932, (float)0.999603, (float)0.999969,\r
+    (float)0.999969, (float)0.999603, (float)0.998932,\r
+    (float)0.997925, (float)0.996552, (float)0.994873,\r
+    (float)0.992828, (float)0.990479, (float)0.987762,\r
+    (float)0.984741, (float)0.981384, (float)0.977692,\r
+    (float)0.973694, (float)0.969360, (float)0.964691,\r
+    (float)0.959717, (float)0.954437, (float)0.948853,\r
+    (float)0.942963, (float)0.936768, (float)0.930267,\r
+    (float)0.923492, (float)0.916412, (float)0.909058,\r
+    (float)0.901428, (float)0.893524, (float)0.885345,\r
+    (float)0.876892, (float)0.868225, (float)0.859253,\r
+    (float)0.850067, (float)0.840668, (float)0.830994,\r
+    (float)0.821106, (float)0.811005, (float)0.800720,\r
+    (float)0.790192, (float)0.779480, (float)0.768585,\r
+    (float)0.757477, (float)0.746216, (float)0.734802,\r
+    (float)0.723206, (float)0.711487, (float)0.699585,\r
+    (float)0.687561, (float)0.675415, (float)0.663147,\r
+    (float)0.650787, (float)0.638306, (float)0.625732,\r
+\r
+\r
+    (float)0.613068, (float)0.600342, (float)0.587524,\r
+    (float)0.574677, (float)0.561768, (float)0.548798,\r
+    (float)0.535828, (float)0.522797, (float)0.509766,\r
+    (float)0.496735, (float)0.483704, (float)0.470673,\r
+    (float)0.457672, (float)0.444702, (float)0.431763,\r
+    (float)0.418884, (float)0.406067, (float)0.393280,\r
+    (float)0.380585, (float)0.367981, (float)0.355438,\r
+    (float)0.343018, (float)0.330688, (float)0.318481,\r
+    (float)0.306396, (float)0.294464, (float)0.282654,\r
+    (float)0.270966, (float)0.259460, (float)0.248108,\r
+    (float)0.236938, (float)0.225952, (float)0.215149,\r
+    (float)0.204529, (float)0.194122, (float)0.183899,\r
+    (float)0.173920, (float)0.164154, (float)0.154602,\r
+    (float)0.145294, (float)0.136230, (float)0.127411,\r
+    (float)0.118835, (float)0.110535, (float)0.102509,\r
+    (float)0.094727, (float)0.087219, (float)0.080017,\r
+    (float)0.073090, (float)0.066437, (float)0.060089,\r
+    (float)0.054047, (float)0.048309, (float)0.042877,\r
+    (float)0.037750, (float)0.032928, (float)0.028442,\r
+    (float)0.024261, (float)0.020416, (float)0.016907,\r
+    (float)0.013702, (float)0.010834, (float)0.008301,\r
+    (float)0.006104, (float)0.004242, (float)0.002716,\r
+    (float)0.001526, (float)0.000671, (float)0.000183\r
+};\r
+\r
+/* Asymmetric LPC window */\r
+float lpc_asymwinTbl[BLOCKL_MAX]={\r
+    (float)0.000061, (float)0.000214, (float)0.000458,\r
+    (float)0.000824, (float)0.001282, (float)0.001831,\r
+    (float)0.002472, (float)0.003235, (float)0.004120,\r
+    (float)0.005066, (float)0.006134, (float)0.007294,\r
+    (float)0.008545, (float)0.009918, (float)0.011383,\r
+    (float)0.012939, (float)0.014587, (float)0.016357,\r
+    (float)0.018219, (float)0.020172, (float)0.022217,\r
+    (float)0.024353, (float)0.026611, (float)0.028961,\r
+    (float)0.031372, (float)0.033905, (float)0.036530,\r
+    (float)0.039276, (float)0.042084, (float)0.044983,\r
+    (float)0.047974, (float)0.051086, (float)0.054260,\r
+    (float)0.057526, (float)0.060883, (float)0.064331,\r
+    (float)0.067871, (float)0.071503, (float)0.075226,\r
+    (float)0.079010, (float)0.082916, (float)0.086884,\r
+    (float)0.090942, (float)0.095062, (float)0.099304,\r
+    (float)0.103607, (float)0.107971, (float)0.112427,\r
+    (float)0.116974, (float)0.121582, (float)0.126282,\r
+    (float)0.131073, (float)0.135895, (float)0.140839,\r
+    (float)0.145813, (float)0.150879, (float)0.156006,\r
+    (float)0.161224, (float)0.166504, (float)0.171844,\r
+    (float)0.177246, (float)0.182709, (float)0.188263,\r
+    (float)0.193848, (float)0.199524, (float)0.205231,\r
+    (float)0.211029, (float)0.216858, (float)0.222778,\r
+    (float)0.228729, (float)0.234741, (float)0.240814,\r
+    (float)0.246918, (float)0.253082, (float)0.259308,\r
+    (float)0.265564, (float)0.271881, (float)0.278259,\r
+    (float)0.284668, (float)0.291107, (float)0.297607,\r
+\r
+\r
+    (float)0.304138, (float)0.310730, (float)0.317322,\r
+    (float)0.323975, (float)0.330658, (float)0.337372,\r
+    (float)0.344147, (float)0.350922, (float)0.357727,\r
+    (float)0.364594, (float)0.371460, (float)0.378357,\r
+    (float)0.385284, (float)0.392212, (float)0.399170,\r
+    (float)0.406158, (float)0.413177, (float)0.420197,\r
+    (float)0.427246, (float)0.434296, (float)0.441376,\r
+    (float)0.448456, (float)0.455536, (float)0.462646,\r
+    (float)0.469757, (float)0.476868, (float)0.483978,\r
+    (float)0.491089, (float)0.498230, (float)0.505341,\r
+    (float)0.512451, (float)0.519592, (float)0.526703,\r
+    (float)0.533813, (float)0.540924, (float)0.548004,\r
+    (float)0.555084, (float)0.562164, (float)0.569244,\r
+    (float)0.576294, (float)0.583313, (float)0.590332,\r
+    (float)0.597321, (float)0.604309, (float)0.611267,\r
+    (float)0.618195, (float)0.625092, (float)0.631989,\r
+    (float)0.638855, (float)0.645660, (float)0.652466,\r
+    (float)0.659241, (float)0.665985, (float)0.672668,\r
+    (float)0.679352, (float)0.685974, (float)0.692566,\r
+    (float)0.699127, (float)0.705658, (float)0.712128,\r
+    (float)0.718536, (float)0.724945, (float)0.731262,\r
+    (float)0.737549, (float)0.743805, (float)0.750000,\r
+    (float)0.756134, (float)0.762238, (float)0.768280,\r
+    (float)0.774261, (float)0.780182, (float)0.786072,\r
+    (float)0.791870, (float)0.797638, (float)0.803314,\r
+    (float)0.808960, (float)0.814514, (float)0.820038,\r
+    (float)0.825470, (float)0.830841, (float)0.836151,\r
+    (float)0.841400, (float)0.846558, (float)0.851654,\r
+    (float)0.856689, (float)0.861633, (float)0.866516,\r
+    (float)0.871338, (float)0.876068, (float)0.880737,\r
+    (float)0.885315, (float)0.889801, (float)0.894226,\r
+    (float)0.898560, (float)0.902832, (float)0.907013,\r
+    (float)0.911102, (float)0.915100, (float)0.919037,\r
+    (float)0.922882, (float)0.926636, (float)0.930328,\r
+    (float)0.933899, (float)0.937408, (float)0.940796,\r
+    (float)0.944122, (float)0.947357, (float)0.950470,\r
+    (float)0.953522, (float)0.956482, (float)0.959351,\r
+    (float)0.962097, (float)0.964783, (float)0.967377,\r
+    (float)0.969849, (float)0.972229, (float)0.974518,\r
+    (float)0.976715, (float)0.978821, (float)0.980835,\r
+    (float)0.982727, (float)0.984528, (float)0.986237,\r
+    (float)0.987854, (float)0.989380, (float)0.990784,\r
+    (float)0.992096, (float)0.993317, (float)0.994415,\r
+    (float)0.995422, (float)0.996338, (float)0.997162,\r
+    (float)0.997864, (float)0.998474, (float)0.998962,\r
+    (float)0.999390, (float)0.999695, (float)0.999878,\r
+    (float)0.999969, (float)0.999969, (float)0.996918,\r
+    (float)0.987701, (float)0.972382, (float)0.951050,\r
+    (float)0.923889, (float)0.891022, (float)0.852631,\r
+    (float)0.809021, (float)0.760406, (float)0.707092,\r
+    (float)0.649445, (float)0.587799, (float)0.522491,\r
+    (float)0.453979, (float)0.382690, (float)0.309021,\r
+    (float)0.233459, (float)0.156433, (float)0.078461\r
+};\r
+\r
+\r
+\r
+/* Lag window for LPC */\r
+float lpc_lagwinTbl[LPC_FILTERORDER + 1]={\r
+    (float)1.000100, (float)0.998890, (float)0.995569,\r
+        (float)0.990057, (float)0.982392,\r
+    (float)0.972623, (float)0.960816, (float)0.947047,\r
+        (float)0.931405, (float)0.913989, (float)0.894909};\r
+\r
+/* LSF quantization*/\r
+float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {\r
+(float)0.155396, (float)0.273193, (float)0.451172,\r
+(float)0.390503, (float)0.648071, (float)1.002075,\r
+(float)0.440186, (float)0.692261, (float)0.955688,\r
+(float)0.343628, (float)0.642334, (float)1.071533,\r
+(float)0.318359, (float)0.491577, (float)0.670532,\r
+(float)0.193115, (float)0.375488, (float)0.725708,\r
+(float)0.364136, (float)0.510376, (float)0.658691,\r
+(float)0.297485, (float)0.527588, (float)0.842529,\r
+(float)0.227173, (float)0.365967, (float)0.563110,\r
+(float)0.244995, (float)0.396729, (float)0.636475,\r
+(float)0.169434, (float)0.300171, (float)0.520264,\r
+(float)0.312866, (float)0.464478, (float)0.643188,\r
+(float)0.248535, (float)0.429932, (float)0.626099,\r
+(float)0.236206, (float)0.491333, (float)0.817139,\r
+(float)0.334961, (float)0.625122, (float)0.895752,\r
+(float)0.343018, (float)0.518555, (float)0.698608,\r
+(float)0.372803, (float)0.659790, (float)0.945435,\r
+(float)0.176880, (float)0.316528, (float)0.581421,\r
+(float)0.416382, (float)0.625977, (float)0.805176,\r
+(float)0.303223, (float)0.568726, (float)0.915039,\r
+(float)0.203613, (float)0.351440, (float)0.588135,\r
+(float)0.221191, (float)0.375000, (float)0.614746,\r
+(float)0.199951, (float)0.323364, (float)0.476074,\r
+(float)0.300781, (float)0.433350, (float)0.566895,\r
+(float)0.226196, (float)0.354004, (float)0.507568,\r
+(float)0.300049, (float)0.508179, (float)0.711670,\r
+(float)0.312012, (float)0.492676, (float)0.763428,\r
+(float)0.329956, (float)0.541016, (float)0.795776,\r
+(float)0.373779, (float)0.604614, (float)0.928833,\r
+(float)0.210571, (float)0.452026, (float)0.755249,\r
+(float)0.271118, (float)0.473267, (float)0.662476,\r
+(float)0.285522, (float)0.436890, (float)0.634399,\r
+(float)0.246704, (float)0.565552, (float)0.859009,\r
+(float)0.270508, (float)0.406250, (float)0.553589,\r
+(float)0.361450, (float)0.578491, (float)0.813843,\r
+(float)0.342651, (float)0.482788, (float)0.622437,\r
+(float)0.340332, (float)0.549438, (float)0.743164,\r
+(float)0.200439, (float)0.336304, (float)0.540894,\r
+(float)0.407837, (float)0.644775, (float)0.895142,\r
+(float)0.294678, (float)0.454834, (float)0.699097,\r
+(float)0.193115, (float)0.344482, (float)0.643188,\r
+(float)0.275757, (float)0.420776, (float)0.598755,\r
+(float)0.380493, (float)0.608643, (float)0.861084,\r
+(float)0.222778, (float)0.426147, (float)0.676514,\r
+\r
+\r
+(float)0.407471, (float)0.700195, (float)1.053101,\r
+(float)0.218384, (float)0.377197, (float)0.669922,\r
+(float)0.313232, (float)0.454102, (float)0.600952,\r
+(float)0.347412, (float)0.571533, (float)0.874146,\r
+(float)0.238037, (float)0.405396, (float)0.729492,\r
+(float)0.223877, (float)0.412964, (float)0.822021,\r
+(float)0.395264, (float)0.582153, (float)0.743896,\r
+(float)0.247925, (float)0.485596, (float)0.720581,\r
+(float)0.229126, (float)0.496582, (float)0.907715,\r
+(float)0.260132, (float)0.566895, (float)1.012695,\r
+(float)0.337402, (float)0.611572, (float)0.978149,\r
+(float)0.267822, (float)0.447632, (float)0.769287,\r
+(float)0.250610, (float)0.381714, (float)0.530029,\r
+(float)0.430054, (float)0.805054, (float)1.221924,\r
+(float)0.382568, (float)0.544067, (float)0.701660,\r
+(float)0.383545, (float)0.710327, (float)1.149170,\r
+(float)0.271362, (float)0.529053, (float)0.775513,\r
+(float)0.246826, (float)0.393555, (float)0.588623,\r
+(float)0.266846, (float)0.422119, (float)0.676758,\r
+(float)0.311523, (float)0.580688, (float)0.838623,\r
+(float)1.331177, (float)1.576782, (float)1.779541,\r
+(float)1.160034, (float)1.401978, (float)1.768188,\r
+(float)1.161865, (float)1.525146, (float)1.715332,\r
+(float)0.759521, (float)0.913940, (float)1.119873,\r
+(float)0.947144, (float)1.121338, (float)1.282471,\r
+(float)1.015015, (float)1.557007, (float)1.804932,\r
+(float)1.172974, (float)1.402100, (float)1.692627,\r
+(float)1.087524, (float)1.474243, (float)1.665405,\r
+(float)0.899536, (float)1.105225, (float)1.406250,\r
+(float)1.148438, (float)1.484741, (float)1.796265,\r
+(float)0.785645, (float)1.209839, (float)1.567749,\r
+(float)0.867798, (float)1.166504, (float)1.450684,\r
+(float)0.922485, (float)1.229858, (float)1.420898,\r
+(float)0.791260, (float)1.123291, (float)1.409546,\r
+(float)0.788940, (float)0.966064, (float)1.340332,\r
+(float)1.051147, (float)1.272827, (float)1.556641,\r
+(float)0.866821, (float)1.181152, (float)1.538818,\r
+(float)0.906738, (float)1.373535, (float)1.607910,\r
+(float)1.244751, (float)1.581421, (float)1.933838,\r
+(float)0.913940, (float)1.337280, (float)1.539673,\r
+(float)0.680542, (float)0.959229, (float)1.662720,\r
+(float)0.887207, (float)1.430542, (float)1.800781,\r
+(float)0.912598, (float)1.433594, (float)1.683960,\r
+(float)0.860474, (float)1.060303, (float)1.455322,\r
+(float)1.005127, (float)1.381104, (float)1.706909,\r
+(float)0.800781, (float)1.363892, (float)1.829102,\r
+(float)0.781860, (float)1.124390, (float)1.505981,\r
+(float)1.003662, (float)1.471436, (float)1.684692,\r
+(float)0.981323, (float)1.309570, (float)1.618042,\r
+(float)1.228760, (float)1.554321, (float)1.756470,\r
+(float)0.734375, (float)0.895752, (float)1.225586,\r
+(float)0.841797, (float)1.055664, (float)1.249268,\r
+(float)0.920166, (float)1.119385, (float)1.486206,\r
+(float)0.894409, (float)1.539063, (float)1.828979,\r
+\r
+\r
+(float)1.283691, (float)1.543335, (float)1.858276,\r
+(float)0.676025, (float)0.933105, (float)1.490845,\r
+(float)0.821289, (float)1.491821, (float)1.739868,\r
+(float)0.923218, (float)1.144653, (float)1.580566,\r
+(float)1.057251, (float)1.345581, (float)1.635864,\r
+(float)0.888672, (float)1.074951, (float)1.353149,\r
+(float)0.942749, (float)1.195435, (float)1.505493,\r
+(float)1.492310, (float)1.788086, (float)2.039673,\r
+(float)1.070313, (float)1.634399, (float)1.860962,\r
+(float)1.253296, (float)1.488892, (float)1.686035,\r
+(float)0.647095, (float)0.864014, (float)1.401855,\r
+(float)0.866699, (float)1.254883, (float)1.453369,\r
+(float)1.063965, (float)1.532593, (float)1.731323,\r
+(float)1.167847, (float)1.521484, (float)1.884033,\r
+(float)0.956055, (float)1.502075, (float)1.745605,\r
+(float)0.928711, (float)1.288574, (float)1.479614,\r
+(float)1.088013, (float)1.380737, (float)1.570801,\r
+(float)0.905029, (float)1.186768, (float)1.371948,\r
+(float)1.057861, (float)1.421021, (float)1.617432,\r
+(float)1.108276, (float)1.312500, (float)1.501465,\r
+(float)0.979492, (float)1.416992, (float)1.624268,\r
+(float)1.276001, (float)1.661011, (float)2.007935,\r
+(float)0.993042, (float)1.168579, (float)1.331665,\r
+(float)0.778198, (float)0.944946, (float)1.235962,\r
+(float)1.223755, (float)1.491333, (float)1.815674,\r
+(float)0.852661, (float)1.350464, (float)1.722290,\r
+(float)1.134766, (float)1.593140, (float)1.787354,\r
+(float)1.051392, (float)1.339722, (float)1.531006,\r
+(float)0.803589, (float)1.271240, (float)1.652100,\r
+(float)0.755737, (float)1.143555, (float)1.639404,\r
+(float)0.700928, (float)0.837280, (float)1.130371,\r
+(float)0.942749, (float)1.197876, (float)1.669800,\r
+(float)0.993286, (float)1.378296, (float)1.566528,\r
+(float)0.801025, (float)1.095337, (float)1.298950,\r
+(float)0.739990, (float)1.032959, (float)1.383667,\r
+(float)0.845703, (float)1.072266, (float)1.543823,\r
+(float)0.915649, (float)1.072266, (float)1.224487,\r
+(float)1.021973, (float)1.226196, (float)1.481323,\r
+(float)0.999878, (float)1.204102, (float)1.555908,\r
+(float)0.722290, (float)0.913940, (float)1.340210,\r
+(float)0.673340, (float)0.835938, (float)1.259521,\r
+(float)0.832397, (float)1.208374, (float)1.394165,\r
+(float)0.962158, (float)1.576172, (float)1.912842,\r
+(float)1.166748, (float)1.370850, (float)1.556763,\r
+(float)0.946289, (float)1.138550, (float)1.400391,\r
+(float)1.035034, (float)1.218262, (float)1.386475,\r
+(float)1.393799, (float)1.717773, (float)2.000244,\r
+(float)0.972656, (float)1.260986, (float)1.760620,\r
+(float)1.028198, (float)1.288452, (float)1.484619,\r
+(float)0.773560, (float)1.258057, (float)1.756714,\r
+(float)1.080322, (float)1.328003, (float)1.742676,\r
+(float)0.823975, (float)1.450806, (float)1.917725,\r
+(float)0.859009, (float)1.016602, (float)1.191895,\r
+(float)0.843994, (float)1.131104, (float)1.645020,\r
+\r
+\r
+(float)1.189697, (float)1.702759, (float)1.894409,\r
+(float)1.346680, (float)1.763184, (float)2.066040,\r
+(float)0.980469, (float)1.253784, (float)1.441650,\r
+(float)1.338135, (float)1.641968, (float)1.932739,\r
+(float)1.223267, (float)1.424194, (float)1.626465,\r
+(float)0.765747, (float)1.004150, (float)1.579102,\r
+(float)1.042847, (float)1.269165, (float)1.647461,\r
+(float)0.968750, (float)1.257568, (float)1.555786,\r
+(float)0.826294, (float)0.993408, (float)1.275146,\r
+(float)0.742310, (float)0.950439, (float)1.430542,\r
+(float)1.054321, (float)1.439819, (float)1.828003,\r
+(float)1.072998, (float)1.261719, (float)1.441895,\r
+(float)0.859375, (float)1.036377, (float)1.314819,\r
+(float)0.895752, (float)1.267212, (float)1.605591,\r
+(float)0.805420, (float)0.962891, (float)1.142334,\r
+(float)0.795654, (float)1.005493, (float)1.468506,\r
+(float)1.105347, (float)1.313843, (float)1.584839,\r
+(float)0.792236, (float)1.221802, (float)1.465698,\r
+(float)1.170532, (float)1.467651, (float)1.664063,\r
+(float)0.838257, (float)1.153198, (float)1.342163,\r
+(float)0.968018, (float)1.198242, (float)1.391235,\r
+(float)1.250122, (float)1.623535, (float)1.823608,\r
+(float)0.711670, (float)1.058350, (float)1.512085,\r
+(float)1.204834, (float)1.454468, (float)1.739136,\r
+(float)1.137451, (float)1.421753, (float)1.620117,\r
+(float)0.820435, (float)1.322754, (float)1.578247,\r
+(float)0.798706, (float)1.005005, (float)1.213867,\r
+(float)0.980713, (float)1.324951, (float)1.512939,\r
+(float)1.112305, (float)1.438843, (float)1.735596,\r
+(float)1.135498, (float)1.356689, (float)1.635742,\r
+(float)1.101318, (float)1.387451, (float)1.686523,\r
+(float)0.849854, (float)1.276978, (float)1.523438,\r
+(float)1.377930, (float)1.627563, (float)1.858154,\r
+(float)0.884888, (float)1.095459, (float)1.287476,\r
+(float)1.289795, (float)1.505859, (float)1.756592,\r
+(float)0.817505, (float)1.384155, (float)1.650513,\r
+(float)1.446655, (float)1.702148, (float)1.931885,\r
+(float)0.835815, (float)1.023071, (float)1.385376,\r
+(float)0.916626, (float)1.139038, (float)1.335327,\r
+(float)0.980103, (float)1.174072, (float)1.453735,\r
+(float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,\r
+(float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,\r
+(float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,\r
+(float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,\r
+(float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,\r
+(float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,\r
+(float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,\r
+(float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,\r
+(float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,\r
+(float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,\r
+(float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,\r
+(float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,\r
+(float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,\r
+(float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,\r
+\r
+\r
+(float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,\r
+(float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,\r
+(float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,\r
+(float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,\r
+(float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,\r
+(float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,\r
+(float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,\r
+(float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,\r
+(float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,\r
+(float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,\r
+(float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,\r
+(float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,\r
+(float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,\r
+(float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,\r
+(float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,\r
+(float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,\r
+(float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,\r
+(float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,\r
+(float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,\r
+(float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,\r
+(float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,\r
+(float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,\r
+(float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,\r
+(float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,\r
+(float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,\r
+(float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,\r
+(float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,\r
+(float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,\r
+(float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,\r
+(float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,\r
+(float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,\r
+(float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,\r
+(float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,\r
+(float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,\r
+(float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,\r
+(float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,\r
+(float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,\r
+(float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,\r
+(float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,\r
+(float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,\r
+(float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,\r
+(float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,\r
+(float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,\r
+(float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,\r
+(float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,\r
+(float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,\r
+(float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,\r
+(float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,\r
+(float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,\r
+(float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,\r
+(float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,\r
+(float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,\r
+(float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,\r
+(float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,\r
+\r
+\r
+(float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,\r
+(float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,\r
+(float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,\r
+(float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,\r
+(float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,\r
+(float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,\r
+(float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,\r
+(float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,\r
+(float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,\r
+(float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,\r
+(float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,\r
+(float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,\r
+(float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,\r
+(float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,\r
+(float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,\r
+(float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,\r
+(float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,\r
+(float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,\r
+(float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,\r
+(float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,\r
+(float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,\r
+(float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,\r
+(float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,\r
+(float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,\r
+(float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,\r
+(float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,\r
+(float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,\r
+(float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,\r
+(float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,\r
+(float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,\r
+(float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,\r
+(float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,\r
+(float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,\r
+(float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,\r
+(float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,\r
+(float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,\r
+(float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,\r
+(float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,\r
+(float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,\r
+(float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,\r
+(float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,\r
+(float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,\r
+(float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,\r
+(float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,\r
+(float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,\r
+(float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,\r
+(float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,\r
+(float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,\r
+(float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,\r
+(float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,\r
+(float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,\r
+(float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,\r
+(float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,\r
+(float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,\r
+\r
+\r
+(float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,\r
+(float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,\r
+(float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,\r
+(float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,\r
+(float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,\r
+(float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143\r
+};\r
+\r
+\r
diff --git a/libs/codec/ilbc/constants.h b/libs/codec/ilbc/constants.h
new file mode 100644 (file)
index 0000000..155ee97
--- /dev/null
@@ -0,0 +1,74 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    constants.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_CONSTANTS_H\r
+#define __iLBC_CONSTANTS_H\r
+\r
+#include "iLBC_define.h"\r
+\r
+\r
+/* ULP bit allocation */\r
+\r
+extern const iLBC_ULP_Inst_t ULP_20msTbl;\r
+extern const iLBC_ULP_Inst_t ULP_30msTbl;\r
+\r
+/* high pass filters */\r
+\r
+extern float hpi_zero_coefsTbl[];\r
+extern float hpi_pole_coefsTbl[];\r
+extern float hpo_zero_coefsTbl[];\r
+extern float hpo_pole_coefsTbl[];  \r
+\r
+/* low pass filters */\r
+extern float lpFilt_coefsTbl[];\r
+\r
+/* LPC analysis and quantization */\r
+\r
+extern float lpc_winTbl[];\r
+extern float lpc_asymwinTbl[];\r
+extern float lpc_lagwinTbl[];\r
+extern float lsfCbTbl[];\r
+extern float lsfmeanTbl[];\r
+extern int   dim_lsfCbTbl[];\r
+extern int   size_lsfCbTbl[];\r
+extern float lsf_weightTbl_30ms[]; \r
+extern float lsf_weightTbl_20ms[];\r
+\r
+/* state quantization tables */\r
+\r
+extern float state_sq3Tbl[];\r
+extern float state_frgqTbl[];\r
+\r
+/* gain quantization tables */\r
+\r
+extern float gain_sq3Tbl[];\r
+extern float gain_sq4Tbl[];\r
+extern float gain_sq5Tbl[];\r
+\r
+/* adaptive codebook definitions */\r
+\r
+extern int search_rangeTbl[5][CB_NSTAGES];\r
+extern int memLfTbl[];\r
+extern int stMemLTbl;\r
+extern float cbfiltersTbl[CB_FILTERLEN];\r
+\r
+\r
+\r
+/* enhancer definitions */\r
+\r
+extern float polyphaserTbl[];\r
+extern float enh_plocsTbl[];\r
+\r
+#endif\r
+\r
diff --git a/libs/codec/ilbc/createCB.c b/libs/codec/ilbc/createCB.c
new file mode 100644 (file)
index 0000000..cd79fa2
--- /dev/null
@@ -0,0 +1,216 @@
+\r
+\r
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    createCB.c\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "iLBC_define.h"\r
+#include "createCB.h"\r
+#include "constants.h"\r
+#include <string.h>\r
+#include <math.h>\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Construct an additional codebook vector by filtering the\r
+ *  initial codebook buffer. This vector is then used to expand\r
+ *  the codebook with an additional section.\r
+ *---------------------------------------------------------------*/\r
+\r
+void filteredCBvecs(\r
+    float *cbvectors,   /* (o) Codebook vectors for the \r
+                               higher section */\r
+    float *mem,         /* (i) Buffer to create codebook \r
+                               vector from */\r
+    int lMem        /* (i) Length of buffer */\r
+){\r
+    int j, k;\r
+    float *pp, *pp1;\r
+    float tempbuff2[CB_MEML+CB_FILTERLEN];\r
+    float *pos;\r
+\r
+    memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));\r
+    memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));\r
+    memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, \r
+        (CB_HALFFILTERLEN+1)*sizeof(float));\r
+\r
+    /* Create codebook vector for higher section by filtering */\r
+\r
+    /* do filtering */\r
+    pos=cbvectors;\r
+    memset(pos, 0, lMem*sizeof(float));\r
+    for (k=0; k<lMem; k++) {\r
+        pp=&tempbuff2[k];\r
+        pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+        for (j=0;j<CB_FILTERLEN;j++) {\r
+            (*pos)+=(*pp++)*(*pp1--);\r
+        }\r
+        pos++;\r
+    }\r
+}\r
+\r
+\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Search the augmented part of the codebook to find the best\r
+ *  measure.\r
+ *----------------------------------------------------------------*/\r
+\r
+void searchAugmentedCB(\r
+    int low,        /* (i) Start index for the search */\r
+    int high,           /* (i) End index for the search */\r
+    int stage,          /* (i) Current stage */\r
+    int startIndex,     /* (i) Codebook index for the first \r
+                               aug vector */\r
+    float *target,      /* (i) Target vector for encoding */\r
+    float *buffer,      /* (i) Pointer to the end of the buffer for\r
+                               augmented codebook construction */\r
+    float *max_measure, /* (i/o) Currently maximum measure */\r
+    int *best_index,/* (o) Currently the best index */\r
+    float *gain,    /* (o) Currently the best gain */\r
+    float *energy,      /* (o) Energy of augmented codebook \r
+                               vectors */\r
+    float *invenergy/* (o) Inv energy of augmented codebook \r
+                               vectors */\r
+) {\r
+    int icount, ilow, j, tmpIndex;\r
+    float *pp, *ppo, *ppi, *ppe, crossDot, alfa; \r
+    float weighted, measure, nrjRecursive;\r
+    float ftmp;\r
+\r
+    /* Compute the energy for the first (low-5) \r
+       noninterpolated samples */\r
+    nrjRecursive = (float) 0.0;\r
+    pp = buffer - low + 1;\r
+    for (j=0; j<(low-5); j++) {\r
+        nrjRecursive += ( (*pp)*(*pp) );\r
+        pp++;\r
+    }\r
+    ppe = buffer - low;\r
+\r
+\r
+    for (icount=low; icount<=high; icount++) {\r
+\r
+        /* Index of the codebook vector used for retrieving \r
+           energy values */\r
+        tmpIndex = startIndex+icount-20;\r
+\r
+        ilow = icount-4;\r
+            \r
+        /* Update the energy recursively to save complexity */\r
+        nrjRecursive = nrjRecursive + (*ppe)*(*ppe);\r
+        ppe--;\r
+        energy[tmpIndex] = nrjRecursive;\r
+\r
+        /* Compute cross dot product for the first (low-5) \r
+           samples */\r
+        crossDot = (float) 0.0;\r
+\r
+\r
+        pp = buffer-icount;\r
+        for (j=0; j<ilow; j++) {\r
+            crossDot += target[j]*(*pp++);\r
+        }\r
+\r
+        /* interpolation */\r
+        alfa = (float) 0.2;\r
+        ppo = buffer-4;\r
+        ppi = buffer-icount-4;\r
+        for (j=ilow; j<icount; j++) {\r
+            weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+            ppo++;\r
+            ppi++;\r
+            energy[tmpIndex] += weighted*weighted;\r
+            crossDot += target[j]*weighted;\r
+            alfa += (float)0.2;\r
+        }\r
+\r
+        /* Compute energy and cross dot product for the \r
+           remaining samples */\r
+        pp = buffer - icount;\r
+        for (j=icount; j<SUBL; j++) {\r
+            energy[tmpIndex] += (*pp)*(*pp);\r
+            crossDot += target[j]*(*pp++);\r
+        }\r
+        \r
+        if (energy[tmpIndex]>0.0) {\r
+            invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);\r
+        } else {\r
+            invenergy[tmpIndex] = (float) 0.0;\r
+        }\r
+        \r
+        if (stage==0) {\r
+            measure = (float)-10000000.0;\r
+            \r
+            if (crossDot > 0.0) {\r
+                measure = crossDot*crossDot*invenergy[tmpIndex];\r
+            }\r
+        }\r
+        else {\r
+            measure = crossDot*crossDot*invenergy[tmpIndex];\r
+        }\r
+    \r
+        /* check if measure is better */\r
+        ftmp = crossDot*invenergy[tmpIndex];\r
+        \r
+        if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+            *best_index = tmpIndex;\r
+            *max_measure = measure;\r
+            *gain = ftmp;\r
+        }\r
+    }\r
+}\r
+\r
+\r
+\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Recreate a specific codebook vector from the augmented part.\r
+ *\r
+ *----------------------------------------------------------------*/\r
+\r
+void createAugmentedVec(\r
+    int index,      /* (i) Index for the augmented vector \r
+                           to be created */\r
+    float *buffer,  /* (i) Pointer to the end of the buffer for\r
+                           augmented codebook construction */\r
+    float *cbVec/* (o) The construced codebook vector */\r
+) {\r
+    int ilow, j;\r
+    float *pp, *ppo, *ppi, alfa, alfa1, weighted;\r
+\r
+    ilow = index-5;\r
+            \r
+    /* copy the first noninterpolated part */\r
+\r
+    pp = buffer-index;\r
+    memcpy(cbVec,pp,sizeof(float)*index);\r
+\r
+    /* interpolation */\r
+\r
+    alfa1 = (float)0.2;\r
+    alfa = 0.0;\r
+    ppo = buffer-5;\r
+    ppi = buffer-index-5;\r
+    for (j=ilow; j<index; j++) {\r
+        weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+        ppo++;\r
+        ppi++;\r
+        cbVec[j] = weighted;\r
+        alfa += alfa1;\r
+    }\r
+\r
+    /* copy the second noninterpolated part */\r
+\r
+    pp = buffer - index;\r
+    memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/createCB.h b/libs/codec/ilbc/createCB.h
new file mode 100644 (file)
index 0000000..b099a83
--- /dev/null
@@ -0,0 +1,56 @@
+\r
+/******************************************************************\r
+\r
+\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    createCB.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_CREATECB_H\r
+#define __iLBC_CREATECB_H\r
+\r
+void filteredCBvecs(\r
+    float *cbvectors,   /* (o) Codebook vector for the \r
+                               higher section */\r
+    float *mem,         /* (i) Buffer to create codebook \r
+                               vectors from */\r
+    int lMem        /* (i) Length of buffer */\r
+);\r
+\r
+void searchAugmentedCB(\r
+    int low,        /* (i) Start index for the search */\r
+    int high,           /* (i) End index for the search */\r
+    int stage,          /* (i) Current stage */\r
+    int startIndex,     /* (i) CB index for the first \r
+                               augmented vector */\r
+    float *target,      /* (i) Target vector for encoding */\r
+    float *buffer,      /* (i) Pointer to the end of the \r
+                               buffer for augmented codebook \r
+                               construction */\r
+    float *max_measure, /* (i/o) Currently maximum measure */\r
+    int *best_index,/* (o) Currently the best index */\r
+    float *gain,    /* (o) Currently the best gain */\r
+    float *energy,      /* (o) Energy of augmented \r
+                               codebook vectors */\r
+    float *invenergy/* (o) Inv energy of aug codebook \r
+                               vectors */\r
+);\r
+\r
+void createAugmentedVec(\r
+    int index,          /* (i) Index for the aug vector \r
+                               to be created */\r
+    float *buffer,      /* (i) Pointer to the end of the \r
+                               buffer for augmented codebook \r
+                               construction */\r
+    float *cbVec    /* (o) The construced codebook vector */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/doCPLC.c b/libs/codec/ilbc/doCPLC.c
new file mode 100644 (file)
index 0000000..b7d3b4e
--- /dev/null
@@ -0,0 +1,259 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    doCPLC.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "doCPLC.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Compute cross correlation and pitch gain for pitch prediction\r
+ *  of last subframe at given lag.\r
+ *---------------------------------------------------------------*/\r
+\r
+static void compCorr(\r
+    float *cc,      /* (o) cross correlation coefficient */\r
+    float *gc,      /* (o) gain */\r
+    float *pm,\r
+    float *buffer,  /* (i) signal buffer */\r
+    int lag,    /* (i) pitch lag */\r
+    int bLen,       /* (i) length of buffer */\r
+    int sRange      /* (i) correlation search length */\r
+){\r
+\r
+\r
+    int i;\r
+    float ftmp1, ftmp2, ftmp3;\r
+\r
+    /* Guard against getting outside buffer */\r
+    if ((bLen-sRange-lag)<0) {\r
+        sRange=bLen-lag;\r
+    }\r
+\r
+    ftmp1 = 0.0;\r
+    ftmp2 = 0.0;\r
+    ftmp3 = 0.0;\r
+    for (i=0; i<sRange; i++) {\r
+        ftmp1 += buffer[bLen-sRange+i] *\r
+            buffer[bLen-sRange+i-lag];\r
+        ftmp2 += buffer[bLen-sRange+i-lag] * \r
+                buffer[bLen-sRange+i-lag];\r
+        ftmp3 += buffer[bLen-sRange+i] * \r
+                buffer[bLen-sRange+i];\r
+    }\r
+\r
+    if (ftmp2 > 0.0) {\r
+        *cc = ftmp1*ftmp1/ftmp2;\r
+        *gc = (float)fabs(ftmp1/ftmp2);\r
+        *pm=(float)fabs(ftmp1)/\r
+            ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));\r
+    }\r
+    else {\r
+        *cc = 0.0;\r
+        *gc = 0.0;\r
+        *pm=0.0;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Packet loss concealment routine. Conceals a residual signal\r
+ *  and LP parameters. If no packet loss, update state.\r
+ *---------------------------------------------------------------*/\r
+\r
+void doThePLC(\r
+    float *PLCresidual, /* (o) concealed residual */ \r
+    float *PLClpc,      /* (o) concealed LP parameters */  \r
+    int PLI,        /* (i) packet loss indicator \r
+                               0 - no PL, 1 = PL */ \r
+    float *decresidual, /* (i) decoded residual */\r
+    float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+    int inlag,          /* (i) pitch lag */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst \r
+                        /* (i/o) decoder instance */\r
+){\r
+    int lag=20, randlag;\r
+    float gain, maxcc;\r
+    float use_gain;\r
+    float gain_comp, maxcc_comp, per, max_per;\r
+    int i, pick, use_lag;\r
+\r
+\r
+    float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;\r
+            \r
+    /* Packet Loss */\r
+\r
+    if (PLI == 1) {\r
+        \r
+        iLBCdec_inst->consPLICount += 1;\r
+        \r
+        /* if previous frame not lost, \r
+           determine pitch pred. gain */\r
+        \r
+        if (iLBCdec_inst->prevPLI != 1) {\r
+\r
+            /* Search around the previous lag to find the \r
+               best pitch period */\r
+            \r
+            lag=inlag-3;\r
+            compCorr(&maxcc, &gain, &max_per, \r
+                iLBCdec_inst->prevResidual,\r
+                lag, iLBCdec_inst->blockl, 60);\r
+            for (i=inlag-2;i<=inlag+3;i++) {\r
+                compCorr(&maxcc_comp, &gain_comp, &per,\r
+                    iLBCdec_inst->prevResidual,\r
+                    i, iLBCdec_inst->blockl, 60);\r
+                \r
+                if (maxcc_comp>maxcc) {\r
+                    maxcc=maxcc_comp;\r
+                    gain=gain_comp;\r
+                    lag=i;\r
+                    max_per=per;\r
+                }\r
+            }\r
+            \r
+        }\r
+\r
+        /* previous frame lost, use recorded lag and periodicity */\r
+\r
+        else {\r
+            lag=iLBCdec_inst->prevLag;\r
+            max_per=iLBCdec_inst->per;\r
+        }\r
+        \r
+        /* downscaling */\r
+\r
+        use_gain=1.0;\r
+        if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)\r
+            use_gain=(float)0.9;\r
+        else if (iLBCdec_inst->consPLICount*\r
+                        iLBCdec_inst->blockl>2*320)\r
+            use_gain=(float)0.7;\r
+        else if (iLBCdec_inst->consPLICount*\r
+                        iLBCdec_inst->blockl>3*320)\r
+            use_gain=(float)0.5;\r
+        else if (iLBCdec_inst->consPLICount*\r
+\r
+\r
+                        iLBCdec_inst->blockl>4*320)\r
+            use_gain=(float)0.0;\r
+\r
+        /* mix noise and pitch repeatition */\r
+        ftmp=(float)sqrt(max_per);\r
+        if (ftmp>(float)0.7)\r
+            pitchfact=(float)1.0;\r
+        else if (ftmp>(float)0.4)\r
+            pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);\r
+        else\r
+            pitchfact=0.0;\r
+\r
+\r
+        /* avoid repetition of same pitch cycle */\r
+        use_lag=lag;\r
+        if (lag<80) {\r
+            use_lag=2*lag;\r
+        }\r
+\r
+        /* compute concealed residual */\r
+\r
+        energy = 0.0;\r
+        for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+\r
+            /* noise component */\r
+\r
+            iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & \r
+                (0x80000000L-1);\r
+            randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;\r
+            pick = i - randlag;\r
+            \r
+            if (pick < 0) {\r
+                randvec[i] = \r
+                    iLBCdec_inst->prevResidual[\r
+                                iLBCdec_inst->blockl+pick];\r
+            } else {\r
+                randvec[i] =  randvec[pick];\r
+            }\r
+\r
+            /* pitch repeatition component */\r
+            pick = i - use_lag;\r
+            \r
+            if (pick < 0) {\r
+                PLCresidual[i] =  \r
+                    iLBCdec_inst->prevResidual[\r
+                                iLBCdec_inst->blockl+pick];\r
+            } else {\r
+                PLCresidual[i] = PLCresidual[pick];\r
+            }\r
+\r
+            /* mix random and periodicity component */\r
+\r
+            if (i<80)\r
+                PLCresidual[i] = use_gain*(pitchfact * \r
+\r
+\r
+                            PLCresidual[i] +\r
+                            ((float)1.0 - pitchfact) * randvec[i]);\r
+            else if (i<160)\r
+                PLCresidual[i] = (float)0.95*use_gain*(pitchfact * \r
+                            PLCresidual[i] +\r
+                            ((float)1.0 - pitchfact) * randvec[i]);\r
+            else\r
+                PLCresidual[i] = (float)0.9*use_gain*(pitchfact * \r
+                            PLCresidual[i] +\r
+                            ((float)1.0 - pitchfact) * randvec[i]);\r
+\r
+            energy += PLCresidual[i] * PLCresidual[i];\r
+        }\r
+        \r
+        /* less than 30 dB, use only noise */\r
+        \r
+        if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { \r
+            gain=0.0;\r
+            for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+                PLCresidual[i] = randvec[i];\r
+            }\r
+        }\r
+\r
+        /* use old LPC */\r
+\r
+        memcpy(PLClpc,iLBCdec_inst->prevLpc,\r
+            (LPC_FILTERORDER+1)*sizeof(float));\r
+        \r
+    }\r
+\r
+    /* no packet loss, copy input */\r
+\r
+    else {\r
+        memcpy(PLCresidual, decresidual, \r
+            iLBCdec_inst->blockl*sizeof(float));\r
+        memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));\r
+        iLBCdec_inst->consPLICount = 0;\r
+    }\r
+    \r
+    /* update state */\r
+\r
+    if (PLI) {\r
+        iLBCdec_inst->prevLag = lag;\r
+        iLBCdec_inst->per=max_per;\r
+    }\r
+\r
+    iLBCdec_inst->prevPLI = PLI;\r
+    memcpy(iLBCdec_inst->prevLpc, PLClpc, \r
+        (LPC_FILTERORDER+1)*sizeof(float));\r
+    memcpy(iLBCdec_inst->prevResidual, PLCresidual,\r
+        iLBCdec_inst->blockl*sizeof(float));\r
+}\r
+\r
+\r
+\r
+\r
diff --git a/libs/codec/ilbc/doCPLC.h b/libs/codec/ilbc/doCPLC.h
new file mode 100644 (file)
index 0000000..7783674
--- /dev/null
@@ -0,0 +1,32 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    doCPLC.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_DOLPC_H\r
+#define __iLBC_DOLPC_H\r
+\r
+void doThePLC(\r
+    float *PLCresidual, /* (o) concealed residual */ \r
+    float *PLClpc,      /* (o) concealed LP parameters */  \r
+    int PLI,        /* (i) packet loss indicator \r
+                               0 - no PL, 1 = PL */ \r
+    float *decresidual, /* (i) decoded residual */\r
+    float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+    int inlag,          /* (i) pitch lag */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst \r
+                        /* (i/o) decoder instance */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/enhancer.c b/libs/codec/ilbc/enhancer.c
new file mode 100644 (file)
index 0000000..4358113
--- /dev/null
@@ -0,0 +1,665 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    enhancer.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <string.h>\r
+#include "iLBC_define.h"\r
+#include "enhancer.h"\r
+#include "constants.h"\r
+#include "filter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+\r
+\r
+ * Find index in array such that the array element with said\r
+ * index is the element of said array closest to "value" \r
+ * according to the squared-error criterion\r
+ *---------------------------------------------------------------*/\r
+\r
+static void NearestNeighbor(\r
+    int   *index,   /* (o) index of array element closest \r
+                           to value */\r
+    float *array,   /* (i) data array */\r
+    float value,/* (i) value */\r
+    int arlength/* (i) dimension of data array */\r
+){\r
+    int i;\r
+    float bestcrit,crit;\r
+\r
+    crit=array[0]-value;\r
+    bestcrit=crit*crit;\r
+    *index=0;\r
+    for (i=1; i<arlength; i++) {\r
+        crit=array[i]-value;\r
+        crit=crit*crit;\r
+        \r
+        if (crit<bestcrit) {\r
+            bestcrit=crit;\r
+            *index=i;\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * compute cross correlation between sequences\r
+ *---------------------------------------------------------------*/\r
+\r
+static void mycorr1( \r
+    float* corr,    /* (o) correlation of seq1 and seq2 */\r
+    float* seq1,    /* (i) first sequence */\r
+    int dim1,           /* (i) dimension first seq1 */\r
+    const float *seq2,  /* (i) second sequence */\r
+    int dim2        /* (i) dimension seq2 */\r
+){\r
+    int i,j;\r
+\r
+    for (i=0; i<=dim1-dim2; i++) {\r
+        corr[i]=0.0;\r
+        for (j=0; j<dim2; j++) {\r
+            corr[i] += seq1[i+j] * seq2[j];\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * upsample finite array assuming zeros outside bounds\r
+ *---------------------------------------------------------------*/\r
+\r
+\r
+\r
+static void enh_upsample( \r
+    float* useq1,   /* (o) upsampled output sequence */\r
+    float* seq1,/* (i) unupsampled sequence */\r
+    int dim1,       /* (i) dimension seq1 */\r
+    int hfl         /* (i) polyphase filter length=2*hfl+1 */\r
+){\r
+    float *pu,*ps;\r
+    int i,j,k,q,filterlength,hfl2;\r
+    const float *polyp[ENH_UPS0]; /* pointers to \r
+                                     polyphase columns */\r
+    const float *pp;\r
+\r
+    /* define pointers for filter */\r
+\r
+    filterlength=2*hfl+1;\r
+    \r
+    if ( filterlength > dim1 ) {\r
+        hfl2=(int) (dim1/2);\r
+        for (j=0; j<ENH_UPS0; j++) {\r
+            polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;\r
+        }\r
+        hfl=hfl2;\r
+        filterlength=2*hfl+1;\r
+    }\r
+    else {\r
+        for (j=0; j<ENH_UPS0; j++) {\r
+            polyp[j]=polyphaserTbl+j*filterlength;\r
+        }\r
+    }\r
+\r
+    /* filtering: filter overhangs left side of sequence */\r
+\r
+    pu=useq1;\r
+    for (i=hfl; i<filterlength; i++) { \r
+        for (j=0; j<ENH_UPS0; j++) {\r
+            *pu=0.0;\r
+            pp = polyp[j];\r
+            ps = seq1+i;\r
+            for (k=0; k<=i; k++) {\r
+                *pu += *ps-- * *pp++;\r
+            }\r
+            pu++;\r
+        }\r
+    }\r
+\r
+    /* filtering: simple convolution=inner products */\r
+\r
+    for (i=filterlength; i<dim1; i++) {\r
+        for (j=0;j<ENH_UPS0; j++){\r
+            *pu=0.0;\r
+            pp = polyp[j];\r
+            ps = seq1+i;\r
+            for (k=0; k<filterlength; k++) {\r
+                *pu += *ps-- * *pp++;\r
+\r
+\r
+            }\r
+            pu++;\r
+        }\r
+    }\r
+\r
+    /* filtering: filter overhangs right side of sequence */\r
+\r
+    for (q=1; q<=hfl; q++) { \r
+        for (j=0; j<ENH_UPS0; j++) {\r
+            *pu=0.0;\r
+            pp = polyp[j]+q;\r
+            ps = seq1+dim1-1;\r
+            for (k=0; k<filterlength-q; k++) {\r
+                *pu += *ps-- * *pp++;\r
+            }\r
+            pu++;\r
+        }\r
+    }\r
+}\r
+\r
+\r
+/*----------------------------------------------------------------*\r
+ * find segment starting near idata+estSegPos that has highest \r
+ * correlation with idata+centerStartPos through \r
+ * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a \r
+ * resolution of ENH_UPSO times the original of the original \r
+ * sampling rate\r
+ *---------------------------------------------------------------*/\r
+\r
+static void refiner(\r
+    float *seg,         /* (o) segment array */\r
+    float *updStartPos, /* (o) updated start point */\r
+    float* idata,       /* (i) original data buffer */\r
+    int idatal,         /* (i) dimension of idata */\r
+    int centerStartPos, /* (i) beginning center segment */\r
+    float estSegPos,/* (i) estimated beginning other segment */\r
+    float period    /* (i) estimated pitch period */\r
+){\r
+    int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;\r
+    int tloc,tloc2,i,st,en,fraction;\r
+    float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;\r
+    float corrVecUps[ENH_CORRDIM*ENH_UPS0];\r
+\r
+    /* defining array bounds */\r
+    \r
+    estSegPosRounded=(int)(estSegPos - 0.5);\r
+\r
+    searchSegStartPos=estSegPosRounded-ENH_SLOP;\r
+    \r
+    if (searchSegStartPos<0) { \r
+        searchSegStartPos=0;\r
+    }\r
+    searchSegEndPos=estSegPosRounded+ENH_SLOP;\r
+    \r
+\r
+\r
+    if (searchSegEndPos+ENH_BLOCKL >= idatal) { \r
+        searchSegEndPos=idatal-ENH_BLOCKL-1;\r
+    }\r
+    corrdim=searchSegEndPos-searchSegStartPos+1;\r
+    \r
+    /* compute upsampled correlation (corr33) and find \r
+       location of max */\r
+\r
+    mycorr1(corrVec,idata+searchSegStartPos,\r
+        corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);\r
+    enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);\r
+    tloc=0; maxv=corrVecUps[0];\r
+    for (i=1; i<ENH_UPS0*corrdim; i++) {\r
+        \r
+        if (corrVecUps[i]>maxv) {\r
+            tloc=i;\r
+            maxv=corrVecUps[i];\r
+        }\r
+    }\r
+    \r
+    /* make vector can be upsampled without ever running outside \r
+       bounds */\r
+    \r
+    *updStartPos= (float)searchSegStartPos + \r
+        (float)tloc/(float)ENH_UPS0+(float)1.0;\r
+    tloc2=(int)(tloc/ENH_UPS0);\r
+    \r
+    if (tloc>tloc2*ENH_UPS0) {\r
+        tloc2++;\r
+    }\r
+    st=searchSegStartPos+tloc2-ENH_FL0;\r
+    \r
+    if (st<0) {\r
+        memset(vect,0,-st*sizeof(float));\r
+        memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));\r
+    }\r
+    else {\r
+        en=st+ENH_VECTL;\r
+        \r
+        if (en>idatal) {\r
+            memcpy(vect, &idata[st], \r
+                (ENH_VECTL-(en-idatal))*sizeof(float));\r
+            memset(&vect[ENH_VECTL-(en-idatal)], 0, \r
+                (en-idatal)*sizeof(float));\r
+        }\r
+        else {\r
+            memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));\r
+        }\r
+    }\r
+    fraction=tloc2*ENH_UPS0-tloc;\r
+    \r
+    /* compute the segment (this is actually a convolution) */\r
+\r
+    mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,\r
+\r
+\r
+        2*ENH_FL0+1);\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * find the smoothed output data\r
+ *---------------------------------------------------------------*/\r
+\r
+static void smath(\r
+    float *odata,   /* (o) smoothed output */\r
+    float *sseq,/* (i) said second sequence of waveforms */\r
+    int hl,         /* (i) 2*hl+1 is sseq dimension */\r
+    float alpha0/* (i) max smoothing energy fraction */\r
+){\r
+    int i,k;\r
+    float w00,w10,w11,A,B,C,*psseq,err,errs;\r
+    float surround[BLOCKL_MAX]; /* shape contributed by other than \r
+                                   current */\r
+    float wt[2*ENH_HL+1];       /* waveform weighting to get \r
+                                   surround shape */\r
+    float denom;\r
+    \r
+    /* create shape of contribution from all waveforms except the\r
+       current one */\r
+\r
+    for (i=1; i<=2*hl+1; i++) {\r
+        wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); \r
+    }\r
+    wt[hl]=0.0; /* for clarity, not used */\r
+    for (i=0; i<ENH_BLOCKL; i++) {\r
+        surround[i]=sseq[i]*wt[0];\r
+    }\r
+    for (k=1; k<hl; k++) {\r
+        psseq=sseq+k*ENH_BLOCKL;\r
+        for(i=0;i<ENH_BLOCKL; i++) {\r
+            surround[i]+=psseq[i]*wt[k];\r
+        }\r
+    }\r
+    for (k=hl+1; k<=2*hl; k++) {\r
+        psseq=sseq+k*ENH_BLOCKL;\r
+        for(i=0;i<ENH_BLOCKL; i++) {\r
+            surround[i]+=psseq[i]*wt[k];\r
+        }\r
+    }\r
+    \r
+    /* compute some inner products */\r
+\r
+    w00 = w10 = w11 = 0.0;\r
+    psseq=sseq+hl*ENH_BLOCKL; /* current block  */\r
+    for (i=0; i<ENH_BLOCKL;i++) {\r
+        w00+=psseq[i]*psseq[i];\r
+        w11+=surround[i]*surround[i];\r
+        w10+=surround[i]*psseq[i];\r
+    }\r
+    \r
+\r
+\r
+    if (fabs(w11) < 1.0) {\r
+        w11=1.0;\r
+    }\r
+    C = (float)sqrt( w00/w11);\r
+    \r
+    /* first try enhancement without power-constraint */\r
+\r
+    errs=0.0;\r
+    psseq=sseq+hl*ENH_BLOCKL;\r
+    for (i=0; i<ENH_BLOCKL; i++) {\r
+        odata[i]=C*surround[i];\r
+        err=psseq[i]-odata[i];\r
+        errs+=err*err;\r
+    }\r
+    \r
+    /* if constraint violated by first try, add constraint */ \r
+    \r
+    if (errs > alpha0 * w00) {\r
+        if ( w00 < 1) {\r
+            w00=1;\r
+        }\r
+        denom = (w11*w00-w10*w10)/(w00*w00);\r
+        \r
+        if (denom > 0.0001) { /* eliminates numerical problems \r
+                                 for if smooth */\r
+            A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);\r
+            B = -alpha0/2 - A * w10/w00;\r
+            B = B+1;\r
+        }\r
+        else { /* essentially no difference between cycles; \r
+                  smoothing not needed */\r
+            A= 0.0;\r
+            B= 1.0;\r
+        }\r
+        \r
+        /* create smoothed sequence */\r
+\r
+        psseq=sseq+hl*ENH_BLOCKL;\r
+        for (i=0; i<ENH_BLOCKL; i++) {\r
+            odata[i]=A*surround[i]+B*psseq[i];\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * get the pitch-synchronous sample sequence\r
+ *---------------------------------------------------------------*/\r
+\r
+static void getsseq(\r
+    float *sseq,    /* (o) the pitch-synchronous sequence */\r
+    float *idata,       /* (i) original data */\r
+    int idatal,         /* (i) dimension of data */\r
+    int centerStartPos, /* (i) where current block starts */\r
+    float *period,      /* (i) rough-pitch-period array */\r
+\r
+\r
+    float *plocs,       /* (i) where periods of period array \r
+                               are taken */\r
+    int periodl,    /* (i) dimension period array */\r
+    int hl              /* (i) 2*hl+1 is the number of sequences */\r
+){\r
+    int i,centerEndPos,q;\r
+    float blockStartPos[2*ENH_HL+1];\r
+    int lagBlock[2*ENH_HL+1];\r
+    float plocs2[ENH_PLOCSL]; \r
+    float *psseq;\r
+\r
+    centerEndPos=centerStartPos+ENH_BLOCKL-1;\r
+    \r
+    /* present */\r
+\r
+    NearestNeighbor(lagBlock+hl,plocs,\r
+        (float)0.5*(centerStartPos+centerEndPos),periodl);\r
+    \r
+    blockStartPos[hl]=(float)centerStartPos;\r
+    psseq=sseq+ENH_BLOCKL*hl;\r
+    memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));\r
+    \r
+    /* past */\r
+\r
+    for (q=hl-1; q>=0; q--) {\r
+        blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];\r
+        NearestNeighbor(lagBlock+q,plocs,\r
+            blockStartPos[q]+\r
+            ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);\r
+                            \r
+        \r
+        if (blockStartPos[q]-ENH_OVERHANG>=0) {\r
+            refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,\r
+                idatal, centerStartPos, blockStartPos[q],\r
+                period[lagBlock[q+1]]);\r
+        } else {\r
+            psseq=sseq+q*ENH_BLOCKL;\r
+            memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+        }\r
+    }\r
+    \r
+    /* future */\r
+\r
+    for (i=0; i<periodl; i++) {\r
+        plocs2[i]=plocs[i]-period[i];\r
+    }\r
+    for (q=hl+1; q<=2*hl; q++) { \r
+        NearestNeighbor(lagBlock+q,plocs2,\r
+            blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);\r
+\r
+        blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];\r
+        if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {\r
+            refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,\r
+                idatal, centerStartPos, blockStartPos[q],\r
+\r
+\r
+                period[lagBlock[q]]);\r
+        }\r
+        else {\r
+            psseq=sseq+q*ENH_BLOCKL;\r
+            memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * perform enhancement on idata+centerStartPos through \r
+ * idata+centerStartPos+ENH_BLOCKL-1\r
+ *---------------------------------------------------------------*/\r
+\r
+static void enhancer(\r
+    float *odata,       /* (o) smoothed block, dimension blockl */\r
+    float *idata,       /* (i) data buffer used for enhancing */\r
+    int idatal,         /* (i) dimension idata */\r
+    int centerStartPos, /* (i) first sample current block \r
+                               within idata */\r
+    float alpha0,       /* (i) max correction-energy-fraction \r
+                              (in [0,1]) */\r
+    float *period,      /* (i) pitch period array */\r
+    float *plocs,       /* (i) locations where period array \r
+                               values valid */\r
+    int periodl         /* (i) dimension of period and plocs */\r
+){\r
+    float sseq[(2*ENH_HL+1)*ENH_BLOCKL];\r
+\r
+    /* get said second sequence of segments */\r
+\r
+    getsseq(sseq,idata,idatal,centerStartPos,period,\r
+        plocs,periodl,ENH_HL);\r
+\r
+    /* compute the smoothed output from said second sequence */\r
+\r
+    smath(odata,sseq,ENH_HL,alpha0);\r
+\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * cross correlation\r
+ *---------------------------------------------------------------*/\r
+\r
+float xCorrCoef( \r
+    float *target,      /* (i) first array */\r
+    float *regressor,   /* (i) second array */\r
+    int subl        /* (i) dimension arrays */\r
+){\r
+    int i;\r
+    float ftmp1, ftmp2;\r
+        \r
+    ftmp1 = 0.0;\r
+    ftmp2 = 0.0;\r
+\r
+\r
+    for (i=0; i<subl; i++) {\r
+        ftmp1 += target[i]*regressor[i];\r
+        ftmp2 += regressor[i]*regressor[i]; \r
+    }\r
+    \r
+    if (ftmp1 > 0.0) {\r
+        return (float)(ftmp1*ftmp1/ftmp2);\r
+    }\r
+    else {\r
+        return (float)0.0;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * interface for enhancer\r
+ *---------------------------------------------------------------*/\r
+\r
+int enhancerInterface(\r
+    float *out,                     /* (o) enhanced signal */\r
+    float *in,                      /* (i) unenhanced signal */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst   /* (i) buffers etc */\r
+){\r
+    float *enh_buf, *enh_period;\r
+    int iblock, isample;\r
+    int lag=0, ilag, i, ioffset;\r
+    float cc, maxcc;\r
+    float ftmp1, ftmp2;\r
+    float *inPtr, *enh_bufPtr1, *enh_bufPtr2;\r
+    float plc_pred[ENH_BLOCKL];\r
+\r
+    float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];\r
+    int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;\r
+    int start, plc_blockl, inlag;\r
+\r
+    enh_buf=iLBCdec_inst->enh_buf;\r
+    enh_period=iLBCdec_inst->enh_period;\r
+    \r
+    memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], \r
+        (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));\r
+                                                            \r
+    memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, \r
+        iLBCdec_inst->blockl*sizeof(float));\r
+\r
+    if (iLBCdec_inst->mode==30)\r
+        plc_blockl=ENH_BLOCKL;\r
+    else\r
+        plc_blockl=40;\r
+\r
+    /* when 20 ms frame, move processing one block */\r
+    ioffset=0;\r
+    if (iLBCdec_inst->mode==20) ioffset=1;\r
+\r
+    i=3-ioffset;\r
+    memmove(enh_period, &enh_period[i], \r
+\r
+\r
+        (ENH_NBLOCKS_TOT-i)*sizeof(float));\r
+\r
+    /* Set state information to the 6 samples right before \r
+       the samples to be downsampled. */\r
+\r
+    memcpy(lpState, \r
+        enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, \r
+        6*sizeof(float));\r
+\r
+    /* Down sample a factor 2 to save computations */\r
+\r
+    DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,\r
+                lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,\r
+                lpState, downsampled);\r
+\r
+    /* Estimate the pitch in the down sampled domain. */\r
+    for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {\r
+        \r
+        lag = 10;\r
+        maxcc = xCorrCoef(downsampled+60+iblock*\r
+            ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+            ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);\r
+        for (ilag=11; ilag<60; ilag++) {\r
+            cc = xCorrCoef(downsampled+60+iblock*\r
+                ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+                ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);\r
+            \r
+            if (cc > maxcc) {\r
+                maxcc = cc;\r
+                lag = ilag;\r
+            }\r
+        }\r
+\r
+        /* Store the estimated lag in the non-downsampled domain */\r
+        enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;\r
+\r
+\r
+    }   \r
+\r
+\r
+    /* PLC was performed on the previous packet */\r
+    if (iLBCdec_inst->prev_enh_pl==1) {\r
+\r
+        inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];\r
+\r
+        lag = inlag-1;\r
+        maxcc = xCorrCoef(in, in+lag, plc_blockl);\r
+        for (ilag=inlag; ilag<=inlag+1; ilag++) {\r
+            cc = xCorrCoef(in, in+ilag, plc_blockl);\r
+            \r
+            if (cc > maxcc) {\r
+                maxcc = cc;\r
+                lag = ilag;\r
+            }\r
+        }\r
+\r
+\r
+\r
+        enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;\r
+\r
+        /* compute new concealed residual for the old lookahead,\r
+           mix the forward PLC with a backward PLC from \r
+           the new frame */\r
+        \r
+        inPtr=&in[lag-1];\r
+        \r
+        enh_bufPtr1=&plc_pred[plc_blockl-1];\r
+        \r
+        if (lag>plc_blockl) {\r
+            start=plc_blockl;\r
+        } else {\r
+            start=lag;\r
+        }\r
+\r
+        for (isample = start; isample>0; isample--) {\r
+            *enh_bufPtr1-- = *inPtr--;\r
+        }\r
+        \r
+        enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+        for (isample = (plc_blockl-1-lag); isample>=0; isample--) \r
+{\r
+            *enh_bufPtr1-- = *enh_bufPtr2--;\r
+        }\r
+\r
+        /* limit energy change */\r
+        ftmp2=0.0;\r
+        ftmp1=0.0;\r
+        for (i=0;i<plc_blockl;i++) {\r
+            ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*\r
+                enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];\r
+            ftmp1+=plc_pred[i]*plc_pred[i];\r
+        }\r
+        ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);\r
+        ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);\r
+        if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {\r
+            for (i=0;i<plc_blockl-10;i++) {\r
+                plc_pred[i]*=(float)2.0*ftmp2/ftmp1;\r
+            }\r
+            for (i=plc_blockl-10;i<plc_blockl;i++) {\r
+                plc_pred[i]*=(float)(i-plc_blockl+10)*\r
+                    ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+\r
+                    (float)2.0*ftmp2/ftmp1;\r
+            }\r
+        }\r
+    \r
+        enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+        for (i=0; i<plc_blockl; i++) {\r
+            ftmp1 = (float) (i+1) / (float) (plc_blockl+1);\r
+            *enh_bufPtr1 *= ftmp1;\r
+            *enh_bufPtr1 += ((float)1.0-ftmp1)*\r
+                                plc_pred[plc_blockl-1-i];\r
+            enh_bufPtr1--;\r
+        }\r
+\r
+\r
+    }\r
+\r
+    if (iLBCdec_inst->mode==20) {\r
+        /* Enhancer with 40 samples delay */\r
+        for (iblock = 0; iblock<2; iblock++) {\r
+            enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,\r
+                ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                    ENH_NBLOCKS_TOT);\r
+        }\r
+    } else if (iLBCdec_inst->mode==30) {\r
+        /* Enhancer with 80 samples delay */\r
+        for (iblock = 0; iblock<3; iblock++) {\r
+            enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                ENH_BUFL, (4+iblock)*ENH_BLOCKL,\r
+                ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                    ENH_NBLOCKS_TOT);\r
+        }\r
+    }\r
+\r
+    return (lag*2);\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/enhancer.h b/libs/codec/ilbc/enhancer.h
new file mode 100644 (file)
index 0000000..dab29ec
--- /dev/null
@@ -0,0 +1,33 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    enhancer.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __ENHANCER_H\r
+#define __ENHANCER_H\r
+\r
+#include "iLBC_define.h"\r
+\r
+float xCorrCoef( \r
+    float *target,      /* (i) first array */\r
+    float *regressor,   /* (i) second array */\r
+    int subl        /* (i) dimension arrays */\r
+);\r
+\r
+int enhancerInterface(\r
+    float *out,         /* (o) the enhanced recidual signal */\r
+    float *in,          /* (i) the recidual signal to enhance */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst \r
+                        /* (i/o) the decoder state structure */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/filter.c b/libs/codec/ilbc/filter.c
new file mode 100644 (file)
index 0000000..1215e31
--- /dev/null
@@ -0,0 +1,168 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    filter.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+\r
+\r
+#include "iLBC_define.h"\r
+#include "filter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  all-pole filter\r
+ *---------------------------------------------------------------*/\r
+\r
+void AllPoleFilter(\r
+    float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                           InOut[-1] contain the state of the \r
+                           filter (delayed samples). InOut[0] to \r
+                           InOut[lengthInOut-1] contain the filter\r
+                           input, on en exit InOut[-orderCoef] to\r
+                           InOut[-1] is unchanged and InOut[0] to\r
+                           InOut[lengthInOut-1] contain filtered \r
+                           samples */\r
+    float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                           to be 1.0 */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef   /* (i) number of filter coefficients */\r
+){  \r
+    int n,k;\r
+    \r
+    for(n=0;n<lengthInOut;n++){\r
+        for(k=1;k<=orderCoef;k++){\r
+            *InOut -= Coef[k]*InOut[-k];\r
+        }\r
+        InOut++;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  all-zero filter                         \r
+ *---------------------------------------------------------------*/\r
+\r
+void AllZeroFilter(\r
+    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                           filter input samples */\r
+    float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                           to be 1.0) */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef,  /* (i) number of filter coefficients */\r
+    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                           contain the filter state, on exit Out[0]\r
+                           to Out[lengthInOut-1] contain filtered\r
+                           samples */\r
+){  \r
+    int n,k;\r
+    \r
+    for(n=0;n<lengthInOut;n++){\r
+        *Out = Coef[0]*In[0];\r
+        for(k=1;k<=orderCoef;k++){\r
+            *Out += Coef[k]*In[-k];\r
+        }\r
+\r
+\r
+        Out++;\r
+        In++;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  pole-zero filter\r
+ *---------------------------------------------------------------*/\r
+\r
+void ZeroPoleFilter(\r
+    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                           filter input samples In[-orderCoef] to \r
+                           In[-1] contain state of all-zero \r
+                           section */\r
+    float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                           section (ZeroCoef[0] is assumed to \r
+                           be 1.0) */\r
+    float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                           (ZeroCoef[0] is assumed to be 1.0) */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef,  /* (i) number of filter coefficients */\r
+    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                           contain state of all-pole section. On \r
+                           exit Out[0] to Out[lengthInOut-1] \r
+                           contain filtered samples */\r
+){\r
+    AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);\r
+    AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ * downsample (LP filter and decimation)\r
+ *---------------------------------------------------------------*/\r
+\r
+void DownSample (\r
+    float  *In,     /* (i) input samples */\r
+    float  *Coef,   /* (i) filter coefficients */\r
+    int lengthIn,   /* (i) number of input samples */ \r
+    float  *state,  /* (i) filter state */\r
+    float  *Out     /* (o) downsampled output */\r
+){\r
+    float   o;\r
+    float *Out_ptr = Out;\r
+    float *Coef_ptr, *In_ptr;\r
+    float *state_ptr;\r
+    int i, j, stop;\r
+\r
+    /* LP filter and decimate at the same time */\r
+\r
+    for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)\r
+    {\r
+        Coef_ptr = &Coef[0];\r
+        In_ptr = &In[i];\r
+        state_ptr = &state[FILTERORDER_DS-2];\r
+\r
+\r
+\r
+        o = (float)0.0;\r
+        \r
+        stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;\r
+\r
+        for (j = 0; j < stop; j++) \r
+        {\r
+            o += *Coef_ptr++ * (*In_ptr--);\r
+        }\r
+        for (j = i + 1; j < FILTERORDER_DS; j++) \r
+        {\r
+            o += *Coef_ptr++ * (*state_ptr--);\r
+        }\r
+\r
+        *Out_ptr++ = o;\r
+    }\r
+\r
+    /* Get the last part (use zeros as input for the future) */\r
+\r
+    for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS); \r
+            i+=FACTOR_DS) {\r
+\r
+        o=(float)0.0;\r
+        \r
+        if (i<lengthIn) {\r
+            Coef_ptr = &Coef[0];\r
+            In_ptr = &In[i];\r
+            for (j=0; j<FILTERORDER_DS; j++) {\r
+                    o += *Coef_ptr++ * (*Out_ptr--);\r
+            }\r
+        } else {\r
+            Coef_ptr = &Coef[i-lengthIn];\r
+            In_ptr = &In[lengthIn-1];\r
+            for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {\r
+                    o += *Coef_ptr++ * (*In_ptr--);\r
+            }\r
+        }\r
+        *Out_ptr++ = o;\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/filter.h b/libs/codec/ilbc/filter.h
new file mode 100644 (file)
index 0000000..bdfdff2
--- /dev/null
@@ -0,0 +1,73 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    filter.h\r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_FILTER_H\r
+#define __iLBC_FILTER_H\r
+\r
+void AllPoleFilter(\r
+    float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                           InOut[-1] contain the state of the \r
+                           filter (delayed samples). InOut[0] to \r
+                           InOut[lengthInOut-1] contain the filter \r
+                           input, on en exit InOut[-orderCoef] to \r
+                           InOut[-1] is unchanged and InOut[0] to \r
+                           InOut[lengthInOut-1] contain filtered \r
+                           samples */\r
+    float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                           to be 1.0 */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef   /* (i) number of filter coefficients */\r
+);\r
+\r
+\r
+\r
+void AllZeroFilter(\r
+    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                           filter input samples */\r
+    float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                           to be 1.0) */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef,  /* (i) number of filter coefficients */\r
+    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                           contain the filter state, on exit Out[0] \r
+                           to Out[lengthInOut-1] contain filtered \r
+                           samples */\r
+);\r
+\r
+void ZeroPoleFilter(\r
+    float *In,      /* (i) In[0] to In[lengthInOut-1] contain filter\r
+                           input samples In[-orderCoef] to In[-1] \r
+                           contain state of all-zero section */\r
+    float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                           section (ZeroCoef[0] is assumed to \r
+                           be 1.0) */\r
+    float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                           (ZeroCoef[0] is assumed to be 1.0) */\r
+    int lengthInOut,/* (i) number of input/output samples */\r
+    int orderCoef,  /* (i) number of filter coefficients */\r
+    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                           contain state of all-pole section. On\r
+                           exit Out[0] to Out[lengthInOut-1] \r
+                           contain filtered samples */\r
+);\r
+\r
+void DownSample (\r
+    float  *In,     /* (i) input samples */\r
+    float  *Coef,   /* (i) filter coefficients */\r
+    int lengthIn,   /* (i) number of input samples */ \r
+    float  *state,  /* (i) filter state */\r
+    float  *Out     /* (o) downsampled output */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/gainquant.c b/libs/codec/ilbc/gainquant.c
new file mode 100644 (file)
index 0000000..9115a80
--- /dev/null
@@ -0,0 +1,107 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    gainquant.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+\r
+\r
+******************************************************************/\r
+\r
+#include <string.h>\r
+#include <math.h>\r
+#include "constants.h"\r
+#include "gainquant.h"\r
+#include "filter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  quantizer for the gain in the gain-shape coding of residual\r
+ *---------------------------------------------------------------*/\r
+\r
+float gainquant(/* (o) quantized gain value */\r
+    float in,       /* (i) gain value */\r
+    float maxIn,/* (i) maximum of gain value */\r
+    int cblen,      /* (i) number of quantization indices */\r
+    int *index      /* (o) quantization index */\r
+){\r
+    int i, tindex;\r
+    float minmeasure,measure, *cb, scale;\r
+\r
+    /* ensure a lower bound on the scaling factor */\r
+\r
+    scale=maxIn;\r
+    \r
+    if (scale<0.1) {\r
+        scale=(float)0.1;\r
+    }\r
+\r
+    /* select the quantization table */\r
+    \r
+    if (cblen == 8) {\r
+        cb = gain_sq3Tbl;\r
+    } else if (cblen == 16) {\r
+        cb = gain_sq4Tbl;\r
+    } else  {\r
+        cb = gain_sq5Tbl;\r
+    }\r
+\r
+    /* select the best index in the quantization table */\r
+    \r
+    minmeasure=10000000.0;\r
+    tindex=0;\r
+    for (i=0; i<cblen; i++) {\r
+        measure=(in-scale*cb[i])*(in-scale*cb[i]);\r
+        \r
+        if (measure<minmeasure) {\r
+            tindex=i;\r
+            minmeasure=measure;\r
+        }\r
+    }\r
+    *index=tindex;\r
+       \r
+    /* return the quantized value */\r
+    \r
+\r
+\r
+    return scale*cb[tindex];\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  decoder for quantized gains in the gain-shape coding of \r
+ *  residual                          \r
+ *---------------------------------------------------------------*/\r
+\r
+float gaindequant(  /* (o) quantized gain value */\r
+    int index,      /* (i) quantization index */\r
+    float maxIn,/* (i) maximum of unquantized gain */\r
+    int cblen       /* (i) number of quantization indices */\r
+){\r
+    float scale;\r
+\r
+    /* obtain correct scale factor */\r
+\r
+    scale=(float)fabs(maxIn);\r
+    \r
+    if (scale<0.1) {\r
+        scale=(float)0.1;\r
+    }\r
+\r
+    /* select the quantization table and return the decoded value */\r
+\r
+    if (cblen==8) {\r
+        return scale*gain_sq3Tbl[index];\r
+    } else if (cblen==16) {\r
+        return scale*gain_sq4Tbl[index];\r
+    }\r
+    else if (cblen==32) {\r
+        return scale*gain_sq5Tbl[index];\r
+    }\r
+\r
+    return 0.0;\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/gainquant.h b/libs/codec/ilbc/gainquant.h
new file mode 100644 (file)
index 0000000..be81799
--- /dev/null
@@ -0,0 +1,31 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    gainquant.h                                         \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_GAINQUANT_H\r
+#define __iLBC_GAINQUANT_H\r
+\r
+float gainquant(/* (o) quantized gain value */\r
+    float in,       /* (i) gain value */\r
+    float maxIn,/* (i) maximum of gain value */\r
+    int cblen,      /* (i) number of quantization indices */\r
+    int *index      /* (o) quantization index */\r
+);\r
+\r
+float gaindequant(  /* (o) quantized gain value */\r
+    int index,      /* (i) quantization index */\r
+    float maxIn,/* (i) maximum of unquantized gain */\r
+    int cblen       /* (i) number of quantization indices */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/getCBvec.c b/libs/codec/ilbc/getCBvec.c
new file mode 100644 (file)
index 0000000..311568c
--- /dev/null
@@ -0,0 +1,181 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    getCBvec.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "iLBC_define.h"\r
+#include "getCBvec.h"\r
+#include "constants.h"\r
+#include <string.h>\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Construct codebook vector for given index.\r
+ *---------------------------------------------------------------*/\r
+\r
+void getCBvec(\r
+    float *cbvec,   /* (o) Constructed codebook vector */\r
+    float *mem,     /* (i) Codebook buffer */\r
+    int index,      /* (i) Codebook index */\r
+    int lMem,       /* (i) Length of codebook buffer */\r
+    int cbveclen/* (i) Codebook vector length */\r
+){\r
+    int j, k, n, memInd, sFilt;\r
+    float tmpbuf[CB_MEML];\r
+    int base_size;\r
+    int ilow, ihigh;\r
+    float alfa, alfa1;\r
+\r
+    /* Determine size of codebook sections */\r
+\r
+    base_size=lMem-cbveclen+1;\r
+    \r
+    if (cbveclen==SUBL) {\r
+        base_size+=cbveclen/2;\r
+    }\r
+\r
+    /* No filter -> First codebook section */\r
+\r
+\r
+    \r
+    if (index<lMem-cbveclen+1) {\r
+\r
+        /* first non-interpolated vectors */\r
+\r
+        k=index+cbveclen;\r
+        /* get vector */\r
+        memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));\r
+\r
+    } else if (index < base_size) {\r
+\r
+        k=2*(index-(lMem-cbveclen+1))+cbveclen;\r
+    \r
+        ihigh=k/2;\r
+        ilow=ihigh-5;\r
+\r
+        /* Copy first noninterpolated part */\r
+\r
+        memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));\r
+\r
+        /* interpolation */\r
+\r
+        alfa1=(float)0.2;\r
+        alfa=0.0;\r
+        for (j=ilow; j<ihigh; j++) {\r
+            cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+\r
+                alfa*mem[lMem-k+j];\r
+            alfa+=alfa1;\r
+        }\r
+\r
+        /* Copy second noninterpolated part */\r
+\r
+        memcpy(cbvec+ihigh, mem+lMem-k+ihigh, \r
+            (cbveclen-ihigh)*sizeof(float));\r
+\r
+    }\r
+\r
+    /* Higher codebbok section based on filtering */\r
+\r
+    else {\r
+\r
+        /* first non-interpolated vectors */\r
+\r
+        if (index-base_size<lMem-cbveclen+1) {\r
+            float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+            float *pos;\r
+            float *pp, *pp1;\r
+\r
+            memset(tempbuff2, 0,\r
+                CB_HALFFILTERLEN*sizeof(float));\r
+            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                lMem*sizeof(float));\r
+            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                (CB_HALFFILTERLEN+1)*sizeof(float));\r
+\r
+\r
+\r
+            k=index-base_size+cbveclen;\r
+            sFilt=lMem-k;\r
+            memInd=sFilt+1-CB_HALFFILTERLEN;\r
+\r
+            /* do filtering */\r
+            pos=cbvec;\r
+            memset(pos, 0, cbveclen*sizeof(float));\r
+            for (n=0; n<cbveclen; n++) {\r
+                pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];\r
+                pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                for (j=0; j<CB_FILTERLEN; j++) {\r
+                    (*pos)+=(*pp++)*(*pp1--);\r
+                }\r
+                pos++;\r
+            }\r
+        }\r
+\r
+        /* interpolated vectors */\r
+\r
+        else {\r
+            float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+\r
+            float *pos;\r
+            float *pp, *pp1;\r
+            int i;\r
+\r
+            memset(tempbuff2, 0,\r
+                CB_HALFFILTERLEN*sizeof(float));\r
+            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                lMem*sizeof(float));\r
+            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                (CB_HALFFILTERLEN+1)*sizeof(float));\r
+\r
+            k=2*(index-base_size-\r
+                (lMem-cbveclen+1))+cbveclen;\r
+            sFilt=lMem-k;\r
+            memInd=sFilt+1-CB_HALFFILTERLEN;\r
+\r
+            /* do filtering */\r
+            pos=&tmpbuf[sFilt];\r
+            memset(pos, 0, k*sizeof(float));\r
+            for (i=0; i<k; i++) {\r
+                pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];\r
+                pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                for (j=0; j<CB_FILTERLEN; j++) {\r
+                    (*pos)+=(*pp++)*(*pp1--);\r
+                }\r
+                pos++;\r
+            }\r
+\r
+            ihigh=k/2;\r
+            ilow=ihigh-5;\r
+\r
+\r
+\r
+            /* Copy first noninterpolated part */\r
+\r
+            memcpy(cbvec, tmpbuf+lMem-k/2, \r
+                ilow*sizeof(float));\r
+\r
+            /* interpolation */\r
+\r
+            alfa1=(float)0.2;\r
+            alfa=0.0;\r
+            for (j=ilow; j<ihigh; j++) {\r
+                cbvec[j]=((float)1.0-alfa)*\r
+                    tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];\r
+                alfa+=alfa1;\r
+            }\r
+\r
+            /* Copy second noninterpolated part */\r
+\r
+            memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, \r
+                (cbveclen-ihigh)*sizeof(float));\r
+        }\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/getCBvec.h b/libs/codec/ilbc/getCBvec.h
new file mode 100644 (file)
index 0000000..d4e9311
--- /dev/null
@@ -0,0 +1,28 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    getCBvec.h                 \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_GETCBVEC_H\r
+#define __iLBC_GETCBVEC_H\r
+\r
+\r
+\r
+void getCBvec(\r
+    float *cbvec,   /* (o) Constructed codebook vector */\r
+    float *mem,     /* (i) Codebook buffer */\r
+    int index,      /* (i) Codebook index */\r
+    int lMem,       /* (i) Length of codebook buffer */\r
+    int cbveclen/* (i) Codebook vector length */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/helpfun.c b/libs/codec/ilbc/helpfun.c
new file mode 100644 (file)
index 0000000..899291d
--- /dev/null
@@ -0,0 +1,308 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    helpfun.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "helpfun.h"\r
+#include "constants.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  calculation of auto correlation \r
+ *---------------------------------------------------------------*/\r
+\r
+void autocorr( \r
+    float *r,       /* (o) autocorrelation vector */\r
+    const float *x, /* (i) data vector */\r
+    int N,          /* (i) length of data vector */\r
+    int order       /* largest lag for calculated \r
+                       autocorrelations */\r
+){\r
+    int     lag, n;\r
+    float   sum;\r
+    \r
+    for (lag = 0; lag <= order; lag++) {\r
+        sum = 0;\r
+        for (n = 0; n < N - lag; n++) {\r
+            sum += x[n] * x[n+lag];\r
+        }\r
+        r[lag] = sum;\r
+    }\r
+}\r
+\r
+\r
+\r
+/*----------------------------------------------------------------*\r
+ *  window multiplication  \r
+ *---------------------------------------------------------------*/\r
+\r
+void window( \r
+    float *z,       /* (o) the windowed data */\r
+    const float *x, /* (i) the original data vector */\r
+    const float *y, /* (i) the window */\r
+    int N           /* (i) length of all vectors */\r
+){\r
+    int     i;\r
+    \r
+    for (i = 0; i < N; i++) {\r
+        z[i] = x[i] * y[i];\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  levinson-durbin solution for lpc coefficients\r
+ *---------------------------------------------------------------*/\r
+\r
+void levdurb( \r
+    float *a,       /* (o) lpc coefficient vector starting \r
+                           with 1.0 */\r
+    float *k,       /* (o) reflection coefficients */\r
+    float *r,       /* (i) autocorrelation vector */\r
+    int order       /* (i) order of lpc filter */\r
+){\r
+    float  sum, alpha;\r
+    int     m, m_h, i;\r
+\r
+    a[0] = 1.0;\r
+    \r
+    if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */\r
+        for (i = 0; i < order; i++) {\r
+            k[i] = 0;\r
+            a[i+1] = 0;\r
+        }   \r
+    } else {\r
+        a[1] = k[0] = -r[1]/r[0];\r
+        alpha = r[0] + r[1] * k[0];\r
+        for (m = 1; m < order; m++){\r
+            sum = r[m + 1];\r
+            for (i = 0; i < m; i++){\r
+                sum += a[i+1] * r[m - i];\r
+            }\r
+            k[m] = -sum / alpha;\r
+            alpha += k[m] * sum;\r
+            m_h = (m + 1) >> 1;\r
+            for (i = 0; i < m_h; i++){\r
+                sum = a[i+1] + k[m] * a[m - i];\r
+                a[m - i] += k[m] * a[i+1];\r
+                a[i+1] = sum;\r
+\r
+\r
+            }\r
+            a[m+1] = k[m];\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  interpolation between vectors \r
+ *---------------------------------------------------------------*/\r
+\r
+void interpolate( \r
+    float *out,      /* (o) the interpolated vector */\r
+    float *in1,     /* (i) the first vector for the \r
+                           interpolation */\r
+    float *in2,     /* (i) the second vector for the \r
+                           interpolation */\r
+    float coef,      /* (i) interpolation weights */\r
+    int length      /* (i) length of all vectors */\r
+){\r
+    int i;\r
+    float invcoef;\r
+\r
+    invcoef = (float)1.0 - coef;\r
+    for (i = 0; i < length; i++) {\r
+        out[i] = coef * in1[i] + invcoef * in2[i];\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  lpc bandwidth expansion                   \r
+ *---------------------------------------------------------------*/\r
+\r
+void bwexpand( \r
+    float *out,      /* (o) the bandwidth expanded lpc \r
+                           coefficients */\r
+    float *in,      /* (i) the lpc coefficients before bandwidth \r
+                           expansion */\r
+    float coef,     /* (i) the bandwidth expansion factor */\r
+    int length      /* (i) the length of lpc coefficient vectors */\r
+){\r
+    int i;\r
+    float  chirp;\r
+    \r
+    chirp = coef;\r
+    \r
+    out[0] = in[0];\r
+    for (i = 1; i < length; i++) {\r
+        out[i] = chirp * in[i];\r
+        chirp *= coef;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  vector quantization \r
+\r
+\r
+ *---------------------------------------------------------------*/\r
+\r
+void vq( \r
+    float *Xq,      /* (o) the quantized vector */\r
+    int *index,     /* (o) the quantization index */\r
+    const float *CB,/* (i) the vector quantization codebook */\r
+    float *X,       /* (i) the vector to quantize */\r
+    int n_cb,       /* (i) the number of vectors in the codebook */\r
+    int dim         /* (i) the dimension of all vectors */\r
+){\r
+    int     i, j;\r
+    int     pos, minindex;\r
+    float   dist, tmp, mindist;\r
+\r
+    pos = 0;\r
+    mindist = FLOAT_MAX;\r
+    minindex = 0;\r
+    for (j = 0; j < n_cb; j++) {\r
+        dist = X[0] - CB[pos];\r
+        dist *= dist;\r
+        for (i = 1; i < dim; i++) {\r
+            tmp = X[i] - CB[pos + i];\r
+            dist += tmp*tmp;\r
+        }\r
+        \r
+        if (dist < mindist) {\r
+            mindist = dist;\r
+            minindex = j;\r
+        }\r
+        pos += dim;\r
+    }\r
+    for (i = 0; i < dim; i++) {\r
+        Xq[i] = CB[minindex*dim + i];\r
+    }\r
+    *index = minindex;\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  split vector quantization \r
+ *---------------------------------------------------------------*/\r
+\r
+void SplitVQ( \r
+    float *qX,      /* (o) the quantized vector */\r
+    int *index,     /* (o) a vector of indexes for all vector\r
+                           codebooks in the split */\r
+    float *X,       /* (i) the vector to quantize */\r
+    const float *CB,/* (i) the quantizer codebook */\r
+    int nsplit,     /* the number of vector splits */\r
+    const int *dim, /* the dimension of X and qX */\r
+    const int *cbsize /* the number of vectors in the codebook */\r
+){\r
+    int    cb_pos, X_pos, i;\r
+    \r
+    cb_pos = 0;\r
+\r
+\r
+    X_pos= 0;\r
+    for (i = 0; i < nsplit; i++) {\r
+        vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, \r
+            cbsize[i], dim[i]);\r
+        X_pos += dim[i];\r
+        cb_pos += dim[i] * cbsize[i];\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  scalar quantization \r
+ *---------------------------------------------------------------*/\r
+\r
+void sort_sq( \r
+    float *xq,      /* (o) the quantized value */\r
+    int *index,     /* (o) the quantization index */\r
+    float x,    /* (i) the value to quantize */\r
+    const float *cb,/* (i) the quantization codebook */\r
+    int cb_size      /* (i) the size of the quantization codebook */\r
+){\r
+    int i;\r
+    \r
+    if (x <= cb[0]) {\r
+        *index = 0;\r
+        *xq = cb[0];\r
+    } else {\r
+        i = 0;\r
+        while ((x > cb[i]) && i < cb_size - 1) {\r
+            i++;\r
+        }\r
+        \r
+        if (x > ((cb[i] + cb[i - 1])/2)) {\r
+            *index = i;\r
+            *xq = cb[i];\r
+        } else {\r
+            *index = i - 1;\r
+            *xq = cb[i - 1];\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  check for stability of lsf coefficients\r
+ *---------------------------------------------------------------*/\r
+\r
+int LSF_check(    /* (o) 1 for stable lsf vectors and 0 for\r
+                           nonstable ones */\r
+    float *lsf,     /* (i) a table of lsf vectors */\r
+    int dim,    /* (i) the dimension of each lsf vector */\r
+    int NoAn    /* (i) the number of lsf vectors in the \r
+                           table */\r
+){\r
+    int k,n,m, Nit=2, change=0,pos;\r
+    float tmp;\r
+\r
+\r
+    static float eps=(float)0.039; /* 50 Hz */\r
+    static float eps2=(float)0.0195;\r
+    static float maxlsf=(float)3.14; /* 4000 Hz */\r
+    static float minlsf=(float)0.01; /* 0 Hz */\r
+    \r
+    /* LSF separation check*/\r
+\r
+    for (n=0; n<Nit; n++) { /* Run through a couple of times */\r
+        for (m=0; m<NoAn; m++) { /* Number of analyses per frame */\r
+            for (k=0; k<(dim-1); k++) {\r
+                pos=m*dim+k;\r
+                \r
+                if ((lsf[pos+1]-lsf[pos])<eps) {\r
+                    \r
+                    if (lsf[pos+1]<lsf[pos]) {\r
+                        tmp=lsf[pos+1];\r
+                        lsf[pos+1]= lsf[pos]+eps2;\r
+                        lsf[pos]= lsf[pos+1]-eps2;\r
+                    } else {\r
+                        lsf[pos]-=eps2;\r
+                        lsf[pos+1]+=eps2;\r
+                    }\r
+                    change=1;\r
+                }\r
+                \r
+                if (lsf[pos]<minlsf) { \r
+                    lsf[pos]=minlsf;\r
+                    change=1;\r
+                }\r
+                \r
+                if (lsf[pos]>maxlsf) { \r
+                    lsf[pos]=maxlsf;\r
+                    change=1;\r
+                }               \r
+            }\r
+        }\r
+    }\r
+    \r
+    return change;  \r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/helpfun.h b/libs/codec/ilbc/helpfun.h
new file mode 100644 (file)
index 0000000..e2bc4b1
--- /dev/null
@@ -0,0 +1,101 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    helpfun.h         \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_HELPFUN_H\r
+#define __iLBC_HELPFUN_H\r
+\r
+void autocorr( \r
+    float *r,       /* (o) autocorrelation vector */\r
+    const float *x, /* (i) data vector */\r
+    int N,          /* (i) length of data vector */\r
+    int order       /* largest lag for calculated \r
+                       autocorrelations */\r
+);\r
+\r
+void window( \r
+    float *z,       /* (o) the windowed data */\r
+    const float *x, /* (i) the original data vector */\r
+    const float *y, /* (i) the window */\r
+    int N           /* (i) length of all vectors */\r
+);\r
+\r
+\r
+\r
+void levdurb( \r
+    float *a,       /* (o) lpc coefficient vector starting \r
+                           with 1.0 */\r
+    float *k,       /* (o) reflection coefficients */\r
+    float *r,       /* (i) autocorrelation vector */\r
+    int order       /* (i) order of lpc filter */\r
+);\r
+\r
+void interpolate( \r
+    float *out,     /* (o) the interpolated vector */\r
+    float *in1,     /* (i) the first vector for the \r
+                           interpolation */\r
+    float *in2,     /* (i) the second vector for the \r
+                           interpolation */\r
+    float coef,     /* (i) interpolation weights */\r
+    int length      /* (i) length of all vectors */\r
+);\r
+           \r
+void bwexpand( \r
+    float *out,     /* (o) the bandwidth expanded lpc \r
+                           coefficients */\r
+    float *in,      /* (i) the lpc coefficients before bandwidth\r
+                           expansion */\r
+    float coef,     /* (i) the bandwidth expansion factor */\r
+    int length      /* (i) the length of lpc coefficient vectors */\r
+);\r
+\r
+void vq( \r
+    float *Xq,      /* (o) the quantized vector */\r
+    int *index,     /* (o) the quantization index */\r
+    const float *CB,/* (i) the vector quantization codebook */\r
+    float *X,       /* (i) the vector to quantize */\r
+    int n_cb,       /* (i) the number of vectors in the codebook */\r
+    int dim         /* (i) the dimension of all vectors */\r
+);  \r
+\r
+void SplitVQ( \r
+    float *qX,      /* (o) the quantized vector */\r
+    int *index,     /* (o) a vector of indexes for all vector\r
+                           codebooks in the split */\r
+    float *X,       /* (i) the vector to quantize */\r
+    const float *CB,/* (i) the quantizer codebook */\r
+    int nsplit,     /* the number of vector splits */\r
+    const int *dim, /* the dimension of X and qX */\r
+    const int *cbsize /* the number of vectors in the codebook */\r
+);\r
+\r
+\r
+void sort_sq( \r
+    float *xq,      /* (o) the quantized value */\r
+    int *index,     /* (o) the quantization index */\r
+    float x,    /* (i) the value to quantize */\r
+    const float *cb,/* (i) the quantization codebook */\r
+\r
+\r
+    int cb_size     /* (i) the size of the quantization codebook */\r
+);\r
+\r
+int LSF_check(      /* (o) 1 for stable lsf vectors and 0 for \r
+                           nonstable ones */\r
+    float *lsf,     /* (i) a table of lsf vectors */\r
+    int dim,    /* (i) the dimension of each lsf vector */\r
+    int NoAn    /* (i) the number of lsf vectors in the \r
+                           table */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/hpInput.c b/libs/codec/ilbc/hpInput.c
new file mode 100644 (file)
index 0000000..54d997e
--- /dev/null
@@ -0,0 +1,60 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    hpInput.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "constants.h"\r
+#include "hpInput.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Input high-pass filter                          \r
+ *---------------------------------------------------------------*/\r
+\r
+void hpInput( \r
+    float *In,  /* (i) vector to filter */\r
+    int len,    /* (i) length of vector to filter */\r
+    float *Out, /* (o) the resulting filtered vector */\r
+    float *mem  /* (i/o) the filter state */\r
+){\r
+    int i;\r
+    float *pi, *po;\r
+\r
+    /* all-zero section*/\r
+\r
+    pi = &In[0];\r
+    po = &Out[0];\r
+    for (i=0; i<len; i++) {\r
+        *po = hpi_zero_coefsTbl[0] * (*pi);\r
+        *po += hpi_zero_coefsTbl[1] * mem[0];\r
+        *po += hpi_zero_coefsTbl[2] * mem[1];\r
+\r
+        mem[1] = mem[0];\r
+        mem[0] = *pi;\r
+        po++;\r
+\r
+\r
+        pi++;\r
+\r
+    }\r
+\r
+    /* all-pole section*/\r
+\r
+    po = &Out[0];\r
+    for (i=0; i<len; i++) {\r
+        *po -= hpi_pole_coefsTbl[1] * mem[2];\r
+        *po -= hpi_pole_coefsTbl[2] * mem[3];\r
+\r
+        mem[3] = mem[2];\r
+        mem[2] = *po;\r
+        po++;\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/hpInput.h b/libs/codec/ilbc/hpInput.h
new file mode 100644 (file)
index 0000000..bd04762
--- /dev/null
@@ -0,0 +1,27 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    hpInput.h        \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+\r
+\r
+#ifndef __iLBC_HPINPUT_H\r
+#define __iLBC_HPINPUT_H\r
+\r
+void hpInput( \r
+    float *In,  /* (i) vector to filter */\r
+    int len,    /* (i) length of vector to filter */\r
+    float *Out, /* (o) the resulting filtered vector */\r
+    float *mem  /* (i/o) the filter state */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/hpOutput.c b/libs/codec/ilbc/hpOutput.c
new file mode 100644 (file)
index 0000000..d85444d
--- /dev/null
@@ -0,0 +1,59 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    hpOutput.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+\r
+\r
+******************************************************************/\r
+\r
+#include "constants.h"\r
+#include "hpOutput.h"\r
+/*----------------------------------------------------------------*\r
+ *  Output high-pass filter                          \r
+ *---------------------------------------------------------------*/\r
+\r
+void hpOutput(\r
+    float *In,  /* (i) vector to filter */\r
+    int len,/* (i) length of vector to filter */\r
+    float *Out, /* (o) the resulting filtered vector */\r
+    float *mem  /* (i/o) the filter state */\r
+){\r
+    int i;\r
+    float *pi, *po;\r
+\r
+    /* all-zero section*/\r
+\r
+    pi = &In[0];\r
+    po = &Out[0];\r
+    for (i=0; i<len; i++) {\r
+        *po = hpo_zero_coefsTbl[0] * (*pi);\r
+        *po += hpo_zero_coefsTbl[1] * mem[0];\r
+        *po += hpo_zero_coefsTbl[2] * mem[1];\r
+\r
+        mem[1] = mem[0];\r
+        mem[0] = *pi;\r
+        po++;\r
+        pi++;\r
+\r
+    }\r
+\r
+    /* all-pole section*/\r
+\r
+    po = &Out[0];\r
+    for (i=0; i<len; i++) {\r
+        *po -= hpo_pole_coefsTbl[1] * mem[2];\r
+        *po -= hpo_pole_coefsTbl[2] * mem[3];\r
+\r
+        mem[3] = mem[2];\r
+        mem[2] = *po;\r
+        po++;\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/hpOutput.h b/libs/codec/ilbc/hpOutput.h
new file mode 100644 (file)
index 0000000..50c4914
--- /dev/null
@@ -0,0 +1,25 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    hpOutput.h       \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_HPOUTPUT_H\r
+#define __iLBC_HPOUTPUT_H\r
+\r
+void hpOutput(\r
+    float *In,  /* (i) vector to filter */\r
+    int len,/* (i) length of vector to filter */\r
+    float *Out, /* (o) the resulting filtered vector */\r
+    float *mem  /* (i/o) the filter state */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/iCBConstruct.c b/libs/codec/ilbc/iCBConstruct.c
new file mode 100644 (file)
index 0000000..2d934b0
--- /dev/null
@@ -0,0 +1,108 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iCBConstruct.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "iCBConstruct.h"\r
+#include "gainquant.h"\r
+#include "getCBvec.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Convert the codebook indexes to make the search easier\r
+ *---------------------------------------------------------------*/\r
+\r
+\r
+\r
+void index_conv_enc(\r
+    int *index          /* (i/o) Codebook indexes */\r
+){\r
+    int k;\r
+\r
+    for (k=1; k<CB_NSTAGES; k++) {\r
+        \r
+        if ((index[k]>=108)&&(index[k]<172)) {\r
+            index[k]-=64;\r
+        } else if (index[k]>=236) {\r
+            index[k]-=128;\r
+        } else {\r
+            /* ERROR */\r
+        }\r
+    }\r
+}\r
+\r
+void index_conv_dec(\r
+    int *index          /* (i/o) Codebook indexes */\r
+){\r
+    int k;\r
+\r
+    for (k=1; k<CB_NSTAGES; k++) {\r
+        \r
+        if ((index[k]>=44)&&(index[k]<108)) {\r
+            index[k]+=64;\r
+        } else if ((index[k]>=108)&&(index[k]<128)) {\r
+            index[k]+=128;\r
+        } else {\r
+            /* ERROR */\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Construct decoded vector from codebook and gains.\r
+ *---------------------------------------------------------------*/\r
+\r
+void iCBConstruct(\r
+    float *decvector,   /* (o) Decoded vector */\r
+    int *index,         /* (i) Codebook indices */\r
+    int *gain_index,/* (i) Gain quantization indices */\r
+    float *mem,         /* (i) Buffer for codevector construction */\r
+    int lMem,           /* (i) Length of buffer */\r
+    int veclen,         /* (i) Length of vector */\r
+    int nStages         /* (i) Number of codebook stages */\r
+){\r
+    int j,k;\r
+    float gain[CB_NSTAGES];\r
+    float cbvec[SUBL];\r
+\r
+    /* gain de-quantization */\r
+\r
+    gain[0] = gaindequant(gain_index[0], 1.0, 32);\r
+\r
+\r
+    if (nStages > 1) {\r
+        gain[1] = gaindequant(gain_index[1], \r
+            (float)fabs(gain[0]), 16);  \r
+    }\r
+    if (nStages > 2) {\r
+        gain[2] = gaindequant(gain_index[2], \r
+            (float)fabs(gain[1]), 8);\r
+    }\r
+\r
+    /* codebook vector construction and construction of \r
+    total vector */\r
+\r
+    getCBvec(cbvec, mem, index[0], lMem, veclen);\r
+    for (j=0;j<veclen;j++){\r
+        decvector[j] = gain[0]*cbvec[j];\r
+    }\r
+    if (nStages > 1) {\r
+        for (k=1; k<nStages; k++) {\r
+            getCBvec(cbvec, mem, index[k], lMem, veclen);\r
+            for (j=0;j<veclen;j++) {\r
+                decvector[j] += gain[k]*cbvec[j];\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/iCBConstruct.h b/libs/codec/ilbc/iCBConstruct.h
new file mode 100644 (file)
index 0000000..d8c69d9
--- /dev/null
@@ -0,0 +1,38 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+\r
+\r
+    iCBConstruct.h   \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_ICBCONSTRUCT_H\r
+#define __iLBC_ICBCONSTRUCT_H\r
+\r
+void index_conv_enc(\r
+    int *index          /* (i/o) Codebook indexes */\r
+);\r
+\r
+void index_conv_dec(\r
+    int *index          /* (i/o) Codebook indexes */\r
+);\r
+\r
+void iCBConstruct(\r
+    float *decvector,   /* (o) Decoded vector */\r
+    int *index,         /* (i) Codebook indices */\r
+    int *gain_index,/* (i) Gain quantization indices */\r
+    float *mem,         /* (i) Buffer for codevector construction */\r
+    int lMem,           /* (i) Length of buffer */\r
+    int veclen,         /* (i) Length of vector */\r
+    int nStages         /* (i) Number of codebook stages */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/iCBSearch.c b/libs/codec/ilbc/iCBSearch.c
new file mode 100644 (file)
index 0000000..80c6f2d
--- /dev/null
@@ -0,0 +1,480 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iCBSearch.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <string.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "iCBSearch.h"\r
+#include "gainquant.h"\r
+#include "createCB.h"\r
+#include "filter.h"\r
+#include "constants.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Search routine for codebook encoding and gain quantization.\r
+ *---------------------------------------------------------------*/\r
+\r
+void iCBSearch(\r
+    iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                        /* (i) the encoder state structure */\r
+    int *index,         /* (o) Codebook indices */\r
+    int *gain_index,/* (o) Gain quantization indices */\r
+    float *intarget,/* (i) Target vector for encoding */    \r
+    float *mem,         /* (i) Buffer for codebook construction */\r
+    int lMem,           /* (i) Length of buffer */\r
+    int lTarget,    /* (i) Length of vector */\r
+    int nStages,    /* (i) Number of codebook stages */\r
+    float *weightDenum, /* (i) weighting filter coefficients */\r
+    float *weightState, /* (i) weighting filter state */\r
+    int block           /* (i) the sub-block number */\r
+){\r
+    int i, j, icount, stage, best_index, range, counter;\r
+    float max_measure, gain, measure, crossDot, ftmp;\r
+    float gains[CB_NSTAGES];\r
+    float target[SUBL];\r
+    int base_index, sInd, eInd, base_size;\r
+    int sIndAug=0, eIndAug=0;\r
+    float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];\r
+\r
+\r
+    float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];\r
+    float *pp, *ppi=0, *ppo=0, *ppe=0;\r
+    float cbvectors[CB_MEML];\r
+    float tene, cene, cvec[SUBL];\r
+    float aug_vec[SUBL];\r
+\r
+    memset(cvec,0,SUBL*sizeof(float));  \r
+\r
+    /* Determine size of codebook sections */\r
+\r
+    base_size=lMem-lTarget+1;\r
+    \r
+    if (lTarget==SUBL) {\r
+        base_size=lMem-lTarget+1+lTarget/2;\r
+    }\r
+\r
+    /* setup buffer for weighting */\r
+\r
+    memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);\r
+    memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));\r
+    memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));\r
+\r
+    /* weighting */\r
+\r
+    AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, \r
+        lMem+lTarget, LPC_FILTERORDER);\r
+    \r
+    /* Construct the codebook and target needed */\r
+\r
+    memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));\r
+\r
+    tene=0.0;\r
+    for (i=0; i<lTarget; i++) {\r
+        tene+=target[i]*target[i];\r
+    }\r
+\r
+    /* Prepare search over one more codebook section. This section \r
+       is created by filtering the original buffer with a filter. */\r
+        \r
+    filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);\r
+\r
+    /* The Main Loop over stages */\r
+\r
+    for (stage=0; stage<nStages; stage++) {\r
+\r
+        range = search_rangeTbl[block][stage];\r
+\r
+        /* initialize search measure */\r
+\r
+        max_measure = (float)-10000000.0;\r
+        gain = (float)0.0;\r
+        best_index = 0;\r
+\r
+        /* Compute cross dot product between the target \r
+\r
+\r
+           and the CB memory */\r
+\r
+        crossDot=0.0;\r
+        pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+        for (j=0; j<lTarget; j++) {\r
+            crossDot += target[j]*(*pp++);\r
+        }       \r
+        \r
+        if (stage==0) {\r
+\r
+            /* Calculate energy in the first block of \r
+              'lTarget' sampels. */\r
+            ppe = energy;\r
+            ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;\r
+            ppo = buf+LPC_FILTERORDER+lMem-1;\r
+\r
+            *ppe=0.0;\r
+            pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+            for (j=0; j<lTarget; j++) {\r
+                *ppe+=(*pp)*(*pp);\r
+                               pp++;\r
+            }\r
+            \r
+            if (*ppe>0.0) {\r
+                invenergy[0] = (float) 1.0 / (*ppe + EPS);\r
+            } else {\r
+                invenergy[0] = (float) 0.0; \r
+            }\r
+            ppe++;\r
+\r
+            measure=(float)-10000000.0; \r
+            \r
+            if (crossDot > 0.0) {\r
+                   measure = crossDot*crossDot*invenergy[0];\r
+            }\r
+        }\r
+        else {\r
+            measure = crossDot*crossDot*invenergy[0];\r
+        }\r
+\r
+        /* check if measure is better */\r
+        ftmp = crossDot*invenergy[0];\r
+        \r
+        if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+            best_index = 0;\r
+            max_measure = measure;\r
+            gain = ftmp;\r
+        }\r
+\r
+        /* loop over the main first codebook section, \r
+           full search */\r
+\r
+        for (icount=1; icount<range; icount++) {\r
+\r
+            /* calculate measure */\r
+\r
+\r
+\r
+            crossDot=0.0;\r
+            pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;\r
+\r
+            for (j=0; j<lTarget; j++) {\r
+                crossDot += target[j]*(*pp++);\r
+            }\r
+            \r
+            if (stage==0) {\r
+                *ppe++ = energy[icount-1] + (*ppi)*(*ppi) - \r
+                    (*ppo)*(*ppo);\r
+                ppo--;\r
+                ppi--;\r
+                \r
+                if (energy[icount]>0.0) {\r
+                    invenergy[icount] = \r
+                        (float)1.0/(energy[icount]+EPS);\r
+                } else {\r
+                    invenergy[icount] = (float) 0.0;\r
+                }\r
+\r
+                measure=(float)-10000000.0;\r
+                \r
+                if (crossDot > 0.0) {\r
+                    measure = crossDot*crossDot*invenergy[icount];\r
+                }\r
+            }\r
+            else {\r
+                measure = crossDot*crossDot*invenergy[icount];\r
+            }\r
+\r
+            /* check if measure is better */\r
+            ftmp = crossDot*invenergy[icount];\r
+\r
+            if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                best_index = icount;\r
+                max_measure = measure;\r
+                gain = ftmp;\r
+            }\r
+        }\r
+\r
+        /* Loop over augmented part in the first codebook \r
+         * section, full search.\r
+         * The vectors are interpolated.\r
+         */\r
+        \r
+        if (lTarget==SUBL) {        \r
+            \r
+            /* Search for best possible cb vector and \r
+               compute the CB-vectors' energy. */\r
+            searchAugmentedCB(20, 39, stage, base_size-lTarget/2, \r
+                target, buf+LPC_FILTERORDER+lMem,\r
+                &max_measure, &best_index, &gain, energy, \r
+                invenergy);\r
+\r
+\r
+        }\r
+\r
+        /* set search range for following codebook sections */\r
+\r
+        base_index=best_index;\r
+\r
+        /* unrestricted search */\r
+\r
+        if (CB_RESRANGE == -1) {\r
+            sInd=0;\r
+            eInd=range-1;\r
+            sIndAug=20;\r
+            eIndAug=39;\r
+        }\r
+\r
+        /* restriced search around best index from first \r
+        codebook section */\r
+\r
+        else {\r
+            /* Initialize search indices */\r
+            sIndAug=0;\r
+            eIndAug=0;\r
+            sInd=base_index-CB_RESRANGE/2;\r
+            eInd=sInd+CB_RESRANGE;\r
+            \r
+            if (lTarget==SUBL) {\r
+\r
+                if (sInd<0) {\r
+                    \r
+                    sIndAug = 40 + sInd;\r
+                    eIndAug = 39;\r
+                    sInd=0;\r
+\r
+                } else if ( base_index < (base_size-20) ) {\r
+                    \r
+                    if (eInd > range) {\r
+                        sInd -= (eInd-range);\r
+                        eInd = range;\r
+                    }\r
+                } else { /* base_index >= (base_size-20) */\r
+                    \r
+                    if (sInd < (base_size-20)) {\r
+                        sIndAug = 20;\r
+                        sInd = 0;\r
+                        eInd = 0;\r
+                        eIndAug = 19 + CB_RESRANGE;\r
+                        \r
+                        if(eIndAug > 39) {\r
+                            eInd = eIndAug-39;\r
+                            eIndAug = 39;\r
+                        }\r
+                    } else {\r
+                        sIndAug = 20 + sInd - (base_size-20);\r
+                        eIndAug = 39;\r
+\r
+\r
+                        sInd = 0;\r
+                        eInd = CB_RESRANGE - (eIndAug-sIndAug+1);\r
+                    }\r
+                }\r
+\r
+            } else { /* lTarget = 22 or 23 */\r
+                \r
+                if (sInd < 0) {\r
+                    eInd -= sInd;\r
+                    sInd = 0;\r
+                }\r
+                \r
+                if(eInd > range) {\r
+                    sInd -= (eInd - range);\r
+                    eInd = range;\r
+                }\r
+            }\r
+        }\r
+\r
+        /* search of higher codebook section */\r
+\r
+        /* index search range */\r
+        counter = sInd;\r
+        sInd += base_size;\r
+        eInd += base_size;\r
+        \r
+        \r
+        if (stage==0) {\r
+            ppe = energy+base_size;\r
+            *ppe=0.0;\r
+\r
+            pp=cbvectors+lMem-lTarget;\r
+            for (j=0; j<lTarget; j++) {\r
+                *ppe+=(*pp)*(*pp);\r
+                               pp++;\r
+            }\r
+\r
+            ppi = cbvectors + lMem - 1 - lTarget;\r
+            ppo = cbvectors + lMem - 1;\r
+            \r
+            for (j=0; j<(range-1); j++) {\r
+                *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);\r
+                ppo--;\r
+                ppi--;\r
+                ppe++;\r
+            }\r
+        }\r
+\r
+        /* loop over search range */\r
+\r
+        for (icount=sInd; icount<eInd; icount++) {\r
+\r
+            /* calculate measure */\r
+\r
+            crossDot=0.0;\r
+\r
+\r
+            pp=cbvectors + lMem - (counter++) - lTarget;\r
+\r
+            for (j=0;j<lTarget;j++) {\r
+                crossDot += target[j]*(*pp++);\r
+            }\r
+            \r
+            if (energy[icount]>0.0) {\r
+                invenergy[icount] =(float)1.0/(energy[icount]+EPS);\r
+            } else {\r
+                invenergy[icount] =(float)0.0;\r
+            }\r
+            \r
+            if (stage==0) {\r
+\r
+                measure=(float)-10000000.0;\r
+                \r
+                if (crossDot > 0.0) {\r
+                    measure = crossDot*crossDot*\r
+                        invenergy[icount];\r
+                }\r
+            }\r
+            else {\r
+                measure = crossDot*crossDot*invenergy[icount];\r
+            }\r
+\r
+            /* check if measure is better */\r
+            ftmp = crossDot*invenergy[icount];\r
+\r
+            if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                best_index = icount;\r
+                max_measure = measure;\r
+                gain = ftmp;\r
+            }\r
+        }\r
+\r
+        /* Search the augmented CB inside the limited range. */\r
+        \r
+        if ((lTarget==SUBL)&&(sIndAug!=0)) {\r
+            searchAugmentedCB(sIndAug, eIndAug, stage, \r
+                2*base_size-20, target, cbvectors+lMem,\r
+                &max_measure, &best_index, &gain, energy, \r
+                invenergy);\r
+        }\r
+\r
+        /* record best index */\r
+\r
+        index[stage] = best_index;\r
+\r
+        /* gain quantization */\r
+\r
+        if (stage==0){\r
+            \r
+            if (gain<0.0){\r
+                gain = 0.0;\r
+\r
+\r
+            }\r
+            \r
+            if (gain>CB_MAXGAIN) {\r
+                gain = (float)CB_MAXGAIN;\r
+            }\r
+            gain = gainquant(gain, 1.0, 32, &gain_index[stage]);\r
+        }\r
+        else {\r
+            if (stage==1) {\r
+                gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                    16, &gain_index[stage]);\r
+            } else {\r
+                gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                    8, &gain_index[stage]);\r
+            }\r
+        }\r
+\r
+        /* Extract the best (according to measure) \r
+           codebook vector */\r
+        \r
+        if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {\r
+            \r
+            if (index[stage]<base_size) {\r
+                pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];\r
+            } else {\r
+                pp=cbvectors+lMem-lTarget-\r
+                    index[stage]+base_size;\r
+            }\r
+        } else {\r
+            \r
+            if (index[stage]<base_size) {\r
+                if (index[stage]<(base_size-20)) {\r
+                    pp=buf+LPC_FILTERORDER+lMem-\r
+                        lTarget-index[stage];\r
+                } else {\r
+                    createAugmentedVec(index[stage]-base_size+40,\r
+                            buf+LPC_FILTERORDER+lMem,aug_vec);\r
+                    pp=aug_vec;\r
+                }\r
+            } else {\r
+                int filterno, position;\r
+\r
+                filterno=index[stage]/base_size;\r
+                position=index[stage]-filterno*base_size;\r
+\r
+                \r
+                if (position<(base_size-20)) {\r
+                    pp=cbvectors+filterno*lMem-lTarget-\r
+                        index[stage]+filterno*base_size;\r
+                } else {\r
+                    createAugmentedVec(\r
+                        index[stage]-(filterno+1)*base_size+40,\r
+                        cbvectors+filterno*lMem,aug_vec);\r
+                    pp=aug_vec;\r
+\r
+\r
+                }\r
+            }\r
+        }\r
+\r
+        /* Subtract the best codebook vector, according \r
+           to measure, from the target vector */\r
+\r
+        for (j=0;j<lTarget;j++) {\r
+            cvec[j] += gain*(*pp);\r
+            target[j] -= gain*(*pp++);\r
+        }\r
+\r
+        /* record quantized gain */\r
+\r
+        gains[stage]=gain;\r
+\r
+    }/* end of Main Loop. for (stage=0;... */\r
+\r
+    /* Gain adjustment for energy matching */\r
+    cene=0.0;\r
+    for (i=0; i<lTarget; i++) {\r
+        cene+=cvec[i]*cvec[i];\r
+    }\r
+    j=gain_index[0];\r
+\r
+    for (i=gain_index[0]; i<32; i++) {\r
+        ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];\r
+        \r
+        if ((ftmp<(tene*gains[0]*gains[0])) && \r
+            (gain_sq5Tbl[j]<(2.0*gains[0]))) {\r
+            j=i;\r
+        }\r
+    }\r
+    gain_index[0]=j;\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/iCBSearch.h b/libs/codec/ilbc/iCBSearch.h
new file mode 100644 (file)
index 0000000..390e3f3
--- /dev/null
@@ -0,0 +1,35 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iCBSearch.h        \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_ICBSEARCH_H\r
+#define __iLBC_ICBSEARCH_H\r
+\r
+void iCBSearch(\r
+    iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                        /* (i) the encoder state structure */\r
+    int *index,         /* (o) Codebook indices */\r
+    int *gain_index,/* (o) Gain quantization indices */\r
+    float *intarget,/* (i) Target vector for encoding */    \r
+    float *mem,         /* (i) Buffer for codebook construction */\r
+    int lMem,           /* (i) Length of buffer */\r
+    int lTarget,    /* (i) Length of vector */\r
+    int nStages,    /* (i) Number of codebook stages */\r
+    float *weightDenum, /* (i) weighting filter coefficients */\r
+\r
+\r
+    float *weightState, /* (i) weighting filter state */\r
+    int block           /* (i) the sub-block number */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/iLBC_decode.c b/libs/codec/ilbc/iLBC_decode.c
new file mode 100644 (file)
index 0000000..460603a
--- /dev/null
@@ -0,0 +1,619 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iLBC_decode.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <stdlib.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "iLBC_decode.h"\r
+#include "StateConstructW.h"\r
+#include "LPCdecode.h"\r
+#include "iCBConstruct.h"\r
+#include "doCPLC.h"\r
+#include "helpfun.h"\r
+#include "constants.h"\r
+#include "packing.h"\r
+#include "string.h"\r
+#include "enhancer.h"\r
+#include "hpOutput.h"\r
+#include "syntFilter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Initiation of decoder instance.\r
+ *---------------------------------------------------------------*/\r
+\r
+short initDecode(                   /* (o) Number of decoded \r
+                                           samples */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+    int mode,                       /* (i) frame size mode */\r
+    int use_enhancer                /* (i) 1 to use enhancer\r
+                                           0 to run without \r
+                                             enhancer */\r
+){\r
+    int i;\r
+\r
+    iLBCdec_inst->mode = mode;\r
+\r
+    if (mode==30) {\r
+        iLBCdec_inst->blockl = BLOCKL_30MS;\r
+        iLBCdec_inst->nsub = NSUB_30MS;\r
+        iLBCdec_inst->nasub = NASUB_30MS;\r
+        iLBCdec_inst->lpc_n = LPC_N_30MS;\r
+\r
+\r
+        iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+        iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;\r
+        iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+        /* ULP init */\r
+        iLBCdec_inst->ULP_inst=&ULP_30msTbl;\r
+    }\r
+    else if (mode==20) {\r
+        iLBCdec_inst->blockl = BLOCKL_20MS;\r
+        iLBCdec_inst->nsub = NSUB_20MS;\r
+        iLBCdec_inst->nasub = NASUB_20MS;\r
+        iLBCdec_inst->lpc_n = LPC_N_20MS;\r
+        iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+        iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;\r
+        iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+        /* ULP init */\r
+        iLBCdec_inst->ULP_inst=&ULP_20msTbl;\r
+    }\r
+    else {\r
+        exit(2);\r
+    }\r
+\r
+    memset(iLBCdec_inst->syntMem, 0, \r
+        LPC_FILTERORDER*sizeof(float));\r
+    memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, \r
+        LPC_FILTERORDER*sizeof(float));\r
+\r
+    memset(iLBCdec_inst->old_syntdenum, 0, \r
+        ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));\r
+    for (i=0; i<NSUB_MAX; i++)\r
+        iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;\r
+\r
+    iLBCdec_inst->last_lag = 20;\r
+\r
+    iLBCdec_inst->prevLag = 120;\r
+    iLBCdec_inst->per = 0.0;\r
+    iLBCdec_inst->consPLICount = 0;\r
+    iLBCdec_inst->prevPLI = 0;\r
+    iLBCdec_inst->prevLpc[0] = 1.0;\r
+    memset(iLBCdec_inst->prevLpc+1,0,\r
+        LPC_FILTERORDER*sizeof(float));\r
+    memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));\r
+    iLBCdec_inst->seed=777;\r
+\r
+    memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));\r
+\r
+    iLBCdec_inst->use_enhancer = use_enhancer;\r
+    memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));\r
+    for (i=0;i<ENH_NBLOCKS_TOT;i++) \r
+        iLBCdec_inst->enh_period[i]=(float)40.0;\r
+\r
+    iLBCdec_inst->prev_enh_pl = 0;\r
+\r
+    return (iLBCdec_inst->blockl);\r
+}\r
+\r
+\r
+\r
+/*----------------------------------------------------------------*\r
+ *  frame residual decoder function (subrutine to iLBC_decode) \r
+ *---------------------------------------------------------------*/\r
+\r
+static void Decode(\r
+    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                             structure */\r
+    float *decresidual,             /* (o) decoded residual frame */\r
+    int start,                      /* (i) location of start \r
+                                           state */\r
+    int idxForMax,                  /* (i) codebook index for the \r
+                                           maximum value */\r
+    int *idxVec,                /* (i) codebook indexes for the \r
+                                           samples  in the start \r
+                                           state */\r
+    float *syntdenum,               /* (i) the decoded synthesis\r
+                                           filter coefficients */\r
+    int *cb_index,                  /* (i) the indexes for the \r
+                                           adaptive codebook */\r
+    int *gain_index,            /* (i) the indexes for the \r
+                                           corresponding gains */\r
+    int *extra_cb_index,        /* (i) the indexes for the \r
+                                           adaptive codebook part \r
+                                           of start state */\r
+    int *extra_gain_index,          /* (i) the indexes for the \r
+                                           corresponding gains */\r
+    int state_first                 /* (i) 1 if non adaptive part \r
+                                           of start state comes \r
+                                           first 0 if that part \r
+                                           comes last */\r
+){\r
+    float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+    int k, meml_gotten, Nfor, Nback, i;\r
+    int diff, start_pos;\r
+    int subcount, subframe;\r
+\r
+    diff = STATE_LEN - iLBCdec_inst->state_short_len;\r
+    \r
+    if (state_first == 1) {\r
+        start_pos = (start-1)*SUBL;\r
+    } else {\r
+        start_pos = (start-1)*SUBL + diff;\r
+    }\r
+\r
+    /* decode scalar part of start state */\r
+\r
+    StateConstructW(idxForMax, idxVec, \r
+        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+        &decresidual[start_pos], iLBCdec_inst->state_short_len);\r
+\r
+    \r
+    if (state_first) { /* put adaptive part in the end */\r
+                \r
+\r
+\r
+        /* setup memory */\r
+\r
+        memset(mem, 0, \r
+            (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));\r
+        memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, \r
+            decresidual+start_pos, \r
+            iLBCdec_inst->state_short_len*sizeof(float));\r
+        \r
+        /* construct decoded vector */\r
+\r
+        iCBConstruct(\r
+            &decresidual[start_pos+iLBCdec_inst->state_short_len],\r
+            extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,\r
+            stMemLTbl, diff, CB_NSTAGES);\r
+    \r
+    } \r
+    else {/* put adaptive part in the beginning */\r
+        \r
+        /* create reversed vectors for prediction */\r
+\r
+        for (k=0; k<diff; k++) {\r
+            reverseDecresidual[k] = \r
+                decresidual[(start+1)*SUBL-1-\r
+                        (k+iLBCdec_inst->state_short_len)];\r
+        }\r
+        \r
+        /* setup memory */\r
+\r
+        meml_gotten = iLBCdec_inst->state_short_len;\r
+        for (k=0; k<meml_gotten; k++){ \r
+            mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+        } \r
+        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+        \r
+        /* construct decoded vector */\r
+\r
+        iCBConstruct(reverseDecresidual, extra_cb_index, \r
+            extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,\r
+            diff, CB_NSTAGES);\r
+        \r
+        /* get decoded residual from reversed vector */\r
+\r
+        for (k=0; k<diff; k++) {\r
+            decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+        }\r
+    }\r
+\r
+    /* counter for predicted sub-frames */\r
+\r
+    subcount=0;\r
+\r
+    /* forward prediction of sub-frames */\r
+\r
+    Nfor = iLBCdec_inst->nsub-start-1;\r
+\r
+\r
+    \r
+    if ( Nfor > 0 ){\r
+        \r
+        /* setup memory */\r
+\r
+        memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+        memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,\r
+            STATE_LEN*sizeof(float));\r
+\r
+        /* loop over sub-frames to encode */\r
+\r
+        for (subframe=0; subframe<Nfor; subframe++) {\r
+            \r
+            /* construct decoded vector */\r
+\r
+            iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                mem+CB_MEML-memLfTbl[subcount], \r
+                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+\r
+            /* update memory */\r
+\r
+            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+            memcpy(mem+CB_MEML-SUBL, \r
+                &decresidual[(start+1+subframe)*SUBL],\r
+                SUBL*sizeof(float));\r
+\r
+            subcount++;\r
+\r
+        }\r
+\r
+    }\r
+    \r
+    /* backward prediction of sub-frames */\r
+\r
+    Nback = start-1;\r
+\r
+    if ( Nback > 0 ) {\r
+\r
+        /* setup memory */\r
+\r
+        meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);\r
+        \r
+        if ( meml_gotten > CB_MEML ) { \r
+            meml_gotten=CB_MEML;\r
+        }\r
+        for (k=0; k<meml_gotten; k++) { \r
+            mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+        }\r
+        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+\r
+        /* loop over subframes to decode */\r
+\r
+\r
+\r
+        for (subframe=0; subframe<Nback; subframe++) {\r
+            \r
+            /* construct decoded vector */\r
+\r
+            iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount], \r
+                SUBL, CB_NSTAGES);\r
+\r
+            /* update memory */\r
+\r
+            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+            memcpy(mem+CB_MEML-SUBL, \r
+                &reverseDecresidual[subframe*SUBL],\r
+                SUBL*sizeof(float));\r
+\r
+            subcount++;\r
+        }\r
+\r
+        /* get decoded residual from reversed vector */\r
+\r
+        for (i=0; i<SUBL*Nback; i++)\r
+            decresidual[SUBL*Nback - i - 1] = \r
+            reverseDecresidual[i];\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  main decoder function \r
+ *---------------------------------------------------------------*/\r
+\r
+void iLBC_decode( \r
+    float *decblock,            /* (o) decoded signal block */\r
+    unsigned char *bytes,           /* (i) encoded signal bits */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                             structure */\r
+    int mode                    /* (i) 0: bad packet, PLC, \r
+                                           1: normal */\r
+){\r
+    float data[BLOCKL_MAX];\r
+    float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];\r
+    float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];\r
+    float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];\r
+    int k, i, start, idxForMax, pos, lastpart, ulp;\r
+    int lag, ilag;\r
+    float cc, maxcc;\r
+    int idxVec[STATE_LEN];\r
+    int check;\r
+    int gain_index[NASUB_MAX*CB_NSTAGES], \r
+        extra_gain_index[CB_NSTAGES];\r
+    int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];\r
+    int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+    int state_first;\r
+\r
+\r
+    int last_bit;\r
+    unsigned char *pbytes;\r
+    float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+    int order_plus_one;\r
+    float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+    float decresidual[BLOCKL_MAX];\r
+    \r
+    if (mode>0) { /* the data are good */\r
+\r
+        /* decode data */\r
+        \r
+        pbytes=bytes;\r
+        pos=0;\r
+\r
+        /* Set everything to zero before decoding */\r
+\r
+        for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {\r
+            lsf_i[k]=0;\r
+        }\r
+        start=0;\r
+        state_first=0;\r
+        idxForMax=0;\r
+        for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+            idxVec[k]=0;\r
+        }\r
+        for (k=0; k<CB_NSTAGES; k++) {\r
+            extra_cb_index[k]=0;\r
+        }\r
+        for (k=0; k<CB_NSTAGES; k++) {\r
+            extra_gain_index[k]=0;\r
+        }\r
+        for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+                cb_index[i*CB_NSTAGES+k]=0;\r
+            }\r
+        }\r
+        for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+                gain_index[i*CB_NSTAGES+k]=0;\r
+            }\r
+        }\r
+\r
+        /* loop over ULP classes */\r
+\r
+        for (ulp=0; ulp<3; ulp++) {\r
+        \r
+            /* LSF */\r
+            for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){\r
+                unpack( &pbytes, &lastpart, \r
+                    iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+                packcombine(&lsf_i[k], lastpart,\r
+                    iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);\r
+            }\r
+\r
+\r
+\r
+            /* Start block info */\r
+\r
+            unpack( &pbytes, &lastpart, \r
+                iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);\r
+            packcombine(&start, lastpart, \r
+                iLBCdec_inst->ULP_inst->start_bits[ulp]);\r
+\r
+            unpack( &pbytes, &lastpart, \r
+                iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+            packcombine(&state_first, lastpart,\r
+                iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);\r
+\r
+            unpack( &pbytes, &lastpart, \r
+                iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);\r
+            packcombine(&idxForMax, lastpart, \r
+                iLBCdec_inst->ULP_inst->scale_bits[ulp]);\r
+\r
+            for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+                unpack( &pbytes, &lastpart, \r
+                    iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);\r
+                packcombine(idxVec+k, lastpart,\r
+                    iLBCdec_inst->ULP_inst->state_bits[ulp]);\r
+            }\r
+\r
+            /* 23/22 (20ms/30ms) sample block */\r
+\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+                unpack( &pbytes, &lastpart, \r
+                    iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                    &pos);\r
+                packcombine(extra_cb_index+k, lastpart, \r
+                    iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);\r
+            }\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+                unpack( &pbytes, &lastpart, \r
+                    iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                    &pos);\r
+                packcombine(extra_gain_index+k, lastpart,\r
+                    iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);\r
+            }\r
+                \r
+            /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+\r
+            for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+                for (k=0; k<CB_NSTAGES; k++) {\r
+                    unpack( &pbytes, &lastpart, \r
+                    iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], \r
+                        &pos);\r
+                    packcombine(cb_index+i*CB_NSTAGES+k, lastpart, \r
+                    iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);\r
+                }\r
+            }\r
+            \r
+            for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+\r
+\r
+                for (k=0; k<CB_NSTAGES; k++) {\r
+                    unpack( &pbytes, &lastpart, \r
+\r
+                    iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                        &pos);\r
+                    packcombine(gain_index+i*CB_NSTAGES+k, lastpart,\r
+                        iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);\r
+                }\r
+            }\r
+        }\r
+        /* Extract last bit. If it is 1 this indicates an \r
+           empty/lost frame */\r
+        unpack( &pbytes, &last_bit, 1, &pos);\r
+\r
+        /* Check for bit errors or empty/lost frames */\r
+        if (start<1)\r
+            mode = 0;\r
+        if (iLBCdec_inst->mode==20 && start>3)\r
+            mode = 0;\r
+        if (iLBCdec_inst->mode==30 && start>5)\r
+            mode = 0;\r
+        if (last_bit==1)\r
+            mode = 0;\r
+\r
+        if (mode==1) { /* No bit errors was detected, \r
+                          continue decoding */\r
+                \r
+            /* adjust index */\r
+            index_conv_dec(cb_index);\r
+\r
+            /* decode the lsf */\r
+\r
+            SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);\r
+            check=LSF_check(lsfdeq, LPC_FILTERORDER, \r
+                iLBCdec_inst->lpc_n);\r
+            DecoderInterpolateLSF(syntdenum, weightdenum, \r
+                lsfdeq, LPC_FILTERORDER, iLBCdec_inst);\r
+        \r
+            Decode(iLBCdec_inst, decresidual, start, idxForMax, \r
+                idxVec, syntdenum, cb_index, gain_index, \r
+                extra_cb_index, extra_gain_index, \r
+                state_first);\r
+\r
+            /* preparing the plc for a future loss! */\r
+\r
+            doThePLC(PLCresidual, PLClpc, 0, decresidual, \r
+                syntdenum + \r
+                (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),\r
+                (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+\r
+        \r
+            memcpy(decresidual, PLCresidual, \r
+                iLBCdec_inst->blockl*sizeof(float));\r
+        }\r
+\r
+\r
+        \r
+    }\r
+    \r
+    if (mode == 0) {\r
+        /* the data is bad (either a PLC call\r
+         * was made or a severe bit error was detected)\r
+         */\r
+        \r
+        /* packet loss conceal */\r
+\r
+        memset(zeros, 0, BLOCKL_MAX*sizeof(float));\r
+        \r
+        one[0] = 1;\r
+        memset(one+1, 0, LPC_FILTERORDER*sizeof(float));\r
+        \r
+        start=0;\r
+        \r
+        doThePLC(PLCresidual, PLClpc, 1, zeros, one,\r
+            (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+        memcpy(decresidual, PLCresidual, \r
+            iLBCdec_inst->blockl*sizeof(float));\r
+        \r
+        order_plus_one = LPC_FILTERORDER + 1;\r
+        for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+            memcpy(syntdenum+(i*order_plus_one), PLClpc, \r
+                order_plus_one*sizeof(float));\r
+        }\r
+    }\r
+\r
+    if (iLBCdec_inst->use_enhancer == 1) {\r
+\r
+        /* post filtering */\r
+        \r
+        iLBCdec_inst->last_lag = \r
+            enhancerInterface(data, decresidual, iLBCdec_inst);\r
+\r
+        /* synthesis filtering */\r
+        \r
+        if (iLBCdec_inst->mode==20) {\r
+            /* Enhancer has 40 samples delay */\r
+            i=0;\r
+            syntFilter(data + i*SUBL, \r
+                iLBCdec_inst->old_syntdenum + \r
+                (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), \r
+                SUBL, iLBCdec_inst->syntMem);\r
+            for (i=1; i < iLBCdec_inst->nsub; i++) {\r
+                syntFilter(data + i*SUBL, \r
+                    syntdenum + (i-1)*(LPC_FILTERORDER+1), \r
+                    SUBL, iLBCdec_inst->syntMem);\r
+            }\r
+        } else if (iLBCdec_inst->mode==30) {\r
+            /* Enhancer has 80 samples delay */\r
+            for (i=0; i < 2; i++) {\r
+                syntFilter(data + i*SUBL, \r
+\r
+\r
+                    iLBCdec_inst->old_syntdenum + \r
+                    (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),\r
+                    SUBL, iLBCdec_inst->syntMem);\r
+            }\r
+            for (i=2; i < iLBCdec_inst->nsub; i++) {\r
+                syntFilter(data + i*SUBL, \r
+                    syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,\r
+                    iLBCdec_inst->syntMem);\r
+            }\r
+        }\r
+\r
+    } else {\r
+\r
+        /* Find last lag */\r
+        lag = 20;\r
+        maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+            &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);\r
+        \r
+        for (ilag=21; ilag<120; ilag++) {\r
+            cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+                &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], \r
+                ENH_BLOCKL);\r
+        \r
+            if (cc > maxcc) {\r
+                maxcc = cc;\r
+                lag = ilag;\r
+            }\r
+        }\r
+        iLBCdec_inst->last_lag = lag;\r
+\r
+        /* copy data and run synthesis filter */\r
+\r
+        memcpy(data, decresidual, \r
+            iLBCdec_inst->blockl*sizeof(float));\r
+        for (i=0; i < iLBCdec_inst->nsub; i++) {\r
+            syntFilter(data + i*SUBL, \r
+                syntdenum + i*(LPC_FILTERORDER+1), SUBL, \r
+                iLBCdec_inst->syntMem);\r
+        }\r
+    }\r
+\r
+    /* high pass filtering on output if desired, otherwise \r
+       copy to out */\r
+\r
+    hpOutput(data, iLBCdec_inst->blockl, \r
+                decblock,iLBCdec_inst->hpomem);\r
+\r
+    /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/\r
+\r
+    memcpy(iLBCdec_inst->old_syntdenum, syntdenum, \r
+\r
+        iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));\r
+\r
+    iLBCdec_inst->prev_enh_pl=0;\r
+\r
+\r
+\r
+    if (mode==0) { /* PLC was used */\r
+        iLBCdec_inst->prev_enh_pl=1;\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/iLBC_decode.h b/libs/codec/ilbc/iLBC_decode.h
new file mode 100644 (file)
index 0000000..ae9c481
--- /dev/null
@@ -0,0 +1,40 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iLBC_decode.h    \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_ILBCDECODE_H\r
+#define __iLBC_ILBCDECODE_H\r
+\r
+#include "iLBC_define.h"\r
+\r
+short initDecode(                   /* (o) Number of decoded \r
+                                           samples */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+    int mode,                       /* (i) frame size mode */\r
+    int use_enhancer                /* (i) 1 to use enhancer\r
+                                           0 to run without \r
+                                             enhancer */\r
+);\r
+\r
+void iLBC_decode( \r
+    float *decblock,            /* (o) decoded signal block */\r
+    unsigned char *bytes,           /* (i) encoded signal bits */\r
+    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                             structure */\r
+    int mode                    /* (i) 0: bad packet, PLC, \r
+                                           1: normal */\r
+);\r
+\r
+\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/iLBC_define.h b/libs/codec/ilbc/iLBC_define.h
new file mode 100644 (file)
index 0000000..85ef7e6
--- /dev/null
@@ -0,0 +1,201 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iLBC_define.h    \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+#include <string.h>\r
+\r
+#ifndef __iLBC_ILBCDEFINE_H\r
+#define __iLBC_ILBCDEFINE_H\r
+\r
+/* general codec settings */\r
+\r
+#define FS                      (float)8000.0\r
+#define BLOCKL_20MS             160\r
+#define BLOCKL_30MS             240\r
+#define BLOCKL_MAX              240\r
+#define NSUB_20MS               4\r
+#define NSUB_30MS               6\r
+#define NSUB_MAX            6\r
+#define NASUB_20MS              2\r
+#define NASUB_30MS              4\r
+#define NASUB_MAX               4\r
+#define SUBL                40\r
+#define STATE_LEN               80\r
+#define STATE_SHORT_LEN_30MS    58\r
+#define STATE_SHORT_LEN_20MS    57\r
+\r
+/* LPC settings */\r
+\r
+#define LPC_FILTERORDER         10\r
+#define LPC_CHIRP_SYNTDENUM     (float)0.9025\r
+#define LPC_CHIRP_WEIGHTDENUM   (float)0.4222\r
+#define LPC_LOOKBACK        60\r
+#define LPC_N_20MS              1\r
+#define LPC_N_30MS              2\r
+#define LPC_N_MAX               2\r
+#define LPC_ASYMDIFF        20\r
+#define LPC_BW                  (float)60.0\r
+#define LPC_WN                  (float)1.0001\r
+#define LSF_NSPLIT              3\r
+\r
+#define LSF_NUMBER_OF_STEPS     4\r
+#define LPC_HALFORDER           (LPC_FILTERORDER/2)\r
+\r
+/* cb settings */\r
+\r
+#define CB_NSTAGES              3\r
+#define CB_EXPAND               2\r
+#define CB_MEML                 147\r
+#define CB_FILTERLEN        2*4\r
+#define CB_HALFFILTERLEN    4\r
+#define CB_RESRANGE             34\r
+#define CB_MAXGAIN              (float)1.3 \r
+\r
+/* enhancer */\r
+\r
+#define ENH_BLOCKL              80  /* block length */\r
+#define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)\r
+#define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks\r
+                                       in said second sequence */\r
+#define ENH_SLOP            2   /* max difference estimated and\r
+                                       correct pitch period */\r
+#define ENH_PLOCSL              20  /* pitch-estimates and pitch-\r
+                                       locations buffer length */\r
+#define ENH_OVERHANG        2\r
+#define ENH_UPS0            4   /* upsampling rate */\r
+#define ENH_FL0                 3   /* 2*FLO+1 is the length of \r
+                                       each filter */\r
+#define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)\r
+#define ENH_CORRDIM             (2*ENH_SLOP+1)\r
+#define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)\r
+#define ENH_NBLOCKS_EXTRA       5\r
+#define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS + \r
+                                       ENH_NBLOCKS_EXTRA */\r
+#define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL\r
+#define ENH_ALPHA0              (float)0.05\r
+\r
+/* Down sampling */\r
+\r
+#define FILTERORDER_DS          7\r
+#define DELAY_DS            3\r
+#define FACTOR_DS               2\r
+\r
+/* bit stream defs */\r
+\r
+#define NO_OF_BYTES_20MS    38\r
+#define NO_OF_BYTES_30MS    50\r
+#define NO_OF_WORDS_20MS    19\r
+#define NO_OF_WORDS_30MS    25\r
+#define STATE_BITS              3\r
+#define BYTE_LEN            8\r
+#define ULP_CLASSES             3\r
+\r
+/* help parameters */\r
+\r
+\r
+#define FLOAT_MAX               (float)1.0e37\r
+#define EPS                     (float)2.220446049250313e-016\r
+#define PI                      (float)3.14159265358979323846\r
+#define MIN_SAMPLE              -32768\r
+#define MAX_SAMPLE              32767\r
+#define TWO_PI                  (float)6.283185307\r
+#define PI2                     (float)0.159154943\r
+\r
+/* type definition encoder instance */\r
+typedef struct iLBC_ULP_Inst_t_ {\r
+    int lsf_bits[6][ULP_CLASSES+2];\r
+    int start_bits[ULP_CLASSES+2];\r
+    int startfirst_bits[ULP_CLASSES+2];\r
+    int scale_bits[ULP_CLASSES+2];\r
+    int state_bits[ULP_CLASSES+2];\r
+    int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];\r
+    int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];\r
+    int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+    int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+} iLBC_ULP_Inst_t;\r
+\r
+/* type definition encoder instance */\r
+typedef struct iLBC_Enc_Inst_t_ {\r
+\r
+    /* flag for frame size mode */\r
+    int mode;\r
+\r
+    /* basic parameters for different frame sizes */\r
+    int blockl;\r
+    int nsub;\r
+    int nasub;\r
+    int no_of_bytes, no_of_words;\r
+    int lpc_n;\r
+    int state_short_len;\r
+    const iLBC_ULP_Inst_t *ULP_inst;\r
+\r
+    /* analysis filter state */\r
+    float anaMem[LPC_FILTERORDER];\r
+\r
+    /* old lsf parameters for interpolation */\r
+    float lsfold[LPC_FILTERORDER];\r
+    float lsfdeqold[LPC_FILTERORDER];\r
+\r
+    /* signal buffer for LP analysis */\r
+    float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];\r
+\r
+    /* state of input HP filter */\r
+    float hpimem[4];\r
+\r
+} iLBC_Enc_Inst_t;\r
+\r
+/* type definition decoder instance */\r
+typedef struct iLBC_Dec_Inst_t_ {\r
+\r
+\r
+    /* flag for frame size mode */\r
+    int mode;\r
+\r
+    /* basic parameters for different frame sizes */\r
+    int blockl;\r
+    int nsub;\r
+    int nasub;\r
+    int no_of_bytes, no_of_words;\r
+    int lpc_n;\r
+    int state_short_len;\r
+    const iLBC_ULP_Inst_t *ULP_inst;\r
+\r
+    /* synthesis filter state */\r
+    float syntMem[LPC_FILTERORDER];\r
+\r
+    /* old LSF for interpolation */\r
+    float lsfdeqold[LPC_FILTERORDER];\r
+\r
+    /* pitch lag estimated in enhancer and used in PLC */\r
+    int last_lag;\r
+\r
+    /* PLC state information */\r
+    int prevLag, consPLICount, prevPLI, prev_enh_pl;\r
+    float prevLpc[LPC_FILTERORDER+1];\r
+    float prevResidual[NSUB_MAX*SUBL];\r
+    float per;\r
+    unsigned long seed;\r
+\r
+    /* previous synthesis filter parameters */\r
+    float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+\r
+    /* state of output HP filter */\r
+    float hpomem[4];\r
+\r
+    /* enhancer state information */\r
+    int use_enhancer;\r
+    float enh_buf[ENH_BUFL];\r
+    float enh_period[ENH_NBLOCKS_TOT];\r
+\r
+} iLBC_Dec_Inst_t;\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/iLBC_encode.c b/libs/codec/ilbc/iLBC_encode.c
new file mode 100644 (file)
index 0000000..e874242
--- /dev/null
@@ -0,0 +1,514 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iLBC_encode.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "iLBC_encode.h"\r
+#include "LPCencode.h"\r
+#include "FrameClassify.h"\r
+#include "StateSearchW.h"\r
+#include "StateConstructW.h"\r
+#include "helpfun.h"\r
+#include "constants.h"\r
+#include "packing.h"\r
+#include "iCBSearch.h"\r
+#include "iCBConstruct.h"\r
+#include "hpInput.h"\r
+#include "anaFilter.h"\r
+#include "syntFilter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  Initiation of encoder instance.\r
+ *---------------------------------------------------------------*/\r
+\r
+short initEncode(                   /* (o) Number of bytes \r
+                                           encoded */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+    int mode                    /* (i) frame size mode */\r
+){\r
+    iLBCenc_inst->mode = mode;\r
+    if (mode==30) {\r
+        iLBCenc_inst->blockl = BLOCKL_30MS;\r
+        iLBCenc_inst->nsub = NSUB_30MS;\r
+\r
+\r
+        iLBCenc_inst->nasub = NASUB_30MS;\r
+        iLBCenc_inst->lpc_n = LPC_N_30MS;\r
+        iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+        iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;\r
+        iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+        /* ULP init */\r
+        iLBCenc_inst->ULP_inst=&ULP_30msTbl;\r
+    }\r
+    else if (mode==20) {\r
+        iLBCenc_inst->blockl = BLOCKL_20MS;\r
+        iLBCenc_inst->nsub = NSUB_20MS;\r
+        iLBCenc_inst->nasub = NASUB_20MS;\r
+        iLBCenc_inst->lpc_n = LPC_N_20MS;\r
+        iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+        iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;\r
+        iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+        /* ULP init */\r
+        iLBCenc_inst->ULP_inst=&ULP_20msTbl;\r
+    }\r
+    else {\r
+        exit(2);\r
+    }\r
+\r
+    memset((*iLBCenc_inst).anaMem, 0, \r
+        LPC_FILTERORDER*sizeof(float));\r
+    memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,\r
+        LPC_FILTERORDER*sizeof(float));\r
+    memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,\r
+        LPC_FILTERORDER*sizeof(float));\r
+    memset((*iLBCenc_inst).lpc_buffer, 0, \r
+        (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));\r
+    memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));\r
+\r
+    return (iLBCenc_inst->no_of_bytes);\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  main encoder function \r
+ *---------------------------------------------------------------*/\r
+\r
+void iLBC_encode(\r
+    unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+    float *block,                   /* (o) speech vector to \r
+                                           encode */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                           state */\r
+){\r
+    \r
+    float data[BLOCKL_MAX];\r
+    float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];\r
+\r
+    int start, idxForMax, idxVec[STATE_LEN];\r
+    float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+    int n, k, meml_gotten, Nfor, Nback, i, pos;\r
+\r
+\r
+    int gain_index[CB_NSTAGES*NASUB_MAX], \r
+        extra_gain_index[CB_NSTAGES];\r
+    int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];\r
+    int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+    unsigned char *pbytes;\r
+    int diff, start_pos, state_first;\r
+    float en1, en2;\r
+    int index, ulp, firstpart;\r
+    int subcount, subframe;\r
+    float weightState[LPC_FILTERORDER];\r
+    float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+    float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+    float decresidual[BLOCKL_MAX];\r
+\r
+    /* high pass filtering of input signal if such is not done \r
+           prior to calling this function */\r
+\r
+    hpInput(block, iLBCenc_inst->blockl, \r
+                data, (*iLBCenc_inst).hpimem);\r
+\r
+    /* otherwise simply copy */\r
+\r
+    /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/\r
+        \r
+    /* LPC of hp filtered input data */\r
+\r
+    LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);\r
+\r
+\r
+    /* inverse filter to get residual */\r
+\r
+    for (n=0; n<iLBCenc_inst->nsub; n++) {\r
+        anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], \r
+            SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);\r
+    }\r
+\r
+    /* find state location */\r
+\r
+    start = FrameClassify(iLBCenc_inst, residual);\r
+    \r
+    /* check if state should be in first or last part of the \r
+    two subframes */\r
+\r
+    diff = STATE_LEN - iLBCenc_inst->state_short_len;\r
+    en1 = 0;\r
+    index = (start-1)*SUBL;\r
+    for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+        en1 += residual[index+i]*residual[index+i];\r
+    }\r
+    en2 = 0;\r
+    index = (start-1)*SUBL+diff;\r
+    for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+        en2 += residual[index+i]*residual[index+i];\r
+    }\r
+\r
+\r
+    \r
+    \r
+    if (en1 > en2) {\r
+        state_first = 1;\r
+        start_pos = (start-1)*SUBL;\r
+    } else {\r
+        state_first = 0;\r
+        start_pos = (start-1)*SUBL + diff;\r
+    }\r
+\r
+    /* scalar quantization of state */\r
+\r
+    StateSearchW(iLBCenc_inst, &residual[start_pos], \r
+        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+        &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, \r
+        idxVec, iLBCenc_inst->state_short_len, state_first);\r
+\r
+    StateConstructW(idxForMax, idxVec, \r
+        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+        &decresidual[start_pos], iLBCenc_inst->state_short_len);\r
+\r
+    /* predictive quantization in state */\r
+    \r
+    if (state_first) { /* put adaptive part in the end */\r
+        \r
+        /* setup memory */\r
+\r
+        memset(mem, 0, \r
+            (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));\r
+        memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, \r
+            decresidual+start_pos, \r
+            iLBCenc_inst->state_short_len*sizeof(float));\r
+        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+        /* encode sub-frames */\r
+\r
+        iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+            &residual[start_pos+iLBCenc_inst->state_short_len], \r
+            mem+CB_MEML-stMemLTbl,\r
+            stMemLTbl, diff, CB_NSTAGES, \r
+            &weightdenum[start*(LPC_FILTERORDER+1)], \r
+            weightState, 0);\r
+\r
+        /* construct decoded vector */\r
+\r
+        iCBConstruct(\r
+            &decresidual[start_pos+iLBCenc_inst->state_short_len],\r
+            extra_cb_index, extra_gain_index, \r
+            mem+CB_MEML-stMemLTbl, \r
+            stMemLTbl, diff, CB_NSTAGES);\r
+    \r
+    } \r
+    else { /* put adaptive part in the beginning */\r
+        \r
+\r
+\r
+        /* create reversed vectors for prediction */\r
+\r
+        for (k=0; k<diff; k++) {\r
+            reverseResidual[k] = residual[(start+1)*SUBL-1\r
+                -(k+iLBCenc_inst->state_short_len)];\r
+        }\r
+        \r
+        /* setup memory */\r
+\r
+        meml_gotten = iLBCenc_inst->state_short_len;\r
+        for (k=0; k<meml_gotten; k++) { \r
+            mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+        } \r
+        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+        \r
+        /* encode sub-frames */\r
+\r
+        iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+            reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+            diff, CB_NSTAGES, \r
+            &weightdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+            weightState, 0);\r
+\r
+        /* construct decoded vector */\r
+\r
+        iCBConstruct(reverseDecresidual, extra_cb_index, \r
+            extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+            diff, CB_NSTAGES);\r
+        \r
+        /* get decoded residual from reversed vector */\r
+\r
+        for (k=0; k<diff; k++) {\r
+            decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+        }\r
+    }\r
+\r
+    /* counter for predicted sub-frames */\r
+\r
+    subcount=0;\r
+\r
+    /* forward prediction of sub-frames */\r
+\r
+    Nfor = iLBCenc_inst->nsub-start-1;\r
+\r
+    \r
+    if ( Nfor > 0 ) {\r
+        \r
+        /* setup memory */\r
+\r
+        memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+        memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, \r
+            STATE_LEN*sizeof(float));\r
+        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+\r
+\r
+        /* loop over sub-frames to encode */\r
+\r
+        for (subframe=0; subframe<Nfor; subframe++) {\r
+\r
+            /* encode sub-frame */\r
+\r
+            iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                &residual[(start+1+subframe)*SUBL], \r
+                mem+CB_MEML-memLfTbl[subcount], \r
+                memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                &weightdenum[(start+1+subframe)*\r
+                            (LPC_FILTERORDER+1)],\r
+                weightState, subcount+1);\r
+\r
+            /* construct decoded vector */\r
+\r
+            iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                mem+CB_MEML-memLfTbl[subcount], \r
+                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+\r
+            /* update memory */\r
+\r
+            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+            memcpy(mem+CB_MEML-SUBL, \r
+                &decresidual[(start+1+subframe)*SUBL], \r
+                SUBL*sizeof(float));\r
+            memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+            subcount++;\r
+        }\r
+    }\r
+    \r
+\r
+    /* backward prediction of sub-frames */\r
+\r
+    Nback = start-1;\r
+\r
+    \r
+    if ( Nback > 0 ) {\r
+               \r
+        /* create reverse order vectors */\r
+\r
+        for (n=0; n<Nback; n++) {\r
+            for (k=0; k<SUBL; k++) {\r
+                reverseResidual[n*SUBL+k] = \r
+                    residual[(start-1)*SUBL-1-n*SUBL-k];\r
+                reverseDecresidual[n*SUBL+k] = \r
+                    decresidual[(start-1)*SUBL-1-n*SUBL-k];\r
+            }\r
+        }\r
+\r
+\r
+\r
+        /* setup memory */\r
+\r
+        meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);\r
+\r
+        \r
+        if ( meml_gotten > CB_MEML ) { \r
+            meml_gotten=CB_MEML;\r
+        }\r
+        for (k=0; k<meml_gotten; k++) { \r
+            mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+        } \r
+        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+        /* loop over sub-frames to encode */\r
+\r
+        for (subframe=0; subframe<Nback; subframe++) {\r
+            \r
+            /* encode sub-frame */\r
+\r
+            iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                &reverseResidual[subframe*SUBL], \r
+                mem+CB_MEML-memLfTbl[subcount], \r
+                memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                &weightdenum[(start-2-subframe)*\r
+                            (LPC_FILTERORDER+1)], \r
+                weightState, subcount+1);\r
+\r
+            /* construct decoded vector */\r
+\r
+            iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                cb_index+subcount*CB_NSTAGES, \r
+                gain_index+subcount*CB_NSTAGES, \r
+                mem+CB_MEML-memLfTbl[subcount], \r
+                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+\r
+            /* update memory */\r
+\r
+            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+            memcpy(mem+CB_MEML-SUBL, \r
+                &reverseDecresidual[subframe*SUBL],\r
+                SUBL*sizeof(float));\r
+            memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+\r
+            subcount++;\r
+\r
+        }\r
+\r
+        /* get decoded residual from reversed vector */\r
+\r
+        for (i=0; i<SUBL*Nback; i++) {\r
+            decresidual[SUBL*Nback - i - 1] = \r
+\r
+\r
+                reverseDecresidual[i];\r
+        }\r
+    }\r
+    /* end encoding part */\r
+\r
+    /* adjust index */\r
+    index_conv_enc(cb_index);\r
+\r
+    /* pack bytes */\r
+\r
+    pbytes=bytes;\r
+    pos=0;\r
+\r
+    /* loop over the 3 ULP classes */\r
+\r
+    for (ulp=0; ulp<3; ulp++) {\r
+    \r
+        /* LSF */\r
+        for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {\r
+            packsplit(&lsf_i[k], &firstpart, &lsf_i[k], \r
+                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], \r
+                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+\r
+                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+\r
+                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);\r
+            dopack( &pbytes, firstpart, \r
+                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+        }\r
+\r
+        /* Start block info */\r
+\r
+        packsplit(&start, &firstpart, &start, \r
+            iLBCenc_inst->ULP_inst->start_bits[ulp], \r
+            iLBCenc_inst->ULP_inst->start_bits[ulp]+\r
+            iLBCenc_inst->ULP_inst->start_bits[ulp+1]+\r
+            iLBCenc_inst->ULP_inst->start_bits[ulp+2]);\r
+        dopack( &pbytes, firstpart, \r
+            iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);\r
+\r
+        packsplit(&state_first, &firstpart, &state_first, \r
+            iLBCenc_inst->ULP_inst->startfirst_bits[ulp], \r
+            iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+\r
+            iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+\r
+            iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);\r
+        dopack( &pbytes, firstpart, \r
+            iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+\r
+        packsplit(&idxForMax, &firstpart, &idxForMax, \r
+            iLBCenc_inst->ULP_inst->scale_bits[ulp], \r
+            iLBCenc_inst->ULP_inst->scale_bits[ulp]+\r
+            iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+\r
+            iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);\r
+        dopack( &pbytes, firstpart, \r
+            iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);\r
+\r
+\r
+\r
+        for (k=0; k<iLBCenc_inst->state_short_len; k++) {\r
+            packsplit(idxVec+k, &firstpart, idxVec+k, \r
+                iLBCenc_inst->ULP_inst->state_bits[ulp], \r
+                iLBCenc_inst->ULP_inst->state_bits[ulp]+\r
+                iLBCenc_inst->ULP_inst->state_bits[ulp+1]+\r
+                iLBCenc_inst->ULP_inst->state_bits[ulp+2]);\r
+            dopack( &pbytes, firstpart, \r
+                iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);\r
+        }\r
+\r
+        /* 23/22 (20ms/30ms) sample block */\r
+\r
+        for (k=0;k<CB_NSTAGES;k++) {\r
+            packsplit(extra_cb_index+k, &firstpart, \r
+                extra_cb_index+k, \r
+                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+\r
+                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+\r
+                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);\r
+            dopack( &pbytes, firstpart, \r
+                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                &pos);\r
+        }\r
+\r
+        for (k=0;k<CB_NSTAGES;k++) {\r
+            packsplit(extra_gain_index+k, &firstpart, \r
+                extra_gain_index+k, \r
+                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+\r
+                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+\r
+                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);\r
+            dopack( &pbytes, firstpart, \r
+                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                &pos);\r
+        }\r
+            \r
+        /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+\r
+        for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+                packsplit(cb_index+i*CB_NSTAGES+k, &firstpart, \r
+                    cb_index+i*CB_NSTAGES+k, \r
+                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+\r
+                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+\r
+                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);\r
+                dopack( &pbytes, firstpart, \r
+                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                    &pos);\r
+            }\r
+        }\r
+        \r
+        for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+            for (k=0; k<CB_NSTAGES; k++) {\r
+\r
+\r
+                packsplit(gain_index+i*CB_NSTAGES+k, &firstpart, \r
+                    gain_index+i*CB_NSTAGES+k, \r
+                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+\r
+                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+\r
+                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);\r
+                dopack( &pbytes, firstpart, \r
+                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                    &pos);\r
+            }\r
+        }\r
+    }\r
+\r
+    /* set the last bit to zero (otherwise the decoder \r
+       will treat it as a lost frame) */\r
+    dopack( &pbytes, 0, 1, &pos);\r
+}\r
+\r
+\r
+\r
diff --git a/libs/codec/ilbc/iLBC_encode.h b/libs/codec/ilbc/iLBC_encode.h
new file mode 100644 (file)
index 0000000..dc46790
--- /dev/null
@@ -0,0 +1,37 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    iLBC_encode.h    \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_ILBCENCODE_H\r
+#define __iLBC_ILBCENCODE_H\r
+\r
+#include "iLBC_define.h"\r
+\r
+short initEncode(                   /* (o) Number of bytes \r
+                                           encoded */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+    int mode                    /* (i) frame size mode */\r
+);\r
+\r
+void iLBC_encode(\r
+\r
+\r
+    unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+    float *block,                   /* (o) speech vector to \r
+                                           encode */\r
+    iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                           state */\r
+);\r
+\r
+#endif\r
+\r
+\r
+\r
diff --git a/libs/codec/ilbc/lsf.c b/libs/codec/ilbc/lsf.c
new file mode 100644 (file)
index 0000000..1be19da
--- /dev/null
@@ -0,0 +1,264 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    lsf.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <string.h>\r
+#include <math.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "lsf.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  conversion from lpc coefficients to lsf coefficients \r
+ *---------------------------------------------------------------*/\r
+\r
+void a2lsf( \r
+    float *freq,/* (o) lsf coefficients */\r
+    float *a    /* (i) lpc coefficients */\r
+){\r
+    float steps[LSF_NUMBER_OF_STEPS] = \r
+        {(float)0.00635, (float)0.003175, (float)0.0015875, \r
+        (float)0.00079375};\r
+    float step;\r
+    int step_idx;\r
+    int lsp_index;  \r
+    float p[LPC_HALFORDER];\r
+    float q[LPC_HALFORDER];\r
+    float p_pre[LPC_HALFORDER];\r
+\r
+\r
+    float q_pre[LPC_HALFORDER];\r
+    float old_p, old_q, *old;\r
+    float *pq_coef; \r
+    float omega, old_omega;\r
+    int i;\r
+    float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;\r
+\r
+    for (i=0; i<LPC_HALFORDER; i++) {\r
+        p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);\r
+        q[i] = a[LPC_FILTERORDER - i] - a[i + 1];\r
+    }\r
+    \r
+    p_pre[0] = (float)-1.0 - p[0];\r
+    p_pre[1] = - p_pre[0] - p[1];\r
+    p_pre[2] = - p_pre[1] - p[2];\r
+    p_pre[3] = - p_pre[2] - p[3];\r
+    p_pre[4] = - p_pre[3] - p[4];\r
+    p_pre[4] = p_pre[4] / 2;\r
+    \r
+    q_pre[0] = (float)1.0 - q[0];\r
+    q_pre[1] = q_pre[0] - q[1];\r
+    q_pre[2] = q_pre[1] - q[2];\r
+    q_pre[3] = q_pre[2] - q[3];\r
+    q_pre[4] = q_pre[3] - q[4];\r
+    q_pre[4] = q_pre[4] / 2;\r
+    \r
+    omega = 0.0;\r
+    old_omega = 0.0;\r
+\r
+    old_p = FLOAT_MAX;\r
+    old_q = FLOAT_MAX;\r
+    \r
+    /* Here we loop through lsp_index to find all the \r
+       LPC_FILTERORDER roots for omega. */  \r
+\r
+    for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {\r
+        \r
+        /* Depending on lsp_index being even or odd, we \r
+        alternatively solve the roots for the two LSP equations. */\r
+\r
+        \r
+        if ((lsp_index & 0x1) == 0) {\r
+            pq_coef = p_pre;\r
+            old = &old_p;\r
+        } else {\r
+            pq_coef = q_pre;\r
+            old = &old_q;\r
+        }\r
+        \r
+        /* Start with low resolution grid */\r
+\r
+        for (step_idx = 0, step = steps[step_idx]; \r
+            step_idx < LSF_NUMBER_OF_STEPS;){\r
+            \r
+\r
+\r
+            /*  cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + \r
+            pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */\r
+\r
+            hlp = (float)cos(omega * TWO_PI);\r
+            hlp1 = (float)2.0 * hlp + pq_coef[0];\r
+            hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 + \r
+                pq_coef[1];\r
+            hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];\r
+            hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];\r
+            hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];\r
+            \r
+            \r
+            if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){\r
+                \r
+                if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){\r
+                    \r
+                    if (fabs(hlp5) >= fabs(*old)) {\r
+                        freq[lsp_index] = omega - step;\r
+                    } else {\r
+                        freq[lsp_index] = omega;\r
+                    }   \r
+                    \r
+                    \r
+                    if ((*old) >= 0.0){\r
+                        *old = (float)-1.0 * FLOAT_MAX;\r
+                    } else {\r
+                        *old = FLOAT_MAX;\r
+                    }\r
+\r
+                    omega = old_omega;\r
+                    step_idx = 0;\r
+                    \r
+                    step_idx = LSF_NUMBER_OF_STEPS;\r
+                } else {\r
+                    \r
+                    if (step_idx == 0) {\r
+                        old_omega = omega;\r
+                    }\r
+\r
+                    step_idx++;\r
+                    omega -= steps[step_idx];\r
+\r
+                    /* Go back one grid step */\r
+\r
+                    step = steps[step_idx];\r
+                }\r
+            } else {\r
+                \r
+            /* increment omega until they are of different sign, \r
+            and we know there is at least one root between omega \r
+            and old_omega */\r
+                *old = hlp5;\r
+                omega += step;\r
+            }\r
+\r
+\r
+        }\r
+    }\r
+\r
+    for (i = 0; i<LPC_FILTERORDER; i++) {\r
+        freq[i] = freq[i] * TWO_PI;\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  conversion from lsf coefficients to lpc coefficients \r
+ *---------------------------------------------------------------*/\r
+\r
+void lsf2a( \r
+    float *a_coef,  /* (o) lpc coefficients */\r
+    float *freq     /* (i) lsf coefficients */\r
+){\r
+    int i, j;\r
+    float hlp;\r
+    float p[LPC_HALFORDER], q[LPC_HALFORDER];\r
+    float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],\r
+        a2[LPC_HALFORDER];\r
+    float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], \r
+        b2[LPC_HALFORDER];\r
+\r
+    for (i=0; i<LPC_FILTERORDER; i++) {\r
+        freq[i] = freq[i] * PI2;\r
+    }\r
+\r
+    /* Check input for ill-conditioned cases.  This part is not \r
+    found in the TIA standard.  It involves the following 2 IF \r
+    blocks. If "freq" is judged ill-conditioned, then we first \r
+    modify freq[0] and freq[LPC_HALFORDER-1] (normally \r
+    LPC_HALFORDER = 10 for LPC applications), then we adjust \r
+    the other "freq" values slightly */\r
+\r
+    \r
+    if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){\r
+\r
+        \r
+        if (freq[0] <= 0.0) {\r
+            freq[0] = (float)0.022;\r
+        }\r
+\r
+        \r
+        if (freq[LPC_FILTERORDER - 1] >= 0.5) {\r
+            freq[LPC_FILTERORDER - 1] = (float)0.499;\r
+        }\r
+\r
+        hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / \r
+            (float) (LPC_FILTERORDER - 1);\r
+\r
+        for (i=1; i<LPC_FILTERORDER; i++) {\r
+            freq[i] = freq[i - 1] + hlp;\r
+        }\r
+\r
+\r
+    }\r
+    \r
+    memset(a1, 0, LPC_HALFORDER*sizeof(float));\r
+    memset(a2, 0, LPC_HALFORDER*sizeof(float));\r
+    memset(b1, 0, LPC_HALFORDER*sizeof(float));\r
+    memset(b2, 0, LPC_HALFORDER*sizeof(float));\r
+    memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+    memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+        \r
+    /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and \r
+    cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.  \r
+    Note that for this code p[i] specifies the coefficients \r
+    used in .Q_A(z) while q[i] specifies the coefficients used \r
+    in .P_A(z) */\r
+\r
+    for (i=0; i<LPC_HALFORDER; i++) {\r
+        p[i] = (float)cos(TWO_PI * freq[2 * i]);\r
+        q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);\r
+    }\r
+    \r
+    a[0] = 0.25;\r
+    b[0] = 0.25;\r
+    \r
+    for (i= 0; i<LPC_HALFORDER; i++) {\r
+        a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+        b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+        a2[i] = a1[i];\r
+        a1[i] = a[i];\r
+        b2[i] = b1[i];\r
+        b1[i] = b[i];\r
+    }\r
+    \r
+    for (j=0; j<LPC_FILTERORDER; j++) {\r
+        \r
+        if (j == 0) {\r
+            a[0] = 0.25;\r
+            b[0] = -0.25;\r
+        } else {\r
+            a[0] = b[0] = 0.0;\r
+        }\r
+        \r
+        for (i=0; i<LPC_HALFORDER; i++) {\r
+            a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+            b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+            a2[i] = a1[i];\r
+            a1[i] = a[i];\r
+            b2[i] = b1[i];\r
+            b1[i] = b[i];\r
+        }\r
+\r
+        a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);\r
+    }\r
+\r
+    a_coef[0] = 1.0;\r
+\r
+\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/lsf.h b/libs/codec/ilbc/lsf.h
new file mode 100644 (file)
index 0000000..02f270a
--- /dev/null
@@ -0,0 +1,30 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    lsf.h             \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_LSF_H\r
+#define __iLBC_LSF_H\r
+\r
+void a2lsf( \r
+    float *freq,/* (o) lsf coefficients */\r
+    float *a    /* (i) lpc coefficients */\r
+);\r
+\r
+void lsf2a( \r
+    float *a_coef,  /* (o) lpc coefficients */\r
+    float *freq     /* (i) lsf coefficients */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/packing.c b/libs/codec/ilbc/packing.c
new file mode 100644 (file)
index 0000000..c6e1980
--- /dev/null
@@ -0,0 +1,175 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    packing.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include <math.h>\r
+#include <stdlib.h>\r
+\r
+#include "iLBC_define.h"\r
+#include "constants.h"\r
+#include "helpfun.h"\r
+#include "packing.h"\r
+#include "string.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  splitting an integer into first most significant bits and \r
+ *  remaining least significant bits\r
+ *---------------------------------------------------------------*/\r
+\r
+void packsplit(\r
+    int *index,                 /* (i) the value to split */\r
+    int *firstpart,             /* (o) the value specified by most \r
+                                       significant bits */\r
+    int *rest,                  /* (o) the value specified by least\r
+                                       significant bits */\r
+    int bitno_firstpart,    /* (i) number of bits in most \r
+                                       significant part */\r
+    int bitno_total             /* (i) number of bits in full range\r
+                                       of value */\r
+){\r
+    int bitno_rest = bitno_total-bitno_firstpart;\r
+\r
+\r
+\r
+    *firstpart = *index>>(bitno_rest);\r
+    *rest = *index-(*firstpart<<(bitno_rest));\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  combining a value corresponding to msb's with a value \r
+ *  corresponding to lsb's\r
+ *---------------------------------------------------------------*/\r
+\r
+void packcombine( \r
+    int *index,                 /* (i/o) the msb value in the \r
+                                       combined value out */\r
+    int rest,                   /* (i) the lsb value */\r
+    int bitno_rest              /* (i) the number of bits in the \r
+                                       lsb part */\r
+){\r
+    *index = *index<<bitno_rest;\r
+    *index += rest;\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  packing of bits into bitstream, i.e., vector of bytes\r
+ *---------------------------------------------------------------*/\r
+\r
+void dopack( \r
+    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                       place in bitstream to pack \r
+                                       new data, on exit pointer \r
+                                       to place in bitstream to \r
+                                       pack future data */\r
+    int index,                  /* (i) the value to pack */\r
+    int bitno,                  /* (i) the number of bits that the \r
+                                       value will fit within */\r
+    int *pos                /* (i/o) write position in the \r
+                                       current byte */\r
+){\r
+    int posLeft;\r
+    \r
+    /* Clear the bits before starting in a new byte */\r
+    \r
+    if ((*pos)==0) {\r
+        **bitstream=0;\r
+    }\r
+\r
+    while (bitno>0) {\r
+        \r
+        /* Jump to the next byte if end of this byte is reached*/\r
+        \r
+        if (*pos==8) {\r
+            *pos=0;\r
+            (*bitstream)++;\r
+            **bitstream=0;\r
+        }\r
+\r
+\r
+\r
+        posLeft=8-(*pos);\r
+\r
+        /* Insert index into the bitstream */\r
+        \r
+        if (bitno <= posLeft) {\r
+            **bitstream |= (unsigned char)(index<<(posLeft-bitno));\r
+            *pos+=bitno;\r
+            bitno=0;\r
+        } else {\r
+            **bitstream |= (unsigned char)(index>>(bitno-posLeft));\r
+            \r
+            *pos=8;\r
+            index-=((index>>(bitno-posLeft))<<(bitno-posLeft));\r
+            \r
+            bitno-=posLeft;\r
+        }\r
+    }\r
+}\r
+\r
+/*----------------------------------------------------------------*\r
+ *  unpacking of bits from bitstream, i.e., vector of bytes\r
+ *---------------------------------------------------------------*/\r
+\r
+void unpack( \r
+    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                       place in bitstream to \r
+                                       unpack new data from, on \r
+                                       exit pointer to place in \r
+                                       bitstream to unpack future \r
+                                       data from */\r
+    int *index,                 /* (o) resulting value */\r
+    int bitno,                  /* (i) number of bits used to \r
+                                       represent the value */\r
+    int *pos                /* (i/o) read position in the \r
+                                       current byte */\r
+){\r
+    int BitsLeft;\r
+\r
+    *index=0;\r
+\r
+    while (bitno>0) {\r
+        \r
+        /* move forward in bitstream when the end of the \r
+           byte is reached */\r
+        \r
+        if (*pos==8) {\r
+            *pos=0;\r
+            (*bitstream)++;\r
+        }\r
+\r
+        BitsLeft=8-(*pos);\r
+\r
+        /* Extract bits to index */\r
+        \r
+\r
+\r
+        if (BitsLeft>=bitno) {\r
+            *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));\r
+            \r
+            *pos+=bitno;\r
+            bitno=0;\r
+        } else {\r
+            \r
+            if ((8-bitno)>0) {\r
+                *index+=((((**bitstream)<<(*pos)) & 0xFF)>>\r
+                    (8-bitno));\r
+                *pos=8;\r
+            } else {\r
+                *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<\r
+                    (bitno-8));\r
+                *pos=8;\r
+            }\r
+            bitno-=BitsLeft;\r
+        }\r
+    }\r
+}\r
+\r
+\r
diff --git a/libs/codec/ilbc/packing.h b/libs/codec/ilbc/packing.h
new file mode 100644 (file)
index 0000000..77db258
--- /dev/null
@@ -0,0 +1,67 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    packing.h              \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __PACKING_H\r
+#define __PACKING_H\r
+\r
+void packsplit(\r
+    int *index,                 /* (i) the value to split */\r
+    int *firstpart,             /* (o) the value specified by most \r
+                                       significant bits */\r
+    int *rest,                  /* (o) the value specified by least \r
+                                       significant bits */\r
+    int bitno_firstpart,    /* (i) number of bits in most \r
+                                       significant part */\r
+    int bitno_total             /* (i) number of bits in full range \r
+                                       of value */\r
+);\r
+\r
+void packcombine( \r
+    int *index,                 /* (i/o) the msb value in the \r
+                                       combined value out */\r
+    int rest,                   /* (i) the lsb value */\r
+    int bitno_rest              /* (i) the number of bits in the \r
+                                       lsb part */\r
+);\r
+\r
+void dopack( \r
+    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                       place in bitstream to pack \r
+                                       new data, on exit pointer \r
+                                       to place in bitstream to \r
+                                       pack future data */\r
+    int index,                  /* (i) the value to pack */\r
+    int bitno,                  /* (i) the number of bits that the \r
+                                       value will fit within */\r
+    int *pos                /* (i/o) write position in the \r
+                                       current byte */\r
+);\r
+\r
+void unpack( \r
+    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+\r
+\r
+                                       place in bitstream to \r
+                                       unpack new data from, on \r
+                                       exit pointer to place in \r
+                                       bitstream to unpack future \r
+                                       data from */\r
+    int *index,                 /* (o) resulting value */\r
+    int bitno,                  /* (i) number of bits used to \r
+                                       represent the value */\r
+    int *pos                /* (i/o) read position in the \r
+                                       current byte */\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/ilbc/syntFilter.c b/libs/codec/ilbc/syntFilter.c
new file mode 100644 (file)
index 0000000..ff2e714
--- /dev/null
@@ -0,0 +1,108 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    syntFilter.c \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#include "iLBC_define.h"\r
+#include "syntFilter.h"\r
+\r
+/*----------------------------------------------------------------*\r
+ *  LP synthesis filter.\r
+ *---------------------------------------------------------------*/\r
+    \r
+void syntFilter(\r
+    float *Out,     /* (i/o) Signal to be filtered */\r
+    float *a,       /* (i) LP parameters */\r
+    int len,    /* (i) Length of signal */\r
+    float *mem      /* (i/o) Filter state */\r
+){\r
+    int i, j;\r
+    float *po, *pi, *pa, *pm;\r
+\r
+    po=Out;\r
+\r
+    /* Filter first part using memory from past */\r
+\r
+    for (i=0; i<LPC_FILTERORDER; i++) {\r
+        pi=&Out[i-1];\r
+        pa=&a[1];\r
+        pm=&mem[LPC_FILTERORDER-1];\r
+        for (j=1; j<=i; j++) {\r
+            *po-=(*pa++)*(*pi--);\r
+        }\r
+        for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+            *po-=(*pa++)*(*pm--);\r
+        }\r
+        po++;\r
+    }\r
+\r
+    /* Filter last part where the state is entierly in \r
+       the output vector */\r
+    \r
+    for (i=LPC_FILTERORDER; i<len; i++) {\r
+\r
+\r
+        pi=&Out[i-1];\r
+        pa=&a[1];\r
+        for (j=1; j<LPC_FILTERORDER+1; j++) {\r
+            *po-=(*pa++)*(*pi--);\r
+        }\r
+        po++;\r
+    }\r
+\r
+    /* Update state vector */\r
+\r
+    memcpy(mem, &Out[len-LPC_FILTERORDER], \r
+        LPC_FILTERORDER*sizeof(float));\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
diff --git a/libs/codec/ilbc/syntFilter.h b/libs/codec/ilbc/syntFilter.h
new file mode 100644 (file)
index 0000000..9e1ad3f
--- /dev/null
@@ -0,0 +1,27 @@
+\r
+/******************************************************************\r
+\r
+    iLBC Speech Coder ANSI-C Source Code\r
+\r
+    syntFilter.h               \r
+\r
+    Copyright (C) The Internet Society (2004). \r
+    All Rights Reserved.\r
+\r
+******************************************************************/\r
+\r
+#ifndef __iLBC_SYNTFILTER_H\r
+#define __iLBC_SYNTFILTER_H\r
+\r
+void syntFilter(\r
+    float *Out,     /* (i/o) Signal to be filtered */\r
+    float *a,       /* (i) LP parameters */\r
+    int len,    /* (i) Length of signal */\r
+    float *mem      /* (i/o) Filter state */\r
+\r
+\r
+);\r
+\r
+#endif\r
+\r
+\r
diff --git a/libs/codec/lpc10/Makefile b/libs/codec/lpc10/Makefile
new file mode 100644 (file)
index 0000000..ccb3141
--- /dev/null
@@ -0,0 +1,75 @@
+# \r
+# Makefile for LPC-10 speech coder library (unix)\r
+# \r
+\r
+# default C compiler\r
+CC?= gcc\r
+\r
+# \r
+# These definitions for CFLAGS and LIB_TARGET_DIR are used when one\r
+# runs make in the lpc10 directory, without environment variables that\r
+# override them.  When make is run in this directory from a makefile\r
+# for an application that uses the LPC10 coder, there are environment\r
+# variables set for CFLAGS and LIB_TARGET_DIR that override these\r
+# definitions.\r
+# \r
+\r
+LIB_TARGET_DIR = .\r
+\r
+# \r
+# -I$(LIB_TARGET_DIR) option needed so that #include "machine.h"\r
+# directives can find the machine.h file.\r
+# \r
+\r
+WARNINGS = -Wall -Wno-comment -Wno-error\r
+CFLAGS += $(OPTIMIZE) -I$(LIB_TARGET_DIR) $(WARNINGS)\r
+ifneq (${OSARCH},CYGWIN)\r
+CFLAGS += -fPIC\r
+endif\r
+#CFLAGS+= $(shell if uname -m | grep -q 86; then echo "-mpentium" ; fi)\r
+\r
+#fix for PPC processors and ALPHA, And UltraSparc too\r
+ifneq ($(OSARCH),Darwin)\r
+ifneq ($(findstring BSD,${OSARCH}),BSD)\r
+ifneq ($(PROC),ppc)\r
+ifneq ($(PROC),x86_64)\r
+ifneq ($(PROC),alpha)\r
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.\r
+#This works for even old (2.96) versions of gcc and provides a small boost either way.\r
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.\r
+#So we go lowest common available by gcc and go a step down, still a step up from\r
+#the default as we now have a better instruction set to work with. - Belgarath\r
+ifeq ($(PROC),ultrasparc)\r
+        CFLAGS+= -mtune=$(PROC) -mcpu=v8 -O3 -fomit-frame-pointer\r
+else\r
+ifneq ($(OSARCH),SunOS)\r
+ifneq  ($(OSARCH),arm)\r
+#        CFLAGS+= -march=$(PROC)\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+endif\r
+\r
+LIB = $(LIB_TARGET_DIR)/liblpc10.a\r
+\r
+.PHONY: all clean\r
+\r
+all:   $(LIB)\r
+\r
+OBJ=   f2clib.o analys.o bsynz.o chanwr.o dcbias.o decode.o \\r
+               deemp.o difmag.o dyptrk.o encode.o energy.o ham84.o \\r
+               hp100.o invert.o irc2pc.o ivfilt.o lpcdec.o lpcenc.o \\r
+               lpcini.o lpfilt.o median.o mload.o onset.o pitsyn.o \\r
+               placea.o placev.o preemp.o prepro.o random.o rcchk.o \\r
+               synths.o tbdm.o voicin.o vparms.o\r
+\r
+$(LIB): $(OBJ)\r
+       $(AR) cr $@ $(OBJ)\r
+       ranlib $@\r
+\r
+clean:\r
+       -rm -f *.o $(LIB)\r
diff --git a/libs/codec/lpc10/README b/libs/codec/lpc10/README
new file mode 100644 (file)
index 0000000..6dc1851
--- /dev/null
@@ -0,0 +1,89 @@
+Tue Aug 20 16:19:51 CDT 1996\r
+Andy Fingerhut (jaf@arl.wustl.edu)\r
+\r
+In release 1.4, there are quite a few hand modifications to the C code\r
+that was automatically created from the Fortran code with f2c.  They\r
+are all summarized in change log comments at the beginning of the\r
+changed files.  All of the original files from f2c were checked in to\r
+RCS before modification, so it is possible to see exactly what changes\r
+were made, for the extremely curious.  That precaution was also for my\r
+benefit, in case I ever recompile the Fortran sources, and want to\r
+make similar changes to that new C source code.\r
+\r
+Below is the README file for this directory included with the 1.3\r
+release of the LPC-10 package.  A few parts of it are a little out of\r
+date, but it is correct for the most part.\r
+\r
+\r
+Sun Jul  7 15:30:31 CDT 1996\r
+Andy Fingerhut (jaf@arl.wustl.edu)\r
+\r
+To create the LPC-10 library, copy the appropriate makefile to the\r
+proper name for easy use, e.g., for Unix, copy makefile.unx to the\r
+file "Makefile".  The file makefile.dos has been used with some\r
+version of the 'nmake' utility that comes with the Microsoft C\r
+compiler (the same one used for Nautilus v1.5a, which I believe\r
+specifies Microsoft C version 7.0 or later).\r
+\r
+Then edit the file lpc10.h in the directory above.  It should already\r
+be set up to work properly on any Unix compiler for which "int" is 32\r
+bits and "short" is 16 bits, and under the Microsoft C compiler\r
+configured so that "long" is 32 bits and "int" is 16 bits.  There must\r
+be a typedef for the two types INT32 and INT16 in that file.  You\r
+should choose types that compile to those sizes using your compiler,\r
+because there are places in the LPC-10 code that expect INT16's to\r
+have exactly 16 bits (at least, I *think* they must be no larger), and\r
+INT32's to have exactly 32 bits.\r
+\r
+\r
+A few notes on how these files were created\r
+-------------------------------------------\r
+\r
+(This section is mostly for my benefit, so I can remember what I did.\r
+You don't need to read it if you just want to use this package.  It\r
+might be useful to read it if you change the Fortran sources and want\r
+to recreate a usable library of C sources.  -- Andy)\r
+\r
+These C sources were created automatically from the Fortran sources\r
+using f2c, for the most part.  Listed below are the extra\r
+modifications that were made after this automatic conversion.  Many of\r
+them were made so that it was not necessary to install f2c in order to\r
+use this LPC-10 coder.\r
+\r
+1.\r
+\r
+Put all of those files that were necessary for only the coder, rather\r
+than an application that uses the coder, into this subdirectory called\r
+lpc10.\r
+\r
+2.\r
+\r
+Copied f2c.h from the f2c distribution into this subdirectory.  Some\r
+modifications were made to the "typedef" statements in this file, to\r
+explicitly indicate the sizes (in bits) that different integer types\r
+should be.  The types INT32 and INT16 must be defined in a file called\r
+lpc10.h in the directory above.  Created the file f2clib.c, containing\r
+only the functions pow_ii(), r_sign(), and i_nint() from the f2c\r
+library.\r
+\r
+3.\r
+\r
+The f2c output originally had a file called contrl_com.c, that defined\r
+a small structure containing a few variables that were used in many\r
+different functions of the LPC10 code.  Every file containing\r
+functions that used it defined it as "extern", while contrl_com.c\r
+actually allocated storage for the structure.  Bill Dorsey, one of the\r
+lead developers of Nautilus, said that the Microsoft C compiler had\r
+problems either compiling this file, or linking it with all of the\r
+other compiled files, so he just eliminated that file and removed the\r
+"extern" keyword from the one of the files that declared it that way.\r
+The file chosen (arbitrarily) was analys.c.\r
+\r
+4.\r
+\r
+Copied the makefiles for Unix and Microsoft C from the Nautilus v1.5a\r
+distribution into the lpc10 directory.  Modified them to take out\r
+references to Nautilus.  These makefiles don't create an executable,\r
+but a library of compiled functions called liblpc10.a (Unix) or\r
+LPC10.LIB (DOS).  This library can be used when linking an executable\r
+that calls the functions lpcini_(), lpcenc_(), and lpcdec_().\r
diff --git a/libs/codec/lpc10/analys.c b/libs/codec/lpc10/analys.c
new file mode 100644 (file)
index 0000000..007a09e
--- /dev/null
@@ -0,0 +1,649 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.2  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:16:01  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:29:08  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: preemp_ 14 5 6 6 4 6 6 */\r
+/*:ref: onset_ 14 7 6 4 4 4 4 4 4 */\r
+/*:ref: placev_ 14 11 4 4 4 4 4 4 4 4 4 4 4 */\r
+/*:ref: lpfilt_ 14 4 6 6 4 4 */\r
+/*:ref: ivfilt_ 14 5 6 6 4 4 6 */\r
+/*:ref: tbdm_ 14 8 6 4 4 4 6 4 4 4 */\r
+/*:ref: voicin_ 14 12 4 6 6 4 4 6 6 4 6 4 4 4 */\r
+/*:ref: dyptrk_ 14 6 6 4 4 4 4 4 */\r
+/*:ref: placea_ 14 9 4 4 4 4 4 4 4 4 4 */\r
+/*:ref: dcbias_ 14 3 4 6 6 */\r
+/*:ref: energy_ 14 3 4 6 6 */\r
+/*:ref: mload_ 14 6 4 4 4 6 6 6 */\r
+/*:ref: invert_ 14 4 4 6 6 6 */\r
+/*:ref: rcchk_ 14 3 4 6 6 */\r
+/*:ref: initonset_ 14 0 */\r
+/*:ref: initvoicin_ 14 0 */\r
+/*:ref: initdyptrk_ 14 0 */\r
+/* Rerunning f2c -P may change prototypes or declarations. */\r
+#endif\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__10 = 10;\r
+static integer c__181 = 181;\r
+static integer c__720 = 720;\r
+static integer c__3 = 3;\r
+static integer c__90 = 90;\r
+static integer c__156 = 156;\r
+static integer c__307 = 307;\r
+static integer c__462 = 462;\r
+static integer c__312 = 312;\r
+static integer c__60 = 60;\r
+static integer c__1 = 1;\r
+\r
+/* ****************************************************************** */\r
+\r
+/*     ANALYS Version 55 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:16:01  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:29:08  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.9  1996/05/23  19:41:07  jaf */\r
+/* Commented out some unnecessary lines that were reading uninitialized */\r
+/* values. */\r
+\r
+/* Revision 1.8  1996/03/27  23:57:55  jaf */\r
+/* Added some comments about which indices of the local buffers INBUF, */\r
+/* LPBUF, etc., get read or modified by some of the subroutine calls.  I */\r
+/* just did this while trying to figure out the discrepancy between the */\r
+/* embedded code compiled with all local variables implicitly saved, and */\r
+/* without. */\r
+\r
+/* I added some debugging write statements in hopes of finding a problem. */\r
+/* None of them ever printed anything while running with the long input */\r
+/* speech file dam9.spd provided in the distribution. */\r
+\r
+/* Revision 1.7  1996/03/27  18:06:20  jaf */\r
+/* Commented out access to MAXOSP, which is just a debugging variable */\r
+/* that was defined in the COMMON block CONTRL in contrl.fh. */\r
+\r
+/* Revision 1.6  1996/03/26  19:31:33  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.5  1996/03/21  15:19:35  jaf */\r
+/* Added comments for ENTRY PITDEC. */\r
+\r
+/* Revision 1.4  1996/03/19  20:54:27  jaf */\r
+/* Added a line to INITANALYS.  See comments there. */\r
+\r
+/* Revision 1.3  1996/03/19  20:52:49  jaf */\r
+/* Rearranged the order of the local variables quite a bit, to separate */\r
+/* them into groups of "constants", "locals that don't need to be saved */\r
+/* from one call to the next", and "local that do need to be saved from */\r
+/* one call to the next". */\r
+\r
+/* Several locals in the last set should have been given initial values, */\r
+/* but weren't.  I gave them all initial values of 0. */\r
+\r
+/* Added a separate ENTRY INITANALYS that initializes all local state */\r
+/* that should be, and also calls the corresponding entries of the */\r
+/* subroutines called by ANALYS that also have local state. */\r
+\r
+/* There used to be DATA statements in ANALYS.  I got rid of most of */\r
+/* them, and added a local logical variable FIRST that calls the entry */\r
+/* INITANALYS on the first call to ANALYS.  This is just so that one need */\r
+/* not remember to call INITANALYS first in order for the state to be */\r
+/* initialized. */\r
+\r
+/* Revision 1.2  1996/03/11  23:29:32  jaf */\r
+/* Added several comments with my own personal questions about the */\r
+/* Fortran 77 meaning of the parameters passed to the subroutine PREEMP. */\r
+\r
+/* Revision 1.1  1996/02/07  14:42:29  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ****************************************************************** */\r
+\r
+/* SUBROUTINE ANALYS */\r
+\r
+/* Input: */\r
+/*  SPEECH */\r
+/*       Indices 1 through LFRAME read. */\r
+/* Output: */\r
+/*  VOICE */\r
+/*       Indices 1 through 2 written. */\r
+/*  PITCH */\r
+/*       Written in subroutine DYPTRK, and then perhaps read and written */\r
+/*       some more. */\r
+/*  RMS */\r
+/*       Written. */\r
+/*  RC */\r
+/*       Indices 1 through ORDER written (ORDER defined in contrl.fh). */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITANALYS. */\r
+\r
+\r
+/* ENTRY PITDEC */\r
+\r
+/* Input: */\r
+/*  PITCH   - Encoded pitch index */\r
+/* Output: */\r
+/*  PTAU    - Decoded pitch period */\r
+\r
+/* This entry has no local state.  It accesses a "constant" array */\r
+/* declared in ANALYS. */\r
+\r
+/* Subroutine */ int analys_(real *speech, integer *voice, integer \r
+       *pitch, real *rms, real *rc, struct lpc10_encoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    static integer tau[60] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,\r
+           35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,\r
+           74,76,78,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,\r
+           140,144,148,152,156 };\r
+    static integer buflim[4] = { 181,720,25,720 };\r
+    static real precoef = .9375f;\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    real amdf[60];\r
+    integer half;\r
+    real abuf[156];\r
+    real *bias;\r
+    extern /* Subroutine */ int tbdm_(real *, integer *, integer *, integer *,\r
+            real *, integer *, integer *, integer *);\r
+    integer *awin;\r
+    integer midx, ewin[6]      /* was [2][3] */;\r
+    real ivrc[2], temp;\r
+    real *zpre;\r
+    integer *vwin;\r
+    integer i__, j, lanal;\r
+    extern /* Subroutine */ int rcchk_(integer *, real *, real *), mload_(\r
+           integer *, integer *, integer *, real *, real *, real *);\r
+    real *inbuf, *pebuf;\r
+    real *lpbuf, *ivbuf;\r
+    real *rcbuf;\r
+    integer *osbuf;\r
+    extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *\r
+           , integer *, integer *, integer *, struct lpc10_encoder_state *);\r
+    integer *osptr;\r
+    extern int dcbias_(integer *, real *, real *);\r
+    integer ipitch;\r
+    integer *obound;\r
+    extern /* Subroutine */ int preemp_(real *, real *, integer *, real *, \r
+           real *), voicin_(integer *, real *, real *, integer *, integer *, \r
+           real *, real *, integer *, real *, integer *, integer *, integer *,\r
+           struct lpc10_encoder_state *);\r
+    integer *voibuf;\r
+    integer mintau;\r
+    real *rmsbuf;\r
+    extern /* Subroutine */ int lpfilt_(real *, real *, integer *, integer *),\r
+            ivfilt_(real *, real *, integer *, integer *, real *), energy_(\r
+           integer *, real *, real *), invert_(integer *, real *, real *, \r
+           real *);\r
+    integer minptr, maxptr;\r
+    extern /* Subroutine */ int dyptrk_(real *, integer *, integer *, integer \r
+           *, integer *, integer *, struct lpc10_encoder_state *);\r
+    real phi[100]      /* was [10][10] */, psi[10];\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:16:01  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:29:08  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments to ANALYS */\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:16:01  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:29:08  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Arguments to entry PITDEC (below) */\r
+/*     Parameters/constants */\r
+/*  Constants */\r
+/*    NF =     Number of frames */\r
+/*    AF =     Frame in which analysis is done */\r
+/*    OSLEN =  Length of the onset buffer */\r
+/*    LTAU =   Number of pitch lags */\r
+/*    SBUFL, SBUFH =   Start and end index of speech buffers */\r
+/*    LBUFL, LBUFH =   Start and end index of LPF speech buffer */\r
+/*   MINWIN, MAXWIN = Min and Max length of voicing (and analysis) windows\r
+*/\r
+/*    PWLEN, PWINH, PWINL = Length, upper and lower limits of pitch window\r
+ */\r
+/*    DVWINL, DVWINH = Default lower and upper limits of voicing window */\r
+/*       The tables TAU and BUFLIM, and the variable PRECOEF, are not */\r
+/*       Fortran PARAMETER's, but they are initialized with DATA */\r
+/*       statements, and never modified.  Thus, they need not have SAVE */\r
+/*       statements for them to keep their values from one invocation to \r
+*/\r
+/*       the next. */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*  Data Buffers */\r
+/*    INBUF    Raw speech (with DC bias removed each frame) */\r
+/*    PEBUF    Preemphasized speech */\r
+/*    LPBUF    Low pass speech buffer */\r
+/*    IVBUF    Inverse filtered speech */\r
+/*    OSBUF    Indexes of onsets in speech buffers */\r
+/*    VWIN     Voicing window indices */\r
+/*    AWIN     Analysis window indices */\r
+/*    EWIN     Energy window indices */\r
+/*    VOIBUF   Voicing decisions on windows in VWIN */\r
+/*    RMSBUF   RMS energy */\r
+/*    RCBUF    Reflection Coefficients */\r
+\r
+/*  Pitch is handled separately from the above parameters. */\r
+/*  The following variables deal with pitch: */\r
+/*    MIDX     Encoded initial pitch estimate for analysis frame */\r
+/*    IPITCH   Initial pitch computed for frame AF (decoded from MIDX) */\r
+/*    PITCH    The encoded pitch value (index into TAU) for the present */\r
+/*             frame (delayed and smoothed by Dyptrack) */\r
+    /* Parameter adjustments */\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+    if (voice) {\r
+       --voice;\r
+       }\r
+    if (rc) {\r
+       --rc;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+/*   Calculations are done on future frame due to requirements */\r
+/*   of the pitch tracker.  Delay RMS and RC's 2 frames to give */\r
+/*   current frame parameters on return. */\r
+/*   Update all buffers */\r
+\r
+    inbuf = &(st->inbuf[0]);\r
+    pebuf = &(st->pebuf[0]);\r
+    lpbuf = &(st->lpbuf[0]);\r
+    ivbuf = &(st->ivbuf[0]);\r
+    bias = &(st->bias);\r
+    osbuf = &(st->osbuf[0]);\r
+    osptr = &(st->osptr);\r
+    obound = &(st->obound[0]);\r
+    vwin = &(st->vwin[0]);\r
+    awin = &(st->awin[0]);\r
+    voibuf = &(st->voibuf[0]);\r
+    rmsbuf = &(st->rmsbuf[0]);\r
+    rcbuf = &(st->rcbuf[0]);\r
+    zpre = &(st->zpre);\r
+\r
+    i__1 = 720 - contrl_1.lframe;\r
+    for (i__ = 181; i__ <= i__1; ++i__) {\r
+       inbuf[i__ - 181] = inbuf[contrl_1.lframe + i__ - 181];\r
+       pebuf[i__ - 181] = pebuf[contrl_1.lframe + i__ - 181];\r
+    }\r
+    i__1 = 540 - contrl_1.lframe;\r
+    for (i__ = 229; i__ <= i__1; ++i__) {\r
+       ivbuf[i__ - 229] = ivbuf[contrl_1.lframe + i__ - 229];\r
+    }\r
+    i__1 = 720 - contrl_1.lframe;\r
+    for (i__ = 25; i__ <= i__1; ++i__) {\r
+       lpbuf[i__ - 25] = lpbuf[contrl_1.lframe + i__ - 25];\r
+    }\r
+    j = 1;\r
+    i__1 = (*osptr) - 1;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       if (osbuf[i__ - 1] > contrl_1.lframe) {\r
+           osbuf[j - 1] = osbuf[i__ - 1] - contrl_1.lframe;\r
+           ++j;\r
+       }\r
+    }\r
+    *osptr = j;\r
+    voibuf[0] = voibuf[2];\r
+    voibuf[1] = voibuf[3];\r
+    for (i__ = 1; i__ <= 2; ++i__) {\r
+       vwin[(i__ << 1) - 2] = vwin[((i__ + 1) << 1) - 2] - contrl_1.lframe;\r
+       vwin[(i__ << 1) - 1] = vwin[((i__ + 1) << 1) - 1] - contrl_1.lframe;\r
+       awin[(i__ << 1) - 2] = awin[((i__ + 1) << 1) - 2] - contrl_1.lframe;\r
+       awin[(i__ << 1) - 1] = awin[((i__ + 1) << 1) - 1] - contrl_1.lframe;\r
+/*       EWIN(*,J) is unused for J .NE. AF, so the following shift is \r
+*/\r
+/*       unnecessary.  It also causes error messages when the C versio\r
+n */\r
+/*       of the code created from this by f2c is run with Purify.  It \r
+*/\r
+/*       correctly complains that uninitialized memory is being read. \r
+*/\r
+/*        EWIN(1,I) = EWIN(1,I+1) - LFRAME */\r
+/*        EWIN(2,I) = EWIN(2,I+1) - LFRAME */\r
+       obound[i__ - 1] = obound[i__];\r
+       voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];\r
+       voibuf[(i__ << 1) + 1] = voibuf[((i__ + 1) << 1) + 1];\r
+       rmsbuf[i__ - 1] = rmsbuf[i__];\r
+       i__1 = contrl_1.order;\r
+       for (j = 1; j <= i__1; ++j) {\r
+           rcbuf[j + i__ * 10 - 11] = rcbuf[j + (i__ + 1) * 10 - 11];\r
+       }\r
+    }\r
+/*   Copy input speech, scale to sign+12 bit integers */\r
+/*   Remove long term DC bias. */\r
+/*       If the average value in the frame was over 1/4096 (after current \r
+*/\r
+/*       BIAS correction), then subtract that much more from samples in */\r
+/*       next frame.  If the average value in the frame was under */\r
+/*       -1/4096, add 1/4096 more to samples in next frame.  In all other \r
+*/\r
+/*       cases, keep BIAS the same. */\r
+    temp = 0.f;\r
+    i__1 = contrl_1.lframe;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       inbuf[720 - contrl_1.lframe + i__ - 181] = speech[i__] * 4096.f - \r
+               (*bias);\r
+       temp += inbuf[720 - contrl_1.lframe + i__ - 181];\r
+    }\r
+    if (temp > (real) contrl_1.lframe) {\r
+       *bias += 1;\r
+    }\r
+    if (temp < (real) (-contrl_1.lframe)) {\r
+       *bias += -1;\r
+    }\r
+/*   Place Voicing Window */\r
+    i__ = 721 - contrl_1.lframe;\r
+    preemp_(&inbuf[i__ - 181], &pebuf[i__ - 181], &contrl_1.lframe, &precoef, \r
+           zpre);\r
+    onset_(pebuf, osbuf, osptr, &c__10, &c__181, &c__720, &contrl_1.lframe, st);\r
+\r
+/*       MAXOSP is just a debugging variable. */\r
+\r
+/*     MAXOSP = MAX( MAXOSP, OSPTR ) */\r
+\r
+    placev_(osbuf, osptr, &c__10, &obound[2], vwin, &c__3, &contrl_1.lframe, \r
+           &c__90, &c__156, &c__307, &c__462);\r
+/*        The Pitch Extraction algorithm estimates the pitch for a frame \r
+*/\r
+/*   of speech by locating the minimum of the average magnitude difference\r
+ */\r
+/*   function (AMDF).  The AMDF operates on low-pass, inverse filtered */\r
+/*   speech.  (The low-pass filter is an 800 Hz, 19 tap, equiripple, FIR \r
+*/\r
+/*   filter and the inverse filter is a 2nd-order LPC filter.)  The pitch \r
+*/\r
+/*   estimate is later refined by dynamic programming (DYPTRK).  However, \r
+*/\r
+/*   since some of DYPTRK's parameters are a function of the voicing */\r
+/*  decisions, a voicing decision must precede the final pitch estimation.\r
+*/\r
+/*   See subroutines LPFILT, IVFILT, and TBDM. */\r
+/*       LPFILT reads indices LBUFH-LFRAME-29 = 511 through LBUFH = 720 */\r
+/*       of INBUF, and writes indices LBUFH+1-LFRAME = 541 through LBUFH \r
+*/\r
+/*       = 720 of LPBUF. */\r
+    lpfilt_(&inbuf[228], &lpbuf[384], &c__312, &contrl_1.lframe);\r
+/*       IVFILT reads indices (PWINH-LFRAME-7) = 353 through PWINH = 540 \r
+*/\r
+/*       of LPBUF, and writes indices (PWINH-LFRAME+1) = 361 through */\r
+/*       PWINH = 540 of IVBUF. */\r
+    ivfilt_(&lpbuf[204], ivbuf, &c__312, &contrl_1.lframe, ivrc);\r
+/*       TBDM reads indices PWINL = 229 through */\r
+/*       (PWINL-1)+MAXWIN+(TAU(LTAU)-TAU(1))/2 = 452 of IVBUF, and writes \r
+*/\r
+/*       indices 1 through LTAU = 60 of AMDF. */\r
+    tbdm_(ivbuf, &c__156, tau, &c__60, amdf, &minptr, &maxptr, &mintau);\r
+/*        Voicing decisions are made for each half frame of input speech. \r
+*/\r
+/*   An initial voicing classification is made for each half of the */\r
+/*   analysis frame, and the voicing decisions for the present frame */\r
+/*   are finalized.  See subroutine VOICIN. */\r
+/*        The voicing detector (VOICIN) classifies the input signal as */\r
+/*   unvoiced (including silence) or voiced using the AMDF windowed */\r
+/*   maximum-to-minimum ratio, the zero crossing rate, energy measures, */\r
+/*   reflection coefficients, and prediction gains. */\r
+/*        The pitch and voicing rules apply smoothing and isolated */\r
+/*   corrections to the pitch and voicing estimates and, in the process, \r
+*/\r
+/*   introduce two frames of delay into the corrected pitch estimates and \r
+*/\r
+/*   voicing decisions. */\r
+    for (half = 1; half <= 2; ++half) {\r
+       voicin_(&vwin[4], inbuf, lpbuf, buflim, &half, &amdf[minptr - 1], &\r
+               amdf[maxptr - 1], &mintau, ivrc, obound, voibuf, &c__3, st);\r
+    }\r
+/*   Find the minimum cost pitch decision over several frames */\r
+/*   given the current voicing decision and the AMDF array */\r
+    dyptrk_(amdf, &c__60, &minptr, &voibuf[7], pitch, &midx, st);\r
+    ipitch = tau[midx - 1];\r
+/*   Place spectrum analysis and energy windows */\r
+    placea_(&ipitch, voibuf, &obound[2], &c__3, vwin, awin, ewin, &\r
+           contrl_1.lframe, &c__156);\r
+/*  Remove short term DC bias over the analysis window, Put result in ABUF\r
+*/\r
+    lanal = awin[5] + 1 - awin[4];\r
+    dcbias_(&lanal, &pebuf[awin[4] - 181], abuf);\r
+/*       ABUF(1:LANAL) is now defined.  It is equal to */\r
+/*       PEBUF(AWIN(1,AF):AWIN(2,AF)) corrected for short term DC bias. */\r
+/*   Compute RMS over integer number of pitch periods within the */\r
+/*   analysis window. */\r
+/*   Note that in a hardware implementation this computation may be */\r
+/*   simplified by using diagonal elements of PHI computed by MLOAD. */\r
+    i__1 = ewin[5] - ewin[4] + 1;\r
+    energy_(&i__1, &abuf[ewin[4] - awin[4]], &rmsbuf[2]);\r
+/*   Matrix load and invert, check RC's for stability */\r
+    mload_(&contrl_1.order, &c__1, &lanal, abuf, phi, psi);\r
+    invert_(&contrl_1.order, phi, psi, &rcbuf[20]);\r
+    rcchk_(&contrl_1.order, &rcbuf[10], &rcbuf[20]);\r
+/*   Set return parameters */\r
+    voice[1] = voibuf[2];\r
+    voice[2] = voibuf[3];\r
+    *rms = rmsbuf[0];\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       rc[i__] = rcbuf[i__ - 1];\r
+    }\r
+    return 0;\r
+} /* analys_ */\r
diff --git a/libs/codec/lpc10/bsynz.c b/libs/codec/lpc10/bsynz.c
new file mode 100644 (file)
index 0000000..e4810de
--- /dev/null
@@ -0,0 +1,447 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:18:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:58  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: random_ 4 0 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     BSYNZ Version 54 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:18:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:58  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.4  1996/03/27  18:11:22  jaf */\r
+/* Changed the range of NOISE printed out in the debugging statements, */\r
+/* even though they are commented out.  I didn't discover this until I */\r
+/* tried comparing two different versions of the LPC-10 coder, each with */\r
+/* full tracing enabled. */\r
+\r
+/* Revision 1.3  1996/03/26  19:33:23  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.2  1996/03/20  17:12:54  jaf */\r
+/* Added comments about which indices of array arguments are read or */\r
+/* written. */\r
+\r
+/* Rearranged local variable declarations to indicate which need to be */\r
+/* saved from one invocation to the next.  Added entry INITBSYNZ to */\r
+/* reinitialize the local state variables, if desired. */\r
+\r
+/* Revision 1.1  1996/02/07 14:43:15  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*   Synthesize One Pitch Epoch */\r
+\r
+/* Input: */\r
+/*  COEF  - Predictor coefficients */\r
+/*          Indices 1 through ORDER read. */\r
+/*  IP    - Pitch period (number of samples to synthesize) */\r
+/*  IV    - Voicing for the current epoch */\r
+/*  RMS   - Energy for the current epoch */\r
+/*  RATIO - Energy slope for plosives */\r
+/*  G2PASS- Sharpening factor for 2 pass synthesis */\r
+/* Output: */\r
+/*  SOUT  - Synthesized speech */\r
+/*          Indices 1 through IP written. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITBSYNZ. */\r
+\r
+/* Subroutine */ int bsynz_(real *coef, integer *ip, integer *iv, \r
+       real *sout, real *rms, real *ratio, real *g2pass,\r
+                           struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    integer *ipo;\r
+    real *rmso;\r
+    static integer kexc[25] = { 8,-16,26,-48,86,-162,294,-502,718,-728,184,\r
+           672,-610,-672,184,728,718,502,294,162,86,48,26,16,8 };\r
+    real *exc;\r
+    real *exc2;\r
+    real *lpi1;\r
+    real *lpi2;\r
+    real *lpi3;\r
+    real *hpi1;\r
+    real *hpi2;\r
+    real *hpi3;\r
+\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+    real r__1, r__2;\r
+\r
+    /* Builtin functions */\r
+    double sqrt(doublereal);\r
+\r
+    /* Local variables */\r
+    real gain, xssq;\r
+    integer i__, j, k;\r
+    real noise[166], pulse;\r
+    integer px;\r
+    real sscale;\r
+    extern integer random_(struct lpc10_decoder_state *);\r
+    real xy, sum, ssq;\r
+    real lpi0, hpi0;\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:18:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:58  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:18:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:58  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Function return value definitions */\r
+/*     Parameters/constants */\r
+/*       KEXC is not a Fortran PARAMETER, but it is an array initialized \r
+*/\r
+/*       with a DATA statement that is never modified. */\r
+/*       Local variables that need not be saved */\r
+/*       NOISE is declared with range (1:MAXPIT+MAXORD), but only indices \r
+*/\r
+/*       ORDER+1 through ORDER+IP are ever used, and I think that IP */\r
+/*       .LE. MAXPIT.  Why not declare it to be in the range (1:MAXPIT) */\r
+/*       and use that range? */\r
+/*       Local state */\r
+/*       I believe that only indices 1 through ORDER of EXC need to be */\r
+/*       saved from one invocation to the next, but we may as well save */\r
+/*       the whole array. */\r
+/*       None of these local variables were given initial values in the */\r
+/*       original code.  I'm guessing that 0 is a reasonable initial */\r
+/*       value for all of them. */\r
+    /* Parameter adjustments */\r
+    if (coef) {\r
+       --coef;\r
+       }\r
+    if (sout) {\r
+       --sout;\r
+       }\r
+\r
+    /* Function Body */\r
+    ipo = &(st->ipo);\r
+    exc = &(st->exc[0]);\r
+    exc2 = &(st->exc2[0]);\r
+    lpi1 = &(st->lpi1);\r
+    lpi2 = &(st->lpi2);\r
+    lpi3 = &(st->lpi3);\r
+    hpi1 = &(st->hpi1);\r
+    hpi2 = &(st->hpi2);\r
+    hpi3 = &(st->hpi3);\r
+    rmso = &(st->rmso_bsynz);\r
+\r
+/*                  MAXPIT+MAXORD=166 */\r
+/*  Calculate history scale factor XY and scale filter state */\r
+/* Computing MIN */\r
+    r__1 = *rmso / (*rms + 1e-6f);\r
+    xy = min(r__1,8.f);\r
+    *rmso = *rms;\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       exc2[i__ - 1] = exc2[*ipo + i__ - 1] * xy;\r
+    }\r
+    *ipo = *ip;\r
+    if (*iv == 0) {\r
+/*  Generate white noise for unvoiced */\r
+       i__1 = *ip;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           exc[contrl_1.order + i__ - 1] = (real) (random_(st) / 64);\r
+       }\r
+/*  Impulse doublet excitation for plosives */\r
+/*       (RANDOM()+32768) is in the range 0 to 2**16-1.  Therefore the\r
+ */\r
+/*       following expression should be evaluated using integers with \r
+at */\r
+/*       least 32 bits (16 isn't enough), and PX should be in the rang\r
+e */\r
+/*       ORDER+1+0 through ORDER+1+(IP-2) .EQ. ORDER+IP-1. */\r
+       px = (random_(st) + 32768) * (*ip - 1) / 65536 + contrl_1.order + 1;\r
+       r__1 = *ratio / 4 * 1.f;\r
+       pulse = r__1 * 342;\r
+       if (pulse > 2e3f) {\r
+           pulse = 2e3f;\r
+       }\r
+       exc[px - 1] += pulse;\r
+       exc[px] -= pulse;\r
+/*  Load voiced excitation */\r
+    } else {\r
+       sscale = sqrt((real) (*ip)) / 6.928f;\r
+       i__1 = *ip;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           exc[contrl_1.order + i__ - 1] = 0.f;\r
+           if (i__ <= 25) {\r
+               exc[contrl_1.order + i__ - 1] = sscale * kexc[i__ - 1];\r
+           }\r
+           lpi0 = exc[contrl_1.order + i__ - 1];\r
+           r__2 = exc[contrl_1.order + i__ - 1] * .125f + *lpi1 * .75f;\r
+           r__1 = r__2 + *lpi2 * .125f;\r
+           exc[contrl_1.order + i__ - 1] = r__1 + *lpi3 * 0.f;\r
+           *lpi3 = *lpi2;\r
+           *lpi2 = *lpi1;\r
+           *lpi1 = lpi0;\r
+       }\r
+       i__1 = *ip;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           noise[contrl_1.order + i__ - 1] = random_(st) * 1.f / 64;\r
+           hpi0 = noise[contrl_1.order + i__ - 1];\r
+           r__2 = noise[contrl_1.order + i__ - 1] * -.125f + *hpi1 * .25f;\r
+           r__1 = r__2 + *hpi2 * -.125f;\r
+           noise[contrl_1.order + i__ - 1] = r__1 + *hpi3 * 0.f;\r
+           *hpi3 = *hpi2;\r
+           *hpi2 = *hpi1;\r
+           *hpi1 = hpi0;\r
+       }\r
+       i__1 = *ip;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           exc[contrl_1.order + i__ - 1] += noise[contrl_1.order + i__ - 1];\r
+       }\r
+    }\r
+/*   Synthesis filters: */\r
+/*    Modify the excitation with all-zero filter  1 + G*SUM */\r
+    xssq = 0.f;\r
+    i__1 = *ip;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       k = contrl_1.order + i__;\r
+       sum = 0.f;\r
+       i__2 = contrl_1.order;\r
+       for (j = 1; j <= i__2; ++j) {\r
+           sum += coef[j] * exc[k - j - 1];\r
+       }\r
+       sum *= *g2pass;\r
+       exc2[k - 1] = sum + exc[k - 1];\r
+    }\r
+/*   Synthesize using the all pole filter  1 / (1 - SUM) */\r
+    i__1 = *ip;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       k = contrl_1.order + i__;\r
+       sum = 0.f;\r
+       i__2 = contrl_1.order;\r
+       for (j = 1; j <= i__2; ++j) {\r
+           sum += coef[j] * exc2[k - j - 1];\r
+       }\r
+       exc2[k - 1] = sum + exc2[k - 1];\r
+       xssq += exc2[k - 1] * exc2[k - 1];\r
+    }\r
+/*  Save filter history for next epoch */\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       exc[i__ - 1] = exc[*ip + i__ - 1];\r
+       exc2[i__ - 1] = exc2[*ip + i__ - 1];\r
+    }\r
+/*  Apply gain to match RMS */\r
+    r__1 = *rms * *rms;\r
+    ssq = r__1 * *ip;\r
+    gain = sqrt(ssq / xssq);\r
+    i__1 = *ip;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       sout[i__] = gain * exc2[contrl_1.order + i__ - 1];\r
+    }\r
+    return 0;\r
+} /* bsynz_ */\r
diff --git a/libs/codec/lpc10/chanwr.c b/libs/codec/lpc10/chanwr.c
new file mode 100644 (file)
index 0000000..2253e7b
--- /dev/null
@@ -0,0 +1,232 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:20:24  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:40:31  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+/* *********************************************************************** */\r
+\r
+/*     CHANL Version 49 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:20:24  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:40:31  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/21  15:14:57  jaf */\r
+/* Added comments about which indices of argument arrays are read or */\r
+/* written, and about the one bit of local state in CHANWR.  CHANRD */\r
+/* has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  18:55:10  jaf */\r
+/* Comments added explaining which of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next, and which */\r
+/* do not. */\r
+\r
+/* Revision 1.1  1996/02/07 14:43:31  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* *********************************************************************** */\r
+\r
+/* CHANWR: */\r
+/*   Place quantized parameters into bitstream */\r
+\r
+/* Input: */\r
+/*  ORDER  - Number of reflection coefficients (not really variable) */\r
+/*  IPITV  - Quantized pitch/voicing parameter */\r
+/*  IRMS   - Quantized energy parameter */\r
+/*  IRC    - Quantized reflection coefficients */\r
+/*           Indices 1 through ORDER read. */\r
+/* Output: */\r
+/*  IBITS  - Serial bitstream */\r
+/*           Indices 1 through 54 written. */\r
+/*           Bit 54, the SYNC bit, alternates from one call to the next. */\r
+\r
+/* Subroutine CHANWR maintains one bit of local state from one call to */\r
+/* the next, in the variable ISYNC.  I believe that this one bit is only */\r
+/* intended to allow a receiver to resynchronize its interpretation of */\r
+/* the bit stream, by looking for which of the 54 bits alternates every */\r
+/* frame time.  This is just a simple framing mechanism that is not */\r
+/* useful when other, higher overhead framing mechanisms are used to */\r
+/* transmit the coded frames. */\r
+\r
+/* I'm not going to make an entry to reinitialize this bit, since it */\r
+/* doesn't help a receiver much to know whether the first sync bit is a 0 */\r
+/* or a 1.  It needs to examine several frames in sequence to have */\r
+/* reasonably good assurance that its framing is correct. */\r
+\r
+\r
+/* CHANRD: */\r
+/*   Reconstruct parameters from bitstream */\r
+\r
+/* Input: */\r
+/*  ORDER  - Number of reflection coefficients (not really variable) */\r
+/*  IBITS  - Serial bitstream */\r
+/*           Indices 1 through 53 read (SYNC bit is ignored). */\r
+/* Output: */\r
+/*  IPITV  - Quantized pitch/voicing parameter */\r
+/*  IRMS   - Quantized energy parameter */\r
+/*  IRC    - Quantized reflection coefficients */\r
+/*           Indices 1 through ORDER written */\r
+\r
+/* Entry CHANRD has no local state. */\r
+\r
+\r
+\r
+/*   IBITS is 54 bits of LPC data ordered as follows: */\r
+/*     R1-0, R2-0, R3-0,  P-0,  A-0, */\r
+/*     R1-1, R2-1, R3-1,  P-1,  A-1, */\r
+/*     R1-2, R4-0, R3-2,  A-2,  P-2, R4-1, */\r
+/*     R1-3, R2-2, R3-3, R4-2,  A-3, */\r
+/*     R1-4, R2-3, R3-4, R4-3,  A-4, */\r
+/*      P-3, R2-4, R7-0, R8-0,  P-4, R4-4, */\r
+/*     R5-0, R6-0, R7-1,R10-0, R8-1, */\r
+/*     R5-1, R6-1, R7-2, R9-0,  P-5, */\r
+/*     R5-2, R6-2,R10-1, R8-2,  P-6, R9-1, */\r
+/*     R5-3, R6-3, R7-3, R9-2, R8-3, SYNC */\r
+/* Subroutine */ int chanwr_0_(int n__, integer *order, integer *ipitv, \r
+       integer *irms, integer *irc, integer *ibits,\r
+                              struct lpc10_encoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    integer *isync;\r
+    static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };\r
+    static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,\r
+           13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,\r
+           4,6,1,5,9,8,7,5,6 };\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    integer itab[13], i__;\r
+\r
+/*       Arguments */\r
+/*       Parameters/constants */\r
+/*       These arrays are not Fortran PARAMETER's, but they are defined */\r
+/*       by DATA statements below, and their contents are never altered. \r
+*/\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       ISYNC is only used by CHANWR, not by ENTRY CHANRD. */\r
+\r
+    /* Parameter adjustments */\r
+    --irc;\r
+    --ibits;\r
+\r
+    /* Function Body */\r
+    switch(n__) {\r
+       case 1: goto L_chanrd;\r
+       }\r
+\r
+    isync = &(st->isync);\r
+\r
+/* ***********************************************************************\r
+ */\r
+/*     Place quantized parameters into bitstream */\r
+/* ***********************************************************************\r
+ */\r
+/*   Place parameters into ITAB */\r
+    itab[0] = *ipitv;\r
+    itab[1] = *irms;\r
+    itab[2] = 0;\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       itab[i__ + 2] = irc[*order + 1 - i__] & 32767;\r
+    }\r
+/*   Put 54 bits into IBITS array */\r
+    for (i__ = 1; i__ <= 53; ++i__) {\r
+       ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;\r
+       itab[iblist[i__ - 1] - 1] /= 2;\r
+    }\r
+    ibits[54] = *isync & 1;\r
+    *isync = 1 - *isync;\r
+    return 0;\r
+/* ***********************************************************************\r
+ */\r
+/*     Reconstruct parameters from bitstream */\r
+/* ***********************************************************************\r
+ */\r
+\r
+L_chanrd:\r
+/*   Reconstruct ITAB */\r
+    for (i__ = 1; i__ <= 13; ++i__) {\r
+       itab[i__ - 1] = 0;\r
+    }\r
+    for (i__ = 1; i__ <= 53; ++i__) {\r
+       itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)\r
+                + ibits[54 - i__];\r
+    }\r
+/*   Sign extend RC's */\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {\r
+           itab[i__ + 2] -= bit[i__ - 1] << 1;\r
+       }\r
+    }\r
+/*   Restore variables */\r
+    *ipitv = itab[0];\r
+    *irms = itab[1];\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       irc[i__] = itab[*order + 4 - i__ - 1];\r
+    }\r
+    return 0;\r
+} /* chanwr_ */\r
+\r
+/* Subroutine */ int chanwr_(integer *order, integer *ipitv, integer *irms, \r
+       integer *irc, integer *ibits, struct lpc10_encoder_state *st)\r
+{\r
+    return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);\r
+    }\r
+\r
+/* Subroutine */ int chanrd_(integer *order, integer *ipitv, integer *irms, \r
+       integer *irc, integer *ibits)\r
+{\r
+    return chanwr_0_(1, order, ipitv, irms, irc, ibits, 0);\r
+    }\r
diff --git a/libs/codec/lpc10/dcbias.c b/libs/codec/lpc10/dcbias.c
new file mode 100644 (file)
index 0000000..b090804
--- /dev/null
@@ -0,0 +1,107 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:40:23  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int dcbias_(integer *len, real *speech, real *sigout);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     DCBIAS Version 50 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:40:23  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/18  21:19:22  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:44:53  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:44:21  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/* Calculate and remove DC bias from buffer. */\r
+\r
+/* Input: */\r
+/*  LEN    - Length of speech buffers */\r
+/*  SPEECH - Input speech buffer */\r
+/*           Indices 1 through LEN read. */\r
+/* Output: */\r
+/*  SIGOUT - Output speech buffer */\r
+/*           Indices 1 through LEN written */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int dcbias_(integer *len, real *speech, real *sigout)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    real bias;\r
+    integer i__;\r
+\r
+/*     Arguments */\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    --sigout;\r
+    --speech;\r
+\r
+    /* Function Body */\r
+    bias = 0.f;\r
+    i__1 = *len;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       bias += speech[i__];\r
+    }\r
+    bias /= *len;\r
+    i__1 = *len;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       sigout[i__] = speech[i__] - bias;\r
+    }\r
+    return 0;\r
+} /* dcbias_ */\r
+\r
diff --git a/libs/codec/lpc10/decode.c b/libs/codec/lpc10/decode.c
new file mode 100644 (file)
index 0000000..3ab77e6
--- /dev/null
@@ -0,0 +1,625 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.2  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:22:39  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:38  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: ham84_ 14 3 4 4 4 */\r
+/*:ref: median_ 4 3 4 4 4 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__2 = 2;\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     DECODE Version 54 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:22:39  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:38  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/05/23  20:06:03  jaf */\r
+/* Assigned PITCH a "default" value on the first call, since otherwise it */\r
+/* would be left uninitialized. */\r
+\r
+/* Revision 1.4  1996/03/26  19:35:18  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.3  1996/03/21  21:10:50  jaf */\r
+/* Added entry INITDECODE to reinitialize the local state of subroutine */\r
+/* DECODE. */\r
+\r
+/* Revision 1.2  1996/03/21  21:04:50  jaf */\r
+/* Determined which local variables should be saved from one invocation */\r
+/* to the next, and guessed initial values for some that should have been */\r
+/* saved, but weren't given initial values.  Many of the arrays are */\r
+/* "constants", and many local variables are only used if the "global" */\r
+/* variable CORRP is .TRUE. */\r
+\r
+/* Added comments explaining which indices of array arguments are read or */\r
+/* written. */\r
+\r
+/* Revision 1.1  1996/02/12 03:21:10  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*   This subroutine provides error correction and decoding */\r
+/*   for all LPC parameters */\r
+\r
+/* Input: */\r
+/*  IPITV  - Index value of pitch */\r
+/*  IRMS   - Coded Energy */\r
+/*  CORRP  - Error correction: */\r
+/*    If FALSE, parameters are decoded directly with no delay.  If TRUE, */\r
+/*    most important parameter bits are protected by Hamming code and */\r
+/*    median smoothed.  This requires an additional frame of delay. */\r
+/* Input/Output: */\r
+/*  IRC    - Coded Reflection Coefficients */\r
+/*           Indices 1 through ORDER always read, then written. */\r
+/* Output: */\r
+/*  VOICE  - Half frame voicing decisions */\r
+/*           Indices 1 through 2 written. */\r
+/*  PITCH  - Decoded pitch */\r
+/*  RMS    - Energy */\r
+/*  RC     - Reflection coefficients */\r
+/*           Indices 1 through ORDER written. */\r
+\r
+/*  NOTE: Zero RC's should be done more directly, but this would affect */\r
+/*   coded parameter printout. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITDECODE. */\r
+\r
+/* Subroutine */ int decode_(integer *ipitv, integer *irms, \r
+       integer *irc, integer *voice, integer *pitch, real *rms, real *rc,\r
+                            struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    logical *first;\r
+    static integer ethrs = 2048;\r
+    static integer ethrs1 = 128;\r
+    static integer ethrs2 = 1024;\r
+    static integer ethrs3 = 2048;\r
+    static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,\r
+           25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,\r
+           24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,\r
+           3641 };\r
+    static real corth[32]      /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,\r
+           32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,\r
+           11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,\r
+           3.2f,0.f };\r
+    static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,\r
+           20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,\r
+           3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,\r
+           100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,\r
+           3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,\r
+           3,3,3,3,1,3,3,3,1,3,1,1,1 };\r
+    static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,\r
+           384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,\r
+           92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,\r
+           14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };\r
+    static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,\r
+           96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,\r
+           127 };\r
+    static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,\r
+           .3828f };\r
+    integer *ivp2h;\r
+    static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }\r
+           ;\r
+    static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };\r
+    static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };\r
+    static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };\r
+    static integer bit[5] = { 2,4,8,16,32 };\r
+    integer *iovoic;\r
+    integer *iavgp;\r
+    integer *iptold;\r
+    integer *erate;\r
+    integer *drc;\r
+    integer *dpit;\r
+    integer *drms;\r
+\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+\r
+    /* Builtin functions */\r
+    integer pow_ii(integer *, integer *);\r
+\r
+    /* Local variables */\r
+    extern /* Subroutine */ int ham84_(integer *, integer *, integer *);\r
+    integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;\r
+    extern integer median_(integer *, integer *, integer *);\r
+    integer ishift, errcnt, lsb;\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:22:39  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:38  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:22:39  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:38  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Function return value definitions */\r
+\r
+/*       Parameters/constants */\r
+\r
+/*       The variables below that are not Fortran PARAMETER's are */\r
+/*       initialized with DATA statements, and then never modified. */\r
+/*       The following are used regardless of CORRP's value. */\r
+\r
+/*       DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */\r
+\r
+/*       The following are used only if CORRP is .TRUE. */\r
+\r
+/*       ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */\r
+\r
+/*       Local variables that need not be saved */\r
+\r
+/*       The following are used regardless of CORRP's value */\r
+/*       The following are used only if CORRP is .TRUE. */\r
+\r
+/*       Local state */\r
+\r
+/*       The following are used regardless of CORRP's value */\r
+/*       The following are used only if CORRP is .TRUE. */\r
+/*       I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */\r
+/*       and DRMS.  They should be checked to see if they are reasonable. \r
+*/\r
+/*       I'm also guessing for ERATE, but I think 0 is the right initial \r
+*/\r
+/*       value. */\r
+    /* Parameter adjustments */\r
+    if (irc) {\r
+       --irc;\r
+       }\r
+    if (voice) {\r
+       --voice;\r
+       }\r
+    if (rc) {\r
+       --rc;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+    iptold = &(st->iptold);\r
+    first = &(st->first);\r
+    ivp2h = &(st->ivp2h);\r
+    iovoic = &(st->iovoic);\r
+    iavgp = &(st->iavgp);\r
+    erate = &(st->erate);\r
+    drc = &(st->drc[0]);\r
+    dpit = &(st->dpit[0]);\r
+    drms = &(st->drms[0]);\r
+\r
+/* DATA statements for "constants" defined above. */\r
+/*     IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */\r
+/* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */\r
+/*  If no error correction, do pitch and voicing then jump to decode */\r
+    i4 = detau[*ipitv];\r
+    if (! contrl_1.corrp) {\r
+       voice[1] = 1;\r
+       voice[2] = 1;\r
+       if (*ipitv <= 1) {\r
+           voice[1] = 0;\r
+       }\r
+       if (*ipitv == 0 || *ipitv == 2) {\r
+           voice[2] = 0;\r
+       }\r
+       *pitch = i4;\r
+       if (*pitch <= 4) {\r
+           *pitch = *iptold;\r
+       }\r
+       if (voice[1] == 1 && voice[2] == 1) {\r
+           *iptold = *pitch;\r
+       }\r
+       if (voice[1] != voice[2]) {\r
+           *pitch = *iptold;\r
+       }\r
+       goto L900;\r
+    }\r
+/*  Do error correction pitch and voicing */\r
+    if (i4 > 4) {\r
+       dpit[0] = i4;\r
+       ivoic = 2;\r
+       *iavgp = (*iavgp * 15 + i4 + 8) / 16;\r
+    } else {\r
+       ivoic = i4;\r
+       dpit[0] = *iavgp;\r
+    }\r
+    drms[0] = *irms;\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       drc[i__ * 3 - 3] = irc[i__];\r
+    }\r
+/*  Determine index to IVTAB from V/UV decision */\r
+/*  If error rate is high then use alternate table */\r
+    index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;\r
+    i1 = ivtab[index - 1];\r
+    ipit = i1 & 3;\r
+    icorf = i1 / 8;\r
+    if (*erate < ethrs) {\r
+       icorf /= 64;\r
+    }\r
+/*  Determine error rate:  4=high    1=low */\r
+    ixcor = 4;\r
+    if (*erate < ethrs3) {\r
+       ixcor = 3;\r
+    }\r
+    if (*erate < ethrs2) {\r
+       ixcor = 2;\r
+    }\r
+    if (*erate < ethrs1) {\r
+       ixcor = 1;\r
+    }\r
+/*  Voice/unvoice decision determined from bits 0 and 1 of IVTAB */\r
+    voice[1] = icorf / 2 & 1;\r
+    voice[2] = icorf & 1;\r
+/*  Skip decoding on first frame because present data not yet available */\r
+    if (*first) {\r
+       *first = FALSE_;\r
+/*          Assign PITCH a "default" value on the first call, since */\r
+/*          otherwise it would be left uninitialized.  The two lines \r
+*/\r
+/*          below were copied from above, since it seemed like a */\r
+/*          reasonable thing to do for the first call. */\r
+       *pitch = i4;\r
+       if (*pitch <= 4) {\r
+           *pitch = *iptold;\r
+       }\r
+       goto L500;\r
+    }\r
+/*  If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */\r
+/*    Determine error rate and correct errors using a Hamming 8,4 code */\r
+/*    during transition or unvoiced frame.  If IOUT is negative, */\r
+/*    more than 1 error occurred, use previous frame's parameters. */\r
+    if ((icorf & bit[3]) != 0) {\r
+       errcnt = 0;\r
+       lsb = drms[1] & 1;\r
+       index = (drc[22] << 4) + drms[1] / 2;\r
+       ham84_(&index, &iout, &errcnt);\r
+       drms[1] = drms[2];\r
+       if (iout >= 0) {\r
+           drms[1] = (iout << 1) + lsb;\r
+       }\r
+       for (i__ = 1; i__ <= 4; ++i__) {\r
+           if (i__ == 1) {\r
+               i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);\r
+           } else {\r
+               i1 = drc[(9 - i__) * 3 - 2] & 15;\r
+           }\r
+           i2 = drc[(5 - i__) * 3 - 2] & 31;\r
+           lsb = i2 & 1;\r
+           index = (i1 << 4) + i2 / 2;\r
+           ham84_(&index, &iout, &errcnt);\r
+           if (iout >= 0) {\r
+               iout = (iout << 1) + lsb;\r
+               if ((iout & 16) == 16) {\r
+                   iout += -32;\r
+               }\r
+           } else {\r
+               iout = drc[(5 - i__) * 3 - 1];\r
+           }\r
+           drc[(5 - i__) * 3 - 2] = iout;\r
+       }\r
+/*  Determine error rate */\r
+       *erate = *erate * .96875f + errcnt * 102;\r
+    }\r
+/*  Get unsmoothed RMS, RC's, and PITCH */\r
+    *irms = drms[1];\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       irc[i__] = drc[i__ * 3 - 2];\r
+    }\r
+    if (ipit == 1) {\r
+       dpit[1] = dpit[2];\r
+    }\r
+    if (ipit == 3) {\r
+       dpit[1] = dpit[0];\r
+    }\r
+    *pitch = dpit[1];\r
+/*  If bit 2 of ICORF is set then smooth RMS and RC's, */\r
+    if ((icorf & bit[1]) != 0) {\r
+       if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3] \r
+               && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[\r
+               ixcor + 3]) {\r
+           *irms = median_(&drms[2], &drms[1], drms);\r
+       }\r
+       for (i__ = 1; i__ <= 6; ++i__) {\r
+           if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))\r
+                    >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *\r
+                    3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[\r
+                   ixcor + ((i__ + 2) << 2) - 5]) {\r
+               irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[\r
+                       i__ * 3 - 3]);\r
+           }\r
+       }\r
+    }\r
+/*  If bit 3 of ICORF is set then smooth pitch */\r
+    if ((icorf & bit[2]) != 0) {\r
+       if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1] \r
+               && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[\r
+               ixcor - 1]) {\r
+           *pitch = median_(&dpit[2], &dpit[1], dpit);\r
+       }\r
+    }\r
+/*  If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */\r
+/*  values so that after quantization bias is removed in decode */\r
+/*  the values will be zero. */\r
+L500:\r
+    if ((icorf & bit[4]) != 0) {\r
+       i__1 = contrl_1.order;\r
+       for (i__ = 5; i__ <= i__1; ++i__) {\r
+           irc[i__] = zrc[i__ - 1];\r
+       }\r
+    }\r
+/*  House keeping  - one frame delay */\r
+    *iovoic = ivoic;\r
+    *ivp2h = voice[2];\r
+    dpit[2] = dpit[1];\r
+    dpit[1] = dpit[0];\r
+    drms[2] = drms[1];\r
+    drms[1] = drms[0];\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       drc[i__ * 3 - 1] = drc[i__ * 3 - 2];\r
+       drc[i__ * 3 - 2] = drc[i__ * 3 - 3];\r
+    }\r
+L900:\r
+/*     IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */\r
+/* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */\r
+/*   Decode RMS */\r
+    *irms = rmst[(31 - *irms) * 2];\r
+/*  Decode RC(1) and RC(2) from log-area-ratios */\r
+/*  Protect from illegal coded value (-16) caused by bit errors */\r
+    for (i__ = 1; i__ <= 2; ++i__) {\r
+       i2 = irc[i__];\r
+       i1 = 0;\r
+       if (i2 < 0) {\r
+           i1 = 1;\r
+           i2 = -i2;\r
+           if (i2 > 15) {\r
+               i2 = 0;\r
+           }\r
+       }\r
+       i2 = detab7[i2 * 2];\r
+       if (i1 == 1) {\r
+           i2 = -i2;\r
+       }\r
+       ishift = 15 - nbit[i__ - 1];\r
+       irc[i__] = i2 * pow_ii(&c__2, &ishift);\r
+    }\r
+/*  Decode RC(3)-RC(10) to sign plus 14 bits */\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 3; i__ <= i__1; ++i__) {\r
+       i2 = irc[i__];\r
+       ishift = 15 - nbit[i__ - 1];\r
+       i2 *= pow_ii(&c__2, &ishift);\r
+       i2 += qb[i__ - 3];\r
+       irc[i__] = i2 * descl[i__ - 3] + deadd[i__ - 3];\r
+    }\r
+/*     IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */\r
+/* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */\r
+/*  Scale RMS and RC's to reals */\r
+    *rms = (real) (*irms);\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       rc[i__] = irc[i__] / 16384.f;\r
+    }\r
+    return 0;\r
+} /* decode_ */\r
diff --git a/libs/codec/lpc10/deemp.c b/libs/codec/lpc10/deemp.c
new file mode 100644 (file)
index 0000000..e6715e8
--- /dev/null
@@ -0,0 +1,154 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:23:46  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:34  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);\r
+#endif\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     DEEMP Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:23:46  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:34  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/20  15:54:37  jaf */\r
+/* Added comments about which indices of array arguments are read or */\r
+/* written. */\r
+\r
+/* Added entry INITDEEMP to reinitialize the local state variables, if */\r
+/* desired. */\r
+\r
+/* Revision 1.2  1996/03/14  22:11:13  jaf */\r
+/* Comments added explaining which of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next, and which */\r
+/* do not. */\r
+\r
+/* Revision 1.1  1996/02/07 14:44:53  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*  De-Emphasize output speech with   1 / ( 1 - .75z**-1 ) */\r
+/*    cascaded with 200 Hz high pass filter */\r
+/*    ( 1 - 1.9998z**-1 + z**-2 ) / ( 1 - 1.75z**-1 + .78z**-2 ) */\r
+\r
+/*  WARNING!  The coefficients above may be out of date with the code */\r
+/*  below.  Either that, or some kind of transformation was performed */\r
+/*  on the coefficients above to create the code below. */\r
+\r
+/* Input: */\r
+/*  N  - Number of samples */\r
+/* Input/Output: */\r
+/*  X  - Speech */\r
+/*       Indices 1 through N are read before being written. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITDEEMP. */\r
+\r
+/* Subroutine */ int deemp_(real *x, integer *n, struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *dei1;\r
+    real *dei2;\r
+    real *deo1;\r
+    real *deo2;\r
+    real *deo3;\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+    real r__1;\r
+\r
+    /* Local variables */\r
+    integer k;\r
+    real dei0;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       All of the locals saved below were not given explicit initial */\r
+/*       values in the original code.  I think 0 is a safe choice. */\r
+    /* Parameter adjustments */\r
+    if (x) {\r
+       --x;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+    dei1 = &(st->dei1);\r
+    dei2 = &(st->dei2);\r
+    deo1 = &(st->deo1);\r
+    deo2 = &(st->deo2);\r
+    deo3 = &(st->deo3);\r
+\r
+    i__1 = *n;\r
+    for (k = 1; k <= i__1; ++k) {\r
+       dei0 = x[k];\r
+       r__1 = x[k] - *dei1 * 1.9998f + *dei2;\r
+       x[k] = r__1 + *deo1 * 2.5f - *deo2 * 2.0925f + *deo3 * .585f;\r
+       *dei2 = *dei1;\r
+       *dei1 = dei0;\r
+       *deo3 = *deo2;\r
+       *deo2 = *deo1;\r
+       *deo1 = x[k];\r
+    }\r
+    return 0;\r
+} /* deemp_ */\r
diff --git a/libs/codec/lpc10/difmag.c b/libs/codec/lpc10/difmag.c
new file mode 100644 (file)
index 0000000..03b12c3
--- /dev/null
@@ -0,0 +1,133 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:31  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr);\r
+#endif\r
+\r
+/* ********************************************************************** */\r
+\r
+/*     DIFMAG Version 49 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:31  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/15  23:09:39  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  14:41:31  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:45:04  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*  Compute Average Magnitude Difference Function */\r
+\r
+/* Inputs: */\r
+/*  SPEECH - Low pass filtered speech */\r
+/*           Indices MIN_N1 through MAX_N1+LPITA-1 are read, where */\r
+/*      MIN_N1 = (MAXLAG - MAX_TAU)/2+1  MAX_TAU = max of TAU(I) for I=1,LTAU\r
+*/\r
+/*      MAX_N1 = (MAXLAG - MIN_TAU)/2+1  MIN_TAU = min of TAU(I) for I=1,LTAU\r
+*/\r
+/*  LPITA  - Length of speech buffer */\r
+/*  TAU    - Table of lags */\r
+/*           Indices 1 through LTAU read. */\r
+/*  LTAU   - Number of lag values to compute */\r
+/*  MAXLAG - Maximum possible lag value */\r
+/* Outputs: */\r
+/*  (All of these outputs are also read, but only after being written.) */\r
+/*  AMDF   - Average Magnitude Difference for each lag in TAU */\r
+/*           Indices 1 through LTAU written */\r
+/*  MINPTR - Index of minimum AMDF value */\r
+/*  MAXPTR - Index of maximum AMDF value */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int difmag_(real *speech, integer *lpita, integer *tau, \r
+       integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *\r
+       maxptr)\r
+{\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+    real r__1;\r
+\r
+    /* Local variables */\r
+    integer i__, j, n1, n2;\r
+    real sum;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       None */\r
+    /* Parameter adjustments */\r
+    --amdf;\r
+    --tau;\r
+    --speech;\r
+\r
+    /* Function Body */\r
+    *minptr = 1;\r
+    *maxptr = 1;\r
+    i__1 = *ltau;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       n1 = (*maxlag - tau[i__]) / 2 + 1;\r
+       n2 = n1 + *lpita - 1;\r
+       sum = 0.f;\r
+       i__2 = n2;\r
+       for (j = n1; j <= i__2; j += 4) {\r
+           sum += (r__1 = speech[j] - speech[j + tau[i__]], abs(r__1));\r
+       }\r
+       amdf[i__] = sum;\r
+       if (amdf[i__] < amdf[*minptr]) {\r
+           *minptr = i__;\r
+       }\r
+       if (amdf[i__] > amdf[*maxptr]) {\r
+           *maxptr = i__;\r
+       }\r
+    }\r
+    return 0;\r
+} /* difmag_ */\r
+\r
diff --git a/libs/codec/lpc10/dyptrk.c b/libs/codec/lpc10/dyptrk.c
new file mode 100644 (file)
index 0000000..4656b00
--- /dev/null
@@ -0,0 +1,405 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:25:29  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:26  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int dyptrk_(real *amdf, integer *ltau, integer *minptr, integer *voice, integer *pitch, integer *midx, struct lpc10_encoder_state *st);\r
+/* comlen contrl_ 12 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     DYPTRK Version 52 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:25:29  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:26  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/26  19:35:35  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.4  1996/03/19  18:03:22  jaf */\r
+/* Replaced the initialization "DATA P/60*DEPTH*0/" with "DATA P/120*0/", */\r
+/* because apparently Fortran (or at least f2c) can't handle expressions */\r
+/* like that. */\r
+\r
+/* Revision 1.3  1996/03/19  17:38:32  jaf */\r
+/* Added comments about the local variables that should be saved from one */\r
+/* invocation to the next.  None of them were given initial values in the */\r
+/* original code, but from my testing, it appears that initializing them */\r
+/* all to 0 works. */\r
+\r
+/* Added entry INITDYPTRK to reinitialize these local variables. */\r
+\r
+/* Revision 1.2  1996/03/13  16:32:17  jaf */\r
+/* Comments added explaining which of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next, and which */\r
+/* do not. */\r
+\r
+/* WARNING!  Some of them that should are never given initial values in */\r
+/* this code.  Hopefully, Fortran 77 defines initial values for them, but */\r
+/* even so, giving them explicit initial values is preferable. */\r
+\r
+/* Revision 1.1  1996/02/07 14:45:14  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*   Dynamic Pitch Tracker */\r
+\r
+/* Input: */\r
+/*  AMDF   - Average Magnitude Difference Function array */\r
+/*           Indices 1 through LTAU read, and MINPTR */\r
+/*  LTAU   - Number of lags in AMDF */\r
+/*  MINPTR - Location of minimum AMDF value */\r
+/*  VOICE  - Voicing decision */\r
+/* Output: */\r
+/*  PITCH  - Smoothed pitch value, 2 frames delayed */\r
+/*  MIDX   - Initial estimate of current frame pitch */\r
+/* Compile time constant: */\r
+/*  DEPTH  - Number of frames to trace back */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITDYPTRK. */\r
+\r
+/* Subroutine */ int dyptrk_(real *amdf, integer *ltau, integer *\r
+       minptr, integer *voice, integer *pitch, integer *midx,\r
+                              struct lpc10_encoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *s;\r
+    integer *p;\r
+    integer *ipoint;\r
+    real *alphax;\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    integer pbar;\r
+    real sbar;\r
+    integer path[2], iptr, i__, j;\r
+    real alpha, minsc, maxsc;\r
+\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:25:29  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:26  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     Parameters/constants */\r
+/*       Local variables that need not be saved */\r
+/*       Note that PATH is only used for debugging purposes, and can be */\r
+/*       removed. */\r
+/*       Local state */\r
+/*       It would be a bit more "general" to define S(LTAU), if Fortran */\r
+/*       allows the argument of a function to be used as the dimension of \r
+*/\r
+/*       a local array variable. */\r
+/*       IPOINT is always in the range 0 to DEPTH-1. */\r
+/*       WARNING! */\r
+\r
+/*       In the original version of this subroutine, IPOINT, ALPHAX, */\r
+/*       every element of S, and potentially any element of P with the */\r
+/*       second index value .NE. IPTR were read without being given */\r
+/*       initial values (all indices of P with second index equal to */\r
+/*       IPTR are all written before being read in this subroutine). */\r
+\r
+/*       From examining the code carefully, it appears that all of these \r
+*/\r
+/*       should be saved from one invocation to the next. */\r
+\r
+/*       I've run lpcsim with the "-l 6" option to see all of the */\r
+/*       debugging information that is printed out by this subroutine */\r
+/*       below, and it appears that S, P, IPOINT, and ALPHAX are all */\r
+/*       initialized to 0 (these initial values would likely be different \r
+*/\r
+/*       on different platforms, compilers, etc.).  Given that the output \r
+*/\r
+/*       of the coder sounds reasonable, I'm going to initialize these */\r
+/*       variables to 0 explicitly. */\r
+\r
+    s = &(st->s[0]);\r
+    p = &(st->p[0]);\r
+    ipoint = &(st->ipoint);\r
+    alphax = &(st->alphax);\r
+\r
+\r
+    /* Parameter adjustments */\r
+    if (amdf) {\r
+       --amdf;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+/*   Calculate the confidence factor ALPHA, used as a threshold slope in \r
+*/\r
+/*   SEESAW.  If unvoiced, set high slope so that every point in P array \r
+*/\r
+/*  is marked as a potential pitch frequency.  A scaled up version (ALPHAX\r
+)*/\r
+/*   is used to maintain arithmetic precision. */\r
+    if (*voice == 1) {\r
+       *alphax = *alphax * .75f + amdf[*minptr] / 2.f;\r
+    } else {\r
+       *alphax *= .984375f;\r
+    }\r
+    alpha = *alphax / 16;\r
+    if (*voice == 0 && *alphax < 128.f) {\r
+       alpha = 8.f;\r
+    }\r
+/* SEESAW: Construct a pitch pointer array and intermediate winner functio\r
+n*/\r
+/*   Left to right pass: */\r
+    iptr = *ipoint + 1;\r
+    p[iptr * 60 - 60] = 1;\r
+    i__ = 1;\r
+    pbar = 1;\r
+    sbar = s[0];\r
+    i__1 = *ltau;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       sbar += alpha;\r
+       if (sbar < s[i__ - 1]) {\r
+           s[i__ - 1] = sbar;\r
+           p[i__ + iptr * 60 - 61] = pbar;\r
+       } else {\r
+           sbar = s[i__ - 1];\r
+           p[i__ + iptr * 60 - 61] = i__;\r
+           pbar = i__;\r
+       }\r
+    }\r
+/*   Right to left pass: */\r
+    i__ = pbar - 1;\r
+    sbar = s[i__];\r
+    while(i__ >= 1) {\r
+       sbar += alpha;\r
+       if (sbar < s[i__ - 1]) {\r
+           s[i__ - 1] = sbar;\r
+           p[i__ + iptr * 60 - 61] = pbar;\r
+       } else {\r
+           pbar = p[i__ + iptr * 60 - 61];\r
+           i__ = pbar;\r
+           sbar = s[i__ - 1];\r
+       }\r
+       --i__;\r
+    }\r
+/*   Update S using AMDF */\r
+/*   Find maximum, minimum, and location of minimum */\r
+    s[0] += amdf[1] / 2;\r
+    minsc = s[0];\r
+    maxsc = minsc;\r
+    *midx = 1;\r
+    i__1 = *ltau;\r
+    for (i__ = 2; i__ <= i__1; ++i__) {\r
+       s[i__ - 1] += amdf[i__] / 2;\r
+       if (s[i__ - 1] > maxsc) {\r
+           maxsc = s[i__ - 1];\r
+       }\r
+       if (s[i__ - 1] < minsc) {\r
+           *midx = i__;\r
+           minsc = s[i__ - 1];\r
+       }\r
+    }\r
+/*   Subtract MINSC from S to prevent overflow */\r
+    i__1 = *ltau;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       s[i__ - 1] -= minsc;\r
+    }\r
+    maxsc -= minsc;\r
+/*   Use higher octave pitch if significant null there */\r
+    j = 0;\r
+    for (i__ = 20; i__ <= 40; i__ += 10) {\r
+       if (*midx > i__) {\r
+           if (s[*midx - i__ - 1] < maxsc / 4) {\r
+               j = i__;\r
+           }\r
+       }\r
+    }\r
+    *midx -= j;\r
+/*   TRACE: look back two frames to find minimum cost pitch estimate */\r
+    j = *ipoint;\r
+    *pitch = *midx;\r
+    for (i__ = 1; i__ <= 2; ++i__) {\r
+       j = j % 2 + 1;\r
+       *pitch = p[*pitch + j * 60 - 61];\r
+       path[i__ - 1] = *pitch;\r
+    }\r
+\r
+/*       The following statement subtracts one from IPOINT, mod DEPTH.  I \r
+*/\r
+/*       think the author chose to add DEPTH-1, instead of subtracting 1, \r
+*/\r
+/*       because then it will work even if MOD doesn't work as desired on \r
+*/\r
+/*       negative arguments. */\r
+\r
+    *ipoint = (*ipoint + 1) % 2;\r
+    return 0;\r
+} /* dyptrk_ */\r
diff --git a/libs/codec/lpc10/encode.c b/libs/codec/lpc10/encode.c
new file mode 100644 (file)
index 0000000..cfe1ef7
--- /dev/null
@@ -0,0 +1,373 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:21  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int encode_(integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc);\r
+/* comlen contrl_ 12 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__2 = 2;\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     ENCODE Version 54 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:21  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/26  19:35:50  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.4  1996/03/21  00:26:29  jaf */\r
+/* Added the comment that this subroutine has no local state. */\r
+\r
+/* In the last check-in, I forgot to mention that I had added comments */\r
+/* explaining which indices of array arguments are read or written. */\r
+\r
+/* Revision 1.3  1996/03/21  00:22:39  jaf */\r
+/* Added comments explaining that all local arrays are effectively */\r
+/* constants. */\r
+\r
+/* Revision 1.2  1996/03/13  18:48:33  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:45:29  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*  Quantize LPC parameters for transmission */\r
+\r
+/* INPUTS: */\r
+/*  VOICE  - Half frame voicing decisions */\r
+/*           Indices 1 through 2 read. */\r
+/*  PITCH  - Pitch */\r
+/*  RMS    - Energy */\r
+/*  RC     - Reflection coefficients */\r
+/*           Indices 1 through ORDER read. */\r
+/*  CORRP  - Error Correction: TRUE = yes, FALSE = none */\r
+/*           (this is defined in file control.fh) */\r
+/* OUTPUTS: */\r
+/*  IPITCH - Coded pitch and voicing */\r
+/*  IRMS   - Quantized energy */\r
+/*  IRC    - Quantized reflection coefficients */\r
+/*           Indices 1 through MAX(ORDER,2) written. */\r
+/*           If CORRP is .TRUE., then indices 1 through 10 written */\r
+/*           for unvoiced frames. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int encode_(integer *voice, integer *pitch, real *rms, real *\r
+       rc, integer *ipitch, integer *irms, integer *irc)\r
+{\r
+    /* Initialized data */\r
+\r
+    static integer enctab[16] = { 0,7,11,12,13,10,6,1,14,9,5,2,3,4,8,15 };\r
+    static integer entau[60] = { 19,11,27,25,29,21,23,22,30,14,15,7,39,38,46,\r
+           42,43,41,45,37,53,49,51,50,54,52,60,56,58,26,90,88,92,84,86,82,83,\r
+           81,85,69,77,73,75,74,78,70,71,67,99,97,113,112,114,98,106,104,108,\r
+           100,101,76 };\r
+    static integer enadd[8] = { 1920,-768,2432,1280,3584,1536,2816,-1152 };\r
+    static real enscl[8] = { .0204f,.0167f,.0145f,.0147f,.0143f,.0135f,.0125f,\r
+           .0112f };\r
+    static integer enbits[8] = { 6,5,4,4,4,4,3,3 };\r
+    static integer entab6[64] = { 0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,\r
+           3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,9,9,\r
+           9,10,10,11,11,12,13,14,15 };\r
+    static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,\r
+           384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,\r
+           92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,\r
+           14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };\r
+\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+\r
+    /* Builtin functions */\r
+    integer pow_ii(integer *, integer *);\r
+\r
+    /* Local variables */\r
+    integer idel, nbit, i__, j, i2, i3, mrk;\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:21  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:21  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Parameters/constants */\r
+/*       These arrays are not Fortran PARAMETER's, but they are defined */\r
+/*       by DATA statements below, and their contents are never altered. \r
+*/\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    --irc;\r
+    --rc;\r
+    --voice;\r
+\r
+    /* Function Body */\r
+/*  Scale RMS and RC's to integers */\r
+    *irms = *rms;\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       irc[i__] = rc[i__] * 32768.f;\r
+    }\r
+/*     IF(LISTL.GE.3)WRITE(FDEBUG,800)VOICE,PITCH,IRMS,(IRC(I),I=1,ORDER) */\r
+/* 800 FORMAT(1X,/,' <<ENCODE IN>>',T32,2I3,I6,I5,T50,10I8) */\r
+/*  Encode pitch and voicing */\r
+    if (voice[1] != 0 && voice[2] != 0) {\r
+       *ipitch = entau[*pitch - 1];\r
+    } else {\r
+       if (contrl_1.corrp) {\r
+           *ipitch = 0;\r
+           if (voice[1] != voice[2]) {\r
+               *ipitch = 127;\r
+           }\r
+       } else {\r
+           *ipitch = (voice[1] << 1) + voice[2];\r
+       }\r
+    }\r
+/*  Encode RMS by binary table search */\r
+    j = 32;\r
+    idel = 16;\r
+    *irms = min(*irms,1023);\r
+    while(idel > 0) {\r
+       if (*irms > rmst[j - 1]) {\r
+           j -= idel;\r
+       }\r
+       if (*irms < rmst[j - 1]) {\r
+           j += idel;\r
+       }\r
+       idel /= 2;\r
+    }\r
+    if (*irms > rmst[j - 1]) {\r
+       --j;\r
+    }\r
+    *irms = 31 - j / 2;\r
+/*  Encode RC(1) and (2) as log-area-ratios */\r
+    for (i__ = 1; i__ <= 2; ++i__) {\r
+       i2 = irc[i__];\r
+       mrk = 0;\r
+       if (i2 < 0) {\r
+           i2 = -i2;\r
+           mrk = 1;\r
+       }\r
+       i2 /= 512;\r
+       i2 = min(i2,63);\r
+       i2 = entab6[i2];\r
+       if (mrk != 0) {\r
+           i2 = -i2;\r
+       }\r
+       irc[i__] = i2;\r
+    }\r
+/*  Encode RC(3) - (10) linearly, remove bias then scale */\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 3; i__ <= i__1; ++i__) {\r
+       i2 = irc[i__] / 2;\r
+       i2 = (i2 + enadd[contrl_1.order + 1 - i__ - 1]) * enscl[\r
+               contrl_1.order + 1 - i__ - 1];\r
+/* Computing MIN */\r
+       i__2 = max(i2,-127);\r
+       i2 = min(i__2,127);\r
+       nbit = enbits[contrl_1.order + 1 - i__ - 1];\r
+       i3 = 0;\r
+       if (i2 < 0) {\r
+           i3 = -1;\r
+       }\r
+       i2 /= pow_ii(&c__2, &nbit);\r
+       if (i3 == -1) {\r
+           --i2;\r
+       }\r
+       irc[i__] = i2;\r
+    }\r
+/*          Protect the most significant bits of the most */\r
+/*     important parameters during non-voiced frames. */\r
+/*     RC(1) - RC(4) are protected using 20 parity bits */\r
+/*     replacing RC(5) - RC(10). */\r
+    if (contrl_1.corrp) {\r
+       if (*ipitch == 0 || *ipitch == 127) {\r
+           irc[5] = enctab[(irc[1] & 30) / 2];\r
+           irc[6] = enctab[(irc[2] & 30) / 2];\r
+           irc[7] = enctab[(irc[3] & 30) / 2];\r
+           irc[8] = enctab[(*irms & 30) / 2];\r
+           irc[9] = enctab[(irc[4] & 30) / 2] / 2;\r
+           irc[10] = enctab[(irc[4] & 30) / 2] & 1;\r
+       }\r
+    }\r
+/*     IF(LISTL.GE.3)WRITE(FDEBUG,801)VOICE,IPITCH,IRMS,(IRC(J),J=1,ORDER) */\r
+/* 801 FORMAT(1X,'<<ENCODE OUT>>',T32,2I3,I6,I5,T50,10I8) */\r
+    return 0;\r
+} /* encode_ */\r
+\r
diff --git a/libs/codec/lpc10/energy.c b/libs/codec/lpc10/energy.c
new file mode 100644 (file)
index 0000000..c5594b8
--- /dev/null
@@ -0,0 +1,103 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:17  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int energy_(integer *len, real *speech, real *rms);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     ENERGY Version 50 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:17  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/18  21:17:41  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:46:02  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:45:40  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/* Compute RMS energy. */\r
+\r
+/* Input: */\r
+/*  LEN    - Length of speech buffer */\r
+/*  SPEECH - Speech buffer */\r
+/*           Indices 1 through LEN read. */\r
+/* Output: */\r
+/*  RMS    - Root Mean Square energy */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int energy_(integer *len, real *speech, real *rms)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Builtin functions */\r
+    double sqrt(doublereal);\r
+\r
+    /* Local variables */\r
+    integer i__;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    --speech;\r
+\r
+    /* Function Body */\r
+    *rms = 0.f;\r
+    i__1 = *len;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       *rms += speech[i__] * speech[i__];\r
+    }\r
+    *rms = sqrt(*rms / *len);\r
+    return 0;\r
+} /* energy_ */\r
+\r
diff --git a/libs/codec/lpc10/f2c.h b/libs/codec/lpc10/f2c.h
new file mode 100644 (file)
index 0000000..71946f0
--- /dev/null
@@ -0,0 +1,325 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:26:28  jaf\r
+ * Any typedef defining a type that was used in lpc10_encoder_state or\r
+ * lpc10_decoder_state struct's was commented out here and added to\r
+ * lpc10.h.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:13  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*\r
+ * f2c.h\r
+ *\r
+ * SCCS ID:  @(#)f2c.h 1.2 96/05/19\r
+ */\r
+\r
+/* f2c.h  --  Standard Fortran to C header file */\r
+\r
+/**  barf  [ba:rf]  2.  "He suggested using FORTRAN, and everybody barfed."\r
+\r
+       - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */\r
+\r
+#ifndef F2C_INCLUDE\r
+#define F2C_INCLUDE\r
+\r
+#include "lpc10.h"\r
+\r
+/*typedef long int integer;*/\r
+/*typedef INT32 integer;*/\r
+/*typedef short int shortint;*/\r
+/*typedef INT16 shortint;*/\r
+/*typedef float real;*/\r
+/* doublereal only used for function arguments to sqrt, exp, etc. */\r
+typedef double doublereal;\r
+/* 32 bits seems wasteful, but there really aren't that many logical\r
+ * variables around, and making them 32 bits could avoid word\r
+ * alignment problems, perhaps.  */\r
+/*typedef long int logical;*/\r
+/*typedef INT32 logical;*/\r
+/* The following types are not used in the translated C code for the\r
+ * LPC-10 coder, but they might be needed by the definitions down\r
+ * below, so they don't cause compilation errors.  */\r
+typedef char *address;\r
+typedef struct { real r, i; } complex;\r
+typedef struct { doublereal r, i; } doublecomplex;\r
+typedef short int shortlogical;\r
+typedef char logical1;\r
+typedef char integer1;\r
+/* typedef long long longint; */ /* system-dependent */\r
+\r
+#define TRUE_ (1)\r
+#define FALSE_ (0)\r
+\r
+/* Extern is for use with -E */\r
+#ifndef Extern\r
+#define Extern extern\r
+#endif\r
+\r
+/* I/O stuff */\r
+\r
+#ifdef f2c_i2\r
+/* for -i2 */\r
+typedef short flag;\r
+typedef short ftnlen;\r
+typedef short ftnint;\r
+#else\r
+typedef long int flag;\r
+typedef long int ftnlen;\r
+typedef long int ftnint;\r
+#endif\r
+\r
+/*external read, write*/\r
+typedef struct\r
+{      flag cierr;\r
+       ftnint ciunit;\r
+       flag ciend;\r
+       char *cifmt;\r
+       ftnint cirec;\r
+} cilist;\r
+\r
+/*internal read, write*/\r
+typedef struct\r
+{      flag icierr;\r
+       char *iciunit;\r
+       flag iciend;\r
+       char *icifmt;\r
+       ftnint icirlen;\r
+       ftnint icirnum;\r
+} icilist;\r
+\r
+/*open*/\r
+typedef struct\r
+{      flag oerr;\r
+       ftnint ounit;\r
+       char *ofnm;\r
+       ftnlen ofnmlen;\r
+       char *osta;\r
+       char *oacc;\r
+       char *ofm;\r
+       ftnint orl;\r
+       char *oblnk;\r
+} olist;\r
+\r
+/*close*/\r
+typedef struct\r
+{      flag cerr;\r
+       ftnint cunit;\r
+       char *csta;\r
+} cllist;\r
+\r
+/*rewind, backspace, endfile*/\r
+typedef struct\r
+{      flag aerr;\r
+       ftnint aunit;\r
+} alist;\r
+\r
+/* inquire */\r
+typedef struct\r
+{      flag inerr;\r
+       ftnint inunit;\r
+       char *infile;\r
+       ftnlen infilen;\r
+       ftnint  *inex;  /*parameters in standard's order*/\r
+       ftnint  *inopen;\r
+       ftnint  *innum;\r
+       ftnint  *innamed;\r
+       char    *inname;\r
+       ftnlen  innamlen;\r
+       char    *inacc;\r
+       ftnlen  inacclen;\r
+       char    *inseq;\r
+       ftnlen  inseqlen;\r
+       char    *indir;\r
+       ftnlen  indirlen;\r
+       char    *infmt;\r
+       ftnlen  infmtlen;\r
+       char    *inform;\r
+       ftnint  informlen;\r
+       char    *inunf;\r
+       ftnlen  inunflen;\r
+       ftnint  *inrecl;\r
+       ftnint  *innrec;\r
+       char    *inblank;\r
+       ftnlen  inblanklen;\r
+} inlist;\r
+\r
+#define VOID void\r
+\r
+union Multitype {      /* for multiple entry points */\r
+       integer1 g;\r
+       shortint h;\r
+       integer i;\r
+       /* longint j; */\r
+       real r;\r
+       doublereal d;\r
+       complex c;\r
+       doublecomplex z;\r
+       };\r
+\r
+typedef union Multitype Multitype;\r
+\r
+/*typedef long int Long;*/     /* No longer used; formerly in Namelist */\r
+\r
+struct Vardesc {       /* for Namelist */\r
+       char *name;\r
+       char *addr;\r
+       ftnlen *dims;\r
+       int  type;\r
+       };\r
+typedef struct Vardesc Vardesc;\r
+\r
+struct Namelist {\r
+       char *name;\r
+       Vardesc **vars;\r
+       int nvars;\r
+       };\r
+typedef struct Namelist Namelist;\r
+\r
+#define abs(x) ((x) >= 0 ? (x) : -(x))\r
+#define dabs(x) (doublereal)abs(x)\r
+#define min(a,b) ((a) <= (b) ? (a) : (b))\r
+#define max(a,b) ((a) >= (b) ? (a) : (b))\r
+#define dmin(a,b) (doublereal)min(a,b)\r
+#define dmax(a,b) (doublereal)max(a,b)\r
+\r
+/* procedure parameter types for -A and -C++ */\r
+\r
+#define F2C_proc_par_types 1\r
+#ifdef __cplusplus\r
+typedef int /* Unknown procedure type */ (*U_fp)(...);\r
+typedef shortint (*J_fp)(...);\r
+typedef integer (*I_fp)(...);\r
+typedef real (*R_fp)(...);\r
+typedef doublereal (*D_fp)(...), (*E_fp)(...);\r
+typedef /* Complex */ VOID (*C_fp)(...);\r
+typedef /* Double Complex */ VOID (*Z_fp)(...);\r
+typedef logical (*L_fp)(...);\r
+typedef shortlogical (*K_fp)(...);\r
+typedef /* Character */ VOID (*H_fp)(...);\r
+typedef /* Subroutine */ int (*S_fp)(...);\r
+#else\r
+typedef int /* Unknown procedure type */ (*U_fp)(VOID);\r
+typedef shortint (*J_fp)(VOID);\r
+typedef integer (*I_fp)(VOID);\r
+typedef real (*R_fp)(VOID);\r
+typedef doublereal (*D_fp)(VOID), (*E_fp)(VOID);\r
+typedef /* Complex */ VOID (*C_fp)(VOID);\r
+typedef /* Double Complex */ VOID (*Z_fp)(VOID);\r
+typedef logical (*L_fp)(VOID);\r
+typedef shortlogical (*K_fp)(VOID);\r
+typedef /* Character */ VOID (*H_fp)(VOID);\r
+typedef /* Subroutine */ int (*S_fp)(VOID);\r
+#endif\r
+/* E_fp is for real functions when -R is not specified */\r
+typedef VOID C_f;      /* complex function */\r
+typedef VOID H_f;      /* character function */\r
+typedef VOID Z_f;      /* double complex function */\r
+typedef doublereal E_f;        /* real function with -R not specified */\r
+\r
+/* undef any lower-case symbols that your C compiler predefines, e.g.: */\r
+\r
+#ifndef Skip_f2c_Undefs\r
+#undef cray\r
+#undef gcos\r
+#undef mc68010\r
+#undef mc68020\r
+#undef mips\r
+#undef pdp11\r
+#undef sgi\r
+#undef sparc\r
+#undef sun\r
+#undef sun2\r
+#undef sun3\r
+#undef sun4\r
+#undef u370\r
+#undef u3b\r
+#undef u3b2\r
+#undef u3b5\r
+#undef unix\r
+#undef vax\r
+#endif\r
+\r
+#ifdef KR_headers\r
+extern integer pow_ii(ap, bp);\r
+extern double r_sign(a,b);\r
+extern integer i_nint(x);\r
+#else\r
+extern integer pow_ii(integer *ap, integer *bp);\r
+extern double r_sign(real *a, real *b);\r
+extern integer i_nint(real *x);\r
+\r
+#endif\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int bsynz_(real *coef, integer *ip, integer *iv, \r
+                  real *sout, real *rms, real *ratio, real *g2pass,\r
+                  struct lpc10_decoder_state *st);\r
+extern int chanwr_(integer *order, integer *ipitv, integer *irms,\r
+                   integer *irc, integer *ibits, struct lpc10_encoder_state *st);\r
+extern int chanrd_(integer *order, integer *ipitv, integer *irms,\r
+                   integer *irc, integer *ibits);\r
+extern int chanwr_0_(int n__, integer *order, integer *ipitv, \r
+                     integer *irms, integer *irc, integer *ibits,\r
+                     struct lpc10_encoder_state *st);\r
+extern int dcbias_(integer *len, real *speech, real *sigout);\r
+extern int decode_(integer *ipitv, integer *irms, integer *irc, \r
+                   integer *voice, integer *pitch, real *rms,\r
+                   real *rc, struct lpc10_decoder_state *st);\r
+extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);\r
+extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau,\r
+                   integer *maxlag, real *amdf, integer *minptr, integer *maxptr);\r
+extern int dyptrk_(real *amdf, integer *ltau, integer *\r
+                   minptr, integer *voice, integer *pitch, integer *midx,\r
+                   struct lpc10_encoder_state *st);\r
+extern int encode_(integer *voice, integer *pitch, real *rms, real *rc,\r
+                   integer *ipitch, integer *irms, integer *irc);\r
+extern int energy_(integer *len, real *speech, real *rms);\r
+extern int ham84_(integer *input, integer *output, integer *errcnt);\r
+extern int hp100_(real *speech, integer *start, integer *end,\r
+                 struct lpc10_encoder_state *st);\r
+extern int inithp100_(void);\r
+extern int invert_(integer *order, real *phi, real *psi, real *rc);\r
+extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);\r
+extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);\r
+extern int lpcdec_(integer *bits, real *speech);\r
+extern int initlpcdec_(void);\r
+extern int lpcenc_(real *speech, integer *bits);\r
+extern int initlpcenc_(void);\r
+extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);\r
+extern integer median_(integer *d1, integer *d2, integer *d3);\r
+extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);\r
+extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);\r
+extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);\r
+extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);\r
+extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);\r
+extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);\r
+extern int prepro_(real *speech, integer *length,\r
+                  struct lpc10_encoder_state *st);\r
+extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);\r
+extern integer random_(struct lpc10_decoder_state *st);\r
+extern int rcchk_(integer *order, real *rc1f, real *rc2f);\r
+extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);\r
+extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);\r
+extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);\r
+extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);\r
+\r
+#endif\r
+\r
+\r
+#endif /* ! defined F2C_INCLUDE */\r
diff --git a/libs/codec/lpc10/f2clib.c b/libs/codec/lpc10/f2clib.c
new file mode 100644 (file)
index 0000000..aaee644
--- /dev/null
@@ -0,0 +1,85 @@
+/*\r
+\r
+$Log$\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:10  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*\r
+ * f2clib.c\r
+ *\r
+ * SCCS ID:  @(#)f2clib.c 1.2 96/05/19\r
+ */\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef KR_headers\r
+integer pow_ii(ap, bp) integer *ap, *bp;\r
+#else\r
+integer pow_ii(integer *ap, integer *bp)\r
+#endif\r
+{\r
+       integer pow, x, n;\r
+       unsigned long u;\r
+\r
+       x = *ap;\r
+       n = *bp;\r
+\r
+       if (n <= 0) {\r
+               if (n == 0 || x == 1)\r
+                       return 1;\r
+               if (x != -1)\r
+                       return x == 0 ? 1/x : 0;\r
+               n = -n;\r
+               }\r
+       u = n;\r
+       for(pow = 1; ; )\r
+               {\r
+               if(u & 01)\r
+                       pow *= x;\r
+               if(u >>= 1)\r
+                       x *= x;\r
+               else\r
+                       break;\r
+               }\r
+       return(pow);\r
+       }\r
+\r
+\r
+\r
+#ifdef KR_headers\r
+double r_sign(a,b) real *a, *b;\r
+#else\r
+double r_sign(real *a, real *b)\r
+#endif\r
+{\r
+double x;\r
+x = (*a >= 0 ? *a : - *a);\r
+return( *b >= 0 ? x : -x);\r
+}\r
+\r
+\r
+\r
+#ifdef KR_headers\r
+double floor();\r
+integer i_nint(x) real *x;\r
+#else\r
+#undef abs\r
+#include "math.h"\r
+integer i_nint(real *x)\r
+#endif\r
+{\r
+return( (*x)>=0 ?\r
+       floor(*x + .5) : -floor(.5 - *x) );\r
+}\r
diff --git a/libs/codec/lpc10/ham84.c b/libs/codec/lpc10/ham84.c
new file mode 100644 (file)
index 0000000..d6a1351
--- /dev/null
@@ -0,0 +1,126 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:07  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int ham84_(integer *input, integer *output, integer *errcnt);\r
+#endif\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     HAM84 Version 45G */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:07  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/21  15:26:00  jaf */\r
+/* Put comment header in standard form. */\r
+\r
+/* Revision 1.2  1996/03/13  22:00:13  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:04  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*  Hamming 8,4 Decoder - can correct 1 out of seven bits */\r
+/*   and can detect up to two errors. */\r
+\r
+/* Input: */\r
+/*  INPUT  - Seven bit data word, 4 bits parameter and */\r
+/*           4 bits parity information */\r
+/* Input/Output: */\r
+/*  ERRCNT - Sums errors detected by Hamming code */\r
+/* Output: */\r
+/*  OUTPUT - 4 corrected parameter bits */\r
+\r
+/* This subroutine is entered with an eight bit word in INPUT.  The 8th */\r
+/* bit is parity and is stripped off.  The remaining 7 bits address the */\r
+/* hamming 8,4 table and the output OUTPUT from the table gives the 4 */\r
+/* bits of corrected data.  If bit 4 is set, no error was detected. */\r
+/* ERRCNT is the number of errors counted. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int ham84_(integer *input, integer *output, integer *errcnt)\r
+{\r
+    /* Initialized data */\r
+\r
+    static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,\r
+           9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,\r
+           12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,\r
+           6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,\r
+           8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,\r
+           12,15,15,31 };\r
+\r
+    integer i__, j, parity;\r
+\r
+/*       Arguments */\r
+/*       Parameters/constants */\r
+/*       Local variables that need not be saved */\r
+/*  Determine parity of input word */\r
+    parity = *input & 255;\r
+    parity ^= parity / 16;\r
+    parity ^= parity / 4;\r
+    parity ^= parity / 2;\r
+    parity &= 1;\r
+    i__ = dactab[*input & 127];\r
+    *output = i__ & 15;\r
+    j = i__ & 16;\r
+    if (j != 0) {\r
+/*          No errors detected in seven bits */\r
+       if (parity != 0) {\r
+           ++(*errcnt);\r
+       }\r
+    } else {\r
+/*          One or two errors detected */\r
+       ++(*errcnt);\r
+       if (parity == 0) {\r
+/*             Two errors detected */\r
+           ++(*errcnt);\r
+           *output = -1;\r
+       }\r
+    }\r
+    return 0;\r
+} /* ham84_ */\r
+\r
diff --git a/libs/codec/lpc10/hp100.c b/libs/codec/lpc10/hp100.c
new file mode 100644 (file)
index 0000000..7c2798e
--- /dev/null
@@ -0,0 +1,169 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:28:05  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:04  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int hp100_(real *speech, integer *start, integer *end,\r
+                 struct lpc10_encoder_state *st);\r
+extern int inithp100_(void);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*      HP100 Version 55 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:28:05  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:32:04  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.6  1996/03/15  16:45:25  jaf */\r
+/* Rearranged a few comments. */\r
+\r
+/* Revision 1.5  1996/03/14  23:20:54  jaf */\r
+/* Added comments about when INITHP100 should be used. */\r
+\r
+/* Revision 1.4  1996/03/14  23:08:08  jaf */\r
+/* Added an entry named INITHP100 that initializes the local state of */\r
+/* subroutine HP100. */\r
+\r
+/* Revision 1.3  1996/03/14  22:09:20  jaf */\r
+/* Comments added explaining which of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next, and which */\r
+/* do not. */\r
+\r
+/* Revision 1.2  1996/02/12  15:05:54  jaf */\r
+/* Added lots of comments explaining why I changed one line, which was a */\r
+/* declaration with initializations. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:12  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*    100 Hz High Pass Filter */\r
+\r
+/* Jan 92 - corrected typo (1.937148 to 1.935715), */\r
+/*          rounded coefficients to 7 places, */\r
+/*          corrected and merged gain (.97466**4), */\r
+/*          merged numerator into first two sections. */\r
+\r
+/* Input: */\r
+/*  start, end - Range of samples to filter */\r
+/* Input/Output: */\r
+/*  speech(end) - Speech data. */\r
+/*                Indices start through end are read and modified. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITHP100. */\r
+/* Subroutine */ int hp100_(real *speech, integer *start, integer *end,\r
+       struct lpc10_encoder_state *st)\r
+{\r
+    /* Temporary local copies of variables in lpc10_encoder_state.\r
+       I've only created these because it might cause the loop below\r
+       to execute a bit faster to access local variables, rather than\r
+       variables in the lpc10_encoder_state structure.  It is just a\r
+       guess that it will be faster. */\r
+\r
+    real z11;\r
+    real z21;\r
+    real z12;\r
+    real z22;\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    integer i__;\r
+    real si, err;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+    /* Parameter adjustments */\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+    z11 = st->z11;\r
+    z21 = st->z21;\r
+    z12 = st->z12;\r
+    z22 = st->z22;\r
+\r
+    i__1 = *end;\r
+    for (i__ = *start; i__ <= i__1; ++i__) {\r
+       si = speech[i__];\r
+       err = si + z11 * 1.859076f - z21 * .8648249f;\r
+       si = err - z11 * 2.f + z21;\r
+       z21 = z11;\r
+       z11 = err;\r
+       err = si + z12 * 1.935715f - z22 * .9417004f;\r
+       si = err - z12 * 2.f + z22;\r
+       z22 = z12;\r
+       z12 = err;\r
+       speech[i__] = si * .902428f;\r
+    }\r
+\r
+    st->z11 = z11;\r
+    st->z21 = z21;\r
+    st->z12 = z12;\r
+    st->z22 = z22;\r
+\r
+    return 0;\r
+} /* hp100_ */\r
diff --git a/libs/codec/lpc10/invert.c b/libs/codec/lpc10/invert.c
new file mode 100644 (file)
index 0000000..8891d1c
--- /dev/null
@@ -0,0 +1,193 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:32:00  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int invert_(integer *order, real *phi, real *psi, real *rc);\r
+#endif\r
+\r
+/* **************************************************************** */\r
+\r
+/*     INVERT Version 45G */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:00  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/18  20:52:47  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:51:32  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Eliminated a comment from the original, describing a local array X */\r
+/* that appeared nowhere in the code. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:20  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* **************************************************************** */\r
+\r
+/*  Invert a covariance matrix using Choleski decomposition method. */\r
+\r
+/* Input: */\r
+/*  ORDER            - Analysis order */\r
+/*  PHI(ORDER,ORDER) - Covariance matrix */\r
+/*                    Indices (I,J) read, where ORDER .GE. I .GE. J .GE. 1.*/\r
+/*                     All other indices untouched. */\r
+/*  PSI(ORDER)       - Column vector to be predicted */\r
+/*                     Indices 1 through ORDER read. */\r
+/* Output: */\r
+/*  RC(ORDER)        - Pseudo reflection coefficients */\r
+/*                    Indices 1 through ORDER written, and then possibly read.\r
+*/\r
+/* Internal: */\r
+/*  V(ORDER,ORDER)   - Temporary matrix */\r
+/*                     Same indices written as read from PHI. */\r
+/*                     Many indices may be read and written again after */\r
+/*                     initially being copied from PHI, but all indices */\r
+/*                     are written before being read. */\r
+\r
+/*  NOTE: Temporary matrix V is not needed and may be replaced */\r
+/*    by PHI if the original PHI values do not need to be preserved. */\r
+\r
+/* Subroutine */ int invert_(integer *order, real *phi, real *psi, real *rc)\r
+{\r
+    /* System generated locals */\r
+    integer phi_dim1, phi_offset, i__1, i__2, i__3;\r
+    real r__1, r__2;\r
+\r
+    /* Local variables */\r
+    real save;\r
+    integer i__, j, k;\r
+    real v[100]        /* was [10][10] */;\r
+\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:32:00  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*     Parameters/constants */\r
+/*       Local variables that need not be saved */\r
+/*  Decompose PHI into V * D * V' where V is a triangular matrix whose */\r
+/*   main diagonal elements are all 1, V' is the transpose of V, and */\r
+/*   D is a vector.  Here D(n) is stored in location V(n,n). */\r
+    /* Parameter adjustments */\r
+    --rc;\r
+    --psi;\r
+    phi_dim1 = *order;\r
+    phi_offset = phi_dim1 + 1;\r
+    phi -= phi_offset;\r
+\r
+    /* Function Body */\r
+    i__1 = *order;\r
+    for (j = 1; j <= i__1; ++j) {\r
+       i__2 = *order;\r
+       for (i__ = j; i__ <= i__2; ++i__) {\r
+           v[i__ + j * 10 - 11] = phi[i__ + j * phi_dim1];\r
+       }\r
+       i__2 = j - 1;\r
+       for (k = 1; k <= i__2; ++k) {\r
+           save = v[j + k * 10 - 11] * v[k + k * 10 - 11];\r
+           i__3 = *order;\r
+           for (i__ = j; i__ <= i__3; ++i__) {\r
+               v[i__ + j * 10 - 11] -= v[i__ + k * 10 - 11] * save;\r
+           }\r
+       }\r
+/*  Compute intermediate results, which are similar to RC's */\r
+       if ((r__1 = v[j + j * 10 - 11], abs(r__1)) < 1e-10f) {\r
+           goto L100;\r
+       }\r
+       rc[j] = psi[j];\r
+       i__2 = j - 1;\r
+       for (k = 1; k <= i__2; ++k) {\r
+           rc[j] -= rc[k] * v[j + k * 10 - 11];\r
+       }\r
+       v[j + j * 10 - 11] = 1.f / v[j + j * 10 - 11];\r
+       rc[j] *= v[j + j * 10 - 11];\r
+/* Computing MAX */\r
+/* Computing MIN */\r
+       r__2 = rc[j];\r
+       r__1 = min(r__2,.999f);\r
+       rc[j] = max(r__1,-.999f);\r
+    }\r
+    return 0;\r
+/*  Zero out higher order RC's if algorithm terminated early */\r
+L100:\r
+    i__1 = *order;\r
+    for (i__ = j; i__ <= i__1; ++i__) {\r
+       rc[i__] = 0.f;\r
+    }\r
+/*  Back substitute for PC's (if needed) */\r
+/* 110 DO J = ORDER,1,-1 */\r
+/*        PC(J) = RC(J) */\r
+/*        DO I = 1,J-1 */\r
+/*           PC(J) = PC(J) - PC(I)*V(J,I) */\r
+/*        END DO */\r
+/*     END DO */\r
+    return 0;\r
+} /* invert_ */\r
+\r
diff --git a/libs/codec/lpc10/irc2pc.c b/libs/codec/lpc10/irc2pc.c
new file mode 100644 (file)
index 0000000..2a62881
--- /dev/null
@@ -0,0 +1,151 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:56  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);\r
+#endif\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     IRC2PC Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:56  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/20  15:47:19  jaf */\r
+/* Added comments about which indices of array arguments are read or */\r
+/* written. */\r
+\r
+/* Revision 1.2  1996/03/14  16:59:04  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:27  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*   Convert Reflection Coefficients to Predictor Coeficients */\r
+\r
+/* Inputs: */\r
+/*  RC     - Reflection coefficients */\r
+/*           Indices 1 through ORDER read. */\r
+/*  ORDER  - Number of RC's */\r
+/*  GPRIME - Excitation modification gain */\r
+/* Outputs: */\r
+/*  PC     - Predictor coefficients */\r
+/*           Indices 1 through ORDER written. */\r
+/*           Indices 1 through ORDER-1 are read after being written. */\r
+/*  G2PASS - Excitation modification sharpening factor */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int irc2pc_(real *rc, real *pc, integer *order, real *gprime,\r
+        real *g2pass)\r
+{\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+\r
+    /* Builtin functions */\r
+    double sqrt(doublereal);\r
+\r
+    /* Local variables */\r
+    real temp[10];\r
+    integer i__, j;\r
+\r
+/*     Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:56  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    --pc;\r
+    --rc;\r
+\r
+    /* Function Body */\r
+    *g2pass = 1.f;\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       *g2pass *= 1.f - rc[i__] * rc[i__];\r
+    }\r
+    *g2pass = *gprime * sqrt(*g2pass);\r
+    pc[1] = rc[1];\r
+    i__1 = *order;\r
+    for (i__ = 2; i__ <= i__1; ++i__) {\r
+       i__2 = i__ - 1;\r
+       for (j = 1; j <= i__2; ++j) {\r
+           temp[j - 1] = pc[j] - rc[i__] * pc[i__ - j];\r
+       }\r
+       i__2 = i__ - 1;\r
+       for (j = 1; j <= i__2; ++j) {\r
+           pc[j] = temp[j - 1];\r
+       }\r
+       pc[i__] = rc[i__];\r
+    }\r
+    return 0;\r
+} /* irc2pc_ */\r
+\r
diff --git a/libs/codec/lpc10/ivfilt.c b/libs/codec/lpc10/ivfilt.c
new file mode 100644 (file)
index 0000000..625dd3e
--- /dev/null
@@ -0,0 +1,136 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.2  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:53  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     IVFILT Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:53  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/15  21:36:29  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  00:01:00  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:34  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*   2nd order inverse filter, speech is decimated 4:1 */\r
+\r
+/* Input: */\r
+/*  LEN    - Length of speech buffers */\r
+/*  NSAMP  - Number of samples to filter */\r
+/*  LPBUF  - Low pass filtered speech buffer */\r
+/*           Indices LEN-NSAMP-7 through LEN read. */\r
+/* Output: */\r
+/*  IVBUF  - Inverse filtered speech buffer */\r
+/*           Indices LEN-NSAMP+1 through LEN written. */\r
+/*  IVRC   - Inverse filter reflection coefficients (for voicing) */\r
+/*          Indices 1 and 2 both written (also read, but only after writing).\r
+*/\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *\r
+       nsamp, real *ivrc)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    integer i__, j, k;\r
+    real r__[3], pc1, pc2;\r
+\r
+/*     Arguments */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       None */\r
+/*  Calculate Autocorrelations */\r
+    /* Parameter adjustments */\r
+    --ivbuf;\r
+    --lpbuf;\r
+    --ivrc;\r
+\r
+    /* Function Body */\r
+    for (i__ = 1; i__ <= 3; ++i__) {\r
+       r__[i__ - 1] = 0.f;\r
+       k = (i__ - 1) << 2;\r
+       i__1 = *len;\r
+       for (j = (i__ << 2) + *len - *nsamp; j <= i__1; j += 2) {\r
+           r__[i__ - 1] += lpbuf[j] * lpbuf[j - k];\r
+       }\r
+    }\r
+/*  Calculate predictor coefficients */\r
+    pc1 = 0.f;\r
+    pc2 = 0.f;\r
+    ivrc[1] = 0.f;\r
+    ivrc[2] = 0.f;\r
+    if (r__[0] > 1e-10f) {\r
+       ivrc[1] = r__[1] / r__[0];\r
+       ivrc[2] = (r__[2] - ivrc[1] * r__[1]) / (r__[0] - ivrc[1] * r__[1]);\r
+       pc1 = ivrc[1] - ivrc[1] * ivrc[2];\r
+       pc2 = ivrc[2];\r
+    }\r
+/*  Inverse filter LPBUF into IVBUF */\r
+    i__1 = *len;\r
+    for (i__ = *len + 1 - *nsamp; i__ <= i__1; ++i__) {\r
+       ivbuf[i__] = lpbuf[i__] - pc1 * lpbuf[i__ - 4] - pc2 * lpbuf[i__ - 8];\r
+    }\r
+    return 0;\r
+} /* ivfilt_ */\r
+\r
diff --git a/libs/codec/lpc10/lpc10.h b/libs/codec/lpc10/lpc10.h
new file mode 100644 (file)
index 0000000..17d0491
--- /dev/null
@@ -0,0 +1,248 @@
+/*\r
+\r
+$Log$\r
+Revision 1.18  2004/08/31 13:32:11  markster\r
+Merge NetBSD and Courtesty tone with modifications (bug #2329)\r
+\r
+Revision 1.17  2003/10/26 18:50:49  markster\r
+Make it build and run on MacOS X\r
+\r
+Revision 1.3  2003/10/26 18:50:49  markster\r
+Make it build and run on MacOS X\r
+\r
+Revision 1.2  2003/04/23 19:13:35  markster\r
+More OpenBSD patches\r
+\r
+Revision 1.1.1.2  2003/03/16 22:37:30  matteo\r
+dom mar 16 23:37:23 CET 2003\r
+\r
+Revision 1.2  2003/03/16 16:09:48  markster\r
+Mere James's cleanups for fewer build warnings\r
+\r
+Revision 1.1  2000/01/05 00:20:06  markster\r
+Add broken lpc10 code...  It's not too far from working I don't think...\r
+\r
+ * Revision 1.1  1996/08/19  22:47:31  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+#ifndef __LPC10_H__\r
+#define __LPC10_H__\r
+\r
+#define LPC10_SAMPLES_PER_FRAME 180\r
+#define LPC10_BITS_IN_COMPRESSED_FRAME 54\r
+\r
+\r
+/*\r
+\r
+  The "#if defined"'s in this file are by no means intended to be\r
+  complete.  They are what Nautilus uses, which has been successfully\r
+  compiled under DOS with the Microsoft C compiler, and under a few\r
+  versions of Unix with the GNU C compiler.\r
+\r
+ */\r
+\r
+#if defined(unix) || defined(__unix__) || defined(__NetBSD__)\r
+typedef short          INT16;\r
+typedef int            INT32;\r
+#endif\r
+\r
+\r
+#if defined(__MSDOS__) || defined(MSDOS)\r
+typedef int            INT16;\r
+typedef long           INT32;\r
+#endif\r
+\r
+#if defined(__APPLE__)\r
+typedef short          INT16;\r
+typedef int            INT32;\r
+#endif\r
+\r
+\r
+/* The initial values for every member of this structure is 0, except\r
+   where noted in comments. */\r
+\r
+/* These two lines are copied from f2c.h.  There should be a more\r
+   elegant way of doing this than having the same declarations in two\r
+   files. */\r
+\r
+typedef float real;\r
+typedef INT32 integer;\r
+typedef INT32 logical;\r
+typedef INT16 shortint;\r
+\r
+struct lpc10_encoder_state {\r
+    /* State used only by function hp100 */\r
+    real z11;\r
+    real z21;\r
+    real z12;\r
+    real z22;\r
+    \r
+    /* State used by function analys */\r
+    real inbuf[540], pebuf[540];\r
+    real lpbuf[696], ivbuf[312];\r
+    real bias;\r
+    integer osbuf[10];  /* no initial value necessary */\r
+    integer osptr;     /* initial value 1 */\r
+    integer obound[3];\r
+    integer vwin[6]    /* was [2][3] */;   /* initial value vwin[4] = 307; vwin[5] = 462; */\r
+    integer awin[6]    /* was [2][3] */;   /* initial value awin[4] = 307; awin[5] = 462; */\r
+    integer voibuf[8]  /* was [2][4] */;\r
+    real rmsbuf[3];\r
+    real rcbuf[30]     /* was [10][3] */;\r
+    real zpre;\r
+\r
+\r
+    /* State used by function onset */\r
+    real n;\r
+    real d__;   /* initial value 1.f */\r
+    real fpc;   /* no initial value necessary */\r
+    real l2buf[16];\r
+    real l2sum1;\r
+    integer l2ptr1;   /* initial value 1 */\r
+    integer l2ptr2;   /* initial value 9 */\r
+    integer lasti;    /* no initial value necessary */\r
+    logical hyst;   /* initial value FALSE_ */\r
+\r
+    /* State used by function voicin */\r
+    real dither;   /* initial value 20.f */\r
+    real snr;\r
+    real maxmin;\r
+    real voice[6]      /* was [2][3] */;   /* initial value is probably unnecessary */\r
+    integer lbve, lbue, fbve, fbue;\r
+    integer ofbue, sfbue;\r
+    integer olbue, slbue;\r
+    /* Initial values:\r
+       lbve = 3000;\r
+       fbve = 3000;\r
+       fbue = 187;\r
+       ofbue = 187;\r
+       sfbue = 187;\r
+       lbue = 93;\r
+       olbue = 93;\r
+       slbue = 93;\r
+       snr = (real) (fbve / fbue << 6);\r
+       */\r
+\r
+    /* State used by function dyptrk */\r
+    real s[60];\r
+    integer p[120]     /* was [60][2] */;\r
+    integer ipoint;\r
+    real alphax;\r
+\r
+    /* State used by function chanwr */\r
+    integer isync;\r
+\r
+};\r
+\r
+\r
+struct lpc10_decoder_state {\r
+\r
+    /* State used by function decode */\r
+    integer iptold;   /* initial value 60 */\r
+    logical first;   /* initial value TRUE_ */\r
+    integer ivp2h;\r
+    integer iovoic;\r
+    integer iavgp;   /* initial value 60 */\r
+    integer erate;\r
+    integer drc[30]    /* was [3][10] */;\r
+    integer dpit[3];\r
+    integer drms[3];\r
+\r
+    /* State used by function synths */\r
+    real buf[360];\r
+    integer buflen;   /* initial value 180 */\r
+\r
+    /* State used by function pitsyn */\r
+    integer ivoico;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    integer ipito;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    real rmso;   /* initial value 1.f */\r
+    real rco[10];   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    integer jsamp;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    logical first_pitsyn;   /* initial value TRUE_ */\r
+\r
+    /* State used by function bsynz */\r
+    integer ipo;\r
+    real exc[166];\r
+    real exc2[166];\r
+    real lpi1;\r
+    real lpi2;\r
+    real lpi3;\r
+    real hpi1;\r
+    real hpi2;\r
+    real hpi3;\r
+    real rmso_bsynz;\r
+\r
+    /* State used by function random */\r
+    integer j;   /* initial value 2 */\r
+    integer k;   /* initial value 5 */\r
+    shortint y[5];  /* initial value { -21161,-8478,30892,-10216,16950 } */\r
+\r
+    /* State used by function deemp */\r
+    real dei1;\r
+    real dei2;\r
+    real deo1;\r
+    real deo2;\r
+    real deo3;\r
+\r
+};\r
+\r
+\r
+\r
+/*\r
+\r
+  Calling sequence:\r
+\r
+  Call create_lpc10_encoder_state(), which returns a pointer to an\r
+  already initialized lpc10_encoder_state structure.\r
+\r
+  lpc10_encode reads indices 0 through (LPC10_SAMPLES_PER_FRAME-1) of\r
+  array speech[], and writes indices 0 through\r
+  (LPC10_BITS_IN_COMPRESSED_FRAME-1) of array bits[], and both reads\r
+  and writes the lpc10_encoder_state structure contents.  The\r
+  lpc10_encoder_state structure should *not* be initialized for every\r
+  frame of encoded speech.  Once at the beginning of execution, done\r
+  automatically for you by create_lpc10_encoder_state(), is enough.\r
+\r
+  init_lpc10_encoder_state() reinitializes the lpc10_encoder_state\r
+  structure.  This might be useful if you are finished processing one\r
+  sound sample, and want to reuse the same lpc10_encoder_state\r
+  structure to process another sound sample.  There might be other\r
+  uses as well.\r
+\r
+  Note that the comments in the lpc10/lpcenc.c file imply that indices\r
+  1 through 180 of array speech[] are read.  These comments were\r
+  written for the Fortran version of the code, before it was\r
+  automatically converted to C by the conversion program f2c.  f2c\r
+  seems to use the convention that the pointers to arrays passed as\r
+  function arguments point to the first index used in the Fortran\r
+  code, whatever index that might be (usually 1), and then it modifies\r
+  the pointer inside of the function, like so:\r
+\r
+  if (speech) {\r
+      --speech;\r
+  }\r
+\r
+  So that the code can access the first value at index 1 and the last\r
+  at index 180.  This makes the translated C code "closer" to the\r
+  original Fortran code.\r
+\r
+  The calling sequence for the decoder is similar to the encoder.  The\r
+  only significant difference is that the array bits[] is read\r
+  (indices 0 through (LPC10_BITS_IN_COMPRESSED_FRAME-1)), and the\r
+  array speech[] is written (indices 0 through\r
+  (LPC10_SAMPLES_PER_FRAME-1)).\r
+  \r
+  */\r
+\r
+struct lpc10_encoder_state * create_lpc10_encoder_state (void);\r
+void init_lpc10_encoder_state (struct lpc10_encoder_state *st);\r
+int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st);\r
+\r
+struct lpc10_decoder_state * create_lpc10_decoder_state (void);\r
+void init_lpc10_decoder_state (struct lpc10_decoder_state *st);\r
+int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st);\r
+\r
+#endif /* __LPC10_H__ */\r
diff --git a/libs/codec/lpc10/lpcdec.c b/libs/codec/lpc10/lpcdec.c
new file mode 100644 (file)
index 0000000..095f6f7
--- /dev/null
@@ -0,0 +1,297 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:30:11  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:48  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int lpcdec_(integer *bits, real *speech);\r
+extern int initlpcdec_(void);\r
+/* comlen contrl_ 12 */\r
+/*:ref: chanrd_ 14 5 4 4 4 4 4 */\r
+/*:ref: decode_ 14 7 4 4 4 4 4 6 6 */\r
+/*:ref: synths_ 14 6 4 4 6 6 6 4 */\r
+/*:ref: initdecode_ 14 0 */\r
+/*:ref: initsynths_ 14 0 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__10 = 10;\r
+\r
+/* ***************************************************************** */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:30:11  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:48  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.1  1996/03/28  00:03:00  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/* Decode 54 bits to one frame of 180 speech samples. */\r
+\r
+/* Input: */\r
+/*  BITS   - 54 encoded bits, stored 1 per array element. */\r
+/*           Indices 1 through 53 read (SYNC bit ignored). */\r
+/* Output: */\r
+/*  SPEECH - Speech encoded as real values in the range [-1,+1]. */\r
+/*           Indices 1 through 180 written. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITLPCDEC. */\r
+\r
+/* Subroutine */ int lpc10_decode(integer *bits, real *speech,\r
+                                 struct lpc10_decoder_state *st)\r
+{\r
+    integer irms, voice[2], pitch, ipitv;\r
+    extern /* Subroutine */ int decode_(integer *, integer *, integer *, \r
+           integer *, integer *, real *, real *, struct lpc10_decoder_state *);\r
+    real rc[10];\r
+    extern /* Subroutine */ int chanrd_(integer *, integer *, integer *, \r
+           integer *, integer *), synths_(integer *, \r
+           integer *, real *, real *, real *, integer *,\r
+                                          struct lpc10_decoder_state *);\r
+    integer irc[10], len;\r
+    real rms;\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:30:11  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:48  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:30:11  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:48  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Local variables that need not be saved */\r
+/*       Uncoded speech parameters */\r
+/*       Coded speech parameters */\r
+/*       Others */\r
+/*       Local state */\r
+/*       None */\r
+    /* Parameter adjustments */\r
+    if (bits) {\r
+       --bits;\r
+       }\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+    chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]);\r
+    decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st);\r
+    synths_(voice, &pitch, &rms, rc, &speech[1], &len, st);\r
+    return 0;\r
+} /* lpcdec_ */\r
diff --git a/libs/codec/lpc10/lpcenc.c b/libs/codec/lpc10/lpcenc.c
new file mode 100644 (file)
index 0000000..cb90d21
--- /dev/null
@@ -0,0 +1,181 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:31:21  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:44  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int lpcenc_(real *speech, integer *bits);\r
+extern int initlpcenc_(void);\r
+/*:ref: prepro_ 14 2 6 4 */\r
+/*:ref: analys_ 14 5 6 4 4 6 6 */\r
+/*:ref: encode_ 14 7 4 4 6 6 4 4 4 */\r
+/*:ref: chanwr_ 14 5 4 4 4 4 4 */\r
+/*:ref: initprepro_ 14 0 */\r
+/*:ref: initanalys_ 14 0 */\r
+#endif\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__180 = 180;\r
+static integer c__10 = 10;\r
+\r
+/* ***************************************************************** */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:31:21  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:44  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.2  1996/03/28  00:01:22  jaf */\r
+/* Commented out some trace statements. */\r
+\r
+/* Revision 1.1  1996/03/28  00:00:27  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/* Encode one frame of 180 speech samples to 54 bits. */\r
+\r
+/* Input: */\r
+/*  SPEECH - Speech encoded as real values in the range [-1,+1]. */\r
+/*           Indices 1 through 180 read, and modified (by PREPRO). */\r
+/* Output: */\r
+/*  BITS   - 54 encoded bits, stored 1 per array element. */\r
+/*           Indices 1 through 54 written. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITLPCENC. */\r
+\r
+/* Subroutine */ int lpc10_encode(real *speech, integer *bits,\r
+                                 struct lpc10_encoder_state *st)\r
+{\r
+    integer irms, voice[2], pitch, ipitv;\r
+    real rc[10];\r
+    extern /* Subroutine */ int encode_(integer *, integer *, real *, real *, \r
+           integer *, integer *, integer *), chanwr_(integer *, integer *, \r
+           integer *, integer *, integer *, struct lpc10_encoder_state *),\r
+            analys_(real *, integer *, \r
+           integer *, real *, real *, struct lpc10_encoder_state *),\r
+            prepro_(real *, integer *, struct lpc10_encoder_state *);\r
+    integer irc[10];\r
+    real rms;\r
+\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:31:21  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Changed name of function from lpcenc_ to lpc10_encode, simply to make\r
+ * all lpc10 functions have more consistent naming with each other.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:44  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Local variables that need not be saved */\r
+/*       Uncoded speech parameters */\r
+/*       Coded speech parameters */\r
+/*       Local state */\r
+/*       None */\r
+    /* Parameter adjustments */\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+    if (bits) {\r
+       --bits;\r
+       }\r
+\r
+    /* Function Body */\r
+    prepro_(&speech[1], &c__180, st);\r
+    analys_(&speech[1], voice, &pitch, &rms, rc, st);\r
+    encode_(voice, &pitch, &rms, rc, &ipitv, &irms, irc);\r
+    chanwr_(&c__10, &ipitv, &irms, irc, &bits[1], st);\r
+    return 0;\r
+} /* lpcenc_ */\r
diff --git a/libs/codec/lpc10/lpcini.c b/libs/codec/lpc10/lpcini.c
new file mode 100644 (file)
index 0000000..fbaf2f6
--- /dev/null
@@ -0,0 +1,446 @@
+/*\r
+\r
+$Log$\r
+Revision 1.18  2003/10/21 18:08:11  markster\r
+Fix include order\r
+\r
+Revision 1.5  2003/10/21 18:08:11  markster\r
+Fix include order\r
+\r
+Revision 1.4  2003/10/21 02:57:29  markster\r
+FreeBSD patch, take 2\r
+\r
+Revision 1.3  2003/10/16 21:11:30  martinp\r
+Revert the previous patch since it's braking compilation\r
+\r
+Revision 1.1  2003/02/12 13:59:15  matteo\r
+Initial revision\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:35:41  jaf\r
+ * Added functions for allocating and initializing lpc10_encoder_state\r
+ * and lpc10_decoder_state structures.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:40  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int lpcini_(void);\r
+/* comlen contrl_ 12 */\r
+/*:ref: initlpcenc_ 14 0 */\r
+/*:ref: initlpcdec_ 14 0 */\r
+#endif\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include <stdlib.h>\r
+#include "f2c.h"\r
+\r
+/* Common Block Declarations */\r
+\r
+struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* ***************************************************************** */\r
+\r
+/* $Log$\r
+ * Revision 1.18  2003/10/21 18:08:11  markster\r
+ * Fix include order\r
+ *\r
+/* Revision 1.5  2003/10/21 18:08:11  markster\r
+/* Fix include order\r
+/*\r
+/* Revision 1.4  2003/10/21 02:57:29  markster\r
+/* FreeBSD patch, take 2\r
+/*\r
+/* Revision 1.3  2003/10/16 21:11:30  martinp\r
+/* Revert the previous patch since it's braking compilation\r
+/*\r
+/* Revision 1.1  2003/02/12 13:59:15  matteo\r
+/* Initial revision\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:35:41  jaf\r
+ * Added functions for allocating and initializing lpc10_encoder_state\r
+ * and lpc10_decoder_state structures.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:40  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.1  1996/03/28  00:04:05  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/* Initialize COMMON block variables used by LPC-10 encoder and decoder, */\r
+/* and call initialization routines for both of them. */\r
+\r
+/* Subroutine */ int lpcini_(void)\r
+{\r
+\r
+/* $Log$\r
+ * Revision 1.18  2003/10/21 18:08:11  markster\r
+ * Fix include order\r
+ *\r
+/* Revision 1.5  2003/10/21 18:08:11  markster\r
+/* Fix include order\r
+/*\r
+/* Revision 1.4  2003/10/21 02:57:29  markster\r
+/* FreeBSD patch, take 2\r
+/*\r
+/* Revision 1.3  2003/10/16 21:11:30  martinp\r
+/* Revert the previous patch since it's braking compilation\r
+/*\r
+/* Revision 1.1  2003/02/12 13:59:15  matteo\r
+/* Initial revision\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:35:41  jaf\r
+ * Added functions for allocating and initializing lpc10_encoder_state\r
+ * and lpc10_decoder_state structures.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:40  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/* $Log$\r
+ * Revision 1.18  2003/10/21 18:08:11  markster\r
+ * Fix include order\r
+ *\r
+/* Revision 1.5  2003/10/21 18:08:11  markster\r
+/* Fix include order\r
+/*\r
+/* Revision 1.4  2003/10/21 02:57:29  markster\r
+/* FreeBSD patch, take 2\r
+/*\r
+/* Revision 1.3  2003/10/16 21:11:30  martinp\r
+/* Revert the previous patch since it's braking compilation\r
+/*\r
+/* Revision 1.1  2003/02/12 13:59:15  matteo\r
+/* Initial revision\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:35:41  jaf\r
+ * Added functions for allocating and initializing lpc10_encoder_state\r
+ * and lpc10_decoder_state structures.\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:40  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+    contrl_1.order = 10;\r
+    contrl_1.lframe = 180;\r
+    contrl_1.corrp = TRUE_;\r
+    return 0;\r
+} /* lpcini_ */\r
+\r
+\r
+\r
+/* Allocate memory for, and initialize, the state that needs to be\r
+   kept from encoding one frame to the next for a single\r
+   LPC-10-compressed audio stream.  Return 0 if malloc fails,\r
+   otherwise return pointer to new structure. */\r
+\r
+struct lpc10_encoder_state *\r
+create_lpc10_encoder_state()\r
+{\r
+    struct lpc10_encoder_state *st;\r
+\r
+    st = (struct lpc10_encoder_state *)\r
+       malloc((unsigned) sizeof (struct lpc10_encoder_state));\r
+    if (st != 0) {\r
+       init_lpc10_encoder_state(st);\r
+    }\r
+    return (st);\r
+}\r
+\r
+\r
+\r
+void init_lpc10_encoder_state(struct lpc10_encoder_state *st)\r
+{\r
+    int i;\r
+\r
+    lpcini_();\r
+\r
+    /* State used only by function hp100 */\r
+    st->z11 = 0.0f;\r
+    st->z21 = 0.0f;\r
+    st->z12 = 0.0f;\r
+    st->z22 = 0.0f;\r
+    \r
+    /* State used by function analys */\r
+    for (i = 0; i < 540; i++) {\r
+       st->inbuf[i] = 0.0f;\r
+       st->pebuf[i] = 0.0f;\r
+    }\r
+    for (i = 0; i < 696; i++) {\r
+       st->lpbuf[i] = 0.0f;\r
+    }\r
+    for (i = 0; i < 312; i++) {\r
+       st->ivbuf[i] = 0.0f;\r
+    }\r
+    st->bias = 0.0f;\r
+    /* integer osbuf[10];  /* no initial value necessary */\r
+    st->osptr = 1;\r
+    for (i = 0; i < 3; i++) {\r
+       st->obound[i] = 0;\r
+    }\r
+    st->vwin[4] = 307;\r
+    st->vwin[5] = 462;\r
+    st->awin[4] = 307;\r
+    st->awin[5] = 462;\r
+    for (i = 0; i < 8; i++) {\r
+       st->voibuf[i] = 0;\r
+    }\r
+    for (i = 0; i < 3; i++) {\r
+       st->rmsbuf[i] = 0.0f;\r
+    }\r
+    for (i = 0; i < 30; i++) {\r
+       st->rcbuf[i] = 0.0f;\r
+    }\r
+    st->zpre = 0.0f;\r
+\r
+\r
+    /* State used by function onset */\r
+    st->n = 0.0f;\r
+    st->d__ = 1.0f;\r
+    /* real fpc;   /* no initial value necessary */\r
+    for (i = 0; i < 16; i++) {\r
+       st->l2buf[i] = 0.0f;\r
+    }\r
+    st->l2sum1 = 0.0f;\r
+    st->l2ptr1 = 1;\r
+    st->l2ptr2 = 9;\r
+    /* integer lasti;    /* no initial value necessary */\r
+    st->hyst = FALSE_;\r
+\r
+    /* State used by function voicin */\r
+    st->dither = 20.0f;\r
+    st->maxmin = 0.0f;\r
+    for (i = 0; i < 6; i++) {\r
+       st->voice[i] = 0.0f;\r
+    }\r
+    st->lbve = 3000;\r
+    st->fbve = 3000;\r
+    st->fbue = 187;\r
+    st->ofbue = 187;\r
+    st->sfbue = 187;\r
+    st->lbue = 93;\r
+    st->olbue = 93;\r
+    st->slbue = 93;\r
+    st->snr = (real) (st->fbve / st->fbue << 6);\r
+\r
+    /* State used by function dyptrk */\r
+    for (i = 0; i < 60; i++) {\r
+       st->s[i] = 0.0f;\r
+    }\r
+    for (i = 0; i < 120; i++) {\r
+       st->p[i] = 0;\r
+    }\r
+    st->ipoint = 0;\r
+    st->alphax = 0.0f;\r
+\r
+    /* State used by function chanwr */\r
+    st->isync = 0;\r
+\r
+}\r
+\r
+\r
+\r
+/* Allocate memory for, and initialize, the state that needs to be\r
+   kept from decoding one frame to the next for a single\r
+   LPC-10-compressed audio stream.  Return 0 if malloc fails,\r
+   otherwise return pointer to new structure. */\r
+\r
+struct lpc10_decoder_state *\r
+create_lpc10_decoder_state()\r
+{\r
+    struct lpc10_decoder_state *st;\r
+\r
+    st = (struct lpc10_decoder_state *)\r
+       malloc((unsigned) sizeof (struct lpc10_decoder_state));\r
+    if (st != 0) {\r
+       init_lpc10_decoder_state(st);\r
+    }\r
+    return (st);\r
+}\r
+\r
+\r
+\r
+void init_lpc10_decoder_state(struct lpc10_decoder_state *st)\r
+{\r
+    int i;\r
+\r
+    lpcini_();\r
+\r
+    /* State used by function decode */\r
+    st->iptold = 60;\r
+    st->first = TRUE_;\r
+    st->ivp2h = 0;\r
+    st->iovoic = 0;\r
+    st->iavgp = 60;\r
+    st->erate = 0;\r
+    for (i = 0; i < 30; i++) {\r
+       st->drc[i] = 0;\r
+    }\r
+    for (i = 0; i < 3; i++) {\r
+       st->dpit[i] = 0;\r
+       st->drms[i] = 0;\r
+    }\r
+\r
+    /* State used by function synths */\r
+    for (i = 0; i < 360; i++) {\r
+       st->buf[i] = 0.0f;\r
+    }\r
+    st->buflen = 180;\r
+\r
+    /* State used by function pitsyn */\r
+    /* ivoico;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    /* ipito;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    st->rmso = 1.0f;\r
+    /* rco[10];   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    /* integer jsamp;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */\r
+    st->first_pitsyn = TRUE_;\r
+\r
+    /* State used by function bsynz */\r
+    st->ipo = 0;\r
+    for (i = 0; i < 166; i++) {\r
+       st->exc[i] = 0.0f;\r
+       st->exc2[i] = 0.0f;\r
+    }\r
+    st->lpi1 = 0.0f;\r
+    st->lpi2 = 0.0f;\r
+    st->lpi3 = 0.0f;\r
+    st->hpi1 = 0.0f;\r
+    st->hpi2 = 0.0f;\r
+    st->hpi3 = 0.0f;\r
+    st->rmso_bsynz = 0.0f;\r
+\r
+    /* State used by function random */\r
+    st->j = 2;\r
+    st->k = 5;\r
+    st->y[0] = (shortint) -21161;\r
+    st->y[1] = (shortint) -8478;\r
+    st->y[2] = (shortint) 30892;\r
+    st->y[3] = (shortint) -10216;\r
+    st->y[4] = (shortint) 16950;\r
+\r
+    /* State used by function deemp */\r
+    st->dei1 = 0.0f;\r
+    st->dei2 = 0.0f;\r
+    st->deo1 = 0.0f;\r
+    st->deo2 = 0.0f;\r
+    st->deo3 = 0.0f;\r
+}\r
diff --git a/libs/codec/lpc10/lpfilt.c b/libs/codec/lpc10/lpfilt.c
new file mode 100644 (file)
index 0000000..35ff5a4
--- /dev/null
@@ -0,0 +1,125 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:35  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);\r
+#endif\r
+\r
+/* *********************************************************************** */\r
+\r
+/*     LPFILT Version 55 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:35  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/15  16:53:49  jaf */\r
+/* Just put comment header in standard form. */\r
+\r
+/* Revision 1.2  1996/03/12  23:58:06  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:44  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* *********************************************************************** */\r
+\r
+/*   31 Point Equiripple FIR Low-Pass Filter */\r
+/*     Linear phase, delay = 15 samples */\r
+\r
+/*     Passband:  ripple = 0.25 dB, cutoff =  800 Hz */\r
+/*     Stopband:  atten. =  40. dB, cutoff = 1240 Hz */\r
+\r
+/* Inputs: */\r
+/*  LEN    - Length of speech buffers */\r
+/*  NSAMP  - Number of samples to filter */\r
+/*  INBUF  - Input speech buffer */\r
+/*           Indices len-nsamp-29 through len are read. */\r
+/* Output: */\r
+/*  LPBUF  - Low passed speech buffer (must be different array than INBUF) */\r
+/*           Indices len+1-nsamp through len are written. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *\r
+       nsamp)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    integer j;\r
+    real t;\r
+\r
+/*     Arguments */\r
+/*     Parameters/constants */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       None */\r
+    /* Parameter adjustments */\r
+    --lpbuf;\r
+    --inbuf;\r
+\r
+    /* Function Body */\r
+    i__1 = *len;\r
+    for (j = *len + 1 - *nsamp; j <= i__1; ++j) {\r
+       t = (inbuf[j] + inbuf[j - 30]) * -.0097201988f;\r
+       t += (inbuf[j - 1] + inbuf[j - 29]) * -.0105179986f;\r
+       t += (inbuf[j - 2] + inbuf[j - 28]) * -.0083479648f;\r
+       t += (inbuf[j - 3] + inbuf[j - 27]) * 5.860774e-4f;\r
+       t += (inbuf[j - 4] + inbuf[j - 26]) * .0130892089f;\r
+       t += (inbuf[j - 5] + inbuf[j - 25]) * .0217052232f;\r
+       t += (inbuf[j - 6] + inbuf[j - 24]) * .0184161253f;\r
+       t += (inbuf[j - 7] + inbuf[j - 23]) * 3.39723e-4f;\r
+       t += (inbuf[j - 8] + inbuf[j - 22]) * -.0260797087f;\r
+       t += (inbuf[j - 9] + inbuf[j - 21]) * -.0455563702f;\r
+       t += (inbuf[j - 10] + inbuf[j - 20]) * -.040306855f;\r
+       t += (inbuf[j - 11] + inbuf[j - 19]) * 5.029835e-4f;\r
+       t += (inbuf[j - 12] + inbuf[j - 18]) * .0729262903f;\r
+       t += (inbuf[j - 13] + inbuf[j - 17]) * .1572008878f;\r
+       t += (inbuf[j - 14] + inbuf[j - 16]) * .2247288674f;\r
+       t += inbuf[j - 15] * .250535965f;\r
+       lpbuf[j] = t;\r
+    }\r
+    return 0;\r
+} /* lpfilt_ */\r
+\r
diff --git a/libs/codec/lpc10/median.c b/libs/codec/lpc10/median.c
new file mode 100644 (file)
index 0000000..a40dd1e
--- /dev/null
@@ -0,0 +1,89 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:31  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern integer median_(integer *d1, integer *d2, integer *d3);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     MEDIAN Version 45G */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:31  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.2  1996/03/14  22:30:22  jaf */\r
+/* Just rearranged the comments and local variable declarations a bit. */\r
+\r
+/* Revision 1.1  1996/02/07 14:47:53  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*  Find median of three values */\r
+\r
+/* Input: */\r
+/*  D1,D2,D3 - Three input values */\r
+/* Output: */\r
+/*  MEDIAN - Median value */\r
+\r
+integer median_(integer *d1, integer *d2, integer *d3)\r
+{\r
+    /* System generated locals */\r
+    integer ret_val;\r
+\r
+/*       Arguments */\r
+    ret_val = *d2;\r
+    if (*d2 > *d1 && *d2 > *d3) {\r
+       ret_val = *d1;\r
+       if (*d3 > *d1) {\r
+           ret_val = *d3;\r
+       }\r
+    } else if (*d2 < *d1 && *d2 < *d3) {\r
+       ret_val = *d1;\r
+       if (*d3 < *d1) {\r
+           ret_val = *d3;\r
+       }\r
+    }\r
+    return ret_val;\r
+} /* median_ */\r
+\r
diff --git a/libs/codec/lpc10/mload.c b/libs/codec/lpc10/mload.c
new file mode 100644 (file)
index 0000000..0847374
--- /dev/null
@@ -0,0 +1,163 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:25  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);\r
+#endif\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     MLOAD Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:25  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/27  23:59:51  jaf */\r
+/* Added some more accurate comments about which indices of the argument */\r
+/* array SPEECH are read.  I thought that this might be the cause of a */\r
+/* problem I've been having, but it isn't. */\r
+\r
+/* Revision 1.4  1996/03/26  19:16:53  jaf */\r
+/* Commented out the code at the end that copied the lower triangular */\r
+/* half of PHI into the upper triangular half (making the resulting */\r
+/* matrix symmetric).  The upper triangular half was never used by later */\r
+/* code in subroutine ANALYS. */\r
+\r
+/* Revision 1.3  1996/03/18  21:16:00  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:47:41  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:01  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/* Load a covariance matrix. */\r
+\r
+/* Input: */\r
+/*  ORDER            - Analysis order */\r
+/*  AWINS            - Analysis window start */\r
+/*  AWINF            - Analysis window finish */\r
+/*  SPEECH(AWINF)    - Speech buffer */\r
+/*                     Indices MIN(AWINS, AWINF-(ORDER-1)) through */\r
+/*                             MAX(AWINF, AWINS+(ORDER-1)) read. */\r
+/*                     As long as (AWINF-AWINS) .GE. (ORDER-1), */\r
+/*                     this is just indices AWINS through AWINF. */\r
+/* Output: */\r
+/*  PHI(ORDER,ORDER) - Covariance matrix */\r
+/*                    Lower triangular half and diagonal written, and read.*/\r
+/*                     Upper triangular half untouched. */\r
+/*  PSI(ORDER)       - Prediction vector */\r
+/*                     Indices 1 through ORDER written, */\r
+/*                     and most are read after that. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int mload_(integer *order, integer *awins, integer *awinf, \r
+       real *speech, real *phi, real *psi)\r
+{\r
+    /* System generated locals */\r
+    integer phi_dim1, phi_offset, i__1, i__2;\r
+\r
+    /* Local variables */\r
+    integer c__, i__, r__, start;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*   Load first column of triangular covariance matrix PHI */\r
+    /* Parameter adjustments */\r
+    --psi;\r
+    phi_dim1 = *order;\r
+    phi_offset = phi_dim1 + 1;\r
+    phi -= phi_offset;\r
+    --speech;\r
+\r
+    /* Function Body */\r
+    start = *awins + *order;\r
+    i__1 = *order;\r
+    for (r__ = 1; r__ <= i__1; ++r__) {\r
+       phi[r__ + phi_dim1] = 0.f;\r
+       i__2 = *awinf;\r
+       for (i__ = start; i__ <= i__2; ++i__) {\r
+           phi[r__ + phi_dim1] += speech[i__ - 1] * speech[i__ - r__];\r
+       }\r
+    }\r
+/*   Load last element of vector PSI */\r
+    psi[*order] = 0.f;\r
+    i__1 = *awinf;\r
+    for (i__ = start; i__ <= i__1; ++i__) {\r
+       psi[*order] += speech[i__] * speech[i__ - *order];\r
+    }\r
+/*   End correct to get additional columns of PHI */\r
+    i__1 = *order;\r
+    for (r__ = 2; r__ <= i__1; ++r__) {\r
+       i__2 = r__;\r
+       for (c__ = 2; c__ <= i__2; ++c__) {\r
+           phi[r__ + c__ * phi_dim1] = phi[r__ - 1 + (c__ - 1) * phi_dim1] - \r
+                   speech[*awinf + 1 - r__] * speech[*awinf + 1 - c__] + \r
+                   speech[start - r__] * speech[start - c__];\r
+       }\r
+    }\r
+/*   End correct to get additional elements of PSI */\r
+    i__1 = *order - 1;\r
+    for (c__ = 1; c__ <= i__1; ++c__) {\r
+       psi[c__] = phi[c__ + 1 + phi_dim1] - speech[start - 1] * speech[start \r
+               - 1 - c__] + speech[*awinf] * speech[*awinf - c__];\r
+    }\r
+/*   Copy lower triangular section into upper (why bother?) */\r
+/*       I'm commenting this out, since the upper triangular half of PHI \r
+*/\r
+/*       is never used by later code, unless a sufficiently high level of \r
+*/\r
+/*       tracing is turned on. */\r
+/*     DO R = 1,ORDER */\r
+/*        DO C = 1,R-1 */\r
+/*           PHI(C,R) = PHI(R,C) */\r
+/*        END DO */\r
+/*     END DO */\r
+    return 0;\r
+} /* mload_ */\r
+\r
diff --git a/libs/codec/lpc10/onset.c b/libs/codec/lpc10/onset.c
new file mode 100644 (file)
index 0000000..1d682c1
--- /dev/null
@@ -0,0 +1,324 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:37:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:18  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);\r
+#endif\r
+\r
+/* Table of constant values */\r
+\r
+static real c_b2 = 1.f;\r
+\r
+/* ****************************************************************** */\r
+\r
+/*     ONSET Version 49 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:37:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:18  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/15  16:41:01  jaf */\r
+/* Just rearranged INITONSET assignment orders to be consistent with */\r
+/* order of DATA statements in ONSET. */\r
+\r
+/* Revision 1.4  1996/03/15  15:48:27  jaf */\r
+/* Changed some comments, and only reordered the DATA statements (their */\r
+/* meaning wasn't changed). */\r
+\r
+/* Revision 1.3  1996/03/14  23:53:06  jaf */\r
+/* Added an entry INITONSET that reinitializes the local state variables */\r
+/* of subroutine ONSET. */\r
+\r
+/* Rearranged quite a few comments, adding more explaining which */\r
+/* arguments were inputs, and how the modified ones can be changed. */\r
+\r
+/* Revision 1.2  1996/03/12  23:53:00  jaf */\r
+/* Lots of comments added about the local state of this subroutine that */\r
+/* must be saved from one invocation to the next. */\r
+\r
+/* One constant 180 replaced with LFRAME, which should be "more general", */\r
+/* even though it would probably require many more changes than this to */\r
+/* get this coder to work for other frame sizes. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:09  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ****************************************************************** */\r
+\r
+/*     Floating point version */\r
+\r
+\r
+/*   Detection of onsets in (or slightly preceding) the futuremost frame */\r
+/*   of speech. */\r
+\r
+\r
+/* Input: */\r
+/*  PEBUF(SBUFL:SBUFH)  - Preemphasized speech */\r
+/*                        Indices SBUFH-LFRAME through SBUFH are read. */\r
+/*  OSLEN  - Maximum number of onsets that can be stored in OSBUF. */\r
+/*  SBUFL, SBUFH        - Range of PEBUF */\r
+/*  LFRAME              - length of a frame, in samples */\r
+/* Input/Output: */\r
+/*  OSBUF(OSLEN) - Buffer which holds sorted indexes of onsets */\r
+/*                 Indices A through B are modified, where A */\r
+/*                 is the original value of OSPTR, and B is the final */\r
+/*                 value of OSPTR-1.  B is at most OSLEN. */\r
+/*  OSPTR        - Free pointer into OSBUF */\r
+/*                 Initial value should be .LE. OSLEN+1. */\r
+/*                 If so, final value grows by one for each new onset */\r
+/*                 found, and final value will be .LE. OSLEN+1. */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this subroutine, or */\r
+/* reinitialize its state for any other reason, call the ENTRY INITONSET. */\r
+\r
+/* Subroutine */ int onset_(real *pebuf, integer *osbuf, integer *\r
+       osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *\r
+       lframe, struct lpc10_encoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *n;\r
+    real *d__;\r
+    real *l2buf;\r
+    real *l2sum1;\r
+    integer *l2ptr1;\r
+    integer *l2ptr2;\r
+    logical *hyst;\r
+\r
+    /* System generated locals */\r
+    integer pebuf_offset, i__1;\r
+    real r__1;\r
+\r
+    /* Builtin functions */\r
+    double r_sign(real *, real *);\r
+\r
+    /* Local variables */\r
+    integer i__;\r
+    integer *lasti;\r
+    real l2sum2;\r
+    real *fpc;\r
+\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:37:55  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:18  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Parameters/constants */\r
+/*   Parameters for onset detection algorithm: */\r
+/*    L2               Threshold for filtered slope of FPC (function of L2WID!) */\r
+/*    L2LAG    Lag due to both filters which compute filtered slope of FPC */\r
+/*    L2WID    Width of the filter which computes the slope of FPC */\r
+/*    OSHYST   The number of samples of slope(FPC) which must be below */\r
+/*             the threshold before a new onset may be declared. */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*   Variables */\r
+/*    N, D       Numerator and denominator of prediction filters */\r
+/*    FPC        Current prediction coefs */\r
+/*    L2BUF, L2SUM1, L2SUM2    State of slope filter */\r
+/*       The only "significant" change I've made is to change L2SUM2 out \r
+*/\r
+/*       of the list of local variables that need to be saved, since it */\r
+/*       didn't need to be. */\r
+/*       L2SUM1 need not be, but avoiding saving it would require a small \r
+*/\r
+/*       change to the body of the code.  See comments below for an */\r
+/*       example of how the code could be changed to avoid saving L2SUM1. \r
+*/\r
+/*       FPC and LASTI are saved from one invocation to the next, but */\r
+/*       they are not given initial values.  This is acceptable, because \r
+*/\r
+/*       FPC will be assigned a value the first time that this function */\r
+/*       is called after D is initialized to 1, since the formula to */\r
+/*       change D will not change it to 0 in one step, and the IF (D */\r
+/*       .NE. 0) statement will execute its THEN part, initializing FPC. \r
+*/\r
+\r
+/*       LASTI's value will not be used until HYST is .TRUE., and */\r
+/*       whenever HYST is changed from its initial value of .FALSE., */\r
+/*       LASTI is assigned a value. */\r
+/*       In a C version of this coder, it would be nice if all of these */\r
+/*       saved things, in this and all other subroutines, could be stored \r
+*/\r
+/*       in a single struct lpc10_coder_state_t, initialized with a call \r
+*/\r
+/*       to a function like lpc10_init(&lpc10_coder_state).  In this way, \r
+*/\r
+/*       a program that used these functions could conveniently alternate \r
+*/\r
+/*       coding more than one distinct audio stream. */\r
+\r
+    n = &(st->n);\r
+    d__ = &(st->d__);\r
+    fpc = &(st->fpc);\r
+    l2buf = &(st->l2buf[0]);\r
+    l2sum1 = &(st->l2sum1);\r
+    l2ptr1 = &(st->l2ptr1);\r
+    l2ptr2 = &(st->l2ptr2);\r
+    lasti = &(st->lasti);\r
+    hyst = &(st->hyst);\r
+\r
+    /* Parameter adjustments */\r
+    if (osbuf) {\r
+       --osbuf;\r
+       }\r
+    if (pebuf) {\r
+       pebuf_offset = *sbufl;\r
+       pebuf -= pebuf_offset;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+/*       The following line subtracted a hard-coded "180" from LASTI, */\r
+/*       instead of using a variable like LFRAME or a constant like */\r
+/*       MAXFRM.  I changed it to LFRAME, for "generality". */\r
+    if (*hyst) {\r
+       *lasti -= *lframe;\r
+    }\r
+    i__1 = *sbufh;\r
+    for (i__ = *sbufh - *lframe + 1; i__ <= i__1; ++i__) {\r
+/*   Compute FPC; Use old FPC on divide by zero; Clamp FPC to +/- 1. \r
+*/\r
+       *n = (pebuf[i__] * pebuf[i__ - 1] + (*n) * 63.f) / 64.f;\r
+/* Computing 2nd power */\r
+       r__1 = pebuf[i__ - 1];\r
+       *d__ = (r__1 * r__1 + (*d__) * 63.f) / 64.f;\r
+       if ((*d__) != 0.f) {\r
+           if (abs(*n) > (*d__)) {\r
+               *fpc = r_sign(&c_b2, n);\r
+           } else {\r
+               *fpc = (*n) / (*d__);\r
+           }\r
+       }\r
+/*   Filter FPC */\r
+/*       In order to allow L2SUM1 not to be saved from one invocation \r
+of */\r
+/*       this subroutine to the next, one could change the sequence of\r
+ */\r
+/*       assignments below, up to the IF statement, to the following. \r
+ In */\r
+/*       addition, the initial value of L2PTR2 should be changed to */\r
+/*       L2WID/2 instead of L2WID/2+1. */\r
+\r
+/*       L2SUM1 = L2BUF(L2PTR2) */\r
+/*       L2PTR2 = MOD(L2PTR2,L2WID)+1 */\r
+/*       L2SUM1 = L2SUM1 - L2BUF(L2PTR2) + FPC */\r
+/*       L2BUF(L2PTR2) = L2SUM1 */\r
+\r
+/* *       The following lines didn't change from the original: */\r
+/*       L2SUM2 = L2BUF(L2PTR1) */\r
+/*       L2BUF(L2PTR1) = FPC */\r
+/*       L2PTR1 = MOD(L2PTR1,L2WID)+1 */\r
+\r
+       l2sum2 = l2buf[*l2ptr1 - 1];\r
+       *l2sum1 = *l2sum1 - l2buf[*l2ptr2 - 1] + *fpc;\r
+       l2buf[*l2ptr2 - 1] = *l2sum1;\r
+       l2buf[*l2ptr1 - 1] = *fpc;\r
+       *l2ptr1 = *l2ptr1 % 16 + 1;\r
+       *l2ptr2 = *l2ptr2 % 16 + 1;\r
+       if ((r__1 = *l2sum1 - l2sum2, abs(r__1)) > 1.7f) {\r
+           if (! (*hyst)) {\r
+/*   Ignore if buffer full */\r
+               if (*osptr <= *oslen) {\r
+                   osbuf[*osptr] = i__ - 9;\r
+                   ++(*osptr);\r
+               }\r
+               *hyst = TRUE_;\r
+           }\r
+           *lasti = i__;\r
+/*       After one onset detection, at least OSHYST sample times m\r
+ust go */\r
+/*       by before another is allowed to occur. */\r
+       } else if ((*hyst) && i__ - *lasti >= 10) {\r
+           *hyst = FALSE_;\r
+       }\r
+    }\r
+    return 0;\r
+} /* onset_ */\r
diff --git a/libs/codec/lpc10/pitsyn.c b/libs/codec/lpc10/pitsyn.c
new file mode 100644 (file)
index 0000000..30d6063
--- /dev/null
@@ -0,0 +1,583 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/11/23 22:14:32  markster\r
+Various warning cleanups\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:40:12  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:12  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);\r
+#endif\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     PITSYN Version 53 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/11/23 22:14:32  markster\r
+/* Various warning cleanups\r
+/*\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:40:12  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:12  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.2  1996/03/25  18:49:07  jaf */\r
+/* Added commments about which indices of array arguments are read or */\r
+/* written. */\r
+\r
+/* Rearranged local variable declarations to indicate which need to be */\r
+/* saved from one invocation to the next.  Added entry INITPITSYN to */\r
+/* reinitialize local state variables, if desired. */\r
+\r
+/* Added lots of comments about proving that the maximum number of pitch */\r
+/* periods (NOUT) that can be returned is 16.  The call to STOP that */\r
+/* could happen if NOUT got too large was removed as a result. */\r
+\r
+/* Also proved that the total number of samples returned from N calls, */\r
+/* each with identical values of LFRAME, will always be in the range */\r
+/* N*LFRAME-MAXPIT+1 to N*LFRAME. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:18  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/*   Synthesize a single pitch epoch */\r
+\r
+/* Input: */\r
+/*  ORDER  - Synthesis order (number of RC's) */\r
+/*  VOICE  - Half frame voicing decisions */\r
+/*           Indices 1 through 2 read. */\r
+/*  LFRAME - Length of speech buffer */\r
+/* Input/Output: */\r
+/*  PITCH  - Pitch */\r
+/*           This value should be in the range MINPIT (20) to MAXPIT */\r
+/*           (156), inclusive. */\r
+/*           PITCH can be modified under some conditions. */\r
+/*  RMS    - Energy  (can be modified) */\r
+/*           RMS is changed to 1 if the value passed in is less than 1. */\r
+/*  RC     - Reflection coefficients */\r
+/*           Indices 1 through ORDER can be temporarily overwritten with */\r
+/*           RCO, and then replaced with original values, under some */\r
+/*           conditions. */\r
+/* Output: */\r
+/*  IVUV   - Pitch epoch voicing decisions */\r
+/*           Indices (I) of IVUV, IPITI, and RMSI are written, */\r
+/*           and indices (J,I) of RCI are written, */\r
+/*           where I ranges from 1 to NOUT, and J ranges from 1 to ORDER. */\r
+/*  IPITI  - Pitch epoch length */\r
+/*  RMSI   - Pitch epoch energy */\r
+/*  RCI    - Pitch epoch RC's */\r
+/*  NOUT   - Number of pitch periods in this frame */\r
+/*           This is at least 0, at least 1 if MAXPIT .LT. LFRAME (this */\r
+/*           is currently true on every call), and can never be more than */\r
+/*           (LFRAME+MAXPIT-1)/PITCH, which is currently 16 with */\r
+/*           LFRAME=180, MAXPIT=156, and PITCH .GE. 20, as SYNTHS */\r
+/*           guarantees when it calls this subroutine. */\r
+/*  RATIO  - Previous to present energy ratio */\r
+/*           Always assigned a value. */\r
+\r
+/* Subroutine */ int pitsyn_(integer *order, integer *voice, \r
+       integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, \r
+       integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio,\r
+                              struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *rmso;\r
+    logical *first;\r
+\r
+    /* System generated locals */\r
+    integer rci_dim1 = 0, rci_offset, i__1, i__2;\r
+    real r__1;\r
+\r
+    /* Builtin functions */\r
+    double log(doublereal), exp(doublereal);\r
+\r
+    /* Local variables */\r
+    real alrn, alro, yarc[10], prop;\r
+    integer i__, j, vflag, jused, lsamp;\r
+    integer *jsamp;\r
+    real slope;\r
+    integer *ipito;\r
+    real uvpit;\r
+    integer ip, nl, ivoice;\r
+    integer *ivoico;\r
+    integer istart;\r
+    real *rco;\r
+    real xxy;\r
+\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/11/23 22:14:32  markster\r
+/* Various warning cleanups\r
+/*\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:40:12  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:31:12  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Local variables that need not be saved */\r
+/*       LSAMP is initialized in the IF (FIRST) THEN clause, but it is */\r
+/*       not used the first time through, and it is given a value before \r
+*/\r
+/*       use whenever FIRST is .FALSE., so it appears unnecessary to */\r
+/*       assign it a value when FIRST is .TRUE. */\r
+/*       Local state */\r
+/* FIRST  - .TRUE. only on first call to PITSYN. */\r
+/* IVOICO - Previous VOICE(2) value. */\r
+/* IPITO  - Previous PITCH value. */\r
+/* RMSO   - Previous RMS value. */\r
+/* RCO    - Previous RC values. */\r
+\r
+/* JSAMP  - If this routine is called N times with identical values of */\r
+/*          LFRAME, then the total length of all pitch periods returned */\r
+/*          is always N*LFRAME-JSAMP, and JSAMP is always in the range 0 \r
+*/\r
+/*          to MAXPIT-1 (see below for why this is so).  Thus JSAMP is */\r
+/*          the number of samples "left over" from the previous call to */\r
+/*          PITSYN, that haven't been "used" in a pitch period returned */\r
+/*          from this subroutine.  Every time this subroutine is called, \r
+*/\r
+/*          it returns pitch periods with a total length of at most */\r
+/*          LFRAME+JSAMP. */\r
+\r
+/* IVOICO, IPITO, RCO, and JSAMP need not be assigned an initial value */\r
+/* with a DATA statement, because they are always initialized on the */\r
+/* first call to PITSYN. */\r
+\r
+/* FIRST and RMSO should be initialized with DATA statements, because */\r
+/* even on the first call, they are used before being initialized. */\r
+    /* Parameter adjustments */\r
+    if (rc) {\r
+       --rc;\r
+       }\r
+    if (rci) {\r
+       rci_dim1 = *order;\r
+       rci_offset = rci_dim1 + 1;\r
+       rci -= rci_offset;\r
+       }\r
+    if (voice) {\r
+       --voice;\r
+       }\r
+    if (ivuv) {\r
+       --ivuv;\r
+       }\r
+    if (ipiti) {\r
+       --ipiti;\r
+       }\r
+    if (rmsi) {\r
+       --rmsi;\r
+       }\r
+\r
+    /* Function Body */\r
+    ivoico = &(st->ivoico);\r
+    ipito = &(st->ipito);\r
+    rmso = &(st->rmso);\r
+    rco = &(st->rco[0]);\r
+    jsamp = &(st->jsamp);\r
+    first = &(st->first_pitsyn);\r
+\r
+    if (*rms < 1.f) {\r
+       *rms = 1.f;\r
+    }\r
+    if (*rmso < 1.f) {\r
+       *rmso = 1.f;\r
+    }\r
+    uvpit = 0.f;\r
+    *ratio = *rms / (*rmso + 8.f);\r
+    if (*first) {\r
+       lsamp = 0;\r
+       ivoice = voice[2];\r
+       if (ivoice == 0) {\r
+           *pitch = *lframe / 4;\r
+       }\r
+       *nout = *lframe / *pitch;\r
+       *jsamp = *lframe - *nout * *pitch;\r
+\r
+/*          SYNTHS only calls this subroutine with PITCH in the range \r
+20 */\r
+/*          to 156.  LFRAME = MAXFRM = 180, so NOUT is somewhere in th\r
+e */\r
+/*          range 1 to 9. */\r
+\r
+/*          JSAMP is "LFRAME mod PITCH", so it is in the range 0 to */\r
+/*          (PITCH-1), or 0 to MAXPIT-1=155, after the first call. */\r
+\r
+       i__1 = *nout;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           i__2 = *order;\r
+           for (j = 1; j <= i__2; ++j) {\r
+               rci[j + i__ * rci_dim1] = rc[j];\r
+           }\r
+           ivuv[i__] = ivoice;\r
+           ipiti[i__] = *pitch;\r
+           rmsi[i__] = *rms;\r
+       }\r
+       *first = FALSE_;\r
+    } else {\r
+       vflag = 0;\r
+       lsamp = *lframe + *jsamp;\r
+       slope = (*pitch - *ipito) / (real) lsamp;\r
+       *nout = 0;\r
+       jused = 0;\r
+       istart = 1;\r
+       if (voice[1] == *ivoico && voice[2] == voice[1]) {\r
+           if (voice[2] == 0) {\r
+/* SSUV - -   0  ,  0  ,  0 */\r
+               *pitch = *lframe / 4;\r
+               *ipito = *pitch;\r
+               if (*ratio > 8.f) {\r
+                   *rmso = *rms;\r
+               }\r
+           }\r
+/* SSVC - -   1  ,  1  ,  1 */\r
+           slope = (*pitch - *ipito) / (real) lsamp;\r
+           ivoice = voice[2];\r
+       } else {\r
+           if (*ivoico != 1) {\r
+               if (*ivoico == voice[1]) {\r
+/* UV2VC2 - -  0  ,  0  ,  1 */\r
+                   nl = lsamp - *lframe / 4;\r
+               } else {\r
+/* UV2VC1 - -  0  ,  1  ,  1 */\r
+                   nl = lsamp - *lframe * 3 / 4;\r
+               }\r
+               ipiti[1] = nl / 2;\r
+               ipiti[2] = nl - ipiti[1];\r
+               ivuv[1] = 0;\r
+               ivuv[2] = 0;\r
+               rmsi[1] = *rmso;\r
+               rmsi[2] = *rmso;\r
+               i__1 = *order;\r
+               for (i__ = 1; i__ <= i__1; ++i__) {\r
+                   rci[i__ + rci_dim1] = rco[i__ - 1];\r
+                   rci[i__ + (rci_dim1 << 1)] = rco[i__ - 1];\r
+                   rco[i__ - 1] = rc[i__];\r
+               }\r
+               slope = 0.f;\r
+               *nout = 2;\r
+               *ipito = *pitch;\r
+               jused = nl;\r
+               istart = nl + 1;\r
+               ivoice = 1;\r
+           } else {\r
+               if (*ivoico != voice[1]) {\r
+/* VC2UV1 - -   1  ,  0  ,  0 */\r
+                   lsamp = *lframe / 4 + *jsamp;\r
+               } else {\r
+/* VC2UV2 - -   1  ,  1  ,  0 */\r
+                   lsamp = *lframe * 3 / 4 + *jsamp;\r
+               }\r
+               i__1 = *order;\r
+               for (i__ = 1; i__ <= i__1; ++i__) {\r
+                   yarc[i__ - 1] = rc[i__];\r
+                   rc[i__] = rco[i__ - 1];\r
+               }\r
+               ivoice = 1;\r
+               slope = 0.f;\r
+               vflag = 1;\r
+           }\r
+       }\r
+/* Here is the value of most variables that are used below, depending \r
+on */\r
+/* the values of IVOICO, VOICE(1), and VOICE(2).  VOICE(1) and VOICE(2\r
+) */\r
+/* are input arguments, and IVOICO is the value of VOICE(2) on the */\r
+/* previous call (see notes for the IF (NOUT .NE. 0) statement near th\r
+e */\r
+/* end).  Each of these three values is either 0 or 1.  These three */\r
+/* values below are given as 3-bit long strings, in the order IVOICO, \r
+*/\r
+/* VOICE(1), and VOICE(2).  It appears that the code above assumes tha\r
+t */\r
+/* the bit sequences 010 and 101 never occur, but I wonder whether a \r
+*/\r
+/* large enough number of bit errors in the channel could cause such a\r
+ */\r
+/* thing to happen, and if so, could that cause NOUT to ever go over 1\r
+1? */\r
+\r
+/* Note that all of the 180 values in the table are really LFRAME, but\r
+ */\r
+/* 180 has fewer characters, and it makes the table a little more */\r
+/* concrete.  If LFRAME is ever changed, keep this in mind.  Similarly\r
+, */\r
+/* 135's are 3*LFRAME/4, and 45's are LFRAME/4.  If LFRAME is not a */\r
+/* multiple of 4, then the 135 for NL-JSAMP is actually LFRAME-LFRAME/\r
+4, */\r
+/* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */\r
+\r
+/* Note that LSAMP-JSAMP is given as the variable.  This was just for \r
+*/\r
+/* brevity, to avoid adding "+JSAMP" to all of the column entries. */\r
+/* Similarly for NL-JSAMP. */\r
+\r
+/* Variable    | 000  001    011,010  111       110       100,101 */\r
+/* ------------+-------------------------------------------------- */\r
+/* ISTART      | 1    NL+1   NL+1     1         1         1 */\r
+/* LSAMP-JSAMP | 180  180    180      180       135       45 */\r
+/* IPITO       | 45   PITCH  PITCH    oldPITCH  oldPITCH  oldPITCH */\r
+/* SLOPE       | 0    0      0        seebelow  0         0 */\r
+/* JUSED       | 0    NL     NL       0         0         0 */\r
+/* PITCH       | 45   PITCH  PITCH    PITCH     PITCH     PITCH */\r
+/* NL-JSAMP    | --   135    45       --        --        -- */\r
+/* VFLAG       | 0    0      0        0         1         1 */\r
+/* NOUT        | 0    2      2        0         0         0 */\r
+/* IVOICE      | 0    1      1        1         1         1 */\r
+\r
+/* while_loop  | once once   once     once      twice     twice */\r
+\r
+/* ISTART      | --   --     --       --        JUSED+1   JUSED+1 */\r
+/* LSAMP-JSAMP | --   --     --       --        180       180 */\r
+/* IPITO       | --   --     --       --        oldPITCH  oldPITCH */\r
+/* SLOPE       | --   --     --       --        0         0 */\r
+/* JUSED       | --   --     --       --        ??        ?? */\r
+/* PITCH       | --   --     --       --        PITCH     PITCH */\r
+/* NL-JSAMP    | --   --     --       --        --        -- */\r
+/* VFLAG       | --   --     --       --        0         0 */\r
+/* NOUT        | --   --     --       --        ??        ?? */\r
+/* IVOICE      | --   --     --       --        0         0 */\r
+\r
+\r
+/* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)\r
+ */\r
+/* loop below. */\r
+\r
+/* The only possible non-0 value of SLOPE (in column 111) is */\r
+/* (PITCH-IPITO)/FLOAT(LSAMP) */\r
+\r
+/* Column 101 is identical to 100.  Any good properties we can prove \r
+*/\r
+/* for 100 will also hold for 101.  Similarly for 010 and 011. */\r
+\r
+/* SYNTHS calls this subroutine with PITCH restricted to the range 20 \r
+to */\r
+/* 156.  IPITO is similarly restricted to this range, after the first \r
+*/\r
+/* call.  IP below is also restricted to this range, given the */\r
+/* definitions of IPITO, SLOPE, UVPIT, and that I is in the range ISTA\r
+RT */\r
+/* to LSAMP. */\r
+\r
+       while(TRUE_) {\r
+\r
+/*             JUSED is the total length of all pitch periods curr\r
+ently */\r
+/*             in the output arrays, in samples. */\r
+\r
+/*             An invariant of the DO I = ISTART,LSAMP loop below,\r
+ under */\r
+/*             the condition that IP is always in the range 1 thro\r
+ugh */\r
+/*             MAXPIT, is: */\r
+\r
+/*             (I - MAXPIT) .LE. JUSED .LE. (I-1) */\r
+\r
+/*             Note that the final value of I is LSAMP+1, so that \r
+after */\r
+/*             the DO loop is complete, we know: */\r
+\r
+/*             (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */\r
+\r
+           i__1 = lsamp;\r
+           for (i__ = istart; i__ <= i__1; ++i__) {\r
+               r__1 = *ipito + slope * i__;\r
+               ip = r__1 + .5f;\r
+               if (uvpit != 0.f) {\r
+                   ip = uvpit;\r
+               }\r
+               if (ip <= i__ - jused) {\r
+                   ++(*nout);\r
+\r
+/*                   The following check is no longer nece\r
+ssary, now that */\r
+/*                   we can prove that NOUT will never go \r
+over 16. */\r
+\r
+/*                 IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs' \r
+*/\r
+\r
+                   ipiti[*nout] = ip;\r
+                   *pitch = ip;\r
+                   ivuv[*nout] = ivoice;\r
+                   jused += ip;\r
+                   prop = (jused - ip / 2) / (real) lsamp;\r
+                   i__2 = *order;\r
+                   for (j = 1; j <= i__2; ++j) {\r
+                       alro = log((rco[j - 1] + 1) / (1 - rco[j - 1]));\r
+                       alrn = log((rc[j] + 1) / (1 - rc[j]));\r
+                       xxy = alro + prop * (alrn - alro);\r
+                       xxy = exp(xxy);\r
+                       rci[j + *nout * rci_dim1] = (xxy - 1) / (xxy + 1);\r
+                   }\r
+                   rmsi[*nout] = log(*rmso) + prop * (log(*rms) - log(*rmso));\r
+                   rmsi[*nout] = exp(rmsi[*nout]);\r
+               }\r
+           }\r
+           if (vflag != 1) {\r
+               goto L100;\r
+           }\r
+\r
+/*             I want to prove what range UVPIT must lie in after \r
+the */\r
+/*             assignments to it below.  To do this, I must determ\r
+ine */\r
+/*             what range (LSAMP-ISTART) must lie in, after the */\r
+/*             assignments to ISTART and LSAMP below. */\r
+\r
+/*             Let oldLSAMP be the value of LSAMP at this point in\r
+ the */\r
+/*             execution.  This is 135+JSAMP in state 110, or 45+J\r
+SAMP in */\r
+/*             states 100 or 101. */\r
+\r
+/*             Given the loop invariant on JUSED above, we know th\r
+at: */\r
+\r
+/*             (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */\r
+\r
+/*             ISTART is one more than this. */\r
+\r
+/*             Let newLSAMP be the value assigned to LSAMP below. \r
+ This */\r
+/*             is 180+JSAMP.  Thus (newLSAMP-oldLSAMP) is either 4\r
+5 or */\r
+/*             135, depending on the state. */\r
+\r
+/*             Thus, the range of newLSAMP-ISTART is: */\r
+\r
+/*             (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */\r
+/*             .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */\r
+\r
+/*             or: */\r
+\r
+/*             46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */\r
+\r
+/*             Therefore, UVPIT is in the range 23 to 144 after th\r
+e first */\r
+/*             assignment to UVPIT below, and after the conditiona\r
+l */\r
+/*             assignment, it is in the range 23 to 90. */\r
+\r
+/*             The important thing is that it is in the range 20 t\r
+o 156, */\r
+/*             so that in the loop above, IP is always in this ran\r
+ge. */\r
+\r
+           vflag = 0;\r
+           istart = jused + 1;\r
+           lsamp = *lframe + *jsamp;\r
+           slope = 0.f;\r
+           ivoice = 0;\r
+           uvpit = (real) ((lsamp - istart) / 2);\r
+           if (uvpit > 90.f) {\r
+               uvpit /= 2;\r
+           }\r
+           *rmso = *rms;\r
+           i__1 = *order;\r
+           for (i__ = 1; i__ <= i__1; ++i__) {\r
+               rc[i__] = yarc[i__ - 1];\r
+               rco[i__ - 1] = yarc[i__ - 1];\r
+           }\r
+       }\r
+L100:\r
+       *jsamp = lsamp - jused;\r
+    }\r
+/*       Given that the maximum pitch period MAXPIT .LT. LFRAME (this is \r
+*/\r
+/*       currently true on every call, since SYNTHS always sets */\r
+/*       LFRAME=180), NOUT will always be .GE. 1 at this point. */\r
+    if (*nout != 0) {\r
+       *ivoico = voice[2];\r
+       *ipito = *pitch;\r
+       *rmso = *rms;\r
+       i__1 = *order;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           rco[i__ - 1] = rc[i__];\r
+       }\r
+    }\r
+    return 0;\r
+} /* pitsyn_ */\r
diff --git a/libs/codec/lpc10/placea.c b/libs/codec/lpc10/placea.c
new file mode 100644 (file)
index 0000000..c0c7fa0
--- /dev/null
@@ -0,0 +1,242 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.2  2003/09/19 01:20:22  markster\r
+Code cleanups (bug #66)\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.3  2001/04/12 21:27:53  markh\r
+app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:07  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);\r
+#endif\r
+\r
+/* *********************************************************************** */\r
+\r
+/*     PLACEA Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.2  2003/09/19 01:20:22  markster\r
+/* Code cleanups (bug #66)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.3  2001/04/12 21:27:53  markh\r
+/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:07  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/19  20:41:55  jaf */\r
+/* Added some conditions satisfied by the output values in EWIN. */\r
+\r
+/* Revision 1.4  1996/03/19  20:24:17  jaf */\r
+/* Added some conditions satisfied by the output values in AWIN. */\r
+\r
+/* Revision 1.3  1996/03/18  21:40:04  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:43:09  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:31  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* *********************************************************************** */\r
+/* Input: */\r
+/*  IPITCH */\r
+/*  VOIBUF */\r
+/*          Indices (2,AF-2), (1,AF-1), (2,AF-1), (1,AF), and (2,AF) read.*/\r
+/*           All other indices untouched. */\r
+/*  OBOUND */\r
+/*  AF */\r
+/*  VWIN */\r
+/*           Indices (1,AF) and (2,AF) read. */\r
+/*           All other indices untouched. */\r
+/*  LFRAME */\r
+/*  MAXWIN */\r
+/* Input/Output: */\r
+/*  AWIN */\r
+/*           Index (1,AF-1) read. */\r
+/*           Indices (1,AF) and (2,AF) written, and then read. */\r
+/*           All other indices untouched. */\r
+/*           In all cases (except possibly one), the final values will */\r
+/*           satisfy the condition: AWIN(2,AF)-AWIN(1,AF)+1 = MAXWIN. */\r
+/*           In that other case, */\r
+/*           AWIN(1,AF)=VWIN(1,AF) and AWIN(2,AF)=VWIN(2,AF). */\r
+/* Output: */\r
+/*  EWIN */\r
+/*           Indices (1,AF) and (2,AF) written. */\r
+/*           All other indices untouched. */\r
+/*           In all cases, the final values will satisfy the condition: */\r
+/*           AWIN(1,AF) .LE. EWIN(1,AF) .LE. EWIN(2,AF) .LE. AWIN(2,AF) */\r
+/*           In other words, the energy window is a sub-window of */\r
+/*           the analysis window. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int placea_(integer *ipitch, integer *voibuf, integer *\r
+       obound, integer *af, integer *vwin, integer *awin, integer *ewin, \r
+       integer *lframe, integer *maxwin)\r
+{\r
+    /* System generated locals */\r
+    real r__1;\r
+\r
+    /* Builtin functions */\r
+    integer i_nint(real *);\r
+\r
+    /* Local variables */\r
+    logical allv, winv;\r
+    integer i__, j, k, l, hrange;\r
+    logical ephase;\r
+    integer lrange;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    ewin -= 3;\r
+    awin -= 3;\r
+    vwin -= 3;\r
+    --voibuf;\r
+\r
+    /* Function Body */\r
+    lrange = (*af - 2) * *lframe + 1;\r
+    hrange = *af * *lframe;\r
+/*   Place the Analysis window based on the voicing window */\r
+/*   placement, onsets, tentative voicing decision, and pitch. */\r
+\r
+/*   Case 1:  Sustained Voiced Speech */\r
+/*   If the five most recent voicing decisions are */\r
+/*   voiced, then the window is placed phase-synchronously with the */\r
+/*   previous window, as close to the present voicing window if possible. \r
+*/\r
+/*   If onsets bound the voicing window, then preference is given to */\r
+/*   a phase-synchronous placement which does not overlap these onsets. */\r
+\r
+/*   Case 2:  Voiced Transition */\r
+/*   If at least one voicing decision in AF is voicied, and there are no \r
+*/\r
+/*   onsets, then the window is placed as in case 1. */\r
+\r
+/*   Case 3:  Unvoiced Speech or Onsets */\r
+/*   If both voicing decisions in AF are unvoiced, or there are onsets, */\r
+/*   then the window is placed coincident with the voicing window. */\r
+\r
+/*   Note:  During phase-synchronous placement of windows, the length */\r
+/*   is not altered from MAXWIN, since this would defeat the purpose */\r
+/*   of phase-synchronous placement. */\r
+/* Check for case 1 and case 2 */\r
+    allv = voibuf[((*af - 2) << 1) + 2] == 1;\r
+    allv = allv && voibuf[((*af - 1) << 1) + 1] == 1;\r
+    allv = allv && voibuf[((*af - 1) << 1) + 2] == 1;\r
+    allv = allv && voibuf[(*af << 1) + 1] == 1;\r
+    allv = allv && voibuf[(*af << 1) + 2] == 1;\r
+    winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;\r
+    if (allv || (winv && *obound == 0)) {\r
+/* APHASE:  Phase synchronous window placement. */\r
+/* Get minimum lower index of the window. */\r
+       i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;\r
+       i__ *= *ipitch;\r
+       i__ += awin[((*af - 1) << 1) + 1];\r
+/* L = the actual length of this frame's analysis window. */\r
+       l = *maxwin;\r
+/* Calculate the location where a perfectly centered window would star\r
+t. */\r
+       k = (vwin[(*af << 1) + 1] + vwin[(*af << 1) + 2] + 1 - l) / 2;\r
+/* Choose the actual location to be the pitch multiple closest to this\r
+. */\r
+       r__1 = (real) (k - i__) / *ipitch;\r
+       awin[(*af << 1) + 1] = i__ + i_nint(&r__1) * *ipitch;\r
+       awin[(*af << 1) + 2] = awin[(*af << 1) + 1] + l - 1;\r
+/* If there is an onset bounding the right of the voicing window and t\r
+he */\r
+/* analysis window overlaps that, then move the analysis window backwa\r
+rd */\r
+/* to avoid this onset. */\r
+       if (*obound >= 2 && awin[(*af << 1) + 2] > vwin[(*af << 1) + 2]) {\r
+           awin[(*af << 1) + 1] -= *ipitch;\r
+           awin[(*af << 1) + 2] -= *ipitch;\r
+       }\r
+/* Similarly for the left of the voicing window. */\r
+       if ((*obound == 1 || *obound == 3) && awin[(*af << 1) + 1] < vwin[(*\r
+               af << 1) + 1]) {\r
+           awin[(*af << 1) + 1] += *ipitch;\r
+           awin[(*af << 1) + 2] += *ipitch;\r
+       }\r
+/* If this placement puts the analysis window above HRANGE, then */\r
+/* move it backward an integer number of pitch periods. */\r
+       while(awin[(*af << 1) + 2] > hrange) {\r
+           awin[(*af << 1) + 1] -= *ipitch;\r
+           awin[(*af << 1) + 2] -= *ipitch;\r
+       }\r
+/* Similarly if the placement puts the analysis window below LRANGE. \r
+*/\r
+       while(awin[(*af << 1) + 1] < lrange) {\r
+           awin[(*af << 1) + 1] += *ipitch;\r
+           awin[(*af << 1) + 2] += *ipitch;\r
+       }\r
+/* Make Energy window be phase-synchronous. */\r
+       ephase = TRUE_;\r
+/* Case 3 */\r
+    } else {\r
+       awin[(*af << 1) + 1] = vwin[(*af << 1) + 1];\r
+       awin[(*af << 1) + 2] = vwin[(*af << 1) + 2];\r
+       ephase = FALSE_;\r
+    }\r
+/* RMS is computed over an integer number of pitch periods in the analysis\r
+ */\r
+/*window.  When it is not placed phase-synchronously, it is placed as clos\r
+e*/\r
+/* as possible to onsets. */\r
+    j = (awin[(*af << 1) + 2] - awin[(*af << 1) + 1] + 1) / *ipitch * *ipitch;\r
+    if (j == 0 || ! winv) {\r
+       ewin[(*af << 1) + 1] = vwin[(*af << 1) + 1];\r
+       ewin[(*af << 1) + 2] = vwin[(*af << 1) + 2];\r
+    } else if (! ephase && *obound == 2) {\r
+       ewin[(*af << 1) + 1] = awin[(*af << 1) + 2] - j + 1;\r
+       ewin[(*af << 1) + 2] = awin[(*af << 1) + 2];\r
+    } else {\r
+       ewin[(*af << 1) + 1] = awin[(*af << 1) + 1];\r
+       ewin[(*af << 1) + 2] = awin[(*af << 1) + 1] + j - 1;\r
+    }\r
+    return 0;\r
+} /* placea_ */\r
+\r
diff --git a/libs/codec/lpc10/placev.c b/libs/codec/lpc10/placev.c
new file mode 100644 (file)
index 0000000..11fadb4
--- /dev/null
@@ -0,0 +1,275 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.3  2001/04/12 21:27:53  markh\r
+app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:31:02  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);\r
+#endif\r
+\r
+/* ****************************************************************** */\r
+\r
+/*     PLACEV Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.3  2001/04/12 21:27:53  markh\r
+/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:31:02  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.6  1996/03/19  20:42:19  jaf */\r
+/* Added some conditions satisfied by the output values in VWIN. */\r
+\r
+/* Revision 1.5  1996/03/19  18:37:56  jaf */\r
+/* Strengthened the specification of which indices of VWIN are read and */\r
+/* written. */\r
+\r
+/* Revision 1.4  1996/03/15  16:38:33  jaf */\r
+/* One tiny comment added. */\r
+\r
+/* Revision 1.3  1996/03/15  16:36:13  jaf */\r
+/* Added comments giving In/Out status of arguments. */\r
+\r
+/* Revision 1.2  1996/03/12  23:56:01  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:39  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ****************************************************************** */\r
+\r
+/* Input: */\r
+/*  OSBUF      Buffer which holds sorted indexes of onsets */\r
+/*             I believe that only indices 1 through OSPTR-1 can be read. */\r
+/*  OSLEN */\r
+/*  OSPTR      Free pointer into OSBUF */\r
+/*  AF */\r
+/*  LFRAME */\r
+/*  MINWIN */\r
+/*  MAXWIN */\r
+/*  DVWINL */\r
+/*  DVWINH     (This argument is never used.  Should it be?) */\r
+/* Input/Output: */\r
+/*  VWIN               Buffer of Voicing Window Positions (Modified) */\r
+/*             Index (2,AF-1) is read. */\r
+/*             Indices (1,AF) and (2,AF) are written, */\r
+/*             and then possibly read. */\r
+/*             All other indices are unused. */\r
+/*              In all cases, the final values will satsify the condition:*/\r
+/*               VWIN(2,AF)-VWIN(1,AF)+1 .LE. MAXWIN */\r
+/*               I'm not certain yet, but they may also satisfy: */\r
+/*               MINWIN .LE. VWIN(2,AF)-VWIN(1,AF)+1 */\r
+/* Output: */\r
+/*  OBOUND     This variable is set by this procedure and used */\r
+/*             in placing analysis windows (PLACEA).  Bit 1 */\r
+/*             indicates whether an onset bounds the left side */\r
+/*             of the voicing window, and bit 2 indicates whether */\r
+/*             an onset bounds the right side of the voicing window. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int placev_(integer *osbuf, integer *osptr, integer *oslen, \r
+       integer *obound, integer *vwin, integer *af, integer *lframe, integer \r
+       *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh)\r
+{\r
+    /* System generated locals */\r
+    integer i__1, i__2;\r
+\r
+    /* Local variables */\r
+    logical crit;\r
+    integer i__, q, osptr1, hrange, lrange;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*   Variables */\r
+/*    LRANGE, HRANGE  Range in which window is placed */\r
+/*    OSPTR1     OSPTR excluding samples in 3F */\r
+/*       Local state */\r
+/*       None */\r
+/*   Voicing Window Placement */\r
+\r
+/*         __________________ __________________ ______________ */\r
+/*        |                  |                  | */\r
+/*        |        1F        |        2F        |        3F ... */\r
+/*        |__________________|__________________|______________ */\r
+\r
+/*    Previous | */\r
+/*      Window | */\r
+/*  ...________| */\r
+\r
+/*             |                                | */\r
+/*      ------>| This window's placement range  |<------ */\r
+/*             |                                | */\r
+\r
+/*   There are three cases.  Note that these are different from those */\r
+/*   given in the LPC-10e phase 1 report. */\r
+\r
+/*   1.  If there are no onsets in this range, then the voicing window */\r
+/*   is centered in the pitch window.  If such a placement is not within \r
+*/\r
+/*   the window's placement range, then the window is placed in the left- \r
+*/\r
+/*   most portion of the placement range.  Its length is always MAXWIN. */\r
+\r
+/*   2.  If the first onset is in 2F and there is sufficient room to place\r
+ */\r
+/*   the window immediately before this onset, then the window is placed \r
+*/\r
+/*   there, and its length is set to the maximum possible under these */\r
+/*   constraints. */\r
+\r
+/*     "Critical Region Exception":  If there is another onset in 2F */\r
+/*     such that a window can be placed between the two onsets, the */\r
+/*     window is placed there (ie, as in case 3). */\r
+\r
+/*   3.  Otherwise, the window is placed immediately after the onset.  The\r
+ */\r
+/*   window's length */\r
+/*  is the longest length that can fit in the range under these constraint\r
+s,*/\r
+/*  except that the window may be shortened even further to avoid overlapp\r
+ing*/\r
+/*  other onsets in the placement range.  In any case, the window's length\r
+*/\r
+/*   is at least MINWIN. */\r
+\r
+/*   Note that the values of MINWIN and LFRAME must be chosen such */\r
+/*   that case 2 = false implies case 3 = true.   This means that */\r
+/*   MINWIN <= LFRAME/2.  If this were not the case, then a fourth case */\r
+/*   would have to be added for when the window cannot fit either before \r
+*/\r
+/*   or after the onset. */\r
+\r
+/*   Note also that onsets which weren't in 2F last time may be in 1F this\r
+ */\r
+/*  time, due to the filter delays in computing onsets.  The result is tha\r
+t*/\r
+/*   occasionally a voicing window will overlap that onset.  The only way \r
+*/\r
+/*   to circumvent this problem is to add more delay in processing input \r
+*/\r
+/*   speech.  In the trade-off between delay and window-placement, window \r
+*/\r
+/*   placement lost. */\r
+/* Compute the placement range */\r
+    /* Parameter adjustments */\r
+    --osbuf;\r
+    vwin -= 3;\r
+\r
+    /* Function Body */\r
+/* Computing MAX */\r
+    i__1 = vwin[((*af - 1) << 1) + 2] + 1, i__2 = (*af - 2) * *lframe + 1;\r
+    lrange = max(i__1,i__2);\r
+    hrange = *af * *lframe;\r
+/* Compute OSPTR1, so the following code only looks at relevant onsets. */\r
+    for (osptr1 = *osptr - 1; osptr1 >= 1; --osptr1) {\r
+       if (osbuf[osptr1] <= hrange) {\r
+           goto L90;\r
+       }\r
+    }\r
+L90:\r
+    ++osptr1;\r
+/* Check for case 1 first (fast case): */\r
+    if (osptr1 <= 1 || osbuf[osptr1 - 1] < lrange) {\r
+/* Computing MAX */\r
+       i__1 = vwin[((*af - 1) << 1) + 2] + 1;\r
+       vwin[(*af << 1) + 1] = max(i__1,*dvwinl);\r
+       vwin[(*af << 1) + 2] = vwin[(*af << 1) + 1] + *maxwin - 1;\r
+       *obound = 0;\r
+    } else {\r
+/* Search backward in OSBUF for first onset in range. */\r
+/* This code relies on the above check being performed first. */\r
+       for (q = osptr1 - 1; q >= 1; --q) {\r
+           if (osbuf[q] < lrange) {\r
+               goto L100;\r
+           }\r
+       }\r
+L100:\r
+       ++q;\r
+/* Check for case 2 (placement before onset): */\r
+/* Check for critical region exception: */\r
+       i__1 = osptr1 - 1;\r
+       for (i__ = q + 1; i__ <= i__1; ++i__) {\r
+           if (osbuf[i__] - osbuf[q] >= *minwin) {\r
+               crit = TRUE_;\r
+               goto L105;\r
+           }\r
+       }\r
+       crit = FALSE_;\r
+L105:\r
+/* Computing MAX */\r
+       i__1 = (*af - 1) * *lframe, i__2 = lrange + *minwin - 1;\r
+       if (! crit && osbuf[q] > max(i__1,i__2)) {\r
+           vwin[(*af << 1) + 2] = osbuf[q] - 1;\r
+/* Computing MAX */\r
+           i__1 = lrange, i__2 = vwin[(*af << 1) + 2] - *maxwin + 1;\r
+           vwin[(*af << 1) + 1] = max(i__1,i__2);\r
+           *obound = 2;\r
+/* Case 3 (placement after onset) */\r
+       } else {\r
+           vwin[(*af << 1) + 1] = osbuf[q];\r
+L110:\r
+           ++q;\r
+           if (q >= osptr1) {\r
+               goto L120;\r
+           }\r
+           if (osbuf[q] > vwin[(*af << 1) + 1] + *maxwin) {\r
+               goto L120;\r
+           }\r
+           if (osbuf[q] < vwin[(*af << 1) + 1] + *minwin) {\r
+               goto L110;\r
+           }\r
+           vwin[(*af << 1) + 2] = osbuf[q] - 1;\r
+           *obound = 3;\r
+           return 0;\r
+L120:\r
+/* Computing MIN */\r
+           i__1 = vwin[(*af << 1) + 1] + *maxwin - 1;\r
+           vwin[(*af << 1) + 2] = min(i__1,hrange);\r
+           *obound = 1;\r
+       }\r
+    }\r
+    return 0;\r
+} /* placev_ */\r
+\r
diff --git a/libs/codec/lpc10/preemp.c b/libs/codec/lpc10/preemp.c
new file mode 100644 (file)
index 0000000..a1dfb30
--- /dev/null
@@ -0,0 +1,144 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:30:58  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);\r
+#endif\r
+\r
+/* ******************************************************************* */\r
+\r
+/*     PREEMP Version 55 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:30:58  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/14  23:16:29  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/11  23:23:34  jaf */\r
+/* Added a bunch of comments to an otherwise simple subroutine. */\r
+\r
+/* Revision 1.1  1996/02/07 14:48:48  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ******************************************************************* */\r
+\r
+/*   Preemphasize speech with a single-zero filter. */\r
+/*  (When coef = .9375, preemphasis is as in LPC43.) */\r
+\r
+/* Inputs: */\r
+/*  NSAMP  - Number of samples to filter */\r
+/*  INBUF  - Input speech buffer */\r
+/*           Indices 1 through NSAMP are read. */\r
+/*  COEF   - Preemphasis coefficient */\r
+/* Input/Output: */\r
+/*  Z      - Filter state */\r
+/* Output: */\r
+/*  PEBUF  - Preemphasized speech buffer (can be equal to INBUF) */\r
+/*           Indices 1 through NSAMP are modified. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *\r
+       coef, real *z__)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+\r
+    /* Local variables */\r
+    real temp;\r
+    integer i__;\r
+\r
+/*       Arguments */\r
+/*       Local variables */\r
+\r
+/*       None of these need to have their values saved from one */\r
+/*       invocation to the next. */\r
+\r
+/*       Logically, this subroutine computes the output sequence */\r
+/*       pebuf(1:nsamp) defined by: */\r
+\r
+/*       pebuf(i) = inbuf(i) - coef * inbuf(i-1) */\r
+\r
+/*       where inbuf(0) is defined by the value of z given as input to */\r
+/*       this subroutine. */\r
+\r
+/*       What is this filter's frequency response and phase response? */\r
+\r
+/*       Why is this filter applied to the speech? */\r
+\r
+/*       Could it be more efficient to apply multiple filters */\r
+/*       simultaneously, by combining them into one equivalent filter? */\r
+\r
+/*       Are there ever cases when "factoring" one high-order filter into \r
+*/\r
+/*       multiple smaller-order filter actually reduces the number of */\r
+/*       arithmetic operations needed to perform them? */\r
+/*       When I first read this subroutine, I didn't understand why the */\r
+/*       variable temp was used.  It seemed that the statements in the do \r
+*/\r
+/*       loop could be replaced with the following: */\r
+\r
+/*           pebuf(i) = inbuf(i) - coef * z */\r
+/*           z = inbuf(i) */\r
+\r
+/*       The reason for temp is so that even if pebuf and inbuf are the */\r
+/*       same arrays in memory (i.e., they are aliased), then this */\r
+/*       subroutine will still work correctly.  I didn't realize this */\r
+/*       until seeing the comment after PEBUF above that says "(can be */\r
+/*       equal to INBUF)". */\r
+    /* Parameter adjustments */\r
+    --pebuf;\r
+    --inbuf;\r
+\r
+    /* Function Body */\r
+    i__1 = *nsamp;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       temp = inbuf[i__] - *coef * *z__;\r
+       *z__ = inbuf[i__];\r
+       pebuf[i__] = temp;\r
+/* L10: */\r
+    }\r
+    return 0;\r
+} /* preemp_ */\r
+\r
diff --git a/libs/codec/lpc10/prepro.c b/libs/codec/lpc10/prepro.c
new file mode 100644 (file)
index 0000000..d535a0b
--- /dev/null
@@ -0,0 +1,116 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:40:51  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:54  jaf\r
+ * Initial revision\r
+ *\r
+ */\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int prepro_(real *speech, integer *length,\r
+                  struct lpc10_encoder_state *st);\r
+/*:ref: hp100_ 14 3 6 4 4 */\r
+/*:ref: inithp100_ 14 0 */\r
+#endif\r
+\r
+/* Table of constant values */\r
+\r
+static integer c__1 = 1;\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     PREPRO Version 48 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:40:51  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:54  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/14  23:22:56  jaf */\r
+/* Added comments about when INITPREPRO should be used. */\r
+\r
+/* Revision 1.2  1996/03/14  23:09:27  jaf */\r
+/* Added an entry named INITPREPRO that initializes the local state of */\r
+/* this subroutine, and those it calls (if any). */\r
+\r
+/* Revision 1.1  1996/02/07  14:48:54  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*    Pre-process input speech: */\r
+\r
+/* Inputs: */\r
+/*  LENGTH - Number of SPEECH samples */\r
+/* Input/Output: */\r
+/*  SPEECH(LENGTH) - Speech data. */\r
+/*                   Indices 1 through LENGTH are read and modified. */\r
+\r
+/* This subroutine has no local state maintained from one call to the */\r
+/* next, but HP100 does.  If you want to switch to using a new audio */\r
+/* stream for this filter, or reinitialize its state for any other */\r
+/* reason, call the ENTRY INITPREPRO. */\r
+\r
+/* Subroutine */ int prepro_(real *speech, integer *length,\r
+                            struct lpc10_encoder_state *st)\r
+{\r
+    extern /* Subroutine */ int hp100_(real *, integer *, integer *, struct lpc10_encoder_state *);\r
+\r
+/*       Arguments */\r
+/*   High Pass Filter at 100 Hz */\r
+    /* Parameter adjustments */\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+\r
+    /* Function Body */\r
+    hp100_(&speech[1], &c__1, length, st);\r
+    return 0;\r
+} /* prepro_ */\r
diff --git a/libs/codec/lpc10/random.c b/libs/codec/lpc10/random.c
new file mode 100644 (file)
index 0000000..4b8b3fc
--- /dev/null
@@ -0,0 +1,125 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:41:32  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:49  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern integer random_(struct lpc10_decoder_state *st);\r
+#endif\r
+\r
+/* ********************************************************************** */\r
+\r
+/*     RANDOM Version 49 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:41:32  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:49  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/20  16:13:54  jaf */\r
+/* Rearranged comments a little bit, and added comments explaining that */\r
+/* even though there is local state here, there is no need to create an */\r
+/* ENTRY for reinitializing it. */\r
+\r
+/* Revision 1.2  1996/03/14  22:25:29  jaf */\r
+/* Just rearranged the comments and local variable declarations a bit. */\r
+\r
+/* Revision 1.1  1996/02/07 14:49:01  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*  Pseudo random number generator based on Knuth, Vol 2, p. 27. */\r
+\r
+/* Function Return: */\r
+/*  RANDOM - Integer variable, uniformly distributed over -32768 to 32767 */\r
+\r
+/* This subroutine maintains local state from one call to the next. */\r
+/* In the context of the LPC10 coder, there is no reason to reinitialize */\r
+/* this local state when switching between audio streams, because its */\r
+/* results are only used to generate noise for unvoiced frames. */\r
+\r
+integer random_(struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    integer *j;\r
+    integer *k;\r
+    shortint *y;\r
+\r
+    /* System generated locals */\r
+    integer ret_val;\r
+\r
+/*     Parameters/constants */\r
+/*       Local state */\r
+/*   The following is a 16 bit 2's complement addition, */\r
+/*   with overflow checking disabled */\r
+\r
+    j = &(st->j);\r
+    k = &(st->k);\r
+    y = &(st->y[0]);\r
+\r
+    y[*k - 1] += y[*j - 1];\r
+    ret_val = y[*k - 1];\r
+    --(*k);\r
+    if (*k <= 0) {\r
+       *k = 5;\r
+    }\r
+    --(*j);\r
+    if (*j <= 0) {\r
+       *j = 5;\r
+    }\r
+    return ret_val;\r
+} /* random_ */\r
+\r
diff --git a/libs/codec/lpc10/rcchk.c b/libs/codec/lpc10/rcchk.c
new file mode 100644 (file)
index 0000000..00ae8e4
--- /dev/null
@@ -0,0 +1,119 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:30:41  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int rcchk_(integer *order, real *rc1f, real *rc2f);\r
+#endif\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     RCCHK Version 45G */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:30:41  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.4  1996/03/27  18:13:47  jaf */\r
+/* Commented out a call to subroutine ERROR. */\r
+\r
+/* Revision 1.3  1996/03/18  15:48:53  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  16:55:22  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:49:08  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*  Check RC's, repeat previous frame's RC's if unstable */\r
+\r
+/* Input: */\r
+/*  ORDER - Number of RC's */\r
+/*  RC1F  - Previous frame's RC's */\r
+/*          Indices 1 through ORDER may be read. */\r
+/* Input/Output: */\r
+/*  RC2F  - Present frame's RC's */\r
+/*          Indices 1 through ORDER may be read, and written. */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int rcchk_(integer *order, real *rc1f, real *rc2f)\r
+{\r
+    /* System generated locals */\r
+    integer i__1;\r
+    real r__1;\r
+\r
+    /* Local variables */\r
+    integer i__;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+    /* Parameter adjustments */\r
+    --rc2f;\r
+    --rc1f;\r
+\r
+    /* Function Body */\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       if ((r__1 = rc2f[i__], abs(r__1)) > .99f) {\r
+           goto L10;\r
+       }\r
+    }\r
+    return 0;\r
+/*       Note: In version embedded in other software, all calls to ERROR \r
+*/\r
+/*       should probably be removed. */\r
+L10:\r
+\r
+/*       This call to ERROR is only needed for debugging purposes. */\r
+\r
+/*       CALL ERROR('RCCHK',2,I) */\r
+    i__1 = *order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+       rc2f[i__] = rc1f[i__];\r
+    }\r
+    return 0;\r
+} /* rcchk_ */\r
+\r
diff --git a/libs/codec/lpc10/synths.c b/libs/codec/lpc10/synths.c
new file mode 100644 (file)
index 0000000..722ceb5
--- /dev/null
@@ -0,0 +1,425 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/09/27 02:45:37  markster\r
+Fix various compiler warnings (bug #322)\r
+\r
+Revision 1.2  2003/09/27 02:45:37  markster\r
+Fix various compiler warnings (bug #322)\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:39  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:42:59  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:33  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: pitsyn_ 14 12 4 4 4 6 6 4 4 4 6 6 4 6 */\r
+/*:ref: irc2pc_ 14 5 6 6 4 6 6 */\r
+/*:ref: bsynz_ 14 7 6 4 4 6 6 6 6 */\r
+/*:ref: deemp_ 14 2 6 4 */\r
+/*:ref: initpitsyn_ 14 0 */\r
+/*:ref: initbsynz_ 14 0 */\r
+/*:ref: initdeemp_ 14 0 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/* Table of constant values */\r
+\r
+static real c_b2 = .7f;\r
+\r
+/* ***************************************************************** */\r
+\r
+/*     SYNTHS Version 54 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.2  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:42:59  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:33  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.5  1996/03/26  19:31:58  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.4  1996/03/25  19:41:01  jaf */\r
+/* Changed so that MAXFRM samples are always returned in the output array */\r
+/* SPEECH. */\r
+\r
+/* This required delaying the returned samples by MAXFRM sample times, */\r
+/* and remembering any "left over" samples returned by PITSYN from one */\r
+/* call of SYNTHS to the next. */\r
+\r
+/* Changed size of SPEECH from 2*MAXFRM to MAXFRM.  Removed local */\r
+/* variable SOUT.  Added local state variables BUF and BUFLEN. */\r
+\r
+/* Revision 1.3  1996/03/25  19:20:10  jaf */\r
+/* Added comments about the range of possible return values for argument */\r
+/* K, and increased the size of the arrays filled in by PITSYN from 11 to */\r
+/* 16, as has been already done inside of PITSYN. */\r
+\r
+/* Revision 1.2  1996/03/22  00:18:18  jaf */\r
+/* Added comments explaining meanings of input and output parameters, and */\r
+/* indicating which array indices can be read or written. */\r
+\r
+/* Added entry INITSYNTHS, which does nothing except call the */\r
+/* corresponding initialization entries for subroutines PITSYN, BSYNZ, */\r
+/* and DEEMP. */\r
+\r
+/* Revision 1.1  1996/02/07 14:49:44  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ***************************************************************** */\r
+\r
+/* The note below is from the distributed version of the LPC10 coder. */\r
+/* The version of the code below has been modified so that SYNTHS always */\r
+/* has a constant frame length output of MAXFRM. */\r
+\r
+/* Also, BSYNZ and DEEMP need not be modified to work on variable */\r
+/* positions within an array.  It is only necessary to pass the first */\r
+/* index desired as the array argument.  What actually gets passed is the */\r
+/* address of that array position, which the subroutine treats as the */\r
+/* first index of the array. */\r
+\r
+/* This technique is used in subroutine ANALYS when calling PREEMP, so it */\r
+/* appears that multiple people wrote different parts of this LPC10 code, */\r
+/* and that they didn't necessarily have equivalent knowledge of Fortran */\r
+/* (not surprising). */\r
+\r
+/*  NOTE: There is excessive buffering here, BSYNZ and DEEMP should be */\r
+/*        changed to operate on variable positions within SOUT.  Also, */\r
+/*        the output length parameter is bogus, and PITSYN should be */\r
+/*        rewritten to allow a constant frame length output. */\r
+\r
+/* Input: */\r
+/*  VOICE  - Half frame voicing decisions */\r
+/*           Indices 1 through 2 read. */\r
+/* Input/Output: */\r
+/*  PITCH  - Pitch */\r
+/*           PITCH is restricted to range 20 to 156, inclusive, */\r
+/*           before calling subroutine PITSYN, and then PITSYN */\r
+/*           can modify it further under some conditions. */\r
+/*  RMS    - Energy */\r
+/*           Only use is for debugging, and passed to PITSYN. */\r
+/*           See comments there for how it can be modified. */\r
+/*  RC     - Reflection coefficients */\r
+/*           Indices 1 through ORDER restricted to range -.99 to .99, */\r
+/*           before calling subroutine PITSYN, and then PITSYN */\r
+/*           can modify it further under some conditions. */\r
+/* Output: */\r
+/*  SPEECH - Synthesized speech samples. */\r
+/*           Indices 1 through the final value of K are written. */\r
+/*  K      - Number of samples placed into array SPEECH. */\r
+/*           This is always MAXFRM. */\r
+\r
+/* Subroutine */ int synths_(integer *voice, integer *pitch, real *\r
+       rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *buf;\r
+    integer *buflen;\r
+\r
+    /* System generated locals */\r
+    integer i__1;\r
+    real r__1, r__2;\r
+\r
+    /* Local variables */\r
+    real rmsi[16];\r
+    integer nout, ivuv[16], i__, j;\r
+    extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);\r
+    real ratio;\r
+    integer ipiti[16];\r
+    real g2pass;\r
+    real pc[10];\r
+    extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real \r
+           *, real *, integer *, integer *, integer *, real *, real *, \r
+           integer *, real *, struct lpc10_decoder_state *);\r
+    real rci[160]      /* was [10][16] */;\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.2  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:42:59  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:33  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:03:47  jaf */\r
+/* Removed definitions for any constants that were no longer used. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:33  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:43:51  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Configuration parameters: */\r
+/* Frame size, Prediction order, Pitch period */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.2  2003/09/27 02:45:37  markster\r
+/* Fix various compiler warnings (bug #322)\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:39  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:42:59  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_decoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_decoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:33  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*       Parameters/constants */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       BUF is a buffer of speech samples that would have been returned \r
+*/\r
+/*       by the older version of SYNTHS, but the newer version doesn't, */\r
+/*       so that the newer version can always return MAXFRM samples on */\r
+/*       every call.  This has the effect of delaying the return of */\r
+/*       samples for one additional frame time. */\r
+\r
+/*       Indices 1 through BUFLEN contain samples that are left over from \r
+*/\r
+/*       the last call to SYNTHS.  Given the way that PITSYN works, */\r
+/*       BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */\r
+/*       MAXFRM, inclusive, after a call to SYNTHS is complete. */\r
+\r
+/*       On the first call to SYNTHS (or the first call after */\r
+/*       reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and \r
+*/\r
+/*       a frame of silence is always returned. */\r
+    /* Parameter adjustments */\r
+    if (voice) {\r
+       --voice;\r
+       }\r
+    if (rc) {\r
+       --rc;\r
+       }\r
+    if (speech) {\r
+       --speech;\r
+       }\r
+\r
+    /* Function Body */\r
+    buf = &(st->buf[0]);\r
+    buflen = &(st->buflen);\r
+\r
+/* Computing MAX */\r
+    i__1 = min(*pitch,156);\r
+    *pitch = max(i__1,20);\r
+    i__1 = contrl_1.order;\r
+    for (i__ = 1; i__ <= i__1; ++i__) {\r
+/* Computing MAX */\r
+/* Computing MIN */\r
+       r__2 = rc[i__];\r
+       r__1 = min(r__2,.99f);\r
+       rc[i__] = max(r__1,-.99f);\r
+    }\r
+    pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe, \r
+           ivuv, ipiti, rmsi, rci, &nout, &ratio, st);\r
+    if (nout > 0) {\r
+       i__1 = nout;\r
+       for (j = 1; j <= i__1; ++j) {\r
+\r
+/*             Add synthesized speech for pitch period J to the en\r
+d of */\r
+/*             BUF. */\r
+\r
+           irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);\r
+           bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]\r
+                   , &ratio, &g2pass, st);\r
+           deemp_(&buf[*buflen], &ipiti[j - 1], st);\r
+           *buflen += ipiti[j - 1];\r
+       }\r
+\r
+/*          Copy first MAXFRM samples from BUF to output array SPEECH \r
+*/\r
+/*          (scaling them), and then remove them from the beginning of\r
+ */\r
+/*          BUF. */\r
+\r
+       for (i__ = 1; i__ <= 180; ++i__) {\r
+           speech[i__] = buf[i__ - 1] / 4096.f;\r
+       }\r
+       *k = 180;\r
+       *buflen += -180;\r
+       i__1 = *buflen;\r
+       for (i__ = 1; i__ <= i__1; ++i__) {\r
+           buf[i__ - 1] = buf[i__ + 179];\r
+       }\r
+    }\r
+    return 0;\r
+} /* synths_ */\r
diff --git a/libs/codec/lpc10/tbdm.c b/libs/codec/lpc10/tbdm.c
new file mode 100644 (file)
index 0000000..aaca148
--- /dev/null
@@ -0,0 +1,188 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:40  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:30:26  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);\r
+/*:ref: difmag_ 14 8 6 4 4 4 4 6 4 4 */\r
+#endif\r
+\r
+/* ********************************************************************** */\r
+\r
+/*     TBDM Version 49 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:40  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:30:26  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/18  22:14:00  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  14:48:37  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:49:54  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*TURBO DIFMAG: Compute High Resolution Average Magnitude Difference Function\r
+*/\r
+\r
+/* Note: There are several constants in here that appear to depend on a */\r
+/* particular TAU table.  That's not a problem for the LPC10 coder, but */\r
+/* watch out if you change the contents of TAU in the subroutine ANALYS. */\r
+\r
+/* Input: */\r
+/*  SPEECH - Low pass filtered speech */\r
+/*           Indices 1 through MAX+LPITA-1 are read, where: */\r
+/*           MAX = (TAU(LTAU)-TAU(1))/2+1 */\r
+/*           (If TAU(1) .LT. 39, then larger indices could be read */\r
+/*           by the last call to DIFMAG below.) */\r
+/*  LPITA  - Length of speech buffer */\r
+/*  TAU    - Table of lags, sorted in increasing order. */\r
+/*           Indices 1 through LTAU read. */\r
+/*  LTAU   - Number of lag values to compute */\r
+/* Output: */\r
+/*  AMDF   - Average Magnitude Difference for each lag in TAU */\r
+/*          Indices 1 through LTAU written, and several might then be read.*/\r
+/*  MINPTR - Index of minimum AMDF value */\r
+/*  MAXPTR - Index of maximum AMDF value within +/- 1/2 octave of min */\r
+/*  MINTAU - Lag corresponding to minimum AMDF value */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int tbdm_(real *speech, integer *lpita, integer *tau, \r
+       integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *\r
+       mintau)\r
+{\r
+    /* System generated locals */\r
+    integer i__1, i__2, i__3, i__4;\r
+\r
+    /* Local variables */\r
+    real amdf2[6];\r
+    integer minp2, ltau2, maxp2, i__;\r
+    extern /* Subroutine */ int difmag_(real *, integer *, integer *, integer \r
+           *, integer *, real *, integer *, integer *);\r
+    integer minamd, ptr, tau2[6];\r
+\r
+/*     Arguments */\r
+/*     REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU) */\r
+/*   Stupid TOAST doesn't understand expressions */\r
+/*       Local variables that need not be saved */\r
+/*       Local state */\r
+/*       None */\r
+/*   Compute full AMDF using log spaced lags, find coarse minimum */\r
+    /* Parameter adjustments */\r
+    --speech;\r
+    --amdf;\r
+    --tau;\r
+\r
+    /* Function Body */\r
+    difmag_(&speech[1], lpita, &tau[1], ltau, &tau[*ltau], &amdf[1], minptr, \r
+           maxptr);\r
+    *mintau = tau[*minptr];\r
+    minamd = amdf[*minptr];\r
+/*   Build table containing all lags within +/- 3 of the AMDF minimum */\r
+/*    excluding all that have already been computed */\r
+    ltau2 = 0;\r
+    ptr = *minptr - 2;\r
+/* Computing MAX */\r
+    i__1 = *mintau - 3;\r
+/* Computing MIN */\r
+    i__3 = *mintau + 3, i__4 = tau[*ltau] - 1;\r
+    i__2 = min(i__3,i__4);\r
+    for (i__ = max(i__1,41); i__ <= i__2; ++i__) {\r
+       while(tau[ptr] < i__) {\r
+           ++ptr;\r
+       }\r
+       if (tau[ptr] != i__) {\r
+           ++ltau2;\r
+           tau2[ltau2 - 1] = i__;\r
+       }\r
+    }\r
+/*   Compute AMDF of the new lags, if there are any, and choose one */\r
+/*    if it is better than the coarse minimum */\r
+    if (ltau2 > 0) {\r
+       difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &\r
+               maxp2);\r
+       if (amdf2[minp2 - 1] < (real) minamd) {\r
+           *mintau = tau2[minp2 - 1];\r
+           minamd = amdf2[minp2 - 1];\r
+       }\r
+    }\r
+/*   Check one octave up, if there are any lags not yet computed */\r
+    if (*mintau >= 80) {\r
+       i__ = *mintau / 2;\r
+       if ((i__ & 1) == 0) {\r
+           ltau2 = 2;\r
+           tau2[0] = i__ - 1;\r
+           tau2[1] = i__ + 1;\r
+       } else {\r
+           ltau2 = 1;\r
+           tau2[0] = i__;\r
+       }\r
+       difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &\r
+               maxp2);\r
+       if (amdf2[minp2 - 1] < (real) minamd) {\r
+           *mintau = tau2[minp2 - 1];\r
+           minamd = amdf2[minp2 - 1];\r
+           *minptr += -20;\r
+       }\r
+    }\r
+/*   Force minimum of the AMDF array to the high resolution minimum */\r
+    amdf[*minptr] = (real) minamd;\r
+/*   Find maximum of AMDF within 1/2 octave of minimum */\r
+/* Computing MAX */\r
+    i__2 = *minptr - 5;\r
+    *maxptr = max(i__2,1);\r
+/* Computing MIN */\r
+    i__1 = *minptr + 5;\r
+    i__2 = min(i__1,*ltau);\r
+    for (i__ = *maxptr + 1; i__ <= i__2; ++i__) {\r
+       if (amdf[i__] > amdf[*maxptr]) {\r
+           *maxptr = i__;\r
+       }\r
+    }\r
+    return 0;\r
+} /* tbdm_ */\r
+\r
diff --git a/libs/codec/lpc10/voicin.c b/libs/codec/lpc10/voicin.c
new file mode 100644 (file)
index 0000000..dc277e5
--- /dev/null
@@ -0,0 +1,786 @@
+/*\r
+\r
+$Log$\r
+Revision 1.16  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.15  2003/11/23 22:14:32  markster\r
+Various warning cleanups\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:40  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.2  1996/08/20  20:45:00  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:14  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: vparms_ 14 14 4 6 6 4 4 6 4 4 4 4 6 6 6 6 */\r
+#endif\r
+\r
+/* Common Block Declarations */\r
+\r
+extern struct {\r
+    integer order, lframe;\r
+    logical corrp;\r
+} contrl_;\r
+\r
+#define contrl_1 contrl_\r
+\r
+/****************************************************************************/\r
+\r
+/*     VOICIN Version 52 */\r
+\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/11/23 22:14:32  markster\r
+/* Various warning cleanups\r
+/*\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:40  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:45:00  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:14  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.10  1996/03/29  17:59:14  jaf */\r
+/* Avoided using VALUE(9), although it shouldn't affect the function of */\r
+/* the code at all, because it was always multiplied by VDC(9,SNRL), */\r
+/* which is 0 for all values of SNRL.  Still, if VALUE(9) had an initial */\r
+/* value of IEEE NaN, it might cause trouble (I don't know how IEEE */\r
+/* defines Nan * 0.  It should either be NaN or 0.) */\r
+\r
+/* Revision 1.9  1996/03/29  17:54:46  jaf */\r
+/* Added a few comments about the accesses made to argument array VOIBUF */\r
+/* and the local saved array VOICE. */\r
+\r
+/* Revision 1.8  1996/03/27  18:19:54  jaf */\r
+/* Added an assignment to VSTATE that does not affect the function of the */\r
+/* program at all.  The only reason I put it in was so that the tracing */\r
+/* statements at the end, when enabled, will print a consistent value for */\r
+/* VSTATE when HALF .EQ. 1, rather than a garbage value that could change */\r
+/* from one call to the next. */\r
+\r
+/* Revision 1.7  1996/03/26  20:00:06  jaf */\r
+/* Removed the inclusion of the file "vcomm.fh", and put its contents */\r
+/* into this file.  It was included nowhere else but here. */\r
+\r
+/* Revision 1.6  1996/03/26  19:38:09  jaf */\r
+/* Commented out trace statements. */\r
+\r
+/* Revision 1.5  1996/03/19  20:43:45  jaf */\r
+/* Added comments about which indices of OBOUND and VOIBUF can be */\r
+/* accessed, and whether they are read or written.  VOIBUF is fairly */\r
+/* messy. */\r
+\r
+/* Revision 1.4  1996/03/19  15:00:58  jaf */\r
+/* Moved the DATA statements for the *VDC* variables later, as it is */\r
+/* apparently illegal to have DATA statements before local variable */\r
+/* declarations. */\r
+\r
+/* Revision 1.3  1996/03/19  00:10:49  jaf */\r
+/* Heavily commented the local variables that are saved from one */\r
+/* invocation to the next, and how the local variable FIRST is used to */\r
+/* avoid the need to assign most of them initial values with DATA */\r
+/* statements. */\r
+\r
+/* A few should be initialized, but aren't.  I've guessed initial values */\r
+/* for two of these, SFBUE and SLBUE, and I've convinced myself that for */\r
+/* VOICE, the effects of uninitialized values will die out after 2 or 3 */\r
+/* frame times.  It would still be good to choose initial values for */\r
+/* these, but I don't know what reasonable values would be (0 comes to */\r
+/* mind). */\r
+\r
+/* Revision 1.2  1996/03/13  16:09:28  jaf */\r
+/* Comments added explaining which of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next, and which */\r
+/* do not. */\r
+\r
+/* WARNING!  Some of them that should are never given initial values in */\r
+/* this code.  Hopefully, Fortran 77 defines initial values for them, but */\r
+/* even so, giving them explicit initial values is preferable. */\r
+\r
+/* WARNING!  VALUE(9) is used, but never assigned a value.  It should */\r
+/* probably be eliminated from the code. */\r
+\r
+/* Revision 1.1  1996/02/07 14:50:28  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/****************************************************************************/\r
+\r
+/*        Voicing Detection (VOICIN) makes voicing decisions for each half */\r
+/*  frame of input speech.  Tentative voicing decisions are made two frames*/\r
+/*   in the future (2F) for each half frame.  These decisions are carried */\r
+/*   through one frame in the future (1F) to the present (P) frame where */\r
+/*   they are examined and smoothed, resulting in the final voicing */\r
+/*   decisions for each half frame. */\r
+/*        The voicing parameter (signal measurement) column vector (VALUE) */\r
+/*   is based on a rectangular window of speech samples determined by the */\r
+/*  window placement algorithm.  The voicing parameter vector contains the*/\r
+/*  AMDF windowed maximum-to-minimum ratio, the zero crossing rate, energy*/\r
+/*   measures, reflection coefficients, and prediction gains.  The voicing */\r
+/*  window is placed to avoid contamination of the voicing parameter vector*/\r
+/*   with speech onsets. */\r
+/*        The input signal is then classified as unvoiced (including */\r
+/*   silence) or voiced.  This decision is made by a linear discriminant */\r
+/*   function consisting of a dot product of the voicing decision */\r
+/*   coefficient (VDC) row vector with the measurement column vector */\r
+/*  (VALUE).  The VDC vector is 2-dimensional, each row vector is optimized*/\r
+/*   for a particular signal-to-noise ratio (SNR).  So, before the dot */\r
+/*   product is performed, the SNR is estimated to select the appropriate */\r
+/*   VDC vector. */\r
+/*        The smoothing algorithm is a modified median smoother.  The */\r
+/*  voicing discriminant function is used by the smoother to determine how*/\r
+/*   strongly voiced or unvoiced a signal is.  The smoothing is further */\r
+/*   modified if a speech onset and a voicing decision transition occur */\r
+/*   within one half frame.  In this case, the voicing decision transition */\r
+/*  is extended to the speech onset.  For transmission purposes, there are*/\r
+/*   constraints on the duration and transition of voicing decisions.  The */\r
+/*   smoother takes these constraints into account. */\r
+/*        Finally, the energy estimates are updated along with the dither */\r
+/*   threshold used to calculate the zero crossing rate (ZC). */\r
+\r
+/* Inputs: */\r
+/*  VWIN      - Voicing window limits */\r
+/*              The indices read of arrays VWIN, INBUF, LPBUF, and BUFLIM */\r
+/*              are the same as those read by subroutine VPARMS. */\r
+/*  INBUF     - Input speech buffer */\r
+/*  LPBUF     - Low-pass filtered speech buffer */\r
+/*  BUFLIM    - INBUF and LPBUF limits */\r
+/*  HALF      - Present analysis half frame number */\r
+/*  MINAMD    - Minimum value of the AMDF */\r
+/*  MAXAMD    - Maximum value of the AMDF */\r
+/*  MINTAU    - Pointer to the lag of the minimum AMDF value */\r
+/*  IVRC(2)   - Inverse filter's RC's */\r
+/*              Only index 2 of array IVRC read under normal operation. */\r
+/*              (Index 1 is also read when debugging is turned on.) */\r
+/*  OBOUND    - Onset boundary descriptions */\r
+/*             Indices 1 through 3 read if (HALF .NE. 1), otherwise untouched.\r
+*/\r
+/*  AF        - The analysis frame number */\r
+/* Output: */\r
+/*  VOIBUF(2,0:AF) - Buffer of voicing decisions */\r
+/*              Index (HALF,3) written. */\r
+/*              If (HALF .EQ. 1), skip down to "Read (HALF,3)" below. */\r
+/*              Indices (1,2), (2,1), (1,2), and (2,2) read. */\r
+/*              One of the following is then done: */\r
+/*                 read (1,3) and possibly write (1,2) */\r
+/*                 read (1,3) and write (1,2) or (2,2) */\r
+/*                 write (2,1) */\r
+/*                 write (2,1) or (1,2) */\r
+/*                 read (1,0) and (1,3) and then write (2,2) or (1,1) */\r
+/*                 no reads or writes on VOIBUF */\r
+/*              Finally, read (HALF,3) */\r
+/* Internal: */\r
+/*  QS        - Ratio of preemphasized to full-band energies */\r
+/*  RC1       - First reflection coefficient */\r
+/* AR_B      - Product of the causal forward and reverse pitch prediction gain\r
+s*/\r
+/* AR_F      - Product of the noncausal forward and rev. pitch prediction gain\r
+s*/\r
+/*  ZC        - Zero crossing rate */\r
+/*  DITHER    - Zero crossing threshold level */\r
+/*  MAXMIN    - AMDF's 1 octave windowed maximum-to-minimum ratio */\r
+/*  MINPTR    - Location  of minimum AMDF value */\r
+/*  NVDC      - Number of elements in each VDC vector */\r
+/*  NVDCL     - Number of VDC vectors */\r
+/*  VDCL      - SNR values corresponding to the set of VDC's */\r
+/*  VDC       - 2-D voicing decision coefficient vector */\r
+/*  VALUE(9)  - Voicing Parameters */\r
+/*  VOICE(2,3)- History of LDA results */\r
+/*              On every call when (HALF .EQ. 1), VOICE(*,I+1) is */\r
+/*              shifted back to VOICE(*,I), for I=1,2. */\r
+/*              VOICE(HALF,3) is written on every call. */\r
+/*              Depending on several conditions, one or more of */\r
+/*              (1,1), (1,2), (2,1), and (2,2) might then be read. */\r
+/*  LBE       - Ratio of low-band instantaneous to average energies */\r
+/*  FBE       - Ratio of full-band instantaneous to average energies */\r
+/*  LBVE      - Low band voiced energy */\r
+/*  LBUE      - Low band unvoiced energy */\r
+/*  FBVE      - Full band voiced energy */\r
+/*  FBUE      - Full band unvoiced energy */\r
+/*  OFBUE     - Previous full-band unvoiced energy */\r
+/*  OLBUE     - Previous low-band unvoiced energy */\r
+/*  REF       - Reference energy for initialization and DITHER threshold */\r
+/*  SNR       - Estimate of signal-to-noise ratio */\r
+/*  SNR2      - Estimate of low-band signal-to-noise ratio */\r
+/*  SNRL      - SNR level number */\r
+/*  OT        - Onset transition present */\r
+/*  VSTATE    - Decimal interpretation of binary voicing classifications */\r
+/*  FIRST     - First call flag */\r
+\r
+/* This subroutine maintains local state from one call to the next.  If */\r
+/* you want to switch to using a new audio stream for this filter, or */\r
+/* reinitialize its state for any other reason, call the ENTRY */\r
+/* INITVOICIN. */\r
+\r
+/* Subroutine */ int voicin_(integer *vwin, real *inbuf, real *\r
+       lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, \r
+       integer *mintau, real *ivrc, integer *obound, integer *voibuf, \r
+       integer *af, struct lpc10_encoder_state *st)\r
+{\r
+    /* Initialized data */\r
+\r
+    real *dither;\r
+    static real vdc[100]       /* was [10][10] */ = { 0.f,1714.f,-110.f,\r
+           334.f,-4096.f,-654.f,3752.f,3769.f,0.f,1181.f,0.f,874.f,-97.f,\r
+           300.f,-4096.f,-1021.f,2451.f,2527.f,0.f,-500.f,0.f,510.f,-70.f,\r
+           250.f,-4096.f,-1270.f,2194.f,2491.f,0.f,-1500.f,0.f,500.f,-10.f,\r
+           200.f,-4096.f,-1300.f,2e3f,2e3f,0.f,-2e3f,0.f,500.f,0.f,0.f,\r
+           -4096.f,-1300.f,2e3f,2e3f,0.f,-2500.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,\r
+           0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,\r
+           0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,\r
+           0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f };\r
+    static integer nvdcl = 5;\r
+    static real vdcl[10] = { 600.f,450.f,300.f,200.f,0.f,0.f,0.f,0.f,0.f,0.f }\r
+           ;\r
+\r
+    /* System generated locals */\r
+    integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;\r
+    real r__1, r__2;\r
+\r
+    /* Builtin functions */\r
+    integer i_nint(real *);\r
+    double sqrt(doublereal);\r
+\r
+    /* Local variables */\r
+    real ar_b__, ar_f__;\r
+    integer *lbve, *lbue, *fbve, *fbue;\r
+    integer snrl, i__;\r
+    integer *ofbue, *sfbue;\r
+    real *voice;\r
+    integer *olbue, *slbue;\r
+    real value[9];\r
+    integer zc;\r
+    logical ot;\r
+    real qs;\r
+    real *maxmin;\r
+    integer vstate;\r
+    real rc1;\r
+    extern /* Subroutine */ int vparms_(integer *, real *, real *, integer *, \r
+           integer *, real *, integer *, integer *, integer *, integer *, \r
+           real *, real *, real *, real *);\r
+    integer fbe, lbe;\r
+    real *snr;\r
+    real snr2;\r
+\r
+/*     Global Variables: */\r
+/*       Arguments */\r
+/* $Log$\r
+ * Revision 1.16  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.15  2003/11/23 22:14:32  markster\r
+/* Various warning cleanups\r
+/*\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:40  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.2  1996/08/20  20:45:00  jaf\r
+ * Removed all static local variables that were SAVE'd in the Fortran\r
+ * code, and put them in struct lpc10_encoder_state that is passed as an\r
+ * argument.\r
+ *\r
+ * Removed init function, since all initialization is now done in\r
+ * init_lpc10_encoder_state().\r
+ *\r
+ * Revision 1.1  1996/08/19  22:30:14  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.3  1996/03/29  22:05:55  jaf */\r
+/* Commented out the common block variables that are not needed by the */\r
+/* embedded version. */\r
+\r
+/* Revision 1.2  1996/03/26  19:34:50  jaf */\r
+/* Added comments indicating which constants are not needed in an */\r
+/* application that uses the LPC-10 coder. */\r
+\r
+/* Revision 1.1  1996/02/07  14:44:09  jaf */\r
+/* Initial revision */\r
+\r
+/*   LPC Processing control variables: */\r
+\r
+/* *** Read-only: initialized in setup */\r
+\r
+/*  Files for Speech, Parameter, and Bitstream Input & Output, */\r
+/*    and message and debug outputs. */\r
+\r
+/* Here are the only files which use these variables: */\r
+\r
+/* lpcsim.f setup.f trans.f error.f vqsetup.f */\r
+\r
+/* Many files which use fdebug are not listed, since it is only used in */\r
+/* those other files conditionally, to print trace statements. */\r
+/*     integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*  LPC order, Frame size, Quantization rate, Bits per frame, */\r
+/*    Error correction */\r
+/* Subroutine SETUP is the only place where order is assigned a value, */\r
+/* and that value is 10.  It could increase efficiency 1% or so to */\r
+/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as \r
+*/\r
+/* a variable in a COMMON block, since it is used in many places in the */\r
+/* core of the coding and decoding routines.  Actually, I take that back. \r
+*/\r
+/* At least when compiling with f2c, the upper bound of DO loops is */\r
+/* stored in a local variable before the DO loop begins, and then that is \r
+*/\r
+/* compared against on each iteration. */\r
+/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */\r
+/* Similarly for quant, which is given a value of 2400 in SETUP.  quant */\r
+/* is used in only a few places, and never in the core coding and */\r
+/* decoding routines, so it could be eliminated entirely. */\r
+/* nbits is similar to quant, and is given a value of 54 in SETUP. */\r
+/* corrp is given a value of .TRUE. in SETUP, and is only used in the */\r
+/* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */\r
+/* coder significantly whether it is .TRUE. or .FALSE., or whether it is \r
+*/\r
+/* a constant or a variable, since it is only examined once per frame. */\r
+/* Leaving it as a variable that is set to .TRUE.  seems like a good */\r
+/* idea, since it does enable some error-correction capability for */\r
+/* unvoiced frames, with no change in the coding rate, and no noticeable \r
+*/\r
+/* quality difference in the decoded speech. */\r
+/*     integer quant, nbits */\r
+/* *** Read/write: variables for debugging, not needed for LPC algorithm \r
+*/\r
+\r
+/*  Current frame, Unstable frames, Output clip count, Max onset buffer, \r
+*/\r
+/*    Debug listing detail level, Line count on listing page */\r
+\r
+/* nframe is not needed for an embedded LPC10 at all. */\r
+/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */\r
+/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */\r
+/* an application, I would recommend removing the call to ERROR in RCCHK, \r
+*/\r
+/* and remove ERROR and nunsfm completely. */\r
+/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in \r
+*/\r
+/* sread.f.  When LPC10 is embedded into an application, one might want */\r
+/* to cause it to be incremented in a routine that takes the output of */\r
+/* SYNTHS and sends it to an audio device.  It could be optionally */\r
+/* displayed, for those that might want to know what it is. */\r
+/* maxosp is never initialized to 0 in SETUP, although it probably should \r
+*/\r
+/* be, and it is updated in subroutine ANALYS.  I doubt that its value */\r
+/* would be of much interest to an application in which LPC10 is */\r
+/* embedded. */\r
+/* listl and lincnt are not needed for an embedded LPC10 at all. */\r
+/*     integer nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */\r
+/*     common /contrl/ quant, nbits */\r
+/*     common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */\r
+/*     Parameters/constants */\r
+/*       Voicing coefficient and Linear Discriminant Analysis variables: \r
+*/\r
+/*       Max number of VDC's and VDC levels */\r
+/*       The following are not Fortran PARAMETER's, but they are */\r
+/*       initialized with DATA statements, and never modified. */\r
+/*       Actual number of VDC's and levels */\r
+/*       Local variables that need not be saved */\r
+/*       Note: */\r
+\r
+/*       VALUE(1) through VALUE(8) are assigned values, but VALUE(9) */\r
+/*       never is.  Yet VALUE(9) is read in the loop that begins "DO I = \r
+*/\r
+/*       1, 9" below.  I believe that this doesn't cause any problems in \r
+*/\r
+/*       this subroutine, because all VDC(9,*) array elements are 0, and \r
+*/\r
+/*       this is what is multiplied by VALUE(9) in all cases.  Still, it \r
+*/\r
+/*       would save a multiplication to change the loop to "DO I = 1, 8". \r
+*/\r
+/*       Local state */\r
+/*       WARNING! */\r
+\r
+/*       VOICE, SFBUE, and SLBUE should be saved from one invocation to */\r
+/*       the next, but they are never given an initial value. */\r
+\r
+/*       Does Fortran 77 specify some default initial value, like 0, or */\r
+/*       is it undefined?  If it is undefined, then this code should be */\r
+/*       corrected to specify an initial value. */\r
+\r
+/*       For VOICE, note that it is "shifted" in the statement that */\r
+/*       begins "IF (HALF .EQ. 1) THEN" below.  Also, uninitialized */\r
+/*       values in the VOICE array can only affect entries in the VOIBUF \r
+*/\r
+/*       array that are for the same frame, or for an older frame.  Thus \r
+*/\r
+/*       the effects of uninitialized values in VOICE cannot linger on */\r
+/*       for more than 2 or 3 frame times. */\r
+\r
+/*       For SFBUE and SLBUE, the effects of uninitialized values can */\r
+/*       linger on for many frame times, because their previous values */\r
+/*       are exponentially decayed.  Thus it is more important to choose \r
+*/\r
+/*       initial values for these variables.  I would guess that a */\r
+/*       reasonable initial value for SFBUE is REF/16, the same as used */\r
+/*       for FBUE and OFBUE.  Similarly, SLBUE can be initialized to */\r
+/*       REF/32, the same as for LBUE and OLBUE. */\r
+\r
+/*       These guessed initial values should be validated by re-running */\r
+/*       the modified program on some audio samples. */\r
+\r
+/*   Declare and initialize filters: */\r
+\r
+    dither = (&st->dither);\r
+    snr = (&st->snr);\r
+    maxmin = (&st->maxmin);\r
+    voice = (&st->voice[0]);\r
+    lbve = (&st->lbve);\r
+    lbue = (&st->lbue);\r
+    fbve = (&st->fbve);\r
+    fbue = (&st->fbue);\r
+    ofbue = (&st->ofbue);\r
+    olbue = (&st->olbue);\r
+    sfbue = (&st->sfbue);\r
+    slbue = (&st->slbue);\r
+\r
+    /* Parameter adjustments */\r
+    if (vwin) {\r
+       --vwin;\r
+       }\r
+    if (buflim) {\r
+       --buflim;\r
+       }\r
+    if (inbuf) {\r
+       inbuf_offset = buflim[1];\r
+       inbuf -= inbuf_offset;\r
+       }\r
+    if (lpbuf) {\r
+       lpbuf_offset = buflim[3];\r
+       lpbuf -= lpbuf_offset;\r
+       }\r
+    if (ivrc) {\r
+       --ivrc;\r
+       }\r
+    if (obound) {\r
+       --obound;\r
+       }\r
+    if (voibuf) {\r
+       --voibuf;\r
+       }\r
+\r
+    /* Function Body */\r
+\r
+/*       The following variables are saved from one invocation to the */\r
+/*       next, but are not initialized with DATA statements.  This is */\r
+/*       acceptable, because FIRST is initialized ot .TRUE., and the */\r
+/*       first time that this subroutine is then called, they are all */\r
+/*       given initial values. */\r
+\r
+/*       SNR */\r
+/*       LBVE, LBUE, FBVE, FBUE, OFBUE, OLBUE */\r
+\r
+/*       MAXMIN is initialized on the first call, assuming that HALF */\r
+/*       .EQ. 1 on first call.  This is how ANALYS calls this subroutine. \r
+*/\r
+\r
+/*   Voicing Decision Parameter vector (* denotes zero coefficient): */\r
+\r
+/*     * MAXMIN */\r
+/*       LBE/LBVE */\r
+/*       ZC */\r
+/*       RC1 */\r
+/*       QS */\r
+/*       IVRC2 */\r
+/*       aR_B */\r
+/*       aR_F */\r
+/*     * LOG(LBE/LBVE) */\r
+/*  Define 2-D voicing decision coefficient vector according to the voicin\r
+g*/\r
+/*  parameter order above.  Each row (VDC vector) is optimized for a speci\r
+fic*/\r
+/*   SNR.  The last element of the vector is the constant. */\r
+/*              E    ZC    RC1    Qs   IVRC2  aRb   aRf        c */\r
+\r
+/*  The VOICE array contains the result of the linear discriminant functio\r
+n*/\r
+/*   (analog values).  The VOIBUF array contains the hard-limited binary \r
+*/\r
+/*   voicing decisions.  The VOICE and VOIBUF arrays, according to FORTRAN\r
+ */\r
+/*   memory allocation, are addressed as: */\r
+\r
+/*        (half-frame number, future-frame number) */\r
+\r
+/*        |   Past    |  Present  |  Future1  |  Future2  | */\r
+/*        | 1,0 | 2,0 | 1,1 | 2,1 | 1,2 | 2,2 | 1,3 | 2,3 |  --->  time */\r
+\r
+/*   Update linear discriminant function history each frame: */\r
+    if (*half == 1) {\r
+       voice[0] = voice[2];\r
+       voice[1] = voice[3];\r
+       voice[2] = voice[4];\r
+       voice[3] = voice[5];\r
+       *maxmin = *maxamd / max(*minamd,1.f);\r
+    }\r
+/*   Calculate voicing parameters twice per frame: */\r
+    vparms_(&vwin[1], &inbuf[inbuf_offset], &lpbuf[lpbuf_offset], &buflim[1], \r
+           half, dither, mintau, &zc, &lbe, &fbe, &qs, &rc1, &ar_b__, &\r
+           ar_f__);\r
+/*   Estimate signal-to-noise ratio to select the appropriate VDC vector. \r
+*/\r
+/*   The SNR is estimated as the running average of the ratio of the */\r
+/*   running average full-band voiced energy to the running average */\r
+/*   full-band unvoiced energy. SNR filter has gain of 63. */\r
+    r__1 = (*snr + *fbve / (real) max(*fbue,1)) * 63 / 64.f;\r
+    *snr = (real) i_nint(&r__1);\r
+    snr2 = *snr * *fbue / max(*lbue,1);\r
+/*   Quantize SNR to SNRL according to VDCL thresholds. */\r
+    snrl = 1;\r
+    i__1 = nvdcl - 1;\r
+    for (snrl = 1; snrl <= i__1; ++snrl) {\r
+       if (snr2 > vdcl[snrl - 1]) {\r
+           goto L69;\r
+       }\r
+    }\r
+/*     (Note:  SNRL = NVDCL here) */\r
+L69:\r
+/*   Linear discriminant voicing parameters: */\r
+    value[0] = *maxmin;\r
+    value[1] = (real) lbe / max(*lbve,1);\r
+    value[2] = (real) zc;\r
+    value[3] = rc1;\r
+    value[4] = qs;\r
+    value[5] = ivrc[2];\r
+    value[6] = ar_b__;\r
+    value[7] = ar_f__;\r
+/*   Evaluation of linear discriminant function: */\r
+    voice[*half + 3] = vdc[snrl * 10 - 1];\r
+    for (i__ = 1; i__ <= 8; ++i__) {\r
+       voice[*half + 3] += vdc[i__ + snrl * 10 - 11] * value[i__ - 1];\r
+    }\r
+/*   Classify as voiced if discriminant > 0, otherwise unvoiced */\r
+/*   Voicing decision for current half-frame:  1 = Voiced; 0 = Unvoiced */\r
+    if (voice[*half + 3] > 0.f) {\r
+       voibuf[*half + 6] = 1;\r
+    } else {\r
+       voibuf[*half + 6] = 0;\r
+    }\r
+/*   Skip voicing decision smoothing in first half-frame: */\r
+/*     Give a value to VSTATE, so that trace statements below will print \r
+*/\r
+/*     a consistent value from one call to the next when HALF .EQ. 1. */\r
+/*     The value of VSTATE is not used for any other purpose when this is \r
+*/\r
+/*     true. */\r
+    vstate = -1;\r
+    if (*half == 1) {\r
+       goto L99;\r
+    }\r
+/*   Voicing decision smoothing rules (override of linear combination): */\r
+\r
+/*     Unvoiced half-frames:  At least two in a row. */\r
+/*     -------------------- */\r
+\r
+/*     Voiced half-frames:    At least two in a row in one frame. */\r
+/*     -------------------    Otherwise at least three in a row. */\r
+/*                            (Due to the way transition frames are encoded) */\r
+\r
+/*     In many cases, the discriminant function determines how to smooth. */\r
+/*     In the following chart, the decisions marked with a * may be overridden\r
+.*/\r
+\r
+/*   Voicing override of transitions at onsets: */\r
+/*     If a V/UV or UV/V voicing decision transition occurs within one-half \r
+*/\r
+/*     frame of an onset bounding a voicing window, then the transition is */\r
+/*     moved to occur at the onset. */\r
+\r
+/*     P       1F */\r
+/*     -----   ----- */\r
+/*     0   0   0   0 */\r
+/*     0   0   0*  1   (If there is an onset there) */\r
+/*     0   0   1*  0*  (Based on 2F and discriminant distance) */\r
+/*     0   0   1   1 */\r
+/*     0   1*  0   0   (Always) */\r
+/*     0   1*  0*  1   (Based on discriminant distance) */\r
+/*     0*  1   1   0*  (Based on past, 2F, and discriminant distance) */\r
+/*     0   1*  1   1   (If there is an onset there) */\r
+/*     1   0*  0   0   (If there is an onset there) */\r
+/*     1   0   0   1 */\r
+/*     1   0*  1*  0   (Based on discriminant distance) */\r
+/*     1   0*  1   1   (Always) */\r
+/*     1   1   0   0 */\r
+/*     1   1   0*  1*  (Based on 2F and discriminant distance) */\r
+/*     1   1   1*  0   (If there is an onset there) */\r
+/*     1   1   1   1 */\r
+\r
+/*   Determine if there is an onset transition between P and 1F. */\r
+/*   OT (Onset Transition) is true if there is an onset between */\r
+/*   P and 1F but not after 1F. */\r
+    ot = ((obound[1] & 2) != 0 || obound[2] == 1) && (obound[3] & 1) == 0;\r
+/*   Multi-way dispatch on voicing decision history: */\r
+    vstate = (voibuf[3] << 3) + (voibuf[4] << 2) + (voibuf[5] << 1) + voibuf[\r
+           6];\r
+    switch (vstate + 1) {\r
+       case 1:  goto L99;\r
+       case 2:  goto L1;\r
+       case 3:  goto L2;\r
+       case 4:  goto L99;\r
+       case 5:  goto L4;\r
+       case 6:  goto L5;\r
+       case 7:  goto L6;\r
+       case 8:  goto L7;\r
+       case 9:  goto L8;\r
+       case 10:  goto L99;\r
+       case 11:  goto L10;\r
+       case 12:  goto L11;\r
+       case 13:  goto L99;\r
+       case 14:  goto L13;\r
+       case 15:  goto L14;\r
+       case 16:  goto L99;\r
+    }\r
+L1:\r
+    if (ot && voibuf[7] == 1) {\r
+       voibuf[5] = 1;\r
+    }\r
+    goto L99;\r
+L2:\r
+    if (voibuf[7] == 0 || voice[2] < -voice[3]) {\r
+       voibuf[5] = 0;\r
+    } else {\r
+       voibuf[6] = 1;\r
+    }\r
+    goto L99;\r
+L4:\r
+    voibuf[4] = 0;\r
+    goto L99;\r
+L5:\r
+    if (voice[1] < -voice[2]) {\r
+       voibuf[4] = 0;\r
+    } else {\r
+       voibuf[5] = 1;\r
+    }\r
+    goto L99;\r
+/*   VOIBUF(2,0) must be 0 */\r
+L6:\r
+    if (voibuf[1] == 1 || voibuf[7] == 1 || voice[3] > voice[0]) {\r
+       voibuf[6] = 1;\r
+    } else {\r
+       voibuf[3] = 1;\r
+    }\r
+    goto L99;\r
+L7:\r
+    if (ot) {\r
+       voibuf[4] = 0;\r
+    }\r
+    goto L99;\r
+L8:\r
+    if (ot) {\r
+       voibuf[4] = 1;\r
+    }\r
+    goto L99;\r
+L10:\r
+    if (voice[2] < -voice[1]) {\r
+       voibuf[5] = 0;\r
+    } else {\r
+       voibuf[4] = 1;\r
+    }\r
+    goto L99;\r
+L11:\r
+    voibuf[4] = 1;\r
+    goto L99;\r
+L13:\r
+    if (voibuf[7] == 0 && voice[3] < -voice[2]) {\r
+       voibuf[6] = 0;\r
+    } else {\r
+       voibuf[5] = 1;\r
+    }\r
+    goto L99;\r
+L14:\r
+    if (ot && voibuf[7] == 0) {\r
+       voibuf[5] = 0;\r
+    }\r
+/*     GOTO 99 */\r
+L99:\r
+/*   Now update parameters: */\r
+/*   ---------------------- */\r
+\r
+/*  During unvoiced half-frames, update the low band and full band unvoice\r
+d*/\r
+/*   energy estimates (LBUE and FBUE) and also the zero crossing */\r
+/*   threshold (DITHER).  (The input to the unvoiced energy filters is */\r
+/*   restricted to be less than 10dB above the previous inputs of the */\r
+/*   filters.) */\r
+/*   During voiced half-frames, update the low-pass (LBVE) and all-pass */\r
+/*   (FBVE) voiced energy estimates. */\r
+    if (voibuf[*half + 6] == 0) {\r
+/* Computing MIN */\r
+       i__1 = fbe, i__2 = *ofbue * 3;\r
+       r__1 = (*sfbue * 63 + (min(i__1,i__2) << 3)) / 64.f;\r
+       *sfbue = i_nint(&r__1);\r
+       *fbue = *sfbue / 8;\r
+       *ofbue = fbe;\r
+/* Computing MIN */\r
+       i__1 = lbe, i__2 = *olbue * 3;\r
+       r__1 = (*slbue * 63 + (min(i__1,i__2) << 3)) / 64.f;\r
+       *slbue = i_nint(&r__1);\r
+       *lbue = *slbue / 8;\r
+       *olbue = lbe;\r
+    } else {\r
+       r__1 = (*lbve * 63 + lbe) / 64.f;\r
+       *lbve = i_nint(&r__1);\r
+       r__1 = (*fbve * 63 + fbe) / 64.f;\r
+       *fbve = i_nint(&r__1);\r
+    }\r
+/*   Set dither threshold to yield proper zero crossing rates in the */\r
+/*   presence of low frequency noise and low level signal input. */\r
+/*   NOTE: The divisor is a function of REF, the expected energies. */\r
+/* Computing MIN */\r
+/* Computing MAX */\r
+    r__2 = sqrt((real) (*lbue * *lbve)) * 64 / 3000;\r
+    r__1 = max(r__2,1.f);\r
+    *dither = min(r__1,20.f);\r
+/*   Voicing decisions are returned in VOIBUF. */\r
+    return 0;\r
+} /* voicin_ */\r
diff --git a/libs/codec/lpc10/vparms.c b/libs/codec/lpc10/vparms.c
new file mode 100644 (file)
index 0000000..e40cbfd
--- /dev/null
@@ -0,0 +1,255 @@
+/*\r
+\r
+$Log$\r
+Revision 1.15  2004/06/26 03:50:14  markster\r
+Merge source cleanups (bug #1911)\r
+\r
+Revision 1.14  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+mer feb 12 14:56:57 CET 2003\r
+\r
+Revision 1.2  2000/01/05 08:20:40  markster\r
+Some OSS fixes and a few lpc changes to make it actually work\r
+\r
+ * Revision 1.1  1996/08/19  22:30:04  jaf\r
+ * Initial revision\r
+ *\r
+\r
+*/\r
+\r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);\r
+#endif\r
+\r
+/* Table of constant values */\r
+\r
+static real c_b2 = 1.f;\r
+\r
+/* ********************************************************************* */\r
+\r
+/*     VPARMS Version 50 */\r
+\r
+/* $Log$\r
+ * Revision 1.15  2004/06/26 03:50:14  markster\r
+ * Merge source cleanups (bug #1911)\r
+ *\r
+/* Revision 1.14  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
+/* mer feb 12 14:56:57 CET 2003\r
+/*\r
+/* Revision 1.2  2000/01/05 08:20:40  markster\r
+/* Some OSS fixes and a few lpc changes to make it actually work\r
+/*\r
+ * Revision 1.1  1996/08/19  22:30:04  jaf\r
+ * Initial revision\r
+ * */\r
+/* Revision 1.6  1996/03/29  18:01:16  jaf */\r
+/* Added some more comments about the range of INBUF and LPBUF that can */\r
+/* be read.  Note that it is possible for index VWIN(2)+1 to be read from */\r
+/* INBUF, which might be outside of its defined range, although that will */\r
+/* require more careful checking. */\r
+\r
+/* Revision 1.5  1996/03/19  00:02:02  jaf */\r
+/* I just noticed that the argument DITHER is modified inside of this */\r
+/* subroutine.  Comments were added explaining the possible final values. */\r
+\r
+/* Revision 1.4  1996/03/18  22:22:59  jaf */\r
+/* Finishing the job I said I did with the last check-in comments. */\r
+\r
+/* Revision 1.3  1996/03/18  22:22:17  jaf */\r
+/* Just added a few comments about which array indices of the arguments */\r
+/* are used, and mentioning that this subroutine has no local state. */\r
+\r
+/* Revision 1.2  1996/03/13  15:02:58  jaf */\r
+/* Comments added explaining that none of the local variables of this */\r
+/* subroutine need to be saved from one invocation to the next. */\r
+\r
+/* Revision 1.1  1996/02/07 14:50:42  jaf */\r
+/* Initial revision */\r
+\r
+\r
+/* ********************************************************************* */\r
+\r
+/*  Calculate voicing parameters: */\r
+\r
+/* Input: */\r
+/*  VWIN   - Voicing window limits */\r
+/*           Indices 1 through 2 read. */\r
+/*  INBUF  - Input speech buffer */\r
+/*           Indices START-1 through STOP read, */\r
+/*          where START and STOP are defined in the code (only written once).\r
+*/\r
+/*           Note that STOP can be as large as VWIN(2)+1 ! */\r
+/*  LPBUF  - Low pass filtered speech */\r
+/*           Indices START-MINTAU through STOP+MINTAU read, */\r
+/*          where START and STOP are defined in the code (only written once).\r
+*/\r
+/*  BUFLIM - Array bounds for INBUF and LPBUF */\r
+/*           Indices 1 through 4 read. */\r
+/*  HALF   - Half frame (1 or 2) */\r
+/*  MINTAU - Lag corresponding to minimum AMDF value (pitch estimate) */\r
+/* Input/Output: */\r
+/*  DITHER - Zero crossing threshold */\r
+/*           The resulting value might be the negation of the input */\r
+/*           value.  It might always be the same as the input value, */\r
+/*           if the DO loop below always executes an even number of times. */\r
+/* Output: (all of them are written on every call) */\r
+/*  ZC     - Zero crossing rate */\r
+/*  LBE    - Low band energy (sum of magnitudes - SM) */\r
+/*  FBE    - Full band energy (SM) */\r
+/*  QS     - Ratio of 6 dB/oct preemphasized energy to full band energy */\r
+/*  RC1    - First reflection coefficient */\r
+/*  AR_B   - Product of the causal forward and reverse pitch */\r
+/*           prediction gains */\r
+/*  AR_F   - Product of the noncausal forward and reverse pitch */\r
+/*           prediction gains */\r
+/* Internal: */\r
+/*  OLDSGN - Previous sign of dithered signal */\r
+/*  VLEN   - Length of voicing window */\r
+/*  START  - Lower address of current half of voicing window */\r
+/*  STOP   - Upper address of current half of voicing window */\r
+/*  E_0    - Energy of LPF speech (sum of squares - SS) */\r
+/*  E_B    - Energy of LPF speech backward one pitch period (SS) */\r
+/*  E_F    - Energy of LPF speech forward one pitch period (SS) */\r
+/*  R_B    - Autocovariance of LPF speech backward one pitch period */\r
+/*  R_F    - Autocovariance of LPF speech forward one pitch period */\r
+/*  LP_RMS - Energy of LPF speech (sum of magnitudes - SM) */\r
+/*  AP_RMS - Energy of all-pass speech (SM) */\r
+/*  E_PRE  - Energy of 6dB preemphasized speech (SM) */\r
+/*  E0AP   - Energy of all-pass speech (SS) */\r
+\r
+/* This subroutine has no local state. */\r
+\r
+/* Subroutine */ int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer \r
+       *buflim, integer *half, real *dither, integer *mintau, integer *zc, \r
+       integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *\r
+       ar_f__)\r
+{\r
+    /* System generated locals */\r
+    integer inbuf_offset, lpbuf_offset, i__1;\r
+    real r__1, r__2;\r
+\r
+    /* Builtin functions */\r
+    double r_sign(real *, real *);\r
+    integer i_nint(real *);\r
+\r
+    /* Local variables */\r
+    integer vlen, stop, i__;\r
+    real e_pre__;\r
+    integer start;\r
+    real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;\r
+\r
+/*       Arguments */\r
+/*       Local variables that need not be saved */\r
+/*   Calculate zero crossings (ZC) and several energy and correlation */\r
+/*   measures on low band and full band speech.  Each measure is taken */\r
+/*   over either the first or the second half of the voicing window, */\r
+/*   depending on the variable HALF. */\r
+    /* Parameter adjustments */\r
+    --vwin;\r
+    --buflim;\r
+    lpbuf_offset = buflim[3];\r
+    lpbuf -= lpbuf_offset;\r
+    inbuf_offset = buflim[1];\r
+    inbuf -= inbuf_offset;\r
+\r
+    /* Function Body */\r
+    lp_rms__ = 0.f;\r
+    ap_rms__ = 0.f;\r
+    e_pre__ = 0.f;\r
+    e0ap = 0.f;\r
+    *rc1 = 0.f;\r
+    e_0__ = 0.f;\r
+    e_b__ = 0.f;\r
+    e_f__ = 0.f;\r
+    r_f__ = 0.f;\r
+    r_b__ = 0.f;\r
+    *zc = 0;\r
+    vlen = vwin[2] - vwin[1] + 1;\r
+    start = vwin[1] + (*half - 1) * vlen / 2 + 1;\r
+    stop = start + vlen / 2 - 1;\r
+\r
+/* I'll use the symbol HVL in the table below to represent the value */\r
+/* VLEN/2.  Note that if VLEN is odd, then HVL should be rounded down, */\r
+/* i.e., HVL = (VLEN-1)/2. */\r
+\r
+/* HALF  START          STOP */\r
+\r
+/* 1     VWIN(1)+1      VWIN(1)+HVL */\r
+/* 2     VWIN(1)+HVL+1  VWIN(1)+2*HVL */\r
+\r
+/* Note that if VLEN is even and HALF is 2, then STOP will be */\r
+/* VWIN(1)+VLEN = VWIN(2)+1.  That could be bad, if that index of INBUF */\r
+/* is undefined. */\r
+\r
+    r__1 = inbuf[start - 1] - *dither;\r
+    oldsgn = r_sign(&c_b2, &r__1);\r
+    i__1 = stop;\r
+    for (i__ = start; i__ <= i__1; ++i__) {\r
+       lp_rms__ += (r__1 = lpbuf[i__], abs(r__1));\r
+       ap_rms__ += (r__1 = inbuf[i__], abs(r__1));\r
+       e_pre__ += (r__1 = inbuf[i__] - inbuf[i__ - 1], abs(r__1));\r
+/* Computing 2nd power */\r
+       r__1 = inbuf[i__];\r
+       e0ap += r__1 * r__1;\r
+       *rc1 += inbuf[i__] * inbuf[i__ - 1];\r
+/* Computing 2nd power */\r
+       r__1 = lpbuf[i__];\r
+       e_0__ += r__1 * r__1;\r
+/* Computing 2nd power */\r
+       r__1 = lpbuf[i__ - *mintau];\r
+       e_b__ += r__1 * r__1;\r
+/* Computing 2nd power */\r
+       r__1 = lpbuf[i__ + *mintau];\r
+       e_f__ += r__1 * r__1;\r
+       r_f__ += lpbuf[i__] * lpbuf[i__ + *mintau];\r
+       r_b__ += lpbuf[i__] * lpbuf[i__ - *mintau];\r
+       r__1 = inbuf[i__] + *dither;\r
+       if (r_sign(&c_b2, &r__1) != oldsgn) {\r
+           ++(*zc);\r
+           oldsgn = -oldsgn;\r
+       }\r
+       *dither = -(*dither);\r
+    }\r
+/*   Normalized short-term autocovariance coefficient at unit sample delay\r
+ */\r
+    *rc1 /= max(e0ap,1.f);\r
+/*  Ratio of the energy of the first difference signal (6 dB/oct preemphas\r
+is)*/\r
+/*   to the energy of the full band signal */\r
+/* Computing MAX */\r
+    r__1 = ap_rms__ * 2.f;\r
+    *qs = e_pre__ / max(r__1,1.f);\r
+/*   aR_b is the product of the forward and reverse prediction gains, */\r
+/*   looking backward in time (the causal case). */\r
+    *ar_b__ = r_b__ / max(e_b__,1.f) * (r_b__ / max(e_0__,1.f));\r
+/*  aR_f is the same as aR_b, but looking forward in time (non causal case\r
+).*/\r
+    *ar_f__ = r_f__ / max(e_f__,1.f) * (r_f__ / max(e_0__,1.f));\r
+/*   Normalize ZC, LBE, and FBE to old fixed window length of 180. */\r
+/*   (The fraction 90/VLEN has a range of .58 to 1) */\r
+    r__2 = (real) (*zc << 1);\r
+    r__1 = r__2 * (90.f / vlen);\r
+    *zc = i_nint(&r__1);\r
+/* Computing MIN */\r
+    r__1 = lp_rms__ / 4 * (90.f / vlen);\r
+    i__1 = i_nint(&r__1);\r
+    *lbe = min(i__1,32767);\r
+/* Computing MIN */\r
+    r__1 = ap_rms__ / 4 * (90.f / vlen);\r
+    i__1 = i_nint(&r__1);\r
+    *fbe = min(i__1,32767);\r
+    return 0;\r
+} /* vparms_ */\r
+\r