[xiph-commits] r10312 - in trunk/speex: . ti ti/speex_C54_test ti/speex_C55_test ti/speex_C64_test

jm at svn.xiph.org jm at svn.xiph.org
Sat Oct 29 06:13:19 PDT 2005


Author: jm
Date: 2005-10-29 06:13:13 -0700 (Sat, 29 Oct 2005)
New Revision: 10312

Added:
   trunk/speex/ti/
   trunk/speex/ti/README.TI-DSP
   trunk/speex/ti/config.h
   trunk/speex/ti/speex_C54_test/
   trunk/speex/ti/speex_C54_test/speex_C54_test.cmd
   trunk/speex/ti/speex_C54_test/speex_C54_test.pjt
   trunk/speex/ti/speex_C55_test/
   trunk/speex/ti/speex_C55_test/speex_C55_test.cmd
   trunk/speex/ti/speex_C55_test/speex_C55_test.pjt
   trunk/speex/ti/speex_C64_test/
   trunk/speex/ti/speex_C64_test/speex_C64_test.cmd
   trunk/speex/ti/speex_C64_test/speex_C64_test.pjt
   trunk/speex/ti/testenc-TI-C5x.c
   trunk/speex/ti/testenc-TI-C64x.c
   trunk/speex/ti/user_misc.h
Log:
TI DSP (C5x and C6x) patch by Jim Crichton


Added: trunk/speex/ti/README.TI-DSP
===================================================================
--- trunk/speex/ti/README.TI-DSP	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/README.TI-DSP	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,56 @@
+These are all of the changes and additions necessary to build a loopback application for the 
+TI C6415, C5509A, or C5416 simulators using the TI Code Composer Studio (CCS) development system.  
+A trial version of the tools can be downloaded from the TI website.
+
+This build runs 8kbps narrowband, with minimum complexity.
+
+Several changes are introduced in Speex 1.1.11 which are used in these applications:
+
+arch.h: Added switch for compilers not supporting "long long" (C55x does, C54x, CCS 2.x C64x does not)
+bits.c: Allow external definition for max buffer size, changed MAX_BYTES_PER_FRAME
+        to MAX_CHARS_PER_FRAME for consistency
+misc.c: Added override switches to alloc routines, conditional include of user file "user_misc.h".
+        These changes allow manual memory allocation rather than using heap
+
+The arch.h change allows operation with 2.x versions of Code Composer Studio.
+The bits.c change reduces the data memory usage.
+The misc.c change allows private memory allocation, for cases where it is not
+desirable to use the normal heap.
+
+Added files:
+
+testenc-TI-C5x.c  (For C54x and C55x builds, derived from testenc.c, 
+                       manual alloc, byte packing/unpacking added)
+testenc-TI-C64x.c  (For C64x builds, derived from testenc.c, manual alloc, byte packing/unpacking added)
+
+config.h (not automatically generated, sets memory sizes, enables/disables manual alloc)
+user_misc.h (contains the manual memory alloc routines, with debug code to display mem usage)
+speex\speex_config_types.h (match Speex types to compiler types, not generated from types.in)
+
+speex_c54_test\speex_c54_test.cmd (C5416 linker command file)
+speex_c54_test\speex_c54_test.pjt (Code Composer Studio Project File )
+speex_c55_test\speex_c55_test.cmd (C5509A linker command file)
+speex_c55_test\speex_c55_test.pjt (Code Composer Studio Project File )
+speex_c64_test\speex_c64_test.cmd (C6415 linker command file)
+speex_c64_test\speex_c64_test.pjt (Code Composer Studio Project File )
+
+samples\male.snd  
+
+Usage:
+1. Create a Speex 1.1.11 (or later) source tree.
+2. Edit the files testenc-TI-C5x.c and/or testenc-TI-C64x.c to change the hard-coded path 
+   for the test audio and data files.
+   This build uses the file e:\speextrunktest\samples\male.snd.
+   Note:  This is a headerless 16-bit stereo audio file derived from the male.wav test file 
+          http://www.speex.org/samples/male.wav
+3. Edit the .pjt file with a text editor and change projdir or projectdir to the correct path 
+   (one place near the top of the file).
+4. Edit config.h if desired, to change the memory allocation method (calloc or manual),
+   and to enable/disable debug prints for the memory allocation 
+   (this makes it easier to determine the required size).
+5. Run Code Composer Studio, and open the project for the desired target (e.g. speex_c55_test).
+   Note that the correct simulator must be selected (in CCS Setup) before starting CCS.
+6. Build and run the simulation.
+
+Note that assembly optimizations will be required to run C54x in real time.
+There are no assembly optimizations in any of these builds.

Added: trunk/speex/ti/config.h
===================================================================
--- trunk/speex/ti/config.h	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/config.h	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,73 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   File: config.h
+   Main Speex option include file for TI C64xx, C54xx and C55xx processors
+   for use with TI Code Composer (TM) DSP development tools.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define FIXED_POINT
+#define FRAME_SIZE 160
+#define DISABLE_WIDEBAND
+
+/* Allow for 2 20ms narrowband blocks per frame, plus a couple of bytes */
+#define MAX_CHARS_PER_FRAME (42/BYTES_PER_CHAR)
+
+/* for debug */
+#undef DECODE_ONLY
+
+/* EITHER    Allocate from fixed array (C heap not used) */
+/*           Enable VERBOSE_ALLOC to see how much is used */
+#define MANUAL_ALLOC
+#define USER_MISC
+#define VERBOSE_ALLOC
+/* OR        Use CALLOC (heap size must be increased in linker command file) */
+//#undef MANUAL_ALLOC
+//#undef USER_MISC
+
+#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 
+//#define PRECISION16
+
+// These values determined by analysis for 8kbps narrowband
+#define SPEEXENC_PERSIST_STACK_SIZE 5000
+#define SPEEXENC_SCRATCH_STACK_SIZE 3000
+#define SPEEXDEC_PERSIST_STACK_SIZE 2500
+#define SPEEXDEC_SCRATCH_STACK_SIZE 1000
+#else /* C6X */
+#define NO_LONGLONG
+
+#define SPEEXENC_PERSIST_STACK_SIZE 10000
+#define SPEEXENC_SCRATCH_STACK_SIZE 6000
+#define SPEEXDEC_PERSIST_STACK_SIZE 5000
+#define SPEEXDEC_SCRATCH_STACK_SIZE 2000
+#endif
+#define SPEEX_PERSIST_STACK_SIZE (SPEEXENC_PERSIST_STACK_SIZE + SPEEXDEC_PERSIST_STACK_SIZE)
+#define SPEEX_SCRATCH_STACK_SIZE SPEEXENC_SCRATCH_STACK_SIZE
+#define NB_ENC_STACK SPEEXENC_SCRATCH_STACK_SIZE
+#define NB_DEC_STACK SPEEXDEC_SCRATCH_STACK_SIZE
+

Added: trunk/speex/ti/speex_C54_test/speex_C54_test.cmd
===================================================================
--- trunk/speex/ti/speex_C54_test/speex_C54_test.cmd	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C54_test/speex_C54_test.cmd	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,71 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   File: speex_C54_test.cmd
+   Linker command file with memory allocation for TI TMS320VC5416 processor
+   for use with TI Code Composer (TM) DSP development tools.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+-c
+-stack 0x2000
+-heap 0x1000	/* If private memory allocation is used for Speex */
+/*-heap 0x6000	/* If calloc is used for Speex */
+-lrts_ext.lib
+
+MEMORY
+{
+/*   PAGE 0:   P_DARAM03:  origin = 0x80,          len = 0x7f00*/
+   PAGE 0:   P_DARAM03:  origin = 0x5000,          len = 0x2f80
+   PAGE 0:   VECT:       origin = 0x7f80,        len = 0x80
+   PAGE 0:   P_DARAM47:  origin = 0x18000,       len = 0x8000
+   PAGE 0:   SARAM03:    origin = 0x28000,       len = 0x8000
+   PAGE 0:   SARAM47:    origin = 0x38000,       len = 0x8000
+
+   PAGE 1:   USERREGS:   origin = 0x60,          len = 0x1a
+   PAGE 1:   BIOSREGS:   origin = 0x7c,          len = 0x4
+   PAGE 1:   CSLREGS:    origin = 0x7a,          len = 0x2
+            D_DARAM03:  origin = 0x80,          len = 0x4f80
+            D_DARAM47:  origin = 0x8000,        len = 0x8000
+}
+
+SECTIONS
+{
+    .vectors: {} > VECT PAGE 0
+    .bootmem: {rts_ext.lib (.text)} > P_DARAM03 PAGE 0 
+/*    .bootmem: {} > P_DARAM03 PAGE 0 */
+    .text:    {} > SARAM03 PAGE 0
+    .cinit:   {} > SARAM03 PAGE 0
+    .switch:  {} > SARAM03 PAGE 0
+    .bss:     {} > D_DARAM03 | D_DARAM47 PAGE 1
+    .far:     {} > D_DARAM03 | D_DARAM47  PAGE 1
+    .const:   {} > D_DARAM03 | D_DARAM47  PAGE 1
+    .sysmem:  {} > D_DARAM47 PAGE 1
+    .cio:     {} > D_DARAM03 | D_DARAM47  PAGE 1
+    .stack:   {} > D_DARAM03 | D_DARAM47  PAGE 1
+    .myheap:   {} > D_DARAM47 PAGE 1
+}

Added: trunk/speex/ti/speex_C54_test/speex_C54_test.pjt
===================================================================
--- trunk/speex/ti/speex_C54_test/speex_C54_test.pjt	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C54_test/speex_C54_test.pjt	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,59 @@
+; Code Composer Project File, Version 2.0 (do not modify or remove this line)
+
+[Project Settings]
+ProjectDir="C:\speextrunktest\ti\speex_C54_test\"
+ProjectType=Executable
+CPUFamily=TMS320C54XX
+Tool="Compiler"
+Tool="DspBiosBuilder"
+Tool="Linker"
+Config="Debug"
+Config="Release"
+
+[Source Files]
+Source="..\..\libspeex\bits.c"
+Source="..\..\libspeex\cb_search.c"
+Source="..\..\libspeex\exc_10_16_table.c"
+Source="..\..\libspeex\exc_10_32_table.c"
+Source="..\..\libspeex\exc_20_32_table.c"
+Source="..\..\libspeex\exc_5_256_table.c"
+Source="..\..\libspeex\exc_5_64_table.c"
+Source="..\..\libspeex\exc_8_128_table.c"
+Source="..\..\libspeex\filters.c"
+Source="..\..\libspeex\gain_table.c"
+Source="..\..\libspeex\gain_table_lbr.c"
+Source="..\..\libspeex\lpc.c"
+Source="..\..\libspeex\lsp.c"
+Source="..\..\libspeex\lsp_tables_nb.c"
+Source="..\..\libspeex\ltp.c"
+Source="..\..\libspeex\math_approx.c"
+Source="..\..\libspeex\misc.c"
+Source="..\..\libspeex\modes.c"
+Source="..\..\libspeex\nb_celp.c"
+Source="..\..\libspeex\quant_lsp.c"
+Source="..\..\libspeex\sb_celp.c"
+Source="..\..\libspeex\speex.c"
+Source="..\..\libspeex\speex_callbacks.c"
+Source="..\..\libspeex\vbr.c"
+Source="..\..\libspeex\vq.c"
+Source="..\..\ti\testenc-TI-C5x.c"
+Source="speex_C54_test.cmd"
+
+["Compiler" Settings: "Debug"]
+Options=-g -q -o3 -fr"..\ti\speex_C54_test\Debug" -i"..\ti" -i"..\include" -d"_DEBUG" -d"CONFIG_TI_C55X" -d"CONFIG_TI_C54X" -d"HAVE_CONFIG_H" -d"NO_LONGLONG" -mf -ms
+
+["Compiler" Settings: "Release"]
+Options=-q -o2 -fr"..\ti\speex_C54_test\Release" -i"..\ti" -i"..\include" -d"CONFIG_TI_C55X" -d"HAVE_CONFIG_H" -d"NO_LONGLONG" -mf -ms
+
+["DspBiosBuilder" Settings: "Debug"]
+Options=-v54
+
+["DspBiosBuilder" Settings: "Release"]
+Options=-v54
+
+["Linker" Settings: "Debug"]
+Options=-q -c -heap4096 -m".\Debug\speex_C54_test.map" -o".\Debug\speex_C54_test.out" -stack4096 -w -x
+
+["Linker" Settings: "Release"]
+Options=-q -c -m".\Release\speex_C54_test.map" -o".\Release\speex_C54_test.out" -w -x
+

Added: trunk/speex/ti/speex_C55_test/speex_C55_test.cmd
===================================================================
--- trunk/speex/ti/speex_C55_test/speex_C55_test.cmd	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C55_test/speex_C55_test.cmd	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,65 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   File: speex_C55_test.cmd
+   Linker command file with memory allocation for TI TMS320VC5509A processor
+   for use with TI Code Composer (TM) DSP development tools.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+-c
+-stack 0x1c00
+-heap 0x1000	/* If private memory allocation is used for Speex */
+/*-heap 0x6000	/ * If calloc is used for Speex */
+-sysstack 0x200
+-lrts55.lib
+
+MEMORY
+{
+   DARAM:      origin = 0x200,         len = 0x7e00
+   DARAM_B:    origin = 0x8000,        len = 0x8000
+   VECT:       origin = 0x100,         len = 0x100
+   SARAM_A:    origin = 0x10000,       len = 0x10000
+   SARAM_B:    origin = 0x20000,       len = 0x20000
+}
+
+SECTIONS
+{
+    .vectors: {} > VECT
+    .bootmem: {} > DARAM
+    .text:    {} > SARAM_B
+    .cinit:   {} > SARAM_B
+    .switch:  {} > SARAM_B
+    .bss:     {} > DARAM
+/*    .far:     {} > DARAM*/
+    .const:   {} > DARAM
+    .sysmem:  {} > DARAM_B
+    .cio:     {} > DARAM
+    .stack:   {} > DARAM
+    .sysstack:   {} > DARAM
+    .myheap:   {} > SARAM_A
+}

Added: trunk/speex/ti/speex_C55_test/speex_C55_test.pjt
===================================================================
--- trunk/speex/ti/speex_C55_test/speex_C55_test.pjt	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C55_test/speex_C55_test.pjt	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,59 @@
+; Code Composer Project File, Version 2.0 (do not modify or remove this line)
+
+[Project Settings]
+ProjectDir="C:\speextrunktest\ti\speex_C55_test\"
+ProjectType=Executable
+CPUFamily=TMS320C55XX
+Tool="Compiler"
+Tool="DspBiosBuilder"
+Tool="Linker"
+Config="Debug"
+Config="Release"
+
+[Source Files]
+Source="..\..\libspeex\bits.c"
+Source="..\..\libspeex\cb_search.c"
+Source="..\..\libspeex\exc_10_16_table.c"
+Source="..\..\libspeex\exc_10_32_table.c"
+Source="..\..\libspeex\exc_20_32_table.c"
+Source="..\..\libspeex\exc_5_256_table.c"
+Source="..\..\libspeex\exc_5_64_table.c"
+Source="..\..\libspeex\exc_8_128_table.c"
+Source="..\..\libspeex\filters.c"
+Source="..\..\libspeex\gain_table.c"
+Source="..\..\libspeex\gain_table_lbr.c"
+Source="..\..\libspeex\lpc.c"
+Source="..\..\libspeex\lsp.c"
+Source="..\..\libspeex\lsp_tables_nb.c"
+Source="..\..\libspeex\ltp.c"
+Source="..\..\libspeex\math_approx.c"
+Source="..\..\libspeex\misc.c"
+Source="..\..\libspeex\modes.c"
+Source="..\..\libspeex\nb_celp.c"
+Source="..\..\libspeex\quant_lsp.c"
+Source="..\..\libspeex\sb_celp.c"
+Source="..\..\libspeex\speex.c"
+Source="..\..\libspeex\speex_callbacks.c"
+Source="..\..\libspeex\vbr.c"
+Source="..\..\libspeex\vq.c"
+Source="..\..\ti\testenc-TI-C5x.c"
+Source="speex_C55_test.cmd"
+
+["Compiler" Settings: "Debug"]
+Options=-g -q -o3 -fr"..\ti\speex_C55_test\Debug" -i"..\ti" -i"..\include" -d"_DEBUG" -d"CONFIG_TI_C55X" -d"HAVE_CONFIG_H" -mn
+
+["Compiler" Settings: "Release"]
+Options=-q -o2 -fr"..\ti\speex_C55_test\Release" -i"..\ti" -i"..\include" -d"CONFIG_TI_C55X" -d"HAVE_CONFIG_H" -mn
+
+["DspBiosBuilder" Settings: "Debug"]
+Options=-v55
+
+["DspBiosBuilder" Settings: "Release"]
+Options=-v55
+
+["Linker" Settings: "Debug"]
+Options=-q -c -m".\Debug\speex_C55_test.map" -o".\Debug\speex_C55_test.out" -w -x
+
+["Linker" Settings: "Release"]
+Options=-q -c -m".\Release\speex_C55_test.map" -o".\Release\speex_C55_test.out" -w -x
+

Added: trunk/speex/ti/speex_C64_test/speex_C64_test.cmd
===================================================================
--- trunk/speex/ti/speex_C64_test/speex_C64_test.cmd	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C64_test/speex_C64_test.cmd	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,59 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   File: speex_C64_test.cmd
+   Linker command file with memory allocation for TI TMS320C6415 processor
+   for use with TI Code Composer (TM) DSP development tools.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+-stack 0x10000
+-heap 0x10000
+
+
+MEMORY 
+{
+   VECRAM       : origin = 0x0,         len = 0x200
+   IPRAM       : origin = 0x200,         len = 0x40000
+   IDRAM       : origin = 0x80000,  len = 0x70000
+}
+
+SECTIONS
+{
+        .vectors > VECRAM
+        .text    > IPRAM
+
+        .bss     > IDRAM
+        .cinit   > IDRAM
+        .const   > IDRAM
+        .far     > IDRAM
+        .stack   > IDRAM
+        .cio     > IDRAM
+        .sysmem  > IDRAM
+        .switch  > IDRAM
+        .myheap  > IDRAM
+}

Added: trunk/speex/ti/speex_C64_test/speex_C64_test.pjt
===================================================================
--- trunk/speex/ti/speex_C64_test/speex_C64_test.pjt	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/speex_C64_test/speex_C64_test.pjt	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,59 @@
+; Code Composer Project File, Version 2.0 (do not modify or remove this line)
+
+[Project Settings]
+ProjectDir="E:\speextrunktest\ti\speex_C64_test\"
+ProjectType=Executable
+CPUFamily=TMS320C64XX
+Tool="Compiler"
+Tool="DspBiosBuilder"
+Tool="Linker"
+Config="Debug"
+Config="Release"
+
+[Source Files]
+Source="..\..\libspeex\bits.c"
+Source="..\..\libspeex\cb_search.c"
+Source="..\..\libspeex\exc_10_16_table.c"
+Source="..\..\libspeex\exc_10_32_table.c"
+Source="..\..\libspeex\exc_20_32_table.c"
+Source="..\..\libspeex\exc_5_256_table.c"
+Source="..\..\libspeex\exc_5_64_table.c"
+Source="..\..\libspeex\exc_8_128_table.c"
+Source="..\..\libspeex\filters.c"
+Source="..\..\libspeex\gain_table.c"
+Source="..\..\libspeex\gain_table_lbr.c"
+Source="..\..\libspeex\lpc.c"
+Source="..\..\libspeex\lsp.c"
+Source="..\..\libspeex\lsp_tables_nb.c"
+Source="..\..\libspeex\ltp.c"
+Source="..\..\libspeex\math_approx.c"
+Source="..\..\libspeex\misc.c"
+Source="..\..\libspeex\modes.c"
+Source="..\..\libspeex\nb_celp.c"
+Source="..\..\libspeex\quant_lsp.c"
+Source="..\..\libspeex\sb_celp.c"
+Source="..\..\libspeex\speex.c"
+Source="..\..\libspeex\speex_callbacks.c"
+Source="..\..\libspeex\vbr.c"
+Source="..\..\libspeex\vq.c"
+Source="..\testenc-TI-C64x.c"
+Source="C:\ti\c6000\cgtools\lib\rts6400.lib"
+Source="speex_C64_test.cmd"
+
+["Compiler" Settings: "Debug"]
+Options=-g -o3 -fr"$(Proj_dir)\Debug" -i"..\ti" -i"..\include" -d"_DEBUG" -d"HAVE_CONFIG_H" -mv6400
+
+["Compiler" Settings: "Release"]
+Options=-o3 -fr"$(Proj_dir)\Release" -i"..\ti" -i"..\include"  -i"..\" -i"..\..\include" -d"HAVE_CONFIG_H" -mv6400
+
+["DspBiosBuilder" Settings: "Debug"]
+Options=-v6x
+
+["DspBiosBuilder" Settings: "Release"]
+Options=-v6x
+
+["Linker" Settings: "Debug"]
+Options=-c -m".\Debug\speex_C64_test.map" -o".\Debug\speex_C64_test.out" -w -x
+
+["Linker" Settings: "Release"]
+Options=-c -m".\Release\speex_C64_test.map" -o".\Release\speex_C64_test.out" -w -x

Added: trunk/speex/ti/testenc-TI-C5x.c
===================================================================
--- trunk/speex/ti/testenc-TI-C5x.c	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/testenc-TI-C5x.c	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,265 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   File: testenc-TI-C5x.c
+   Encoder/Decoder Loop Main file for TI C54xx and C55xx processors
+   for use with TI Code Composer (TM) DSP development tools.
+   Modified from speexlib/testenc.c
+
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Modified from speexlib/testenc.c for Code Composer simulator */
+
+#include <speex/speex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <speex/speex_callbacks.h>
+#include <..\libspeex\arch.h>
+
+#undef DECODE_ONLY
+
+#ifdef FIXED_DEBUG
+extern long long spx_mips;
+#endif
+#include <math.h>
+
+#ifdef MANUAL_ALLOC
+#pragma DATA_SECTION(spxHeap, ".myheap"); 
+static char spxHeap[SPEEX_PERSIST_STACK_SIZE];
+
+#pragma DATA_SECTION(spxScratch, ".myheap"); 
+static char spxScratch[SPEEX_SCRATCH_STACK_SIZE];
+
+char *spxGlobalHeapPtr, *spxGlobalHeapEnd;
+char *spxGlobalScratchPtr, *spxGlobalScratchEnd;
+#endif
+
+void byte2word(short* pInBuf, short* pOutBuf, int nWords)
+{
+   short *pIn, *pOut, sNext;
+   int i;
+   
+   pIn = pInBuf;
+   pOut = pOutBuf;
+   for(i=0;i<nWords;i++)
+   {
+      sNext = *pIn++;			// Get low byte
+      *pOut++ = (sNext & 0x00ff) | (*pIn++ << 8);	// insert high byte
+   }
+}
+   
+void word2byte(short* pInBuf, short* pOutBuf, int nWords)
+{
+   short *pIn, *pOut;
+   int i;
+   
+   pIn = pInBuf;
+   pOut = pOutBuf;
+   for(i=0;i<nWords;i++)
+   {
+      *pOut++ = *pIn & 0x00ff;	// Get low byte
+      *pOut++ = (short) ((unsigned short) *pIn++ >> 8);
+   }
+}
+   
+void main()
+{
+   char *outFile, *bitsFile;
+   FILE *fout, *fbits=NULL;
+#ifndef DECODE_ONLY
+   char *inFile;
+   FILE *fin;
+#endif
+   short out_short[FRAME_SIZE];
+   short inout_byte[2*FRAME_SIZE];
+#ifndef DECODE_ONLY
+   short in_short[FRAME_SIZE];
+   float sigpow,errpow,snr, seg_snr=0;
+   int snr_frames = 0;
+   int nbChars;
+   int i;
+#endif
+   char cbits[22];
+   void *st;
+   void *dec;
+   SpeexBits bits;
+   int tmp;
+   unsigned int bitCount=0;
+   int skip_group_delay;
+   SpeexCallback callback;
+
+   /* C54xx defaults to max wait states, even for parts like C5416 with 
+      larger internal memory.  Need to force the wait state register to zero */
+
+#ifdef CONFIG_TI_C54X
+   asm("	STM	#0,SWWSR");
+#endif
+
+#ifndef DECODE_ONLY
+   sigpow = 0;
+   errpow = 0;
+#endif
+
+#ifdef MANUAL_ALLOC
+	spxGlobalHeapPtr = spxHeap;
+	spxGlobalHeapEnd = spxHeap + sizeof(spxHeap);
+
+	spxGlobalScratchPtr = spxScratch;
+	spxGlobalScratchEnd = spxScratch + sizeof(spxScratch);
+#endif
+   st = speex_encoder_init(&speex_nb_mode);
+#ifdef MANUAL_ALLOC
+	spxGlobalScratchPtr = spxScratch;		/* Reuse scratch for decoder */
+#endif
+   dec = speex_decoder_init(&speex_nb_mode);
+
+   callback.callback_id = SPEEX_INBAND_CHAR;
+   callback.func = speex_std_char_handler;
+   callback.data = stderr;
+   speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
+   callback.callback_id = SPEEX_INBAND_MODE_REQUEST;
+   callback.func = speex_std_mode_request_handler;
+   callback.data = st;
+   speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
+   tmp=0;
+   speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
+   tmp=0;
+   speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
+   tmp=4;
+   speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
+   tmp=1;
+   speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
+
+   speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
+   fprintf (stderr, "frame size: %d\n", tmp);
+   skip_group_delay = tmp / 2;
+
+#ifdef DECODE_ONLY
+   bitsFile = "c:\\speextrunktest\\samples\\malebitsin5x.dat";
+   fbits = fopen(bitsFile, "rb");
+#else
+   bitsFile = "c:\\speextrunktest\\samples\\malebits.dat";
+   fbits = fopen(bitsFile, "wb");
+#endif
+   inFile = "c:\\speextrunktest\\samples\\male.snd";
+   fin = fopen(inFile, "rb");
+   outFile = "c:\\speextrunktest\\samples\\maleout.snd";
+   fout = fopen(outFile, "wb+");
+ 
+   speex_bits_init(&bits);
+#ifndef DECODE_ONLY
+   while (!feof(fin))
+   {
+      fread(inout_byte, 2, FRAME_SIZE, fin);
+      byte2word(inout_byte, in_short, FRAME_SIZE);  /* C5x has 16-bit char */
+
+      if (feof(fin))
+         break;
+      speex_bits_reset(&bits);
+
+      speex_encode_int(st, in_short, &bits);
+      nbChars = speex_bits_write(&bits, cbits, sizeof(cbits))/BYTES_PER_CHAR;
+      bitCount+=bits.nbBits;
+
+      word2byte((short *) cbits, inout_byte, nbChars);
+      fwrite(inout_byte, 2, nbChars, fbits);
+      speex_bits_rewind(&bits);
+
+#else /* DECODE_ONLY */
+   while (!feof(fbits))
+   {
+      fread(inout_byte, 1, 20, fbits);
+
+      if (feof(fbits))
+         break;
+
+      byte2word(inout_byte, (short *)cbits, 10);
+      speex_bits_read_from(&bits, cbits, 20);
+      bitCount+=160;
+#endif
+      speex_decode_int(dec, &bits, out_short);
+      speex_bits_reset(&bits);
+
+      word2byte(&out_short[skip_group_delay], inout_byte, FRAME_SIZE-skip_group_delay);
+      fwrite(inout_byte, 2, FRAME_SIZE-skip_group_delay, fout);
+      skip_group_delay = 0;
+#if 1
+   fprintf (stderr, "Bits so far: %u \n", bitCount);
+#endif
+   }
+   fprintf (stderr, "Total encoded size: %u bits\n", bitCount);
+   speex_encoder_destroy(st);
+   speex_decoder_destroy(dec);
+
+#ifndef DECODE_ONLY
+   rewind(fin);
+   rewind(fout);
+
+//   while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) 
+//           &&
+//           FRAME_SIZE ==  fread(out_short, sizeof(short), FRAME_SIZE,fout) )
+   while ( bitCount > 0 )
+   {
+	float s=0, e=0;
+
+    fread(inout_byte, 2, FRAME_SIZE, fin);
+    byte2word(inout_byte, in_short, FRAME_SIZE);
+    fread(inout_byte, 2, FRAME_SIZE, fout);
+    byte2word(inout_byte, out_short, FRAME_SIZE);
+
+    bitCount -= FRAME_SIZE;
+        for (i=0;i<FRAME_SIZE;++i) {
+            s += (float)in_short[i] * in_short[i];
+            e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]);
+        }
+	seg_snr += 10*log10((s+160)/(e+160));
+	sigpow += s;
+	errpow += e;
+	snr_frames++;
+   }
+   fclose(fin);
+#endif
+   fclose(fout);
+   fclose(fbits);
+
+#ifndef DECODE_ONLY
+   snr = 10 * log10( sigpow / errpow );
+   seg_snr /= snr_frames;
+   fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr);
+
+#ifdef FIXED_DEBUG
+   printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames));
+#endif
+#endif   
+}

Added: trunk/speex/ti/testenc-TI-C64x.c
===================================================================
--- trunk/speex/ti/testenc-TI-C64x.c	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/testenc-TI-C64x.c	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,224 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   Author:  Jean-Marc Valin 
+   File: testenc-TI-C64x.c
+   Encoder/Decoder Loop Main file for TI TMS320C64xx processor
+   for use with TI Code Composer (TM) DSP development tools.
+   Modified from speexlib/testenc.c
+
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <speex/speex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <speex/speex_callbacks.h>
+
+#ifdef FIXED_DEBUG
+extern long long spx_mips;
+#endif
+
+#ifdef MANUAL_ALLOC
+#pragma DATA_SECTION(spxHeap, ".myheap"); 
+static char spxHeap[SPEEX_PERSIST_STACK_SIZE];
+
+#pragma DATA_SECTION(spxScratch, ".myheap"); 
+static char spxScratch[SPEEX_SCRATCH_STACK_SIZE];
+
+char *spxGlobalHeapPtr, *spxGlobalHeapEnd;
+char *spxGlobalScratchPtr, *spxGlobalScratchEnd;
+#endif    /* MANUAL_ALLOC */
+
+#include <math.h>
+void main()
+{
+   char *outFile, *bitsFile;
+   FILE *fout, *fbits=NULL;
+#ifndef DECODE_ONLY
+   char *inFile;
+   FILE *fin;
+#endif
+#if 0
+   char *dbgoutFile;
+   FILE *fdbgout;
+#endif
+   short out_short[FRAME_SIZE];
+#ifndef DECODE_ONLY
+   short in_short[FRAME_SIZE];
+   float sigpow,errpow,snr, seg_snr=0;
+   int snr_frames = 0;
+   int nbBits;
+   int i;
+#endif
+   char cbits[200];
+   void *st;
+   void *dec;
+   SpeexBits bits;
+   int tmp;
+   int bitCount=0;
+   int skip_group_delay;
+   SpeexCallback callback;
+
+#ifndef DECODE_ONLY
+   sigpow = 0;
+   errpow = 0;
+#endif
+
+#ifdef MANUAL_ALLOC
+	spxGlobalHeapPtr = spxHeap;
+	spxGlobalHeapEnd = spxHeap + sizeof(spxHeap);
+
+	spxGlobalScratchPtr = spxScratch;
+	spxGlobalScratchEnd = spxScratch + sizeof(spxScratch);
+#endif
+   st = speex_encoder_init(&speex_nb_mode);
+#ifdef MANUAL_ALLOC
+	spxGlobalScratchPtr = spxScratch;		/* Reuse scratch for decoder */
+#endif
+   dec = speex_decoder_init(&speex_nb_mode);
+
+   callback.callback_id = SPEEX_INBAND_CHAR;
+   callback.func = speex_std_char_handler;
+   callback.data = stderr;
+   speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
+   callback.callback_id = SPEEX_INBAND_MODE_REQUEST;
+   callback.func = speex_std_mode_request_handler;
+   callback.data = st;
+   speex_decoder_ctl(dec, SPEEX_SET_HANDLER, &callback);
+
+   tmp=0;
+   speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
+   tmp=0;
+   speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
+   tmp=4;
+   speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
+   tmp=1;
+   speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
+
+   speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
+   fprintf (stderr, "frame size: %d\n", tmp);
+   skip_group_delay = tmp / 2;
+
+#ifdef DECODE_ONLY
+   bitsFile = "e:\\speextrunktest\\samples\\malebitsin54.dat";
+   fbits = fopen(bitsFile, "rb");
+#else
+   bitsFile = "e:\\speextrunktest\\samples\\malebits.dat";
+   fbits = fopen(bitsFile, "wb");
+#endif
+   inFile = "e:\\speextrunktest\\samples\\male.snd";
+   fin = fopen(inFile, "rb");
+   outFile = "e:\\speextrunktest\\samples\\maleout.snd";
+   fout = fopen(outFile, "wb+");
+#if 0
+   dbgoutFile = "e:\\speextrunktest\\samples\\maledbgout.snd";
+   fdbgout = fopen(dbgoutFile, "wb+");
+#endif
+ 
+   speex_bits_init(&bits);
+#ifndef DECODE_ONLY
+   while (!feof(fin))
+   {
+      fread(in_short, sizeof(short), FRAME_SIZE, fin);
+#if 0
+      fwrite(in_short, sizeof(short), FRAME_SIZE, fdbgout);
+#endif
+      if (feof(fin))
+         break;
+      speex_bits_reset(&bits);
+
+      speex_encode_int(st, in_short, &bits);
+      nbBits = speex_bits_write(&bits, cbits, 200);
+      bitCount+=bits.nbBits;
+
+      fwrite(cbits, 1, nbBits, fbits);
+      speex_bits_rewind(&bits);
+
+#else /* DECODE_ONLY */
+   while (!feof(fbits))
+   {
+      fread(cbits, 1, 20, fbits);
+
+      if (feof(fbits))
+         break;
+
+      speex_bits_read_from(&bits, cbits, 20);
+      bitCount+=160;
+#endif
+      
+      speex_decode_int(dec, &bits, out_short);
+      speex_bits_reset(&bits);
+
+      fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
+      skip_group_delay = 0;
+#if 1
+   fprintf (stderr, "Bits so far: %d \n", bitCount);
+#endif
+   }
+   fprintf (stderr, "Total encoded size: %d bits\n", bitCount);
+   speex_encoder_destroy(st);
+   speex_decoder_destroy(dec);
+
+#ifndef DECODE_ONLY
+   rewind(fin);
+   rewind(fout);
+
+   while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) 
+           &&
+           FRAME_SIZE ==  fread(out_short, sizeof(short), FRAME_SIZE,fout) )
+   {
+	float s=0, e=0;
+        for (i=0;i<FRAME_SIZE;++i) {
+            s += (float)in_short[i] * in_short[i];
+            e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]);
+        }
+	seg_snr += 10*log10((s+160)/(e+160));
+	sigpow += s;
+	errpow += e;
+	snr_frames++;
+   }
+   fclose(fin);
+#endif
+   fclose(fout);
+   fclose(fbits);
+
+#ifndef DECODE_ONLY
+   snr = 10 * log10( sigpow / errpow );
+   seg_snr /= snr_frames;
+   fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr);
+
+#ifdef FIXED_DEBUG
+   printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames));
+#endif
+#endif   
+}

Added: trunk/speex/ti/user_misc.h
===================================================================
--- trunk/speex/ti/user_misc.h	2005-10-29 05:15:35 UTC (rev 10311)
+++ trunk/speex/ti/user_misc.h	2005-10-29 13:13:13 UTC (rev 10312)
@@ -0,0 +1,127 @@
+/* Copyright (C) 2005 Psi Systems, Inc.
+   Author:  Jean-Marc Valin 
+   File: user_misc.h
+   Memory Allocation overrides to allow user control rather than C alloc/free.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef MANUAL_ALLOC
+
+/* To avoid changing the Speex call model, this file relies on four static variables 
+   The user main creates two linear buffers, and initializes spxGlobalHeap/ScratchPtr 
+   to point to the start of the two buffers, and initializes spxGlobalHeap/ScratchEnd 
+   to point to the first address following the last byte of the two buffers.
+   
+   This mechanism allows, for example, data caching for multichannel applications, 
+   where the Speex state is swapped from a large slow memory to a small fast memory 
+   each time the codec runs.
+   
+   Persistent data is allocated in spxGlobalHeap (instead of calloc), while scratch
+   data is allocated in spxGlobalScratch.
+*/
+
+extern char *spxGlobalHeapPtr, *spxGlobalHeapEnd; 
+extern char *spxGlobalScratchPtr, *spxGlobalScratchEnd;
+
+/* Make sure that all structures are aligned to largest type */
+#define BLOCK_MASK      (sizeof(long double)-1)
+
+#define OVERRIDE_SPEEX_ALLOC
+void *speex_alloc (int size)
+{
+    void *ptr;
+    
+    ptr = (void *) (((int)spxGlobalHeapPtr + BLOCK_MASK) & ~BLOCK_MASK);  //Start on 8 boundary
+
+    spxGlobalHeapPtr = (char *)((int)ptr + size);	// Update pointer to next free location
+
+    if (spxGlobalHeapPtr > spxGlobalHeapEnd ) 
+    {
+#ifdef VERBOSE_ALLOC
+	    fprintf (stderr, "insufficient space for persistent alloc request %d bytes\n", size);
+#endif
+       return 0;
+    }
+   
+#ifdef VERBOSE_ALLOC
+    fprintf (stderr, "Persist Allocated %d chars at %x, %d remaining\n", size, ptr, ((int)spxGlobalHeapEnd - (int)spxGlobalHeapPtr));
+#endif
+    memset(ptr, 0, size);
+    return ptr;
+}
+
+#define OVERRIDE_SPEEX_ALLOC_SCRATCH
+void *speex_alloc_scratch (int size)
+{
+    void *ptr;
+
+    ptr = (void *) (((int)spxGlobalScratchPtr + BLOCK_MASK) & ~BLOCK_MASK);  //Start on 8 boundary
+
+    spxGlobalScratchPtr = (char *)((int)ptr + size);	// Update pointer to next free location
+
+    if (spxGlobalScratchPtr > spxGlobalScratchEnd ) 
+    {
+#ifdef VERBOSE_ALLOC
+	    fprintf (stderr, "insufficient space for scratch alloc request %d bytes\n", size);
+#endif
+       return 0;
+    }
+   
+#ifdef VERBOSE_ALLOC
+    fprintf (stderr, "Scratch Allocated %d chars at %x, %d remaining\n", size, ptr, ((int)spxGlobalScratchEnd - (int)spxGlobalScratchPtr));
+#endif
+    memset(ptr, 0, size);
+    return ptr;
+}
+
+#define OVERRIDE_SPEEX_REALLOC
+void *speex_realloc (void *ptr, int size)
+{
+#ifdef VERBOSE_ALLOC
+   speex_warning("realloc attempted, not allowed");
+#endif
+   return 0;
+}
+
+#define OVERRIDE_SPEEX_FREE
+void speex_free (void *ptr)
+{
+#ifdef VERBOSE_ALLOC
+   speex_warning("at speex_free");
+#endif
+}
+#define OVERRIDE_SPEEX_FREE_SCRATCH
+void speex_free_scratch (void *ptr)
+{
+#ifdef VERBOSE_ALLOC
+   speex_warning("at speex_free_scratch");
+#endif
+}
+
+#endif    /* !MANUAL_ALLOC */



More information about the commits mailing list