[Freeswitch-svn] [commit] r11535 - in freeswitch/trunk/libs/spandsp: . spandsp-sim spandsp-sim/spandsp src src/msvc src/spandsp src/spandsp/private tests

FreeSWITCH SVN mikej at freeswitch.org
Tue Jan 27 20:48:03 PST 2009


Author: mikej
Date: Tue Jan 27 22:48:03 2009
New Revision: 11535

Log:
update to snapshot spandsp-20090128

Added:
   freeswitch/trunk/libs/spandsp/spandsp.pc
   freeswitch/trunk/libs/spandsp/spandsp.pc.in
   freeswitch/trunk/libs/spandsp/src/spandsp/expose.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/
   freeswitch/trunk/libs/spandsp/src/spandsp/private/README
   freeswitch/trunk/libs/spandsp/src/spandsp/private/adsi.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/async.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/at_interpreter.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/awgn.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/bell_r2_mf.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/bert.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/bitstream.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/dtmf.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/fax.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/fax_modems.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/fsk.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/g711.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/g722.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/g726.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/gsm0610.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/hdlc.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/ima_adpcm.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/logging.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/lpc10.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/modem_connect_tones.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/noise.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/oki_adpcm.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/queue.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/schedule.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/sig_tone.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t30.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t31.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_core.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_gateway.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_non_ecm_buffer.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_terminal.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/t4.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/time_scale.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_detect.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_generate.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v17rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v17tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v22bis.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v29rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v29tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v42.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v42bis.h
   freeswitch/trunk/libs/spandsp/src/spandsp/private/v8.h
Modified:
   freeswitch/trunk/libs/spandsp/   (props changed)
   freeswitch/trunk/libs/spandsp/INSTALL
   freeswitch/trunk/libs/spandsp/Makefile.am
   freeswitch/trunk/libs/spandsp/README
   freeswitch/trunk/libs/spandsp/configure.ac
   freeswitch/trunk/libs/spandsp/spandsp-sim/g1050.c
   freeswitch/trunk/libs/spandsp/spandsp-sim/line_model.c
   freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/g1050.h
   freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/line_model.h
   freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/test_utils.h
   freeswitch/trunk/libs/spandsp/spandsp-sim/test_utils.c
   freeswitch/trunk/libs/spandsp/spandsp.spec
   freeswitch/trunk/libs/spandsp/spandsp.spec.in
   freeswitch/trunk/libs/spandsp/src/Makefile.am
   freeswitch/trunk/libs/spandsp/src/adsi.c
   freeswitch/trunk/libs/spandsp/src/async.c
   freeswitch/trunk/libs/spandsp/src/at_interpreter.c
   freeswitch/trunk/libs/spandsp/src/awgn.c
   freeswitch/trunk/libs/spandsp/src/bell_r2_mf.c
   freeswitch/trunk/libs/spandsp/src/bert.c
   freeswitch/trunk/libs/spandsp/src/bitstream.c
   freeswitch/trunk/libs/spandsp/src/complex_filters.c
   freeswitch/trunk/libs/spandsp/src/complex_vector_float.c
   freeswitch/trunk/libs/spandsp/src/complex_vector_int.c
   freeswitch/trunk/libs/spandsp/src/crc.c
   freeswitch/trunk/libs/spandsp/src/dds_float.c
   freeswitch/trunk/libs/spandsp/src/dds_int.c
   freeswitch/trunk/libs/spandsp/src/dtmf.c
   freeswitch/trunk/libs/spandsp/src/echo.c
   freeswitch/trunk/libs/spandsp/src/fax.c
   freeswitch/trunk/libs/spandsp/src/filter_tools.c
   freeswitch/trunk/libs/spandsp/src/fsk.c
   freeswitch/trunk/libs/spandsp/src/g711.c
   freeswitch/trunk/libs/spandsp/src/g722.c
   freeswitch/trunk/libs/spandsp/src/g726.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_decode.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_encode.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_local.h
   freeswitch/trunk/libs/spandsp/src/gsm0610_long_term.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_lpc.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_preprocess.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_rpe.c
   freeswitch/trunk/libs/spandsp/src/gsm0610_short_term.c
   freeswitch/trunk/libs/spandsp/src/hdlc.c
   freeswitch/trunk/libs/spandsp/src/ima_adpcm.c
   freeswitch/trunk/libs/spandsp/src/libspandsp.dsp
   freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj
   freeswitch/trunk/libs/spandsp/src/logging.c
   freeswitch/trunk/libs/spandsp/src/lpc10_analyse.c
   freeswitch/trunk/libs/spandsp/src/lpc10_decode.c
   freeswitch/trunk/libs/spandsp/src/lpc10_encode.c
   freeswitch/trunk/libs/spandsp/src/lpc10_placev.c
   freeswitch/trunk/libs/spandsp/src/lpc10_voicing.c
   freeswitch/trunk/libs/spandsp/src/make_modem_filter.c
   freeswitch/trunk/libs/spandsp/src/modem_connect_tones.c
   freeswitch/trunk/libs/spandsp/src/modem_echo.c
   freeswitch/trunk/libs/spandsp/src/msvc/spandsp.def
   freeswitch/trunk/libs/spandsp/src/noise.c
   freeswitch/trunk/libs/spandsp/src/oki_adpcm.c
   freeswitch/trunk/libs/spandsp/src/playout.c
   freeswitch/trunk/libs/spandsp/src/plc.c
   freeswitch/trunk/libs/spandsp/src/power_meter.c
   freeswitch/trunk/libs/spandsp/src/queue.c
   freeswitch/trunk/libs/spandsp/src/schedule.c
   freeswitch/trunk/libs/spandsp/src/sig_tone.c
   freeswitch/trunk/libs/spandsp/src/silence_gen.c
   freeswitch/trunk/libs/spandsp/src/spandsp.h.in
   freeswitch/trunk/libs/spandsp/src/spandsp/adsi.h
   freeswitch/trunk/libs/spandsp/src/spandsp/async.h
   freeswitch/trunk/libs/spandsp/src/spandsp/at_interpreter.h
   freeswitch/trunk/libs/spandsp/src/spandsp/awgn.h
   freeswitch/trunk/libs/spandsp/src/spandsp/bell_r2_mf.h
   freeswitch/trunk/libs/spandsp/src/spandsp/bert.h
   freeswitch/trunk/libs/spandsp/src/spandsp/bit_operations.h
   freeswitch/trunk/libs/spandsp/src/spandsp/bitstream.h
   freeswitch/trunk/libs/spandsp/src/spandsp/complex_vector_float.h
   freeswitch/trunk/libs/spandsp/src/spandsp/dtmf.h
   freeswitch/trunk/libs/spandsp/src/spandsp/fax.h
   freeswitch/trunk/libs/spandsp/src/spandsp/fax_modems.h
   freeswitch/trunk/libs/spandsp/src/spandsp/fsk.h
   freeswitch/trunk/libs/spandsp/src/spandsp/g711.h
   freeswitch/trunk/libs/spandsp/src/spandsp/g722.h
   freeswitch/trunk/libs/spandsp/src/spandsp/g726.h
   freeswitch/trunk/libs/spandsp/src/spandsp/gsm0610.h
   freeswitch/trunk/libs/spandsp/src/spandsp/hdlc.h
   freeswitch/trunk/libs/spandsp/src/spandsp/ima_adpcm.h
   freeswitch/trunk/libs/spandsp/src/spandsp/logging.h
   freeswitch/trunk/libs/spandsp/src/spandsp/lpc10.h
   freeswitch/trunk/libs/spandsp/src/spandsp/modem_connect_tones.h
   freeswitch/trunk/libs/spandsp/src/spandsp/noise.h
   freeswitch/trunk/libs/spandsp/src/spandsp/oki_adpcm.h
   freeswitch/trunk/libs/spandsp/src/spandsp/queue.h
   freeswitch/trunk/libs/spandsp/src/spandsp/schedule.h
   freeswitch/trunk/libs/spandsp/src/spandsp/sig_tone.h
   freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t30.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t30_api.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t31.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t38_core.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t38_gateway.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t38_non_ecm_buffer.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t38_terminal.h
   freeswitch/trunk/libs/spandsp/src/spandsp/t4.h
   freeswitch/trunk/libs/spandsp/src/spandsp/telephony.h
   freeswitch/trunk/libs/spandsp/src/spandsp/time_scale.h
   freeswitch/trunk/libs/spandsp/src/spandsp/tone_detect.h
   freeswitch/trunk/libs/spandsp/src/spandsp/tone_generate.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v17rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v17tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v22bis.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v29rx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v29tx.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v42.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v42bis.h
   freeswitch/trunk/libs/spandsp/src/spandsp/v8.h
   freeswitch/trunk/libs/spandsp/src/spandsp/vector_float.h
   freeswitch/trunk/libs/spandsp/src/spandsp/version.h
   freeswitch/trunk/libs/spandsp/src/super_tone_rx.c
   freeswitch/trunk/libs/spandsp/src/super_tone_tx.c
   freeswitch/trunk/libs/spandsp/src/t30.c
   freeswitch/trunk/libs/spandsp/src/t30_api.c
   freeswitch/trunk/libs/spandsp/src/t30_logging.c
   freeswitch/trunk/libs/spandsp/src/t31.c
   freeswitch/trunk/libs/spandsp/src/t35.c
   freeswitch/trunk/libs/spandsp/src/t38_core.c
   freeswitch/trunk/libs/spandsp/src/t38_gateway.c
   freeswitch/trunk/libs/spandsp/src/t38_non_ecm_buffer.c
   freeswitch/trunk/libs/spandsp/src/t38_terminal.c
   freeswitch/trunk/libs/spandsp/src/t4.c
   freeswitch/trunk/libs/spandsp/src/testcpuid.c
   freeswitch/trunk/libs/spandsp/src/time_scale.c
   freeswitch/trunk/libs/spandsp/src/tone_detect.c
   freeswitch/trunk/libs/spandsp/src/tone_generate.c
   freeswitch/trunk/libs/spandsp/src/v17rx.c
   freeswitch/trunk/libs/spandsp/src/v17tx.c
   freeswitch/trunk/libs/spandsp/src/v22bis_rx.c
   freeswitch/trunk/libs/spandsp/src/v22bis_tx.c
   freeswitch/trunk/libs/spandsp/src/v27ter_rx.c
   freeswitch/trunk/libs/spandsp/src/v27ter_tx.c
   freeswitch/trunk/libs/spandsp/src/v29rx.c
   freeswitch/trunk/libs/spandsp/src/v29tx.c
   freeswitch/trunk/libs/spandsp/src/v42.c
   freeswitch/trunk/libs/spandsp/src/v42bis.c
   freeswitch/trunk/libs/spandsp/src/v8.c
   freeswitch/trunk/libs/spandsp/src/vector_float.c
   freeswitch/trunk/libs/spandsp/src/vector_int.c
   freeswitch/trunk/libs/spandsp/tests/Makefile.am
   freeswitch/trunk/libs/spandsp/tests/adsi_tests.c
   freeswitch/trunk/libs/spandsp/tests/async_tests.c
   freeswitch/trunk/libs/spandsp/tests/at_interpreter_tests.c
   freeswitch/trunk/libs/spandsp/tests/awgn_tests.c
   freeswitch/trunk/libs/spandsp/tests/bell_mf_rx_tests.c
   freeswitch/trunk/libs/spandsp/tests/bell_mf_tx_tests.c
   freeswitch/trunk/libs/spandsp/tests/bert_tests.c
   freeswitch/trunk/libs/spandsp/tests/complex_tests.c
   freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c
   freeswitch/trunk/libs/spandsp/tests/dc_restore_tests.c
   freeswitch/trunk/libs/spandsp/tests/dtmf_rx_tests.c
   freeswitch/trunk/libs/spandsp/tests/dtmf_tx_tests.c
   freeswitch/trunk/libs/spandsp/tests/echo_tests.c
   freeswitch/trunk/libs/spandsp/tests/fax_decode.c
   freeswitch/trunk/libs/spandsp/tests/fax_tester.c
   freeswitch/trunk/libs/spandsp/tests/fax_tests.c
   freeswitch/trunk/libs/spandsp/tests/fsk_tests.c
   freeswitch/trunk/libs/spandsp/tests/g1050_tests.c
   freeswitch/trunk/libs/spandsp/tests/g168_tests.c
   freeswitch/trunk/libs/spandsp/tests/g711_tests.c
   freeswitch/trunk/libs/spandsp/tests/g722_tests.c
   freeswitch/trunk/libs/spandsp/tests/g726_tests.c
   freeswitch/trunk/libs/spandsp/tests/gsm0610_tests.c
   freeswitch/trunk/libs/spandsp/tests/hdlc_tests.c
   freeswitch/trunk/libs/spandsp/tests/ima_adpcm_tests.c
   freeswitch/trunk/libs/spandsp/tests/line_model_tests.c
   freeswitch/trunk/libs/spandsp/tests/logging_tests.c
   freeswitch/trunk/libs/spandsp/tests/lpc10_tests.c
   freeswitch/trunk/libs/spandsp/tests/make_g168_css.c
   freeswitch/trunk/libs/spandsp/tests/modem_connect_tones_tests.c
   freeswitch/trunk/libs/spandsp/tests/modem_echo_tests.c
   freeswitch/trunk/libs/spandsp/tests/noise_tests.c
   freeswitch/trunk/libs/spandsp/tests/oki_adpcm_tests.c
   freeswitch/trunk/libs/spandsp/tests/playout_tests.c
   freeswitch/trunk/libs/spandsp/tests/power_meter_tests.c
   freeswitch/trunk/libs/spandsp/tests/queue_tests.c
   freeswitch/trunk/libs/spandsp/tests/r2_mf_rx_tests.c
   freeswitch/trunk/libs/spandsp/tests/r2_mf_tx_tests.c
   freeswitch/trunk/libs/spandsp/tests/regression_tests.sh
   freeswitch/trunk/libs/spandsp/tests/rfc2198_sim_tests.c
   freeswitch/trunk/libs/spandsp/tests/schedule_tests.c
   freeswitch/trunk/libs/spandsp/tests/sig_tone_tests.c
   freeswitch/trunk/libs/spandsp/tests/super_tone_rx_tests.c
   freeswitch/trunk/libs/spandsp/tests/super_tone_tx_tests.c
   freeswitch/trunk/libs/spandsp/tests/t31_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_core_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_gateway_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_gateway_to_terminal_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_non_ecm_buffer_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_terminal_tests.c
   freeswitch/trunk/libs/spandsp/tests/t38_terminal_to_gateway_tests.c
   freeswitch/trunk/libs/spandsp/tests/t4_tests.c
   freeswitch/trunk/libs/spandsp/tests/time_scale_tests.c
   freeswitch/trunk/libs/spandsp/tests/tone_detect_tests.c
   freeswitch/trunk/libs/spandsp/tests/tone_generate_tests.c
   freeswitch/trunk/libs/spandsp/tests/tsb85_tests.c
   freeswitch/trunk/libs/spandsp/tests/v17_tests.c
   freeswitch/trunk/libs/spandsp/tests/v22bis_tests.c
   freeswitch/trunk/libs/spandsp/tests/v27ter_tests.c
   freeswitch/trunk/libs/spandsp/tests/v29_tests.c
   freeswitch/trunk/libs/spandsp/tests/v42_tests.c
   freeswitch/trunk/libs/spandsp/tests/v42bis_tests.c
   freeswitch/trunk/libs/spandsp/tests/v8_tests.c
   freeswitch/trunk/libs/spandsp/tests/vector_float_tests.c

Modified: freeswitch/trunk/libs/spandsp/INSTALL
==============================================================================
--- freeswitch/trunk/libs/spandsp/INSTALL	(original)
+++ freeswitch/trunk/libs/spandsp/INSTALL	Tue Jan 27 22:48:03 2009
@@ -1,3 +1,76 @@
+Building and installing spandsp
+===============================
+
+A number of distributions include spandsp, but they usually use older versions
+of the library, which lack a lot of the features of the current version. Before
+installing spandsp, make sure there are no older versions already on your
+machine. Make sure libtiff is installed on your machine. Versions 3.5.7,
+3.6.0, 3.7.1 and 3.8.2 seem to work OK. There have been several bugs related
+to FAX document handling in some versions of libtiff. Also, some people have
+had trouble using spandsp because they had more than one version of libtiff
+on their machine. Take care with this. If you are using an RPM based system,
+such as RedHat or Fedora, you will need the libtiff and libtiff-devel RPMs
+installed to be able to build spandsp.
+
+You can use the usual:
+
+    ./configure
+    make
+    make install
+
+process to build the spandsp library. Note that if you use configure in this
+way, the software will be installed in /usr/local. In this case make sure your
+/etc/ld.so.conf file has an entry for /usr/local/lib. If you wish the software
+to be installed in /usr, you should build it with the commands.
+
+    ./configure --prefix=/usr
+    make
+    make install
+
+
+Building the programming documentation
+======================================
+
+If you wish to build the programming documentation for spandsp, configure
+spandsp with:
+
+    ./configure --enable-doc
+
+You need doxygen installed on your machine.
+
+
+Building the test suite
+=======================
+
+Most sections of the spandsp library have an accompanying test program in the
+test directory. If you wish to build these test programs, configure spandsp
+with:
+
+    ./configure --enable-tests
+
+To build these tests you will need libaudiofile installed on your machine. To
+build the modem tests, with the GUI monitoring feature you will need Fltk 1.1.4
+or later, an audio meter module and a cartesian plotting module. Fltk may be
+obtained from http://www.fltk.org. The audio meter module may be obtained from
+http://www.soft-switch.org/downloads/Fl_Audio_Meter.tgz . The cartesian plotting
+module may be obtained from http://134.226.68.29/fltk. However, there is no
+suitable makefile supplied with that. You can find a version at
+http://www.soft-switch.org/downloads/Fl_Cartesian.tgz which will build as a
+Linux library. The actual code in both these versions is identical.
+You need to have Fltk 1.1.4 or later installed before building the plotting
+library.
+
+
+Applications
+============
+
+Applications support for spandsp is built into packages such as Callweaver,
+FreeSwitch and iaxmodem. Code to add spandsp based FAX support to Asterisk may
+be found at http://sourceforge.net/projects/agx-ast-addons.
+
+
+
+
 Basic Installation
 ==================
 

Modified: freeswitch/trunk/libs/spandsp/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/Makefile.am	(original)
+++ freeswitch/trunk/libs/spandsp/Makefile.am	Tue Jan 27 22:48:03 2009
@@ -16,7 +16,7 @@
 ## License along with this program; if not, write to the Free Software
 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ##
-## $Id: Makefile.am,v 1.44 2008/09/28 14:36:25 steveu Exp $
+## $Id: Makefile.am,v 1.45 2008/11/28 12:41:25 steveu Exp $
 
 AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
 AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
@@ -28,6 +28,7 @@
 EXTRA_DIST = autogen.sh \
              DueDiligence \
              README.testdata \
+             spandsp.pc \
              spandsp.spec \
              wrapper.xsl \
              unpack_g722_data.sh \
@@ -60,6 +61,9 @@
 
 DIST_SUBDIRS = src doc spandsp-sim tests test-data
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = spandsp.pc
+
 faq: faq.xml
 	cd faq ; xsltproc ../wrapper.xsl ../faq.xml
 

Modified: freeswitch/trunk/libs/spandsp/README
==============================================================================
--- freeswitch/trunk/libs/spandsp/README	(original)
+++ freeswitch/trunk/libs/spandsp/README	Tue Jan 27 22:48:03 2009
@@ -1,4 +1,4 @@
-spandsp 0.0.4 - A DSP library for telephony
+spandsp 0.0.5 - A DSP library for telephony
 -------------------------------------------
 
 SpanDSP is a library of DSP functions for telephony, in the 8000 sample per
@@ -26,8 +26,8 @@
 fftw (and fftw-devel) is required to build the test suite. Version 2 or 3 of
 FFTW may be used. Spandsp adapts to the differences between them.
 
-fltk (and fltk-devel), Fl_Cartesian and Fl_Audio_Meter are required to build the
-test suite with GUI interfaces for some of the tests. The tests will build
+fltk (and fltk-devel), Fl_Cartesian and Fl_Audio_Meter are required to build
+the test suite with GUI interfaces for some of the tests. The tests will build
 without these packages, but the GUI features will not be available.
 Fl_Cartesian and Fl_Audio_Meter can be downloaded from
 http://www.soft-switch.org/downloads.

Modified: freeswitch/trunk/libs/spandsp/configure.ac
==============================================================================
--- freeswitch/trunk/libs/spandsp/configure.ac	(original)
+++ freeswitch/trunk/libs/spandsp/configure.ac	Tue Jan 27 22:48:03 2009
@@ -16,7 +16,7 @@
 # License along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
-# $Id: configure.ac,v 1.59 2008/09/16 15:21:52 steveu Exp $
+# $Id: configure.ac,v 1.64 2009/01/17 08:16:08 steveu Exp $
 
 # @start 1
 
@@ -30,7 +30,7 @@
 
 SPANDSP_MAJOR_VERSION=0
 SPANDSP_MINOR_VERSION=0
-SPANDSP_MICRO_VERSION=5
+SPANDSP_MICRO_VERSION=6
 
 SPANDSP_LT_CURRENT=1
 SPANDSP_LT_REVISION=0
@@ -49,7 +49,7 @@
 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
 
 AC_CANONICAL_HOST
-AC_CANONICAL_BUILD
+#AC_CANONICAL_BUILD
 AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_GCC_TRADITIONAL
@@ -237,7 +237,11 @@
 then
     case "${host}" in
     x86_64-*)
+        # X86_64 Linux machines may have both 64 bit and 32 bit libraries. We need to choose the right set
         AX_CHECK_REAL_FILE([${prefix}/lib64], libdir='$(exec_prefix)/lib64')
+        AX_CHECK_REAL_FILE([/usr/X11R6/lib64], [TESTLIBS="$TESTLIBS -L/usr/X11R6/lib64"], AC_CHECK_FILE([/usr/X11R6/lib], [TESTLIBS="$TESTLIBS -L/usr/X11R6/lib"]))
+        # The very oldest AMD 64 bit chips support SSE2, SSE and MMX
+        enable_sse2="yes"
         ;;
     esac
 fi
@@ -258,16 +262,6 @@
 AC_SEARCH_LIBS([logf], [m], AC_DEFINE([HAVE_LOGF], [1], [Define to 1 if you have the logf() function.]))
 AC_SEARCH_LIBS([log10f], [m], AC_DEFINE([HAVE_LOG10F], [1], [Define to 1 if you have the log10f() function.]))
 
-if test "${build}" == "${host}"
-then
-    case "${host}" in
-    x86_64-*)
-        # X86_64 Linux machines may have both 64 bit and 32 bit libraries. We need to choose the right set
-        AX_CHECK_REAL_FILE([/usr/X11R6/lib64], [TESTLIBS="$TESTLIBS -L/usr/X11R6/lib64"], AC_CHECK_FILE([/usr/X11R6/lib], [TESTLIBS="$TESTLIBS -L/usr/X11R6/lib"]))
-        ;;
-    esac
-fi
-
 # Checks for libraries.
 AC_CHECK_LIB([tiff], [TIFFOpen], , AC_MSG_ERROR("Can't build without libtiff (does your system require a libtiff-devel package?)"), -lm)
 
@@ -373,57 +367,37 @@
     [AC_DEFINE([SPANDSP_MISALIGNED_ACCESS_FAILS], [1], [Do not expect a misaligned memory access to work correctly])
     SPANDSP_MISALIGNED_ACCESS_FAILS="#define SPANDSP_MISALIGNED_ACCESS_FAILS 1"],
     [SPANDSP_MISALIGNED_ACCESS_FAILS="#undef SPANDSP_MISALIGNED_ACCESS_FAILS"])
-if test "$enable_mmx" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
+
+if test "$enable_sse5" = "yes" ; then
+    AC_DEFINE([SPANDSP_USE_SSE5], [1], [Use the SSE5 instruction set (i386 and x86_64 only).])
+    enable_sse4a="yes"
 fi
-if test "$enable_sse" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
+if test "$enable_sse4a" = "yes" ; then
+    AC_DEFINE([SPANDSP_USE_SSE4A], [1], [Use the SSE4A instruction set (i386 and x86_64 only).])
+    enable_sse4_2="yes"
 fi
-if test "$enable_sse2" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
+if test "$enable_sse4_2" = "yes" ; then
+    AC_DEFINE([SPANDSP_USE_SSE4_2], [1], [Use the SSE4.2 instruction set (i386 and x86_64 only).])
+    enable_sse4_1="yes"
 fi
-if test "$enable_sse3" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE3], [1], [Use the SSE3 instruction set (i386 and x86_64 only).])
+if test "$enable_sse4_1" = "yes" ; then
     AC_DEFINE([SPANDSP_USE_SSE4_1], [1], [Use the SSE4.1 instruction set (i386 and x86_64 only).])
+    enable_sse3="yes"
 fi
-if test "$enable_sse4_1" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
+if test "$enable_sse3" = "yes" ; then
     AC_DEFINE([SPANDSP_USE_SSE3], [1], [Use the SSE3 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_1], [1], [Use the SSE4.1 instruction set (i386 and x86_64 only).])
+    enable_sse2="yes"
 fi
-if test "$enable_sse4_2" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
+if test "$enable_sse2" = "yes" ; then
     AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE3], [1], [Use the SSE3 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_1], [1], [Use the SSE4.1 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_2], [1], [Use the SSE4.2 instruction set (i386 and x86_64 only).])
+    enable_sse="yes"
 fi
-if test "$enable_sse4a" = "yes" ; then
-    AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
+if test "$enable_sse" = "yes" ; then
     AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE3], [1], [Use the SSE3 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_1], [1], [Use the SSE4.1 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_2], [1], [Use the SSE4.2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4A], [1], [Use the SSE4A instruction set (i386 and x86_64 only).])
+    enable_mmx="yes"
 fi
-if test "$enable_sse5" = "yes" ; then
+if test "$enable_mmx" = "yes" ; then
     AC_DEFINE([SPANDSP_USE_MMX], [1], [Use the MMX instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE], [1], [Use the SSE instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE2], [1], [Use the SSE2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE3], [1], [Use the SSE3 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_1], [1], [Use the SSE4.1 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE4_2], [1], [Use the SSE4.2 instruction set (i386 and x86_64 only).])
-    AC_DEFINE([SPANDSP_USE_SSE5], [1], [Use the SSE5 instruction set (i386 and x86_64 only).])
 fi
 
 AC_SUBST(CC_FOR_BUILD)
@@ -451,6 +425,7 @@
                  test-data/itu/fax/Makefile
                  test-data/local/Makefile
                  tests/Makefile
+                 spandsp.pc
                  spandsp.spec])
 
 AC_OUTPUT

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/g1050.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/g1050.c	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/g1050.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g1050.c,v 1.10 2008/07/02 14:48:25 steveu Exp $
+ * $Id: g1050.c,v 1.11 2009/01/16 15:13:16 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -142,141 +142,176 @@
     }
 };
 
-g1050_channel_speeds_t g1050_speed_patterns[133] =
+g1050_channel_speeds_t g1050_speed_patterns[168] =
 {
-    {  4000000, 0,    128000,   768000, 0,     4000000, 0,    128000,   768000, 0,  2.2500},
-    {  4000000, 0,    128000,   768000, 0,    20000000, 0,    128000,   768000, 0,  1.5000},
-    { 20000000, 0,    128000,   768000, 0,    20000000, 0,    128000,   768000, 0,  0.2500},
-    {  4000000, 0,    128000,  1536000, 0,     4000000, 0,    384000,   768000, 0,  3.4125},
-    {  4000000, 0,    128000,  1536000, 0,    20000000, 0,    384000,   768000, 0,  2.6750},
-    { 20000000, 0,    128000,  1536000, 0,    20000000, 0,    384000,   768000, 0,  0.5125},
-    {  4000000, 0,    128000,  3000000, 0,     4000000, 0,    384000,   768000, 0,  0.7875},
-    {  4000000, 0,    128000,  3000000, 0,    20000000, 0,    384000,   768000, 0,  0.6750},
-    { 20000000, 0,    128000,  3000000, 0,    20000000, 0,    384000,   768000, 0,  0.1375},
-    {  4000000, 0,    384000,   768000, 0,     4000000, 0,    128000,  1536000, 0,  3.4125},
-    {  4000000, 0,    384000,   768000, 0,    20000000, 0,    128000,  1536000, 0,  2.6750},
-    { 20000000, 0,    384000,   768000, 0,    20000000, 0,    128000,  1536000, 0,  0.5125},
-    {  4000000, 0,    384000,  1536000, 0,     4000000, 0,    384000,  1536000, 0,  5.1756},
-    {  4000000, 0,    384000,  1536000, 0,    20000000, 0,    384000,  1536000, 0,  4.6638},
-    { 20000000, 0,    384000,  1536000, 0,    20000000, 0,    384000,  1536000, 0,  1.0506},
-    {  4000000, 0,    384000,  3000000, 0,     4000000, 0,    384000,  1536000, 0,  1.1944},
-    {  4000000, 0,    384000,  3000000, 0,    20000000, 0,    384000,  1536000, 0,  1.1638},
-    { 20000000, 0,    384000,  3000000, 0,    20000000, 0,    384000,  1536000, 0,  0.2819},
-    {  4000000, 0,    384000,   768000, 0,     4000000, 0,    128000,  3000000, 0,  0.7875},
-    {  4000000, 0,    384000,   768000, 0,    20000000, 0,    128000,  3000000, 0,  0.6750},
-    { 20000000, 0,    384000,   768000, 0,    20000000, 0,    128000,  3000000, 0,  0.1375},
-    {  4000000, 0,    384000,  1536000, 0,     4000000, 0,    384000,  3000000, 0,  1.1944},
-    {  4000000, 0,    384000,  1536000, 0,    20000000, 0,    384000,  3000000, 0,  1.1638},
-    { 20000000, 0,    384000,  1536000, 0,    20000000, 0,    384000,  3000000, 0,  0.2819},
-    {  4000000, 0,    384000,  3000000, 0,     4000000, 0,    384000,  3000000, 0,  0.2756},
-    {  4000000, 0,    384000,  3000000, 0,    20000000, 0,    384000,  3000000, 0,  0.2888},
-    { 20000000, 0,    384000,  3000000, 0,    20000000, 0,    384000,  3000000, 0,  0.0756},
-    {  4000000, 0,    128000,  1536000, 0,   100000000, 0,    384000,   768000, 0,  1.8000},
-    { 20000000, 0,    128000,  1536000, 0,   100000000, 0,    384000,   768000, 0,  0.6000},
-    {  4000000, 0,    128000,  3000000, 0,   100000000, 0,    384000,   768000, 0,  0.6750},
-    { 20000000, 0,    128000,  3000000, 0,   100000000, 0,    384000,   768000, 0,  0.2250},
-    {  4000000, 0,    128000,  1536000, 0,     4000000, 0,    768000,  1536000, 0,  0.6000},
-    {  4000000, 0,    128000,  1536000, 0,    20000000, 0,    768000,  1536000, 0,  0.8000},
-    {  4000000, 0,    128000,  1536000, 0,   100000000, 0,    768000,  1536000, 0,  1.8000},
-    { 20000000, 0,    128000,  1536000, 0,    20000000, 0,    768000,  1536000, 0,  0.2000},
-    { 20000000, 0,    128000,  1536000, 0,   100000000, 0,    768000,  1536000, 0,  0.6000},
-    {  4000000, 0,    128000, 43000000, 0,     4000000, 0,    768000, 43000000, 0,  0.0750},
-    {  4000000, 0,    128000, 43000000, 0,    20000000, 0,    768000, 43000000, 0,  0.1000},
-    {  4000000, 0,    128000, 43000000, 0,   100000000, 0,    768000, 43000000, 0,  0.2250},
-    { 20000000, 0,    128000, 43000000, 0,    20000000, 0,    768000, 43000000, 0,  0.0250},
-    { 20000000, 0,    128000, 43000000, 0,   100000000, 0,    768000, 43000000, 0,  0.0750},
-    {  4000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  5.4600},
-    { 20000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  2.4600},
-    {  4000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  1.6538},
-    { 20000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  0.7913},
-    {  4000000, 0,    384000,  1536000, 0,     4000000, 0,   1536000,  1536000, 0,  0.9100},
-    {  4000000, 0,    384000,  1536000, 0,    20000000, 0,   1536000,  1536000, 0,  1.3200},
-    {  4000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  3.2100},
-    { 20000000, 0,    384000,  1536000, 0,    20000000, 0,   1536000,  1536000, 0,  0.4100},
-    { 20000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  1.7100},
-    {  4000000, 0,    384000, 43000000, 0,     4000000, 0,   1536000, 43000000, 0,  0.1138},
-    {  4000000, 0,    384000, 43000000, 0,    20000000, 0,   1536000, 43000000, 0,  0.1650},
-    {  4000000, 0,    384000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.4013},
-    { 20000000, 0,    384000, 43000000, 0,    20000000, 0,   1536000, 43000000, 0,  0.0513},
-    { 20000000, 0,    384000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.2138},
-    {  4000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  3000000, 0,  1.6538},
-    { 20000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  3000000, 0,  0.7913},
-    {  4000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  3000000, 0,  0.4725},
-    { 20000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  3000000, 0,  0.2475},
-    {  4000000, 0,    384000,  1536000, 0,     4000000, 0,   1536000,  3000000, 0,  0.2100},
-    {  4000000, 0,    384000,  1536000, 0,    20000000, 0,   1536000,  3000000, 0,  0.3200},
-    {  4000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  3000000, 0,  0.8100},
-    { 20000000, 0,    384000,  1536000, 0,    20000000, 0,   1536000,  3000000, 0,  0.1100},
-    { 20000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  3000000, 0,  0.5100},
-    {  4000000, 0,    384000, 43000000, 0,     4000000, 0,   3000000, 43000000, 0,  0.0263},
-    {  4000000, 0,    384000, 43000000, 0,    20000000, 0,   3000000, 43000000, 0,  0.0400},
-    {  4000000, 0,    384000, 43000000, 0,   100000000, 0,   3000000, 43000000, 0,  0.1013},
-    { 20000000, 0,    384000, 43000000, 0,    20000000, 0,   3000000, 43000000, 0,  0.0138},
-    { 20000000, 0,    384000, 43000000, 0,   100000000, 0,   3000000, 43000000, 0,  0.0638},
-    {  4000000, 0,    384000,   768000, 0,   100000000, 0,    128000,  1536000, 0,  1.8000},
-    { 20000000, 0,    384000,   768000, 0,   100000000, 0,    128000,  1536000, 0,  0.6000},
-    {  4000000, 0,    384000,   768000, 0,   100000000, 0,    128000,  3000000, 0,  0.6750},
-    { 20000000, 0,    384000,   768000, 0,   100000000, 0,    128000,  3000000, 0,  0.2250},
-    {  4000000, 0,    768000,  1536000, 0,     4000000, 0,    128000,  1536000, 0,  0.6000},
-    {  4000000, 0,    768000,  1536000, 0,    20000000, 0,    128000,  1536000, 0,  0.8000},
-    { 20000000, 0,    768000,  1536000, 0,    20000000, 0,    128000,  1536000, 0,  0.2000},
-    {  4000000, 0,    768000,  1536000, 0,   100000000, 0,    128000,  1536000, 0,  1.8000},
-    { 20000000, 0,    768000,  1536000, 0,   100000000, 0,    128000,  1536000, 0,  0.6000},
-    {  4000000, 0,   1536000,  1536000, 0,     4000000, 0,    384000,  1536000, 0,  0.9100},
-    {  4000000, 0,   1536000,  1536000, 0,    20000000, 0,    384000,  1536000, 0,  1.3200},
-    { 20000000, 0,   1536000,  1536000, 0,    20000000, 0,    384000,  1536000, 0,  0.4100},
-    {  4000000, 0,   1536000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  3.2100},
-    { 20000000, 0,   1536000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  1.7100},
-    {  4000000, 0,   1536000,  3000000, 0,     4000000, 0,    384000,  1536000, 0,  0.2100},
-    {  4000000, 0,   1536000,  3000000, 0,    20000000, 0,    384000,  1536000, 0,  0.3200},
-    { 20000000, 0,   1536000,  3000000, 0,    20000000, 0,    384000,  1536000, 0,  0.1100},
-    {  4000000, 0,   1536000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  0.8100},
-    { 20000000, 0,   1536000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  0.5100},
-    {  4000000, 0,    768000, 43000000, 0,     4000000, 0,    128000, 43000000, 0,  0.0750},
-    {  4000000, 0,    768000, 43000000, 0,    20000000, 0,    128000, 43000000, 0,  0.1000},
-    { 20000000, 0,    768000, 43000000, 0,    20000000, 0,    128000, 43000000, 0,  0.0250},
-    {  4000000, 0,    768000, 43000000, 0,   100000000, 0,    128000, 43000000, 0,  0.2250},
-    { 20000000, 0,    768000, 43000000, 0,   100000000, 0,    128000, 43000000, 0,  0.0750},
-    {  4000000, 0,   1536000, 43000000, 0,     4000000, 0,    384000, 43000000, 0,  0.1138},
-    {  4000000, 0,   1536000, 43000000, 0,    20000000, 0,    384000, 43000000, 0,  0.1650},
-    { 20000000, 0,   1536000, 43000000, 0,    20000000, 0,    384000, 43000000, 0,  0.0513},
-    {  4000000, 0,   1536000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.4013},
-    { 20000000, 0,   1536000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.2138},
-    {  4000000, 0,   3000000, 43000000, 0,     4000000, 0,    384000, 43000000, 0,  0.0263},
-    {  4000000, 0,   3000000, 43000000, 0,    20000000, 0,    384000, 43000000, 0,  0.0400},
-    { 20000000, 0,   3000000, 43000000, 0,    20000000, 0,    384000, 43000000, 0,  0.0138},
-    {  4000000, 0,   3000000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.1013},
-    { 20000000, 0,   3000000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.0638},
-    {100000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  1.4400},
-    {100000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  0.5400},
-    {100000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  1.4400},
-    {100000000, 0,    384000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.1800},
-    {100000000, 0,    384000,  1536000, 0,   100000000, 0,    384000,  3000000, 0,  0.5400},
-    {100000000, 0,    384000,  3000000, 0,   100000000, 0,    384000,  3000000, 0,  0.2025},
-    {100000000, 0,    384000,  1536000, 0,   100000000, 0,   1536000,  3000000, 0,  0.5400},
-    {100000000, 0,    384000, 43000000, 0,   100000000, 0,   3000000, 43000000, 0,  0.0675},
-    {100000000, 0,   1536000,  1536000, 0,   100000000, 0,    384000,  1536000, 0,  1.4400},
-    {100000000, 0,   1536000,  3000000, 0,   100000000, 0,    384000,  1536000, 0,  0.5400},
-    {  4000000, 0,   1536000,  1536000, 0,     4000000, 0,   1536000,  1536000, 0,  0.1600},
-    {  4000000, 0,   1536000,  1536000, 0,    20000000, 0,   1536000,  1536000, 0,  0.3200},
-    {  4000000, 0,   1536000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  0.9600},
-    { 20000000, 0,   1536000,  1536000, 0,    20000000, 0,   1536000,  1536000, 0,  0.1600},
-    { 20000000, 0,   1536000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  0.9600},
-    {100000000, 0,   1536000,  1536000, 0,   100000000, 0,   1536000,  1536000, 0,  1.4400},
-    {  4000000, 0,   1536000, 43000000, 0,     4000000, 0,   1536000, 43000000, 0,  0.0400},
-    {  4000000, 0,   1536000, 43000000, 0,    20000000, 0,   1536000, 43000000, 0,  0.0800},
-    {  4000000, 0,   1536000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.2400},
-    { 20000000, 0,   1536000, 43000000, 0,    20000000, 0,   1536000, 43000000, 0,  0.0400},
-    { 20000000, 0,   1536000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.2400},
-    {100000000, 0,   1536000, 43000000, 0,   100000000, 0,   1536000, 43000000, 0,  0.3600},
-    {100000000, 0,   1536000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.1800},
-    {100000000, 0,   3000000, 43000000, 0,   100000000, 0,    384000, 43000000, 0,  0.0675},
-    {  4000000, 0,  43000000, 43000000, 0,     4000000, 0,  43000000, 43000000, 0,  0.0025},
-    {  4000000, 0,  43000000, 43000000, 0,    20000000, 0,  43000000, 43000000, 0,  0.0050},
-    {  4000000, 0,  43000000, 43000000, 0,   100000000, 0,  43000000, 43000000, 0,  0.0150},
-    { 20000000, 0,  43000000, 43000000, 0,    20000000, 0,  43000000, 43000000, 0,  0.0025},
-    { 20000000, 0,  43000000, 43000000, 0,   100000000, 0,  43000000, 43000000, 0,  0.0150},
-    {100000000, 0,  43000000, 43000000, 0,   100000000, 0,  43000000, 43000000, 0,  0.0225}
+    {  4000000, 0,   128000,   768000, 0,   4000000, 0,   128000,   768000, 0, 0.360},
+    {  4000000, 0,   128000,   768000, 0,  20000000, 0,   128000,   768000, 0, 0.720},
+    {  4000000, 0,   128000,   768000, 0, 100000000, 0,   128000,   768000, 0, 0.360},
+    { 20000000, 0,   128000,   768000, 0,  20000000, 0,   128000,   768000, 0, 0.360},
+    { 20000000, 0,   128000,   768000, 0, 100000000, 0,   128000,   768000, 0, 0.360},
+    {100000000, 0,   128000,   768000, 0, 100000000, 0,   128000,   768000, 0, 0.090},
+    {  4000000, 0,   128000,  1536000, 0,   4000000, 0,   384000,   768000, 0, 0.720},
+    {  4000000, 0,   128000,  1536000, 0,  20000000, 0,   384000,   768000, 0, 1.470},
+    {  4000000, 0,   128000,  1536000, 0, 100000000, 0,   384000,   768000, 0, 0.840},
+    { 20000000, 0,   128000,  1536000, 0,  20000000, 0,   384000,   768000, 0, 0.750},
+    { 20000000, 0,   128000,  1536000, 0, 100000000, 0,   384000,   768000, 0, 0.855},
+    {100000000, 0,   128000,  1536000, 0, 100000000, 0,   384000,   768000, 0, 0.240},
+    {  4000000, 0,   128000,  3000000, 0,   4000000, 0,   384000,   768000, 0, 0.120},
+    {  4000000, 0,   128000,  3000000, 0,  20000000, 0,   384000,   768000, 0, 0.420},
+    {  4000000, 0,   128000,  3000000, 0, 100000000, 0,   384000,   768000, 0, 0.840},
+    { 20000000, 0,   128000,  3000000, 0,  20000000, 0,   384000,   768000, 0, 0.300},
+    { 20000000, 0,   128000,  3000000, 0, 100000000, 0,   384000,   768000, 0, 0.930},
+    {100000000, 0,   128000,  3000000, 0, 100000000, 0,   384000,   768000, 0, 0.390},
+    {  4000000, 0,   384000,   768000, 0,   4000000, 0,   128000,  1536000, 0, 0.720},
+    {  4000000, 0,   384000,   768000, 0,  20000000, 0,   128000,  1536000, 0, 1.470},
+    {  4000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  1536000, 0, 0.840},
+    { 20000000, 0,   384000,   768000, 0,  20000000, 0,   128000,  1536000, 0, 0.750},
+    { 20000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  1536000, 0, 0.855},
+    {100000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  1536000, 0, 0.240},
+    {  4000000, 0,   384000,  1536000, 0,   4000000, 0,   384000,  1536000, 0, 1.440},
+    {  4000000, 0,   384000,  1536000, 0,  20000000, 0,   384000,  1536000, 0, 3.000},
+    {  4000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 1.920},
+    { 20000000, 0,   384000,  1536000, 0,  20000000, 0,   384000,  1536000, 0, 1.563},
+    { 20000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 2.000},
+    {100000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 0.640},
+    {  4000000, 0,   384000,  3000000, 0,   4000000, 0,   384000,  1536000, 0, 0.240},
+    {  4000000, 0,   384000,  3000000, 0,  20000000, 0,   384000,  1536000, 0, 0.850},
+    {  4000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 1.720},
+    { 20000000, 0,   384000,  3000000, 0,  20000000, 0,   384000,  1536000, 0, 0.625},
+    { 20000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 2.025},
+    {100000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 1.040},
+    {  4000000, 0,   384000,   768000, 0,   4000000, 0,   128000,  3000000, 0, 0.120},
+    {  4000000, 0,   384000,   768000, 0,  20000000, 0,   128000,  3000000, 0, 0.420},
+    {  4000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  3000000, 0, 0.840},
+    { 20000000, 0,   384000,   768000, 0,  20000000, 0,   128000,  3000000, 0, 0.300},
+    { 20000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  3000000, 0, 0.930},
+    {100000000, 0,   384000,   768000, 0, 100000000, 0,   128000,  3000000, 0, 0.390},
+    {  4000000, 0,   384000,  1536000, 0,   4000000, 0,   384000,  3000000, 0, 0.240},
+    {  4000000, 0,   384000,  1536000, 0,  20000000, 0,   384000,  3000000, 0, 0.850},
+    {  4000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  3000000, 0, 1.720},
+    { 20000000, 0,   384000,  1536000, 0,  20000000, 0,   384000,  3000000, 0, 0.625},
+    { 20000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  3000000, 0, 2.025},
+    {100000000, 0,   384000,  1536000, 0, 100000000, 0,   384000,  3000000, 0, 1.040},
+    {  4000000, 0,   384000,  3000000, 0,   4000000, 0,   384000,  3000000, 0, 0.040},
+    {  4000000, 0,   384000,  3000000, 0,  20000000, 0,   384000,  3000000, 0, 0.200},
+    {  4000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  3000000, 0, 0.520},
+    { 20000000, 0,   384000,  3000000, 0,  20000000, 0,   384000,  3000000, 0, 0.250},
+    { 20000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  3000000, 0, 1.300},
+    {100000000, 0,   384000,  3000000, 0, 100000000, 0,   384000,  3000000, 0, 1.690},
+    {  4000000, 0,   128000,  1536000, 0,  20000000, 0,   768000,  1536000, 0, 0.090},
+    {  4000000, 0,   128000,  1536000, 0, 100000000, 0,   768000,  1536000, 0, 0.360},
+    { 20000000, 0,   128000,  1536000, 0,  20000000, 0,   768000,  1536000, 0, 0.090},
+    { 20000000, 0,   128000,  1536000, 0, 100000000, 0,   768000,  1536000, 0, 0.405},
+    {100000000, 0,   128000,  1536000, 0, 100000000, 0,   768000,  1536000, 0, 0.180},
+    {  4000000, 0,   128000,  7000000, 0,  20000000, 0,   768000,   768000, 0, 0.270},
+    {  4000000, 0,   128000,  7000000, 0, 100000000, 0,   768000,   768000, 0, 1.080},
+    { 20000000, 0,   128000,  7000000, 0,  20000000, 0,   768000,   768000, 0, 0.270},
+    { 20000000, 0,   128000,  7000000, 0, 100000000, 0,   768000,   768000, 0, 1.215},
+    {100000000, 0,   128000,  7000000, 0, 100000000, 0,   768000,   768000, 0, 0.540},
+    {  4000000, 0,   128000, 13000000, 0,  20000000, 0,   768000, 13000000, 0, 0.030},
+    {  4000000, 0,   128000, 13000000, 0, 100000000, 0,   768000, 13000000, 0, 0.120},
+    { 20000000, 0,   128000, 13000000, 0,  20000000, 0,   768000, 13000000, 0, 0.030},
+    { 20000000, 0,   128000, 13000000, 0, 100000000, 0,   768000, 13000000, 0, 0.135},
+    {100000000, 0,   128000, 13000000, 0, 100000000, 0,   768000, 13000000, 0, 0.060},
+    {  4000000, 0,   384000,  1536000, 0,  20000000, 0,  1536000,  1536000, 0, 0.180},
+    {  4000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  1536000, 0, 0.720},
+    { 20000000, 0,   384000,  1536000, 0,  20000000, 0,  1536000,  1536000, 0, 0.188},
+    { 20000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  1536000, 0, 0.870},
+    {100000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  1536000, 0, 0.480},
+    {  4000000, 0,   384000,  7000000, 0,  20000000, 0,   768000,  1536000, 0, 0.540},
+    {  4000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  1536000, 0, 2.160},
+    { 20000000, 0,   384000,  7000000, 0,  20000000, 0,   768000,  1536000, 0, 0.563},
+    { 20000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  1536000, 0, 2.610},
+    {100000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  1536000, 0, 1.440},
+    {  4000000, 0,   384000, 13000000, 0,  20000000, 0,  1536000, 13000000, 0, 0.060},
+    {  4000000, 0,   384000, 13000000, 0, 100000000, 0,  1536000, 13000000, 0, 0.240},
+    { 20000000, 0,   384000, 13000000, 0,  20000000, 0,  1536000, 13000000, 0, 0.063},
+    { 20000000, 0,   384000, 13000000, 0, 100000000, 0,  1536000, 13000000, 0, 0.290},
+    {100000000, 0,   384000, 13000000, 0, 100000000, 0,  1536000, 13000000, 0, 0.160},
+    {  4000000, 0,   384000,  1536000, 0,  20000000, 0,  1536000,  3000000, 0, 0.030},
+    {  4000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  3000000, 0, 0.120},
+    { 20000000, 0,   384000,  1536000, 0,  20000000, 0,  1536000,  3000000, 0, 0.075},
+    { 20000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  3000000, 0, 0.495},
+    {100000000, 0,   384000,  1536000, 0, 100000000, 0,  1536000,  3000000, 0, 0.780},
+    {  4000000, 0,   384000,  7000000, 0,  20000000, 0,   768000,  3000000, 0, 0.090},
+    {  4000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  3000000, 0, 0.360},
+    { 20000000, 0,   384000,  7000000, 0,  20000000, 0,   768000,  3000000, 0, 0.225},
+    { 20000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  3000000, 0, 1.485},
+    {100000000, 0,   384000,  7000000, 0, 100000000, 0,   768000,  3000000, 0, 2.340},
+    {  4000000, 0,   384000, 13000000, 0,  20000000, 0,  3000000, 13000000, 0, 0.010},
+    {  4000000, 0,   384000, 13000000, 0, 100000000, 0,  3000000, 13000000, 0, 0.040},
+    { 20000000, 0,   384000, 13000000, 0,  20000000, 0,  3000000, 13000000, 0, 0.025},
+    { 20000000, 0,   384000, 13000000, 0, 100000000, 0,  3000000, 13000000, 0, 0.165},
+    {100000000, 0,   384000, 13000000, 0, 100000000, 0,  3000000, 13000000, 0, 0.260},
+    {  4000000, 0,   768000,  1536000, 0,  20000000, 0,   128000,  1536000, 0, 0.090},
+    { 20000000, 0,   768000,  1536000, 0,  20000000, 0,   128000,  1536000, 0, 0.090},
+    { 20000000, 0,   768000,  1536000, 0, 100000000, 0,   128000,  1536000, 0, 0.405},
+    {  4000000, 0,   768000,  1536000, 0, 100000000, 0,   128000,  1536000, 0, 0.360},
+    {100000000, 0,   768000,  1536000, 0, 100000000, 0,   128000,  1536000, 0, 0.180},
+    {  4000000, 0,  1536000,  1536000, 0,  20000000, 0,   384000,  1536000, 0, 0.180},
+    { 20000000, 0,  1536000,  1536000, 0,  20000000, 0,   384000,  1536000, 0, 0.188},
+    { 20000000, 0,  1536000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 0.870},
+    {  4000000, 0,  1536000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 0.720},
+    {100000000, 0,  1536000,  1536000, 0, 100000000, 0,   384000,  1536000, 0, 0.480},
+    {  4000000, 0,  1536000,  3000000, 0,  20000000, 0,   384000,  1536000, 0, 0.030},
+    { 20000000, 0,  1536000,  3000000, 0,  20000000, 0,   384000,  1536000, 0, 0.075},
+    { 20000000, 0,  1536000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 0.495},
+    {  4000000, 0,  1536000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 0.120},
+    {100000000, 0,  1536000,  3000000, 0, 100000000, 0,   384000,  1536000, 0, 0.780},
+    {  4000000, 0,   768000,   768000, 0,  20000000, 0,   128000,  7000000, 0, 0.270},
+    { 20000000, 0,   768000,   768000, 0,  20000000, 0,   128000,  7000000, 0, 0.270},
+    { 20000000, 0,   768000,   768000, 0, 100000000, 0,   128000,  7000000, 0, 1.215},
+    {  4000000, 0,   768000,   768000, 0, 100000000, 0,   128000,  7000000, 0, 1.080},
+    {100000000, 0,   768000,   768000, 0, 100000000, 0,   128000,  7000000, 0, 0.540},
+    {  4000000, 0,   768000,  1536000, 0,  20000000, 0,   384000,  7000000, 0, 0.540},
+    { 20000000, 0,   768000,  1536000, 0,  20000000, 0,   384000,  7000000, 0, 0.563},
+    { 20000000, 0,   768000,  1536000, 0, 100000000, 0,   384000,  7000000, 0, 2.610},
+    {  4000000, 0,   768000,  1536000, 0, 100000000, 0,   384000,  7000000, 0, 2.160},
+    {100000000, 0,   768000,  1536000, 0, 100000000, 0,   384000,  7000000, 0, 1.440},
+    {  4000000, 0,   768000,  3000000, 0,  20000000, 0,   384000,  7000000, 0, 0.090},
+    { 20000000, 0,   768000,  3000000, 0,  20000000, 0,   384000,  7000000, 0, 0.225},
+    { 20000000, 0,   768000,  3000000, 0, 100000000, 0,   384000,  7000000, 0, 1.485},
+    {  4000000, 0,   768000,  3000000, 0, 100000000, 0,   384000,  7000000, 0, 0.360},
+    {100000000, 0,   768000,  3000000, 0, 100000000, 0,   384000,  7000000, 0, 2.340},
+    {  4000000, 0,   768000, 13000000, 0,  20000000, 0,   128000, 13000000, 0, 0.030},
+    { 20000000, 0,   768000, 13000000, 0,  20000000, 0,   128000, 13000000, 0, 0.030},
+    { 20000000, 0,   768000, 13000000, 0, 100000000, 0,   128000, 13000000, 0, 0.135},
+    {  4000000, 0,   768000, 13000000, 0, 100000000, 0,   128000, 13000000, 0, 0.120},
+    {100000000, 0,   768000, 13000000, 0, 100000000, 0,   128000, 13000000, 0, 0.060},
+    {  4000000, 0,  1536000, 13000000, 0,  20000000, 0,   384000, 13000000, 0, 0.060},
+    { 20000000, 0,  1536000, 13000000, 0,  20000000, 0,   384000, 13000000, 0, 0.063},
+    { 20000000, 0,  1536000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.290},
+    {  4000000, 0,  1536000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.240},
+    {100000000, 0,  1536000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.160},
+    {  4000000, 0,  3000000, 13000000, 0,  20000000, 0,   384000, 13000000, 0, 0.010},
+    { 20000000, 0,  3000000, 13000000, 0,  20000000, 0,   384000, 13000000, 0, 0.025},
+    { 20000000, 0,  3000000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.165},
+    {  4000000, 0,  3000000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.040},
+    {100000000, 0,  3000000, 13000000, 0, 100000000, 0,   384000, 13000000, 0, 0.260},
+    { 20000000, 0,  1536000,  1536000, 0,  20000000, 0,  1536000,  1536000, 0, 0.023},
+    { 20000000, 0,  1536000,  1536000, 0, 100000000, 0,  1536000,  1536000, 0, 0.180},
+    {100000000, 0,  1536000,  1536000, 0, 100000000, 0,  1536000,  1536000, 0, 0.360},
+    { 20000000, 0,  1536000,  7000000, 0,  20000000, 0,   768000,  1536000, 0, 0.068},
+    { 20000000, 0,  1536000,  7000000, 0, 100000000, 0,   768000,  1536000, 0, 0.540},
+    {100000000, 0,  1536000,  7000000, 0, 100000000, 0,   768000,  1536000, 0, 1.080},
+    { 20000000, 0,  1536000, 13000000, 0,  20000000, 0,  1536000, 13000000, 0, 0.015},
+    { 20000000, 0,  1536000, 13000000, 0, 100000000, 0,  1536000, 13000000, 0, 0.120},
+    {100000000, 0,  1536000, 13000000, 0, 100000000, 0,  1536000, 13000000, 0, 0.240},
+    { 20000000, 0,   768000,  1536000, 0,  20000000, 0,  1536000,  7000000, 0, 0.068},
+    { 20000000, 0,   768000,  1536000, 0, 100000000, 0,  1536000,  7000000, 0, 0.540},
+    {100000000, 0,   768000,  1536000, 0, 100000000, 0,  1536000,  7000000, 0, 1.080},
+    { 20000000, 0,   768000,  7000000, 0,  20000000, 0,   768000,  7000000, 0, 0.203},
+    { 20000000, 0,   768000,  7000000, 0, 100000000, 0,   768000,  7000000, 0, 1.620},
+    {100000000, 0,   768000,  7000000, 0, 100000000, 0,   768000,  7000000, 0, 3.240},
+    { 20000000, 0,   768000, 13000000, 0,  20000000, 0,  7000000, 13000000, 0, 0.023},
+    { 20000000, 0,   768000, 13000000, 0, 100000000, 0,  7000000, 13000000, 0, 0.180},
+    {100000000, 0,   768000, 13000000, 0, 100000000, 0,  7000000, 13000000, 0, 0.360},
+    { 20000000, 0,  7000000, 13000000, 0,  20000000, 0,   768000, 13000000, 0, 0.023},
+    { 20000000, 0,  7000000, 13000000, 0, 100000000, 0,   768000, 13000000, 0, 0.180},
+    {100000000, 0,  7000000, 13000000, 0, 100000000, 0,   768000, 13000000, 0, 0.360},
+    { 20000000, 0, 13000000, 13000000, 0,  20000000, 0, 13000000, 13000000, 0, 0.003},
+    { 20000000, 0, 13000000, 13000000, 0, 100000000, 0, 13000000, 13000000, 0, 0.020},
+    {100000000, 0, 13000000, 13000000, 0, 100000000, 0, 13000000, 13000000, 0, 0.040}
 };
 
 g1050_model_t g1050_standard_models[9] =

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/line_model.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/line_model.c	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/line_model.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: line_model.c,v 1.6 2008/07/02 14:48:25 steveu Exp $
+ * $Id: line_model.c,v 1.7 2008/11/30 10:17:30 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -46,6 +46,7 @@
 #include <math.h>
 #endif
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
 #include "spandsp.h"
 #include "spandsp-sim.h"
 #include "spandsp/g168models.h"

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/g1050.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/g1050.h	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/g1050.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g1050.h,v 1.8 2008/09/09 16:13:12 steveu Exp $
+ * $Id: g1050.h,v 1.9 2009/01/16 15:13:16 steveu Exp $
  */
 
 /*! \file */
@@ -39,7 +39,7 @@
  - a distant LAN (wired or wireless)
 The impairments typical of these segments at various service levels are modelled.
 8 standard service level behaviours are defined, covering lightly loaded to heavily
-congested levels. 133 standard sets of link speeds are defined, covering typical
+congested levels. 168 standard sets of link speeds are defined, covering typical
 wired and wireless LAN, broadband access link, and backbone characteristics.
 
 The G.1050 model is suitable for testing the behaviour of RTP, UDPTL and other streaming
@@ -261,7 +261,7 @@
 } g1050_state_t;
 
 extern g1050_constants_t g1050_constants[1];
-extern g1050_channel_speeds_t g1050_speed_patterns[133];
+extern g1050_channel_speeds_t g1050_speed_patterns[168];
 extern g1050_model_t g1050_standard_models[9];
 
 #ifdef  __cplusplus

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/line_model.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/line_model.h	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/line_model.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: line_model.h,v 1.3 2008/04/17 18:03:23 steveu Exp $
+ * $Id: line_model.h,v 1.4 2009/01/07 13:28:10 steveu Exp $
  */
 
 /*! \file */
@@ -56,6 +56,9 @@
 #if !defined(_SPANDSP_LINE_MODEL_H_)
 #define _SPANDSP_LINE_MODEL_H_
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+#include <spandsp.h>
+
 #define LINE_FILTER_SIZE 129
 
 /*!

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/test_utils.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/test_utils.h	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/spandsp/test_utils.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: test_utils.h,v 1.5 2008/08/29 09:28:13 steveu Exp $
+ * $Id: test_utils.h,v 1.6 2009/01/07 13:28:10 steveu Exp $
  */
 
 /*! \file */
@@ -30,6 +30,8 @@
 #if !defined(_TEST_UTILS_H_)
 #define _TEST_UTILS_H_
 
+#include <audiofile.h>
+
 enum
 {
     MUNGE_CODEC_NONE = 0,

Modified: freeswitch/trunk/libs/spandsp/spandsp-sim/test_utils.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp-sim/test_utils.c	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp-sim/test_utils.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: test_utils.c,v 1.8 2008/08/29 09:28:13 steveu Exp $
+ * $Id: test_utils.c,v 1.10 2008/11/30 10:17:30 steveu Exp $
  */
 
 /*! \file */
@@ -46,6 +46,7 @@
 #include <fcntl.h>
 #include <audiofile.h>
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Added: freeswitch/trunk/libs/spandsp/spandsp.pc
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/spandsp.pc	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=$(exec_prefix)/lib64
+includedir=${prefix}/include
+
+Name: spandsp
+Description: A DSP library for telephony.
+Requires:
+Version: 0.0.6
+Libs: -L${libdir} -lspandsp -ltiff -lm
+Cflags: -I${includedir}

Added: freeswitch/trunk/libs/spandsp/spandsp.pc.in
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/spandsp.pc.in	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: spandsp
+Description: A DSP library for telephony.
+Requires:
+Version: @VERSION@
+Libs: -L${libdir} -lspandsp -ltiff -lm
+Cflags: -I${includedir}

Modified: freeswitch/trunk/libs/spandsp/spandsp.spec
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp.spec	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp.spec	Tue Jan 27 22:48:03 2009
@@ -1,12 +1,12 @@
 Summary:    A DSP library for telephony.
 Name:       spandsp
-Version:    0.0.5
+Version:    0.0.6
 Release:    1
 License:    LGPL
 Group:      System Environment/Libraries
 URL:        http://www.soft-switch.org/spandsp
 BuildRoot:  %{_tmppath}/%{name}-%{version}-root
-Source:     http://www.soft-switch.org/downloads/spandsp/spandsp-0.0.5.tar.gz
+Source:     http://www.soft-switch.org/downloads/spandsp/spandsp-0.0.6.tar.gz
 BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildRequires: libtiff-devel
@@ -62,6 +62,7 @@
 %{_includedir}/spandsp.h
 %{_includedir}/spandsp
 %{_libdir}/libspandsp.so
+%{_libdir}/pkgconfig/spandsp.pc
 
 %post -p /sbin/ldconfig
 
@@ -72,7 +73,7 @@
 - Preparing for 0.0.5pre4 release
 - License: LGPL
 
-* Mon 23 Jun 2008 Steve Underwood <steveu at coppice.org> 0.0.5-1
+* Mon Jun 23 2008 Steve Underwood <steveu at coppice.org> 0.0.5-1
 - Cleared out the dependency on libxml2
 
 * Sun Dec 31 2006 Steve Underwood <steveu at coppice.org> 0.0.3-1

Modified: freeswitch/trunk/libs/spandsp/spandsp.spec.in
==============================================================================
--- freeswitch/trunk/libs/spandsp/spandsp.spec.in	(original)
+++ freeswitch/trunk/libs/spandsp/spandsp.spec.in	Tue Jan 27 22:48:03 2009
@@ -62,6 +62,7 @@
 %{_includedir}/spandsp.h
 %{_includedir}/spandsp
 %{_libdir}/libspandsp.so
+%{_libdir}/pkgconfig/spandsp.pc
 
 %post -p /sbin/ldconfig
 
@@ -72,7 +73,7 @@
 - Preparing for 0.0.5pre4 release
 - License: LGPL
 
-* Mon 23 Jun 2008 Steve Underwood <steveu at coppice.org> 0.0.5-1
+* Mon Jun 23 2008 Steve Underwood <steveu at coppice.org> 0.0.5-1
 - Cleared out the dependency on libxml2
 
 * Sun Dec 31 2006 Steve Underwood <steveu at coppice.org> 0.0.3-1

Modified: freeswitch/trunk/libs/spandsp/src/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/Makefile.am	(original)
+++ freeswitch/trunk/libs/spandsp/src/Makefile.am	Tue Jan 27 22:48:03 2009
@@ -16,7 +16,7 @@
 ## License along with this program; if not, write to the Free Software
 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ##
-## $Id: Makefile.am,v 1.105 2008/09/30 18:12:42 steveu Exp $
+## $Id: Makefile.am,v 1.116 2008/12/12 13:18:21 steveu Exp $
 
 AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
 AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
@@ -37,7 +37,8 @@
              msvc/msvcproj.head \
              msvc/msvcproj.foot \
              msvc/vc8proj.head \
-             msvc/vc8proj.foot
+             msvc/vc8proj.foot \
+             spandsp/private/README
 
 INCLUDES = -I$(top_builddir)
 
@@ -120,7 +121,7 @@
                         vector_float.c \
                         vector_int.c
 
-libspandsp_la_LDFLAGS = -version-info @SPANDSP_LT_CURRENT@:@SPANDSP_LT_REVISION@:@SPANDSP_LT_AGE@
+libspandsp_la_LDFLAGS = -version-info @SPANDSP_LT_CURRENT@:@SPANDSP_LT_REVISION@:@SPANDSP_LT_AGE@ $(COMP_VENDOR_FLAGS)
 
 nobase_include_HEADERS = spandsp/adsi.h \
                          spandsp/async.h \
@@ -196,7 +197,55 @@
                          spandsp/v8.h \
                          spandsp/vector_float.h \
                          spandsp/vector_int.h \
-                         spandsp/version.h
+                         spandsp/version.h \
+                         spandsp/private/adsi.h \
+                         spandsp/private/async.h \
+                         spandsp/private/at_interpreter.h \
+                         spandsp/private/awgn.h \
+                         spandsp/private/bell_r2_mf.h \
+                         spandsp/private/bert.h \
+                         spandsp/private/bitstream.h \
+                         spandsp/private/dtmf.h \
+                         spandsp/private/fax.h \
+                         spandsp/private/fax_modems.h \
+                         spandsp/private/fsk.h \
+                         spandsp/private/g711.h \
+                         spandsp/private/g722.h \
+                         spandsp/private/g726.h \
+                         spandsp/private/gsm0610.h \
+                         spandsp/private/hdlc.h \
+                         spandsp/private/ima_adpcm.h \
+                         spandsp/private/logging.h \
+                         spandsp/private/lpc10.h \
+                         spandsp/private/modem_connect_tones.h \
+                         spandsp/private/noise.h \
+                         spandsp/private/oki_adpcm.h \
+                         spandsp/private/queue.h \
+                         spandsp/private/schedule.h \
+                         spandsp/private/sig_tone.h \
+                         spandsp/private/super_tone_rx.h \
+                         spandsp/private/super_tone_tx.h \
+                         spandsp/private/t30.h \
+                         spandsp/private/t31.h \
+                         spandsp/private/t38_core.h \
+                         spandsp/private/t38_gateway.h \
+                         spandsp/private/t38_non_ecm_buffer.h \
+                         spandsp/private/t38_terminal.h \
+                         spandsp/private/t4.h \
+                         spandsp/private/time_scale.h \
+                         spandsp/private/tone_detect.h \
+                         spandsp/private/tone_generate.h \
+                         spandsp/private/v17rx.h \
+                         spandsp/private/v17tx.h \
+                         spandsp/private/v22bis.h \
+                         spandsp/private/v27ter_rx.h \
+                         spandsp/private/v27ter_tx.h \
+                         spandsp/private/v29rx.h \
+                         spandsp/private/v29tx.h \
+                         spandsp/private/v42.h \
+                         spandsp/private/v42bis.h \
+                         spandsp/private/v8.h \
+                         spandsp/expose.h
 
 nodist_include_HEADERS = spandsp.h
 

Modified: freeswitch/trunk/libs/spandsp/src/adsi.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/adsi.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/adsi.c	Tue Jan 27 22:48:03 2009
@@ -23,26 +23,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: adsi.c,v 1.60 2008/09/07 12:45:16 steveu Exp $
+ * $Id: adsi.c,v 1.67 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
 #include "spandsp/telephony.h"
@@ -60,6 +60,14 @@
 #include "spandsp/dtmf.h"
 #include "spandsp/adsi.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/queue.h"
+#include "spandsp/private/tone_generate.h"
+#include "spandsp/private/async.h"
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/dtmf.h"
+#include "spandsp/private/adsi.h"
+
 #define BAUDOT_FIGURE_SHIFT     0x1B
 #define BAUDOT_LETTER_SHIFT     0x1F
 
@@ -440,6 +448,13 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+int adsi_rx_free(adsi_rx_state_t *s)
+{
+    free(s);
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 int adsi_tx(adsi_tx_state_t *s, int16_t *amp, int max_len)
 {
     int len;
@@ -642,6 +657,13 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+int adsi_tx_free(adsi_tx_state_t *s)
+{
+    free(s);
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 static uint16_t adsi_encode_baudot(adsi_tx_state_t *s, uint8_t ch)
 {
     static const uint8_t conv[128] =

Modified: freeswitch/trunk/libs/spandsp/src/async.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/async.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/async.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: async.c,v 1.13 2008/09/07 12:45:16 steveu Exp $
+ * $Id: async.c,v 1.15 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
@@ -39,6 +39,8 @@
 #include "spandsp/telephony.h"
 #include "spandsp/async.h"
 
+#include "spandsp/private/async.h"
+
 const char *signal_status_to_str(int status)
 {
     switch (status)

Modified: freeswitch/trunk/libs/spandsp/src/at_interpreter.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/at_interpreter.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/at_interpreter.c	Tue Jan 27 22:48:03 2009
@@ -25,13 +25,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: at_interpreter.c,v 1.30 2008/07/24 13:55:23 steveu Exp $
+ * $Id: at_interpreter.c,v 1.34 2009/01/16 15:13:16 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
@@ -55,6 +55,9 @@
 
 #include "spandsp/at_interpreter.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/at_interpreter.h"
+
 #define ms_to_samples(t)        (((t)*SAMPLE_RATE)/1000)
 
 #define MANUFACTURER            "www.soft-switch.org"
@@ -180,6 +183,7 @@
 {
     uint8_t buf[20];
 
+    span_log(&s->logging, SPAN_LOG_FLOW, "Sending AT response code %s\n", at_response_codes[code]);
     switch (s->p.result_code_format)
     {
     case ASCII_RESULT_CODES:
@@ -239,7 +243,7 @@
         }
         break;
     case AT_CALL_EVENT_CONNECTED:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Dial call - connected. fclass=%d\n", s->fclass_mode);
+        span_log(&s->logging, SPAN_LOG_FLOW, "Dial call - connected. FCLASS=%d\n", s->fclass_mode);
         at_modem_control(s, AT_MODEM_CONTROL_RNG, (void *) 0);
         if (s->fclass_mode == 0)
         {
@@ -309,8 +313,8 @@
 
 void at_reset_call_info(at_state_t *s)
 {
-    struct at_call_id *call_id;
-    struct at_call_id *next;
+    at_call_id_t *call_id;
+    at_call_id_t *next;
  
     for (call_id = s->call_id;  call_id;  call_id = next)
     {
@@ -325,11 +329,11 @@
 
 void at_set_call_info(at_state_t *s, char const *id, char const *value)
 {
-    struct at_call_id *new_call_id;
-    struct at_call_id *call_id;
+    at_call_id_t *new_call_id;
+    at_call_id_t *call_id;
 
     /* TODO: We should really not merely ignore a failure to malloc */
-    if ((new_call_id = (struct at_call_id *) malloc(sizeof(*new_call_id))) == NULL)
+    if ((new_call_id = (at_call_id_t *) malloc(sizeof(*new_call_id))) == NULL)
         return;
     call_id = s->call_id;
     /* If these strdups fail its pretty harmless. We just appear to not
@@ -354,7 +358,7 @@
 void at_display_call_info(at_state_t *s)
 {
     char buf[132 + 1];
-    struct at_call_id *call_id = s->call_id;
+    at_call_id_t *call_id = s->call_id;
 
     while (call_id)
     {
@@ -5299,6 +5303,8 @@
             return NULL;
     }
     memset(s, '\0', sizeof(*s));
+    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
+    span_log_set_protocol(&s->logging, "AT");
     s->modem_control_handler = modem_control_handler;
     s->modem_control_user_data = modem_control_user_data;
     s->at_tx_handler = at_tx_handler;

Modified: freeswitch/trunk/libs/spandsp/src/awgn.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/awgn.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/awgn.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: awgn.c,v 1.17 2008/09/19 14:02:05 steveu Exp $
+ * $Id: awgn.c,v 1.20 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
@@ -43,23 +43,25 @@
    to ever be optimised. */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/saturated.h"
 #include "spandsp/awgn.h"
 
+#include "spandsp/private/awgn.h"
+
 /* Gaussian noise generator constants */
 #define M1 259200
 #define IA1 7141

Modified: freeswitch/trunk/libs/spandsp/src/bell_r2_mf.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/bell_r2_mf.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/bell_r2_mf.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bell_r2_mf.c,v 1.29 2008/07/02 14:48:25 steveu Exp $
+ * $Id: bell_r2_mf.c,v 1.33 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
@@ -36,13 +36,13 @@
 #include <string.h>
 #include <time.h>
 #include <fcntl.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/queue.h"
@@ -55,6 +55,10 @@
 #include "spandsp/dtmf.h"
 #include "spandsp/bell_r2_mf.h"
 
+#include "spandsp/private/queue.h"
+#include "spandsp/private/tone_generate.h"
+#include "spandsp/private/bell_r2_mf.h"
+
 #if !defined(M_PI)
 /* C99 systems may not define M_PI */
 #define M_PI 3.14159265358979323846264338327

Modified: freeswitch/trunk/libs/spandsp/src/bert.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/bert.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/bert.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bert.c,v 1.28 2008/09/07 12:45:16 steveu Exp $
+ * $Id: bert.c,v 1.30 2008/11/30 13:44:35 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -41,6 +41,9 @@
 #include "spandsp/async.h"
 #include "spandsp/bert.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/bert.h"
+
 static const char *qbf = "VoyeZ Le BricK GeanT QuE J'ExaminE PreS Du WharF 123 456 7890 + - * : = $ % ( )"
                          "ThE QuicK BrowN FoX JumpS OveR ThE LazY DoG 123 456 7890 + - * : = $ % ( )";
 

Modified: freeswitch/trunk/libs/spandsp/src/bitstream.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/bitstream.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/bitstream.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bitstream.c,v 1.13 2008/05/13 13:17:22 steveu Exp $
+ * $Id: bitstream.c,v 1.16 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
@@ -39,7 +39,9 @@
 #include "spandsp/telephony.h"
 #include "spandsp/bitstream.h"
 
-void bitstream_put(bitstream_state_t *s, uint8_t **c, unsigned int value, int bits)
+#include "spandsp/private/bitstream.h"
+
+void bitstream_put(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits)
 {
     value &= ((1 << bits) - 1);
     if (s->residue + bits <= 32)
@@ -56,7 +58,7 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-void bitstream_put2(bitstream_state_t *s, uint8_t **c, unsigned int value, int bits)
+void bitstream_put2(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits)
 {
     value &= ((1 << bits) - 1);
     if (s->residue + bits <= 32)
@@ -72,14 +74,13 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-unsigned int bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits)
+uint32_t bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits)
 {
-    unsigned int x;
+    uint32_t x;
 
-    while (s->residue < (unsigned int) bits)
+    while (s->residue < bits)
     {
-        x = (unsigned int) *(*c)++;
-        s->bitstream |= (x << s->residue);
+        s->bitstream |= (((uint32_t) *(*c)++) << s->residue);
         s->residue += 8;
     }
     s->residue -= bits;
@@ -89,14 +90,13 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-unsigned int bitstream_get2(bitstream_state_t *s, const uint8_t **c, int bits)
+uint32_t bitstream_get2(bitstream_state_t *s, const uint8_t **c, int bits)
 {
-    unsigned int x;
+    uint32_t x;
 
-    while (s->residue < (unsigned int) bits)
+    while (s->residue < bits)
     {
-        x = (unsigned int) *(*c)++;
-        s->bitstream = (s->bitstream << 8) | x;
+        s->bitstream = (s->bitstream << 8) | ((uint32_t) *(*c)++);
         s->residue += 8;
     }
     s->residue -= bits;

Modified: freeswitch/trunk/libs/spandsp/src/complex_filters.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/complex_filters.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/complex_filters.c	Tue Jan 27 22:48:03 2009
@@ -22,11 +22,11 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_filters.c,v 1.13 2008/05/13 13:17:22 steveu Exp $
+ * $Id: complex_filters.c,v 1.14 2009/01/05 13:48:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>

Modified: freeswitch/trunk/libs/spandsp/src/complex_vector_float.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/complex_vector_float.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/complex_vector_float.c	Tue Jan 27 22:48:03 2009
@@ -22,34 +22,132 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_vector_float.c,v 1.10 2008/09/18 13:16:49 steveu Exp $
+ * $Id: complex_vector_float.c,v 1.14 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
+#if defined(SPANDSP_USE_MMX)
+#include <mmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE)
+#include <xmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE2)
+#include <emmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE3)
+#include <pmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_1)
+#include <smmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_2)
+#include <nmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4A)
+#include <ammintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE5)
+#include <bmmintrin.h>
+#endif
+
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
 #include "spandsp/complex.h"
 #include "spandsp/vector_float.h"
 #include "spandsp/complex_vector_float.h"
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE3)
+void cvec_mulf(complexf_t z[], const complexf_t x[], const complexf_t y[], int n)
+{
+    int i;
+    __m128 n0;
+    __m128 n1;
+    __m128 n2;
+    __m128 n3;
+
+    if ((i = n & ~1))
+    {
+        i <<= 1;
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n3 = _mm_loadu_ps((float *) x + i);
+            n0 = _mm_moveldup_ps(n3);
+            n1 = _mm_loadu_ps((float *) y + i);
+            n0 = _mm_mul_ps(n0, n1);
+            n1 = _mm_shuffle_ps(n1, n1, 0xB1);
+            n2 = _mm_movehdup_ps(n3);
+            n2 = _mm_mul_ps(n2, n1);
+            n0 = _mm_addsub_ps(n0, n2);
+            _mm_storeu_ps((float *) z + i, n0);
+        }
+    }
+    /* Now deal with the last element, which doesn't fill an SSE2 register */
+    switch (n & 1)
+    {
+    case 1:
+        z[n - 1].re = x[n - 1].re*y[n - 1].re - x[n - 1].im*y[n - 1].im;
+        z[n - 1].im = x[n - 1].re*y[n - 1].im + x[n - 1].im*y[n - 1].re;
+    }
+}
+#else
+void cvec_mulf(complexf_t z[], const complexf_t x[], const complexf_t y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+    {
+        z[i].re = x[i].re*y[i].re - x[i].im*y[i].im;
+        z[i].im = x[i].re*y[i].im + x[i].im*y[i].re;
+    }
+}
+#endif
+/*- End of function --------------------------------------------------------*/
+
+void cvec_mul(complex_t z[], const complex_t x[], const complex_t y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+    {
+        z[i].re = x[i].re*y[i].re - x[i].im*y[i].im;
+        z[i].im = x[i].re*y[i].im + x[i].im*y[i].re;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
+#if defined(HAVE_LONG_DOUBLE)
+void cvec_mull(complexl_t z[], const complexl_t x[], const complexl_t y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+    {
+        z[i].re = x[i].re*y[i].re - x[i].im*y[i].im;
+        z[i].im = x[i].re*y[i].im + x[i].im*y[i].re;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+#endif
+
 complexf_t cvec_dot_prodf(const complexf_t x[], const complexf_t y[], int n)
 {
     int i;
@@ -109,17 +207,17 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+#define LMS_LEAK_RATE   0.9999f
+
 void cvec_lmsf(const complexf_t x[], complexf_t y[], int n, const complexf_t *error)
 {
     int i;
 
     for (i = 0;  i < n;  i++)
     {
-        y[i].re += (x[i].im*error->im + x[i].re*error->re);
-        y[i].im += (x[i].re*error->im - x[i].im*error->re);
         /* Leak a little to tame uncontrolled wandering */
-        y[i].re *= 0.9999f;
-        y[i].im *= 0.9999f;
+        y[i].re = y[i].re*LMS_LEAK_RATE + (x[i].im*error->im + x[i].re*error->re);
+        y[i].im = y[i].im*LMS_LEAK_RATE + (x[i].re*error->im - x[i].im*error->re);
     }
 }
 /*- End of function --------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/complex_vector_int.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/complex_vector_int.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/complex_vector_int.c	Tue Jan 27 22:48:03 2009
@@ -22,28 +22,53 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_vector_int.c,v 1.3 2008/09/18 13:54:32 steveu Exp $
+ * $Id: complex_vector_int.c,v 1.6 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
+#if defined(SPANDSP_USE_MMX)
+#include <mmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE)
+#include <xmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE2)
+#include <emmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE3)
+#include <pmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_1)
+#include <smmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_2)
+#include <nmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4A)
+#include <ammintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE5)
+#include <bmmintrin.h>
+#endif
+
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
 #include "spandsp/complex.h"

Modified: freeswitch/trunk/libs/spandsp/src/crc.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/crc.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/crc.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: crc.c,v 1.4 2008/05/13 13:17:22 steveu Exp $
+ * $Id: crc.c,v 1.5 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>

Modified: freeswitch/trunk/libs/spandsp/src/dds_float.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/dds_float.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/dds_float.c	Tue Jan 27 22:48:03 2009
@@ -22,24 +22,24 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dds_float.c,v 1.8 2008/07/02 14:48:25 steveu Exp $
+ * $Id: dds_float.c,v 1.10 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/complex.h"

Modified: freeswitch/trunk/libs/spandsp/src/dds_int.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/dds_int.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/dds_int.c	Tue Jan 27 22:48:03 2009
@@ -22,23 +22,23 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dds_int.c,v 1.11 2008/09/11 15:13:42 steveu Exp $
+ * $Id: dds_int.c,v 1.13 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/complex.h"

Modified: freeswitch/trunk/libs/spandsp/src/dtmf.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/dtmf.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/dtmf.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dtmf.c,v 1.43 2008/07/02 14:48:25 steveu Exp $
+ * $Id: dtmf.c,v 1.47 2009/01/28 03:41:26 steveu Exp $
  */
  
 /*! \file dtmf.h */
@@ -33,13 +33,13 @@
 
 #include <inttypes.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <string.h>
 #include <stdio.h>
 #include <time.h>
@@ -54,6 +54,10 @@
 #include "spandsp/super_tone_rx.h"
 #include "spandsp/dtmf.h"
 
+#include "spandsp/private/queue.h"
+#include "spandsp/private/tone_generate.h"
+#include "spandsp/private/dtmf.h"
+
 #define DEFAULT_DTMF_TX_LEVEL       -10
 #define DEFAULT_DTMF_TX_ON_TIME     50
 #define DEFAULT_DTMF_TX_OFF_TIME    55

Modified: freeswitch/trunk/libs/spandsp/src/echo.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/echo.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/echo.c	Tue Jan 27 22:48:03 2009
@@ -27,7 +27,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: echo.c,v 1.28 2008/09/19 14:02:05 steveu Exp $
+ * $Id: echo.c,v 1.30 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
@@ -79,18 +79,18 @@
    reasonable way. */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <string.h>
 #include <stdio.h>
 

Modified: freeswitch/trunk/libs/spandsp/src/fax.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/fax.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/fax.c	Tue Jan 27 22:48:03 2009
@@ -23,26 +23,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax.c,v 1.79 2008/08/13 00:11:30 steveu Exp $
+ * $Id: fax.c,v 1.84 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <fcntl.h>
 #include <time.h>
@@ -63,12 +63,12 @@
 #include "spandsp/hdlc.h"
 #include "spandsp/silence_gen.h"
 #include "spandsp/fsk.h"
-#include "spandsp/v29rx.h"
 #include "spandsp/v29tx.h"
-#include "spandsp/v27ter_rx.h"
+#include "spandsp/v29rx.h"
 #include "spandsp/v27ter_tx.h"
-#include "spandsp/v17rx.h"
+#include "spandsp/v27ter_rx.h"
 #include "spandsp/v17tx.h"
+#include "spandsp/v17rx.h"
 #include "spandsp/super_tone_rx.h"
 #include "spandsp/modem_connect_tones.h"
 #include "spandsp/t4.h"
@@ -82,6 +82,21 @@
 #include "spandsp/fax_modems.h"
 #include "spandsp/fax.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/v17tx.h"
+#include "spandsp/private/v17rx.h"
+#include "spandsp/private/v27ter_tx.h"
+#include "spandsp/private/v27ter_rx.h"
+#include "spandsp/private/v29tx.h"
+#include "spandsp/private/v29rx.h"
+#include "spandsp/private/modem_connect_tones.h"
+#include "spandsp/private/hdlc.h"
+#include "spandsp/private/fax_modems.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+#include "spandsp/private/fax.h"
+
 #define HDLC_FRAMING_OK_THRESHOLD       5
 
 static void fax_send_hdlc(void *user_data, const uint8_t *msg, int len)
@@ -517,6 +532,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *fax_get_logging_state(fax_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 fax_state_t *fax_init(fax_state_t *s, int calling_party)
 {
     if (s == NULL)

Modified: freeswitch/trunk/libs/spandsp/src/filter_tools.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/filter_tools.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/filter_tools.c	Tue Jan 27 22:48:03 2009
@@ -25,7 +25,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: filter_tools.c,v 1.8 2008/08/29 09:28:13 steveu Exp $
+ * $Id: filter_tools.c,v 1.9 2009/01/28 03:41:26 steveu Exp $
  */
  
 #if defined(HAVE_CONFIG_H)
@@ -35,13 +35,13 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <string.h>
 #include <stdio.h>
 #include <time.h>

Modified: freeswitch/trunk/libs/spandsp/src/fsk.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/fsk.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/fsk.c	Tue Jan 27 22:48:03 2009
@@ -22,25 +22,25 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fsk.c,v 1.46 2008/09/07 12:45:16 steveu Exp $
+ * $Id: fsk.c,v 1.49 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
 #include "spandsp/telephony.h"
@@ -50,6 +50,8 @@
 #include "spandsp/async.h"
 #include "spandsp/fsk.h"
 
+#include "spandsp/private/fsk.h"
+
 const fsk_spec_t preset_fsk_specs[] =
 {
     {

Modified: freeswitch/trunk/libs/spandsp/src/g711.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/g711.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/g711.c	Tue Jan 27 22:48:03 2009
@@ -22,30 +22,24 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g711.c,v 1.11 2008/07/02 14:48:25 steveu Exp $
+ * $Id: g711.c,v 1.14 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
-#if defined(HAVE_TGMATH_H)
-#include <tgmath.h>
-#endif
-#if defined(HAVE_MATH_H)
-#include <math.h>
-#endif
 #include <assert.h>
 
 #include "spandsp/telephony.h"
 #include "spandsp/bit_operations.h"
 #include "spandsp/g711.h"
+#include "spandsp/private/g711.h"
 
 /* Copied from the CCITT G.711 specification */
 static const uint8_t ulaw_to_alaw_table[256] =

Modified: freeswitch/trunk/libs/spandsp/src/g722.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/g722.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/g722.c	Tue Jan 27 22:48:03 2009
@@ -28,31 +28,33 @@
  * Computer Science, Speech Group
  * Chengxiang Lu and Alex Hauptmann
  *
- * $Id: g722.c,v 1.2 2008/09/19 16:24:25 steveu Exp $
+ * $Id: g722.c,v 1.5 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <memory.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/saturated.h"
 #include "spandsp/vector_int.h"
 #include "spandsp/g722.h"
 
+#include "spandsp/private/g722.h"
+
 static const int16_t qmf_coeffs_fwd[12] =
 {
       3,  -11,   12,   32, -210,  951, 3876, -805,  362, -156,   53,  -11,

Modified: freeswitch/trunk/libs/spandsp/src/g726.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/g726.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/g726.c	Tue Jan 27 22:48:03 2009
@@ -48,25 +48,25 @@
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  *
- * $Id: g726.c,v 1.22 2008/07/02 14:48:25 steveu Exp $
+ * $Id: g726.c,v 1.26 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <memory.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
@@ -75,6 +75,9 @@
 #include "spandsp/g711.h"
 #include "spandsp/g726.h"
 
+#include "spandsp/private/bitstream.h"
+#include "spandsp/private/g726.h"
+
 /*
  * Maps G.726_16 code word to reconstructed scale factor normalized log
  * magnitude values.

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_decode.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_decode.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_decode.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_decode.c,v 1.22 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_decode.c,v 1.24 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 #include <memory.h>
 

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_encode.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_encode.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_encode.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_encode.c,v 1.26 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_encode.c,v 1.28 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 #include <memory.h>
 

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_local.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_local.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_local.h	Tue Jan 27 22:48:03 2009
@@ -25,7 +25,7 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_local.h,v 1.10 2008/04/17 14:26:56 steveu Exp $
+ * $Id: gsm0610_local.h,v 1.13 2009/01/16 15:49:59 steveu Exp $
  */
 
 #if !defined(_GSM0610_LOCAL_H_)
@@ -35,16 +35,18 @@
 
 #define	GSM0610_MAGIC                   0xD
 
+#include "spandsp/private/gsm0610.h"
+
 static __inline__ int16_t gsm_add(int16_t a, int16_t b)
 {
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     __asm__ __volatile__(
         " addw %2,%0;\n"
         " jno 0f;\n"
         " movw $0x7fff,%0;\n"
         " adcw $0,%0;\n"
         "0:"
-        : "=r" (a)
+        : "=&r" (a)
         : "0" (a), "ir" (b)
         : "cc"
     );
@@ -60,14 +62,14 @@
 
 static __inline__ int32_t gsm_l_add(int32_t a, int32_t b)
 {
-#if defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     __asm__ __volatile__(
         " addl %2,%0;\n"
         " jno 0f;\n"
         " movl $0x7fffffff,%0;\n"
         " adcl $0,%0;\n"
         "0:"
-        : "=r" (a)
+        : "=&r" (a)
         : "0" (a), "ir" (b)
         : "cc"
     );

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_long_term.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_long_term.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_long_term.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_long_term.c,v 1.17 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_long_term.c,v 1.20 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 
 #include "spandsp/telephony.h"
@@ -66,12 +66,82 @@
 
 /* 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION */
 
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
 int32_t gsm0610_max_cross_corr(const int16_t *wt, const int16_t *dp, int16_t *Nc_out)
 {
     int32_t lmax;
     int32_t out;
 
+#if defined(__x86_64__)
+    __asm__ __volatile__(
+        " emms;\n"
+        " pushq %%rbx;\n"
+        " movl $0,%%edx;\n"             /* Will be maximum inner-product */
+        " movl $40,%%ebx;\n"
+        " movl %%ebx,%%ecx;\n"          /* Will be index of max inner-product */
+        " subq $80,%%rsi;\n"
+        " .p2align 2;\n"
+        "1:\n"
+        " movq (%%rdi),%%mm0;\n"
+        " movq (%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm0;\n"
+        " movq 8(%%rdi),%%mm1;\n"
+        " movq 8(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 16(%%rdi),%%mm1;\n"
+        " movq 16(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 24(%%rdi),%%mm1;\n"
+        " movq 24(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 32(%%rdi),%%mm1;\n"
+        " movq 32(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 40(%%rdi),%%mm1;\n"
+        " movq 40(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 48(%%rdi),%%mm1;\n"
+        " movq 48(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 56(%%rdi),%%mm1;\n"
+        " movq 56(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 64(%%rdi),%%mm1;\n"
+        " movq 64(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 72(%%rdi),%%mm1;\n"
+        " movq 72(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq %%mm0,%%mm1;\n"
+        " punpckhdq %%mm0,%%mm1;\n"        /* mm1 has high int32 of mm0 dup'd */
+        " paddd %%mm1,%%mm0;\n"
+        " movd %%mm0,%%eax;\n"                /* eax has result */
+        " cmpl %%edx,%%eax;\n"
+        " jle 2f;\n"
+        " movl %%eax,%%edx;\n"
+        " movl %%ebx,%%ecx;\n"
+        " .p2align 2;\n"
+        "2:\n"
+        " subq $2,%%rsi;\n"
+        " incl %%ebx;\n"
+        " cmpq $120,%%rbx;\n"
+        " jle 1b;\n"
+        " popq %%rbx;\n"
+        " emms;\n"
+        : "=d" (lmax), "=c" (out)
+        : "D" (wt), "S" (dp)
+        : "eax"
+    );
+#else
     __asm__ __volatile__(
         " emms;\n"
         " pushl %%ebx;\n"
@@ -140,6 +210,7 @@
         : "D" (wt), "S" (dp)
         : "eax"
     );
+#endif
     *Nc_out = out;
     return  lmax;
 }
@@ -176,7 +247,7 @@
     int16_t scale;
     int16_t temp;
     int32_t L_temp;
-#if !(defined(__GNUC__)  &&  defined(__i386__))
+#if !(defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX))
     int16_t lambda;
 #endif
 
@@ -216,7 +287,7 @@
     /*endfor*/
 
     /* Search for the maximum cross-correlation and coding of the LTP lag */
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     L_max = gsm0610_max_cross_corr(wt, dp, &Nc);
 #else
     L_max = 0;

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_lpc.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_lpc.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_lpc.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_lpc.c,v 1.22 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_lpc.c,v 1.27 2009/01/28 03:41:26 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 #include <memory.h>
 
@@ -133,7 +133,7 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
 void gsm0610_vec_vsraw(const int16_t *p, int n, int bits)
 {
     static const int64_t ones = 0x0001000100010001LL;
@@ -141,6 +141,70 @@
     if (n == 0)
         return;
     /*endif*/
+#if defined(__x86_64__)
+    __asm__ __volatile__(
+        " leaq -16(%%rsi,%%rax,2),%%rdx;\n"         /* edx = top - 16 */
+        " emms;\n"
+        " movd %%ecx,%%mm3;\n"
+        " movq %[ones],%%mm2;\n"
+        " psllw %%mm3,%%mm2;\n"
+        " psrlw $1,%%mm2;\n"
+        " cmpq %%rdx,%%rsi;"
+        " ja 4f;\n"
+
+         " .p2align 2;\n"
+        /* 8 words per iteration */
+        "6:\n"
+        " movq (%%rsi),%%mm0;\n"
+        " movq 8(%%rsi),%%mm1;\n"
+        " paddsw %%mm2,%%mm0;\n"
+        " psraw %%mm3,%%mm0;\n"
+        " paddsw %%mm2,%%mm1;\n"
+        " psraw %%mm3,%%mm1;\n"
+        " movq %%mm0,(%%rsi);\n"
+        " movq %%mm1,8(%%rsi);\n"
+        " addq $16,%%rsi;\n"
+        " cmpq %%rdx,%%rsi;\n"
+        " jbe 6b;\n"
+
+        " .p2align 2;\n"
+        "4:\n"
+        " addq $12,%%rdx;\n"                        /* now edx = top-4 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 3f;\n"
+
+        " .p2align 2;\n"
+        /* do up to 6 words, two per iteration */
+        "5:\n"
+        " movd (%%rsi),%%mm0;\n"
+        " paddsw %%mm2,%%mm0;\n"
+        " psraw %%mm3,%%mm0;\n"
+        " movd %%mm0,(%%rsi);\n"
+        " addq $4,%%rsi;\n"
+        " cmpq %%rdx,%%rsi;\n"
+        " jbe 5b;\n"
+
+        " .p2align 2;\n"
+        "3:\n"
+        " addq $2,%%rdx;\n"                        /* now edx = top-2 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 2f;\n"
+        
+        " movzwl (%%rsi),%%eax;\n"
+        " movd %%eax,%%mm0;\n"
+        " paddsw %%mm2,%%mm0;\n"
+        " psraw %%mm3,%%mm0;\n"
+        " movd %%mm0,%%eax;\n"
+        " movw %%ax,(%%rsi);\n"
+
+        " .p2align 2;\n"
+        "2:\n"
+        " emms;\n"
+        :
+        : "S" (p), "a" (n), "c" (bits), [ones] "m" (ones)
+        : "edx"
+    );
+#else
     __asm__ __volatile__(
         " leal -16(%%esi,%%eax,2),%%edx;\n"         /* edx = top - 16 */
         " emms;\n"
@@ -175,7 +239,7 @@
         " .p2align 2;\n"
         /* do up to 6 words, two per iteration */
         "5:\n"
-        " movd  (%%esi),%%mm0;\n"
+        " movd (%%esi),%%mm0;\n"
         " paddsw %%mm2,%%mm0;\n"
         " psraw %%mm3,%%mm0;\n"
         " movd %%mm0,(%%esi);\n"
@@ -203,6 +267,7 @@
         : "S" (p), "a" (n), "c" (bits), [ones] "m" (ones)
         : "edx"
     );
+#endif
 }
 /*- End of function --------------------------------------------------------*/
 #endif
@@ -213,7 +278,7 @@
     int k;
     int16_t smax;
     int16_t scalauto;
-#if !(defined(__GNUC__)  &&  defined(__i386__))
+#if !(defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX))
     int i;
     int temp;
     int16_t *sp;
@@ -225,7 +290,7 @@
 
     /* Dynamic scaling of the array  s[0..159] */
     /* Search for the maximum. */
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     smax = saturate(vec_min_maxi16(amp, GSM0610_FRAME_LEN, NULL));
 #else
     for (smax = 0, k = 0;  k < GSM0610_FRAME_LEN;  k++)
@@ -251,7 +316,7 @@
     /*endif*/
 
     /* Scaling of the array s[0...159] */
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     if (scalauto > 0)
         gsm0610_vec_vsraw(amp, GSM0610_FRAME_LEN, scalauto);
     /*endif*/
@@ -266,78 +331,78 @@
 #endif
 
     /* Compute the L_ACF[..]. */
-#if defined(__GNUC__)  &&  defined(__i386__)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
     for (k = 0;  k < 9;  k++)
         L_ACF[k] = vec_dot_prodi16(amp, amp + k, GSM0610_FRAME_LEN - k) << 1;
     /*endfor*/
 #else
     sp = amp;
     sl = *sp;
-    L_ACF[0] = ((int32_t) sl*sp[0]);
+    L_ACF[0] = ((int32_t) sl*(int32_t) sp[0]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] = ((int32_t) sl*sp[-1]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] = ((int32_t) sl*(int32_t) sp[-1]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] = ((int32_t) sl*sp[-2]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] = ((int32_t) sl*(int32_t) sp[-2]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] = ((int32_t) sl*sp[-3]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] = ((int32_t) sl*(int32_t) sp[-3]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] += ((int32_t) sl*sp[-3]);
-    L_ACF[4] = ((int32_t) sl*sp[-4]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+    L_ACF[4] = ((int32_t) sl*(int32_t) sp[-4]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] += ((int32_t) sl*sp[-3]);
-    L_ACF[4] += ((int32_t) sl*sp[-4]);
-    L_ACF[5] = ((int32_t) sl*sp[-5]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+    L_ACF[4] += ((int32_t) sl*(int32_t) sp[-4]);
+    L_ACF[5] = ((int32_t) sl*(int32_t) sp[-5]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] += ((int32_t) sl*sp[-3]);
-    L_ACF[4] += ((int32_t) sl*sp[-4]);
-    L_ACF[5] += ((int32_t) sl*sp[-5]);
-    L_ACF[6] = ((int32_t) sl*sp[-6]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+    L_ACF[4] += ((int32_t) sl*(int32_t) sp[-4]);
+    L_ACF[5] += ((int32_t) sl*(int32_t) sp[-5]);
+    L_ACF[6] = ((int32_t) sl*(int32_t) sp[-6]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] += ((int32_t) sl*sp[-3]);
-    L_ACF[4] += ((int32_t) sl*sp[-4]);
-    L_ACF[5] += ((int32_t) sl*sp[-5]);
-    L_ACF[6] += ((int32_t) sl*sp[-6]);
-    L_ACF[7] = ((int32_t) sl*sp[-7]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+    L_ACF[4] += ((int32_t) sl*(int32_t) sp[-4]);
+    L_ACF[5] += ((int32_t) sl*(int32_t) sp[-5]);
+    L_ACF[6] += ((int32_t) sl*(int32_t) sp[-6]);
+    L_ACF[7] = ((int32_t) sl*(int32_t) sp[-7]);
     sl = *++sp;
-    L_ACF[0] += ((int32_t) sl*sp[0]);
-    L_ACF[1] += ((int32_t) sl*sp[-1]);
-    L_ACF[2] += ((int32_t) sl*sp[-2]);
-    L_ACF[3] += ((int32_t) sl*sp[-3]);
-    L_ACF[4] += ((int32_t) sl*sp[-4]);
-    L_ACF[5] += ((int32_t) sl*sp[-5]);
-    L_ACF[6] += ((int32_t) sl*sp[-6]);
-    L_ACF[7] += ((int32_t) sl*sp[-7]);
-    L_ACF[8] = ((int32_t) sl*sp[-8]);
+    L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+    L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+    L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+    L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+    L_ACF[4] += ((int32_t) sl*(int32_t) sp[-4]);
+    L_ACF[5] += ((int32_t) sl*(int32_t) sp[-5]);
+    L_ACF[6] += ((int32_t) sl*(int32_t) sp[-6]);
+    L_ACF[7] += ((int32_t) sl*(int32_t) sp[-7]);
+    L_ACF[8] = ((int32_t) sl*(int32_t) sp[-8]);
     for (i = 9;  i < GSM0610_FRAME_LEN;  i++)
     {
         sl = *++sp;
-        L_ACF[0] += ((int32_t) sl*sp[0]);
-        L_ACF[1] += ((int32_t) sl*sp[-1]);
-        L_ACF[2] += ((int32_t) sl*sp[-2]);
-        L_ACF[3] += ((int32_t) sl*sp[-3]);
-        L_ACF[4] += ((int32_t) sl*sp[-4]);
-        L_ACF[5] += ((int32_t) sl*sp[-5]);
-        L_ACF[6] += ((int32_t) sl*sp[-6]);
-        L_ACF[7] += ((int32_t) sl*sp[-7]);
-        L_ACF[8] += ((int32_t) sl*sp[-8]);
+        L_ACF[0] += ((int32_t) sl*(int32_t) sp[0]);
+        L_ACF[1] += ((int32_t) sl*(int32_t) sp[-1]);
+        L_ACF[2] += ((int32_t) sl*(int32_t) sp[-2]);
+        L_ACF[3] += ((int32_t) sl*(int32_t) sp[-3]);
+        L_ACF[4] += ((int32_t) sl*(int32_t) sp[-4]);
+        L_ACF[5] += ((int32_t) sl*(int32_t) sp[-5]);
+        L_ACF[6] += ((int32_t) sl*(int32_t) sp[-6]);
+        L_ACF[7] += ((int32_t) sl*(int32_t) sp[-7]);
+        L_ACF[8] += ((int32_t) sl*(int32_t) sp[-8]);
     }
     /*endfor*/
     for (k = 0;  k < 9;  k++)

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_preprocess.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_preprocess.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_preprocess.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_preprocess.c,v 1.14 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_preprocess.c,v 1.16 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 
 #include "spandsp/telephony.h"

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_rpe.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_rpe.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_rpe.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_rpe.c,v 1.22 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_rpe.c,v 1.24 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 
 #include "spandsp/telephony.h"

Modified: freeswitch/trunk/libs/spandsp/src/gsm0610_short_term.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/gsm0610_short_term.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/gsm0610_short_term.c	Tue Jan 27 22:48:03 2009
@@ -25,24 +25,24 @@
  * This code is based on the widely used GSM 06.10 code available from
  * http://kbs.cs.tu-berlin.de/~jutta/toast.html
  *
- * $Id: gsm0610_short_term.c,v 1.16 2008/09/19 14:02:05 steveu Exp $
+ * $Id: gsm0610_short_term.c,v 1.18 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <assert.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdlib.h>
 
 #include "spandsp/telephony.h"

Modified: freeswitch/trunk/libs/spandsp/src/hdlc.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/hdlc.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/hdlc.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: hdlc.c,v 1.61 2008/09/07 12:45:16 steveu Exp $
+ * $Id: hdlc.c,v 1.64 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -41,6 +41,7 @@
 #include "spandsp/crc.h"
 #include "spandsp/bit_operations.h"
 #include "spandsp/hdlc.h"
+#include "spandsp/private/hdlc.h"
 
 static void rx_special_condition(hdlc_rx_state_t *s, int condition)
 {
@@ -120,7 +121,7 @@
         /* If we have not yet seen enough flags, restart the count. If we
            are beyond that point, just back off one step, so we need to see
            another flag before proceeding to collect frame octets. */
-        if (s->flags_seen < s->framing_ok_threshold)
+        if (s->flags_seen < s->framing_ok_threshold - 1)
             s->flags_seen = 0;
         else
             s->flags_seen = s->framing_ok_threshold - 1;
@@ -181,7 +182,16 @@
                greatly reduces the chances of false preamble detection, and anything
                which doesn't send them back-to-back is badly broken. */
             if (s->num_bits != 7)
-                s->flags_seen = 0;
+            {
+                /* Don't set the flags seen indicator back to zero too aggressively.
+                   We want to pick up with the minimum of discarded data when there
+                   is a bit error in the stream, and a bit error could emulate a
+                   misaligned flag. */
+                if (s->flags_seen < s->framing_ok_threshold - 1)
+                    s->flags_seen = 0;
+                else
+                    s->flags_seen = s->framing_ok_threshold - 1;
+            }
             if (++s->flags_seen >= s->framing_ok_threshold  &&  !s->framing_ok_announced)
             {
                 s->frame_handler(s->user_data, NULL, SIG_STATUS_FRAMING_OK, TRUE);

Modified: freeswitch/trunk/libs/spandsp/src/ima_adpcm.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/ima_adpcm.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/ima_adpcm.c	Tue Jan 27 22:48:03 2009
@@ -23,29 +23,30 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: ima_adpcm.c,v 1.29 2008/09/19 14:02:05 steveu Exp $
+ * $Id: ima_adpcm.c,v 1.33 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/saturated.h"
 #include "spandsp/ima_adpcm.h"
+#include "spandsp/private/ima_adpcm.h"
 
 /*
  * Intel/DVI ADPCM coder/decoder.
@@ -118,15 +119,18 @@
 /* Intel ADPCM step variation table */
 static const int step_size[STEP_MAX + 1] =
 {
-        7,     8,     9,   10,     11,    12,    13,    14,    16,    17,
-       19,    21,    23,   25,     28,    31,    34,    37,    41,    45,
-       50,    55,    60,   66,     73,    80,    88,    97,   107,   118,
-      130,   143,   157,   173,   190,   209,   230,   253,   279,   307,
-      337,   371,   408,   449,   494,   544,   598,   658,   724,   796,
-      876,   963,  1060,  1166,  1282,  1411,  1552,  1707,  1878,  2066,
-     2272,  2499,  2749,  3024,  3327,  3660,  4026,  4428,  4871,  5358,
-     5894,  6484,  7132,  7845,  8630,  9493, 10442, 11487, 12635, 13899,
-    15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+        7,     8,     9,    10,    11,    12,    13,    14,
+       16,    17,    19,    21,    23,    25,    28,    31,
+       34,    37,    41,    45,    50,    55,    60,    66,
+       73,    80,    88,    97,   107,   118,   130,   143,
+      157,   173,   190,   209,   230,   253,   279,   307,
+      337,   371,   408,   449,   494,   544,   598,   658,
+      724,   796,   876,   963,  1060,  1166,  1282,  1411,
+     1552,  1707,  1878,  2066,  2272,  2499,  2749,  3024,
+     3327,  3660,  4026,  4428,  4871,  5358,  5894,  6484,
+     7132,  7845,  8630,  9493, 10442, 11487, 12635, 13899,
+    15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
+    32767
 };
 
 static const int step_adjustment[8] =

Modified: freeswitch/trunk/libs/spandsp/src/libspandsp.dsp
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/libspandsp.dsp	(original)
+++ freeswitch/trunk/libs/spandsp/src/libspandsp.dsp	Tue Jan 27 22:48:03 2009
@@ -703,6 +703,198 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\spandsp/private/adsi.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/async.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/at_interpreter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/awgn.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/bell_r2_mf.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/bert.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/bitstream.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/dtmf.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/fax.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/fax_modems.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/fsk.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/g711.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/g722.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/g726.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/gsm0610.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/hdlc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/ima_adpcm.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/logging.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/lpc10.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/modem_connect_tones.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/noise.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/oki_adpcm.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/queue.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/schedule.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/sig_tone.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/super_tone_rx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/super_tone_tx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t30.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t31.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t38_core.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t38_gateway.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t38_non_ecm_buffer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t38_terminal.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/t4.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/time_scale.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/tone_detect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/tone_generate.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v17rx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v17tx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v22bis.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v27ter_rx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v27ter_tx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v29rx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v29tx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v42.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v42bis.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/private/v8.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spandsp/expose.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\spandsp.h
 # End Source File
 # End Group

Modified: freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj	(original)
+++ freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj	Tue Jan 27 22:48:03 2009
@@ -331,6 +331,54 @@
 <File RelativePath="spandsp/vector_float.h"></File>
 <File RelativePath="spandsp/vector_int.h"></File>
 <File RelativePath="spandsp/version.h"></File>
+<File RelativePath="spandsp/private/adsi.h"></File>
+<File RelativePath="spandsp/private/async.h"></File>
+<File RelativePath="spandsp/private/at_interpreter.h"></File>
+<File RelativePath="spandsp/private/awgn.h"></File>
+<File RelativePath="spandsp/private/bell_r2_mf.h"></File>
+<File RelativePath="spandsp/private/bert.h"></File>
+<File RelativePath="spandsp/private/bitstream.h"></File>
+<File RelativePath="spandsp/private/dtmf.h"></File>
+<File RelativePath="spandsp/private/fax.h"></File>
+<File RelativePath="spandsp/private/fax_modems.h"></File>
+<File RelativePath="spandsp/private/fsk.h"></File>
+<File RelativePath="spandsp/private/g711.h"></File>
+<File RelativePath="spandsp/private/g722.h"></File>
+<File RelativePath="spandsp/private/g726.h"></File>
+<File RelativePath="spandsp/private/gsm0610.h"></File>
+<File RelativePath="spandsp/private/hdlc.h"></File>
+<File RelativePath="spandsp/private/ima_adpcm.h"></File>
+<File RelativePath="spandsp/private/logging.h"></File>
+<File RelativePath="spandsp/private/lpc10.h"></File>
+<File RelativePath="spandsp/private/modem_connect_tones.h"></File>
+<File RelativePath="spandsp/private/noise.h"></File>
+<File RelativePath="spandsp/private/oki_adpcm.h"></File>
+<File RelativePath="spandsp/private/queue.h"></File>
+<File RelativePath="spandsp/private/schedule.h"></File>
+<File RelativePath="spandsp/private/sig_tone.h"></File>
+<File RelativePath="spandsp/private/super_tone_rx.h"></File>
+<File RelativePath="spandsp/private/super_tone_tx.h"></File>
+<File RelativePath="spandsp/private/t30.h"></File>
+<File RelativePath="spandsp/private/t31.h"></File>
+<File RelativePath="spandsp/private/t38_core.h"></File>
+<File RelativePath="spandsp/private/t38_gateway.h"></File>
+<File RelativePath="spandsp/private/t38_non_ecm_buffer.h"></File>
+<File RelativePath="spandsp/private/t38_terminal.h"></File>
+<File RelativePath="spandsp/private/t4.h"></File>
+<File RelativePath="spandsp/private/time_scale.h"></File>
+<File RelativePath="spandsp/private/tone_detect.h"></File>
+<File RelativePath="spandsp/private/tone_generate.h"></File>
+<File RelativePath="spandsp/private/v17rx.h"></File>
+<File RelativePath="spandsp/private/v17tx.h"></File>
+<File RelativePath="spandsp/private/v22bis.h"></File>
+<File RelativePath="spandsp/private/v27ter_rx.h"></File>
+<File RelativePath="spandsp/private/v27ter_tx.h"></File>
+<File RelativePath="spandsp/private/v29rx.h"></File>
+<File RelativePath="spandsp/private/v29tx.h"></File>
+<File RelativePath="spandsp/private/v42.h"></File>
+<File RelativePath="spandsp/private/v42bis.h"></File>
+<File RelativePath="spandsp/private/v8.h"></File>
+<File RelativePath="spandsp/expose.h"></File>
 <File RelativePath="spandsp.h"></File>
 		</Filter>
 		<Filter

Modified: freeswitch/trunk/libs/spandsp/src/logging.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/logging.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/logging.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: logging.c,v 1.26 2008/05/13 13:17:22 steveu Exp $
+ * $Id: logging.c,v 1.29 2009/01/20 04:24:45 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <limits.h>
@@ -46,9 +46,11 @@
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
 
+#include "spandsp/private/logging.h"
+
 static void default_message_handler(int level, const char *text);
 
-static message_handler_func_t __span_message = *default_message_handler;
+static message_handler_func_t __span_message = &default_message_handler;
 static error_handler_func_t __span_error = NULL;
 
 /* Note that this list *must* match the enum definition in logging.h */

Modified: freeswitch/trunk/libs/spandsp/src/lpc10_analyse.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/lpc10_analyse.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/lpc10_analyse.c	Tue Jan 27 22:48:03 2009
@@ -26,28 +26,29 @@
  * implementation of the LPC-10 2400 bps Voice Coder. They do not
  * exert copyright claims on their code, and it may be freely used.
  *
- * $Id: lpc10_analyse.c,v 1.19 2008/07/02 14:48:25 steveu Exp $
+ * $Id: lpc10_analyse.c,v 1.22 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
 #include "spandsp/lpc10.h"
+#include "spandsp/private/lpc10.h"
 
 #include "lpc10_encdecs.h"
 

Modified: freeswitch/trunk/libs/spandsp/src/lpc10_decode.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/lpc10_decode.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/lpc10_decode.c	Tue Jan 27 22:48:03 2009
@@ -26,28 +26,29 @@
  * implementation of the LPC-10 2400 bps Voice Coder. They do not
  * exert copyright claims on their code, and it may be freely used.
  *
- * $Id: lpc10_decode.c,v 1.22 2008/07/02 14:48:25 steveu Exp $
+ * $Id: lpc10_decode.c,v 1.25 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <memory.h>
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
 #include "spandsp/lpc10.h"
+#include "spandsp/private/lpc10.h"
 
 #define LPC10_ORDER     10
 

Modified: freeswitch/trunk/libs/spandsp/src/lpc10_encode.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/lpc10_encode.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/lpc10_encode.c	Tue Jan 27 22:48:03 2009
@@ -26,28 +26,29 @@
  * implementation of the LPC-10 2400 bps Voice Coder. They do not
  * exert copyright claims on their code, and it may be freely used.
  *
- * $Id: lpc10_encode.c,v 1.23 2008/07/02 14:48:25 steveu Exp $
+ * $Id: lpc10_encode.c,v 1.26 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
 #include "spandsp/lpc10.h"
+#include "spandsp/private/lpc10.h"
 
 #include "lpc10_encdecs.h"
 

Modified: freeswitch/trunk/libs/spandsp/src/lpc10_placev.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/lpc10_placev.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/lpc10_placev.c	Tue Jan 27 22:48:03 2009
@@ -26,24 +26,24 @@
  * implementation of the LPC-10 2400 bps Voice Coder. They do not
  * exert copyright claims on their code, and it may be freely used.
  *
- * $Id: lpc10_placev.c,v 1.17 2008/07/02 14:48:25 steveu Exp $
+ * $Id: lpc10_placev.c,v 1.19 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"

Modified: freeswitch/trunk/libs/spandsp/src/lpc10_voicing.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/lpc10_voicing.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/lpc10_voicing.c	Tue Jan 27 22:48:03 2009
@@ -26,28 +26,29 @@
  * implementation of the LPC-10 2400 bps Voice Coder. They do not
  * exert copyright claims on their code, and it may be freely used.
  *
- * $Id: lpc10_voicing.c,v 1.14 2008/07/02 14:48:25 steveu Exp $
+ * $Id: lpc10_voicing.c,v 1.17 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
 #include "spandsp/lpc10.h"
+#include "spandsp/private/lpc10.h"
 
 #include "lpc10_encdecs.h"
 

Modified: freeswitch/trunk/libs/spandsp/src/make_modem_filter.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/make_modem_filter.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/make_modem_filter.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: make_modem_filter.c,v 1.12 2008/09/18 14:59:30 steveu Exp $
+ * $Id: make_modem_filter.c,v 1.13 2009/01/28 03:41:27 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -33,13 +33,13 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <string.h>
 #include <stdio.h>
 #include <time.h>

Modified: freeswitch/trunk/libs/spandsp/src/modem_connect_tones.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/modem_connect_tones.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/modem_connect_tones.c	Tue Jan 27 22:48:03 2009
@@ -23,25 +23,25 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: modem_connect_tones.c,v 1.28 2008/09/07 12:45:16 steveu Exp $
+ * $Id: modem_connect_tones.c,v 1.31 2009/01/28 03:41:27 steveu Exp $
  */
  
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <stdio.h>
 
 #include "spandsp/telephony.h"
@@ -56,6 +56,9 @@
 #include "spandsp/fsk.h"
 #include "spandsp/modem_connect_tones.h"
 
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/modem_connect_tones.h"
+
 #define HDLC_FRAMING_OK_THRESHOLD       5
 
 const char *modem_connect_tone_to_str(int tone)

Modified: freeswitch/trunk/libs/spandsp/src/modem_echo.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/modem_echo.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/modem_echo.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: modem_echo.c,v 1.22 2008/07/02 14:48:25 steveu Exp $
+ * $Id: modem_echo.c,v 1.24 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -33,20 +33,20 @@
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/bit_operations.h"

Modified: freeswitch/trunk/libs/spandsp/src/msvc/spandsp.def
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/msvc/spandsp.def	(original)
+++ freeswitch/trunk/libs/spandsp/src/msvc/spandsp.def	Tue Jan 27 22:48:03 2009
@@ -4,6 +4,7 @@
 adsi_tx_init
 adsi_next_field
 adsi_add_field
+alaw_to_ulaw
 async_tx_init
 async_rx_init
 awgn
@@ -53,6 +54,11 @@
 fsk_rx_init
 fsk_rx
 fsk_rx_set_put_bit
+g711_init
+g711_release
+g711_encode
+g711_decode
+g711_transcode
 g722_encode_init
 g722_encode_release
 g722_encode
@@ -191,6 +197,7 @@
 tone_gen
 dtmf_tx_init
 dtmf_tx
+ulaw_to_alaw
 v17_rx_init
 v17_rx_restart
 v17_rx_set_put_bit

Modified: freeswitch/trunk/libs/spandsp/src/noise.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/noise.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/noise.c	Tue Jan 27 22:48:03 2009
@@ -23,31 +23,33 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: noise.c,v 1.25 2008/09/19 14:02:05 steveu Exp $
+ * $Id: noise.c,v 1.28 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/saturated.h"
 #include "spandsp/noise.h"
 
+#include "spandsp/private/noise.h"
+
 int16_t noise(noise_state_t *s)
 {
     int32_t val;

Modified: freeswitch/trunk/libs/spandsp/src/oki_adpcm.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/oki_adpcm.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/oki_adpcm.c	Tue Jan 27 22:48:03 2009
@@ -27,13 +27,13 @@
  * The actual OKI ADPCM encode and decode method is derived from freely
  * available code, whose exact origins seem uncertain.
  *
- * $Id: oki_adpcm.c,v 1.27 2008/05/13 13:17:23 steveu Exp $
+ * $Id: oki_adpcm.c,v 1.30 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -42,19 +42,21 @@
 
 #include "spandsp/telephony.h"
 #include "spandsp/oki_adpcm.h"
+#include "spandsp/private/oki_adpcm.h"
 
 /* Routines to convert 12 bit linear samples to the Oki ADPCM coding format,
    widely used in CTI, because Dialogic use it. */
 
+/* OKI ADPCM step variation table */
 static const int16_t step_size[49] =
 {
-      16,   17,   19,   21,   23,   25,   28,   31,
-      34,   37,   41,   45,   50,   55,   60,   66,
-      73,   80,   88,   97,  107,  118,  130,  143,
-     157,  173,  190,  209,  230,  253,  279,  307,
-     337,  371,  408,  449,  494,  544,  598,  658,
-     724,  796,  876,  963, 1060, 1166, 1282, 1408,
-    1552
+       16,    17,    19,    21,    23,    25,    28,    31,
+       34,    37,    41,    45,    50,    55,    60,    66,
+       73,    80,    88,    97,   107,   118,   130,   143,
+      157,   173,   190,   209,   230,   253,   279,   307,
+      337,   371,   408,   449,   494,   544,   598,   658,
+      724,   796,   876,   963,  1060,  1166,  1282,  1411,
+     1552
 };
 
 static const int16_t step_adjustment[8] =

Modified: freeswitch/trunk/libs/spandsp/src/playout.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/playout.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/playout.c	Tue Jan 27 22:48:03 2009
@@ -29,11 +29,11 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: playout.c,v 1.14 2008/05/13 13:17:23 steveu Exp $
+ * $Id: playout.c,v 1.15 2009/01/05 13:48:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>

Modified: freeswitch/trunk/libs/spandsp/src/plc.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/plc.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/plc.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: plc.c,v 1.23 2008/09/19 14:02:05 steveu Exp $
+ * $Id: plc.c,v 1.25 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <limits.h>
 
 #include "spandsp/telephony.h"

Modified: freeswitch/trunk/libs/spandsp/src/power_meter.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/power_meter.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/power_meter.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: power_meter.c,v 1.24 2008/07/02 14:48:26 steveu Exp $
+ * $Id: power_meter.c,v 1.26 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
@@ -37,13 +37,13 @@
 #include <fcntl.h>
 #include <string.h>
 #include <float.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
 #include "spandsp/telephony.h"

Modified: freeswitch/trunk/libs/spandsp/src/queue.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/queue.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/queue.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: queue.c,v 1.23 2008/09/09 16:25:51 steveu Exp $
+ * $Id: queue.c,v 1.25 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
@@ -42,6 +42,8 @@
 #define FULLY_DEFINE_QUEUE_STATE_T
 #include "spandsp/queue.h"
 
+#include "spandsp/private/queue.h"
+
 int queue_empty(queue_state_t *s)
 {
     return (s->iptr == s->optr);

Modified: freeswitch/trunk/libs/spandsp/src/schedule.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/schedule.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/schedule.c	Tue Jan 27 22:48:03 2009
@@ -22,11 +22,11 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: schedule.c,v 1.17 2008/05/13 13:17:23 steveu Exp $
+ * $Id: schedule.c,v 1.20 2009/01/05 13:48:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
@@ -38,6 +38,9 @@
 #include "spandsp/logging.h"
 #include "spandsp/schedule.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/schedule.h"
+
 int span_schedule_event(span_sched_state_t *s, int us, span_sched_callback_func_t function, void *user_data)
 {
     int i;

Modified: freeswitch/trunk/libs/spandsp/src/sig_tone.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/sig_tone.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/sig_tone.c	Tue Jan 27 22:48:03 2009
@@ -23,25 +23,25 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: sig_tone.c,v 1.25 2008/09/19 14:02:05 steveu Exp $
+ * $Id: sig_tone.c,v 1.28 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <memory.h>
 #include <string.h>
 
@@ -53,6 +53,8 @@
 #include "spandsp/dds.h"
 #include "spandsp/sig_tone.h"
 
+#include "spandsp/private/sig_tone.h"
+
 #define PI 3.14159265358979323
 
 /* The coefficients for the data notch filter. This filter is also the

Modified: freeswitch/trunk/libs/spandsp/src/silence_gen.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/silence_gen.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/silence_gen.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: silence_gen.c,v 1.16 2008/09/07 12:45:16 steveu Exp $
+ * $Id: silence_gen.c,v 1.17 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -36,13 +36,13 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <limits.h>
 

Modified: freeswitch/trunk/libs/spandsp/src/spandsp.h.in
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp.h.in	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp.h.in	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: spandsp.h.in,v 1.11 2008/09/19 14:02:05 steveu Exp $
+ * $Id: spandsp.h.in,v 1.14 2009/01/07 13:31:53 steveu Exp $
  */
 
 /*! \file */
@@ -116,4 +116,8 @@
 #include <spandsp/playout.h>
 
 #endif
+
+#if defined(SPANDSP_EXPOSE_INTERNAL_STRUCTURES)
+#include <spandsp/expose.h>
+#endif
 /*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/adsi.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/adsi.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/adsi.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: adsi.h,v 1.31 2008/05/05 11:25:01 steveu Exp $
+ * $Id: adsi.h,v 1.33 2008/10/13 14:19:18 steveu Exp $
  */
 
 /*! \file */
@@ -371,58 +371,13 @@
     ADSI transmitter descriptor. This contains all the state information for an ADSI
     (caller ID, CLASS, CLIP, ACLIP) transmit channel.
  */
-typedef struct
-{
-    int standard;
-
-    tone_gen_descriptor_t alert_tone_desc;
-    tone_gen_state_t alert_tone_gen;
-    fsk_tx_state_t fsktx;
-    dtmf_tx_state_t dtmftx;
-    async_tx_state_t asynctx;
-    
-    int tx_signal_on;
-    
-    int byte_no;
-    int bit_pos;
-    int bit_no;
-    uint8_t msg[256];
-    int msg_len;
-    int preamble_len;
-    int preamble_ones_len;
-    int postamble_ones_len;
-    int stop_bits;
-    int baudot_shift;
-    
-    logging_state_t logging;
-} adsi_tx_state_t;
+typedef struct adsi_tx_state_s adsi_tx_state_t;
 
 /*!
     ADSI receiver descriptor. This contains all the state information for an ADSI
     (caller ID, CLASS, CLIP, ACLIP, JCLIP) receive channel.
  */
-typedef struct
-{
-    int standard;
-    put_msg_func_t put_msg;
-    void *user_data;
-
-    fsk_rx_state_t fskrx;
-    dtmf_rx_state_t dtmfrx;
-    async_rx_state_t asyncrx;
-    
-    int consecutive_ones;
-    int bit_pos;
-    int in_progress;
-    uint8_t msg[256];
-    int msg_len;
-    int baudot_shift;
-    
-    /*! A count of the framing errors. */
-    int framing_errors;
-
-    logging_state_t logging;
-} adsi_rx_state_t;
+typedef struct adsi_rx_state_s adsi_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -439,6 +394,8 @@
 */
 adsi_rx_state_t *adsi_rx_init(adsi_rx_state_t *s, int standard, put_msg_func_t put_msg, void *user_data);
 
+int adsi_rx_free(adsi_rx_state_t *s);
+
 /*! \brief Receive a chunk of ADSI audio.
     \param s The ADSI receive context.
     \param amp The audio sample buffer.
@@ -454,6 +411,8 @@
 */
 adsi_tx_state_t *adsi_tx_init(adsi_tx_state_t *s, int standard);
 
+int adsi_tx_free(adsi_tx_state_t *s);
+
 /*! \brief Adjust the preamble associated with an ADSI transmit context.
     \param s The ADSI transmit context.
     \param preamble_len The number of bits of preamble.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/async.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/async.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/async.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: async.h,v 1.18 2008/09/07 12:45:17 steveu Exp $
+ * $Id: async.h,v 1.19 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -120,59 +120,14 @@
     working instance of a byte to asynchronous serial converter, for use
     in FSK modems.
 */
-typedef struct
-{
-    /*! \brief The number of data bits per character. */
-    int data_bits;
-    /*! \brief The type of parity. */
-    int parity;
-    /*! \brief The number of stop bits per character. */
-    int stop_bits;
-    /*! \brief A pointer to the callback routine used to get characters to be transmitted. */
-    get_byte_func_t get_byte;
-    /*! \brief An opaque pointer passed when calling get_byte. */
-    void *user_data;
-
-    /*! \brief A current, partially transmitted, character. */
-    int byte_in_progress;
-    /*! \brief The current bit position within a partially transmitted character. */
-    int bitpos;
-    /*! \brief Parity bit. */
-    int parity_bit;
-} async_tx_state_t;
+typedef struct async_tx_state_s async_tx_state_t;
 
 /*!
     Asynchronous data receive descriptor. This defines the state of a single
     working instance of an asynchronous serial to byte converter, for use
     in FSK modems.
 */
-typedef struct
-{
-    /*! \brief The number of data bits per character. */
-    int data_bits;
-    /*! \brief The type of parity. */
-    int parity;
-    /*! \brief The number of stop bits per character. */
-    int stop_bits;
-    /*! \brief TRUE if V.14 rate adaption processing should be performed. */
-    int use_v14;
-    /*! \brief A pointer to the callback routine used to handle received characters. */
-    put_byte_func_t put_byte;
-    /*! \brief An opaque pointer passed when calling put_byte. */
-    void *user_data;
-
-    /*! \brief A current, partially complete, character. */
-    int byte_in_progress;
-    /*! \brief The current bit position within a partially complete character. */
-    int bitpos;
-    /*! \brief Parity bit. */
-    int parity_bit;
-
-    /*! A count of the number of parity errors seen. */
-    int parity_errors;
-    /*! A count of the number of character framing errors seen. */
-    int framing_errors;
-} async_rx_state_t;
+typedef struct async_rx_state_s async_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/at_interpreter.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/at_interpreter.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/at_interpreter.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: at_interpreter.h,v 1.19 2008/09/16 12:45:50 steveu Exp $
+ * $Id: at_interpreter.h,v 1.20 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \file */
@@ -112,13 +112,6 @@
     AT_RESPONSE_CODE_FRH3
 };
 
-struct at_call_id
-{
-    char *id;
-    char *value;
-    struct at_call_id *next;
-};
-
 /*!
     AT profile.
 */
@@ -140,93 +133,6 @@
     uint8_t s_regs[100];
 } at_profile_t;
 
-/*!
-    AT descriptor. This defines the working state for a single instance of
-    the AT interpreter.
-*/
-struct at_state_s
-{
-    at_profile_t p;
-    /*! Value set by +GCI */
-    int country_of_installation;
-    /*! Value set by +FIT */
-    int dte_inactivity_timeout;
-    /*! Value set by +FIT */
-    int dte_inactivity_action;
-    /*! Value set by L */
-    int speaker_volume;
-    /*! Value set by M */
-    int speaker_mode;
-    /*! This is no real DTE rate. This variable is for compatibility this serially
-        connected modems. */
-    /*! Value set by +IPR/+FPR */
-    int dte_rate;
-    /*! Value set by +ICF */
-    int dte_char_format;
-    /*! Value set by +ICF */
-    int dte_parity;
-    /*! Value set by &C */
-    int rlsd_behaviour;
-    /*! Value set by &D */
-    int dtr_behaviour;
-    /*! Value set by +FCL */
-    int carrier_loss_timeout;
-    /*! Value set by X */
-    int result_code_mode;
-    /*! Value set by +IDSR */
-    int dsr_option;
-    /*! Value set by +ILSD */
-    int long_space_disconnect_option;
-    /*! Value set by +ICLOK */
-    int sync_tx_clock_source;
-    /*! Value set by +EWIND */
-    int rx_window;
-    /*! Value set by +EWIND */
-    int tx_window;
-    
-    int v8bis_signal;
-    int v8bis_1st_message;
-    int v8bis_2nd_message;
-    int v8bis_sig_en;
-    int v8bis_msg_en;
-    int v8bis_supp_delay;
-
-    uint8_t rx_data[256];
-    int rx_data_bytes;
-
-    int display_call_info;
-    int call_info_displayed;
-    struct at_call_id *call_id;
-    char *local_id;
-    /*! The currently select FAX modem class. 0 = data modem mode. */
-    int fclass_mode;
-    int at_rx_mode;
-    int rings_indicated;
-    int do_hangup;
-    int silent_dial;
-    int command_dial;
-    int ok_is_pending;
-    int dte_is_waiting;
-    /*! \brief TRUE if a carrier is presnt. Otherwise FALSE. */
-    int rx_signal_present;
-    /*! \brief TRUE if a modem has trained, Otherwise FALSE. */
-    int rx_trained;
-    int transmit;
-
-    char line[256];
-    int line_ptr;
-
-    at_modem_control_handler_t *modem_control_handler;
-    void *modem_control_user_data;
-    at_tx_handler_t *at_tx_handler;
-    void *at_tx_user_data;
-    at_class1_handler_t *class1_handler;
-    void *class1_user_data;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-};
-
 #if defined(__cplusplus)
 extern "C"
 {

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/awgn.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/awgn.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/awgn.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: awgn.h,v 1.14 2008/04/17 14:26:59 steveu Exp $
+ * $Id: awgn.h,v 1.15 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \file */
@@ -71,16 +71,7 @@
 /*!
     AWGN generator descriptor. This contains all the state information for an AWGN generator.
  */
-typedef struct
-{
-    double rms;
-    long int ix1;
-    long int ix2;
-    long int ix3;
-    double r[98];
-    double gset;
-    int iset;
-} awgn_state_t;
+typedef struct awgn_state_s awgn_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/bell_r2_mf.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/bell_r2_mf.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/bell_r2_mf.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bell_r2_mf.h,v 1.19 2008/05/30 13:51:28 steveu Exp $
+ * $Id: bell_r2_mf.h,v 1.21 2008/10/13 14:19:18 steveu Exp $
  */
 
 /*! \file */
@@ -108,73 +108,22 @@
     Bell MF generator state descriptor. This defines the state of a single
     working instance of a Bell MF generator.
 */
-typedef struct
-{
-    /*! The tone generator. */
-    tone_gen_state_t tones;
-    int current_sample;
-    union
-    {
-        queue_state_t queue;
-        uint8_t buf[QUEUE_STATE_T_SIZE(MAX_BELL_MF_DIGITS)];
-    } queue;
-} bell_mf_tx_state_t;
+typedef struct bell_mf_tx_state_s bell_mf_tx_state_t;
 
 /*!
     Bell MF digit detector descriptor.
 */
-typedef struct
-{
-    /*! Optional callback funcion to deliver received digits. */
-    digits_rx_callback_t digits_callback;
-    /*! An opaque pointer passed to the callback function. */
-    void *digits_callback_data;
-    /*! Tone detector working states */
-    goertzel_state_t out[6];
-    /*! Short term history of results from the tone detection, using in persistence checking */
-    uint8_t hits[5];
-    /*! The current sample number within a processing block. */
-    int current_sample;
-
-    /*! The number of digits which have been lost due to buffer overflows. */
-    int lost_digits;
-    /*! The number of digits currently in the digit buffer. */
-    int current_digits;
-    /*! The received digits buffer. This is a NULL terminated string. */
-    char digits[MAX_BELL_MF_DIGITS + 1];
-} bell_mf_rx_state_t;
+typedef struct bell_mf_rx_state_s bell_mf_rx_state_t;
 
 /*!
     MFC/R2 tone detector descriptor.
 */
-typedef struct
-{
-    /*! The tone generator. */
-    tone_gen_state_t tone;
-    /*! TRUE if generating forward tones, otherwise generating reverse tones. */
-    int fwd;
-    /*! The current digit being generated. */
-    int digit;
-} r2_mf_tx_state_t;
+typedef struct r2_mf_tx_state_s r2_mf_tx_state_t;
 
 /*!
     MFC/R2 tone detector descriptor.
 */
-typedef struct
-{
-    /*! Optional callback funcion to deliver received digits. */
-    tone_report_func_t callback;
-    /*! An opaque pointer passed to the callback function. */
-    void *callback_data;
-    /*! TRUE is we are detecting forward tones. FALSE if we are detecting backward tones */
-    int fwd;
-    /*! Tone detector working states */
-    goertzel_state_t out[6];
-    /*! The current sample number within a processing block. */
-    int current_sample;
-    /*! The currently detected digit. */
-    int current_digit;
-} r2_mf_rx_state_t;
+typedef struct r2_mf_rx_state_s r2_mf_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/bert.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/bert.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/bert.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bert.h,v 1.19 2008/04/17 14:26:59 steveu Exp $
+ * $Id: bert.h,v 1.20 2008/11/30 12:38:27 steveu Exp $
  */
 
 #if !defined(_SPANDSP_BERT_H_)
@@ -106,54 +106,7 @@
     Bit error rate tester (BERT) descriptor. This defines the working state for a
     single instance of the BERT.
 */
-typedef struct
-{
-    int pattern;
-    int pattern_class;
-    bert_report_func_t reporter;
-    void *user_data;
-    int report_frequency;
-    int limit;
-
-    uint32_t tx_reg;
-    int tx_step;
-    int tx_step_bit;
-    int tx_bits;
-    int tx_zeros;
-
-    uint32_t rx_reg;
-    uint32_t ref_reg;
-    uint32_t master_reg;
-    int rx_step;
-    int rx_step_bit;
-    int resync;
-    int rx_bits;
-    int rx_zeros;
-    int resync_len;
-    int resync_percent;
-    int resync_bad_bits;
-    int resync_cnt;
-    
-    uint32_t mask;
-    int shift;
-    int shift2;
-    int max_zeros;
-    int invert;
-    int resync_time;
-
-    int decade_ptr[9];
-    int decade_bad[9][10];
-    int step;
-    int error_rate;
-
-    int bit_error_status;
-    int report_countdown;
-
-    bert_results_t results;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} bert_state_t;
+typedef struct bert_state_s bert_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/bit_operations.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/bit_operations.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/bit_operations.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bit_operations.h,v 1.22 2008/07/10 13:43:40 steveu Exp $
+ * $Id: bit_operations.h,v 1.23 2008/10/13 23:41:40 steveu Exp $
  */
 
 /*! \file */
@@ -40,9 +40,9 @@
     \return The bit number of the highest set bit, or -1 if the word is zero. */
 static __inline__ int top_bit(unsigned int bits)
 {
+#if defined(__i386__)  ||  defined(__x86_64__)
     int res;
 
-#if defined(__i386__)  ||  defined(__x86_64__)
     __asm__ (" xorl %[res],%[res];\n"
              " decl %[res];\n"
              " bsrl %[bits],%[res]\n"
@@ -50,11 +50,22 @@
              : [bits] "rm" (bits));
     return res;
 #elif defined(__ppc__)  ||   defined(__powerpc__)
+    int res;
+
     __asm__ ("cntlzw %[res],%[bits];\n"
              : [res] "=&r" (res)
              : [bits] "r" (bits));
     return 31 - res;
+#elif defined(_M_IX86) // Visual Studio x86
+    __asm
+    {
+        xor eax, eax
+        dec eax
+        bsr eax, bits
+    }
 #else
+    int res;
+
     if (bits == 0)
         return -1;
     res = 0;

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/bitstream.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/bitstream.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/bitstream.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bitstream.h,v 1.10 2008/04/17 14:27:00 steveu Exp $
+ * $Id: bitstream.h,v 1.12 2008/11/30 12:45:09 steveu Exp $
  */
 
 /*! \file */
@@ -37,13 +37,7 @@
 */
 
 /*! Bitstream handler state */
-typedef struct
-{
-    /*! The bit stream. */
-    unsigned int bitstream;
-    /*! The residual bits in bitstream. */
-    unsigned int residue;
-} bitstream_state_t;
+typedef struct bitstream_state_s bitstream_state_t;
 
 
 #if defined(__cplusplus)
@@ -55,19 +49,19 @@
     \param s A pointer to the bitstream context.
     \param c A pointer to the bitstream output buffer.
     \param value The value to be pushed into the output buffer.
-    \param bits The number of bits of value to be pushed. 1 to 25 bit is valid. */
-void bitstream_put(bitstream_state_t *s, uint8_t **c, unsigned int value, int bits);
+    \param bits The number of bits of value to be pushed. 1 to 25 bits is valid. */
+void bitstream_put(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits);
 
-void bitstream_put2(bitstream_state_t *s, uint8_t **c, unsigned int value, int bits);
+void bitstream_put2(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits);
 
 /*! \brief Get a chunk of bits from the input buffer.
     \param s A pointer to the bitstream context.
     \param c A pointer to the bitstream input buffer.
-    \param bits The number of bits of value to be grabbed. 1 to 25 bit is valid.
+    \param bits The number of bits of value to be grabbed. 1 to 25 bits is valid.
     \return The value retrieved from the input buffer. */
-unsigned int bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits);
+uint32_t bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits);
 
-unsigned int bitstream_get2(bitstream_state_t *s, const uint8_t **c, int bits);
+uint32_t bitstream_get2(bitstream_state_t *s, const uint8_t **c, int bits);
 
 /*! \brief Flush any residual bit to the output buffer.
     \param s A pointer to the bitstream context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/complex_vector_float.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/complex_vector_float.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/complex_vector_float.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_vector_float.h,v 1.10 2008/09/18 13:16:49 steveu Exp $
+ * $Id: complex_vector_float.h,v 1.11 2008/10/09 13:25:19 steveu Exp $
  */
 
 #if !defined(_SPANDSP_COMPLEX_VECTOR_FLOAT_H_)
@@ -120,6 +120,14 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+void cvec_mulf(complexf_t z[], const complexf_t x[], const complexf_t y[], int n);
+
+void cvec_mul(complex_t z[], const complex_t x[], const complex_t y[], int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void cvec_mull(complexl_t z[], const complexl_t x[], const complexl_t y[], int n);
+#endif
+
 /*! \brief Find the dot product of two complex float vectors.
     \param x The first vector.
     \param y The first vector.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/dtmf.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/dtmf.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/dtmf.h	Tue Jan 27 22:48:03 2009
@@ -1,7 +1,7 @@
 /*
  * SpanDSP - a series of DSP components for telephony
  *
- * dtmf.h - 
+ * dtmf.h - DTMF tone generation and detection.
  *
  * Written by Steve Underwood <steveu at coppice.org>
  *
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dtmf.h,v 1.28 2008/06/13 14:46:52 steveu Exp $
+ * $Id: dtmf.h,v 1.29 2008/10/13 13:14:00 steveu Exp $
  */
 
 #if !defined(_SPANDSP_DTMF_H_)
@@ -81,80 +81,12 @@
     DTMF generator state descriptor. This defines the state of a single
     working instance of a DTMF generator.
 */
-typedef struct
-{
-    tone_gen_state_t tones;
-    float low_level;
-    float high_level;
-    int on_time;
-    int off_time;
-    union
-    {
-        queue_state_t queue;
-        uint8_t buf[QUEUE_STATE_T_SIZE(MAX_DTMF_DIGITS)];
-    } queue;
-} dtmf_tx_state_t;
+typedef struct dtmf_tx_state_s dtmf_tx_state_t;
 
 /*!
     DTMF digit detector descriptor.
 */
-typedef struct
-{
-    /*! Optional callback funcion to deliver received digits. */
-    digits_rx_callback_t digits_callback;
-    /*! An opaque pointer passed to the callback function. */
-    void *digits_callback_data;
-    /*! Optional callback funcion to deliver real time digit state changes. */
-    tone_report_func_t realtime_callback;
-    /*! An opaque pointer passed to the real time callback function. */
-    void *realtime_callback_data;
-    /*! TRUE if dialtone should be filtered before processing */
-    int filter_dialtone;
-#if defined(SPANDSP_USE_FIXED_POINT)
-    /*! 350Hz filter state for the optional dialtone filter. */
-    float z350[2];
-    /*! 440Hz filter state for the optional dialtone filter. */
-    float z440[2];
-    /*! Maximum acceptable "normal" (lower bigger than higher) twist ratio. */
-    float normal_twist;
-    /*! Maximum acceptable "reverse" (higher bigger than lower) twist ratio. */
-    float reverse_twist;
-    /*! Minimum acceptable tone level for detection. */
-    int32_t threshold;
-    /*! The accumlating total energy on the same period over which the Goertzels work. */
-    int32_t energy;
-#else
-    /*! 350Hz filter state for the optional dialtone filter. */
-    float z350[2];
-    /*! 440Hz filter state for the optional dialtone filter. */
-    float z440[2];
-    /*! Maximum acceptable "normal" (lower bigger than higher) twist ratio. */
-    float normal_twist;
-    /*! Maximum acceptable "reverse" (higher bigger than lower) twist ratio. */
-    float reverse_twist;
-    /*! Minimum acceptable tone level for detection. */
-    float threshold;
-    /*! The accumlating total energy on the same period over which the Goertzels work. */
-    float energy;
-#endif
-    /*! Tone detector working states for the row tones. */
-    goertzel_state_t row_out[4];
-    /*! Tone detector working states for the column tones. */
-    goertzel_state_t col_out[4];
-    /*! The result of the last tone analysis. */
-    uint8_t last_hit;
-    /*! The confirmed digit we are currently receiving */
-    uint8_t in_digit;
-    /*! The current sample number within a processing block. */
-    int current_sample;
-
-    /*! The number of digits which have been lost due to buffer overflows. */
-    int lost_digits;
-    /*! The number of digits currently in the digit buffer. */
-    int current_digits;
-    /*! The received digits buffer. This is a NULL terminated string. */
-    char digits[MAX_DTMF_DIGITS + 1];
-} dtmf_rx_state_t;
+typedef struct dtmf_rx_state_s dtmf_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Added: freeswitch/trunk/libs/spandsp/src/spandsp/expose.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/expose.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,84 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * expose.h - Expose the internal structures of spandsp, for users who
+ *            really need that.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2008 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: expose.h,v 1.11 2008/11/30 13:44:35 steveu Exp $
+ */
+
+/*! \file */
+
+/* TRY TO ONLY INCLUDE THIS IF YOU REALLY REALLY HAVE TO */
+
+#if !defined(_SPANDSP_EXPOSE_H_)
+#define _SPANDSP_EXPOSE_H_
+
+#include <spandsp/private/logging.h>
+#include <spandsp/private/schedule.h>
+#include <spandsp/private/bitstream.h>
+#include <spandsp/private/queue.h>
+#include <spandsp/private/awgn.h>
+#include <spandsp/private/noise.h>
+#include <spandsp/private/bert.h>
+#include <spandsp/private/tone_generate.h>
+#include <spandsp/private/bell_r2_mf.h>
+#include <spandsp/private/sig_tone.h>
+#include <spandsp/private/dtmf.h>
+#include <spandsp/private/g711.h>
+#include <spandsp/private/g722.h>
+#include <spandsp/private/g726.h>
+#include <spandsp/private/lpc10.h>
+#include <spandsp/private/gsm0610.h>
+#include <spandsp/private/oki_adpcm.h>
+#include <spandsp/private/ima_adpcm.h>
+#include <spandsp/private/hdlc.h>
+#include <spandsp/private/time_scale.h>
+#include <spandsp/private/super_tone_tx.h>
+#include <spandsp/private/super_tone_rx.h>
+#include <spandsp/private/async.h>
+#include <spandsp/private/fsk.h>
+#include <spandsp/private/v29rx.h>
+#include <spandsp/private/v29tx.h>
+#include <spandsp/private/v17rx.h>
+#include <spandsp/private/v17tx.h>
+#include <spandsp/private/v22bis.h>
+#include <spandsp/private/v27ter_rx.h>
+#include <spandsp/private/v27ter_tx.h>
+#include <spandsp/private/modem_connect_tones.h>
+#include <spandsp/private/at_interpreter.h>
+#include <spandsp/private/fax_modems.h>
+#include <spandsp/private/t4.h>
+#include <spandsp/private/t30.h>
+#include <spandsp/private/fax.h>
+#include <spandsp/private/t38_core.h>
+#include <spandsp/private/t38_non_ecm_buffer.h>
+#include <spandsp/private/t38_gateway.h>
+#include <spandsp/private/t38_terminal.h>
+#include <spandsp/private/t31.h>
+#include <spandsp/private/v8.h>
+#include <spandsp/private/v42.h>
+#include <spandsp/private/v42bis.h>
+#include <spandsp/private/adsi.h>
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/fax.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/fax.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/fax.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax.h,v 1.35 2008/08/13 00:11:30 steveu Exp $
+ * $Id: fax.h,v 1.36 2008/10/13 13:14:00 steveu Exp $
  */
 
 /*! \file */
@@ -39,22 +39,6 @@
 
 typedef struct fax_state_s fax_state_t;
 
-/*!
-    Analogue line T.30 FAX channel descriptor. This defines the state of a single working
-    instance of an analogue line soft-FAX machine.
-*/
-struct fax_state_s
-{
-    /*! \brief The T.30 back-end */
-    t30_state_t t30;
-    
-    /*! \brief The analogue modem front-end */
-    fax_modems_state_t modems;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-};
-
 #if defined(__cplusplus)
 extern "C"
 {
@@ -103,6 +87,13 @@
 */
 t30_state_t *fax_get_t30_state(fax_state_t *s);
 
+/*! Get a pointer to the logging context associated with a FAX context.
+    \brief Get a pointer to the logging context associated with a FAX context.
+    \param s The FAX context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *fax_get_logging_state(fax_state_t *s);
+
 /*! Initialise a FAX context.
     \brief Initialise a FAX context.
     \param s The FAX context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/fax_modems.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/fax_modems.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/fax_modems.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax_modems.h,v 1.5 2008/08/13 00:11:30 steveu Exp $
+ * $Id: fax_modems.h,v 1.6 2008/10/13 13:14:00 steveu Exp $
  */
 
 /*! \file */
@@ -33,91 +33,7 @@
 /*!
     The set of modems needed for FAX, plus the auxilliary stuff, like tone generation.
 */
-typedef struct
-{
-    /*! TRUE is talker echo protection should be sent for the image modems */
-    int use_tep;
-
-    /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
-        the actual generated audio. Note that this only affects untimed silences. Timed silences
-        (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
-        silent audio. */
-    int transmit_on_idle;
-
-    /*! \brief An HDLC context used when transmitting HDLC messages. */
-    hdlc_tx_state_t hdlc_tx;
-    /*! \brief An HDLC context used when receiving HDLC messages. */
-    hdlc_rx_state_t hdlc_rx;
-    /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
-               messages. */
-    fsk_tx_state_t v21_tx;
-    /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
-               messages. */
-    fsk_rx_state_t v21_rx;
-    /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
-               12000bps or 14400bps */
-    v17_tx_state_t v17_tx;
-    /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
-               12000bps or 14400bps */
-    v17_rx_state_t v17_rx;
-    /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
-               9600bps */
-    v29_tx_state_t v29_tx;
-    /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
-               9600bps */
-    v29_rx_state_t v29_rx;
-    /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
-               4800bps */
-    v27ter_tx_state_t v27ter_tx;
-    /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
-               4800bps */
-    v27ter_rx_state_t v27ter_rx;
-    /*! \brief Used to insert timed silences. */
-    silence_gen_state_t silence_gen;
-    /*! \brief CED or CNG generator */
-    modem_connect_tones_tx_state_t connect_tx;
-    /*! \brief CED or CNG detector */
-    modem_connect_tones_rx_state_t connect_rx;
-    /*! \brief */
-    dc_restore_state_t dc_restore;
-
-    /*! \brief The currently select receiver type */
-    int current_rx_type;
-    /*! \brief The currently select transmitter type */
-    int current_tx_type;
-
-    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
-    int rx_signal_present;
-    /*! \brief TRUE if a modem has trained correctly. */
-    int rx_trained;
-
-    /*! The current receive signal handler */
-    span_rx_handler_t *rx_handler;
-    void *rx_user_data;
-
-    /*! The current transmit signal handler */
-    span_tx_handler_t *tx_handler;
-    void *tx_user_data;
-
-    /*! The next transmit signal handler, for two stage transmit operations.
-        E.g. a short silence followed by a modem signal. */
-    span_tx_handler_t *next_tx_handler;
-    void *next_tx_user_data;
-
-    /*! The current bit rate of the transmitter. */
-    int tx_bit_rate;
-    /*! The current bit rate of the receiver. */
-    int rx_bit_rate;
-
-    /*! If TRUE, transmission is in progress */
-    int transmit;
-    /*! \brief Audio logging file handle for received audio. */
-    int audio_rx_log;
-    /*! \brief Audio logging file handle for transmitted audio. */
-    int audio_tx_log;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} fax_modems_state_t;
+typedef struct fax_modems_state_s fax_modems_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/fsk.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/fsk.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/fsk.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fsk.h,v 1.31 2008/09/04 14:40:05 steveu Exp $
+ * $Id: fsk.h,v 1.32 2008/10/13 13:14:00 steveu Exp $
  */
 
 /*! \file */
@@ -120,27 +120,7 @@
     FSK modem transmit descriptor. This defines the state of a single working
     instance of an FSK modem transmitter.
 */
-typedef struct
-{
-    int baud_rate;
-    /*! \brief The callback function used to get the next bit to be transmitted. */
-    get_bit_func_t get_bit;
-    /*! \brief A user specified opaque pointer passed to the get_bit function. */
-    void *get_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_tx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    int32_t phase_rates[2];
-    int scaling;
-    int32_t current_phase_rate;
-    uint32_t phase_acc;
-    int baud_frac;
-    int baud_inc;
-    int shutdown;
-} fsk_tx_state_t;
+typedef struct fsk_tx_state_s fsk_tx_state_t;
 
 /* The longest window will probably be 106 for 75 baud */
 #define FSK_MAX_WINDOW_LEN 128
@@ -149,42 +129,7 @@
     FSK modem receive descriptor. This defines the state of a single working
     instance of an FSK modem receiver.
 */
-typedef struct
-{
-    int baud_rate;
-    int sync_mode;
-    /*! \brief The callback function used to put each bit received. */
-    put_bit_func_t put_bit;
-    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
-    void *put_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_tx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    int32_t carrier_on_power;
-    int32_t carrier_off_power;
-    power_meter_t power;
-    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
-    int16_t last_sample;
-    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.29 signal. */
-    int signal_present;
-
-    int32_t phase_rate[2];
-    uint32_t phase_acc[2];
-
-    int correlation_span;
-
-    complexi32_t window[2][FSK_MAX_WINDOW_LEN];
-    complexi32_t dot[2];
-    int buf_ptr;
-
-    int baud_inc;
-    int baud_pll;
-    int lastbit;
-    int scaling_shift;
-} fsk_rx_state_t;
+typedef struct fsk_rx_state_s fsk_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/g711.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/g711.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/g711.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g711.h,v 1.14 2008/05/02 17:57:32 steveu Exp $
+ * $Id: g711.h,v 1.15 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -62,11 +62,7 @@
     G711_ULAW
 };
 
-typedef struct
-{
-    /*! One of the G.711_xxx options */
-    int mode;
-} g711_state_t;
+typedef struct g711_state_s g711_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/g722.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/g722.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/g722.h	Tue Jan 27 22:48:03 2009
@@ -28,7 +28,7 @@
  * Computer Science, Speech Group
  * Chengxiang Lu and Alex Hauptmann
  *
- * $Id: g722.h,v 1.21 2008/09/19 16:24:25 steveu Exp $
+ * $Id: g722.h,v 1.22 2008/10/13 13:14:00 steveu Exp $
  */
 
 
@@ -56,69 +56,9 @@
     G722_PACKED = 0x0002
 };
 
-/*! The per band parameters for both encoding and decoding G.722 */
-typedef struct
-{
-    int16_t nb;
-    int16_t det;
-    int16_t s;
-    int16_t sz;
-    int16_t r;
-    int16_t p[2];
-    int16_t a[2];
-    int16_t b[6];
-    int16_t d[7];
-} g722_band_t;
-
-typedef struct
-{
-    /*! TRUE if the operating in the special ITU test mode, with the band split filters
-             disabled. */
-    int itu_test_mode;
-    /*! TRUE if the G.722 data is packed */
-    int packed;
-    /*! TRUE if encode from 8k samples/second */
-    int eight_k;
-    /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
-    int bits_per_sample;
-
-    /*! Signal history for the QMF */
-    int16_t x[12];
-    int16_t y[12];
-    int ptr;
-
-    g722_band_t band[2];
-
-    uint32_t in_buffer;
-    int in_bits;
-    uint32_t out_buffer;
-    int out_bits;
-} g722_encode_state_t;
+typedef struct g722_encode_state_s g722_encode_state_t;
 
-typedef struct
-{
-    /*! TRUE if the operating in the special ITU test mode, with the band split filters
-             disabled. */
-    int itu_test_mode;
-    /*! TRUE if the G.722 data is packed */
-    int packed;
-    /*! TRUE if decode to 8k samples/second */
-    int eight_k;
-    /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
-    int bits_per_sample;
-
-    /*! Signal history for the QMF */
-    int16_t x[12];
-    int16_t y[12];
-    int ptr;
-
-    g722_band_t band[2];
-    
-    uint32_t in_buffer;
-    int in_bits;
-    uint32_t out_buffer;
-    int out_bits;
-} g722_decode_state_t;
+typedef struct g722_decode_state_s g722_decode_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/g726.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/g726.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/g726.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g726.h,v 1.21 2008/04/17 14:27:00 steveu Exp $
+ * $Id: g726.h,v 1.22 2008/10/13 13:14:00 steveu Exp $
  */
 
 /*! \file */
@@ -59,66 +59,11 @@
     G726_PACKING_RIGHT = 2
 };
 
-struct g726_state_s;
+typedef struct g726_state_s g726_state_t;
 
-typedef int16_t (*g726_decoder_func_t)(struct g726_state_s *s, uint8_t code);
+typedef int16_t (*g726_decoder_func_t)(g726_state_t *s, uint8_t code);
 
-typedef uint8_t (*g726_encoder_func_t)(struct g726_state_s *s, int16_t amp);
-
-/*!
- * The following is the definition of the state structure
- * used by the G.726 encoder and decoder to preserve their internal
- * state between successive calls.  The meanings of the majority
- * of the state structure fields are explained in detail in the
- * CCITT Recommendation G.721.  The field names are essentially indentical
- * to variable names in the bit level description of the coding algorithm
- * included in this Recommendation.
- */
-typedef struct g726_state_s
-{
-    /*! The bit rate */
-    int rate;
-    /*! The external coding, for tandem operation */
-    int ext_coding;
-    /*! The number of bits per sample */
-    unsigned int bits_per_sample;
-    /*! One of the G.726_PACKING_xxx options */
-    int packing;
-
-    /*! Locked or steady state step size multiplier. */
-    int32_t yl;
-    /*! Unlocked or non-steady state step size multiplier. */
-    int16_t yu;
-    /*! int16_t term energy estimate. */
-    int16_t dms;
-    /*! Long term energy estimate. */
-    int16_t dml;
-    /*! Linear weighting coefficient of 'yl' and 'yu'. */
-    int16_t ap;
-    
-    /*! Coefficients of pole portion of prediction filter. */
-    int16_t a[2];
-    /*! Coefficients of zero portion of prediction filter. */
-    int16_t b[6];
-    /*! Signs of previous two samples of a partially reconstructed signal. */
-    int16_t pk[2];
-    /*! Previous 6 samples of the quantized difference signal represented in
-        an internal floating point format. */
-    int16_t dq[6];
-    /*! Previous 2 samples of the quantized difference signal represented in an
-        internal floating point format. */
-    int16_t sr[2];
-    /*! Delayed tone detect */
-    int td;
-    
-    /*! \brief The bit stream processing context. */
-    bitstream_state_t bs;
-
-    /*! \brief The current encoder function. */
-    g726_encoder_func_t enc_func;
-    /*! \brief The current decoder function. */
-    g726_decoder_func_t dec_func;
-} g726_state_t;
+typedef uint8_t (*g726_encoder_func_t)(g726_state_t *s, int16_t amp);
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/gsm0610.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/gsm0610.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/gsm0610.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: gsm0610.h,v 1.17 2008/04/17 14:27:00 steveu Exp $
+ * $Id: gsm0610.h,v 1.18 2008/11/15 14:17:46 steveu Exp $
  */
 
 #if !defined(_SPANDSP_GSM0610_H_)
@@ -72,34 +72,7 @@
     GSM 06.10 FR codec state descriptor. This defines the state of
     a single working instance of the GSM 06.10 FR encoder or decoder.
 */
-typedef struct
-{
-    /*! \brief One of the packing modes */
-    int packing;
-
-    int16_t dp0[280];
-
-    /*! Preprocessing */
-    int16_t z1;
-    int32_t L_z2;
-    /*! Pre-emphasis */
-    int16_t mp;
-
-    /*! Short term delay filter */
-    int16_t u[8];
-    int16_t LARpp[2][8];
-    int16_t j;
-
-    /*! Long term synthesis */
-    int16_t nrp;
-    /*! Short term synthesis */
-    int16_t v[9];
-    /*! Decoder postprocessing */
-    int16_t msr;
-    
-    /*! Encoder data */
-    int16_t e[50];
-} gsm0610_state_t;
+typedef struct gsm0610_state_s gsm0610_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/hdlc.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/hdlc.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/hdlc.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: hdlc.h,v 1.39 2008/04/17 14:27:00 steveu Exp $
+ * $Id: hdlc.h,v 1.40 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \file */
@@ -53,56 +53,7 @@
 /*!
     HDLC receive descriptor. This contains all the state information for an HDLC receiver.
  */
-typedef struct
-{
-    /*! 2 for CRC-16, 4 for CRC-32 */
-    int crc_bytes;
-    /*! \brief Maximum permitted frame length. */
-    size_t max_frame_len;
-    /*! \brief The callback routine called to process each good received frame. */
-    hdlc_frame_handler_t frame_handler;
-    /*! \brief An opaque parameter passed to the callback routine. */
-    void *user_data;
-    /*! \brief TRUE if bad frames are to be reported. */
-    int report_bad_frames;
-    /*! \brief The number of consecutive flags which must be seen before framing is
-        declared OK. */
-    int framing_ok_threshold;
-    /*! \brief TRUE if framing OK has been announced. */
-    int framing_ok_announced;
-    /*! \brief Number of consecutive flags seen so far. */
-    int flags_seen;
-
-    /*! \brief The raw (stuffed) bit stream buffer. */
-    unsigned int raw_bit_stream;
-    /*! \brief The destuffed bit stream buffer. */
-    unsigned int byte_in_progress;
-    /*! \brief The current number of bits in byte_in_progress. */
-    int num_bits;
-    /*! \brief TRUE if in octet counting mode (e.g. for MTP). */
-    int octet_counting_mode;
-    /*! \brief Octet count, to achieve the functionality needed for things
-               like MTP. */
-    int octet_count;
-    /*! \brief The number of octets to be allowed between octet count reports. */
-    int octet_count_report_interval;
-
-    /*! \brief Buffer for a frame in progress. */
-    uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
-    /*! \brief Length of a frame in progress. */
-    size_t len;
-
-    /*! \brief The number of bytes of good frames received (CRC not included). */
-    unsigned long int rx_bytes;
-    /*! \brief The number of good frames received. */
-    unsigned long int rx_frames;
-    /*! \brief The number of frames with CRC errors received. */
-    unsigned long int rx_crc_errors;
-    /*! \brief The number of too short and too long frames received. */
-    unsigned long int rx_length_errors;
-    /*! \brief The number of HDLC aborts received. */
-    unsigned long int rx_aborts;
-} hdlc_rx_state_t;
+typedef struct hdlc_rx_state_s hdlc_rx_state_t;
 
 /*!
     HDLC received data statistics.
@@ -125,51 +76,7 @@
     HDLC transmit descriptor. This contains all the state information for an
     HDLC transmitter.
  */
-typedef struct
-{
-    /*! 2 for CRC-16, 4 for CRC-32 */
-    int crc_bytes;
-    /*! \brief The callback routine called to indicate transmit underflow. */
-    hdlc_underflow_handler_t underflow_handler;
-    /*! \brief An opaque parameter passed to the callback routine. */
-    void *user_data;
-    /*! \brief The minimum flag octets to insert between frames. */
-    int inter_frame_flags;
-    /*! \brief TRUE if frame creation works in progressive mode. */
-    int progressive;
-    /*! \brief Maximum permitted frame length. */
-    size_t max_frame_len;
-
-    /*! \brief The stuffed bit stream being created. */
-    uint32_t octets_in_progress;
-    /*! \brief The number of bits currently in octets_in_progress. */
-    int num_bits;
-    /*! \brief The currently rotated state of the flag octet. */
-    int idle_octet;
-    /*! \brief The number of flag octets to send for a timed burst of flags. */
-    int flag_octets;
-    /*! \brief The number of abort octets to send for a timed burst of aborts. */
-    int abort_octets;
-    /*! \brief TRUE if the next underflow of timed flag octets should be reported */
-    int report_flag_underflow;
-
-    /*! \brief The current message being transmitted, with its CRC attached. */
-    uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
-    /*! \brief The length of the message in the buffer. */
-    size_t len;
-    /*! \brief The current send position within the buffer. */
-    int pos;
-    /*! \brief The running CRC, as data fills the frame buffer. */
-    uint32_t crc;
-
-    /*! \brief The current byte being broken into bits for transmission. */
-    int byte;
-    /*! \brief The number of bits remaining in byte. */
-    int bits;
-    
-    /*! \brief TRUE if transmission should end on buffer underflow .*/
-    int tx_end;
-} hdlc_tx_state_t;
+typedef struct hdlc_tx_state_s hdlc_tx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/ima_adpcm.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/ima_adpcm.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/ima_adpcm.h	Tue Jan 27 22:48:03 2009
@@ -1,8 +1,8 @@
 /*
  * SpanDSP - a series of DSP components for telephony
  *
- * imaadpcm.c - Conversion routines between linear 16 bit PCM data and
- *		        IMA/DVI/Intel ADPCM format.
+ * ima_adpcm.c - Conversion routines between linear 16 bit PCM data and
+ *		         IMA/DVI/Intel ADPCM format.
  *
  * Written by Steve Underwood <steveu at coppice.org>
  *
@@ -26,7 +26,7 @@
  * Based on a bit from here, a bit from there, eye of toad,
  * ear of bat, etc - plus, of course, my own 2 cents.
  *
- * $Id: ima_adpcm.h,v 1.20 2008/04/17 14:27:00 steveu Exp $
+ * $Id: ima_adpcm.h,v 1.21 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -59,19 +59,7 @@
     a single working instance of the IMA ADPCM converter. This is used for
     either linear to ADPCM or ADPCM to linear conversion.
 */
-typedef struct
-{
-    int variant;
-    /*! \brief The size of a chunk, in samples. */
-    int chunk_size;
-    /*! \brief The last state of the ADPCM algorithm. */
-    int last;
-    /*! \brief Current index into the step size table. */
-    int step_index;
-    /*! \brief The current IMA code byte in progress. */
-    uint16_t ima_byte;
-    int bits;
-} ima_adpcm_state_t;
+typedef struct ima_adpcm_state_s ima_adpcm_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/logging.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/logging.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/logging.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: logging.h,v 1.16 2008/05/05 11:25:01 steveu Exp $
+ * $Id: logging.h,v 1.17 2008/11/30 13:44:35 steveu Exp $
  */
 
 /*! \file */
@@ -74,17 +74,7 @@
     Logging descriptor. This defines the working state for a single instance of
     the logging facility for spandsp.
 */
-typedef struct
-{
-    int level;
-    int samples_per_second;
-    int64_t elapsed_samples;
-    const char *tag;
-    const char *protocol;
-
-    message_handler_func_t span_message;
-    error_handler_func_t span_error;
-} logging_state_t;
+typedef struct logging_state_s logging_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/lpc10.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/lpc10.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/lpc10.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: lpc10.h,v 1.17 2008/04/17 14:27:00 steveu Exp $
+ * $Id: lpc10.h,v 1.18 2008/11/30 05:43:37 steveu Exp $
  */
 
 #if !defined(_SPANDSP_LPC10_H_)
@@ -57,115 +57,13 @@
     LPC10 codec encoder state descriptor. This defines the state of
     a single working instance of the LPC10 encoder.
 */
-typedef struct
-{
-    int error_correction;
-
-    /* State used only by function high_pass_100hz */
-    float z11;
-    float z21;
-    float z12;
-    float z22;
-    
-    /* State used by function lpc10_analyse */
-    float inbuf[LPC10_SAMPLES_PER_FRAME*3];
-    float pebuf[LPC10_SAMPLES_PER_FRAME*3];
-    float lpbuf[696];
-    float ivbuf[312];
-    float bias;
-    int32_t osbuf[10];      /* No initial value necessary */
-    int32_t osptr;          /* Initial value 1 */
-    int32_t obound[3];
-    int32_t vwin[3][2];     /* Initial value vwin[2][0] = 307; vwin[2][1] = 462; */
-    int32_t awin[3][2];     /* Initial value awin[2][0] = 307; awin[2][1] = 462; */
-    int32_t voibuf[4][2];
-    float rmsbuf[3];
-    float rcbuf[3][10];
-    float zpre;
-
-    /* State used by function onset */
-    float n;
-    float d__;          /* Initial value 1.0f */
-    float fpc;          /* No initial value necessary */
-    float l2buf[16];
-    float l2sum1;
-    int32_t l2ptr1;     /* Initial value 1 */
-    int32_t l2ptr2;     /* Initial value 9 */
-    int32_t lasti;      /* No initial value necessary */
-    int hyst;           /* Initial value FALSE */
-
-    /* State used by function lpc10_voicing */
-    float dither;       /* Initial value 20.0f */
-    float snr;
-    float maxmin;
-    float voice[3][2];  /* Initial value is probably unnecessary */
-    int32_t lbve;
-    int32_t lbue;
-    int32_t fbve;
-    int32_t fbue;
-    int32_t ofbue;
-    int32_t sfbue;
-    int32_t olbue;
-    int32_t slbue;
-
-    /* State used by function dynamic_pitch_tracking */
-    float s[60];
-    int32_t p[2][60];
-    int32_t ipoint;
-    float alphax;
-
-    /* State used by function lpc10_pack */
-    int32_t isync;
-} lpc10_encode_state_t;
+typedef struct lpc10_encode_state_s lpc10_encode_state_t;
 
 /*!
     LPC10 codec decoder state descriptor. This defines the state of
     a single working instance of the LPC10 decoder.
 */
-typedef struct
-{
-    int error_correction;
-
-    /* State used by function decode */
-    int32_t iptold;     /* Initial value 60 */
-    int first;          /* Initial value TRUE */
-    int32_t ivp2h;
-    int32_t iovoic;
-    int32_t iavgp;      /* Initial value 60 */
-    int32_t erate;
-    int32_t drc[10][3];
-    int32_t dpit[3];
-    int32_t drms[3];
-
-    /* State used by function synths */
-    float buf[LPC10_SAMPLES_PER_FRAME*2];
-    int32_t buflen;     /* Initial value LPC10_SAMPLES_PER_FRAME */
-
-    /* State used by function pitsyn */
-    int32_t ivoico;     /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
-    int32_t ipito;      /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
-    float rmso;         /* Initial value 1.0f */
-    float rco[10];      /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
-    int32_t jsamp;      /* Nno initial value necessary as long as first_pitsyn is initially TRUE_ */
-    int first_pitsyn;   /* Initial value TRUE */
-
-    /* State used by function bsynz */
-    int32_t ipo;
-    float exc[166];
-    float exc2[166];
-    float lpi[3];
-    float hpi[3];
-    float rmso_bsynz;
-
-    /* State used by function random */
-    int32_t j;
-    int32_t k;
-    int16_t y[5];
-
-    /* State used by function deemp */
-    float dei[2];
-    float deo[3];
-} lpc10_decode_state_t;
+typedef struct lpc10_decode_state_s lpc10_decode_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/modem_connect_tones.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/modem_connect_tones.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/modem_connect_tones.h	Tue Jan 27 22:48:03 2009
@@ -2,7 +2,8 @@
  * SpanDSP - a series of DSP components for telephony
  *
  * modem_connect_tones.c - Generation and detection of tones
- * associated with modems calling and answering calls.
+ *                         associated with modems calling and
+ *                         answering calls.
  *
  * Written by Steve Underwood <steveu at coppice.org>
  *
@@ -23,7 +24,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: modem_connect_tones.h,v 1.18 2008/08/10 03:42:38 steveu Exp $
+ * $Id: modem_connect_tones.h,v 1.19 2008/10/13 13:14:00 steveu Exp $
  */
  
 /*! \file */
@@ -87,65 +88,13 @@
     Modem connect tones generator descriptor. This defines the state
     of a single working instance of the tone generator.
 */
-typedef struct
-{
-    int tone_type;
-
-    int32_t tone_phase_rate;
-    uint32_t tone_phase;
-    int level;
-    /*! \brief Countdown to the next phase hop */
-    int hop_timer;
-    /*! \brief Maximum duration timer */
-    int duration_timer;
-    uint32_t mod_phase;
-    int32_t mod_phase_rate;
-    int mod_level;
-} modem_connect_tones_tx_state_t;
+typedef struct modem_connect_tones_tx_state_s modem_connect_tones_tx_state_t;
 
 /*!
     Modem connect tones receiver descriptor. This defines the state
     of a single working instance of the tone detector.
 */
-typedef struct
-{
-    /*! \brief The tone type being detected. */
-    int tone_type;
-    /*! \brief Callback routine, using to report detection of the tone. */
-    tone_report_func_t tone_callback;
-    /*! \brief An opaque pointer passed to tone_callback. */
-    void *callback_data;
-
-    /*! \brief The notch filter state. */
-    float z1;
-    float z2;
-    /*! \brief The in notch power estimate */
-    int notch_level;
-    /*! \brief The total channel power estimate */
-    int channel_level;
-    /*! \brief Sample counter for the small chunks of samples, after which a test is conducted. */
-    int chunk_remainder;
-    /*! \brief TRUE is the tone is currently confirmed present in the audio. */
-    int tone_present;
-    /*! \brief */
-    int tone_on;
-    /*! \brief A millisecond counter, to time the duration of tone sections. */
-    int tone_cycle_duration;
-    /*! \brief A count of the number of good cycles of tone reversal seen. */
-    int good_cycles;
-    /*! \brief TRUE if the tone has been seen since the last time the user tested for it */
-    int hit;
-    /*! \brief A V.21 FSK modem context used when searching for FAX preamble. */
-    fsk_rx_state_t v21rx;
-    /*! \brief The raw (stuffed) bit stream buffer. */
-    unsigned int raw_bit_stream;
-    /*! \brief The current number of bits in the octet in progress. */
-    int num_bits;
-    /*! \brief Number of consecutive flags seen so far. */
-    int flags_seen;
-    /*! \brief TRUE if framing OK has been announced. */
-    int framing_ok_announced;
-} modem_connect_tones_rx_state_t;
+typedef struct modem_connect_tones_rx_state_s modem_connect_tones_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/noise.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/noise.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/noise.h	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: noise.h,v 1.13 2008/04/17 14:27:00 steveu Exp $
+ * $Id: noise.h,v 1.14 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \file */
@@ -91,14 +91,7 @@
     Noise generator descriptor. This contains all the state information for an instance
     of the noise generator.
  */
-typedef struct
-{
-    int class_of_noise;
-    int quality;
-    int32_t rms;
-    uint32_t rndnum;
-    int32_t state;
-} noise_state_t;
+typedef struct noise_state_s noise_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/oki_adpcm.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/oki_adpcm.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/oki_adpcm.h	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: oki_adpcm.h,v 1.20 2008/04/17 14:27:00 steveu Exp $
+ * $Id: oki_adpcm.h,v 1.21 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -49,25 +49,7 @@
     a single working instance of the Oki ADPCM converter. This is used for
     either linear to ADPCM or ADPCM to linear conversion.
 */
-typedef struct
-{
-    /*! \brief The bit rate - 24000 or 32000. */
-    int bit_rate;
-    /*! \brief The last state of the ADPCM algorithm. */
-    int16_t last;
-    /*! \brief Current index into the step size table. */
-    int16_t step_index;
-    /*! \brief The compressed data byte in progress. */
-    uint8_t oki_byte;
-    /*! \brief The signal history for the sample rate converter. */
-    int16_t history[32];
-    /*! \brief Pointer into the history buffer. */
-    int ptr;
-    /*! \brief Odd/even sample counter. */
-    int mark;
-    /*! \brief Phase accumulator for the sample rate converter. */
-    int phase;
-} oki_adpcm_state_t;
+typedef struct oki_adpcm_state_s oki_adpcm_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/README
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/README	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,3 @@
+The header files in this directory should only be used by code tightly integrating itself with the
+spandsp library to maximise performance. To maximise compatibility with futures revisions of spandsp,
+most users should avoid using these headers, or probing into the spandsp data structures in other ways.
\ No newline at end of file

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/adsi.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/adsi.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,91 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/adsi.h - Analogue display services interface and other call ID related handling.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: adsi.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_ADSI_H_)
+#define _SPANDSP_PRIVATE_ADSI_H_
+
+/*!
+    ADSI transmitter descriptor. This contains all the state information for an ADSI
+    (caller ID, CLASS, CLIP, ACLIP) transmit channel.
+ */
+struct adsi_tx_state_s
+{
+    int standard;
+
+    tone_gen_descriptor_t alert_tone_desc;
+    tone_gen_state_t alert_tone_gen;
+    fsk_tx_state_t fsktx;
+    dtmf_tx_state_t dtmftx;
+    async_tx_state_t asynctx;
+    
+    int tx_signal_on;
+    
+    int byte_no;
+    int bit_pos;
+    int bit_no;
+    uint8_t msg[256];
+    int msg_len;
+    int preamble_len;
+    int preamble_ones_len;
+    int postamble_ones_len;
+    int stop_bits;
+    int baudot_shift;
+    
+    logging_state_t logging;
+};
+
+/*!
+    ADSI receiver descriptor. This contains all the state information for an ADSI
+    (caller ID, CLASS, CLIP, ACLIP, JCLIP) receive channel.
+ */
+struct adsi_rx_state_s
+{
+    int standard;
+    put_msg_func_t put_msg;
+    void *user_data;
+
+    fsk_rx_state_t fskrx;
+    dtmf_rx_state_t dtmfrx;
+    async_rx_state_t asyncrx;
+    
+    int consecutive_ones;
+    int bit_pos;
+    int in_progress;
+    uint8_t msg[256];
+    int msg_len;
+    int baudot_shift;
+    
+    /*! A count of the framing errors. */
+    int framing_errors;
+
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/async.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/async.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,91 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/async.h - Asynchronous serial bit stream encoding and decoding
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: async.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_ASYNC_H_)
+#define _SPANDSP_PRIVATE_ASYNC_H_
+
+/*!
+    Asynchronous data transmit descriptor. This defines the state of a single
+    working instance of a byte to asynchronous serial converter, for use
+    in FSK modems.
+*/
+struct async_tx_state_s
+{
+    /*! \brief The number of data bits per character. */
+    int data_bits;
+    /*! \brief The type of parity. */
+    int parity;
+    /*! \brief The number of stop bits per character. */
+    int stop_bits;
+    /*! \brief A pointer to the callback routine used to get characters to be transmitted. */
+    get_byte_func_t get_byte;
+    /*! \brief An opaque pointer passed when calling get_byte. */
+    void *user_data;
+
+    /*! \brief A current, partially transmitted, character. */
+    int byte_in_progress;
+    /*! \brief The current bit position within a partially transmitted character. */
+    int bitpos;
+    /*! \brief Parity bit. */
+    int parity_bit;
+};
+
+/*!
+    Asynchronous data receive descriptor. This defines the state of a single
+    working instance of an asynchronous serial to byte converter, for use
+    in FSK modems.
+*/
+struct async_rx_state_s
+{
+    /*! \brief The number of data bits per character. */
+    int data_bits;
+    /*! \brief The type of parity. */
+    int parity;
+    /*! \brief The number of stop bits per character. */
+    int stop_bits;
+    /*! \brief TRUE if V.14 rate adaption processing should be performed. */
+    int use_v14;
+    /*! \brief A pointer to the callback routine used to handle received characters. */
+    put_byte_func_t put_byte;
+    /*! \brief An opaque pointer passed when calling put_byte. */
+    void *user_data;
+
+    /*! \brief A current, partially complete, character. */
+    int byte_in_progress;
+    /*! \brief The current bit position within a partially complete character. */
+    int bitpos;
+    /*! \brief Parity bit. */
+    int parity_bit;
+
+    /*! A count of the number of parity errors seen. */
+    int parity_errors;
+    /*! A count of the number of character framing errors seen. */
+    int framing_errors;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/at_interpreter.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/at_interpreter.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,130 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/at_interpreter.h - AT command interpreter to V.251, V.252, V.253, T.31 and the 3GPP specs.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004, 2005, 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: at_interpreter.h,v 1.1 2008/11/30 05:43:37 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_AT_INTERPRETER_H_)
+#define _SPANDSP_PRIVATE_AT_INTERPRETER_H_
+
+typedef struct at_call_id_s at_call_id_t;
+
+struct at_call_id_s
+{
+    char *id;
+    char *value;
+    at_call_id_t *next;
+};
+
+/*!
+    AT descriptor. This defines the working state for a single instance of
+    the AT interpreter.
+*/
+struct at_state_s
+{
+    at_profile_t p;
+    /*! Value set by +GCI */
+    int country_of_installation;
+    /*! Value set by +FIT */
+    int dte_inactivity_timeout;
+    /*! Value set by +FIT */
+    int dte_inactivity_action;
+    /*! Value set by L */
+    int speaker_volume;
+    /*! Value set by M */
+    int speaker_mode;
+    /*! This is no real DTE rate. This variable is for compatibility this serially
+        connected modems. */
+    /*! Value set by +IPR/+FPR */
+    int dte_rate;
+    /*! Value set by +ICF */
+    int dte_char_format;
+    /*! Value set by +ICF */
+    int dte_parity;
+    /*! Value set by &C */
+    int rlsd_behaviour;
+    /*! Value set by &D */
+    int dtr_behaviour;
+    /*! Value set by +FCL */
+    int carrier_loss_timeout;
+    /*! Value set by X */
+    int result_code_mode;
+    /*! Value set by +IDSR */
+    int dsr_option;
+    /*! Value set by +ILSD */
+    int long_space_disconnect_option;
+    /*! Value set by +ICLOK */
+    int sync_tx_clock_source;
+    /*! Value set by +EWIND */
+    int rx_window;
+    /*! Value set by +EWIND */
+    int tx_window;
+    
+    int v8bis_signal;
+    int v8bis_1st_message;
+    int v8bis_2nd_message;
+    int v8bis_sig_en;
+    int v8bis_msg_en;
+    int v8bis_supp_delay;
+
+    uint8_t rx_data[256];
+    int rx_data_bytes;
+
+    int display_call_info;
+    int call_info_displayed;
+    at_call_id_t *call_id;
+    char *local_id;
+    /*! The currently select FAX modem class. 0 = data modem mode. */
+    int fclass_mode;
+    int at_rx_mode;
+    int rings_indicated;
+    int do_hangup;
+    int silent_dial;
+    int command_dial;
+    int ok_is_pending;
+    int dte_is_waiting;
+    /*! \brief TRUE if a carrier is presnt. Otherwise FALSE. */
+    int rx_signal_present;
+    /*! \brief TRUE if a modem has trained, Otherwise FALSE. */
+    int rx_trained;
+    int transmit;
+
+    char line[256];
+    int line_ptr;
+
+    at_modem_control_handler_t *modem_control_handler;
+    void *modem_control_user_data;
+    at_tx_handler_t *at_tx_handler;
+    void *at_tx_user_data;
+    at_class1_handler_t *class1_handler;
+    void *class1_user_data;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/awgn.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/awgn.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,46 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/awgn.h - An additive Gaussian white noise generator
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: awgn.h,v 1.1 2008/11/30 12:38:27 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_AWGN_H_)
+#define _SPANDSP_PRIVATE_AWGN_H_
+
+/*!
+    AWGN generator descriptor. This contains all the state information for an AWGN generator.
+ */
+struct awgn_state_s
+{
+    double rms;
+    long int ix1;
+    long int ix2;
+    long int ix3;
+    double r[98];
+    double gset;
+    int iset;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/bell_r2_mf.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/bell_r2_mf.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,104 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * bell_r2_mf.h - Bell MF and MFC/R2 tone generation and detection.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: bell_r2_mf.h,v 1.2 2008/10/13 14:19:18 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_BELL_R2_MF_H_)
+#define _SPANDSP_PRIVATE_BELL_R2_MF_H_
+
+/*!
+    Bell MF generator state descriptor. This defines the state of a single
+    working instance of a Bell MF generator.
+*/
+struct bell_mf_tx_state_s
+{
+    /*! The tone generator. */
+    tone_gen_state_t tones;
+    int current_sample;
+    union
+    {
+        queue_state_t queue;
+        uint8_t buf[QUEUE_STATE_T_SIZE(MAX_BELL_MF_DIGITS)];
+    } queue;
+};
+
+/*!
+    Bell MF digit detector descriptor.
+*/
+struct bell_mf_rx_state_s
+{
+    /*! Optional callback funcion to deliver received digits. */
+    digits_rx_callback_t digits_callback;
+    /*! An opaque pointer passed to the callback function. */
+    void *digits_callback_data;
+    /*! Tone detector working states */
+    goertzel_state_t out[6];
+    /*! Short term history of results from the tone detection, using in persistence checking */
+    uint8_t hits[5];
+    /*! The current sample number within a processing block. */
+    int current_sample;
+
+    /*! The number of digits which have been lost due to buffer overflows. */
+    int lost_digits;
+    /*! The number of digits currently in the digit buffer. */
+    int current_digits;
+    /*! The received digits buffer. This is a NULL terminated string. */
+    char digits[MAX_BELL_MF_DIGITS + 1];
+};
+
+/*!
+    MFC/R2 tone detector descriptor.
+*/
+struct r2_mf_tx_state_s
+{
+    /*! The tone generator. */
+    tone_gen_state_t tone;
+    /*! TRUE if generating forward tones, otherwise generating reverse tones. */
+    int fwd;
+    /*! The current digit being generated. */
+    int digit;
+};
+
+/*!
+    MFC/R2 tone detector descriptor.
+*/
+struct r2_mf_rx_state_s
+{
+    /*! Optional callback funcion to deliver received digits. */
+    tone_report_func_t callback;
+    /*! An opaque pointer passed to the callback function. */
+    void *callback_data;
+    /*! TRUE is we are detecting forward tones. FALSE if we are detecting backward tones */
+    int fwd;
+    /*! Tone detector working states */
+    goertzel_state_t out[6];
+    /*! The current sample number within a processing block. */
+    int current_sample;
+    /*! The currently detected digit. */
+    int current_digit;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/bert.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/bert.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,85 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/bert.h - Bit error rate tests.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: bert.h,v 1.1 2008/11/30 12:38:27 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_BERT_H_)
+#define _SPANDSP_PRIVATE_BERT_H_
+
+/*!
+    Bit error rate tester (BERT) descriptor. This defines the working state for a
+    single instance of the BERT.
+*/
+struct bert_state_s
+{
+    int pattern;
+    int pattern_class;
+    bert_report_func_t reporter;
+    void *user_data;
+    int report_frequency;
+    int limit;
+
+    uint32_t tx_reg;
+    int tx_step;
+    int tx_step_bit;
+    int tx_bits;
+    int tx_zeros;
+
+    uint32_t rx_reg;
+    uint32_t ref_reg;
+    uint32_t master_reg;
+    int rx_step;
+    int rx_step_bit;
+    int resync;
+    int rx_bits;
+    int rx_zeros;
+    int resync_len;
+    int resync_percent;
+    int resync_bad_bits;
+    int resync_cnt;
+    
+    uint32_t mask;
+    int shift;
+    int shift2;
+    int max_zeros;
+    int invert;
+    int resync_time;
+
+    int decade_ptr[9];
+    int decade_bad[9][10];
+    int step;
+    int error_rate;
+
+    int bit_error_status;
+    int report_countdown;
+
+    bert_results_t results;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/bitstream.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/bitstream.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,42 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/bitstream.h - Bitstream composition and decomposition routines.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: bitstream.h,v 1.1 2008/11/30 12:45:09 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_BITSTREAM_H_)
+#define _SPANDSP_PRIVATE_BITSTREAM_H_
+
+/*! Bitstream handler state */
+struct bitstream_state_s
+{
+    /*! The bit stream. */
+    uint32_t bitstream;
+    /*! The residual bits in bitstream. */
+    int residue;
+};
+
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/dtmf.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/dtmf.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,111 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/dtmf.h - DTMF tone generation and detection 
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001, 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: dtmf.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_DTMF_H_)
+#define _SPANDSP_PRIVATE_DTMF_H_
+
+/*!
+    DTMF generator state descriptor. This defines the state of a single
+    working instance of a DTMF generator.
+*/
+struct dtmf_tx_state_s
+{
+    tone_gen_state_t tones;
+    float low_level;
+    float high_level;
+    int on_time;
+    int off_time;
+    union
+    {
+        queue_state_t queue;
+        uint8_t buf[QUEUE_STATE_T_SIZE(MAX_DTMF_DIGITS)];
+    } queue;
+};
+
+/*!
+    DTMF digit detector descriptor.
+*/
+struct dtmf_rx_state_s
+{
+    /*! Optional callback funcion to deliver received digits. */
+    digits_rx_callback_t digits_callback;
+    /*! An opaque pointer passed to the callback function. */
+    void *digits_callback_data;
+    /*! Optional callback funcion to deliver real time digit state changes. */
+    tone_report_func_t realtime_callback;
+    /*! An opaque pointer passed to the real time callback function. */
+    void *realtime_callback_data;
+    /*! TRUE if dialtone should be filtered before processing */
+    int filter_dialtone;
+#if defined(SPANDSP_USE_FIXED_POINT)
+    /*! 350Hz filter state for the optional dialtone filter. */
+    float z350[2];
+    /*! 440Hz filter state for the optional dialtone filter. */
+    float z440[2];
+    /*! Maximum acceptable "normal" (lower bigger than higher) twist ratio. */
+    float normal_twist;
+    /*! Maximum acceptable "reverse" (higher bigger than lower) twist ratio. */
+    float reverse_twist;
+    /*! Minimum acceptable tone level for detection. */
+    int32_t threshold;
+    /*! The accumlating total energy on the same period over which the Goertzels work. */
+    int32_t energy;
+#else
+    /*! 350Hz filter state for the optional dialtone filter. */
+    float z350[2];
+    /*! 440Hz filter state for the optional dialtone filter. */
+    float z440[2];
+    /*! Maximum acceptable "normal" (lower bigger than higher) twist ratio. */
+    float normal_twist;
+    /*! Maximum acceptable "reverse" (higher bigger than lower) twist ratio. */
+    float reverse_twist;
+    /*! Minimum acceptable tone level for detection. */
+    float threshold;
+    /*! The accumlating total energy on the same period over which the Goertzels work. */
+    float energy;
+#endif
+    /*! Tone detector working states for the row tones. */
+    goertzel_state_t row_out[4];
+    /*! Tone detector working states for the column tones. */
+    goertzel_state_t col_out[4];
+    /*! The result of the last tone analysis. */
+    uint8_t last_hit;
+    /*! The confirmed digit we are currently receiving */
+    uint8_t in_digit;
+    /*! The current sample number within a processing block. */
+    int current_sample;
+
+    /*! The number of digits which have been lost due to buffer overflows. */
+    int lost_digits;
+    /*! The number of digits currently in the digit buffer. */
+    int current_digits;
+    /*! The received digits buffer. This is a NULL terminated string. */
+    char digits[MAX_DTMF_DIGITS + 1];
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/fax.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/fax.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,50 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/fax.h - private definitions for analogue line ITU T.30 fax processing
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: fax.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_FAX_H_)
+#define _SPANDSP_PRIVATE_FAX_H_
+
+/*!
+    Analogue line T.30 FAX channel descriptor. This defines the state of a single working
+    instance of an analogue line soft-FAX machine.
+*/
+struct fax_state_s
+{
+    /*! \brief The T.30 back-end */
+    t30_state_t t30;
+    
+    /*! \brief The analogue modem front-end */
+    fax_modems_state_t modems;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/fax_modems.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/fax_modems.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,123 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/fax_modems.h - definitions for the analogue modem set for fax processing
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2008 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: fax_modems.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_FAX_MODEMS_H_)
+#define _SPANDSP_PRIVATE_FAX_MODEMS_H_
+
+/*!
+    The set of modems needed for FAX, plus the auxilliary stuff, like tone generation.
+*/
+struct fax_modems_state_s
+{
+    /*! TRUE is talker echo protection should be sent for the image modems */
+    int use_tep;
+
+    /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
+        the actual generated audio. Note that this only affects untimed silences. Timed silences
+        (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
+        silent audio. */
+    int transmit_on_idle;
+
+    /*! \brief An HDLC context used when transmitting HDLC messages. */
+    hdlc_tx_state_t hdlc_tx;
+    /*! \brief An HDLC context used when receiving HDLC messages. */
+    hdlc_rx_state_t hdlc_rx;
+    /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
+               messages. */
+    fsk_tx_state_t v21_tx;
+    /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
+               messages. */
+    fsk_rx_state_t v21_rx;
+    /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
+               12000bps or 14400bps */
+    v17_tx_state_t v17_tx;
+    /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
+               12000bps or 14400bps */
+    v17_rx_state_t v17_rx;
+    /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
+               9600bps */
+    v29_tx_state_t v29_tx;
+    /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
+               9600bps */
+    v29_rx_state_t v29_rx;
+    /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
+               4800bps */
+    v27ter_tx_state_t v27ter_tx;
+    /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
+               4800bps */
+    v27ter_rx_state_t v27ter_rx;
+    /*! \brief Used to insert timed silences. */
+    silence_gen_state_t silence_gen;
+    /*! \brief CED or CNG generator */
+    modem_connect_tones_tx_state_t connect_tx;
+    /*! \brief CED or CNG detector */
+    modem_connect_tones_rx_state_t connect_rx;
+    /*! \brief */
+    dc_restore_state_t dc_restore;
+
+    /*! \brief The currently select receiver type */
+    int current_rx_type;
+    /*! \brief The currently select transmitter type */
+    int current_tx_type;
+
+    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
+    int rx_signal_present;
+    /*! \brief TRUE if a modem has trained correctly. */
+    int rx_trained;
+
+    /*! The current receive signal handler */
+    span_rx_handler_t *rx_handler;
+    void *rx_user_data;
+
+    /*! The current transmit signal handler */
+    span_tx_handler_t *tx_handler;
+    void *tx_user_data;
+
+    /*! The next transmit signal handler, for two stage transmit operations.
+        E.g. a short silence followed by a modem signal. */
+    span_tx_handler_t *next_tx_handler;
+    void *next_tx_user_data;
+
+    /*! The current bit rate of the transmitter. */
+    int tx_bit_rate;
+    /*! The current bit rate of the receiver. */
+    int rx_bit_rate;
+
+    /*! If TRUE, transmission is in progress */
+    int transmit;
+    /*! \brief Audio logging file handle for received audio. */
+    int audio_rx_log;
+    /*! \brief Audio logging file handle for transmitted audio. */
+    int audio_tx_log;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/fsk.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/fsk.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,99 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/fsk.h - FSK modem transmit and receive parts
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: fsk.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_FSK_H_)
+#define _SPANDSP_PRIVATE_FSK_H_
+
+/*!
+    FSK modem transmit descriptor. This defines the state of a single working
+    instance of an FSK modem transmitter.
+*/
+struct fsk_tx_state_s
+{
+    int baud_rate;
+    /*! \brief The callback function used to get the next bit to be transmitted. */
+    get_bit_func_t get_bit;
+    /*! \brief A user specified opaque pointer passed to the get_bit function. */
+    void *get_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_tx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    int32_t phase_rates[2];
+    int scaling;
+    int32_t current_phase_rate;
+    uint32_t phase_acc;
+    int baud_frac;
+    int baud_inc;
+    int shutdown;
+};
+
+/*!
+    FSK modem receive descriptor. This defines the state of a single working
+    instance of an FSK modem receiver.
+*/
+struct fsk_rx_state_s
+{
+    int baud_rate;
+    int sync_mode;
+    /*! \brief The callback function used to put each bit received. */
+    put_bit_func_t put_bit;
+    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
+    void *put_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_tx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    int32_t carrier_on_power;
+    int32_t carrier_off_power;
+    power_meter_t power;
+    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
+    int16_t last_sample;
+    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.29 signal. */
+    int signal_present;
+
+    int32_t phase_rate[2];
+    uint32_t phase_acc[2];
+
+    int correlation_span;
+
+    complexi32_t window[2][FSK_MAX_WINDOW_LEN];
+    complexi32_t dot[2];
+    int buf_ptr;
+
+    int baud_inc;
+    int baud_pll;
+    int lastbit;
+    int scaling_shift;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/g711.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/g711.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,38 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/g711.h - In line A-law and u-law conversion routines
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: g711.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_G711_H_)
+#define _SPANDSP_PRIVATE_G711_H_
+
+struct g711_state_s
+{
+    /*! One of the G.711_xxx options */
+    int mode;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/g722.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/g722.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,105 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/g722.h - The ITU G.722 codec.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Based on a single channel G.722 codec which is:
+ *
+ *****    Copyright (c) CMU    1993      *****
+ * Computer Science, Speech Group
+ * Chengxiang Lu and Alex Hauptmann
+ *
+ * $Id: g722.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_G722_H_)
+#define _SPANDSP_PRIVATE_G722_H_
+
+/*! The per band parameters for both encoding and decoding G.722 */
+typedef struct
+{
+    int16_t nb;
+    int16_t det;
+    int16_t s;
+    int16_t sz;
+    int16_t r;
+    int16_t p[2];
+    int16_t a[2];
+    int16_t b[6];
+    int16_t d[7];
+} g722_band_t;
+
+struct g722_encode_state_s
+{
+    /*! TRUE if the operating in the special ITU test mode, with the band split filters
+             disabled. */
+    int itu_test_mode;
+    /*! TRUE if the G.722 data is packed */
+    int packed;
+    /*! TRUE if encode from 8k samples/second */
+    int eight_k;
+    /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
+    int bits_per_sample;
+
+    /*! Signal history for the QMF */
+    int16_t x[12];
+    int16_t y[12];
+    int ptr;
+
+    g722_band_t band[2];
+
+    uint32_t in_buffer;
+    int in_bits;
+    uint32_t out_buffer;
+    int out_bits;
+};
+
+struct g722_decode_state_s
+{
+    /*! TRUE if the operating in the special ITU test mode, with the band split filters
+             disabled. */
+    int itu_test_mode;
+    /*! TRUE if the G.722 data is packed */
+    int packed;
+    /*! TRUE if decode to 8k samples/second */
+    int eight_k;
+    /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
+    int bits_per_sample;
+
+    /*! Signal history for the QMF */
+    int16_t x[12];
+    int16_t y[12];
+    int ptr;
+
+    g722_band_t band[2];
+    
+    uint32_t in_buffer;
+    int in_bits;
+    uint32_t out_buffer;
+    int out_bits;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/g726.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/g726.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,87 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/g726.h - ITU G.726 codec.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: g726.h,v 1.2 2008/11/16 12:20:57 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_G726_H_)
+#define _SPANDSP_PRIVATE_G726_H_
+
+/*!
+ * The following is the definition of the state structure
+ * used by the G.726 encoder and decoder to preserve their internal
+ * state between successive calls.  The meanings of the majority
+ * of the state structure fields are explained in detail in the
+ * CCITT Recommendation G.726.  The field names are essentially indentical
+ * to variable names in the bit level description of the coding algorithm
+ * included in this recommendation.
+ */
+struct g726_state_s
+{
+    /*! The bit rate */
+    int rate;
+    /*! The external coding, for tandem operation */
+    int ext_coding;
+    /*! The number of bits per sample */
+    unsigned int bits_per_sample;
+    /*! One of the G.726_PACKING_xxx options */
+    int packing;
+
+    /*! Locked or steady state step size multiplier. */
+    int32_t yl;
+    /*! Unlocked or non-steady state step size multiplier. */
+    int16_t yu;
+    /*! int16_t term energy estimate. */
+    int16_t dms;
+    /*! Long term energy estimate. */
+    int16_t dml;
+    /*! Linear weighting coefficient of 'yl' and 'yu'. */
+    int16_t ap;
+    
+    /*! Coefficients of pole portion of prediction filter. */
+    int16_t a[2];
+    /*! Coefficients of zero portion of prediction filter. */
+    int16_t b[6];
+    /*! Signs of previous two samples of a partially reconstructed signal. */
+    int16_t pk[2];
+    /*! Previous 6 samples of the quantized difference signal represented in
+        an internal floating point format. */
+    int16_t dq[6];
+    /*! Previous 2 samples of the quantized difference signal represented in an
+        internal floating point format. */
+    int16_t sr[2];
+    /*! Delayed tone detect */
+    int td;
+    
+    /*! \brief The bit stream processing context. */
+    bitstream_state_t bs;
+
+    /*! \brief The current encoder function. */
+    g726_encoder_func_t enc_func;
+    /*! \brief The current decoder function. */
+    g726_decoder_func_t dec_func;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/gsm0610.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/gsm0610.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,65 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/gsm0610.h - GSM 06.10 full rate speech codec.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: gsm0610.h,v 1.2 2008/11/15 14:27:29 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_GSM0610_H_)
+#define _SPANDSP_PRIVATE_GSM0610_H_
+
+/*!
+    GSM 06.10 FR codec state descriptor. This defines the state of
+    a single working instance of the GSM 06.10 FR encoder or decoder.
+*/
+struct gsm0610_state_s
+{
+    /*! \brief One of the packing modes */
+    int packing;
+
+    int16_t dp0[280];
+
+    /*! Preprocessing */
+    int16_t z1;
+    int32_t L_z2;
+    /*! Pre-emphasis */
+    int16_t mp;
+
+    /*! Short term delay filter */
+    int16_t u[8];
+    int16_t LARpp[2][8];
+    int16_t j;
+
+    /*! Long term synthesis */
+    int16_t nrp;
+    /*! Short term synthesis */
+    int16_t v[9];
+    /*! Decoder postprocessing */
+    int16_t msr;
+    
+    /*! Encoder data */
+    int16_t e[50];
+};
+
+#endif
+/*- End of include ---------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/hdlc.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/hdlc.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,136 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/hdlc.h
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: hdlc.h,v 1.1 2008/11/30 05:43:37 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_HDLC_H_)
+#define _SPANDSP_PRIVATE_HDLC_H_
+
+/*!
+    HDLC receive descriptor. This contains all the state information for an HDLC receiver.
+ */
+struct hdlc_rx_state_s
+{
+    /*! 2 for CRC-16, 4 for CRC-32 */
+    int crc_bytes;
+    /*! \brief Maximum permitted frame length. */
+    size_t max_frame_len;
+    /*! \brief The callback routine called to process each good received frame. */
+    hdlc_frame_handler_t frame_handler;
+    /*! \brief An opaque parameter passed to the callback routine. */
+    void *user_data;
+    /*! \brief TRUE if bad frames are to be reported. */
+    int report_bad_frames;
+    /*! \brief The number of consecutive flags which must be seen before framing is
+        declared OK. */
+    int framing_ok_threshold;
+    /*! \brief TRUE if framing OK has been announced. */
+    int framing_ok_announced;
+    /*! \brief Number of consecutive flags seen so far. */
+    int flags_seen;
+
+    /*! \brief The raw (stuffed) bit stream buffer. */
+    unsigned int raw_bit_stream;
+    /*! \brief The destuffed bit stream buffer. */
+    unsigned int byte_in_progress;
+    /*! \brief The current number of bits in byte_in_progress. */
+    int num_bits;
+    /*! \brief TRUE if in octet counting mode (e.g. for MTP). */
+    int octet_counting_mode;
+    /*! \brief Octet count, to achieve the functionality needed for things
+               like MTP. */
+    int octet_count;
+    /*! \brief The number of octets to be allowed between octet count reports. */
+    int octet_count_report_interval;
+
+    /*! \brief Buffer for a frame in progress. */
+    uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
+    /*! \brief Length of a frame in progress. */
+    size_t len;
+
+    /*! \brief The number of bytes of good frames received (CRC not included). */
+    unsigned long int rx_bytes;
+    /*! \brief The number of good frames received. */
+    unsigned long int rx_frames;
+    /*! \brief The number of frames with CRC errors received. */
+    unsigned long int rx_crc_errors;
+    /*! \brief The number of too short and too long frames received. */
+    unsigned long int rx_length_errors;
+    /*! \brief The number of HDLC aborts received. */
+    unsigned long int rx_aborts;
+};
+
+/*!
+    HDLC transmit descriptor. This contains all the state information for an
+    HDLC transmitter.
+ */
+struct hdlc_tx_state_s
+{
+    /*! 2 for CRC-16, 4 for CRC-32 */
+    int crc_bytes;
+    /*! \brief The callback routine called to indicate transmit underflow. */
+    hdlc_underflow_handler_t underflow_handler;
+    /*! \brief An opaque parameter passed to the callback routine. */
+    void *user_data;
+    /*! \brief The minimum flag octets to insert between frames. */
+    int inter_frame_flags;
+    /*! \brief TRUE if frame creation works in progressive mode. */
+    int progressive;
+    /*! \brief Maximum permitted frame length. */
+    size_t max_frame_len;
+
+    /*! \brief The stuffed bit stream being created. */
+    uint32_t octets_in_progress;
+    /*! \brief The number of bits currently in octets_in_progress. */
+    int num_bits;
+    /*! \brief The currently rotated state of the flag octet. */
+    int idle_octet;
+    /*! \brief The number of flag octets to send for a timed burst of flags. */
+    int flag_octets;
+    /*! \brief The number of abort octets to send for a timed burst of aborts. */
+    int abort_octets;
+    /*! \brief TRUE if the next underflow of timed flag octets should be reported */
+    int report_flag_underflow;
+
+    /*! \brief The current message being transmitted, with its CRC attached. */
+    uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
+    /*! \brief The length of the message in the buffer. */
+    size_t len;
+    /*! \brief The current send position within the buffer. */
+    int pos;
+    /*! \brief The running CRC, as data fills the frame buffer. */
+    uint32_t crc;
+
+    /*! \brief The current byte being broken into bits for transmission. */
+    int byte;
+    /*! \brief The number of bits remaining in byte. */
+    int bits;
+    
+    /*! \brief TRUE if transmission should end on buffer underflow .*/
+    int tx_end;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/ima_adpcm.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/ima_adpcm.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,55 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/ima_adpcm.c - Conversion routines between linear 16 bit PCM data
+ *		                 and IMA/DVI/Intel ADPCM format.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Based on a bit from here, a bit from there, eye of toad,
+ * ear of bat, etc - plus, of course, my own 2 cents.
+ *
+ * $Id: ima_adpcm.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_IMA_ADPCM_H_)
+#define _SPANDSP_PRIVATE_IMA_ADPCM_H_
+
+/*!
+    IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of
+    a single working instance of the IMA ADPCM converter. This is used for
+    either linear to ADPCM or ADPCM to linear conversion.
+*/
+struct ima_adpcm_state_s
+{
+    int variant;
+    /*! \brief The size of a chunk, in samples. */
+    int chunk_size;
+    /*! \brief The last state of the ADPCM algorithm. */
+    int last;
+    /*! \brief Current index into the step size table. */
+    int step_index;
+    /*! \brief The current IMA code byte in progress. */
+    uint16_t ima_byte;
+    int bits;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/logging.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/logging.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,48 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/logging.h - definitions for error and debug logging.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: logging.h,v 1.1 2008/11/30 13:44:35 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_LOGGING_H_)
+#define _SPANDSP_PRIVATE_LOGGING_H_
+
+/*!
+    Logging descriptor. This defines the working state for a single instance of
+    the logging facility for spandsp.
+*/
+struct logging_state_s
+{
+    int level;
+    int samples_per_second;
+    int64_t elapsed_samples;
+    const char *tag;
+    const char *protocol;
+
+    message_handler_func_t span_message;
+    error_handler_func_t span_error;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/lpc10.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/lpc10.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,146 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/lpc10.h - LPC10 low bit rate speech codec.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: lpc10.h,v 1.1 2008/11/30 05:43:37 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_LPC10_H_)
+#define _SPANDSP_PRIVATE_LPC10_H_
+
+/*!
+    LPC10 codec encoder state descriptor. This defines the state of
+    a single working instance of the LPC10 encoder.
+*/
+struct lpc10_encode_state_s
+{
+    int error_correction;
+
+    /* State used only by function high_pass_100hz */
+    float z11;
+    float z21;
+    float z12;
+    float z22;
+    
+    /* State used by function lpc10_analyse */
+    float inbuf[LPC10_SAMPLES_PER_FRAME*3];
+    float pebuf[LPC10_SAMPLES_PER_FRAME*3];
+    float lpbuf[696];
+    float ivbuf[312];
+    float bias;
+    int32_t osbuf[10];      /* No initial value necessary */
+    int32_t osptr;          /* Initial value 1 */
+    int32_t obound[3];
+    int32_t vwin[3][2];     /* Initial value vwin[2][0] = 307; vwin[2][1] = 462; */
+    int32_t awin[3][2];     /* Initial value awin[2][0] = 307; awin[2][1] = 462; */
+    int32_t voibuf[4][2];
+    float rmsbuf[3];
+    float rcbuf[3][10];
+    float zpre;
+
+    /* State used by function onset */
+    float n;
+    float d__;          /* Initial value 1.0f */
+    float fpc;          /* No initial value necessary */
+    float l2buf[16];
+    float l2sum1;
+    int32_t l2ptr1;     /* Initial value 1 */
+    int32_t l2ptr2;     /* Initial value 9 */
+    int32_t lasti;      /* No initial value necessary */
+    int hyst;           /* Initial value FALSE */
+
+    /* State used by function lpc10_voicing */
+    float dither;       /* Initial value 20.0f */
+    float snr;
+    float maxmin;
+    float voice[3][2];  /* Initial value is probably unnecessary */
+    int32_t lbve;
+    int32_t lbue;
+    int32_t fbve;
+    int32_t fbue;
+    int32_t ofbue;
+    int32_t sfbue;
+    int32_t olbue;
+    int32_t slbue;
+
+    /* State used by function dynamic_pitch_tracking */
+    float s[60];
+    int32_t p[2][60];
+    int32_t ipoint;
+    float alphax;
+
+    /* State used by function lpc10_pack */
+    int32_t isync;
+};
+
+/*!
+    LPC10 codec decoder state descriptor. This defines the state of
+    a single working instance of the LPC10 decoder.
+*/
+struct lpc10_decode_state_s
+{
+    int error_correction;
+
+    /* State used by function decode */
+    int32_t iptold;     /* Initial value 60 */
+    int first;          /* Initial value TRUE */
+    int32_t ivp2h;
+    int32_t iovoic;
+    int32_t iavgp;      /* Initial value 60 */
+    int32_t erate;
+    int32_t drc[10][3];
+    int32_t dpit[3];
+    int32_t drms[3];
+
+    /* State used by function synths */
+    float buf[LPC10_SAMPLES_PER_FRAME*2];
+    int32_t buflen;     /* Initial value LPC10_SAMPLES_PER_FRAME */
+
+    /* State used by function pitsyn */
+    int32_t ivoico;     /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
+    int32_t ipito;      /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
+    float rmso;         /* Initial value 1.0f */
+    float rco[10];      /* No initial value necessary as long as first_pitsyn is initially TRUE_ */
+    int32_t jsamp;      /* Nno initial value necessary as long as first_pitsyn is initially TRUE_ */
+    int first_pitsyn;   /* Initial value TRUE */
+
+    /* State used by function bsynz */
+    int32_t ipo;
+    float exc[166];
+    float exc2[166];
+    float lpi[3];
+    float hpi[3];
+    float rmso_bsynz;
+
+    /* State used by function random */
+    int32_t j;
+    int32_t k;
+    int16_t y[5];
+
+    /* State used by function deemp */
+    float dei[2];
+    float deo[3];
+};
+
+#endif
+/*- End of include ---------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/modem_connect_tones.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/modem_connect_tones.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,100 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/modem_connect_tones.c - Generation and detection of tones
+ *                                 associated with modems calling and
+ *                                 answering calls.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: modem_connect_tones.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+ 
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_MODEM_CONNECT_TONES_H_)
+#define _SPANDSP_PRIVATE_MODEM_CONNECT_TONES_H_
+
+/*!
+    Modem connect tones generator descriptor. This defines the state
+    of a single working instance of the tone generator.
+*/
+struct modem_connect_tones_tx_state_s
+{
+    int tone_type;
+
+    int32_t tone_phase_rate;
+    uint32_t tone_phase;
+    int level;
+    /*! \brief Countdown to the next phase hop */
+    int hop_timer;
+    /*! \brief Maximum duration timer */
+    int duration_timer;
+    uint32_t mod_phase;
+    int32_t mod_phase_rate;
+    int mod_level;
+};
+
+/*!
+    Modem connect tones receiver descriptor. This defines the state
+    of a single working instance of the tone detector.
+*/
+struct modem_connect_tones_rx_state_s
+{
+    /*! \brief The tone type being detected. */
+    int tone_type;
+    /*! \brief Callback routine, using to report detection of the tone. */
+    tone_report_func_t tone_callback;
+    /*! \brief An opaque pointer passed to tone_callback. */
+    void *callback_data;
+
+    /*! \brief The notch filter state. */
+    float z1;
+    float z2;
+    /*! \brief The in notch power estimate */
+    int notch_level;
+    /*! \brief The total channel power estimate */
+    int channel_level;
+    /*! \brief Sample counter for the small chunks of samples, after which a test is conducted. */
+    int chunk_remainder;
+    /*! \brief TRUE is the tone is currently confirmed present in the audio. */
+    int tone_present;
+    /*! \brief */
+    int tone_on;
+    /*! \brief A millisecond counter, to time the duration of tone sections. */
+    int tone_cycle_duration;
+    /*! \brief A count of the number of good cycles of tone reversal seen. */
+    int good_cycles;
+    /*! \brief TRUE if the tone has been seen since the last time the user tested for it */
+    int hit;
+    /*! \brief A V.21 FSK modem context used when searching for FAX preamble. */
+    fsk_rx_state_t v21rx;
+    /*! \brief The raw (stuffed) bit stream buffer. */
+    unsigned int raw_bit_stream;
+    /*! \brief The current number of bits in the octet in progress. */
+    int num_bits;
+    /*! \brief Number of consecutive flags seen so far. */
+    int flags_seen;
+    /*! \brief TRUE if framing OK has been announced. */
+    int framing_ok_announced;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/noise.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/noise.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,48 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/noise.h - A low complexity audio noise generator, suitable for
+ *                   real time generation (current just approx AWGN)
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: noise.h,v 1.1 2008/11/30 12:45:09 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_NOISE_H_)
+#define _SPANDSP_PRIVATE_NOISE_H_
+
+/*!
+    Noise generator descriptor. This contains all the state information for an instance
+    of the noise generator.
+ */
+struct noise_state_s
+{
+    int class_of_noise;
+    int quality;
+    int32_t rms;
+    uint32_t rndnum;
+    int32_t state;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/oki_adpcm.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/oki_adpcm.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,60 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/oki_adpcm.h - Conversion routines between linear 16 bit PCM data
+ *		                 and OKI (Dialogic) ADPCM format.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: oki_adpcm.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_OKI_ADPCM_H_)
+#define _SPANDSP_PRIVATE_OKI_ADPCM_H_
+
+/*!
+    Oki (Dialogic) ADPCM conversion state descriptor. This defines the state of
+    a single working instance of the Oki ADPCM converter. This is used for
+    either linear to ADPCM or ADPCM to linear conversion.
+*/
+struct oki_adpcm_state_s
+{
+    /*! \brief The bit rate - 24000 or 32000. */
+    int bit_rate;
+    /*! \brief The last state of the ADPCM algorithm. */
+    int16_t last;
+    /*! \brief Current index into the step size table. */
+    int16_t step_index;
+    /*! \brief The compressed data byte in progress. */
+    uint8_t oki_byte;
+    /*! \brief The signal history for the sample rate converter. */
+    int16_t history[32];
+    /*! \brief Pointer into the history buffer. */
+    int ptr;
+    /*! \brief Odd/even sample counter. */
+    int mark;
+    /*! \brief Phase accumulator for the sample rate converter. */
+    int phase;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/queue.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/queue.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,52 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/queue.h - simple in process message queuing
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: queue.h,v 1.1 2008/11/30 13:08:42 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_QUEUE_H_)
+#define _SPANDSP_PRIVATE_QUEUE_H_
+
+/*!
+    Queue descriptor. This defines the working state for a single instance of
+    a byte stream or message oriented queue.
+*/
+struct queue_state_s
+{
+    /*! \brief Flags indicating the mode of the queue. */
+    int flags;
+    /*! \brief The length of the data buffer. */
+    int len;
+    /*! \brief The buffer input pointer. */
+    volatile int iptr;
+    /*! \brief The buffer output pointer. */
+    volatile int optr;
+#if defined(FULLY_DEFINE_QUEUE_STATE_T)
+    /*! \brief The data buffer, sized at the time the structure is created. */
+    uint8_t data[];
+#endif
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/schedule.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/schedule.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,50 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/schedule.h
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: schedule.h,v 1.1 2008/11/30 05:43:37 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_SCHEDULE_H_)
+#define _SPANDSP_PRIVATE_SCHEDULE_H_
+
+/*! A scheduled event entry. */
+struct span_sched_s
+{
+    uint64_t when;
+    span_sched_callback_func_t callback;
+    void *user_data;
+};
+
+/*! A scheduled event queue. */
+struct span_sched_state_s
+{
+    uint64_t ticker;
+    int allocated;
+    int max_to_date;
+    span_sched_t *sched;
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/sig_tone.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/sig_tone.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,185 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/sig_tone.h - Signalling tone processing for the 2280Hz, 2400Hz, 2600Hz
+ *                      and similar signalling tone used in older protocols.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: sig_tone.h,v 1.1 2008/11/30 13:08:42 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_SIG_TONE_H_)
+#define _SPANDSP_PRIVATE_SIG_TONE_H_
+
+/*!
+    Signaling tone descriptor. This defines the working state for a
+    single instance of the transmit and receive sides of a signaling
+    tone processor.
+*/
+struct sig_tone_descriptor_s
+{
+    /*! \brief The tones used. */
+    int tone_freq[2];
+    /*! \brief The high and low tone amplitudes. */
+    int tone_amp[2];
+
+    /*! \brief The delay, in audio samples, before the high level tone drops
+               to a low level tone. */
+    int high_low_timeout;
+
+    /*! \brief Some signaling tone detectors use a sharp initial filter,
+               changing to a broader band filter after some delay. This
+               parameter defines the delay. 0 means it never changes. */
+    int sharp_flat_timeout;
+
+    /*! \brief Parameters to control the behaviour of the notch filter, used
+               to remove the tone from the voice path in some protocols. */
+    int notch_lag_time;
+    int notch_allowed;
+
+    /*! \brief The tone on persistence check, in audio samples. */
+    int tone_on_check_time;
+    /*! \brief The tone off persistence check, in audio samples. */
+    int tone_off_check_time;
+
+    int tones;
+    /*! \brief The coefficients for the cascaded bi-quads notch filter. */
+    struct
+    {
+#if defined(SPANDSP_USE_FIXED_POINT)
+        int32_t notch_a1[3];
+        int32_t notch_b1[3];
+        int32_t notch_a2[3];
+        int32_t notch_b2[3];
+        int notch_postscale;
+#else
+        float notch_a1[3];
+        float notch_b1[3];
+        float notch_a2[3];
+        float notch_b2[3];
+#endif
+    } tone[2];
+
+
+    /*! \brief Flat mode bandpass bi-quad parameters */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int32_t broad_a[3];
+    int32_t broad_b[3];
+    int broad_postscale;
+#else
+    float broad_a[3];
+    float broad_b[3];
+#endif
+    /*! \brief The coefficients for the post notch leaky integrator. */
+    int32_t notch_slugi;
+    int32_t notch_slugp;
+
+    /*! \brief The coefficients for the post modulus leaky integrator in the
+               unfiltered data path.  The prescale value incorporates the
+               detection ratio. This is called the guard ratio in some
+               protocols. */
+    int32_t unfiltered_slugi;
+    int32_t unfiltered_slugp;
+
+    /*! \brief The coefficients for the post modulus leaky integrator in the
+               bandpass filter data path. */
+    int32_t broad_slugi;
+    int32_t broad_slugp;
+
+    /*! \brief Masks which effectively threshold the notched, weighted and
+               bandpassed data. */
+    int32_t notch_threshold;
+    int32_t unfiltered_threshold;
+    int32_t broad_threshold;
+};
+
+struct sig_tone_tx_state_s
+{
+    /*! \brief The callback function used to handle signaling changes. */
+    sig_tone_func_t sig_update;
+    /*! \brief A user specified opaque pointer passed to the callback function. */
+    void *user_data;
+
+    sig_tone_descriptor_t *desc;
+
+    /*! The scaling values for the high and low level tones */
+    int32_t tone_scaling[2];
+    /*! The sample timer, used to switch between the high and low level tones. */
+    int high_low_timer;
+
+    /*! The phase rates for the one or two tones */
+    int32_t phase_rate[2];
+    /*! The phase accumulators for the one or two tones */
+    uint32_t phase_acc[2];
+
+    int current_tx_tone;
+    int current_tx_timeout;
+    int signaling_state_duration;
+};
+
+struct sig_tone_rx_state_s
+{
+    /*! \brief The callback function used to handle signaling changes. */
+    sig_tone_func_t sig_update;
+    /*! \brief A user specified opaque pointer passed to the callback function. */
+    void *user_data;
+
+    sig_tone_descriptor_t *desc;
+
+    int current_rx_tone;
+    int high_low_timer;
+
+    struct
+    {
+        /*! \brief The z's for the notch filter */
+#if defined(SPANDSP_USE_FIXED_POINT)
+        int32_t notch_z1[3];
+        int32_t notch_z2[3];
+#else
+        float notch_z1[3];
+        float notch_z2[3];
+#endif
+
+        /*! \brief The z's for the notch integrators. */
+        int32_t notch_zl;
+    } tone[2];
+
+    /*! \brief The z's for the weighting/bandpass filter. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int32_t broad_z[3];
+#else
+    float broad_z[3];
+#endif
+    /*! \brief The z for the broadband integrator. */
+    int32_t broad_zl;
+
+    int flat_mode;
+    int tone_present;
+    int notch_enabled;
+    int flat_mode_timeout;
+    int notch_insertion_timeout;
+    int tone_persistence_timeout;
+    
+    int signaling_state_duration;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_rx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_rx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,67 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/super_tone_rx.h - Flexible telephony supervisory tone detection.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: super_tone_rx.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_SUPER_TONE_RX_H_)
+#define _SPANDSP_PRIVATE_SUPER_TONE_RX_H_
+
+#define BINS            128
+
+struct super_tone_rx_segment_s
+{
+    int f1;
+    int f2;
+    int recognition_duration;
+    int min_duration;
+    int max_duration;
+};
+
+struct super_tone_rx_descriptor_s
+{
+    int used_frequencies;
+    int monitored_frequencies;
+    int pitches[BINS/2][2];
+    int tones;
+    super_tone_rx_segment_t **tone_list;
+    int *tone_segs;
+    goertzel_descriptor_t *desc;
+};
+
+struct super_tone_rx_state_s
+{
+    super_tone_rx_descriptor_t *desc;
+    float energy;
+    int detected_tone;
+    int rotation;
+    tone_report_func_t tone_callback;
+    void (*segment_callback)(void *data, int f1, int f2, int duration);
+    void *callback_data;
+    super_tone_rx_segment_t segments[11];
+    goertzel_state_t state[];
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_tx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/super_tone_tx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,52 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/super_tone_tx.h - Flexible telephony supervisory tone generation.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: super_tone_tx.h,v 1.1 2008/11/30 10:22:19 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_SUPER_TONE_TX_H_)
+#define _SPANDSP_PRIVATE_SUPER_TONE_TX_H_
+
+struct super_tone_tx_step_s
+{
+    tone_gen_tone_descriptor_t tone[4];
+    int tone_on;
+    int length;
+    int cycles;
+    super_tone_tx_step_t *next;
+    super_tone_tx_step_t *nest;
+};
+
+struct super_tone_tx_state_s
+{
+    tone_gen_tone_descriptor_t tone[4];
+    uint32_t phase[4];
+    int current_position;
+    int level;
+    super_tone_tx_step_t *levels[4];
+    int cycles[4];
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t30.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t30.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,281 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t30.h - definitions for T.30 fax processing
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t30.h,v 1.2 2009/01/03 13:02:31 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_T30_H_)
+#define _SPANDSP_PRIVATE_T30_H_
+
+/*!
+    T.30 FAX channel descriptor. This defines the state of a single working
+    instance of a T.30 FAX channel.
+*/
+struct t30_state_s
+{
+    /* This must be kept the first thing in the structure, so it can be pointed
+       to reliably as the structures change over time. */
+    /*! \brief T.4 context for reading or writing image data. */
+    t4_state_t t4;
+    
+    int operation_in_progress;
+
+    /*! \brief TRUE if behaving as the calling party */
+    int calling_party;
+    
+    /*! \brief The received DCS, formatted as an ASCII string, for inclusion
+               in the TIFF file. */
+    char rx_dcs_string[T30_MAX_DIS_DTC_DCS_LEN*3 + 1];
+    /*! \brief The text which will be used in FAX page header. No text results
+               in no header line. */
+    char header_info[T30_MAX_PAGE_HEADER_INFO + 1];
+    /*! \brief The information fields received. */
+    t30_exchanged_info_t rx_info;
+    /*! \brief The information fields to be transmitted. */
+    t30_exchanged_info_t tx_info;
+    /*! \brief The country of origin of the remote machine, if known, else NULL. */
+    const char *country;
+    /*! \brief The vendor of the remote machine, if known, else NULL. */
+    const char *vendor;
+    /*! \brief The model of the remote machine, if known, else NULL. */
+    const char *model;
+
+    /*! \brief A pointer to a callback routine to be called when phase B events
+        occur. */
+    t30_phase_b_handler_t *phase_b_handler;
+    /*! \brief An opaque pointer supplied in event B callbacks. */
+    void *phase_b_user_data;
+    /*! \brief A pointer to a callback routine to be called when phase D events
+        occur. */
+    t30_phase_d_handler_t *phase_d_handler;
+    /*! \brief An opaque pointer supplied in event D callbacks. */
+    void *phase_d_user_data;
+    /*! \brief A pointer to a callback routine to be called when phase E events
+        occur. */
+    t30_phase_e_handler_t *phase_e_handler;
+    /*! \brief An opaque pointer supplied in event E callbacks. */
+    void *phase_e_user_data;
+    /*! \brief A pointer to a callback routine to be called when frames are
+        exchanged. */
+    t30_real_time_frame_handler_t *real_time_frame_handler;
+    /*! \brief An opaque pointer supplied in real time frame callbacks. */
+    void *real_time_frame_user_data;
+
+    /*! \brief A pointer to a callback routine to be called when document events
+        (e.g. end of transmitted document) occur. */
+    t30_document_handler_t *document_handler;
+    /*! \brief An opaque pointer supplied in document callbacks. */
+    void *document_user_data;
+
+    /*! \brief The handler for changes to the receive mode */
+    t30_set_handler_t *set_rx_type_handler;
+    /*! \brief An opaque pointer passed to the handler for changes to the receive mode */
+    void *set_rx_type_user_data;
+    /*! \brief The handler for changes to the transmit mode */
+    t30_set_handler_t *set_tx_type_handler;
+    /*! \brief An opaque pointer passed to the handler for changes to the transmit mode */
+    void *set_tx_type_user_data;
+
+    /*! \brief The transmitted HDLC frame handler. */
+    t30_send_hdlc_handler_t *send_hdlc_handler;
+    /*! \brief An opaque pointer passed to the transmitted HDLC frame handler. */
+    void *send_hdlc_user_data;
+
+    /*! \brief The DIS code for the minimum scan row time we require. This is usually 0ms,
+        but if we are trying to simulate another type of FAX machine, we may need a non-zero
+        value here. */
+    uint8_t local_min_scan_time_code;
+
+    /*! \brief The current T.30 phase. */
+    int phase;
+    /*! \brief The T.30 phase to change to when the current phase ends. */
+    int next_phase;
+    /*! \brief The current state of the T.30 state machine. */
+    int state;
+    /*! \brief The step in sending a sequence of HDLC frames. */
+    int step;
+
+    /*! \brief The preparation buffer for the DCS message to be transmitted. */
+    uint8_t dcs_frame[T30_MAX_DIS_DTC_DCS_LEN];
+    /*! \brief The length of the DCS message to be transmitted. */
+    int dcs_len;
+    /*! \brief The preparation buffer for DIS or DTC message to be transmitted. */
+    uint8_t local_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
+    /*! \brief The length of the DIS or DTC message to be transmitted. */
+    int local_dis_dtc_len;
+    /*! \brief The last DIS or DTC message received form the far end. */
+    uint8_t far_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
+    /*! \brief The length of the last DIS or DTC message received form the far end. */
+    int far_dis_dtc_len;
+    /*! \brief TRUE if a valid DIS has been received from the far end. */
+    int dis_received;
+
+    /*! \brief A flag to indicate a message is in progress. */
+    int in_message;
+
+    /*! \brief TRUE if the short training sequence should be used. */
+    int short_train;
+
+    /*! \brief A count of the number of bits in the trainability test. This counts down to zero when
+        sending TCF, and counts up when receiving it. */
+    int tcf_test_bits;
+    /*! \brief The current count of consecutive received zero bits, during the trainability test. */
+    int tcf_current_zeros;
+    /*! \brief The maximum consecutive received zero bits seen to date, during the trainability test. */
+    int tcf_most_zeros;
+
+    /*! \brief The current fallback step for the fast message transfer modem. */
+    int current_fallback;
+    /*! \brief The subset of supported modems allowed at the current time, allowing for negotiation. */
+    int current_permitted_modems;
+    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
+    int rx_signal_present;
+    /*! \brief TRUE if a modem has trained correctly. */
+    int rx_trained;
+    /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */
+    int rx_frame_received;
+
+    /*! \brief Current reception mode. */
+    int current_rx_type;
+    /*! \brief Current transmission mode. */
+    int current_tx_type;
+
+    /*! \brief T0 is the answer timeout when calling another FAX machine.
+        Placing calls is handled outside the FAX processing, but this timeout keeps
+        running until V.21 modulation is sent or received.
+        T1 is the remote terminal identification timeout (in audio samples). */
+    int timer_t0_t1;
+    /*! \brief T2, T2A and T2B are the HDLC command timeouts.
+               T4, T4A and T4B are the HDLC response timeouts (in audio samples). */
+    int timer_t2_t4;
+    /*! \brief A value specifying which of the possible timers is currently running in timer_t2_t4 */
+    int timer_t2_t4_is;
+    /*! \brief Procedural interrupt timeout (in audio samples). */
+    int timer_t3;
+    /*! \brief This is only used in error correcting mode. */
+    int timer_t5;
+    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
+    int timer_t6;
+    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
+    int timer_t7;
+    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
+    int timer_t8;
+
+    /*! \brief TRUE once the far end FAX entity has been detected. */
+    int far_end_detected;
+
+    /*! \brief TRUE if a local T.30 interrupt is pending. */
+    int local_interrupt_pending;
+    /*! \brief The image coding being used on the line. */
+    int line_encoding;
+    /*! \brief The image coding being used for output files. */
+    int output_encoding;
+    /*! \brief The current DCS message minimum scan time code. */
+    uint8_t min_scan_time_code;
+    /*! \brief The X direction resolution of the current image, in pixels per metre. */
+    int x_resolution;
+    /*! \brief The Y direction resolution of the current image, in pixels per metre. */
+    int y_resolution;
+    /*! \brief The width of the current image, in pixels. */
+    t4_image_width_t image_width;
+    /*! \brief Current number of retries of the action in progress. */
+    int retries;
+    /*! \brief TRUE if error correcting mode is used. */
+    int error_correcting_mode;
+    /*! \brief The number of HDLC frame retries, if error correcting mode is used. */
+    int error_correcting_mode_retries;
+    /*! \brief The current count of consecutive T30_PPR messages. */
+    int ppr_count;
+    /*! \brief The current count of consecutive T30_RNR messages. */
+    int receiver_not_ready_count;
+    /*! \brief The number of octets to be used per ECM frame. */
+    int octets_per_ecm_frame;
+    /*! \brief The ECM partial page buffer. */
+    uint8_t ecm_data[256][260];
+    /*! \brief The lengths of the frames in the ECM partial page buffer. */
+    int16_t ecm_len[256];
+    /*! \brief A bit map of the OK ECM frames, constructed as a PPR frame. */
+    uint8_t ecm_frame_map[3 + 32];
+    
+    /*! \brief The current page number for receiving, in ECM mode. This is reset at the start of a call. */
+    int ecm_rx_page;
+    /*! \brief The current page number for sending, in ECM mode. This is reset at the start of a call. */
+    int ecm_tx_page;
+    /*! \brief The current block number, in ECM mode */
+    int ecm_block;
+    /*! \brief The number of frames in the current block number, in ECM mode */
+    int ecm_frames;
+    /*! \brief The number of frames sent in the current burst of image transmission, in ECM mode */
+    int ecm_frames_this_tx_burst;
+    /*! \brief The current ECM frame, during ECM transmission. */
+    int ecm_current_tx_frame;
+    /*! \brief TRUE if we are at the end of an ECM page to se sent - i.e. there are no more
+        partial pages still to come. */
+    int ecm_at_page_end;
+    int next_tx_step;
+    int next_rx_step;
+    /*! \brief Image file name for image reception. */
+    char rx_file[256];
+    /*! \brief The last page we are prepared accept for a received image file. -1 means no restriction. */
+    int rx_stop_page;
+    /*! \brief Image file name to be sent. */
+    char tx_file[256];
+    /*! \brief The first page to be sent from the image file. -1 means no restriction. */
+    int tx_start_page;
+    /*! \brief The last page to be sent from the image file. -1 means no restriction. */
+    int tx_stop_page;
+    int current_status;
+    /*! \brief Internet Aware FAX mode bit mask. */
+    int iaf;
+    /*! \brief A bit mask of the currently supported modem types. */
+    int supported_modems;
+    /*! \brief A bit mask of the currently supported image compression modes. */
+    int supported_compressions;
+    /*! \brief A bit mask of the currently supported image resolutions. */
+    int supported_resolutions;
+    /*! \brief A bit mask of the currently supported image sizes. */
+    int supported_image_sizes;
+    /*! \brief A bit mask of the currently supported T.30 special features. */
+    int supported_t30_features;
+    /*! \brief TRUE is ECM mode handling is enabled. */
+    int ecm_allowed;
+    
+    /*! \brief the FCF2 field of the last PPS message we received. */
+    int last_pps_fcf2;
+    /*! \brief The number of the first ECM frame which we do not currently received correctly. For
+        a partial page received correctly, this will be one greater than the number of frames it
+        contains. */
+    int ecm_first_bad_frame;
+    /*! \brief A count of successfully received ECM frames, to assess progress as a basis for
+        deciding whether to continue error correction when PPRs keep repeating. */
+    int ecm_progress;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t31.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t31.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,195 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t31.h - A T.31 compatible class 1 FAX modem interface.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t31.h,v 1.6 2009/01/16 15:13:16 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_T31_H_)
+#define _SPANDSP_PRIVATE_T31_H_
+
+/*!
+    Analogue FAX front end channel descriptor. This defines the state of a single working
+    instance of an analogue line FAX front end.
+*/
+typedef struct
+{
+    fax_modems_state_t modems;
+
+    /*! The transmit signal handler to be used when the current one has finished sending. */
+    span_tx_handler_t *next_tx_handler;
+    void *next_tx_user_data;
+
+    /*! \brief No of data bits in current_byte. */
+    int bit_no;
+    /*! \brief The current data byte in progress. */
+    int current_byte;
+
+    /*! \brief Rx power meter, used to detect silence. */
+    power_meter_t rx_power;
+    /*! \brief Last sample, used for an elementary HPF for the power meter. */
+    int16_t last_sample;
+    /*! \brief The current silence threshold. */
+    int32_t silence_threshold_power;
+
+    /*! \brief Samples of silence heard */
+    int silence_heard;
+} t31_audio_front_end_state_t;
+
+/*!
+    Analogue FAX front end channel descriptor. This defines the state of a single working
+    instance of an analogue line FAX front end.
+*/
+typedef struct
+{
+    /*! \brief Internet Aware FAX mode bit mask. */
+    int iaf;
+    /*! \brief Required time between T.38 transmissions, in ms. */
+    int ms_per_tx_chunk;
+    /*! \brief Bit fields controlling the way data is packed into chunked for transmission. */
+    int chunking_modes;
+
+    /*! \brief Core T.38 IFP support */
+    t38_core_state_t t38;
+
+    /*! \brief The current transmit step being timed */
+    int timed_step;
+
+    /*! \brief TRUE is there has been some T.38 data missed */
+    int rx_data_missing;
+
+    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
+               rate and the current specified packet interval. */
+    int octets_per_data_packet;
+
+    /*! \brief An HDLC context used when sending HDLC messages to the terminal port
+               (ECM mode support). */
+    hdlc_tx_state_t hdlc_tx_term;
+    /*! \brief An HDLC context used when receiving HDLC messages from the terminal port.
+               (ECM mode support). */
+    hdlc_rx_state_t hdlc_rx_term;
+
+    struct
+    {
+        uint8_t buf[T31_T38_MAX_HDLC_LEN];
+        int len;
+    } hdlc_rx;
+
+    struct
+    {
+        /*! \brief The number of extra bits in a fully stuffed version of the
+                   contents of the HDLC transmit buffer. This is needed to accurately
+                   estimate the playout time for this frame, through an analogue modem. */
+        int extra_bits;
+    } hdlc_tx;
+
+    /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */
+    int non_ecm_trailer_bytes;
+
+    /*! \brief The next queued tramsit indicator */
+    int next_tx_indicator;
+    /*! \brief The current T.38 data type being transmitted */
+    int current_tx_data_type;
+
+    /*! \brief The current operating mode of the receiver. */
+    int current_rx_type;
+    /*! \brief The current operating mode of the transmitter. */
+    int current_tx_type;
+
+    /*! \brief Current transmission bit rate. */
+    int tx_bit_rate;
+    /*! \brief A "sample" count, used to time events. */
+    int32_t samples;
+    /*! \brief The value for samples at the next transmission point. */
+    int32_t next_tx_samples;
+    /*! \brief The current receive timeout. */
+    int32_t timeout_rx_samples;
+} t31_t38_front_end_state_t;
+
+/*!
+    T.31 descriptor. This defines the working state for a single instance of
+    a T.31 FAX modem.
+*/
+struct t31_state_s
+{
+    at_state_t at_state;
+    t31_modem_control_handler_t *modem_control_handler;
+    void *modem_control_user_data;
+
+    t31_audio_front_end_state_t audio;
+    t31_t38_front_end_state_t t38_fe;
+    /*! TRUE if working in T.38 mode. */
+    int t38_mode;
+
+    /*! HDLC buffer, for composing an HDLC frame from the computer to the channel. */
+    struct
+    {
+        uint8_t buf[T31_MAX_HDLC_LEN];
+        int len;
+        int ptr;
+        /*! \brief TRUE when the end of HDLC data from the computer has been detected. */
+        int final;
+    } hdlc_tx;
+    /*! Buffer for data from the computer to the channel. */
+    struct
+    {
+        uint8_t data[T31_TX_BUF_LEN];
+        /*! \brief The number of bytes stored in transmit buffer. */
+        int in_bytes;
+        /*! \brief The number of bytes sent from the transmit buffer. */
+        int out_bytes;
+        /*! \brief TRUE if the flow of real data has started. */
+        int data_started;
+        /*! \brief TRUE if holding up further data into the buffer, for flow control. */
+        int holding;
+        /*! \brief TRUE when the end of non-ECM data from the computer has been detected. */
+        int final;
+    } tx;
+
+    /*! TRUE if DLE prefix just used */
+    int dled;
+
+	/*! \brief Samples of silence awaited, as specified in a "wait for silence" command */
+    int silence_awaited;
+
+    /*! \brief The current bit rate for the FAX fast message transfer modem. */
+    int bit_rate;
+    /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */
+    int rx_frame_received;
+
+    /*! \brief Samples elapsed in the current call */
+    int64_t call_samples;
+    int64_t dte_data_timeout;
+
+    /*! \brief The currently queued modem type. */
+    int modem;
+    /*! \brief TRUE when short training mode has been selected by the computer. */
+    int short_train;
+    queue_state_t *rx_queue;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_core.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_core.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,142 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t38_core.h - An implementation of T.38, less the packet exchange part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t38_core.h,v 1.2 2009/01/19 17:14:10 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_T38_CORE_H_)
+#define _SPANDSP_PRIVATE_T38_CORE_H_
+
+/*!
+    Core T.38 state, common to all modes of T.38.
+*/
+struct t38_core_state_s
+{
+    /*! Handler routine to transmit IFP packets generated by the T.38 protocol engine */
+    t38_tx_packet_handler_t *tx_packet_handler;
+    /*! An opaque pointer passed to tx_packet_handler */
+    void *tx_packet_user_data;
+
+    /*! Handler routine to process received indicator packets */
+    t38_rx_indicator_handler_t *rx_indicator_handler;
+    /*! Handler routine to process received data packets */
+    t38_rx_data_handler_t *rx_data_handler;
+    /*! Handler routine to process the missing packet condition */
+    t38_rx_missing_handler_t *rx_missing_handler;
+    /*! An opaque pointer passed to any of the above receive handling routines */
+    void *rx_user_data;
+
+    /*! NOTE - Bandwidth reduction shall only be done on suitable Phase C data, i.e., MH, MR
+        and - in the case of transcoding to JBIG - MMR. MMR and JBIG require reliable data
+        transport such as that provided by TCP. When transcoding is selected, it shall be
+        applied to every suitable page in a call. */
+
+    /*! Method 1: Local generation of TCF (required for use with TCP).
+        Method 2: Transfer of TCF is required for use with UDP (UDPTL or RTP).
+        Method 2 is not recommended for use with TCP. */
+    int data_rate_management_method;
+    
+    /*! The emitting gateway may indicate a preference for either UDP/UDPTL, or
+        UDP/RTP, or TCP for transport of T.38 IFP Packets. The receiving device
+        selects the transport protocol. */
+    int data_transport_protocol;
+
+    /*! Indicates the capability to remove and insert fill bits in Phase C, non-ECM
+        data to reduce bandwidth in the packet network. */
+    int fill_bit_removal;
+
+    /*! Indicates the ability to convert to/from MMR from/to the line format to
+        improve the compression of the data, and reduce the bandwidth, in the
+        packet network. */
+    int mmr_transcoding;
+
+    /*! Indicates the ability to convert to/from JBIG to reduce bandwidth. */
+    int jbig_transcoding;
+
+    /*! For UDP (UDPTL or RTP) modes, this option indicates the maximum
+        number of octets that can be stored on the remote device before an overflow
+        condition occurs. It is the responsibility of the transmitting application to
+        limit the transfer rate to prevent an overflow. The negotiated data rate
+        should be used to determine the rate at which data is being removed from
+        the buffer. */
+    int max_buffer_size;
+
+    /*! This option indicates the maximum size of a UDPTL packet or the
+        maximum size of the payload within an RTP packet that can be accepted by
+        the remote device. */
+    int max_datagram_size;
+
+    /*! This is the version number of ITU-T Rec. T.38. New versions shall be
+        compatible with previous versions. */
+    int t38_version;
+
+    /*! Allow time for TEP playout */
+    int allow_for_tep;
+
+    /*! The fastest data rate supported by the T.38 channel. */
+    int fastest_image_data_rate;
+
+    /*! \brief The number of times an indicator packet will be sent. Numbers greater than one
+               will increase reliability for UDP transmission. Zero is valid, to suppress all
+               indicator packets for TCP transmission. */
+    int indicator_tx_count;
+
+    /*! \brief The number of times a data packet which does not end transmission will be sent.
+               Numbers greater than one will increase reliability for UDP transmission. Zero
+               is not valid. */
+    int data_tx_count;
+
+    /*! \brief The number of times a data packet which ends transmission will be sent. Numbers
+               greater than one will increase reliability for UDP transmission. Zero is not valid. */
+    int data_end_tx_count;
+
+    /*! TRUE if IFP packet sequence numbers are relevant. For some transports, like TPKT
+        over TCP they are not relevent. */
+    int check_sequence_numbers;
+
+    /*! The sequence number for the next packet to be transmitted */
+    int tx_seq_no;
+    /*! The sequence number expected in the next received packet */
+    int rx_expected_seq_no;
+
+    /*! The current receive indicator - i.e. the last indicator received */
+    int current_rx_indicator;
+    /*! The current receive data type - i.e. the last data type received */
+    int current_rx_data_type;
+    /*! The current receive field type - i.e. the last field_type received */
+    int current_rx_field_type;
+    /*! The current transmit indicator - i.e. the last indicator transmitted */
+    int current_tx_indicator;
+    /*! The bit rate for V.34 operation */
+    int v34_rate;
+
+    /*! A count of missing receive packets. This count might not be accurate if the
+        received packet numbers jump wildly. */
+    int missing_packets;
+
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_gateway.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_gateway.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,195 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t38_gateway.h - A T.38, less the packet exchange part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005, 2006, 2007 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t38_gateway.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_T38_GATEWAY_H_)
+#define _SPANDSP_PRIVATE_T38_GATEWAY_H_
+
+/*!
+    T.38 gateway T.38 side channel descriptor.
+*/
+typedef struct
+{
+    /*! Core T.38 IFP support */
+    t38_core_state_t t38;
+
+    /*! \brief TRUE if the NSF, NSC, and NSS are to be suppressed by altering
+               their contents to something the far end will not recognise. */
+    int suppress_nsx_len[2];
+    /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
+               interpret it. The two values are for the two directions. */
+    int corrupt_current_frame[2];
+
+    /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */
+    int current_rx_field_class;
+    /*! \brief The T.38 indicator currently in use */
+    int in_progress_rx_indicator;
+
+    /*! \brief The current T.38 data type being sent. */
+    int current_tx_data_type;
+} t38_gateway_t38_state_t;
+
+/*!
+    T.38 gateway audio side channel descriptor.
+*/
+typedef struct
+{
+    fax_modems_state_t modems;
+    /*! \brief The current receive signal handler. Actual receiving hop between this
+               and a dummy receive routine. */
+    span_rx_handler_t *base_rx_handler;
+} t38_gateway_audio_state_t;
+
+typedef struct
+{
+    /*! \brief non-ECM and HDLC modem receive data buffer. */
+    uint8_t data[T38_RX_BUF_LEN];
+    /*! \brief Current pointer into the data buffer. */
+    int data_ptr;
+    /*! \brief The current octet being received as non-ECM data. */
+    unsigned int bit_stream;
+    /*! \brief The number of bits taken from the modem for the current scan row. This
+               is used during non-ECM transmission will fill bit removal to see that
+               T.38 packet transmissions do not stretch too far apart. */
+    int bits_absorbed;
+    /*! \brief The current bit number in the current non-ECM octet. */
+    int bit_no;
+    /*! \brief Progressively calculated CRC for HDLC messages received from a modem. */
+    uint16_t crc;
+    /*! \brief TRUE if non-ECM fill bits are to be stripped when sending image data. */
+    int fill_bit_removal;
+    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
+               rate and the current specified packet interval. */
+    int octets_per_data_packet;
+
+    int in_bits;
+    int out_octets;
+} t38_gateway_to_t38_state_t;
+
+typedef struct
+{
+    /*! \brief HDLC message buffers. */
+    uint8_t buf[T38_MAX_HDLC_LEN];
+    /*! \brief HDLC message lengths. */
+    int len;
+    /*! \brief HDLC message status flags. */
+    int flags;
+    /*! \brief HDLC buffer contents. */
+    int contents;
+} t38_gateway_hdlc_buf_t;
+
+typedef struct
+{
+    /*! \brief HDLC message buffers. */
+    t38_gateway_hdlc_buf_t buf[T38_TX_HDLC_BUFS];
+#if 0
+    /*! \brief HDLC message buffers. */
+    uint8_t buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN];
+    /*! \brief HDLC message lengths. */
+    int len[T38_TX_HDLC_BUFS];
+    /*! \brief HDLC message status flags. */
+    int flags[T38_TX_HDLC_BUFS];
+    /*! \brief HDLC buffer contents. */
+    int contents[T38_TX_HDLC_BUFS];
+#endif
+    /*! \brief HDLC buffer number for input. */
+    int in;
+    /*! \brief HDLC buffer number for output. */
+    int out;
+} t38_gateway_hdlc_state_t;
+
+/*!
+    T.38 gateway core descriptor.
+*/
+typedef struct
+{
+    /*! \brief A bit mask of the currently supported modem types. */
+    int supported_modems;
+    /*! \brief TRUE if ECM FAX mode is allowed through the gateway. */
+    int ecm_allowed;
+
+    /*! \brief TRUE if in image data modem is to use short training. This usually
+               follows image_data_mode, but in ECM mode T.30 defines recovery
+               conditions in which long training is used for image data. */
+    int short_train;
+    /*! \brief TRUE if in image data mode, as opposed to TCF mode. */
+    int image_data_mode;
+    /*! \brief The minimum permitted bits per FAX scan line row. */
+    int min_row_bits;
+
+    /*! \brief TRUE if we should count the next MCF as a page end, else FALSE */
+    int count_page_on_mcf;
+    /*! \brief The number of pages for which a confirm (MCF) message was returned. */
+    int pages_confirmed;
+
+    /*! \brief TRUE if we are in error correcting (ECM) mode */
+    int ecm_mode;
+    /*! \brief The current bit rate for the fast modem. */
+    int fast_bit_rate;
+    /*! \brief The current fast modem type. */
+    int fast_modem;
+    /*! \brief The type of fast receive modem currently active, which may be T38_NONE */
+    int fast_rx_active;
+
+    /*! \brief TRUE if between DCS and TCF, and we want the fast image modem to
+               start in the T.38 data at a predictable time from the end of the
+               V.21 signal. */
+    int tcf_mode_predictable_modem_start;
+
+    /*! \brief The number of samples until the next timeout event */
+    int samples_to_timeout;
+
+    /*! Buffer for HDLC and non-ECM data going to the T.38 channel */
+    t38_gateway_to_t38_state_t to_t38;
+    /*! Buffer for data going to an HDLC modem. */
+    t38_gateway_hdlc_state_t hdlc_to_modem;
+    /*! Buffer for data going to a non-ECM mode modem. */
+    t38_non_ecm_buffer_state_t non_ecm_to_modem;
+
+    /*! \brief A pointer to a callback routine to be called when frames are
+        exchanged. */
+    t38_gateway_real_time_frame_handler_t *real_time_frame_handler;
+    /*! \brief An opaque pointer supplied in real time frame callbacks. */
+    void *real_time_frame_user_data;
+} t38_gateway_core_state_t;
+
+/*!
+    T.38 gateway state.
+*/
+struct t38_gateway_state_s
+{
+    t38_gateway_t38_state_t t38x;
+    t38_gateway_audio_state_t audio;
+    t38_gateway_core_state_t core;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_non_ecm_buffer.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_non_ecm_buffer.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,86 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t38_non_ecm_buffer.h - A rate adapting buffer for T.38 non-ECM image
+ *                                and TCF data
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005, 2006, 2007, 2008 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t38_non_ecm_buffer.h,v 1.2 2008/10/13 14:19:18 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_T38_NON_ECM_BUFFER_H_)
+#define _SPANDSP_PRIVATE_T38_NON_ECM_BUFFER_H_
+
+/*! \brief A flow controlled non-ECM image data buffer, for buffering T.38 to analogue
+           modem data.
+*/
+struct t38_non_ecm_buffer_state_s
+{
+    /*! \brief Minimum number of bits per row, used when fill bits are being deleted on the
+               link, and restored at the emitting gateway. */
+    int min_row_bits;
+
+    /*! \brief non-ECM modem transmit data buffer. */
+    uint8_t data[T38_NON_ECM_TX_BUF_LEN];
+    /*! \brief The current write point in the buffer. */
+    int in_ptr;
+    /*! \brief The current read point in the buffer. */
+    int out_ptr;
+    /*! \brief The location of the most recent EOL marker in the buffer. */
+    int latest_eol_ptr;
+    /*! \brief The number of bits to date in the current row, used when min_row_bits is
+               to be applied. */
+    int row_bits;
+
+    /*! \brief The bit stream entering the buffer, used to detect EOLs */
+    unsigned int bit_stream;
+    /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00
+               once data has started). */
+    uint8_t flow_control_fill_octet;
+    /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */
+    int at_initial_all_ones;
+    /*! \brief TRUE is the end of non-ECM data indication has been received. */
+    int data_finished;
+    /*! \brief The current octet being transmitted from the buffer. */
+    unsigned int octet;
+    /*! \brief The current bit number in the current non-ECM octet. */
+    int bit_no;
+    /*! \brief TRUE if in image data mode, as opposed to TCF mode. */
+    int image_data_mode;
+
+    /*! \brief The number of octets input to the buffer. */
+    int in_octets;
+    /*! \brief The number of rows input to the buffer. */
+    int in_rows;
+    /*! \brief The number of non-ECM fill octets generated for minimum row bits
+               purposes. */
+    int min_row_bits_fill_octets;
+    /*! \brief The number of octets output from the buffer. */
+    int out_octets;
+    /*! \brief The number of rows output from the buffer. */
+    int out_rows;
+    /*! \brief The number of non-ECM fill octets generated for flow control
+               purposes. */
+    int flow_control_fill_octets;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_terminal.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t38_terminal.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,120 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t38_terminal.h - T.38 termination, less the packet exchange part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t38_terminal.h,v 1.2 2008/12/31 13:57:13 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_T38_TERMINAL_H_)
+#define _SPANDSP_PRIVATE_T38_TERMINAL_H_
+
+typedef struct
+{
+    /*! \brief Internet Aware FAX mode bit mask. */
+    int iaf;
+    /*! \brief Required time between T.38 transmissions, in ms. */
+    int ms_per_tx_chunk;
+    /*! \brief Bit fields controlling the way data is packed into chunked for transmission. */
+    int chunking_modes;
+
+    /*! \brief Core T.38 IFP support */
+    t38_core_state_t t38;
+
+    /*! \brief The current transmit step being timed */
+    int timed_step;
+
+    /*! \brief TRUE is there has been some T.38 data missed (i.e. lost packets) in the current
+               reception period. */
+    int rx_data_missing;
+
+    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
+               rate and the current specified packet interval. */
+    int octets_per_data_packet;
+
+    struct
+    {
+        /*! \brief HDLC receive buffer */
+        uint8_t buf[T38_MAX_HDLC_LEN];
+        /*! \brief The length of the contents of the HDLC receive buffer */
+        int len;
+    } hdlc_rx;
+
+    struct
+    {
+        /*! \brief HDLC transmit buffer */
+        uint8_t buf[T38_MAX_HDLC_LEN];
+        /*! \brief The length of the contents of the HDLC transmit buffer */
+        int len;
+        /*! \brief Current pointer within the contents of the HDLC transmit buffer */
+        int ptr;
+        /*! \brief The number of extra bits in a fully stuffed version of the
+                   contents of the HDLC transmit buffer. This is needed to accurately
+                   estimate the playout time for this frame, through an analogue modem. */
+        int extra_bits;
+    } hdlc_tx;
+
+    /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */
+    int non_ecm_trailer_bytes;
+
+    /*! \brief The next T.38 indicator queued for transmission. */
+    int next_tx_indicator;
+    /*! \brief The current T.38 data type being transmitted. */
+    int current_tx_data_type;
+
+    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
+    int rx_signal_present;
+
+    /*! \brief The current operating mode of the receiver. */
+    int current_rx_type;
+    /*! \brief The current operating mode of the transmitter. */
+    int current_tx_type;
+
+    /*! \brief Current transmission bit rate. */
+    int tx_bit_rate;
+    /*! \brief A "sample" count, used to time events. */
+    int32_t samples;
+    /*! \brief The value for samples at the next transmission point. */
+    int32_t next_tx_samples;
+    /*! \brief The current receive timeout. */
+    int32_t timeout_rx_samples;
+} t38_terminal_front_end_state_t;
+
+/*!
+    T.38 terminal state.
+*/
+struct t38_terminal_state_s
+{
+    /*! \brief The T.30 back-end */
+    t30_state_t t30;
+
+    /*! \brief The T.38 front-end */
+    t38_terminal_front_end_state_t t38_fe;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/t4.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/t4.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,201 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/t4.h - definitions for T.4 fax processing
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: t4.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_T4_H_)
+#define _SPANDSP_PRIVATE_T4_H_
+
+/*!
+    T.4 FAX compression/decompression descriptor. This defines the working state
+    for a single instance of a T.4 FAX compression or decompression channel.
+*/
+struct t4_state_s
+{
+    /*! \brief The same structure is used for T.4 transmit and receive. This variable
+               records which mode is in progress. */
+    int rx;
+    /* "Background" information about the FAX, which can be stored in a TIFF file. */
+    /*! \brief The vendor of the machine which produced the TIFF file. */ 
+    const char *vendor;
+    /*! \brief The model of machine which produced the TIFF file. */ 
+    const char *model;
+    /*! \brief The local ident string. */ 
+    const char *local_ident;
+    /*! \brief The remote end's ident string. */ 
+    const char *far_ident;
+    /*! \brief The FAX sub-address. */ 
+    const char *sub_address;
+    /*! \brief The FAX DCS information, as an ASCII string. */ 
+    const char *dcs;
+    /*! \brief The text which will be used in FAX page header. No text results
+               in no header line. */
+    const char *header_info;
+
+    /*! \brief The type of compression used between the FAX machines. */
+    int line_encoding;
+    /*! \brief The minimum number of encoded bits per row. This is a timing thing
+               for hardware FAX machines. */
+    int min_bits_per_row;
+    
+    /*! \brief The compression type for output to the TIFF file. */
+    int output_compression;
+    /*! \brief The TIFF G3 FAX options. */
+    int output_t4_options;
+
+    /*! \brief Callback function to read a row of pixels from the image source. */
+    t4_row_read_handler_t row_read_handler;
+    /*! \brief Opaque pointer passed to row_read_handler. */
+    void *row_read_user_data;
+    /*! \brief Callback function to write a row of pixels to the image destination. */
+    t4_row_write_handler_t row_write_handler;
+    /*! \brief Opaque pointer passed to row_write_handler. */
+    void *row_write_user_data;
+
+    /*! \brief The time at which handling of the current page began. */
+    time_t page_start_time;
+
+    /*! \brief The current number of bytes per row of uncompressed image data. */
+    int bytes_per_row;
+    /*! \brief The size of the image in the image buffer, in bytes. */
+    int image_size;
+    /*! \brief The size of the compressed image on the line side, in bits. */
+    int line_image_size;
+    /*! \brief The current size of the image buffer. */
+    int image_buffer_size;
+    /*! \brief A point to the image buffer. */
+    uint8_t *image_buffer;
+
+    /*! \brief The libtiff context for the current TIFF file */
+    TIFF *tiff_file;
+    /*! \brief The current file name. */
+    const char *file;
+    /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
+    int start_page;
+    /*! \brief The last page to transfer. -1 to continue to the end of the file. */
+    int stop_page;
+
+    /*! \brief The number of pages transferred to date. */
+    int pages_transferred;
+    /*! \brief The number of pages in the current TIFF file. */
+    int pages_in_file;
+    /*! \brief Column-to-column (X) resolution in pixels per metre. */
+    int x_resolution;
+    /*! \brief Row-to-row (Y) resolution in pixels per metre. */
+    int y_resolution;
+    /*! \brief Width of the current page, in pixels. */
+    int image_width;
+    /*! \brief Length of the current page, in pixels. */
+    int image_length;
+    /*! \brief Current pixel row number. */
+    int row;
+    /*! \brief The current number of consecutive bad rows. */
+    int curr_bad_row_run;
+    /*! \brief The longest run of consecutive bad rows seen in the current page. */
+    int longest_bad_row_run;
+    /*! \brief The total number of bad rows in the current page. */
+    int bad_rows;
+
+    /*! \brief Incoming bit buffer for decompression. */
+    uint32_t rx_bitstream;
+    /*! \brief The number of bits currently in rx_bitstream. */
+    int rx_bits;
+    /*! \brief The number of bits to be skipped before trying to match the next code word. */
+    int rx_skip_bits;
+
+    /*! \brief This variable is set if we are treating the current row as a 2D encoded
+               one. */
+    int row_is_2d;
+    /*! \brief TRUE if the current run is black */
+    int its_black;
+    /*! \brief The current length of the current row. */
+    int row_len;
+    /*! \brief This variable is used to count the consecutive EOLS we have seen. If it
+               reaches six, this is the end of the image. It is initially set to -1 for
+               1D and 2D decoding, as an indicator that we must wait for the first EOL,
+               before decodin any image data. */
+    int consecutive_eols;
+
+    /*! \brief Black and white run-lengths for the current row. */
+    uint32_t *cur_runs;
+    /*! \brief Black and white run-lengths for the reference row. */
+    uint32_t *ref_runs;
+    /*! \brief The number of runs currently in the reference row. */
+    int ref_steps;
+    /*! \brief The current step into the reference row run-lengths buffer. */
+    int b_cursor;
+    /*! \brief The current step into the current row run-lengths buffer. */
+    int a_cursor;
+
+    /*! \brief The reference or starting changing element on the coding line. At the
+               start of the coding line, a0 is set on an imaginary white changing element
+               situated just before the first element on the line. During the coding of
+               the coding line, the position of a0 is defined by the previous coding mode.
+               (See 4.2.1.3.2.). */
+    int a0;
+    /*! \brief The first changing element on the reference line to the right of a0 and of
+               opposite colour to a0. */
+    int b1;
+    /*! \brief The length of the in-progress run of black or white. */
+    int run_length;
+    /*! \brief 2D horizontal mode control. */
+    int black_white;
+
+    /*! \brief Encoded data bits buffer. */
+    uint32_t tx_bitstream;
+    /*! \brief The number of bits currently in tx_bitstream. */
+    int tx_bits;
+
+    /*! \brief A pointer into the image buffer indicating where the last row begins */
+    int last_row_starts_at;
+    /*! \brief A pointer into the image buffer indicating where the current row begins */
+    int row_starts_at;
+    
+    /*! \brief Pointer to the buffer for the current pixel row. */
+    uint8_t *row_buf;
+    
+    /*! \brief Pointer to the byte containing the next image bit to transmit. */
+    int bit_pos;
+    /*! \brief Pointer to the bit within the byte containing the next image bit to transmit. */
+    int bit_ptr;
+
+    /*! \brief The current maximum contiguous rows that may be 2D encoded. */
+    int max_rows_to_next_1d_row;
+    /*! \brief Number of rows left that can be 2D encoded, before a 1D encoded row
+               must be used. */
+    int rows_to_next_1d_row;
+    /*! \brief The current number of bits in the current encoded row. */
+    int row_bits;
+    /*! \brief The minimum bits in any row of the current page. For monitoring only. */
+    int min_row_bits;
+    /*! \brief The maximum bits in any row of the current page. For monitoring only. */
+    int max_row_bits;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/time_scale.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/time_scale.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,52 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/time_scale.h - Time scaling for linear speech data
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: time_scale.h,v 1.1 2008/11/15 14:27:29 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_TIME_SCALE_H_)
+#define _SPANDSP_PRIVATE_TIME_SCALE_H_
+
+#define TIME_SCALE_MAX_SAMPLE_RATE  48000
+#define TIME_SCALE_MIN_PITCH        60
+#define TIME_SCALE_MAX_PITCH        250
+#define TIME_SCALE_BUF_LEN          (2*TIME_SCALE_MAX_SAMPLE_RATE/TIME_SCALE_MIN_PITCH)
+
+/*! Audio time scaling descriptor. */
+struct time_scale_state_s
+{
+    int sample_rate;
+    int min_pitch;
+    int max_pitch;
+    int buf_len;
+    float playout_rate;
+    double rcomp;
+    double rate_nudge;
+    int fill;
+    int lcp;
+    int16_t buf[TIME_SCALE_BUF_LEN];
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_detect.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_detect.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,32 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/tone_detect.h - General telephony tone detection.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001, 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: tone_detect.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_TONE_DETECT_H_)
+#define _SPANDSP_PRIVATE_TONE_DETECT_H_
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_generate.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/tone_generate.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,68 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/tone_generate.h - General telephony tone generation.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2001 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: tone_generate.h,v 1.1 2008/11/30 10:17:31 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_TONE_GENERATE_H_)
+#define _SPANDSP_PRIVATE_TONE_GENERATE_H_
+
+struct tone_gen_tone_descriptor_s
+{
+    int32_t phase_rate;
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int16_t gain;
+#else
+    float gain;
+#endif
+};
+
+/*!
+    Cadenced multi-tone generator descriptor.
+*/
+struct tone_gen_descriptor_s
+{
+    tone_gen_tone_descriptor_t tone[4];
+    int duration[4];
+    int repeat;
+};
+
+/*!
+    Cadenced multi-tone generator state descriptor. This defines the state of
+    a single working instance of a generator.
+*/
+struct tone_gen_state_s
+{
+    tone_gen_tone_descriptor_t tone[4];
+
+    uint32_t phase[4];
+    int duration[4];
+    int repeat;
+
+    int current_section;
+    int current_position;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v17rx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v17rx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,210 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v17rx.h - ITU V.17 modem receive part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v17rx.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V17RX_H_)
+#define _SPANDSP_PRIVATE_V17RX_H_
+
+/*!
+    V.17 modem receive side descriptor. This defines the working state for a
+    single instance of a V.17 modem receiver.
+*/
+struct v17_rx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 7200 9600, 12000 and 14400. */
+    int bit_rate;
+    /*! \brief The callback function used to put each bit received. */
+    put_bit_func_t put_bit;
+    /*! \brief A user specified opaque pointer passed to the put_but routine. */
+    void *put_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_rx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    /*! \brief A callback function which may be enabled to report every symbol's
+               constellation position. */
+    qam_report_handler_t qam_report;
+    /*! \brief A user specified opaque pointer passed to the qam_report callback
+               routine. */
+    void *qam_user_data;
+
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int16_t rrc_filter[V17_RX_FILTER_STEPS];
+#else
+    float rrc_filter[V17_RX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+
+    /*! \brief The state of the differential decoder */
+    int diff;
+    /*! \brief The register for the data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief TRUE if the short training sequence is to be used. */
+    int short_train;
+    /*! \brief The section of the training data we are currently in. */
+    int training_stage;
+    /*! \brief A count of how far through the current training step we are. */
+    int training_count;
+    /*! \brief A measure of how much mismatch there is between the real constellation,
+        and the decoded symbol positions. */
+    float training_error;
+    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
+    int16_t last_sample;
+    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.17 signal. */
+    int signal_present;
+    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
+    int carrier_drop_pending;
+    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
+    int low_samples;
+    /*! \brief A highest magnitude sample seen. */
+    int16_t high_sample;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The carrier update rate saved for reuse when using short training. */
+    int32_t carrier_phase_rate_save;
+#if defined(SPANDSP_USE_FIXED_POINTx)
+    /*! \brief The proportional part of the carrier tracking filter. */
+    float carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    float carrier_track_i;
+#else
+    /*! \brief The proportional part of the carrier tracking filter. */
+    float carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    float carrier_track_i;
+#endif
+
+    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
+    power_meter_t power;
+    /*! \brief The power meter level at which carrier on is declared. */
+    int32_t carrier_on_power;
+    /*! \brief The power meter level at which carrier off is declared. */
+    int32_t carrier_off_power;
+
+    /*! \brief Current read offset into the equalizer buffer. */
+    int eq_step;
+    /*! \brief Current write offset into the equalizer buffer. */
+    int eq_put_step;
+    /*! \brief Symbol counter to the next equalizer update. */
+    int eq_skip;
+
+    /*! \brief The current half of the baud. */
+    int baud_half;
+
+#if defined(SPANDSP_USE_FIXED_POINTx)
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    float agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    float agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    float eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    complexi16_t eq_coeff[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    complexi16_t eq_coeff_save[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    complexi16_t eq_buf[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+
+    /*! Low band edge filter for symbol sync. */
+    int32_t symbol_sync_low[2];
+    /*! High band edge filter for symbol sync. */
+    int32_t symbol_sync_high[2];
+    /*! DC filter for symbol sync. */
+    int32_t symbol_sync_dc_filter[2];
+    /*! Baud phase for symbol sync. */
+    int32_t baud_phase;
+#else
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    float agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    float agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    float eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    complexf_t eq_coeff[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    complexf_t eq_coeff_save[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    complexf_t eq_buf[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
+
+    /*! Low band edge filter for symbol sync. */
+    float symbol_sync_low[2];
+    /*! High band edge filter for symbol sync. */
+    float symbol_sync_high[2];
+    /*! DC filter for symbol sync. */
+    float symbol_sync_dc_filter[2];
+    /*! Baud phase for symbol sync. */
+    float baud_phase;
+#endif
+
+    /*! \brief The total symbol timing correction since the carrier came up.
+               This is only for performance analysis purposes. */
+    int total_baud_timing_correction;
+
+    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
+    int32_t start_angles[2];
+    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
+    int32_t angles[16];
+    /*! \brief A pointer to the current constellation. */
+#if defined(SPANDSP_USE_FIXED_POINTx)
+    const complexi16_t *constellation;
+#else
+    const complexf_t *constellation;
+#endif
+    /*! \brief A pointer to the current space map. There is a space map for
+               each trellis state. */
+    int space_map;
+    /*! \brief The number of bits in each symbol at the current bit rate. */
+    int bits_per_symbol;
+
+    /*! \brief Current pointer to the trellis buffers */
+    int trellis_ptr;
+    /*! \brief The trellis. */
+    int full_path_to_past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
+    /*! \brief The trellis. */
+    int past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
+    /*! \brief Euclidean distances (actually the squares of the distances)
+               from the last states of the trellis. */
+#if defined(SPANDSP_USE_FIXED_POINTx)
+    uint32_t distances[8];
+#else
+    float distances[8];
+#endif
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v17tx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v17tx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,106 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v17tx.h - ITU V.17 modem transmit part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v17tx.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+/*! \file */
+
+#if !defined(_SPANDSP_PRIVATE_V17TX_H_)
+#define _SPANDSP_PRIVATE_V17TX_H_
+
+/*!
+    V.17 modem transmit side descriptor. This defines the working state for a
+    single instance of a V.17 modem transmitter.
+*/
+struct v17_tx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
+    int bit_rate;
+    /*! \brief The callback function used to get the next bit to be transmitted. */
+    get_bit_func_t get_bit;
+    /*! \brief A user specified opaque pointer passed to the get_bit function. */
+    void *get_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_tx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    /*! \brief The gain factor needed to achieve the specified output power. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int32_t gain;
+#else
+    float gain;
+#endif
+
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    complexi16_t rrc_filter[2*V17_TX_FILTER_STEPS];
+#else
+    complexf_t rrc_filter[2*V17_TX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+
+    /*! \brief The current state of the differential encoder. */
+    int diff;
+    /*! \brief The current state of the convolutional encoder. */
+    int convolution;
+
+    /*! \brief The register for the data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief TRUE if transmitting the training sequence. FALSE if transmitting user data. */
+    int in_training;
+    /*! \brief TRUE if the short training sequence is to be used. */
+    int short_train;
+    /*! \brief A counter used to track progress through sending the training sequence. */
+    int training_step;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The current fractional phase of the baud timing. */
+    int baud_phase;
+    /*! \brief The code number for the current position in the constellation. */
+    int constellation_state;
+    
+    /*! \brief A pointer to the constellation currently in use. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    const complexi16_t *constellation;
+#else
+    const complexf_t *constellation;
+#endif
+    /*! \brief The current number of data bits per symbol. This does not include
+               the redundant bit. */
+    int bits_per_symbol;
+    /*! \brief The get_bit function in use at any instant. */
+    get_bit_func_t current_get_bit;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v22bis.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v22bis.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,183 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v22bis.h - ITU V.22bis modem
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v22bis.h,v 1.1 2008/11/30 03:39:58 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V22BIS_H_)
+#define _SPANDSP_PRIVATE_V22BIS_H_
+
+/*!
+    V.22bis modem descriptor. This defines the working state for a single instance
+    of a V.22bis modem.
+*/
+struct v22bis_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 1200 and 2400. */
+    int bit_rate;
+    /*! \brief TRUE is this is the calling side modem. */
+    int caller;
+    /*! \brief The callback function used to put each bit received. */
+    put_bit_func_t put_bit;
+    /*! \brief The callback function used to get the next bit to be transmitted. */
+    get_bit_func_t get_bit;
+    /*! \brief A user specified opaque pointer passed to the callback routines. */
+    void *user_data;
+
+    /* RECEIVE SECTION */
+    struct
+    {
+        /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+        float rrc_filter[2*V22BIS_RX_FILTER_STEPS];
+        /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+        int rrc_filter_step;
+
+        /*! \brief The register for the data scrambler. */
+        unsigned int scramble_reg;
+        /*! \brief A counter for the number of consecutive bits of repeating pattern through
+                   the scrambler. */
+        int scrambler_pattern_count;
+
+        /*! \brief 0 if receiving user data. A training stage value during training */
+        int training;
+        /*! \brief A count of how far through the current training step we are. */
+        int training_count;
+
+        /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
+        int signal_present;
+
+        /*! \brief A measure of how much mismatch there is between the real constellation,
+            and the decoded symbol positions. */
+        float training_error;
+
+        /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+        uint32_t carrier_phase;
+        /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+        int32_t carrier_phase_rate;
+        /*! \brief The proportional part of the carrier tracking filter. */
+        float carrier_track_p;
+        /*! \brief The integral part of the carrier tracking filter. */
+        float carrier_track_i;
+
+        /*! \brief A callback function which may be enabled to report every symbol's
+                   constellation position. */
+        qam_report_handler_t qam_report;
+        /*! \brief A user specified opaque pointer passed to the qam_report callback
+                   routine. */
+        void *qam_user_data;
+
+        /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
+        power_meter_t rx_power;
+        /*! \brief The power meter level at which carrier on is declared. */
+        int32_t carrier_on_power;
+        /*! \brief The power meter level at which carrier off is declared. */
+        int32_t carrier_off_power;
+        /*! \brief The scaling factor accessed by the AGC algorithm. */
+        float agc_scaling;
+    
+        int constellation_state;
+
+        /*! \brief The current delta factor for updating the equalizer coefficients. */
+        float eq_delta;
+#if defined(SPANDSP_USE_FIXED_POINTx)
+        /*! \brief The adaptive equalizer coefficients. */
+        complexi_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
+        /*! \brief The equalizer signal buffer. */
+        complexi_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
+#else
+        complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
+        complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
+#endif
+        /*! \brief Current offset into the equalizer buffer. */
+        int eq_step;
+        /*! \brief Current write offset into the equalizer buffer. */
+        int eq_put_step;
+
+        /*! \brief Integration variable for damping the Gardner algorithm tests. */
+        int gardner_integrate;
+        /*! \brief Current step size of Gardner algorithm integration. */
+        int gardner_step;
+        /*! \brief The total symbol timing correction since the carrier came up.
+                   This is only for performance analysis purposes. */
+        int total_baud_timing_correction;
+        /*! \brief The current fractional phase of the baud timing. */
+        int baud_phase;
+    
+        int sixteen_way_decisions;
+    } rx;
+
+    /* TRANSMIT SECTION */
+    struct
+    {
+        /*! \brief The gain factor needed to achieve the specified output power. */
+        float gain;
+
+        /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+        complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS];
+        /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+        int rrc_filter_step;
+
+        /*! \brief The register for the data scrambler. */
+        unsigned int scramble_reg;
+        /*! \brief A counter for the number of consecutive bits of repeating pattern through
+                   the scrambler. */
+        int scrambler_pattern_count;
+
+        /*! \brief 0 if transmitting user data. A training stage value during training */
+        int training;
+        /*! \brief A counter used to track progress through sending the training sequence. */
+        int training_count;
+        /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+        uint32_t carrier_phase;
+        /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+        int32_t carrier_phase_rate;
+        /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */
+        uint32_t guard_phase;
+        /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */
+        int32_t guard_phase_rate;
+        float guard_level;
+        /*! \brief The current fractional phase of the baud timing. */
+        int baud_phase;
+        /*! \brief The code number for the current position in the constellation. */
+        int constellation_state;
+        /*! \brief An indicator to mark that we are tidying up to stop transmission. */
+        int shutdown;
+        /*! \brief The get_bit function in use at any instant. */
+        get_bit_func_t current_get_bit;
+    } tx;
+
+    int detected_unscrambled_ones;
+    int detected_unscrambled_zeros;
+
+    int detected_unscrambled_ones_or_zeros;
+    int detected_unscrambled_0011_ending;
+    int detected_scrambled_ones_or_zeros_at_1200bps;
+    int detected_scrambled_ones_at_2400bps;
+
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_rx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_rx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,178 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v27ter_rx.h - ITU V.27ter modem receive part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v27ter_rx.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V27TER_RX_H_)
+#define _SPANDSP_PRIVATE_V27TER_RX_H_
+
+/*!
+    V.27ter modem receive side descriptor. This defines the working state for a
+    single instance of a V.27ter modem receiver.
+*/
+struct v27ter_rx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
+    int bit_rate;
+    /*! \brief The callback function used to put each bit received. */
+    put_bit_func_t put_bit;
+    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
+    void *put_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_rx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    /*! \brief A callback function which may be enabled to report every symbol's
+               constellation position. */
+    qam_report_handler_t qam_report;
+    /*! \brief A user specified opaque pointer passed to the qam_report callback
+               routine. */
+    void *qam_user_data;
+
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int16_t rrc_filter[V27TER_RX_FILTER_STEPS];
+#else
+    float rrc_filter[V27TER_RX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+
+    /*! \brief The register for the training and data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief A counter for the number of consecutive bits of repeating pattern through
+               the scrambler. */
+    int scrambler_pattern_count;
+    /*! \brief The current step in the table of BC constellation positions. */
+    int training_bc;
+    /*! \brief TRUE if the previous trained values are to be reused. */
+    int old_train;
+    /*! \brief The section of the training data we are currently in. */
+    int training_stage;
+    /*! \brief A count of how far through the current training step we are. */
+    int training_count;
+    /*! \brief A measure of how much mismatch there is between the real constellation,
+        and the decoded symbol positions. */
+    float training_error;
+    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
+    int16_t last_sample;
+    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.27ter signal. */
+    int signal_present;
+    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
+    int carrier_drop_pending;
+    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
+    int low_samples;
+    /*! \brief A highest magnitude sample seen. */
+    int16_t high_sample;
+
+    /*! \brief The position of the current symbol in the constellation, used for
+               differential decoding. */
+    int constellation_state;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The carrier update rate saved for reuse when using short training. */
+    int32_t carrier_phase_rate_save;
+#if defined(SPANDSP_USE_FIXED_POINTx)
+    /*! \brief The proportional part of the carrier tracking filter. */
+    float carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    float carrier_track_i;
+#else
+    /*! \brief The proportional part of the carrier tracking filter. */
+    float carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    float carrier_track_i;
+#endif
+
+    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
+    power_meter_t power;
+    /*! \brief The power meter level at which carrier on is declared. */
+    int32_t carrier_on_power;
+    /*! \brief The power meter level at which carrier off is declared. */
+    int32_t carrier_off_power;
+
+    /*! \brief Current read offset into the equalizer buffer. */
+    int eq_step;
+    /*! \brief Current write offset into the equalizer buffer. */
+    int eq_put_step;
+    /*! \brief Symbol counter to the next equalizer update. */
+    int eq_skip;
+
+    /*! \brief The current half of the baud. */
+    int baud_half;
+
+#if defined(SPANDSP_USE_FIXED_POINT)
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    int16_t agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    int16_t agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    float eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    /*complexi16_t*/ complexf_t  eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    /*complexi16_t*/ complexf_t  eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    /*complexi16_t*/ complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+#else
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    float agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    float agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    float eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    complexf_t eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    complexf_t eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
+#endif
+
+    /*! \brief Integration variable for damping the Gardner algorithm tests. */
+    int gardner_integrate;
+    /*! \brief Current step size of Gardner algorithm integration. */
+    int gardner_step;
+    /*! \brief The total symbol timing correction since the carrier came up.
+               This is only for performance analysis purposes. */
+    int total_baud_timing_correction;
+
+    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
+    int32_t start_angles[2];
+    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
+    int32_t angles[16];
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_tx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v27ter_tx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,95 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v27ter_tx.h - ITU V.27ter modem transmit part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v27ter_tx.h,v 1.2 2008/12/06 14:35:04 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V27TER_TX_H_)
+#define _SPANDSP_PRIVATE_V27TER_TX_H_
+
+/*!
+    V.27ter modem transmit side descriptor. This defines the working state for a
+    single instance of a V.27ter modem transmitter.
+*/
+struct v27ter_tx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
+    int bit_rate;
+    /*! \brief The callback function used to get the next bit to be transmitted. */
+    get_bit_func_t get_bit;
+    /*! \brief A user specified opaque pointer passed to the get_bit function. */
+    void *get_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_tx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+#if defined(SPANDSP_USE_FIXED_POINT)
+    /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */
+    int32_t gain_2400;
+    /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */
+    int32_t gain_4800;
+#else
+    /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */
+    float gain_2400;
+    /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */
+    float gain_4800;
+#endif
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    complexi16_t rrc_filter[2*V27TER_TX_FILTER_STEPS];
+#else
+    complexf_t rrc_filter[2*V27TER_TX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+    
+    /*! \brief The register for the training and data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief A counter for the number of consecutive bits of repeating pattern through
+               the scrambler. */
+    int scrambler_pattern_count;
+    /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
+               FALSE if transmitting user data. */
+    int in_training;
+    /*! \brief A counter used to track progress through sending the training sequence. */
+    int training_step;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The current fractional phase of the baud timing. */
+    int baud_phase;
+    /*! \brief The code number for the current position in the constellation. */
+    int constellation_state;
+    /*! \brief The get_bit function in use at any instant. */
+    get_bit_func_t current_get_bit;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v29rx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v29rx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,191 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v29rx.h - ITU V.29 modem receive part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v29rx.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V29RX_H_)
+#define _SPANDSP_PRIVATE_V29RX_H_
+
+/*!
+    V.29 modem receive side descriptor. This defines the working state for a
+    single instance of a V.29 modem receiver.
+*/
+struct v29_rx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
+    int bit_rate;
+    /*! \brief The callback function used to put each bit received. */
+    put_bit_func_t put_bit;
+    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
+    void *put_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_rx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    /*! \brief A callback function which may be enabled to report every symbol's
+               constellation position. */
+    qam_report_handler_t qam_report;
+    /*! \brief A user specified opaque pointer passed to the qam_report callback
+               routine. */
+    void *qam_user_data;
+
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int16_t rrc_filter[V29_RX_FILTER_STEPS];
+#else
+    float rrc_filter[V29_RX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+
+    /*! \brief The register for the data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief The register for the training scrambler. */
+    uint8_t training_scramble_reg;
+    /*! \brief The current step in the table of CD constellation positions. */
+    int training_cd;
+    /*! \brief TRUE if the previous trained values are to be reused. */
+    int old_train;
+    /*! \brief The section of the training data we are currently in. */
+    int training_stage;
+    /*! \brief A count of how far through the current training step we are. */
+    int training_count;
+    /*! \brief A measure of how much mismatch there is between the real constellation,
+        and the decoded symbol positions. */
+    float training_error;
+    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
+    int16_t last_sample;
+    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.29 signal. */
+    int signal_present;
+    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
+    int carrier_drop_pending;
+    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
+    int low_samples;
+    /*! \brief A highest magnitude sample seen. */
+    int16_t high_sample;
+
+    /*! \brief The position of the current symbol in the constellation, used for
+               differential decoding. */
+    int constellation_state;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The carrier update rate saved for reuse when using short training. */
+    int32_t carrier_phase_rate_save;
+#if defined(SPANDSP_USE_FIXED_POINT)
+    /*! \brief The proportional part of the carrier tracking filter. */
+    int32_t carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    int32_t carrier_track_i;
+#else
+    /*! \brief The proportional part of the carrier tracking filter. */
+    float carrier_track_p;
+    /*! \brief The integral part of the carrier tracking filter. */
+    float carrier_track_i;
+#endif
+
+    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
+    power_meter_t power;
+    /*! \brief The power meter level at which carrier on is declared. */
+    int32_t carrier_on_power;
+    /*! \brief The power meter level at which carrier off is declared. */
+    int32_t carrier_off_power;
+
+    /*! \brief Current read offset into the equalizer buffer. */
+    int eq_step;
+    /*! \brief Current write offset into the equalizer buffer. */
+    int eq_put_step;
+    /*! \brief Symbol counter to the next equalizer update. */
+    int eq_skip;
+
+    /*! \brief The current half of the baud. */
+    int baud_half;
+
+#if defined(SPANDSP_USE_FIXED_POINT)
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    int16_t agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    int16_t agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    int16_t eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    complexi16_t eq_coeff[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    complexi16_t eq_coeff_save[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    complexi16_t eq_buf[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+
+    /*! Low band edge filter for symbol sync. */
+    int32_t symbol_sync_low[2];
+    /*! High band edge filter for symbol sync. */
+    int32_t symbol_sync_high[2];
+    /*! DC filter for symbol sync. */
+    int32_t symbol_sync_dc_filter[2];
+    /*! Baud phase for symbol sync. */
+    int32_t baud_phase;
+#else
+    /*! \brief The scaling factor accessed by the AGC algorithm. */
+    float agc_scaling;
+    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
+    float agc_scaling_save;
+
+    /*! \brief The current delta factor for updating the equalizer coefficients. */
+    float eq_delta;
+    /*! \brief The adaptive equalizer coefficients. */
+    complexf_t eq_coeff[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
+    complexf_t eq_coeff_save[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+    /*! \brief The equalizer signal buffer. */
+    complexf_t eq_buf[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
+
+    /*! Low band edge filter for symbol sync. */
+    float symbol_sync_low[2];
+    /*! High band edge filter for symbol sync. */
+    float symbol_sync_high[2];
+    /*! DC filter for symbol sync. */
+    float symbol_sync_dc_filter[2];
+    /*! Baud phase for symbol sync. */
+    float baud_phase;
+#endif
+
+    /*! \brief The total symbol timing correction since the carrier came up.
+               This is only for performance analysis purposes. */
+    int total_baud_timing_correction;
+
+    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
+    int32_t start_angles[2];
+    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
+    int32_t angles[16];
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v29tx.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v29tx.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,97 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v29tx.h - ITU V.29 modem transmit part
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v29tx.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V29TX_H_)
+#define _SPANDSP_PRIVATE_V29TX_H_
+
+/*!
+    V.29 modem transmit side descriptor. This defines the working state for a
+    single instance of a V.29 modem transmitter.
+*/
+struct v29_tx_state_s
+{
+    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
+    int bit_rate;
+    /*! \brief The callback function used to get the next bit to be transmitted. */
+    get_bit_func_t get_bit;
+    /*! \brief A user specified opaque pointer passed to the get_bit function. */
+    void *get_bit_user_data;
+
+    /*! \brief The callback function used to report modem status changes. */
+    modem_tx_status_func_t status_handler;
+    /*! \brief A user specified opaque pointer passed to the status function. */
+    void *status_user_data;
+
+    /*! \brief Gain required to achieve the specified output power, not allowing
+               for the size of the current constellation. */
+    float base_gain;
+    /*! \brief Gain required to achieve the specified output power, allowing
+               for the size of the current constellation. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    int32_t gain;
+#else
+    float gain;
+#endif
+
+    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
+#if defined(SPANDSP_USE_FIXED_POINT)
+    complexi16_t rrc_filter[2*V29_TX_FILTER_STEPS];
+#else
+    complexf_t rrc_filter[2*V29_TX_FILTER_STEPS];
+#endif
+    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
+    int rrc_filter_step;
+
+    /*! \brief The register for the data scrambler. */
+    unsigned int scramble_reg;
+    /*! \brief The register for the training scrambler. */
+    uint8_t training_scramble_reg;
+    /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
+               FALSE if transmitting user data. */
+    int in_training;
+    /*! \brief A counter used to track progress through sending the training sequence. */
+    int training_step;
+    /*! \brief An offset value into the table of training parameters, used to match the
+               training pattern to the bit rate. */
+    int training_offset;
+
+    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
+    uint32_t carrier_phase;
+    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
+    int32_t carrier_phase_rate;
+    /*! \brief The current fractional phase of the baud timing. */
+    int baud_phase;
+    /*! \brief The code number for the current position in the constellation. */
+    int constellation_state;
+    /*! \brief The get_bit function in use at any instant. */
+    get_bit_func_t current_get_bit;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v42.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v42.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,119 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v42.h
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2003 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v42.h,v 1.1 2008/11/15 14:43:08 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V42_H_)
+#define _SPANDSP_PRIVATE_V42_H_
+
+/*!
+    LAP-M descriptor. This defines the working state for a single instance of LAP-M.
+*/
+struct lapm_state_s
+{
+    int handle;
+    hdlc_rx_state_t hdlc_rx;
+    hdlc_tx_state_t hdlc_tx;
+    
+    v42_frame_handler_t iframe_receive;
+    void *iframe_receive_user_data;
+
+    v42_status_func_t status_callback;
+    void *status_callback_user_data;
+
+    int state;
+    int tx_waiting;
+    int debug;
+    /*! TRUE if originator. FALSE if answerer */
+    int we_are_originator;
+    /*! Remote network type (unknown, answerer. originator) */
+    int peer_is_originator;
+    /*! Next N(S) for transmission */
+    int next_tx_frame;
+    /*! The last of our frames which the peer acknowledged */
+    int last_frame_peer_acknowledged;
+    /*! Next N(R) for reception */
+    int next_expected_frame;
+    /*! The last of the peer's frames which we acknowledged */
+    int last_frame_we_acknowledged;
+    /*! TRUE if we sent an I or S frame with the F-bit set */
+    int solicit_f_bit;
+    /*! Retransmission count */
+    int retransmissions;
+    /*! TRUE if peer is busy */
+    int busy;
+
+    /*! Acknowledgement timer */
+    int t401_timer;
+    /*! Reply delay timer - optional */
+    int t402_timer;
+    /*! Inactivity timer - optional */
+    int t403_timer;
+    /*! Maximum number of octets in an information field */
+    int n401;
+    /*! Window size */
+    int window_size_k;
+	
+    lapm_frame_queue_t *txqueue;
+    lapm_frame_queue_t *tx_next;
+    lapm_frame_queue_t *tx_last;
+    queue_state_t *tx_queue;
+    
+    span_sched_state_t sched;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+/*!
+    V.42 descriptor. This defines the working state for a single instance of V.42.
+*/
+struct v42_state_s
+{
+    /*! TRUE if we are the calling party, otherwise FALSE */
+    int caller;
+    /*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go
+        directly to protocol establishment */
+    int detect;
+
+    /*! Stage in negotiating V.42 support */
+    int rx_negotiation_step;
+    int rxbits;
+    int rxstream;
+    int rxoks;
+    int odp_seen;
+    int txbits;
+    int txstream;
+    int txadps;
+    /*! The LAP.M context */
+    lapm_state_t lapm;
+
+    /*! V.42 support detection timer */
+    int t400_timer;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v42bis.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v42bis.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,151 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v42bis.h
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2005 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v42bis.h,v 1.1 2008/11/15 14:43:08 steveu Exp $
+ */
+
+#if !defined(_SPANDSP_PRIVATE_V42BIS_H_)
+#define _SPANDSP_PRIVATE_V42BIS_H_
+
+/*!
+    V.42bis dictionary node.
+*/
+typedef struct
+{
+    /*! \brief The prior code for each defined code. */
+    uint16_t parent_code;
+    /*! \brief The number of leaf nodes this node has */
+    int16_t leaves;
+    /*! \brief This leaf octet for each defined code. */
+    uint8_t node_octet;
+    /*! \brief Bit map of the children which exist */
+    uint32_t children[8];
+} v42bis_dict_node_t;
+
+/*!
+    V.42bis compression. This defines the working state for a single instance
+    of V.42bis compression.
+*/
+typedef struct
+{
+    /*! \brief Compression mode. */
+    int compression_mode;
+    /*! \brief Callback function to handle received frames. */
+    v42bis_frame_handler_t handler;
+    /*! \brief An opaque pointer passed in calls to frame_handler. */
+    void *user_data;
+    /*! \brief The maximum frame length allowed */
+    int max_len;
+
+    uint32_t string_code;
+    uint32_t latest_code;
+    int string_length;
+    uint32_t output_bit_buffer;
+    int output_bit_count;
+    int output_octet_count;
+    uint8_t output_buf[1024];
+    v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
+    /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
+    int transparent;
+    int change_transparency;
+    /*! \brief IIR filter state, used in assessing compressibility. */
+    int compressibility_filter;
+    int compressibility_persistence;
+    
+    /*! \brief Next empty dictionary entry */
+    uint32_t v42bis_parm_c1;
+    /*! \brief Current codeword size */
+    int v42bis_parm_c2;
+    /*! \brief Threshold for codeword size change */
+    uint32_t v42bis_parm_c3;
+
+    /*! \brief Mark that this is the first octet/code to be processed */
+    int first;
+    uint8_t escape_code;
+} v42bis_compress_state_t;
+
+/*!
+    V.42bis decompression. This defines the working state for a single instance
+    of V.42bis decompression.
+*/
+typedef struct
+{
+    /*! \brief Callback function to handle decompressed data. */
+    v42bis_data_handler_t handler;
+    /*! \brief An opaque pointer passed in calls to data_handler. */
+    void *user_data;
+    /*! \brief The maximum decompressed data block length allowed */
+    int max_len;
+
+    uint32_t old_code;
+    uint32_t last_old_code;
+    uint32_t input_bit_buffer;
+    int input_bit_count;
+    int octet;
+    int last_length;
+    int output_octet_count;
+    uint8_t output_buf[1024];
+    v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
+    /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
+    int transparent;
+
+    int last_extra_octet;
+
+    /*! \brief Next empty dictionary entry */
+    uint32_t v42bis_parm_c1;
+    /*! \brief Current codeword size */
+    int v42bis_parm_c2;
+    /*! \brief Threshold for codeword size change */
+    uint32_t v42bis_parm_c3;
+        
+    /*! \brief Mark that this is the first octet/code to be processed */
+    int first;
+    uint8_t escape_code;
+    int escaped;
+} v42bis_decompress_state_t;
+
+/*!
+    V.42bis compression/decompression descriptor. This defines the working state for a
+    single instance of V.42bis compress/decompression.
+*/
+struct v42bis_state_s
+{
+    /*! \brief V.42bis data compression directions. */
+    int v42bis_parm_p0;
+
+    /*! \brief Compression state. */
+    v42bis_compress_state_t compress;
+    /*! \brief Decompression state. */
+    v42bis_decompress_state_t decompress;
+    
+    /*! \brief Maximum codeword size (bits) */
+    int v42bis_parm_n1;
+    /*! \brief Total number of codewords */
+    uint32_t v42bis_parm_n2;
+    /*! \brief Maximum string length */
+    int v42bis_parm_n7;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Added: freeswitch/trunk/libs/spandsp/src/spandsp/private/v8.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/private/v8.h	Tue Jan 27 22:48:03 2009
@@ -0,0 +1,82 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * private/v8.h - V.8 modem negotiation processing.
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2004 Steve Underwood
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id: v8.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
+ */
+ 
+#if !defined(_SPANDSP_PRIVATE_V8_H_)
+#define _SPANDSP_PRIVATE_V8_H_
+
+struct v8_state_s
+{
+    /*! \brief TRUE if we are the calling modem */
+    int caller;
+    /*! \brief The current state of the V8 protocol */
+    int state;
+    int negotiation_timer;
+    int ci_timer;
+    int ci_count;
+    fsk_tx_state_t v21tx;
+    fsk_rx_state_t v21rx;
+    queue_state_t *tx_queue;
+    modem_connect_tones_tx_state_t ansam_tx;
+    modem_connect_tones_rx_state_t ansam_rx;
+
+    v8_result_handler_t *result_handler;
+    void *result_handler_user_data;
+
+    /*! \brief Modulation schemes available at this end. */
+    int available_modulations;
+    int common_modulations;
+    int negotiated_modulation;
+    int far_end_modulations;
+    
+    int call_function;
+    int protocol;
+    int pstn_access;
+    int nsf_seen;
+    int pcm_modem_availability;
+    int t66_seen;
+
+    /* V8 data parsing */
+    unsigned int bit_stream;
+    int bit_cnt;
+    /* Indicates the type of message coming up */
+    int preamble_type;
+    uint8_t rx_data[64];
+    int rx_data_ptr;
+    
+    /*! \brief a reference copy of the last CM or JM message, used when
+               testing for matches. */
+    uint8_t cm_jm_data[64];
+    int cm_jm_count;
+    int got_cm_jm;
+    int got_cj;
+    int zero_byte_count;
+    /*! \brief Error and flow logging control */
+    logging_state_t logging;
+};
+
+#endif
+/*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/queue.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/queue.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/queue.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: queue.h,v 1.17 2008/09/09 16:25:51 steveu Exp $
+ * $Id: queue.h,v 1.18 2008/11/30 13:08:42 steveu Exp $
  */
 
 /*! \file */
@@ -53,21 +53,7 @@
     Queue descriptor. This defines the working state for a single instance of
     a byte stream or message oriented queue.
 */
-typedef struct
-{
-    /*! \brief Flags indicating the mode of the queue. */
-    int flags;
-    /*! \brief The length of the data buffer. */
-    int len;
-    /*! \brief The buffer input pointer. */
-    volatile int iptr;
-    /*! \brief The buffer output pointer. */
-    volatile int optr;
-#if defined(FULLY_DEFINE_QUEUE_STATE_T)
-    /*! \brief The data buffer, sized at the time the structure is created. */
-    uint8_t data[];
-#endif
-} queue_state_t;
+typedef struct queue_state_s queue_state_t;
 
 #define QUEUE_STATE_T_SIZE(len) (sizeof(queue_state_t) + len + 1)
 

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/schedule.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/schedule.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/schedule.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: schedule.h,v 1.16 2008/04/17 14:27:00 steveu Exp $
+ * $Id: schedule.h,v 1.17 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \file */
@@ -38,27 +38,13 @@
 #if !defined(_SPANDSP_SCHEDULE_H_)
 #define _SPANDSP_SCHEDULE_H_
 
-typedef struct span_sched_state_s span_sched_state_t;
-
-typedef void (*span_sched_callback_func_t)(span_sched_state_t *s, void *user_data);
-
 /*! A scheduled event entry. */
-typedef struct
-{
-    uint64_t when;
-    span_sched_callback_func_t callback;
-    void *user_data;
-} span_sched_t;
+typedef struct span_sched_s span_sched_t;
 
 /*! A scheduled event queue. */
-struct span_sched_state_s
-{
-    uint64_t ticker;
-    int allocated;
-    int max_to_date;
-    span_sched_t *sched;
-    logging_state_t logging;
-};
+typedef struct span_sched_state_s span_sched_state_t;
+
+typedef void (*span_sched_callback_func_t)(span_sched_state_t *s, void *user_data);
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/sig_tone.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/sig_tone.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/sig_tone.h	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: sig_tone.h,v 1.14 2008/07/29 14:15:21 steveu Exp $
+ * $Id: sig_tone.h,v 1.15 2008/11/30 13:08:42 steveu Exp $
  */
 
 /*! \file */
@@ -87,152 +87,11 @@
     single instance of the transmit and receive sides of a signaling
     tone processor.
 */
-typedef struct
-{
-    /*! \brief The tones used. */
-    int tone_freq[2];
-    /*! \brief The high and low tone amplitudes. */
-    int tone_amp[2];
-
-    /*! \brief The delay, in audio samples, before the high level tone drops
-               to a low level tone. */
-    int high_low_timeout;
-
-    /*! \brief Some signaling tone detectors use a sharp initial filter,
-               changing to a broader band filter after some delay. This
-               parameter defines the delay. 0 means it never changes. */
-    int sharp_flat_timeout;
-
-    /*! \brief Parameters to control the behaviour of the notch filter, used
-               to remove the tone from the voice path in some protocols. */
-    int notch_lag_time;
-    int notch_allowed;
-
-    /*! \brief The tone on persistence check, in audio samples. */
-    int tone_on_check_time;
-    /*! \brief The tone off persistence check, in audio samples. */
-    int tone_off_check_time;
-
-    int tones;
-    /*! \brief The coefficients for the cascaded bi-quads notch filter. */
-    struct
-    {
-#if defined(SPANDSP_USE_FIXED_POINT)
-        int32_t notch_a1[3];
-        int32_t notch_b1[3];
-        int32_t notch_a2[3];
-        int32_t notch_b2[3];
-        int notch_postscale;
-#else
-        float notch_a1[3];
-        float notch_b1[3];
-        float notch_a2[3];
-        float notch_b2[3];
-#endif
-    } tone[2];
-
+typedef struct sig_tone_descriptor_s sig_tone_descriptor_t;
 
-    /*! \brief Flat mode bandpass bi-quad parameters */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int32_t broad_a[3];
-    int32_t broad_b[3];
-    int broad_postscale;
-#else
-    float broad_a[3];
-    float broad_b[3];
-#endif
-    /*! \brief The coefficients for the post notch leaky integrator. */
-    int32_t notch_slugi;
-    int32_t notch_slugp;
-
-    /*! \brief The coefficients for the post modulus leaky integrator in the
-               unfiltered data path.  The prescale value incorporates the
-               detection ratio. This is called the guard ratio in some
-               protocols. */
-    int32_t unfiltered_slugi;
-    int32_t unfiltered_slugp;
-
-    /*! \brief The coefficients for the post modulus leaky integrator in the
-               bandpass filter data path. */
-    int32_t broad_slugi;
-    int32_t broad_slugp;
-
-    /*! \brief Masks which effectively threshold the notched, weighted and
-               bandpassed data. */
-    int32_t notch_threshold;
-    int32_t unfiltered_threshold;
-    int32_t broad_threshold;
-} sig_tone_descriptor_t;
-
-typedef struct
-{
-    /*! \brief The callback function used to handle signaling changes. */
-    sig_tone_func_t sig_update;
-    /*! \brief A user specified opaque pointer passed to the callback function. */
-    void *user_data;
-
-    sig_tone_descriptor_t *desc;
-
-    /*! The scaling values for the high and low level tones */
-    int32_t tone_scaling[2];
-    /*! The sample timer, used to switch between the high and low level tones. */
-    int high_low_timer;
-
-    /*! The phase rates for the one or two tones */
-    int32_t phase_rate[2];
-    /*! The phase accumulators for the one or two tones */
-    uint32_t phase_acc[2];
-
-    int current_tx_tone;
-    int current_tx_timeout;
-    int signaling_state_duration;
-} sig_tone_tx_state_t;
-
-typedef struct
-{
-    /*! \brief The callback function used to handle signaling changes. */
-    sig_tone_func_t sig_update;
-    /*! \brief A user specified opaque pointer passed to the callback function. */
-    void *user_data;
-
-    sig_tone_descriptor_t *desc;
-
-    int current_rx_tone;
-    int high_low_timer;
-
-    struct
-    {
-        /*! \brief The z's for the notch filter */
-#if defined(SPANDSP_USE_FIXED_POINT)
-        int32_t notch_z1[3];
-        int32_t notch_z2[3];
-#else
-        float notch_z1[3];
-        float notch_z2[3];
-#endif
-
-        /*! \brief The z's for the notch integrators. */
-        int32_t notch_zl;
-    } tone[2];
-
-    /*! \brief The z's for the weighting/bandpass filter. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int32_t broad_z[3];
-#else
-    float broad_z[3];
-#endif
-    /*! \brief The z for the broadband integrator. */
-    int32_t broad_zl;
+typedef struct sig_tone_tx_state_s sig_tone_tx_state_t;
 
-    int flat_mode;
-    int tone_present;
-    int notch_enabled;
-    int flat_mode_timeout;
-    int notch_insertion_timeout;
-    int tone_persistence_timeout;
-    
-    int signaling_state_duration;
-} sig_tone_rx_state_t;
+typedef struct sig_tone_rx_state_s sig_tone_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_rx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_rx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_rx.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_rx.h,v 1.17 2008/06/13 14:46:52 steveu Exp $
+ * $Id: super_tone_rx.h,v 1.18 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if !defined(_SPANDSP_SUPER_TONE_RX_H_)
@@ -57,40 +57,11 @@
 /*! Tone detection indication callback routine */
 typedef void (*tone_report_func_t)(void *user_data, int code, int level, int delay);
 
-#define BINS            128
+typedef struct super_tone_rx_segment_s super_tone_rx_segment_t;
 
-typedef struct
-{
-    int f1;
-    int f2;
-    int recognition_duration;
-    int min_duration;
-    int max_duration;
-} super_tone_rx_segment_t;
-
-typedef struct
-{
-    int used_frequencies;
-    int monitored_frequencies;
-    int pitches[BINS/2][2];
-    int tones;
-    super_tone_rx_segment_t **tone_list;
-    int *tone_segs;
-    goertzel_descriptor_t *desc;
-} super_tone_rx_descriptor_t;
+typedef struct super_tone_rx_descriptor_s super_tone_rx_descriptor_t;
 
-typedef struct
-{
-    super_tone_rx_descriptor_t *desc;
-    float energy;
-    int detected_tone;
-    int rotation;
-    tone_report_func_t tone_callback;
-    void (*segment_callback)(void *data, int f1, int f2, int duration);
-    void *callback_data;
-    super_tone_rx_segment_t segments[11];
-    goertzel_state_t state[];
-} super_tone_rx_state_t;
+typedef struct super_tone_rx_state_s super_tone_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_tx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_tx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/super_tone_tx.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_tx.h,v 1.13 2008/04/17 14:27:00 steveu Exp $
+ * $Id: super_tone_tx.h,v 1.14 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if !defined(_SPANDSP_SUPER_TONE_TX_H_)
@@ -43,25 +43,7 @@
 
 typedef struct super_tone_tx_step_s super_tone_tx_step_t;
 
-struct super_tone_tx_step_s
-{
-    tone_gen_tone_descriptor_t tone[4];
-    int tone_on;
-    int length;
-    int cycles;
-    super_tone_tx_step_t *next;
-    super_tone_tx_step_t *nest;
-};
-
-typedef struct
-{
-    tone_gen_tone_descriptor_t tone[4];
-    uint32_t phase[4];
-    int current_position;
-    int level;
-    super_tone_tx_step_t *levels[4];
-    int cycles[4];
-} super_tone_tx_state_t;
+typedef struct super_tone_tx_state_s super_tone_tx_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t30.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t30.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t30.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t30.h,v 1.115 2008/09/04 14:40:05 steveu Exp $
+ * $Id: t30.h,v 1.120 2009/01/19 17:14:10 steveu Exp $
  */
 
 /*! \file */
@@ -329,45 +329,76 @@
         dying. */
     T30_FRONT_END_RECEIVE_COMPLETE,
     T30_FRONT_END_SIGNAL_PRESENT,
-    T30_FRONT_END_SIGNAL_ABSENT
+    T30_FRONT_END_SIGNAL_ABSENT,
+    T30_FRONT_END_CED_PRESENT,
+    T30_FRONT_END_CNG_PRESENT
 };
 
 enum
 {
+    /*! Support the V.27ter modem (2400, and 4800bps) for image transfer. */
     T30_SUPPORT_V27TER = 0x01,
+    /*! Support the V.29 modem (9600, and 7200bps) for image transfer. */
     T30_SUPPORT_V29 = 0x02,
+    /*! Support the V.17 modem (14400, 12000, 9600 and 7200bps) for image transfer. */
     T30_SUPPORT_V17 = 0x04,
+    /*! Support the V.34 modem (up to 33,600bps) for image transfer. */
     T30_SUPPORT_V34 = 0x08,
+    /*! Support the Internet Aware FAX mode (no bit rate limit) for image transfer. */
     T30_SUPPORT_IAF = 0x10
 };
 
 enum
 {
+    /*! No compression */
     T30_SUPPORT_NO_COMPRESSION = 0x01,
+    /*! T.1 1D compression */
     T30_SUPPORT_T4_1D_COMPRESSION = 0x02,
+    /*! T.4 2D compression */
     T30_SUPPORT_T4_2D_COMPRESSION = 0x04,
+    /*! T.6 2D compression */
     T30_SUPPORT_T6_COMPRESSION = 0x08,
-    T30_SUPPORT_T85_COMPRESSION = 0x10,     /* Monochrome JBIG */
-    T30_SUPPORT_T43_COMPRESSION = 0x20,     /* Colour JBIG */
-    T30_SUPPORT_T45_COMPRESSION = 0x40      /* Run length colour compression */
+    /*! T.85 monochrome JBIG coding */
+    T30_SUPPORT_T85_COMPRESSION = 0x10,
+    /*! T.43 colour JBIG coding */
+    T30_SUPPORT_T43_COMPRESSION = 0x20,
+    /*! T.45 run length colour compression */
+    T30_SUPPORT_T45_COMPRESSION = 0x40,
+    /*! T.81 + T.30 Annex E colour JPEG coding */
+    T30_SUPPORT_T81_COMPRESSION = 0x80,
+    /*! T.81 + T.30 Annex K colour sYCC-JPEG coding */
+    T30_SUPPORT_SYCC_T81_COMPRESSION = 0x100
 };
 
 enum
 {
+    /*! Support standard FAX Y-resolution 98/100dpi */
     T30_SUPPORT_STANDARD_RESOLUTION = 0x01,
+    /*! Support fine FAX Y-resolution 196/200dpi */
     T30_SUPPORT_FINE_RESOLUTION = 0x02,
+    /*! Support super-fine FAX Y-resolution 392/400dpi */
     T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04,
 
+    /*! Support half FAX X-resolution 100/102dpi */
     T30_SUPPORT_R4_RESOLUTION = 0x10000,
+    /*! Support standard FAX X-resolution 200/204dpi */
     T30_SUPPORT_R8_RESOLUTION = 0x20000,
+    /*! Support double FAX X-resolution 400dpi */
     T30_SUPPORT_R16_RESOLUTION = 0x40000,
 
+    /*! Support 300dpi x 300 dpi */
     T30_SUPPORT_300_300_RESOLUTION = 0x100000,
+    /*! Support 400dpi x 400 dpi */
     T30_SUPPORT_400_400_RESOLUTION = 0x200000,
+    /*! Support 600dpi x 600 dpi */
     T30_SUPPORT_600_600_RESOLUTION = 0x400000,
+    /*! Support 1200dpi x 1200 dpi */
     T30_SUPPORT_1200_1200_RESOLUTION = 0x800000,
+    /*! Support 300dpi x 600 dpi */
     T30_SUPPORT_300_600_RESOLUTION = 0x1000000,
+    /*! Support 400dpi x 800 dpi */
     T30_SUPPORT_400_800_RESOLUTION = 0x2000000,
+    /*! Support 600dpi x 1200 dpi */
     T30_SUPPORT_600_1200_RESOLUTION = 0x4000000
 };
 
@@ -386,29 +417,29 @@
 
 enum
 {
-    /*! Enable support of identification, through the SID and/or PWD frames */
+    /*! Enable support of identification, through the SID and/or PWD frames. */
     T30_SUPPORT_IDENTIFICATION = 0x01,
-    /*! Enable support of selective polling, through the SEP frame */
+    /*! Enable support of selective polling, through the SEP frame. */
     T30_SUPPORT_SELECTIVE_POLLING = 0x02,
-    /*! Enable support of polling sub-addressing, through the PSA frame */
+    /*! Enable support of polling sub-addressing, through the PSA frame. */
     T30_SUPPORT_POLLED_SUB_ADDRESSING = 0x04,
-    /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames */
+    /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames. */
     T30_SUPPORT_MULTIPLE_SELECTIVE_POLLING = 0x08,
-    /*! Enable support of sub-addressing, through the SUB frame */
+    /*! Enable support of sub-addressing, through the SUB frame. */
     T30_SUPPORT_SUB_ADDRESSING = 0x10,
-    /*! Enable support of transmitting subscriber internet address, through the TSA frame */
+    /*! Enable support of transmitting subscriber internet address, through the TSA frame. */
     T30_SUPPORT_TRANSMITTING_SUBSCRIBER_INTERNET_ADDRESS = 0x20,
-    /*! Enable support of internet routing address, through the IRA frame */
+    /*! Enable support of internet routing address, through the IRA frame. */
     T30_SUPPORT_INTERNET_ROUTING_ADDRESS = 0x40,
-    /*! Enable support of calling subscriber internet address, through the CIA frame */
+    /*! Enable support of calling subscriber internet address, through the CIA frame. */
     T30_SUPPORT_CALLING_SUBSCRIBER_INTERNET_ADDRESS = 0x80,
-    /*! Enable support of internet selective polling address, through the ISP frame */
+    /*! Enable support of internet selective polling address, through the ISP frame. */
     T30_SUPPORT_INTERNET_SELECTIVE_POLLING_ADDRESS = 0x100,
-    /*! Enable support of called subscriber internet address, through the CSA frame */
+    /*! Enable support of called subscriber internet address, through the CSA frame. */
     T30_SUPPORT_CALLED_SUBSCRIBER_INTERNET_ADDRESS = 0x200,
-    /*! Enable support of the field not valid (FNV) frame */
+    /*! Enable support of the field not valid (FNV) frame. */
     T30_SUPPORT_FIELD_NOT_VALID = 0x400,
-    /*! Enable support of the command repeat (CRP) frame */
+    /*! Enable support of the command repeat (CRP) frame. */
     T30_SUPPORT_COMMAND_REPEAT = 0x800
 };
 
@@ -427,7 +458,10 @@
         them. */
     T30_IAF_MODE_NO_FILL_BITS = 0x20,
     /*! No indicators means do not send indicator messages when using T.38. */
-    T30_IAF_MODE_NO_INDICATORS = 0x40
+    T30_IAF_MODE_NO_INDICATORS = 0x40,
+    /*! Use relaxed timers for T.38. This is appropriate when using TCP/TPKT for T.38,
+        as there is no point in anything but a long backstop timeout in such a mode. */
+    T30_IAF_MODE_RELAXED_TIMERS = 0x80
 };
 
 typedef struct
@@ -475,251 +509,6 @@
     size_t csa_len;
 } t30_exchanged_info_t;
 
-/*!
-    T.30 FAX channel descriptor. This defines the state of a single working
-    instance of a T.30 FAX channel.
-*/
-struct t30_state_s
-{
-    /* This must be kept the first thing in the structure, so it can be pointed
-       to reliably as the structures change over time. */
-    /*! \brief T.4 context for reading or writing image data. */
-    t4_state_t t4;
-    
-    int operation_in_progress;
-
-    /*! \brief TRUE if behaving as the calling party */
-    int calling_party;
-    
-    /*! \brief The received DCS, formatted as an ASCII string, for inclusion
-               in the TIFF file. */
-    char rx_dcs_string[T30_MAX_DIS_DTC_DCS_LEN*3 + 1];
-    /*! \brief The text which will be used in FAX page header. No text results
-               in no header line. */
-    char header_info[T30_MAX_PAGE_HEADER_INFO + 1];
-    /*! \brief The information fields received. */
-    t30_exchanged_info_t rx_info;
-    /*! \brief The information fields to be transmitted. */
-    t30_exchanged_info_t tx_info;
-    /*! \brief The country of origin of the remote machine, if known, else NULL. */
-    const char *country;
-    /*! \brief The vendor of the remote machine, if known, else NULL. */
-    const char *vendor;
-    /*! \brief The model of the remote machine, if known, else NULL. */
-    const char *model;
-
-    /*! \brief A pointer to a callback routine to be called when phase B events
-        occur. */
-    t30_phase_b_handler_t *phase_b_handler;
-    /*! \brief An opaque pointer supplied in event B callbacks. */
-    void *phase_b_user_data;
-    /*! \brief A pointer to a callback routine to be called when phase D events
-        occur. */
-    t30_phase_d_handler_t *phase_d_handler;
-    /*! \brief An opaque pointer supplied in event D callbacks. */
-    void *phase_d_user_data;
-    /*! \brief A pointer to a callback routine to be called when phase E events
-        occur. */
-    t30_phase_e_handler_t *phase_e_handler;
-    /*! \brief An opaque pointer supplied in event E callbacks. */
-    void *phase_e_user_data;
-    /*! \brief A pointer to a callback routine to be called when frames are
-        exchanged. */
-    t30_real_time_frame_handler_t *real_time_frame_handler;
-    /*! \brief An opaque pointer supplied in real time frame callbacks. */
-    void *real_time_frame_user_data;
-
-    /*! \brief A pointer to a callback routine to be called when document events
-        (e.g. end of transmitted document) occur. */
-    t30_document_handler_t *document_handler;
-    /*! \brief An opaque pointer supplied in document callbacks. */
-    void *document_user_data;
-
-    /*! \brief The handler for changes to the receive mode */
-    t30_set_handler_t *set_rx_type_handler;
-    /*! \brief An opaque pointer passed to the handler for changes to the receive mode */
-    void *set_rx_type_user_data;
-    /*! \brief The handler for changes to the transmit mode */
-    t30_set_handler_t *set_tx_type_handler;
-    /*! \brief An opaque pointer passed to the handler for changes to the transmit mode */
-    void *set_tx_type_user_data;
-
-    /*! \brief The transmitted HDLC frame handler. */
-    t30_send_hdlc_handler_t *send_hdlc_handler;
-    /*! \brief An opaque pointer passed to the transmitted HDLC frame handler. */
-    void *send_hdlc_user_data;
-
-    /*! \brief The DIS code for the minimum scan row time we require. This is usually 0ms,
-        but if we are trying to simulate another type of FAX machine, we may need a non-zero
-        value here. */
-    uint8_t local_min_scan_time_code;
-
-    /*! \brief The current T.30 phase. */
-    int phase;
-    /*! \brief The T.30 phase to change to when the current phase ends. */
-    int next_phase;
-    /*! \brief The current state of the T.30 state machine. */
-    int state;
-    /*! \brief The step in sending a sequence of HDLC frames. */
-    int step;
-
-    /*! \brief The preparation buffer for the DCS message to be transmitted. */
-    uint8_t dcs_frame[T30_MAX_DIS_DTC_DCS_LEN];
-    /*! \brief The length of the DCS message to be transmitted. */
-    int dcs_len;
-    /*! \brief The preparation buffer for DIS or DTC message to be transmitted. */
-    uint8_t local_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
-    /*! \brief The length of the DIS or DTC message to be transmitted. */
-    int local_dis_dtc_len;
-    /*! \brief The last DIS or DTC message received form the far end. */
-    uint8_t far_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
-    /*! \brief The length of the last DIS or DTC message received form the far end. */
-    int far_dis_dtc_len;
-    /*! \brief TRUE if a valid DIS has been received from the far end. */
-    int dis_received;
-
-    /*! \brief A flag to indicate a message is in progress. */
-    int in_message;
-
-    /*! \brief TRUE if the short training sequence should be used. */
-    int short_train;
-
-    /*! \brief A count of the number of bits in the trainability test. This counts down to zero when
-        sending TCF, and counts up when receiving it. */
-    int tcf_test_bits;
-    /*! \brief The current count of consecutive received zero bits, during the trainability test. */
-    int tcf_current_zeros;
-    /*! \brief The maximum consecutive received zero bits seen to date, during the trainability test. */
-    int tcf_most_zeros;
-
-    /*! \brief The current fallback step for the fast message transfer modem. */
-    int current_fallback;
-    /*! \brief The subset of supported modems allowed at the current time, allowing for negotiation. */
-    int current_permitted_modems;
-    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
-    int rx_signal_present;
-    /*! \brief TRUE if a modem has trained correctly. */
-    int rx_trained;
-    /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */
-    int rx_frame_received;
-
-    /*! \brief Current reception mode. */
-    int current_rx_type;
-    /*! \brief Current transmission mode. */
-    int current_tx_type;
-
-    /*! \brief T0 is the answer timeout when calling another FAX machine.
-        Placing calls is handled outside the FAX processing, but this timeout keeps
-        running until V.21 modulation is sent or received.
-        T1 is the remote terminal identification timeout (in audio samples). */
-    int timer_t0_t1;
-    /*! \brief T2, T2A and T2B are the HDLC command timeouts.
-               T4, T4A and T4B are the HDLC response timeouts (in audio samples). */
-    int timer_t2_t4;
-    /*! \brief A value specifying which of the possible timers is currently running in timer_t2_t4 */
-    int timer_t2_t4_is;
-    /*! \brief Procedural interrupt timeout (in audio samples). */
-    int timer_t3;
-    /*! \brief This is only used in error correcting mode. */
-    int timer_t5;
-    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
-    int timer_t6;
-    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
-    int timer_t7;
-    /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
-    int timer_t8;
-
-    /*! \brief TRUE once the far end FAX entity has been detected. */
-    int far_end_detected;
-
-    /*! \brief TRUE if a local T.30 interrupt is pending. */
-    int local_interrupt_pending;
-    /*! \brief The image coding being used on the line. */
-    int line_encoding;
-    /*! \brief The image coding being used for output files. */
-    int output_encoding;
-    /*! \brief The current DCS message minimum scan time code. */
-    uint8_t min_scan_time_code;
-    /*! \brief The X direction resolution of the current image, in pixels per metre. */
-    int x_resolution;
-    /*! \brief The Y direction resolution of the current image, in pixels per metre. */
-    int y_resolution;
-    /*! \brief The width of the current image, in pixels. */
-    t4_image_width_t image_width;
-    /*! \brief Current number of retries of the action in progress. */
-    int retries;
-    /*! \brief TRUE if error correcting mode is used. */
-    int error_correcting_mode;
-    /*! \brief The current count of consecutive T30_PPR messages. */
-    int ppr_count;
-    /*! \brief The current count of consecutive T30_RNR messages. */
-    int receiver_not_ready_count;
-    /*! \brief The number of octets to be used per ECM frame. */
-    int octets_per_ecm_frame;
-    /*! \brief The ECM partial page buffer. */
-    uint8_t ecm_data[256][260];
-    /*! \brief The lengths of the frames in the ECM partial page buffer. */
-    int16_t ecm_len[256];
-    /*! \brief A bit map of the OK ECM frames, constructed as a PPR frame. */
-    uint8_t ecm_frame_map[3 + 32];
-    
-    /*! \brief The current page number for receiving, in ECM mode. This is reset at the start of a call. */
-    int ecm_rx_page;
-    /*! \brief The current page number for sending, in ECM mode. This is reset at the start of a call. */
-    int ecm_tx_page;
-    /*! \brief The current block number, in ECM mode */
-    int ecm_block;
-    /*! \brief The number of frames in the current block number, in ECM mode */
-    int ecm_frames;
-    /*! \brief The number of frames sent in the current burst of image transmission, in ECM mode */
-    int ecm_frames_this_tx_burst;
-    /*! \brief The current ECM frame, during ECM transmission. */
-    int ecm_current_tx_frame;
-    /*! \brief TRUE if we are at the end of an ECM page to se sent - i.e. there are no more
-        partial pages still to come. */
-    int ecm_at_page_end;
-    int next_tx_step;
-    int next_rx_step;
-    /*! \brief Image file name for image reception. */
-    char rx_file[256];
-    /*! \brief The last page we are prepared accept for a received image file. -1 means no restriction. */
-    int rx_stop_page;
-    /*! \brief Image file name to be sent. */
-    char tx_file[256];
-    /*! \brief The first page to be sent from the image file. -1 means no restriction. */
-    int tx_start_page;
-    /*! \brief The last page to be sent from the image file. -1 means no restriction. */
-    int tx_stop_page;
-    int current_status;
-    /*! \brief Internet Aware FAX mode bit mask. */
-    int iaf;
-    /*! \brief A bit mask of the currently supported modem types. */
-    int supported_modems;
-    /*! \brief A bit mask of the currently supported image compression modes. */
-    int supported_compressions;
-    /*! \brief A bit mask of the currently supported image resolutions. */
-    int supported_resolutions;
-    /*! \brief A bit mask of the currently supported image sizes. */
-    int supported_image_sizes;
-    /*! \brief A bit mask of the currently supported T.30 special features. */
-    int supported_t30_features;
-    /*! \brief TRUE is ECM mode handling is enabled. */
-    int ecm_allowed;
-    
-    /*! \brief the FCF2 field of the last PPS message we received. */
-    int last_pps_fcf2;
-    /*! \brief The number of the first ECM frame which we do not currently received correctly. For
-        a partial page received correctly, this will be one greater than the number of frames it
-        contains. */
-    int ecm_first_bad_frame;
-    /*! \brief A count of successfully received ECM frames, to assess progress as a basis for
-        deciding whether to continue error correction when PPRs keep repeating. */
-    int ecm_progress;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-};
-
 typedef struct
 {
     /*! \brief The current bit rate for image transfer. */
@@ -730,22 +519,24 @@
     int pages_transferred;
     /*! \brief The number of pages in the file (<0 if not known). */
     int pages_in_file;
+    /*! \brief The horizontal column-to-column resolution of the page, in pixels per metre */
+    int x_resolution;
+    /*! \brief The vertical row-to-row resolution of the page, in pixels per metre */
+    int y_resolution;
     /*! \brief The number of horizontal pixels in the most recent page. */
     int width;
     /*! \brief The number of vertical pixels in the most recent page. */
     int length;
+    /*! \brief The size of the image, in bytes */
+    int image_size;
+    /*! \brief The type of compression used between the FAX machines */
+    int encoding;
     /*! \brief The number of bad pixel rows in the most recent page. */
     int bad_rows;
     /*! \brief The largest number of bad pixel rows in a block in the most recent page. */
     int longest_bad_row_run;
-    /*! \brief The horizontal column-to-column resolution of the page in pixels per metre */
-    int x_resolution;
-    /*! \brief The vertical row-to-row resolution of the page in pixels per metre */
-    int y_resolution;
-    /*! \brief The type of compression used between the FAX machines */
-    int encoding;
-    /*! \brief The size of the image, in bytes */
-    int image_size;
+    /*! \brief The number of HDLC frame retries, if error correcting mode is used. */
+    int error_correcting_mode_retries;
     /*! \brief Current status */
     int current_status;
 } t30_stats_t;
@@ -794,6 +585,13 @@
     \return 0 for OK, else -1. */
 int t30_restart(t30_state_t *s);
 
+/*! Check if a T.30 call is still active. This may be used to regularly poll
+    if the job has finished.
+    \brief Check if a T.30 call is still active.
+    \param s The T.30 context.
+    \return TRUE for call still active, or FALSE for call completed. */
+int t30_call_active(t30_state_t *s);
+
 /*! Cleanup a T.30 context if the call terminates.
     \brief Cleanup a T.30 context if the call terminates.
     \param s The T.30 context. */

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t30_api.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t30_api.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t30_api.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t30_api.h,v 1.6 2008/08/14 14:06:05 steveu Exp $
+ * $Id: t30_api.h,v 1.7 2008/10/13 13:14:00 steveu Exp $
  */
 
 /*! \file */
@@ -552,6 +552,13 @@
     \param user_data An opaque pointer passed to the callback function. */
 void t30_set_real_time_frame_handler(t30_state_t *s, t30_real_time_frame_handler_t *handler, void *user_data);
 
+/*! Get a pointer to the logging context associated with a T.30 context.
+    \brief Get a pointer to the logging context associated with a T.30 context.
+    \param s The T.30 context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *t30_get_logging_state(t30_state_t *s);
+
 #if defined(__cplusplus)
 }
 #endif

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t31.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t31.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t31.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t31.h,v 1.52 2008/07/31 12:55:30 steveu Exp $
+ * $Id: t31.h,v 1.55 2009/01/09 16:09:06 steveu Exp $
  */
 
 /*! \file */
@@ -38,6 +38,10 @@
 \section t31_page_sec_2 How does it work?
 */
 
+/*!
+    T.31 descriptor. This defines the working state for a single instance of
+    a T.31 FAX modem.
+*/
 typedef struct t31_state_s t31_state_t;
 
 typedef int (t31_modem_control_handler_t)(t31_state_t *s, void *user_data, int op, const char *num);
@@ -48,150 +52,6 @@
 #define T31_MAX_HDLC_LEN        284
 #define T31_T38_MAX_HDLC_LEN    260
 
-/*!
-    Analogue FAX front end channel descriptor. This defines the state of a single working
-    instance of an analogue line FAX front end.
-*/
-typedef struct
-{
-    fax_modems_state_t modems;
-
-    /*! The transmit signal handler to be used when the current one has finished sending. */
-    span_tx_handler_t *next_tx_handler;
-    void *next_tx_user_data;
-
-    /*! \brief No of data bits in current_byte. */
-    int bit_no;
-    /*! \brief The current data byte in progress. */
-    int current_byte;
-
-    /*! \brief Rx power meter, used to detect silence. */
-    power_meter_t rx_power;
-    /*! \brief Last sample, used for an elementary HPF for the power meter. */
-    int16_t last_sample;
-    /*! \brief The current silence threshold. */
-    int32_t silence_threshold_power;
-
-    /*! \brief Samples of silence heard */
-    int silence_heard;
-} t31_audio_front_end_state_t;
-
-/*!
-    Analogue FAX front end channel descriptor. This defines the state of a single working
-    instance of an analogue line FAX front end.
-*/
-typedef struct
-{
-    t38_core_state_t t38;
-
-    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
-               rate and the current specified packet interval. */
-    int octets_per_data_packet;
-
-    int timed_step;
-
-    int ms_per_tx_chunk;
-    int merge_tx_fields;
-
-    /*! \brief TRUE is there has been some T.38 data missed */
-    int missing_data;
-
-    /*! \brief The number of times an indicator packet will be sent. Numbers greater than one
-               will increase reliability for UDP transmission. Zero is valid, to suppress all
-               indicator packets for TCP transmission. */
-    int indicator_tx_count;
-
-    /*! \brief The number of times a data packet which ends transmission will be sent. Numbers
-               greater than one will increase reliability for UDP transmission. Zero is not valid. */
-    int data_end_tx_count;
-
-    /*! \brief The current T.38 data type being transmitted */
-    int current_tx_data_type;
-    /*! \brief The next queued tramsit indicator */
-    int next_tx_indicator;
-
-    int trailer_bytes;
-
-    struct
-    {
-        uint8_t buf[T31_T38_MAX_HDLC_LEN];
-        int len;
-    } hdlc_rx;
-
-    int current_rx_type;
-    int current_tx_type;
-
-    int32_t next_tx_samples;
-    int32_t timeout_rx_samples;
-    /*! \brief A "sample" count, used to time events */
-    int32_t samples;
-} t31_t38_front_end_state_t;
-
-/*!
-    T.31 descriptor. This defines the working state for a single instance of
-    a T.31 FAX modem.
-*/
-struct t31_state_s
-{
-    at_state_t at_state;
-    t31_modem_control_handler_t *modem_control_handler;
-    void *modem_control_user_data;
-
-    t31_audio_front_end_state_t audio;
-    t31_t38_front_end_state_t t38_fe;
-    /*! TRUE if working in T.38 mode. */
-    int t38_mode;
-
-    /*! HDLC buffer, for composing an HDLC frame from the computer to the channel. */
-    struct
-    {
-        uint8_t buf[T31_MAX_HDLC_LEN];
-        int len;
-        int ptr;
-        /*! \brief TRUE when the end of HDLC data from the computer has been detected. */
-        int final;
-    } hdlc_tx;
-    /*! Buffer for data from the computer to the channel. */
-    struct
-    {
-        uint8_t data[T31_TX_BUF_LEN];
-        /*! \brief The number of bytes stored in transmit buffer. */
-        int in_bytes;
-        /*! \brief The number of bytes sent from the transmit buffer. */
-        int out_bytes;
-        /*! \brief TRUE if the flow of real data has started. */
-        int data_started;
-        /*! \brief TRUE if holding up further data into the buffer, for flow control. */
-        int holding;
-        /*! \brief TRUE when the end of non-ECM data from the computer has been detected. */
-        int final;
-    } tx;
-
-    /*! TRUE if DLE prefix just used */
-    int dled;
-
-	/*! \brief Samples of silence awaited, as specified in a "wait for silence" command */
-    int silence_awaited;
-
-    /*! \brief The current bit rate for the FAX fast message transfer modem. */
-    int bit_rate;
-    /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */
-    int rx_frame_received;
-
-    /*! \brief Samples elapsed in the current call */
-    int64_t call_samples;
-    int64_t dte_data_timeout;
-
-    /*! \brief The currently queued modem type. */
-    int modem;
-    /*! \brief TRUE when short training mode has been selected by the computer. */
-    int short_train;
-    queue_state_t *rx_queue;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-};
-
 #if defined(__cplusplus)
 extern "C"
 {
@@ -244,6 +104,17 @@
 */
 void t31_set_t38_config(t31_state_t *s, int without_pacing);
 
+void t31_set_mode(t31_state_t *s, int t38_mode);
+
+/*! Get a pointer to the logging context associated with a T.31 context.
+    \brief Get a pointer to the logging context associated with a T.31 context.
+    \param s The T.31 context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *t31_get_logging_state(t31_state_t *s);
+
+t38_core_state_t *t31_get_t38_core_state(t31_state_t *s);
+
 /*! Initialise a T.31 context. This must be called before the first
     use of the context, to initialise its contents.
     \brief Initialise a T.31 context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t38_core.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t38_core.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t38_core.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_core.h,v 1.29 2008/09/04 14:40:05 steveu Exp $
+ * $Id: t38_core.h,v 1.33 2009/01/23 16:07:14 steveu Exp $
  */
 
 /*! \file */
@@ -160,6 +160,13 @@
     T38_TRANSPORT_TCP
 };
 
+/*! T.38 TCF management types */
+enum t38_data_rate_management_types_e
+{
+    T38_DATA_RATE_MANAGEMENT_LOCAL_TCF = 1,
+    T38_DATA_RATE_MANAGEMENT_TRANSFERRED_TCF = 2
+};
+
 #define T38_RX_BUF_LEN  2048
 #define T38_TX_BUF_LEN  16384
 
@@ -171,6 +178,9 @@
     int field_len;
 } t38_data_field_t;
 
+/*!
+    Core T.38 state, common to all modes of T.38.
+*/
 typedef struct t38_core_state_s t38_core_state_t;
 
 typedef int (t38_tx_packet_handler_t)(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count);
@@ -179,113 +189,6 @@
 typedef int (t38_rx_data_handler_t)(t38_core_state_t *s, void *user_data, int data_type, int field_type, const uint8_t *buf, int len);
 typedef int (t38_rx_missing_handler_t)(t38_core_state_t *s, void *user_data, int rx_seq_no, int expected_seq_no);
 
-/*!
-    Core T.38 state, common to all modes of T.38.
-*/
-struct t38_core_state_s
-{
-    /*! Handler routine to transmit IFP packets generated by the T.38 protocol engine */
-    t38_tx_packet_handler_t *tx_packet_handler;
-    /*! An opaque pointer passed to tx_packet_handler */
-    void *tx_packet_user_data;
-
-    /*! Handler routine to process received indicator packets */
-    t38_rx_indicator_handler_t *rx_indicator_handler;
-    /*! Handler routine to process received data packets */
-    t38_rx_data_handler_t *rx_data_handler;
-    /*! Handler routine to process the missing packet condition */
-    t38_rx_missing_handler_t *rx_missing_handler;
-    /*! An opaque pointer passed to any of the above receive handling routines */
-    void *rx_user_data;
-
-    /*! NOTE - Bandwidth reduction shall only be done on suitable Phase C data, i.e., MH, MR
-        and - in the case of transcoding to JBIG - MMR. MMR and JBIG require reliable data
-        transport such as that provided by TCP. When transcoding is selected, it shall be
-        applied to every suitable page in a call. */
-
-    /*! Method 1: Local generation of TCF (required for use with TCP).
-        Method 2: Transfer of TCF is required for use with UDP (UDPTL or RTP).
-        Method 2 is not recommended for use with TCP. */
-    int data_rate_management_method;
-    
-    /*! The emitting gateway may indicate a preference for either UDP/UDPTL, or
-        UDP/RTP, or TCP for transport of T.38 IFP Packets. The receiving device
-        selects the transport protocol. */
-    int data_transport_protocol;
-
-    /*! Indicates the capability to remove and insert fill bits in Phase C, non-ECM
-        data to reduce bandwidth in the packet network. */
-    int fill_bit_removal;
-
-    /*! Indicates the ability to convert to/from MMR from/to the line format to
-        improve the compression of the data, and reduce the bandwidth, in the
-        packet network. */
-    int mmr_transcoding;
-
-    /*! Indicates the ability to convert to/from JBIG to reduce bandwidth. */
-    int jbig_transcoding;
-
-    /*! For UDP (UDPTL or RTP) modes, this option indicates the maximum
-        number of octets that can be stored on the remote device before an overflow
-        condition occurs. It is the responsibility of the transmitting application to
-        limit the transfer rate to prevent an overflow. The negotiated data rate
-        should be used to determine the rate at which data is being removed from
-        the buffer. */
-    int max_buffer_size;
-
-    /*! This option indicates the maximum size of a UDPTL packet or the
-        maximum size of the payload within an RTP packet that can be accepted by
-        the remote device. */
-    int max_datagram_size;
-
-    /*! This is the version number of ITU-T Rec. T.38. New versions shall be
-        compatible with previous versions. */
-    int t38_version;
-
-    /*! The fastest data rate supported by the T.38 channel. */
-    int fastest_image_data_rate;
-
-    /*! \brief The number of times an indicator packet will be sent. Numbers greater than one
-               will increase reliability for UDP transmission. Zero is valid, to suppress all
-               indicator packets for TCP transmission. */
-    int indicator_tx_count;
-
-    /*! \brief The number of times a data packet which does not end transmission will be sent.
-               Numbers greater than one will increase reliability for UDP transmission. Zero
-               is not valid. */
-    int data_tx_count;
-
-    /*! \brief The number of times a data packet which ends transmission will be sent. Numbers
-               greater than one will increase reliability for UDP transmission. Zero is not valid. */
-    int data_end_tx_count;
-
-    /*! TRUE if IFP packet sequence numbers are relevant. For some transports, like TPKT
-        over TCP they are not relevent. */
-    int check_sequence_numbers;
-
-    /*! The sequence number for the next packet to be transmitted */
-    int tx_seq_no;
-    /*! The sequence number expected in the next received packet */
-    int rx_expected_seq_no;
-
-    /*! The current receive indicator - i.e. the last indicator received */
-    int current_rx_indicator;
-    /*! The current receive data type - i.e. the last data type received */
-    int current_rx_data_type;
-    /*! The current receive field type - i.e. the last field_type received */
-    int current_rx_field_type;
-    /*! The current transmit indicator - i.e. the last indicator transmitted */
-    int current_tx_indicator;
-    /*! The bit rate for V.34 operation */
-    int v34_rate;
-
-    /*! A count of missing receive packets. This count might not be accurate if the
-        received packet numbers jump wildly. */
-    int missing_packets;
-
-    logging_state_t logging;
-};
-
 #if defined(__cplusplus)
 extern "C"
 {
@@ -327,9 +230,15 @@
     \param s The T.38 context.
     \param indicator The indicator to send.
     \param count The number of copies of the packet to send.
-    \return ??? */
+    \return The delay to allow after this indicator is sent. */
 int t38_core_send_indicator(t38_core_state_t *s, int indicator, int count);
 
+/*! \brief Find the delay to allow for HDLC flags after sending an indicator
+    \param s The T.38 context.
+    \param indicator The indicator to send.
+    \return The delay to allow for initial HDLC flags after this indicator is sent. */
+int t38_core_send_flags_delay(t38_core_state_t *s, int indicator);
+
 /*! \brief Send a data packet
     \param s The T.38 context.
     \param data_type The packet's data type.
@@ -399,13 +308,26 @@
 */
 void t38_set_t38_version(t38_core_state_t *s, int t38_version);
 
-/* Set the sequence number handling option.
+/*! Set the sequence number handling option.
     \param s The T.38 context.
     \param check TRUE to check sequence numbers, and handle gaps reasonably. FALSE
            for no sequence number processing (e.g. for TPKT over TCP transport).
 */
 void t38_set_sequence_number_handling(t38_core_state_t *s, int check);
 
+/*! Set the TEP handling option.
+    \param s The T.38 context.
+    \param allow_for_tep TRUE to allow for TEP playout, else FALSE.
+*/
+void t38_set_tep_handling(t38_core_state_t *s, int allow_for_tep);
+
+/*! Get a pointer to the logging context associated with a T.38 context.
+    \brief Get a pointer to the logging context associated with a T.38 context.
+    \param s The T.38 context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *t38_core_get_logging_state(t38_core_state_t *s);
+
 t38_core_state_t *t38_core_init(t38_core_state_t *s,
                                 t38_rx_indicator_handler_t *rx_indicator_handler,
                                 t38_rx_data_handler_t *rx_data_handler,

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t38_gateway.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t38_gateway.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t38_gateway.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_gateway.h,v 1.57 2008/09/02 13:56:10 steveu Exp $
+ * $Id: t38_gateway.h,v 1.59 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -62,167 +62,6 @@
                                                      const uint8_t *msg,
                                                      int len);
 
-/*!
-    T.38 gateway T.38 side channel descriptor.
-*/
-typedef struct
-{
-    /*! Core T.38 IFP support */
-    t38_core_state_t t38;
-
-    /*! \brief TRUE if the NSF, NSC, and NSS are to be suppressed by altering
-               their contents to something the far end will not recognise. */
-    int suppress_nsx_len[2];
-    /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
-               interpret it. The two values are for the two directions. */
-    int corrupt_current_frame[2];
-
-    /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */
-    int current_rx_field_class;
-    /*! \brief The T.38 indicator currently in use */
-    int in_progress_rx_indicator;
-
-    /*! \brief The current T.38 data type being sent. */
-    int current_tx_data_type;
-} t38_gateway_t38_state_t;
-
-/*!
-    T.38 gateway audio side channel descriptor.
-*/
-typedef struct
-{
-    fax_modems_state_t modems;
-    /*! \brief The current receive signal handler. Actual receiving hop between this
-               and a dummy receive routine. */
-    span_rx_handler_t *base_rx_handler;
-} t38_gateway_audio_state_t;
-
-typedef struct
-{
-    /*! \brief non-ECM and HDLC modem receive data buffer. */
-    uint8_t data[T38_RX_BUF_LEN];
-    /*! \brief Current pointer into the data buffer. */
-    int data_ptr;
-    /*! \brief The current octet being received as non-ECM data. */
-    unsigned int bit_stream;
-    /*! \brief The number of bits taken from the modem for the current scan row. This
-               is used during non-ECM transmission will fill bit removal to see that
-               T.38 packet transmissions do not stretch too far apart. */
-    int bits_absorbed;
-    /*! \brief The current bit number in the current non-ECM octet. */
-    int bit_no;
-    /*! \brief Progressively calculated CRC for HDLC messages received from a modem. */
-    uint16_t crc;
-    /*! \brief TRUE if non-ECM fill bits are to be stripped when sending image data. */
-    int fill_bit_removal;
-    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
-               rate and the current specified packet interval. */
-    int octets_per_data_packet;
-
-    int in_bits;
-    int out_octets;
-} t38_gateway_to_t38_state_t;
-
-typedef struct
-{
-    /*! \brief HDLC message buffers. */
-    uint8_t buf[T38_MAX_HDLC_LEN];
-    /*! \brief HDLC message lengths. */
-    int len;
-    /*! \brief HDLC message status flags. */
-    int flags;
-    /*! \brief HDLC buffer contents. */
-    int contents;
-} t38_gateway_hdlc_buf_t;
-
-typedef struct
-{
-    /*! \brief HDLC message buffers. */
-    t38_gateway_hdlc_buf_t buf[T38_TX_HDLC_BUFS];
-#if 0
-    /*! \brief HDLC message buffers. */
-    uint8_t buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN];
-    /*! \brief HDLC message lengths. */
-    int len[T38_TX_HDLC_BUFS];
-    /*! \brief HDLC message status flags. */
-    int flags[T38_TX_HDLC_BUFS];
-    /*! \brief HDLC buffer contents. */
-    int contents[T38_TX_HDLC_BUFS];
-#endif
-    /*! \brief HDLC buffer number for input. */
-    int in;
-    /*! \brief HDLC buffer number for output. */
-    int out;
-} t38_gateway_hdlc_state_t;
-
-/*!
-    T.38 gateway core descriptor.
-*/
-typedef struct
-{
-    /*! \brief A bit mask of the currently supported modem types. */
-    int supported_modems;
-    /*! \brief TRUE if ECM FAX mode is allowed through the gateway. */
-    int ecm_allowed;
-
-    /*! \brief TRUE if in image data modem is to use short training. This usually
-               follows image_data_mode, but in ECM mode T.30 defines recovery
-               conditions in which long training is used for image data. */
-    int short_train;
-    /*! \brief TRUE if in image data mode, as opposed to TCF mode. */
-    int image_data_mode;
-    /*! \brief The minimum permitted bits per FAX scan line row. */
-    int min_row_bits;
-
-    /*! \brief TRUE if we should count the next MCF as a page end, else FALSE */
-    int count_page_on_mcf;
-    /*! \brief The number of pages for which a confirm (MCF) message was returned. */
-    int pages_confirmed;
-
-    /*! \brief TRUE if we are in error correcting (ECM) mode */
-    int ecm_mode;
-    /*! \brief The current bit rate for the fast modem. */
-    int fast_bit_rate;
-    /*! \brief The current fast modem type. */
-    int fast_modem;
-    /*! \brief The type of fast receive modem currently active, which may be T38_NONE */
-    int fast_rx_active;
-
-    /*! \brief TRUE if between DCS and TCF, and we want the fast image modem to
-               start in the T.38 data at a predictable time from the end of the
-               V.21 signal. */
-    int tcf_mode_predictable_modem_start;
-
-    /*! \brief The number of samples until the next timeout event */
-    int samples_to_timeout;
-
-    /*! Buffer for HDLC and non-ECM data going to the T.38 channel */
-    t38_gateway_to_t38_state_t to_t38;
-    /*! Buffer for data going to an HDLC modem. */
-    t38_gateway_hdlc_state_t hdlc_to_modem;
-    /*! Buffer for data going to a non-ECM mode modem. */
-    t38_non_ecm_buffer_state_t non_ecm_to_modem;
-
-    /*! \brief A pointer to a callback routine to be called when frames are
-        exchanged. */
-    t38_gateway_real_time_frame_handler_t *real_time_frame_handler;
-    /*! \brief An opaque pointer supplied in real time frame callbacks. */
-    void *real_time_frame_user_data;
-} t38_gateway_core_state_t;
-
-/*!
-    T.38 gateway state.
-*/
-struct t38_gateway_state_s
-{
-    t38_gateway_t38_state_t t38x;
-    t38_gateway_audio_state_t audio;
-    t38_gateway_core_state_t core;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-};
-
 typedef struct
 {
     /*! \brief The current bit rate for image transfer. */
@@ -331,6 +170,22 @@
     \param t A pointer to a buffer for the statistics. */
 void t38_gateway_get_transfer_statistics(t38_gateway_state_t *s, t38_stats_t *t);
 
+/*! Get a pointer to the T.38 core IFP packet engine associated with a
+    gateway mode T.38 context.
+    \brief Get a pointer to the T.38 core IFP packet engine associated
+           with a T.38 context.
+    \param s The T.38 context.
+    \return A pointer to the T.38 core context, or NULL.
+*/
+t38_core_state_t *t38_gateway_get_t38_core_state(t38_gateway_state_t *s);
+
+/*! Get a pointer to the logging context associated with a T.38 context.
+    \brief Get a pointer to the logging context associated with a T.38 context.
+    \param s The T.38 context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *t38_gateway_get_logging_state(t38_gateway_state_t *s);
+
 /*! Set a callback function for T.30 frame exchange monitoring. This is called from the heart
     of the signal processing, so don't take too long in the handler routine.
     \brief Set a callback function for T.30 frame exchange monitoring.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t38_non_ecm_buffer.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t38_non_ecm_buffer.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t38_non_ecm_buffer.h	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_non_ecm_buffer.h,v 1.2 2008/09/02 13:56:10 steveu Exp $
+ * $Id: t38_non_ecm_buffer.h,v 1.3 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -47,55 +47,7 @@
 /*! \brief A flow controlled non-ECM image data buffer, for buffering T.38 to analogue
            modem data.
 */
-typedef struct
-{
-    /*! \brief Minimum number of bits per row, used when fill bits are being deleted on the
-               link, and restored at the emitting gateway. */
-    int min_row_bits;
-
-    /*! \brief non-ECM modem transmit data buffer. */
-    uint8_t data[T38_NON_ECM_TX_BUF_LEN];
-    /*! \brief The current write point in the buffer. */
-    int in_ptr;
-    /*! \brief The current read point in the buffer. */
-    int out_ptr;
-    /*! \brief The location of the most recent EOL marker in the buffer. */
-    int latest_eol_ptr;
-    /*! \brief The number of bits to date in the current row, used when min_row_bits is
-               to be applied. */
-    int row_bits;
-
-    /*! \brief The bit stream entering the buffer, used to detect EOLs */
-    unsigned int bit_stream;
-    /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00
-               once data has started). */
-    uint8_t flow_control_fill_octet;
-    /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */
-    int at_initial_all_ones;
-    /*! \brief TRUE is the end of non-ECM data indication has been received. */
-    int data_finished;
-    /*! \brief The current octet being transmitted from the buffer. */
-    unsigned int octet;
-    /*! \brief The current bit number in the current non-ECM octet. */
-    int bit_no;
-    /*! \brief TRUE if in image data mode, as opposed to TCF mode. */
-    int image_data_mode;
-
-    /*! \brief The number of octets input to the buffer. */
-    int in_octets;
-    /*! \brief The number of rows input to the buffer. */
-    int in_rows;
-    /*! \brief The number of non-ECM fill octets generated for minimum row bits
-               purposes. */
-    int min_row_bits_fill_octets;
-    /*! \brief The number of octets output from the buffer. */
-    int out_octets;
-    /*! \brief The number of rows output from the buffer. */
-    int out_rows;
-    /*! \brief The number of non-ECM fill octets generated for flow control
-               purposes. */
-    int flow_control_fill_octets;
-} t38_non_ecm_buffer_state_t;
+typedef struct t38_non_ecm_buffer_state_s t38_non_ecm_buffer_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t38_terminal.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t38_terminal.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t38_terminal.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_terminal.h,v 1.37 2008/08/14 14:06:05 steveu Exp $
+ * $Id: t38_terminal.h,v 1.39 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -39,91 +39,7 @@
 /* Make sure the HDLC frame buffers are big enough for ECM frames. */
 #define T38_MAX_HDLC_LEN        260
 
-typedef struct
-{
-    /*! \brief Internet Aware FAX mode bit mask. */
-    int iaf;
-    /*! \brief Required time between T.38 transmissions, in ms. */
-    int ms_per_tx_chunk;
-    /*! \brief Bit fields controlling the way data is packed into chunked for transmission. */
-    int chunking_modes;
-
-    /*! \brief Core T.38 IFP support */
-    t38_core_state_t t38;
-
-    /*! \brief The current transmit step being timed */
-    int timed_step;
-
-    /*! \brief TRUE is there has been some T.38 data missed (i.e. lost packets) in the current
-               reception period. */
-    int rx_data_missing;
-
-    /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
-               rate and the current specified packet interval. */
-    int octets_per_data_packet;
-
-    struct
-    {
-        /*! \brief HDLC receive buffer */
-        uint8_t buf[T38_MAX_HDLC_LEN];
-        /*! \brief The length of the contents of the HDLC receive buffer */
-        int len;
-    } hdlc_rx;
-
-    struct
-    {
-        /*! \brief HDLC transmit buffer */
-        uint8_t buf[T38_MAX_HDLC_LEN];
-        /*! \brief The length of the contents of the HDLC transmit buffer */
-        int len;
-        /*! \brief Current pointer within the contents of the HDLC transmit buffer */
-        int ptr;
-        /*! \brief The number of extra bits in a fully stuffed version of the
-                   contents of the HDLC transmit buffer. This is needed to accurately
-                   estimate the playout time for this frame, through an analogue modem. */
-        int extra_bits;
-    } tx;
-
-    /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */
-    int non_ecm_trailer_bytes;
-
-    /*! \brief The next T.38 indicator queued for transmission. */
-    int next_tx_indicator;
-    /*! \brief The current T.38 data type being transmitted. */
-    int current_tx_data_type;
-
-    /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
-    int rx_signal_present;
-
-    /*! \brief The current operating mode of the receiver. */
-    int current_rx_type;
-    /*! \brief The current operating mode of the transmitter. */
-    int current_tx_type;
-
-    /*! \brief Current transmission bit rate. */
-    int tx_bit_rate;
-    /*! \brief A "sample" count, used to time events. */
-    int32_t samples;
-    /*! \brief The value for samples at the next transmission point. */
-    int32_t next_tx_samples;
-    /*! \brief The current receive timeout. */
-    int32_t timeout_rx_samples;
-} t38_terminal_front_end_state_t;
-
-/*!
-    T.38 terminal state.
-*/
-typedef struct
-{
-    /*! \brief The T.30 back-end */
-    t30_state_t t30;
-
-    /*! \brief The T.38 front-end */
-    t38_terminal_front_end_state_t t38_fe;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} t38_terminal_state_t;
+typedef struct t38_terminal_state_s t38_terminal_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -155,6 +71,22 @@
 */
 t30_state_t *t38_terminal_get_t30_state(t38_terminal_state_t *s);
 
+/*! Get a pointer to the T.38 core IFP packet engine associated with a
+    termination mode T.38 context.
+    \brief Get a pointer to the T.38 core IFP packet engine associated
+           with a T.38 context.
+    \param s The T.38 context.
+    \return A pointer to the T.38 core context, or NULL.
+*/
+t38_core_state_t *t38_terminal_get_t38_core_state(t38_terminal_state_t *s);
+
+/*! Get a pointer to the logging context associated with a T.38 context.
+    \brief Get a pointer to the logging context associated with a T.38 context.
+    \param s The T.38 context.
+    \return A pointer to the logging context, or NULL.
+*/
+logging_state_t *t38_terminal_get_logging_state(t38_terminal_state_t *s);
+
 /*! \brief Initialise a termination mode T.38 context.
     \param s The T.38 context.
     \param calling_party TRUE if the context is for a calling party. FALSE if the

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/t4.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/t4.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/t4.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t4.h,v 1.52 2008/07/22 13:48:15 steveu Exp $
+ * $Id: t4.h,v 1.53 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -175,170 +175,7 @@
     T.4 FAX compression/decompression descriptor. This defines the working state
     for a single instance of a T.4 FAX compression or decompression channel.
 */
-typedef struct
-{
-    /*! \brief The same structure is used for T.4 transmit and receive. This variable
-               records which mode is in progress. */
-    int rx;
-    /* "Background" information about the FAX, which can be stored in a TIFF file. */
-    /*! \brief The vendor of the machine which produced the TIFF file. */ 
-    const char *vendor;
-    /*! \brief The model of machine which produced the TIFF file. */ 
-    const char *model;
-    /*! \brief The local ident string. */ 
-    const char *local_ident;
-    /*! \brief The remote end's ident string. */ 
-    const char *far_ident;
-    /*! \brief The FAX sub-address. */ 
-    const char *sub_address;
-    /*! \brief The FAX DCS information, as an ASCII string. */ 
-    const char *dcs;
-    /*! \brief The text which will be used in FAX page header. No text results
-               in no header line. */
-    const char *header_info;
-
-    /*! \brief The type of compression used between the FAX machines. */
-    int line_encoding;
-    /*! \brief The minimum number of encoded bits per row. This is a timing thing
-               for hardware FAX machines. */
-    int min_bits_per_row;
-    
-    /*! \brief The compression type for output to the TIFF file. */
-    int output_compression;
-    /*! \brief The TIFF G3 FAX options. */
-    int output_t4_options;
-
-    /*! \brief Callback function to read a row of pixels from the image source. */
-    t4_row_read_handler_t row_read_handler;
-    /*! \brief Opaque pointer passed to row_read_handler. */
-    void *row_read_user_data;
-    /*! \brief Callback function to write a row of pixels to the image destination. */
-    t4_row_write_handler_t row_write_handler;
-    /*! \brief Opaque pointer passed to row_write_handler. */
-    void *row_write_user_data;
-
-    /*! \brief The time at which handling of the current page began. */
-    time_t page_start_time;
-
-    /*! \brief The current number of bytes per row of uncompressed image data. */
-    int bytes_per_row;
-    /*! \brief The size of the image in the image buffer, in bytes. */
-    int image_size;
-    /*! \brief The size of the compressed image on the line side, in bits. */
-    int line_image_size;
-    /*! \brief The current size of the image buffer. */
-    int image_buffer_size;
-    /*! \brief A point to the image buffer. */
-    uint8_t *image_buffer;
-
-    /*! \brief The libtiff context for the current TIFF file */
-    TIFF *tiff_file;
-    /*! \brief The current file name. */
-    const char *file;
-    /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
-    int start_page;
-    /*! \brief The last page to transfer. -1 to continue to the end of the file. */
-    int stop_page;
-
-    /*! \brief The number of pages transferred to date. */
-    int pages_transferred;
-    /*! \brief The number of pages in the current TIFF file. */
-    int pages_in_file;
-    /*! \brief Column-to-column (X) resolution in pixels per metre. */
-    int x_resolution;
-    /*! \brief Row-to-row (Y) resolution in pixels per metre. */
-    int y_resolution;
-    /*! \brief Width of the current page, in pixels. */
-    int image_width;
-    /*! \brief Length of the current page, in pixels. */
-    int image_length;
-    /*! \brief Current pixel row number. */
-    int row;
-    /*! \brief The current number of consecutive bad rows. */
-    int curr_bad_row_run;
-    /*! \brief The longest run of consecutive bad rows seen in the current page. */
-    int longest_bad_row_run;
-    /*! \brief The total number of bad rows in the current page. */
-    int bad_rows;
-
-    /*! \brief Incoming bit buffer for decompression. */
-    uint32_t rx_bitstream;
-    /*! \brief The number of bits currently in rx_bitstream. */
-    int rx_bits;
-    /*! \brief The number of bits to be skipped before trying to match the next code word. */
-    int rx_skip_bits;
-
-    /*! \brief This variable is set if we are treating the current row as a 2D encoded
-               one. */
-    int row_is_2d;
-    /*! \brief TRUE if the current run is black */
-    int its_black;
-    /*! \brief The current length of the current row. */
-    int row_len;
-    /*! \brief This variable is used to count the consecutive EOLS we have seen. If it
-               reaches six, this is the end of the image. It is initially set to -1 for
-               1D and 2D decoding, as an indicator that we must wait for the first EOL,
-               before decodin any image data. */
-    int consecutive_eols;
-
-    /*! \brief Black and white run-lengths for the current row. */
-    uint32_t *cur_runs;
-    /*! \brief Black and white run-lengths for the reference row. */
-    uint32_t *ref_runs;
-    /*! \brief The number of runs currently in the reference row. */
-    int ref_steps;
-    /*! \brief The current step into the reference row run-lengths buffer. */
-    int b_cursor;
-    /*! \brief The current step into the current row run-lengths buffer. */
-    int a_cursor;
-
-    /*! \brief The reference or starting changing element on the coding line. At the
-               start of the coding line, a0 is set on an imaginary white changing element
-               situated just before the first element on the line. During the coding of
-               the coding line, the position of a0 is defined by the previous coding mode.
-               (See 4.2.1.3.2.). */
-    int a0;
-    /*! \brief The first changing element on the reference line to the right of a0 and of
-               opposite colour to a0. */
-    int b1;
-    /*! \brief The length of the in-progress run of black or white. */
-    int run_length;
-    /*! \brief 2D horizontal mode control. */
-    int black_white;
-
-    /*! \brief Encoded data bits buffer. */
-    uint32_t tx_bitstream;
-    /*! \brief The number of bits currently in tx_bitstream. */
-    int tx_bits;
-
-    /*! \brief A pointer into the image buffer indicating where the last row begins */
-    int last_row_starts_at;
-    /*! \brief A pointer into the image buffer indicating where the current row begins */
-    int row_starts_at;
-    
-    /*! \brief Pointer to the buffer for the current pixel row. */
-    uint8_t *row_buf;
-    
-    /*! \brief Pointer to the byte containing the next image bit to transmit. */
-    int bit_pos;
-    /*! \brief Pointer to the bit within the byte containing the next image bit to transmit. */
-    int bit_ptr;
-
-    /*! \brief The current maximum contiguous rows that may be 2D encoded. */
-    int max_rows_to_next_1d_row;
-    /*! \brief Number of rows left that can be 2D encoded, before a 1D encoded row
-               must be used. */
-    int rows_to_next_1d_row;
-    /*! \brief The current number of bits in the current encoded row. */
-    int row_bits;
-    /*! \brief The minimum bits in any row of the current page. For monitoring only. */
-    int min_row_bits;
-    /*! \brief The maximum bits in any row of the current page. For monitoring only. */
-    int max_row_bits;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} t4_state_t;
+typedef struct t4_state_s t4_state_t;
 
 /*!
     T.4 FAX compression/decompression statistics.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/telephony.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/telephony.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/telephony.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: telephony.h,v 1.12 2008/04/17 14:27:01 steveu Exp $
+ * $Id: telephony.h,v 1.13 2009/01/19 17:14:10 steveu Exp $
  */
 
 #if !defined(_SPANDSP_TELEPHONY_H_)
@@ -47,6 +47,7 @@
 typedef int (span_tx_handler_t)(void *s, int16_t amp[], int max_len);
 
 #define ms_to_samples(t)    (((t)*SAMPLE_RATE)/1000)
+#define us_to_samples(t)    (((t)*SAMPLE_RATE)/1000000)
 
 #if !defined(FALSE)
 #define FALSE 0

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/time_scale.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/time_scale.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/time_scale.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: time_scale.h,v 1.16 2008/07/28 15:14:30 steveu Exp $
+ * $Id: time_scale.h,v 1.17 2008/11/15 14:27:29 steveu Exp $
  */
 
 #if !defined(_SPANDSP_TIME_SCALE_H_)
@@ -56,25 +56,8 @@
     input_len*playout_rate + sample_rate/TIME_SCALE_MIN_PITCH + 1
 */
 
-#define TIME_SCALE_MAX_SAMPLE_RATE  48000
-#define TIME_SCALE_MIN_PITCH        60
-#define TIME_SCALE_MAX_PITCH        250
-#define TIME_SCALE_BUF_LEN          (2*TIME_SCALE_MAX_SAMPLE_RATE/TIME_SCALE_MIN_PITCH)
-
 /*! Audio time scaling descriptor. */
-typedef struct
-{
-    int sample_rate;
-    int min_pitch;
-    int max_pitch;
-    int buf_len;
-    float playout_rate;
-    double rcomp;
-    double rate_nudge;
-    int fill;
-    int lcp;
-    int16_t buf[TIME_SCALE_BUF_LEN];
-} time_scale_state_t;
+typedef struct time_scale_state_s time_scale_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/tone_detect.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/tone_detect.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/tone_detect.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_detect.h,v 1.41 2008/06/13 14:46:52 steveu Exp $
+ * $Id: tone_detect.h,v 1.42 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if !defined(_SPANDSP_TONE_DETECT_H_)
@@ -31,7 +31,7 @@
 /*!
     Goertzel filter descriptor.
 */
-typedef struct
+struct goertzel_descriptor_s
 {
 #if defined(SPANDSP_USE_FIXED_POINT)
     int16_t fac;
@@ -39,12 +39,12 @@
     float fac;
 #endif
     int samples;
-} goertzel_descriptor_t;
+};
 
 /*!
     Goertzel filter state descriptor.
 */
-typedef struct
+struct goertzel_state_s
 {
 #if defined(SPANDSP_USE_FIXED_POINT)
     int16_t v2;
@@ -57,7 +57,17 @@
 #endif
     int samples;
     int current_sample;
-} goertzel_state_t;
+};
+
+/*!
+    Goertzel filter descriptor.
+*/
+typedef struct goertzel_descriptor_s goertzel_descriptor_t;
+
+/*!
+    Goertzel filter state descriptor.
+*/
+typedef struct goertzel_state_s goertzel_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/tone_generate.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/tone_generate.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/tone_generate.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_generate.h,v 1.34 2008/09/11 15:13:42 steveu Exp $
+ * $Id: tone_generate.h,v 1.35 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -45,41 +45,18 @@
 conditions in which we will use it. 
 */
 
-typedef struct
-{
-    int32_t phase_rate;
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int16_t gain;
-#else
-    float gain;
-#endif
-} tone_gen_tone_descriptor_t;
+typedef struct tone_gen_tone_descriptor_s tone_gen_tone_descriptor_t;
 
 /*!
-    Cadenced dual tone generator descriptor.
+    Cadenced multi-tone generator descriptor.
 */
-typedef struct
-{
-    tone_gen_tone_descriptor_t tone[4];
-    int duration[4];
-    int repeat;
-} tone_gen_descriptor_t;
+typedef struct tone_gen_descriptor_s tone_gen_descriptor_t;
 
 /*!
-    Cadenced dual tone generator state descriptor. This defines the state of
+    Cadenced multi-tone generator state descriptor. This defines the state of
     a single working instance of a generator.
 */
-typedef struct
-{
-    tone_gen_tone_descriptor_t tone[4];
-
-    uint32_t phase[4];
-    int duration[4];
-    int repeat;
-
-    int current_section;
-    int current_position;
-} tone_gen_state_t;
+typedef struct tone_gen_state_s tone_gen_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v17rx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v17rx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v17rx.h	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v17rx.h,v 1.57 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v17rx.h,v 1.58 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
 
-#if !defined(_V17RX_H_)
-#define _V17RX_H_
+#if !defined(_SPANDSP_V17RX_H_)
+#define _SPANDSP_V17RX_H_
 
 /*! \page v17rx_page The V.17 receiver
 \section v17rx_page_sec_1 What does it do?
@@ -229,179 +229,7 @@
     V.17 modem receive side descriptor. This defines the working state for a
     single instance of a V.17 modem receiver.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 7200 9600, 12000 and 14400. */
-    int bit_rate;
-    /*! \brief The callback function used to put each bit received. */
-    put_bit_func_t put_bit;
-    /*! \brief A user specified opaque pointer passed to the put_but routine. */
-    void *put_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_rx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    /*! \brief A callback function which may be enabled to report every symbol's
-               constellation position. */
-    qam_report_handler_t qam_report;
-    /*! \brief A user specified opaque pointer passed to the qam_report callback
-               routine. */
-    void *qam_user_data;
-
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int16_t rrc_filter[V17_RX_FILTER_STEPS];
-#else
-    float rrc_filter[V17_RX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-
-    /*! \brief The state of the differential decoder */
-    int diff;
-    /*! \brief The register for the data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief TRUE if the short training sequence is to be used. */
-    int short_train;
-    /*! \brief The section of the training data we are currently in. */
-    int training_stage;
-    /*! \brief A count of how far through the current training step we are. */
-    int training_count;
-    /*! \brief A measure of how much mismatch there is between the real constellation,
-        and the decoded symbol positions. */
-    float training_error;
-    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
-    int16_t last_sample;
-    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.17 signal. */
-    int signal_present;
-    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
-    int carrier_drop_pending;
-    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
-    int low_samples;
-    /*! \brief A highest magnitude sample seen. */
-    int16_t high_sample;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The carrier update rate saved for reuse when using short training. */
-    int32_t carrier_phase_rate_save;
-#if defined(SPANDSP_USE_FIXED_POINTx)
-    /*! \brief The proportional part of the carrier tracking filter. */
-    float carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    float carrier_track_i;
-#else
-    /*! \brief The proportional part of the carrier tracking filter. */
-    float carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    float carrier_track_i;
-#endif
-
-    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
-    power_meter_t power;
-    /*! \brief The power meter level at which carrier on is declared. */
-    int32_t carrier_on_power;
-    /*! \brief The power meter level at which carrier off is declared. */
-    int32_t carrier_off_power;
-
-    /*! \brief Current read offset into the equalizer buffer. */
-    int eq_step;
-    /*! \brief Current write offset into the equalizer buffer. */
-    int eq_put_step;
-    /*! \brief Symbol counter to the next equalizer update. */
-    int eq_skip;
-
-    /*! \brief The current half of the baud. */
-    int baud_half;
-
-#if defined(SPANDSP_USE_FIXED_POINTx)
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    float agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    float agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    float eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    complexi16_t eq_coeff[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    complexi16_t eq_coeff_save[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    complexi16_t eq_buf[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-
-    /*! Low band edge filter for symbol sync. */
-    int32_t symbol_sync_low[2];
-    /*! High band edge filter for symbol sync. */
-    int32_t symbol_sync_high[2];
-    /*! DC filter for symbol sync. */
-    int32_t symbol_sync_dc_filter[2];
-    /*! Baud phase for symbol sync. */
-    int32_t baud_phase;
-#else
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    float agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    float agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    float eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    complexf_t eq_coeff[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    complexf_t eq_coeff_save[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    complexf_t eq_buf[V17_EQUALIZER_PRE_LEN + 1 + V17_EQUALIZER_POST_LEN];
-
-    /*! Low band edge filter for symbol sync. */
-    float symbol_sync_low[2];
-    /*! High band edge filter for symbol sync. */
-    float symbol_sync_high[2];
-    /*! DC filter for symbol sync. */
-    float symbol_sync_dc_filter[2];
-    /*! Baud phase for symbol sync. */
-    float baud_phase;
-#endif
-
-    /*! \brief The total symbol timing correction since the carrier came up.
-               This is only for performance analysis purposes. */
-    int total_baud_timing_correction;
-
-    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
-    int32_t start_angles[2];
-    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
-    int32_t angles[16];
-    /*! \brief A pointer to the current constellation. */
-#if defined(SPANDSP_USE_FIXED_POINTx)
-    const complexi16_t *constellation;
-#else
-    const complexf_t *constellation;
-#endif
-    /*! \brief A pointer to the current space map. There is a space map for
-               each trellis state. */
-    int space_map;
-    /*! \brief The number of bits in each symbol at the current bit rate. */
-    int bits_per_symbol;
-
-    /*! \brief Current pointer to the trellis buffers */
-    int trellis_ptr;
-    /*! \brief The trellis. */
-    int full_path_to_past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
-    /*! \brief The trellis. */
-    int past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
-    /*! \brief Euclidean distances (actually the squares of the distances)
-               from the last states of the trellis. */
-#if defined(SPANDSP_USE_FIXED_POINTx)
-    uint32_t distances[8];
-#else
-    float distances[8];
-#endif
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v17_rx_state_t;
+typedef struct v17_rx_state_s v17_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -431,6 +259,8 @@
     \return 0 for OK */
 int v17_rx_free(v17_rx_state_t *s);
 
+logging_state_t *v17_rx_get_logging_state(v17_rx_state_t *s);
+
 /*! Change the put_bit function associated with a V.17 modem receive context.
     \brief Change the put_bit function associated with a V.17 modem receive context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v17tx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v17tx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v17tx.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v17tx.h,v 1.36 2008/07/16 14:23:48 steveu Exp $
+ * $Id: v17tx.h,v 1.37 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -87,73 +87,7 @@
     V.17 modem transmit side descriptor. This defines the working state for a
     single instance of a V.17 modem transmitter.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
-    int bit_rate;
-    /*! \brief The callback function used to get the next bit to be transmitted. */
-    get_bit_func_t get_bit;
-    /*! \brief A user specified opaque pointer passed to the get_bit function. */
-    void *get_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_tx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    /*! \brief The gain factor needed to achieve the specified output power. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int32_t gain;
-#else
-    float gain;
-#endif
-
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    complexi16_t rrc_filter[2*V17_TX_FILTER_STEPS];
-#else
-    complexf_t rrc_filter[2*V17_TX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-
-    /*! \brief The current state of the differential encoder. */
-    int diff;
-    /*! \brief The current state of the convolutional encoder. */
-    int convolution;
-
-    /*! \brief The register for the data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief TRUE if transmitting the training sequence. FALSE if transmitting user data. */
-    int in_training;
-    /*! \brief TRUE if the short training sequence is to be used. */
-    int short_train;
-    /*! \brief A counter used to track progress through sending the training sequence. */
-    int training_step;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The current fractional phase of the baud timing. */
-    int baud_phase;
-    /*! \brief The code number for the current position in the constellation. */
-    int constellation_state;
-    
-    /*! \brief A pointer to the constellation currently in use. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    const complexi16_t *constellation;
-#else
-    const complexf_t *constellation;
-#endif
-    /*! \brief The current number of data bits per symbol. This does not include
-               the redundant bit. */
-    int bits_per_symbol;
-    /*! \brief The get_bit function in use at any instant. */
-    get_bit_func_t current_get_bit;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v17_tx_state_t;
+typedef struct v17_tx_state_s v17_tx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -192,6 +126,8 @@
     \return 0 for OK */
 int v17_tx_free(v17_tx_state_t *s);
 
+logging_state_t *v17_tx_get_logging_state(v17_tx_state_t *s);
+
 /*! Change the get_bit function associated with a V.17 modem transmit context.
     \brief Change the get_bit function associated with a V.17 modem transmit context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v22bis.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v22bis.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v22bis.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v22bis.h,v 1.30 2008/07/25 13:56:54 steveu Exp $
+ * $Id: v22bis.h,v 1.32 2008/11/30 03:40:12 steveu Exp $
  */
 
 /*! \file */
@@ -47,8 +47,8 @@
 or 1200bps if one or both ends to not acknowledge that 2400bps is OK.
 */
 
-#if !defined(_V22BIS_H_)
-#define _V22BIS_H_
+#if !defined(_SPANDSP_V22BIS_H_)
+#define _SPANDSP_V22BIS_H_
 
 #define V22BIS_EQUALIZER_LEN    7  /* this much to the left and this much to the right */
 #define V22BIS_EQUALIZER_MASK   15 /* one less than a power of 2 >= (2*V22BIS_EQUALIZER_LEN + 1) */
@@ -61,152 +61,7 @@
     V.22bis modem descriptor. This defines the working state for a single instance
     of a V.22bis modem.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 1200 and 2400. */
-    int bit_rate;
-    /*! \brief TRUE is this is the calling side modem. */
-    int caller;
-    /*! \brief The callback function used to put each bit received. */
-    put_bit_func_t put_bit;
-    /*! \brief The callback function used to get the next bit to be transmitted. */
-    get_bit_func_t get_bit;
-    /*! \brief A user specified opaque pointer passed to the callback routines. */
-    void *user_data;
-
-    /* RECEIVE SECTION */
-    struct
-    {
-        /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-        float rrc_filter[2*V22BIS_RX_FILTER_STEPS];
-        /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-        int rrc_filter_step;
-
-        /*! \brief The register for the data scrambler. */
-        unsigned int scramble_reg;
-        /*! \brief A counter for the number of consecutive bits of repeating pattern through
-                   the scrambler. */
-        int scrambler_pattern_count;
-
-        /*! \brief 0 if receiving user data. A training stage value during training */
-        int training;
-        /*! \brief A count of how far through the current training step we are. */
-        int training_count;
-
-        /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
-        int signal_present;
-
-        /*! \brief A measure of how much mismatch there is between the real constellation,
-            and the decoded symbol positions. */
-        float training_error;
-
-        /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-        uint32_t carrier_phase;
-        /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-        int32_t carrier_phase_rate;
-        /*! \brief The proportional part of the carrier tracking filter. */
-        float carrier_track_p;
-        /*! \brief The integral part of the carrier tracking filter. */
-        float carrier_track_i;
-
-        /*! \brief A callback function which may be enabled to report every symbol's
-                   constellation position. */
-        qam_report_handler_t qam_report;
-        /*! \brief A user specified opaque pointer passed to the qam_report callback
-                   routine. */
-        void *qam_user_data;
-
-        /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
-        power_meter_t rx_power;
-        /*! \brief The power meter level at which carrier on is declared. */
-        int32_t carrier_on_power;
-        /*! \brief The power meter level at which carrier off is declared. */
-        int32_t carrier_off_power;
-        /*! \brief The scaling factor accessed by the AGC algorithm. */
-        float agc_scaling;
-    
-        int constellation_state;
-
-        /*! \brief The current delta factor for updating the equalizer coefficients. */
-        float eq_delta;
-#if defined(SPANDSP_USE_FIXED_POINTx)
-        /*! \brief The adaptive equalizer coefficients. */
-        complexi_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
-        /*! \brief The equalizer signal buffer. */
-        complexi_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
-#else
-        complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
-        complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
-#endif
-        /*! \brief Current offset into the equalizer buffer. */
-        int eq_step;
-        /*! \brief Current write offset into the equalizer buffer. */
-        int eq_put_step;
-
-        /*! \brief Integration variable for damping the Gardner algorithm tests. */
-        int gardner_integrate;
-        /*! \brief Current step size of Gardner algorithm integration. */
-        int gardner_step;
-        /*! \brief The total symbol timing correction since the carrier came up.
-                   This is only for performance analysis purposes. */
-        int total_baud_timing_correction;
-        /*! \brief The current fractional phase of the baud timing. */
-        int baud_phase;
-    
-        int sixteen_way_decisions;
-    } rx;
-
-    /* TRANSMIT SECTION */
-    struct
-    {
-        /*! \brief The gain factor needed to achieve the specified output power. */
-        float gain;
-
-        /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-        complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS];
-        /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-        int rrc_filter_step;
-
-        /*! \brief The register for the data scrambler. */
-        unsigned int scramble_reg;
-        /*! \brief A counter for the number of consecutive bits of repeating pattern through
-                   the scrambler. */
-        int scrambler_pattern_count;
-
-        /*! \brief 0 if transmitting user data. A training stage value during training */
-        int training;
-        /*! \brief A counter used to track progress through sending the training sequence. */
-        int training_count;
-        /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-        uint32_t carrier_phase;
-        /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-        int32_t carrier_phase_rate;
-        /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */
-        uint32_t guard_phase;
-        /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */
-        int32_t guard_phase_rate;
-        float guard_level;
-        /*! \brief The current fractional phase of the baud timing. */
-        int baud_phase;
-        /*! \brief The code number for the current position in the constellation. */
-        int constellation_state;
-        /*! \brief An indicator to mark that we are tidying up to stop transmission. */
-        int shutdown;
-        /*! \brief The get_bit function in use at any instant. */
-        get_bit_func_t current_get_bit;
-    } tx;
-
-    int detected_unscrambled_ones;
-    int detected_unscrambled_zeros;
-
-    int detected_unscrambled_ones_or_zeros;
-    int detected_unscrambled_0011_ending;
-    int detected_scrambled_ones_or_zeros_at_1200bps;
-    int detected_scrambled_ones_at_2400bps;
-
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v22bis_state_t;
+typedef struct v22bis_state_s v22bis_state_t;
 
 extern const complexf_t v22bis_constellation[16];
 
@@ -303,6 +158,8 @@
     \return 0 for OK */
 int v22bis_free(v22bis_state_t *s);
 
+logging_state_t *v22bis_get_logging_state(v22bis_state_t *s);
+
 /*! Change the get_bit function associated with a V.22bis modem context.
     \brief Change the get_bit function associated with a V.22bis modem context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_rx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_rx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_rx.h	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v27ter_rx.h,v 1.53 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v27ter_rx.h,v 1.54 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
 
-#if !defined(_V27TER_RX_H_)
-#define _V27TER_RX_H_
+#if !defined(_SPANDSP_V27TER_RX_H_)
+#define _SPANDSP_V27TER_RX_H_
 
 /*! \page v27ter_rx_page The V.27ter receiver
 
@@ -64,147 +64,7 @@
     V.27ter modem receive side descriptor. This defines the working state for a
     single instance of a V.27ter modem receiver.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
-    int bit_rate;
-    /*! \brief The callback function used to put each bit received. */
-    put_bit_func_t put_bit;
-    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
-    void *put_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_rx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    /*! \brief A callback function which may be enabled to report every symbol's
-               constellation position. */
-    qam_report_handler_t qam_report;
-    /*! \brief A user specified opaque pointer passed to the qam_report callback
-               routine. */
-    void *qam_user_data;
-
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int16_t rrc_filter[V27TER_RX_FILTER_STEPS];
-#else
-    float rrc_filter[V27TER_RX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-
-    /*! \brief The register for the training and data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief A counter for the number of consecutive bits of repeating pattern through
-               the scrambler. */
-    int scrambler_pattern_count;
-    /*! \brief The current step in the table of BC constellation positions. */
-    int training_bc;
-    /*! \brief TRUE if the previous trained values are to be reused. */
-    int old_train;
-    /*! \brief The section of the training data we are currently in. */
-    int training_stage;
-    /*! \brief A count of how far through the current training step we are. */
-    int training_count;
-    /*! \brief A measure of how much mismatch there is between the real constellation,
-        and the decoded symbol positions. */
-    float training_error;
-    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
-    int16_t last_sample;
-    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.27ter signal. */
-    int signal_present;
-    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
-    int carrier_drop_pending;
-    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
-    int low_samples;
-    /*! \brief A highest magnitude sample seen. */
-    int16_t high_sample;
-
-    /*! \brief The position of the current symbol in the constellation, used for
-               differential decoding. */
-    int constellation_state;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The carrier update rate saved for reuse when using short training. */
-    int32_t carrier_phase_rate_save;
-#if defined(SPANDSP_USE_FIXED_POINTx)
-    /*! \brief The proportional part of the carrier tracking filter. */
-    float carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    float carrier_track_i;
-#else
-    /*! \brief The proportional part of the carrier tracking filter. */
-    float carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    float carrier_track_i;
-#endif
-
-    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
-    power_meter_t power;
-    /*! \brief The power meter level at which carrier on is declared. */
-    int32_t carrier_on_power;
-    /*! \brief The power meter level at which carrier off is declared. */
-    int32_t carrier_off_power;
-
-    /*! \brief Current read offset into the equalizer buffer. */
-    int eq_step;
-    /*! \brief Current write offset into the equalizer buffer. */
-    int eq_put_step;
-    /*! \brief Symbol counter to the next equalizer update. */
-    int eq_skip;
-
-    /*! \brief The current half of the baud. */
-    int baud_half;
-
-#if defined(SPANDSP_USE_FIXED_POINT)
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    int16_t agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    int16_t agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    float eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    /*complexi16_t*/ complexf_t  eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    /*complexi16_t*/ complexf_t  eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    /*complexi16_t*/ complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-#else
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    float agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    float agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    float eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    complexf_t eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    complexf_t eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
-#endif
-
-    /*! \brief Integration variable for damping the Gardner algorithm tests. */
-    int gardner_integrate;
-    /*! \brief Current step size of Gardner algorithm integration. */
-    int gardner_step;
-    /*! \brief The total symbol timing correction since the carrier came up.
-               This is only for performance analysis purposes. */
-    int total_baud_timing_correction;
-
-    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
-    int32_t start_angles[2];
-    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
-    int32_t angles[16];
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v27ter_rx_state_t;
+typedef struct v27ter_rx_state_s v27ter_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -234,6 +94,8 @@
     \return 0 for OK */
 int v27ter_rx_free(v27ter_rx_state_t *s);
 
+logging_state_t *v27ter_rx_get_logging_state(v27ter_rx_state_t *s);
+
 /*! Change the put_bit function associated with a V.27ter modem receive context.
     \brief Change the put_bit function associated with a V.27ter modem receive context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_tx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_tx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v27ter_tx.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v27ter_tx.h,v 1.36 2008/07/16 14:23:48 steveu Exp $
+ * $Id: v27ter_tx.h,v 1.37 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -70,64 +70,7 @@
     V.27ter modem transmit side descriptor. This defines the working state for a
     single instance of a V.27ter modem transmitter.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
-    int bit_rate;
-    /*! \brief The callback function used to get the next bit to be transmitted. */
-    get_bit_func_t get_bit;
-    /*! \brief A user specified opaque pointer passed to the get_bit function. */
-    void *get_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_tx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-#if defined(SPANDSP_USE_FIXED_POINT)
-    /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */
-    int32_t gain_2400;
-    /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */
-    int32_t gain_4800;
-#else
-    /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */
-    float gain_2400;
-    /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */
-    float gain_4800;
-#endif
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    complexi16_t rrc_filter[2*V27TER_TX_FILTER_STEPS];
-#else
-    complexf_t rrc_filter[2*V27TER_TX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-    
-    /*! \brief The register for the training and data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief A counter for the number of consecutive bits of repeating pattern through
-               the scrambler. */
-    int scrambler_pattern_count;
-    /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
-               FALSE if transmitting user data. */
-    int in_training;
-    /*! \brief A counter used to track progress through sending the training sequence. */
-    int training_step;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The current fractional phase of the baud timing. */
-    int baud_phase;
-    /*! \brief The code number for the current position in the constellation. */
-    int constellation_state;
-    /*! \brief The get_bit function in use at any instant. */
-    get_bit_func_t current_get_bit;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v27ter_tx_state_t;
+typedef struct v27ter_tx_state_s v27ter_tx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -164,6 +107,8 @@
     \return 0 for OK */
 int v27ter_tx_free(v27ter_tx_state_t *s);
 
+logging_state_t *v27ter_tx_get_logging_state(v27ter_tx_state_t *s);
+
 /*! Change the get_bit function associated with a V.27ter modem transmit context.
     \brief Change the get_bit function associated with a V.27ter modem transmit context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v29rx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v29rx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v29rx.h	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v29rx.h,v 1.64 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v29rx.h,v 1.65 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
 
-#if !defined(_V29RX_H_)
-#define _V29RX_H_
+#if !defined(_SPANDSP_V29RX_H_)
+#define _SPANDSP_V29RX_H_
 
 /*! \page v29rx_page The V.29 receiver
 \section v29rx_page_sec_1 What does it do?
@@ -133,160 +133,7 @@
     V.29 modem receive side descriptor. This defines the working state for a
     single instance of a V.29 modem receiver.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
-    int bit_rate;
-    /*! \brief The callback function used to put each bit received. */
-    put_bit_func_t put_bit;
-    /*! \brief A user specified opaque pointer passed to the put_bit routine. */
-    void *put_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_rx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    /*! \brief A callback function which may be enabled to report every symbol's
-               constellation position. */
-    qam_report_handler_t qam_report;
-    /*! \brief A user specified opaque pointer passed to the qam_report callback
-               routine. */
-    void *qam_user_data;
-
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int16_t rrc_filter[V29_RX_FILTER_STEPS];
-#else
-    float rrc_filter[V29_RX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-
-    /*! \brief The register for the data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief The register for the training scrambler. */
-    uint8_t training_scramble_reg;
-    /*! \brief The current step in the table of CD constellation positions. */
-    int training_cd;
-    /*! \brief TRUE if the previous trained values are to be reused. */
-    int old_train;
-    /*! \brief The section of the training data we are currently in. */
-    int training_stage;
-    /*! \brief A count of how far through the current training step we are. */
-    int training_count;
-    /*! \brief A measure of how much mismatch there is between the real constellation,
-        and the decoded symbol positions. */
-    float training_error;
-    /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
-    int16_t last_sample;
-    /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.29 signal. */
-    int signal_present;
-    /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
-    int carrier_drop_pending;
-    /*! \brief A count of the current consecutive samples below the carrier off threshold. */
-    int low_samples;
-    /*! \brief A highest magnitude sample seen. */
-    int16_t high_sample;
-
-    /*! \brief The position of the current symbol in the constellation, used for
-               differential decoding. */
-    int constellation_state;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The carrier update rate saved for reuse when using short training. */
-    int32_t carrier_phase_rate_save;
-#if defined(SPANDSP_USE_FIXED_POINT)
-    /*! \brief The proportional part of the carrier tracking filter. */
-    int32_t carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    int32_t carrier_track_i;
-#else
-    /*! \brief The proportional part of the carrier tracking filter. */
-    float carrier_track_p;
-    /*! \brief The integral part of the carrier tracking filter. */
-    float carrier_track_i;
-#endif
-
-    /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
-    power_meter_t power;
-    /*! \brief The power meter level at which carrier on is declared. */
-    int32_t carrier_on_power;
-    /*! \brief The power meter level at which carrier off is declared. */
-    int32_t carrier_off_power;
-
-    /*! \brief Current read offset into the equalizer buffer. */
-    int eq_step;
-    /*! \brief Current write offset into the equalizer buffer. */
-    int eq_put_step;
-    /*! \brief Symbol counter to the next equalizer update. */
-    int eq_skip;
-
-    /*! \brief The current half of the baud. */
-    int baud_half;
-
-#if defined(SPANDSP_USE_FIXED_POINT)
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    int16_t agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    int16_t agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    int16_t eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    complexi16_t eq_coeff[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    complexi16_t eq_coeff_save[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    complexi16_t eq_buf[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-
-    /*! Low band edge filter for symbol sync. */
-    int32_t symbol_sync_low[2];
-    /*! High band edge filter for symbol sync. */
-    int32_t symbol_sync_high[2];
-    /*! DC filter for symbol sync. */
-    int32_t symbol_sync_dc_filter[2];
-    /*! Baud phase for symbol sync. */
-    int32_t baud_phase;
-#else
-    /*! \brief The scaling factor accessed by the AGC algorithm. */
-    float agc_scaling;
-    /*! \brief The previous value of agc_scaling, needed to reuse old training. */
-    float agc_scaling_save;
-
-    /*! \brief The current delta factor for updating the equalizer coefficients. */
-    float eq_delta;
-    /*! \brief The adaptive equalizer coefficients. */
-    complexf_t eq_coeff[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-    /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
-    complexf_t eq_coeff_save[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-    /*! \brief The equalizer signal buffer. */
-    complexf_t eq_buf[V29_EQUALIZER_PRE_LEN + 1 + V29_EQUALIZER_POST_LEN];
-
-    /*! Low band edge filter for symbol sync. */
-    float symbol_sync_low[2];
-    /*! High band edge filter for symbol sync. */
-    float symbol_sync_high[2];
-    /*! DC filter for symbol sync. */
-    float symbol_sync_dc_filter[2];
-    /*! Baud phase for symbol sync. */
-    float baud_phase;
-#endif
-
-    /*! \brief The total symbol timing correction since the carrier came up.
-               This is only for performance analysis purposes. */
-    int total_baud_timing_correction;
-
-    /*! \brief Starting phase angles for the coarse carrier aquisition step. */
-    int32_t start_angles[2];
-    /*! \brief History list of phase angles for the coarse carrier aquisition step. */
-    int32_t angles[16];
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v29_rx_state_t;
+typedef struct v29_rx_state_s v29_rx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -316,6 +163,8 @@
     \return 0 for OK */
 int v29_rx_free(v29_rx_state_t *s);
 
+logging_state_t *v29_rx_get_logging_state(v29_rx_state_t *s);
+
 /*! Change the put_bit function associated with a V.29 modem receive context.
     \brief Change the put_bit function associated with a V.29 modem receive context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v29tx.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v29tx.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v29tx.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v29tx.h,v 1.34 2008/07/16 14:23:48 steveu Exp $
+ * $Id: v29tx.h,v 1.35 2008/10/13 13:14:01 steveu Exp $
  */
 
 /*! \file */
@@ -100,66 +100,7 @@
     V.29 modem transmit side descriptor. This defines the working state for a
     single instance of a V.29 modem transmitter.
 */
-typedef struct
-{
-    /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
-    int bit_rate;
-    /*! \brief The callback function used to get the next bit to be transmitted. */
-    get_bit_func_t get_bit;
-    /*! \brief A user specified opaque pointer passed to the get_bit function. */
-    void *get_bit_user_data;
-
-    /*! \brief The callback function used to report modem status changes. */
-    modem_tx_status_func_t status_handler;
-    /*! \brief A user specified opaque pointer passed to the status function. */
-    void *status_user_data;
-
-    /*! \brief Gain required to achieve the specified output power, not allowing
-               for the size of the current constellation. */
-    float base_gain;
-    /*! \brief Gain required to achieve the specified output power, allowing
-               for the size of the current constellation. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    int32_t gain;
-#else
-    float gain;
-#endif
-
-    /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
-#if defined(SPANDSP_USE_FIXED_POINT)
-    complexi16_t rrc_filter[2*V29_TX_FILTER_STEPS];
-#else
-    complexf_t rrc_filter[2*V29_TX_FILTER_STEPS];
-#endif
-    /*! \brief Current offset into the RRC pulse shaping filter buffer. */
-    int rrc_filter_step;
-
-    /*! \brief The register for the data scrambler. */
-    unsigned int scramble_reg;
-    /*! \brief The register for the training scrambler. */
-    uint8_t training_scramble_reg;
-    /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
-               FALSE if transmitting user data. */
-    int in_training;
-    /*! \brief A counter used to track progress through sending the training sequence. */
-    int training_step;
-    /*! \brief An offset value into the table of training parameters, used to match the
-               training pattern to the bit rate. */
-    int training_offset;
-
-    /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
-    uint32_t carrier_phase;
-    /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
-    int32_t carrier_phase_rate;
-    /*! \brief The current fractional phase of the baud timing. */
-    int baud_phase;
-    /*! \brief The code number for the current position in the constellation. */
-    int constellation_state;
-    /*! \brief The get_bit function in use at any instant. */
-    get_bit_func_t current_get_bit;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v29_tx_state_t;
+typedef struct v29_tx_state_s v29_tx_state_t;
 
 #if defined(__cplusplus)
 extern "C"
@@ -197,6 +138,8 @@
     \return 0 for OK */
 int v29_tx_free(v29_tx_state_t *s);
 
+logging_state_t *v29_tx_get_logging_state(v29_tx_state_t *s);
+
 /*! Change the get_bit function associated with a V.29 modem transmit context.
     \brief Change the get_bit function associated with a V.29 modem transmit context.
     \param s The modem context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v42.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v42.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v42.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42.h,v 1.25 2008/04/17 14:27:01 steveu Exp $
+ * $Id: v42.h,v 1.26 2008/11/15 14:43:08 steveu Exp $
  */
 
 /*! \page v42_page V.42 modem error correction
@@ -63,89 +63,12 @@
 /*!
     LAP-M descriptor. This defines the working state for a single instance of LAP-M.
 */
-typedef struct
-{
-    int handle;
-    hdlc_rx_state_t hdlc_rx;
-    hdlc_tx_state_t hdlc_tx;
-    
-    v42_frame_handler_t iframe_receive;
-    void *iframe_receive_user_data;
-
-    v42_status_func_t status_callback;
-    void *status_callback_user_data;
-
-    int state;
-    int tx_waiting;
-    int debug;
-    /*! TRUE if originator. FALSE if answerer */
-    int we_are_originator;
-    /*! Remote network type (unknown, answerer. originator) */
-    int peer_is_originator;
-    /*! Next N(S) for transmission */
-    int next_tx_frame;
-    /*! The last of our frames which the peer acknowledged */
-    int last_frame_peer_acknowledged;
-    /*! Next N(R) for reception */
-    int next_expected_frame;
-    /*! The last of the peer's frames which we acknowledged */
-    int last_frame_we_acknowledged;
-    /*! TRUE if we sent an I or S frame with the F-bit set */
-    int solicit_f_bit;
-    /*! Retransmission count */
-    int retransmissions;
-    /*! TRUE if peer is busy */
-    int busy;
-
-    /*! Acknowledgement timer */
-    int t401_timer;
-    /*! Reply delay timer - optional */
-    int t402_timer;
-    /*! Inactivity timer - optional */
-    int t403_timer;
-    /*! Maximum number of octets in an information field */
-    int n401;
-    /*! Window size */
-    int window_size_k;
-	
-    lapm_frame_queue_t *txqueue;
-    lapm_frame_queue_t *tx_next;
-    lapm_frame_queue_t *tx_last;
-    queue_state_t *tx_queue;
-    
-    span_sched_state_t sched;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} lapm_state_t;
+typedef struct lapm_state_s lapm_state_t;
 
 /*!
     V.42 descriptor. This defines the working state for a single instance of V.42.
 */
-typedef struct
-{
-    /*! TRUE if we are the calling party, otherwise FALSE */
-    int caller;
-    /*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go
-        directly to protocol establishment */
-    int detect;
-
-    /*! Stage in negotiating V.42 support */
-    int rx_negotiation_step;
-    int rxbits;
-    int rxstream;
-    int rxoks;
-    int odp_seen;
-    int txbits;
-    int txstream;
-    int txadps;
-    /*! The LAP.M context */
-    lapm_state_t lapm;
-
-    /*! V.42 support detection timer */
-    int t400_timer;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v42_state_t;
+typedef struct v42_state_s v42_state_t;
 
 /*! Log the raw HDLC frames */
 #define LAPM_DEBUG_LAPM_RAW         (1 << 0)

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v42bis.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v42bis.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v42bis.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42bis.h,v 1.22 2008/04/17 14:27:01 steveu Exp $
+ * $Id: v42bis.h,v 1.23 2008/11/15 14:43:08 steveu Exp $
  */
 
 /*! \page v42bis_page V.42bis modem data compression
@@ -60,123 +60,10 @@
 typedef void (*v42bis_data_handler_t)(void *user_data, const uint8_t *buf, int len);
 
 /*!
-    V.42bis dictionary node.
-*/
-typedef struct
-{
-    /*! \brief The prior code for each defined code. */
-    uint16_t parent_code;
-    /*! \brief The number of leaf nodes this node has */
-    int16_t leaves;
-    /*! \brief This leaf octet for each defined code. */
-    uint8_t node_octet;
-    /*! \brief Bit map of the children which exist */
-    uint32_t children[8];
-} v42bis_dict_node_t;
-
-/*!
-    V.42bis compression. This defines the working state for a single instance
-    of V.42bis compression.
-*/
-typedef struct
-{
-    /*! \brief Compression mode. */
-    int compression_mode;
-    /*! \brief Callback function to handle received frames. */
-    v42bis_frame_handler_t handler;
-    /*! \brief An opaque pointer passed in calls to frame_handler. */
-    void *user_data;
-    /*! \brief The maximum frame length allowed */
-    int max_len;
-
-    uint32_t string_code;
-    uint32_t latest_code;
-    int string_length;
-    uint32_t output_bit_buffer;
-    int output_bit_count;
-    int output_octet_count;
-    uint8_t output_buf[1024];
-    v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
-    /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
-    int transparent;
-    int change_transparency;
-    /*! \brief IIR filter state, used in assessing compressibility. */
-    int compressibility_filter;
-    int compressibility_persistence;
-    
-    /*! \brief Next empty dictionary entry */
-    uint32_t v42bis_parm_c1;
-    /*! \brief Current codeword size */
-    int v42bis_parm_c2;
-    /*! \brief Threshold for codeword size change */
-    uint32_t v42bis_parm_c3;
-
-    /*! \brief Mark that this is the first octet/code to be processed */
-    int first;
-    uint8_t escape_code;
-} v42bis_compress_state_t;
-
-/*!
-    V.42bis decompression. This defines the working state for a single instance
-    of V.42bis decompression.
-*/
-typedef struct
-{
-    /*! \brief Callback function to handle decompressed data. */
-    v42bis_data_handler_t handler;
-    /*! \brief An opaque pointer passed in calls to data_handler. */
-    void *user_data;
-    /*! \brief The maximum decompressed data block length allowed */
-    int max_len;
-
-    uint32_t old_code;
-    uint32_t last_old_code;
-    uint32_t input_bit_buffer;
-    int input_bit_count;
-    int octet;
-    int last_length;
-    int output_octet_count;
-    uint8_t output_buf[1024];
-    v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
-    /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
-    int transparent;
-
-    int last_extra_octet;
-
-    /*! \brief Next empty dictionary entry */
-    uint32_t v42bis_parm_c1;
-    /*! \brief Current codeword size */
-    int v42bis_parm_c2;
-    /*! \brief Threshold for codeword size change */
-    uint32_t v42bis_parm_c3;
-        
-    /*! \brief Mark that this is the first octet/code to be processed */
-    int first;
-    uint8_t escape_code;
-    int escaped;
-} v42bis_decompress_state_t;
-
-/*!
     V.42bis compression/decompression descriptor. This defines the working state for a
     single instance of V.42bis compress/decompression.
 */
-typedef struct
-{
-    /*! \brief V.42bis data compression directions. */
-    int v42bis_parm_p0;
-
-    /*! \brief Compression state. */
-    v42bis_compress_state_t compress;
-    /*! \brief Decompression state. */
-    v42bis_decompress_state_t decompress;
-    
-    /*! \brief Maximum codeword size (bits) */
-    int v42bis_parm_n1;
-    /*! \brief Total number of codewords */
-    uint32_t v42bis_parm_n2;
-    /*! \brief Maximum string length */
-    int v42bis_parm_n7;
-} v42bis_state_t;
+typedef struct v42bis_state_s v42bis_state_t;
 
 #if defined(__cplusplus)
 extern "C"

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/v8.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/v8.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/v8.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v8.h,v 1.23 2008/09/04 14:40:05 steveu Exp $
+ * $Id: v8.h,v 1.25 2008/10/13 14:19:18 steveu Exp $
  */
  
 /*! \file */
@@ -100,55 +100,7 @@
     V8_PSTN_PCM_MODEM_V91 = 0x80
 };
 
-typedef struct
-{
-    /*! \brief TRUE if we are the calling modem */
-    int caller;
-    /*! \brief The current state of the V8 protocol */
-    int state;
-    int negotiation_timer;
-    int ci_timer;
-    int ci_count;
-    fsk_tx_state_t v21tx;
-    fsk_rx_state_t v21rx;
-    queue_state_t *tx_queue;
-    modem_connect_tones_tx_state_t ansam_tx;
-    modem_connect_tones_rx_state_t ansam_rx;
-
-    v8_result_handler_t *result_handler;
-    void *result_handler_user_data;
-
-    /*! \brief Modulation schemes available at this end. */
-    int available_modulations;
-    int common_modulations;
-    int negotiated_modulation;
-    int far_end_modulations;
-    
-    int call_function;
-    int protocol;
-    int pstn_access;
-    int nsf_seen;
-    int pcm_modem_availability;
-    int t66_seen;
-
-    /* V8 data parsing */
-    unsigned int bit_stream;
-    int bit_cnt;
-    /* Indicates the type of message coming up */
-    int preamble_type;
-    uint8_t rx_data[64];
-    int rx_data_ptr;
-    
-    /*! \brief a reference copy of the last CM or JM message, used when
-               testing for matches. */
-    uint8_t cm_jm_data[64];
-    int cm_jm_count;
-    int got_cm_jm;
-    int got_cj;
-    int zero_byte_count;
-    /*! \brief Error and flow logging control */
-    logging_state_t logging;
-} v8_state_t;
+typedef struct v8_state_s v8_state_t;
 
 struct v8_result_s
 {
@@ -188,6 +140,14 @@
     \return 0 for OK. */
 int v8_release(v8_state_t *s);
 
+/*! Free a V.8 context.
+    \brief Release a V.8 context.
+    \param s The V.8 context.
+    \return 0 for OK. */
+int v8_free(v8_state_t *s);
+
+logging_state_t *v8_get_logging_state(v8_state_t *s);
+
 /*! Generate a block of V.8 audio samples.
     \brief Generate a block of V.8 audio samples.
     \param s The V.8 context.

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/vector_float.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/vector_float.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/vector_float.h	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: vector_float.h,v 1.13 2008/09/18 13:54:32 steveu Exp $
+ * $Id: vector_float.h,v 1.14 2008/10/09 13:25:19 steveu Exp $
  */
 
 #if !defined(_SPANDSP_VECTOR_FLOAT_H_)
@@ -41,6 +41,14 @@
 void vec_copyl(long double z[], const long double x[], int n);
 #endif
 
+void vec_negatef(float z[], const float x[], int n);
+
+void vec_negate(double z[], const double x[], int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_negatel(long double z[], const long double x[], int n);
+#endif
+
 void vec_zerof(float z[], int n);
 
 void vec_zero(double z[], int n);
@@ -65,12 +73,20 @@
 void vec_addl(long double z[], const long double x[], const long double y[], int n);
 #endif
 
-void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
+void vec_scaledxy_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
 
-void vec_scaled_add(double z[], const double x[], double x_scale, const double y[], double y_scale, int n);
+void vec_scaledxy_add(double z[], const double x[], double x_scale, const double y[], double y_scale, int n);
 
 #if defined(HAVE_LONG_DOUBLE)
-void vec_scaled_addl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n);
+void vec_scaledxy_addl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n);
+#endif
+
+void vec_scaledy_addf(float z[], const float x[], const float y[], float y_scale, int n);
+
+void vec_scaledy_add(double z[], const double x[], const double y[], double y_scale, int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scaledy_addl(long double z[], const long double x[], const long double y[], long double y_scale, int n);
 #endif
 
 void vec_subf(float z[], const float x[], const float y[], int n);
@@ -81,12 +97,28 @@
 void vec_subl(long double z[], const long double x[], const long double y[], int n);
 #endif
 
-void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
+void vec_scaledxy_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
+
+void vec_scaledxy_sub(double z[], const double x[], double x_scale, const double y[], double y_scale, int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scaledxy_subl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n);
+#endif
+
+void vec_scaledx_subf(float z[], const float x[], float x_scale, const float y[], int n);
 
-void vec_scaled_sub(double z[], const double x[], double x_scale, const double y[], double y_scale, int n);
+void vec_scaledx_sub(double z[], const double x[], double x_scale, const double y[], int n);
 
 #if defined(HAVE_LONG_DOUBLE)
-void vec_scaled_subl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n);
+void vec_scaledx_subl(long double z[], const long double x[], long double x_scale, const long double y[], int n);
+#endif
+
+void vec_scaledy_subf(float z[], const float x[], const float y[], float y_scale, int n);
+
+void vec_scaledy_sub(double z[], const double x[], const double y[], double y_scale, int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scaledy_subl(long double z[], const long double x[], const long double y[], long double y_scale, int n);
 #endif
 
 void vec_scalar_mulf(float z[], const float x[], float y, int n);
@@ -97,6 +129,22 @@
 void vec_scalar_mull(long double z[], const long double x[], long double y, int n);
 #endif
 
+void vec_scalar_addf(float z[], const float x[], float y, int n);
+
+void vec_scalar_add(double z[], const double x[], double y, int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scalar_addl(long double z[], const long double x[], long double y, int n);
+#endif
+
+void vec_scalar_subf(float z[], const float x[], float y, int n);
+
+void vec_scalar_sub(double z[], const double x[], double y, int n);
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scalar_subl(long double z[], const long double x[], long double y, int n);
+#endif
+
 void vec_mulf(float z[], const float x[], const float y[], int n);
 
 void vec_mul(double z[], const double x[], const double y[], int n);

Modified: freeswitch/trunk/libs/spandsp/src/spandsp/version.h
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/spandsp/version.h	(original)
+++ freeswitch/trunk/libs/spandsp/src/spandsp/version.h	Tue Jan 27 22:48:03 2009
@@ -30,8 +30,8 @@
 
 /* The date and time of the version are in UTC form. */
 
-#define SPANDSP_RELEASE_DATE    20080930
-#define SPANDSP_RELEASE_TIME    181513
+#define SPANDSP_RELEASE_DATE    20090128
+#define SPANDSP_RELEASE_TIME    034417
 
 #endif
 /*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/super_tone_rx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/super_tone_rx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/super_tone_rx.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_rx.c,v 1.29 2008/07/25 13:56:54 steveu Exp $
+ * $Id: super_tone_rx.c,v 1.31 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -38,13 +38,13 @@
 #include <ctype.h>
 #include <time.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/complex.h"
@@ -54,6 +54,8 @@
 #include "spandsp/tone_generate.h"
 #include "spandsp/super_tone_rx.h"
 
+#include "spandsp/private/super_tone_rx.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #define DETECTION_THRESHOLD         16439           /* -42dBm0 */
 #define TONE_TWIST                  4               /* 6dB */

Modified: freeswitch/trunk/libs/spandsp/src/super_tone_tx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/super_tone_tx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/super_tone_tx.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_tx.c,v 1.25 2008/07/02 14:48:26 steveu Exp $
+ * $Id: super_tone_tx.c,v 1.27 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -38,13 +38,13 @@
 #include <ctype.h>
 #include <time.h>
 #include <inttypes.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/complex.h"
@@ -52,6 +52,9 @@
 #include "spandsp/tone_generate.h"
 #include "spandsp/super_tone_tx.h"
 
+#include "spandsp/private/tone_generate.h"
+#include "spandsp/private/super_tone_tx.h"
+
 /*
     The tone played to wake folk up when they have left the phone off hook is an
     oddity amongst supervisory tones. It is designed to sound loud and nasty. Most

Modified: freeswitch/trunk/libs/spandsp/src/t30.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t30.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t30.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t30.c,v 1.267 2008/09/16 12:45:01 steveu Exp $
+ * $Id: t30.c,v 1.278 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -37,13 +37,13 @@
 #include <string.h>
 #include <fcntl.h>
 #include <time.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <tiffio.h>
 
 #include "spandsp/telephony.h"
@@ -67,6 +67,10 @@
 #include "spandsp/t30_api.h"
 #include "spandsp/t30_logging.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+
 #include "t30_local.h"
 
 #define MAX_MESSAGE_TRIES   3
@@ -371,13 +375,25 @@
         s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
         return -1;
     }
-    s->ecm_tx_page++;
     s->ecm_block = 0;
+    s->error_correcting_mode_retries = 0;
     span_log(&s->logging, SPAN_LOG_FLOW, "Starting page %d of transfer\n", s->ecm_tx_page + 1);
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
 
+static int tx_end_page(t30_state_t *s)
+{
+    s->retries = 0;
+    if (t4_tx_end_page(&(s->t4)) == 0)
+    {
+        s->ecm_tx_page++;
+        s->ecm_block = 0;
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 static int rx_start_page(t30_state_t *s)
 {
     int i;
@@ -398,10 +414,21 @@
     /* Clear the buffer */
     for (i = 0;  i < 256;  i++)
         s->ecm_len[i] = -1;
-    s->ecm_rx_page++;
     s->ecm_block = 0;
     s->ecm_frames = -1;
     s->ecm_frames_this_tx_burst = 0;
+    s->error_correcting_mode_retries = 0;
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int rx_end_page(t30_state_t *s)
+{
+    if (t4_rx_end_page(&(s->t4)) == 0)
+    {
+        s->ecm_rx_page++;
+        s->ecm_block = 0;
+    }
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
@@ -1981,7 +2008,7 @@
     }
     if (s->phase_b_handler)
     {
-        new_status = s->phase_b_handler(s, s->phase_d_user_data, msg[2]);
+        new_status = s->phase_b_handler(s, s->phase_b_user_data, msg[2]);
         if (new_status != T30_ERR_OK)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Application rejected DIS/DTC - '%s'\n", t30_completion_code_to_str(new_status));
@@ -2156,7 +2183,7 @@
 
     if (s->phase_b_handler)
     {
-        new_status = s->phase_b_handler(s, s->phase_d_user_data, msg[2]);
+        new_status = s->phase_b_handler(s, s->phase_b_user_data, msg[2]);
         if (new_status != T30_ERR_OK)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Application rejected DCS - '%s'\n", t30_completion_code_to_str(new_status));
@@ -2217,7 +2244,7 @@
         default:
             /* We can confirm the whole page. */
             s->next_rx_step = s->last_pps_fcf2;
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, s->last_pps_fcf2);
             rx_start_page(s);
@@ -2290,20 +2317,21 @@
         span_log(&s->logging, SPAN_LOG_FLOW, "ECM rx block mismatch - expected %d, but received %d.\n", s->ecm_block, block);
     }
     /* Build a bit map of which frames we now have stored OK */
-    frame_no = 0;
     s->ecm_first_bad_frame = 256;
-    for (i = 3;  i < 3 + 32;  i++)
+    for (i = 0;  i < 32;  i++)
     {
-        s->ecm_frame_map[i] = 0;
+        s->ecm_frame_map[i + 3] = 0;
         for (j = 0;  j < 8;  j++)
         {
+            frame_no = (i << 3) + j;
             if (s->ecm_len[frame_no] < 0)
-            {   
-                s->ecm_frame_map[i] |= (1 << j);
+            {
+                s->ecm_frame_map[i + 3] |= (1 << j);
                 if (frame_no < s->ecm_first_bad_frame)
                     s->ecm_first_bad_frame = frame_no;
+                if (frame_no < s->ecm_frames)
+                    s->error_correcting_mode_retries++;
             }
-            frame_no++;
         }
     }
     /* Are there any bad frames, or does our scan represent things being OK? */
@@ -2366,7 +2394,10 @@
             else
             {
                 if (frame_no < s->ecm_frames)
+                {
                     span_log(&s->logging, SPAN_LOG_FLOW, "Frame %d to be resent\n", frame_no);
+                    s->error_correcting_mode_retries++;
+                }
 #if 0
                 /* Diagnostic: See if the other end is complaining about something we didn't even send this time. */
                 if (s->ecm_len[frame_no] < 0)
@@ -2892,13 +2923,13 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             rx_start_page(s);
             set_state(s, T30_STATE_III_Q_MCF);
             send_simple_frame(s, T30_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             rx_start_page(s);
             set_state(s, T30_STATE_III_Q_RTP);
             send_simple_frame(s, T30_RTP);
@@ -2921,14 +2952,14 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
             set_state(s, T30_STATE_III_Q_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
@@ -2950,13 +2981,13 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             rx_start_page(s);
             set_state(s, T30_STATE_III_Q_MCF);
             send_simple_frame(s, T30_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             rx_start_page(s);
             set_state(s, T30_STATE_III_Q_RTP);
             send_simple_frame(s, T30_RTP);
@@ -2979,14 +3010,14 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
             set_state(s, T30_STATE_III_Q_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
@@ -3006,7 +3037,7 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
@@ -3014,7 +3045,7 @@
             send_simple_frame(s, T30_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
@@ -3038,14 +3069,14 @@
         {
         case T30_COPY_QUALITY_PERFECT:
         case T30_COPY_QUALITY_GOOD:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
             set_state(s, T30_STATE_III_Q_MCF);
             break;
         case T30_COPY_QUALITY_POOR:
-            t4_rx_end_page(&(s->t4));
+            rx_end_page(s);
             t4_rx_end(&(s->t4));
             s->operation_in_progress = OPERATION_IN_PROGRESS_NONE;
             s->in_message = FALSE;
@@ -3332,8 +3363,7 @@
         {
         case T30_MPS:
         case T30_PRI_MPS:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
             if (tx_start_page(s))
@@ -3347,8 +3377,7 @@
         case T30_EOM:
         case T30_PRI_EOM:
         case T30_EOS:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
             t4_tx_end(&(s->t4));
@@ -3362,8 +3391,7 @@
             break;
         case T30_EOP:
         case T30_PRI_EOP:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
             t4_tx_end(&(s->t4));
@@ -3382,8 +3410,7 @@
         {
         case T30_MPS:
         case T30_PRI_MPS:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_RTP);
             if (tx_start_page(s))
@@ -3406,8 +3433,7 @@
         case T30_EOM:
         case T30_PRI_EOM:
         case T30_EOS:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_RTP);
             t4_tx_end(&(s->t4));
@@ -3416,8 +3442,7 @@
             break;
         case T30_EOP:
         case T30_PRI_EOP:
-            s->retries = 0;
-            t4_tx_end_page(&(s->t4));
+            tx_end_page(s);
             if (s->phase_d_handler)
                 s->phase_d_handler(s, s->phase_d_user_data, T30_RTP);
             t4_tx_end(&(s->t4));
@@ -3643,7 +3668,7 @@
         span_log(&s->logging, SPAN_LOG_FLOW, "Is there more to send? - %d %d\n", s->ecm_frames, s->ecm_len[255]);
         if (!s->ecm_at_page_end  &&  get_partial_ecm_page(s) > 0)
         {
-            span_log(&s->logging, SPAN_LOG_WARNING, "Additional image data to send\n");
+            span_log(&s->logging, SPAN_LOG_FLOW, "Additional image data to send\n");
             s->ecm_block++;
             set_state(s, T30_STATE_IV);
             queue_phase(s, T30_PHASE_C_ECM_TX);
@@ -3656,8 +3681,7 @@
             {
             case T30_MPS:
             case T30_PRI_MPS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 if (tx_start_page(s))
@@ -3675,8 +3699,7 @@
             case T30_EOM:
             case T30_PRI_EOM:
             case T30_EOS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -3690,8 +3713,7 @@
                 break;
             case T30_EOP:
             case T30_PRI_EOP:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -3748,7 +3770,7 @@
         span_log(&s->logging, SPAN_LOG_FLOW, "Is there more to send? - %d %d\n", s->ecm_frames, s->ecm_len[255]);
         if (!s->ecm_at_page_end  &&  get_partial_ecm_page(s) > 0)
         {
-            span_log(&s->logging, SPAN_LOG_WARNING, "Additional image data to send\n");
+            span_log(&s->logging, SPAN_LOG_FLOW, "Additional image data to send\n");
             s->ecm_block++;
             set_state(s, T30_STATE_IV);
             queue_phase(s, T30_PHASE_C_ECM_TX);
@@ -3761,8 +3783,7 @@
             {
             case T30_MPS:
             case T30_PRI_MPS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 if (tx_start_page(s))
@@ -3780,8 +3801,7 @@
             case T30_EOM:
             case T30_PRI_EOM:
             case T30_EOS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -3795,8 +3815,7 @@
                 break;
             case T30_EOP:
             case T30_PRI_EOP:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -3869,7 +3888,7 @@
         span_log(&s->logging, SPAN_LOG_FLOW, "Is there more to send? - %d %d\n", s->ecm_frames, s->ecm_len[255]);
         if (!s->ecm_at_page_end  &&  get_partial_ecm_page(s) > 0)
         {
-            span_log(&s->logging, SPAN_LOG_WARNING, "Additional image data to send\n");
+            span_log(&s->logging, SPAN_LOG_FLOW, "Additional image data to send\n");
             s->ecm_block++;
             set_state(s, T30_STATE_IV);
             queue_phase(s, T30_PHASE_C_ECM_TX);
@@ -3882,8 +3901,7 @@
             {
             case T30_MPS:
             case T30_PRI_MPS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 if (tx_start_page(s))
@@ -3901,8 +3919,7 @@
             case T30_EOM:
             case T30_PRI_EOM:
             case T30_EOS:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -3916,8 +3933,7 @@
                 break;
             case T30_EOP:
             case T30_PRI_EOP:
-                s->retries = 0;
-                t4_tx_end_page(&(s->t4));
+                tx_end_page(s);
                 if (s->phase_d_handler)
                     s->phase_d_handler(s, s->phase_d_user_data, T30_MCF);
                 t4_tx_end(&(s->t4));
@@ -4872,17 +4888,16 @@
     int was_trained;
 
     s = (t30_state_t *) user_data;
+    span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM signal status is %s (%d) in state %d\n", signal_status_to_str(status), status, s->state);
     switch (status)
     {
     case SIG_STATUS_TRAINING_IN_PROGRESS:
         break;
     case SIG_STATUS_TRAINING_FAILED:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier training failed in state %d\n", s->state);
         s->rx_trained = FALSE;
         break;
     case SIG_STATUS_TRAINING_SUCCEEDED:
         /* The modem is now trained */
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier trained in state %d\n", s->state);
         /* In case we are in trainability test mode... */
         s->tcf_test_bits = 0;
         s->tcf_current_zeros = 0;
@@ -4892,10 +4907,8 @@
         s->timer_t2_t4 = 0;
         break;
     case SIG_STATUS_CARRIER_UP:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier up in state %d\n", s->state);
         break;
     case SIG_STATUS_CARRIER_DOWN:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier down in state %d\n", s->state);
         was_trained = s->rx_trained;
         s->rx_signal_present = FALSE;
         s->rx_trained = FALSE;
@@ -5199,22 +5212,20 @@
     t30_state_t *s;
 
     s = (t30_state_t *) user_data;
+    span_log(&s->logging, SPAN_LOG_FLOW, "HDLC signal status is %s (%d) in state %d\n", signal_status_to_str(status), status, s->state);
     switch (status)
     {
     case SIG_STATUS_TRAINING_IN_PROGRESS:
         break;
     case SIG_STATUS_TRAINING_FAILED:
-        span_log(&s->logging, SPAN_LOG_FLOW, "HDLC carrier training failed in state %d\n", s->state);
         s->rx_trained = FALSE;
         break;
     case SIG_STATUS_TRAINING_SUCCEEDED:
         /* The modem is now trained */
-        span_log(&s->logging, SPAN_LOG_FLOW, "HDLC carrier trained in state %d\n", s->state);
         s->rx_signal_present = TRUE;
         s->rx_trained = TRUE;
         break;
     case SIG_STATUS_CARRIER_UP:
-        span_log(&s->logging, SPAN_LOG_FLOW, "HDLC carrier up in state %d\n", s->state);
         s->rx_signal_present = TRUE;
         switch (s->timer_t2_t4_is)
         {
@@ -5229,7 +5240,6 @@
         }
         break;
     case SIG_STATUS_CARRIER_DOWN:
-        span_log(&s->logging, SPAN_LOG_FLOW, "HDLC carrier down in state %d\n", s->state);
         s->rx_signal_present = FALSE;
         s->rx_trained = FALSE;
         /* If a phase change has been queued to occur after the receive signal drops,
@@ -5258,7 +5268,6 @@
         }
         break;
     case SIG_STATUS_FRAMING_OK:
-        span_log(&s->logging, SPAN_LOG_FLOW, "HDLC framing OK in state %d\n", s->state);
         if (!s->far_end_detected  &&  s->timer_t0_t1 > 0)
         {
             s->timer_t0_t1 = ms_to_samples(DEFAULT_TIMER_T1);
@@ -5507,7 +5516,7 @@
             }
             else
             {
-                /* We just sent the disconnect message. Now it is time to disconnect */
+                /* We just sent the disconnect message. Now it is time to disconnect. */
                 disconnect(s);
             }
             break;
@@ -5650,6 +5659,14 @@
         span_log(&s->logging, SPAN_LOG_FLOW, "No signal is present\n");
         /* TODO: Should we do anything here? */
         break;
+    case T30_FRONT_END_CED_PRESENT:
+        span_log(&s->logging, SPAN_LOG_FLOW, "CED tone is present\n");
+        /* TODO: Should we do anything here? */
+        break;
+    case T30_FRONT_END_CNG_PRESENT:
+        span_log(&s->logging, SPAN_LOG_FLOW, "CNG tone is present\n");
+        /* TODO: Should we do anything here? */
+        break;
     }
 }
 /*- End of function --------------------------------------------------------*/
@@ -5742,6 +5759,7 @@
 
     t->bit_rate = fallback_sequence[s->current_fallback].bit_rate;
     t->error_correcting_mode = s->error_correcting_mode;
+    t->error_correcting_mode_retries = s->error_correcting_mode_retries;
     t4_get_transfer_statistics(&s->t4, &stats);
     t->pages_transferred = stats.pages_transferred;
     t->pages_in_file = stats.pages_in_file;
@@ -5798,8 +5816,8 @@
     s->far_end_detected = FALSE;
     s->timer_t0_t1 = ms_to_samples(DEFAULT_TIMER_T0);
     release_resources(s);
-    s->ecm_rx_page = -1;
-    s->ecm_tx_page = -1;
+    s->ecm_rx_page = 0;
+    s->ecm_tx_page = 0;
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
@@ -5870,4 +5888,10 @@
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
+
+int t30_call_active(t30_state_t *s)
+{
+    return (s->phase != T30_PHASE_CALL_FINISHED);
+}
+/*- End of function --------------------------------------------------------*/
 /*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/t30_api.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t30_api.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t30_api.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t30_api.c,v 1.8 2008/08/14 14:06:05 steveu Exp $
+ * $Id: t30_api.c,v 1.12 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -37,13 +37,13 @@
 #include <string.h>
 #include <fcntl.h>
 #include <time.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <tiffio.h>
 
 #include "spandsp/telephony.h"
@@ -67,6 +67,10 @@
 #include "spandsp/t30_api.h"
 #include "spandsp/t30_logging.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+
 #include "t30_local.h"
 
 int t30_set_tx_ident(t30_state_t *s, const char *id)
@@ -724,4 +728,10 @@
     s->real_time_frame_user_data = user_data;
 }
 /*- End of function --------------------------------------------------------*/
+
+logging_state_t *t30_get_logging_state(t30_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
 /*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/t30_logging.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t30_logging.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t30_logging.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t30_logging.c,v 1.6 2008/08/01 17:59:46 steveu Exp $
+ * $Id: t30_logging.c,v 1.10 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -37,13 +37,13 @@
 #include <string.h>
 #include <fcntl.h>
 #include <time.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <tiffio.h>
 
 #include "spandsp/telephony.h"
@@ -66,6 +66,10 @@
 #include "spandsp/t30.h"
 #include "spandsp/t30_logging.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+
 #include "t30_local.h"
 
 typedef struct

Modified: freeswitch/trunk/libs/spandsp/src/t31.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t31.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t31.c	Tue Jan 27 22:48:03 2009
@@ -8,7 +8,7 @@
  * Special thanks to Lee Howard <faxguy at howardsilvan.com>
  * for his great work debugging and polishing this code.
  *
- * Copyright (C) 2004, 2005, 2006 Steve Underwood
+ * Copyright (C) 2004, 2005, 2006, 2008 Steve Underwood
  *
  * All rights reserved.
  *
@@ -25,13 +25,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t31.c,v 1.120 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t31.c,v 1.136 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
@@ -42,13 +42,13 @@
 #include <memory.h>
 #include <string.h>
 #include <ctype.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <tiffio.h>
 
@@ -62,15 +62,16 @@
 #include "spandsp/tone_detect.h"
 #include "spandsp/tone_generate.h"
 #include "spandsp/async.h"
+#include "spandsp/crc.h"
 #include "spandsp/hdlc.h"
 #include "spandsp/silence_gen.h"
 #include "spandsp/fsk.h"
-#include "spandsp/v29rx.h"
 #include "spandsp/v29tx.h"
-#include "spandsp/v27ter_rx.h"
+#include "spandsp/v29rx.h"
 #include "spandsp/v27ter_tx.h"
-#include "spandsp/v17rx.h"
+#include "spandsp/v27ter_rx.h"
 #include "spandsp/v17tx.h"
+#include "spandsp/v17rx.h"
 #include "spandsp/super_tone_rx.h"
 #include "spandsp/modem_connect_tones.h"
 #include "spandsp/t4.h"
@@ -82,20 +83,35 @@
 #include "spandsp/fax_modems.h"
 #include "spandsp/t31.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t38_core.h"
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/v17tx.h"
+#include "spandsp/private/v17rx.h"
+#include "spandsp/private/v27ter_tx.h"
+#include "spandsp/private/v27ter_rx.h"
+#include "spandsp/private/v29tx.h"
+#include "spandsp/private/v29rx.h"
+#include "spandsp/private/modem_connect_tones.h"
+#include "spandsp/private/hdlc.h"
+#include "spandsp/private/fax_modems.h"
+#include "spandsp/private/at_interpreter.h"
+#include "spandsp/private/t31.h"
+
 /* Settings suitable for paced transmission over a UDP transport */
-#define MS_PER_TX_CHUNK                 30
-#define INDICATOR_TX_COUNT              3
-#define DATA_TX_COUNT                   1
-#define DATA_END_TX_COUNT               3
-#define DEFAULT_DTE_TIMEOUT             5
+#define MS_PER_TX_CHUNK                         30
+#define INDICATOR_TX_COUNT                      3
+#define DATA_TX_COUNT                           1
+#define DATA_END_TX_COUNT                       3
+#define DEFAULT_DTE_TIMEOUT                     5
 
 /* Settings suitable for unpaced transmission over a TCP transport */
-#define MAX_OCTETS_PER_UNPACED_CHUNK    300
+#define MAX_OCTETS_PER_UNPACED_CHUNK            300
 
 /* Backstop timeout if reception of packets stops in the middle of a burst */
-#define MID_RX_TIMEOUT                  15000
+#define MID_RX_TIMEOUT                          15000
 
-#define HDLC_FRAMING_OK_THRESHOLD       5
+#define HDLC_FRAMING_OK_THRESHOLD               5
 
 typedef const char *(*at_cmd_service_t)(t31_state_t *s, const char *cmd);
 
@@ -125,30 +141,44 @@
 
 enum
 {
+    T38_CHUNKING_MERGE_FCS_WITH_DATA    = 0x0001,
+    T38_CHUNKING_WHOLE_FRAMES           = 0x0002,
+    T38_CHUNKING_ALLOW_TEP_TIME         = 0x0004
+};
+
+enum
+{
     T38_TIMED_STEP_NONE = 0,
-    T38_TIMED_STEP_NON_ECM_MODEM,
-    T38_TIMED_STEP_NON_ECM_MODEM_2,
-    T38_TIMED_STEP_NON_ECM_MODEM_3,
-    T38_TIMED_STEP_NON_ECM_MODEM_4,
-    T38_TIMED_STEP_NON_ECM_MODEM_5,
-    T38_TIMED_STEP_HDLC_MODEM,
-    T38_TIMED_STEP_HDLC_MODEM_2,
-    T38_TIMED_STEP_HDLC_MODEM_3,
-    T38_TIMED_STEP_HDLC_MODEM_4,
-    T38_TIMED_STEP_CED,
-    T38_TIMED_STEP_CED_2,
-    T38_TIMED_STEP_CNG,
-    T38_TIMED_STEP_CNG_2,
-    T38_TIMED_STEP_PAUSE
+    T38_TIMED_STEP_NON_ECM_MODEM = 0x10,
+    T38_TIMED_STEP_NON_ECM_MODEM_2 = 0x11,
+    T38_TIMED_STEP_NON_ECM_MODEM_3 = 0x12,
+    T38_TIMED_STEP_NON_ECM_MODEM_4 = 0x13,
+    T38_TIMED_STEP_NON_ECM_MODEM_5 = 0x14,
+    T38_TIMED_STEP_HDLC_MODEM = 0x20,
+    T38_TIMED_STEP_HDLC_MODEM_2 = 0x21,
+    T38_TIMED_STEP_HDLC_MODEM_3 = 0x22,
+    T38_TIMED_STEP_HDLC_MODEM_4 = 0x23,
+    T38_TIMED_STEP_HDLC_MODEM_5 = 0x24,
+    T38_TIMED_STEP_CED = 0x30,
+    T38_TIMED_STEP_CED_2 = 0x31,
+    T38_TIMED_STEP_CED_3 = 0x32,
+    T38_TIMED_STEP_CNG = 0x40,
+    T38_TIMED_STEP_CNG_2 = 0x41,
+    T38_TIMED_STEP_PAUSE = 0x50
 };
 
 static int restart_modem(t31_state_t *s, int new_modem);
-static void hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok);
+static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ok);
 static int v17_v21_rx(void *user_data, const int16_t amp[], int len);
 static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len);
 static int v29_v21_rx(void *user_data, const int16_t amp[], int len);
 static int silence_rx(void *user_data, const int16_t amp[], int len);
 static int cng_rx(void *user_data, const int16_t amp[], int len);
+static void non_ecm_put_bit(void *user_data, int bit);
+static void non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len);
+static int non_ecm_get_chunk(void *user_data, uint8_t buf[], int len);
+static void non_ecm_rx_status(void *user_data, int status);
+static void hdlc_rx_status(void *user_data, int status);
 
 static __inline__ void t31_set_at_rx_mode(t31_state_t *s, int new_mode)
 {
@@ -156,12 +186,105 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+static void front_end_status(t31_state_t *s, int status)
+{
+    span_log(&s->logging, SPAN_LOG_FLOW, "Front end status %d\n", status);
+    switch (status)
+    {
+    case T30_FRONT_END_SEND_STEP_COMPLETE:
+        switch (s->modem)
+        {
+        case T31_SILENCE_TX:
+            s->modem = T31_NONE;
+            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
+            if (s->at_state.do_hangup)
+            {
+                at_modem_control(&s->at_state, AT_MODEM_CONTROL_HANGUP, NULL);
+                t31_set_at_rx_mode(s, AT_MODE_ONHOOK_COMMAND);
+                s->at_state.do_hangup = FALSE;
+            }
+            else
+            {
+                t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
+            }
+            break;
+        case T31_CED_TONE:
+            /* Go directly to V.21/HDLC transmit. */
+            s->modem = T31_NONE;
+            restart_modem(s, T31_V21_TX);
+            t31_set_at_rx_mode(s, AT_MODE_HDLC);
+            break;
+        case T31_V21_TX:
+        case T31_V17_TX:
+        case T31_V27TER_TX:
+        case T31_V29_TX:
+            s->modem = T31_NONE;
+            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
+            t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
+            restart_modem(s, T31_SILENCE_TX);
+            break;
+        }
+        break;
+    case T30_FRONT_END_RECEIVE_COMPLETE:
+        break;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
+static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len)
+{
+    int bitstream;
+    int ones;
+    int stuffed;
+    int i;
+    int j;
+    
+    bitstream = 0;
+    ones = 0;
+    stuffed = 0;
+    /* We should really append the CRC, and include the stuffed bits for that, to get
+       the exact number of bits in the frame. */
+    //len = crc_itu16_append(buf, len);
+    for (i = 0;  i < len;  i++)
+    {
+        bitstream = buf[i];
+        for (j = 0;  j < 8;  j++)
+        {
+            if ((bitstream & 1))
+            {
+                if (++ones >= 5)
+                {
+                    ones = 0;
+                    stuffed++;
+                }
+            }
+            else
+            {
+                ones = 0;
+            }
+            bitstream >>= 1;
+        }
+    }
+    /* The total length of the frame is:
+          the number of bits in the body
+        + the number of additional bits in the body due to stuffing
+        + the number of bits in the CRC
+        + the number of additional bits in the CRC due to stuffing
+        + 16 bits for the two terminating flag octets.
+       Lets just allow 3 bits for the CRC, which is the worst case. It
+       avoids calculating the real CRC, and the worst it can do is cause
+       a flag octet's worth of additional output.
+    */
+    return stuffed + 16 + 3 + 16;
+}
+/*- End of function --------------------------------------------------------*/
+
 static int process_rx_missing(t38_core_state_t *t, void *user_data, int rx_seq_no, int expected_seq_no)
 {
     t31_state_t *s;
     
     s = (t31_state_t *) user_data;
-    s->t38_fe.missing_data = TRUE;
+    s->t38_fe.rx_data_missing = TRUE;
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
@@ -170,15 +293,20 @@
 {
     t31_state_t *s;
     t31_t38_front_end_state_t *fe;
-    
+
     s = (t31_state_t *) user_data;
     fe = &s->t38_fe;
 
     if (t->current_rx_indicator == indicator)
     {
-        /* This is probably due to the far end repeating itself. Ignore it. Its harmless */
+        /* This is probably due to the far end repeating itself, or slipping
+           preamble messages in between HDLC frames. T.38/V.1.3 tells us to
+           ignore it. Its harmless. */
         return 0;
     }
+    /* In termination mode we don't care very much about indicators telling us training
+       is starting. We only care about V.21 preamble starting, for timeout control, and
+       the actual data. */
     switch (indicator)
     {
     case T38_IND_NO_SIGNAL:
@@ -186,19 +314,22 @@
             &&
             (fe->current_rx_type == T30_MODEM_V21  ||  fe->current_rx_type == T30_MODEM_CNG))
         {
-            /* TODO: report carrier down */
+            hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
         }
         fe->timeout_rx_samples = 0;
-        /* TODO: report end of signal */
+        front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
         break;
     case T38_IND_CNG:
+        front_end_status(s, T30_FRONT_END_CNG_PRESENT);
         break;
     case T38_IND_CED:
+        front_end_status(s, T30_FRONT_END_CED_PRESENT);
         break;
     case T38_IND_V21_PREAMBLE:
-        /* Some people pop these preamble indicators between HDLC frames, so we need to be tolerant of that. */
+        /* Some T.38 implementations insert these preamble indicators between HDLC frames, so
+           we need to be tolerant of that. */
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-        /* TODO: report signal present */
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     case T38_IND_V27TER_2400_TRAINING:
     case T38_IND_V27TER_4800_TRAINING:
@@ -214,22 +345,25 @@
     case T38_IND_V17_14400_LONG_TRAINING:
     case T38_IND_V33_12000_TRAINING:
     case T38_IND_V33_14400_TRAINING:
+        /* We really don't care what kind of modem is delivering the following image data.
+           We only care that some kind of fast modem signal is coming next. */
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-        /* TODO: report signal present */
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     case T38_IND_V8_ANSAM:
     case T38_IND_V8_SIGNAL:
     case T38_IND_V34_CNTL_CHANNEL_1200:
     case T38_IND_V34_PRI_CHANNEL:
     case T38_IND_V34_CC_RETRAIN:
-        /* TODO: report signal present */
+        /* V.34 support is a work in progress. */
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     default:
-        /* TODO: report end of signal */
+        front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
         break;
     }
     fe->hdlc_rx.len = 0;
-    fe->missing_data = FALSE;
+    fe->rx_data_missing = FALSE;
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
@@ -247,6 +381,7 @@
     s = (t31_state_t *) user_data;
     fe = &s->t38_fe;
 #if 0
+    /* In termination mode we don't care very much what the data type is. */
     switch (data_type)
     {
     case T38_DATA_V21:
@@ -277,13 +412,13 @@
                there is zero packet lost. Nasty, but true. Its a good idea to be tolerant of
                loss, though, so accepting a sudden start of HDLC data is the right thing to do. */
             fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-            /* TODO: report signal present */
+            front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
             /* All real HDLC messages in the FAX world start with 0xFF. If this one is not starting
                with 0xFF it would appear some octets must have been missed before this one. */
-            if (buf[0] != 0xFF)
-                fe->missing_data = TRUE;
+            if (len <= 0  ||  buf[0] != 0xFF)
+                fe->rx_data_missing = TRUE;
         }
-        if (fe->hdlc_rx.len + len <= T31_T38_MAX_HDLC_LEN)
+        if (len > 0  &&  fe->hdlc_rx.len + len <= T31_T38_MAX_HDLC_LEN)
         {
             bit_reverse(fe->hdlc_rx.buf + fe->hdlc_rx.len, buf, len);
             fe->hdlc_rx.len += len;
@@ -302,11 +437,13 @@
            of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
-            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->missing_data)  ?  "missing octets"  :  "clean");
-            hdlc_accept((void *) s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->missing_data);
+            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
+            crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
         }
         fe->hdlc_rx.len = 0;
-        fe->missing_data = FALSE;
+        fe->rx_data_missing = FALSE;
+        fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
         break;
     case T38_FIELD_HDLC_FCS_BAD:
         if (len > 0)
@@ -320,11 +457,12 @@
            of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
-            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->missing_data)  ?  "missing octets"  :  "clean");
-            hdlc_accept((void *) s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
+            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
         }
         fe->hdlc_rx.len = 0;
-        fe->missing_data = FALSE;
+        fe->rx_data_missing = FALSE;
+        fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
         break;
     case T38_FIELD_HDLC_FCS_OK_SIG_END:
         if (len > 0)
@@ -333,47 +471,75 @@
             /* The sender has incorrectly included data in this message. It is unclear what we should do
                with it, to maximise tolerance of buggy implementations. */
         }
-        span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK, sig end (%s)\n", t30_frametype(s->tx.data[2]), (fe->missing_data)  ?  "missing octets"  :  "clean");
-        if (fe->current_rx_type == T31_V21_RX)
+        /* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_OK_SIG_END messages, in IFP packets with
+           incrementing sequence numbers, which are actually repeats. They get through to this point because
+           of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
+        if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
-            /* Don't deal with zero length frames. Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_OK
-               packets, when they have sent no data for the body of the frame. */
-            if (s->tx.out_bytes > 0)
-                hdlc_accept((void *) s, fe->hdlc_rx.buf, fe->hdlc_rx.len, TRUE);
-            hdlc_accept((void *) s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
+            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK, sig end (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
+            crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
+            hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
         }
-        s->tx.out_bytes = 0;
-        fe->missing_data = FALSE;
         fe->hdlc_rx.len = 0;
+        fe->rx_data_missing = FALSE;
+        fe->timeout_rx_samples = 0;
         break;
     case T38_FIELD_HDLC_FCS_BAD_SIG_END:
         if (len > 0)
+        {
             span_log(&s->logging, SPAN_LOG_WARNING, "There is data in a T38_FIELD_HDLC_FCS_BAD_SIG_END!\n");
-        span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad, sig end (%s)\n", t30_frametype(s->tx.data[2]), (fe->missing_data)  ?  "missing octets"  :  "clean");
-        if (fe->current_rx_type == T31_V21_RX)
-            hdlc_accept((void *) s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
+            /* The sender has incorrectly included data in this message. We can safely ignore it, as the
+               bad FCS means we will throw away the whole message, anyway. */
+        }
+        /* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_BAD_SIG_END messages, in IFP packets with
+           incrementing sequence numbers, which are actually repeats. They get through to this point because
+           of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
+        if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
+        {
+            span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad, sig end (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
+            hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
+        }
         fe->hdlc_rx.len = 0;
-        fe->missing_data = FALSE;
+        fe->rx_data_missing = FALSE;
+        fe->timeout_rx_samples = 0;
         break;
     case T38_FIELD_HDLC_SIG_END:
         if (len > 0)
+        {
             span_log(&s->logging, SPAN_LOG_WARNING, "There is data in a T38_FIELD_HDLC_SIG_END!\n");
-        /* This message is expected under 2 circumstances. One is as an alternative to T38_FIELD_HDLC_FCS_OK_SIG_END - 
-           i.e. they send T38_FIELD_HDLC_FCS_OK, and then T38_FIELD_HDLC_SIG_END when the carrier actually drops.
-           The other is because the HDLC signal drops unexpectedly - i.e. not just after a final frame. */
-        if (fe->current_rx_type == T31_V21_RX)
-            hdlc_accept((void *) s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
-        fe->hdlc_rx.len = 0;
-        fe->missing_data = FALSE;
+            /* The sender has incorrectly included data in this message, but there seems nothing meaningful
+               it could be. There could not be an FCS good/bad report beyond this. */
+        }
+        /* Some T.38 implementations send multiple T38_FIELD_HDLC_SIG_END messages, in IFP packets with
+           incrementing sequence numbers, which are actually repeats. They get through to this point because
+           of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
+        if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
+        {
+            /* WORKAROUND: At least some Mediatrix boxes have a bug, where they can send this message at the
+                           end of non-ECM data. We need to tolerate this. We use the generic receive complete
+                           indication, rather than the specific HDLC carrier down. */
+            /* This message is expected under 2 circumstances. One is as an alternative to T38_FIELD_HDLC_FCS_OK_SIG_END - 
+               i.e. they send T38_FIELD_HDLC_FCS_OK, and then T38_FIELD_HDLC_SIG_END when the carrier actually drops.
+               The other is because the HDLC signal drops unexpectedly - i.e. not just after a final frame. */
+            fe->hdlc_rx.len = 0;
+            fe->rx_data_missing = FALSE;
+            fe->timeout_rx_samples = 0;
+            hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
+        }
         break;
     case T38_FIELD_T4_NON_ECM_DATA:
         if (!s->at_state.rx_signal_present)
         {
-            /* TODO: report training succeeded */
+            non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED);
             s->at_state.rx_signal_present = TRUE;
         }
-        bit_reverse(buf2, buf, len);
-        /* TODO: put the chunk */
+        if (len > 0)
+        {
+            bit_reverse(buf2, buf, len);
+            non_ecm_put_chunk(s, buf, len);
+        }
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
         break;
     case T38_FIELD_T4_NON_ECM_SIG_END:
@@ -386,25 +552,50 @@
             {
                 if (!s->at_state.rx_signal_present)
                 {
-                    /* TODO: report training succeeded */
+                    non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED);
                     s->at_state.rx_signal_present = TRUE;
                 }
                 bit_reverse(buf2, buf, len);
-                /* TODO: put the chunk */
+                non_ecm_put_chunk(s, buf, len);
             }
             /* WORKAROUND: At least some Mediatrix boxes have a bug, where they can send HDLC signal end where
                            they should send non-ECM signal end. It is possible they also do the opposite.
                            We need to tolerate this, so we use the generic receive complete
                            indication, rather than the specific non-ECM carrier down. */
-            /* TODO: report receive complete */
+            non_ecm_rx_status(s, SIG_STATUS_CARRIER_DOWN);
         }
         s->at_state.rx_signal_present = FALSE;
         fe->timeout_rx_samples = 0;
         break;
     case T38_FIELD_CM_MESSAGE:
+        if (len >= 1)
+            span_log(&s->logging, SPAN_LOG_FLOW, "CM profile %d - %s\n", buf[0] - '0', t38_cm_profile_to_str(buf[0]));
+        else
+            span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CM message - %d\n", len);
+        break;
     case T38_FIELD_JM_MESSAGE:
+        if (len >= 2)
+            span_log(&s->logging, SPAN_LOG_FLOW, "JM - %s\n", t38_jm_to_str(buf, len));
+        else
+            span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for JM message - %d\n", len);
+        break;
     case T38_FIELD_CI_MESSAGE:
+        if (len >= 1)
+            span_log(&s->logging, SPAN_LOG_FLOW, "CI 0x%X\n", buf[0]);
+        else
+            span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CI message - %d\n", len);
+        break;
     case T38_FIELD_V34RATE:
+        if (len >= 3)
+        {
+            fe->t38.v34_rate = t38_v34rate_to_bps(buf, len);
+            span_log(&s->logging, SPAN_LOG_FLOW, "V.34 rate %d bps\n", fe->t38.v34_rate);
+        }
+        else
+        {
+            span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for V34rate message - %d\n", len);
+        }
+        break;
     default:
         break;
     }
@@ -412,248 +603,378 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-int t31_t38_send_timeout(t31_state_t *s, int samples)
+static void send_hdlc(void *user_data, const uint8_t *msg, int len)
 {
-    int len;
-    int i;
-    int previous;
-    uint8_t buf[MAX_OCTETS_PER_UNPACED_CHUNK + 50];
-    t31_t38_front_end_state_t *fe;
-    t38_data_field_t data_fields[2];
-    /* The times for training, the optional TEP, and the HDLC preamble, for all the modem options, in ms.
-       Note that the preamble for V.21 is 1s+-15%, and for the other modems is 200ms+100ms. */
-    static const struct
-    {
-        int tep;
-        int training;
-        int flags;
-    } startup_time[] =
-    {
-        {   0,    0,    0},     /* T38_IND_NO_SIGNAL */
-        {   0,    0,    0},     /* T38_IND_CNG */
-        {   0,    0,    0},     /* T38_IND_CED */
-        {   0,    0, 1000},     /* T38_IND_V21_PREAMBLE */ /* TODO: 850ms should be OK for this, but it causes trouble with some ATAs. Why? */
-        { 215,  943,  200},     /* T38_IND_V27TER_2400_TRAINING */
-        { 215,  708,  200},     /* T38_IND_V27TER_4800_TRAINING */
-        { 215,  234,  200},     /* T38_IND_V29_7200_TRAINING */
-        { 215,  234,  200},     /* T38_IND_V29_9600_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_7200_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_7200_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_9600_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_9600_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_12000_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_12000_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_14400_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_14400_LONG_TRAINING */
-        { 215,    0,    0},     /* T38_IND_V8_ANSAM */
-        { 215,    0,    0},     /* T38_IND_V8_SIGNAL */
-        { 215,    0,    0},     /* T38_IND_V34_CNTL_CHANNEL_1200 */
-        { 215,    0,    0},     /* T38_IND_V34_PRI_CHANNEL */
-        { 215,    0,    0},     /* T38_IND_V34_CC_RETRAIN */
-        { 215,    0,    0},     /* T38_IND_V33_12000_TRAINING */
-        { 215,    0,    0}      /* T38_IND_V33_14400_TRAINING */
-    };
+    t31_state_t *s;
 
-    fe = &s->t38_fe;
-    if (fe->current_rx_type == T30_MODEM_DONE  ||  fe->current_tx_type == T30_MODEM_DONE)
-        return TRUE;
+    s = (t31_state_t *) user_data;
+    if (len <= 0)
+    {
+        s->hdlc_tx.len = -1;
+    }
+    else
+    {
+        s->t38_fe.hdlc_tx.extra_bits = extra_bits_in_stuffed_frame(msg, len);
+        bit_reverse(s->hdlc_tx.buf, msg, len);
+        s->hdlc_tx.len = len;
+        s->hdlc_tx.ptr = 0;
+    }
+}
+/*- End of function --------------------------------------------------------*/
 
-    fe->samples += samples;
-    if (fe->timeout_rx_samples  &&  fe->samples > fe->timeout_rx_samples)
+static __inline__ int bits_to_us(t31_state_t *s, int bits)
+{
+    if (s->t38_fe.ms_per_tx_chunk == 0)
+        return 0;
+    return bits*1000000/s->t38_fe.tx_bit_rate;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void set_octets_per_data_packet(t31_state_t *s, int bit_rate)
+{
+    s->t38_fe.tx_bit_rate = bit_rate;
+    if (s->t38_fe.ms_per_tx_chunk == 0)
     {
-        span_log(&s->logging, SPAN_LOG_FLOW, "Timeout mid-receive\n");
-        fe->timeout_rx_samples = 0;
-        /* TODO: report completion */
+        s->t38_fe.octets_per_data_packet = MAX_OCTETS_PER_UNPACED_CHUNK;
     }
-    if (fe->timed_step == T38_TIMED_STEP_NONE)
-        return FALSE;
-    if (fe->samples < fe->next_tx_samples)
-        return FALSE;
-    /* Its time to send something */
-    switch (fe->timed_step)
+    else
     {
-    case T38_TIMED_STEP_NON_ECM_MODEM:
-        /* Create a 75ms silence */
-        if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
-            t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2;
-        fe->next_tx_samples += ms_to_samples(75);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_2:
-        /* Switch on a fast modem, and give the training time to complete */
-        t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3;
-        fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].training);
-        if (s->audio.modems.use_tep)
-            fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].tep);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_3:
-        /* Send a chunk of non-ECM image data */
-        /* T.38 says it is OK to send the last of the non-ECM data in the signal end message.
-           However, I think the early versions of T.38 said the signal end message should not
-           contain data. Hopefully, following the current spec will not cause compatibility
-           issues. */
-        /* Get a chunk of data */
-        len = fe->octets_per_data_packet;
-        bit_reverse(buf, buf, len);
-        if (len < fe->octets_per_data_packet)
-        {
-            /* That's the end of the image data. Do a little padding now */
-            memset(buf + len, 0, fe->octets_per_data_packet - len);
-            fe->trailer_bytes = 3*fe->octets_per_data_packet + len;
-            len = fe->octets_per_data_packet;
-            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_4;
-        }
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, DATA_TX_COUNT);
-        fe->next_tx_samples += ms_to_samples(fe->ms_per_tx_chunk);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_4:
-        /* This pads the end of the data with some zeros. If we just stop abruptly
-           at the end of the EOLs, some ATAs fail to clean up properly before
-           shutting down their transmit modem, and the last few rows of the image
-           get corrupted. Simply delaying the no-signal message does not help for
-           all implentations. It often appears to be ignored. */
-        len = fe->octets_per_data_packet;
-        fe->trailer_bytes -= len;
-        if (fe->trailer_bytes <= 0)
+        s->t38_fe.octets_per_data_packet = s->t38_fe.ms_per_tx_chunk*bit_rate/(8*1000);
+        /* Make sure we have a positive number (i.e. we didn't truncate to zero). */
+        if (s->t38_fe.octets_per_data_packet < 1)
+            s->t38_fe.octets_per_data_packet = 1;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_non_ecm(t31_state_t *s)
+{
+    t31_t38_front_end_state_t *fe;
+    uint8_t buf[MAX_OCTETS_PER_UNPACED_CHUNK + 50];
+    int delay;
+    int len;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
         {
-            len += fe->trailer_bytes;
+        case T38_TIMED_STEP_NON_ECM_MODEM:
+            /* Create a 75ms silence */
+            if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
+                delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_2:
+            /* Switch on a fast modem, and give the training time to complete */
+            delay = t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3;
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_3:
+            /* Send a chunk of non-ECM image data */
+            /* T.38 says it is OK to send the last of the non-ECM data in the signal end message.
+               However, I think the early versions of T.38 said the signal end message should not
+               contain data. Hopefully, following the current spec will not cause compatibility
+               issues. */
+            len = non_ecm_get_chunk(s, buf, fe->octets_per_data_packet);
+            if (len > 0)
+                bit_reverse(buf, buf, len);
+            if (len < fe->octets_per_data_packet)
+            {
+                /* That's the end of the image data. Do a little padding now */
+                memset(buf + len, 0, fe->octets_per_data_packet - len);
+                fe->non_ecm_trailer_bytes = 3*fe->octets_per_data_packet + len;
+                len = fe->octets_per_data_packet;
+                fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_4;
+            }
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
+            delay = bits_to_us(s, 8*len);
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_4:
+            /* This pads the end of the data with some zeros. If we just stop abruptly
+               at the end of the EOLs, some ATAs fail to clean up properly before
+               shutting down their transmit modem, and the last few rows of the image
+               are corrupted. Simply delaying the no-signal message does not help for
+               all implentations. It is usually ignored, which is probably the right
+               thing to do after receiving a message saying the signal has ended. */
+            len = fe->octets_per_data_packet;
+            fe->non_ecm_trailer_bytes -= len;
+            if (fe->non_ecm_trailer_bytes <= 0)
+            {
+                len += fe->non_ecm_trailer_bytes;
+                memset(buf, 0, len);
+                t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, buf, len, fe->t38.data_end_tx_count);
+                fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
+                /* Allow a bit more time than the data will take to play out, to ensure the far ATA does not
+                   cut things short. */
+                delay = bits_to_us(s, 8*len) + 60000;
+                front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                break;
+            }
             memset(buf, 0, len);
-            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, buf, len, fe->data_end_tx_count);
-            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
-            fe->next_tx_samples += ms_to_samples(60);
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
+            delay = bits_to_us(s, 8*len);
             break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_5:
+            /* This should not be needed, since the message above indicates the end of the signal, but it
+               seems like it can improve compatibility with quirky implementations. */
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            return delay;
         }
-        memset(buf, 0, len);
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, DATA_TX_COUNT);
-        fe->next_tx_samples += ms_to_samples(fe->ms_per_tx_chunk);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_5:
-        /* This should not be needed, since the message above indicates the end of the signal, but it
-           seems like it can improve compatibility with quirky implementations. */
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NONE;
-        /* TODO: report send complete */
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM:
-        /* Send HDLC preambling */
-        t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
-        fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].training + startup_time[fe->next_tx_indicator].flags);
-        if (s->audio.modems.use_tep)
-            fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].tep);
-        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM_2:
-        /* Send a chunk of HDLC data */
-        i = s->hdlc_tx.len - s->hdlc_tx.ptr;
-        if (fe->octets_per_data_packet >= i)
-        {
-            /* The last part of the HDLC frame */
-            if (fe->merge_tx_fields)
-            {
-                /* Copy the data, as we might be about to refill the buffer it is in */
-                memcpy(buf, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i);
-                data_fields[0].field_type = T38_FIELD_HDLC_DATA;
-                data_fields[0].field = buf;
-                data_fields[0].field_len = i;
-
-                /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
-                previous = fe->current_tx_data_type;
-                s->hdlc_tx.ptr = 0;
-                s->hdlc_tx.len = 0;
-                /* TODO: report completion */
-                /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
-                if (s->hdlc_tx.len < 0)
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_hdlc(t31_state_t *s)
+{
+    t31_t38_front_end_state_t *fe;
+    uint8_t buf[MAX_OCTETS_PER_UNPACED_CHUNK + 50];
+    t38_data_field_t data_fields[2];
+    int previous;
+    int delay;
+    int i;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_HDLC_MODEM:
+            /* Create a 75ms silence */
+            if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
+                delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
+            fe->next_tx_samples = fe->samples + ms_to_samples(75);
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_2:
+            /* Send HDLC preambling */
+            delay = t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
+            delay += t38_core_send_flags_delay(&fe->t38, fe->next_tx_indicator);
+            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_3:
+            /* Send a chunk of HDLC data */
+            if (s->hdlc_tx.len == 0)
+            {
+                /* We don't have a frame ready yet, so wait a little */
+                delay = MS_PER_TX_CHUNK*1000;
+                break;
+            }
+            i = s->hdlc_tx.len - s->hdlc_tx.ptr;
+            if (fe->octets_per_data_packet >= i)
+            {
+                /* The last part of an HDLC frame */
+                if (fe->chunking_modes & T38_CHUNKING_MERGE_FCS_WITH_DATA)
                 {
-                    data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END;
-                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
+                    /* Copy the data, as we might be about to refill the buffer it is in */
+                    memcpy(buf, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i);
+                    data_fields[0].field_type = T38_FIELD_HDLC_DATA;
+                    data_fields[0].field = buf;
+                    data_fields[0].field_len = i;
+
+                    /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
+                    previous = fe->current_tx_data_type;
+                    s->hdlc_tx.ptr = 0;
+                    s->hdlc_tx.len = 0;
+                    front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                    if (s->hdlc_tx.final)
+                    {
+                        data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END;
+                        data_fields[1].field = NULL;
+                        data_fields[1].field_len = 0;
+                        t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, fe->t38.data_tx_count);
+                        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
+                        /* We add a bit of extra time here, as with some implementations
+                           the carrier falling too abruptly causes data loss. */
+                        delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits) + 100000;
+                        at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
+                        t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
+                    }
+                    else
+                    {
+                        data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK;
+                        data_fields[1].field = NULL;
+                        data_fields[1].field_len = 0;
+                        t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, fe->t38.data_tx_count);
+                        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+                        delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits);
+                        at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
+                    }
                 }
                 else
                 {
-                    data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK;
-                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
+                    t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, fe->t38.data_tx_count);
+                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
+                    delay = bits_to_us(s, i*8);
                 }
-                data_fields[1].field = NULL;
-                data_fields[1].field_len = 0;
-                t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, DATA_TX_COUNT);
+                break;
             }
-            else
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], fe->octets_per_data_packet, fe->t38.data_tx_count);
+            s->hdlc_tx.ptr += fe->octets_per_data_packet;
+            delay = bits_to_us(s, fe->octets_per_data_packet*8);
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_4:
+            /* End of HDLC frame */
+            previous = fe->current_tx_data_type;
+            s->hdlc_tx.ptr = 0;
+            s->hdlc_tx.len = 0;
+            if (s->hdlc_tx.final)
             {
-                t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, DATA_TX_COUNT);
-                fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+                /* End of transmission */
+                s->hdlc_tx.len = 0;
+                s->hdlc_tx.final = FALSE;
+                t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, fe->t38.data_tx_count);
+                fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
+                /* We add a bit of extra time here, as with some implementations
+                   the carrier falling too abruptly causes data loss. */
+                delay = bits_to_us(s, fe->hdlc_tx.extra_bits) + 100000;
+                front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                break;
             }
-            fe->next_tx_samples += ms_to_samples(fe->ms_per_tx_chunk);
+            /* Finish the current frame off, and prepare for the next one. */
+            t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, fe->t38.data_tx_count);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
+            /* We should now wait enough time for everything to clear through an analogue modem at the far end. */
+            delay = bits_to_us(s, fe->hdlc_tx.extra_bits);
+            if (s->hdlc_tx.len == 0)
+                span_log(&s->logging, SPAN_LOG_FLOW, "No new frame or end transmission condition.\n");
             break;
+        case T38_TIMED_STEP_HDLC_MODEM_5:
+            /* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point.
+               A T38_IND_NO_SIGNAL should always be OK. */
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_SIG_END, NULL, 0, fe->t38.data_end_tx_count);
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
+            t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
+            return 0;
         }
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], fe->octets_per_data_packet, DATA_TX_COUNT);
-        s->hdlc_tx.ptr += fe->octets_per_data_packet;
-        fe->next_tx_samples += ms_to_samples(fe->ms_per_tx_chunk);
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM_3:
-        /* End of HDLC frame */
-        previous = fe->current_tx_data_type;
-        s->hdlc_tx.ptr = 0;
-        s->hdlc_tx.len = 0;
-        /* TODO: report completion */
-        /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
-        if (s->hdlc_tx.len < 0)
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_ced(t31_state_t *s)
+{
+    t31_t38_front_end_state_t *fe;
+    int delay;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
         {
-            t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK_SIG_END, NULL, 0, fe->data_end_tx_count);
-            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
-            fe->next_tx_samples += ms_to_samples(100);
+        case T38_TIMED_STEP_CED:
+            /* It seems common practice to start with a no signal indicator, though
+               this is not a specified requirement. Since we should be sending 200ms
+               of silence, starting the delay with a no signal indication makes sense.
+               We do need a 200ms delay, as that is a specification requirement. */
+            fe->timed_step = T38_TIMED_STEP_CED_2;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            delay = 200000;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_CED_2:
+            /* Initial 200ms delay over. Send the CED indicator */
+            fe->timed_step = T38_TIMED_STEP_CED_3;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_CED, fe->t38.indicator_tx_count);
+            fe->current_tx_data_type = T38_DATA_NONE;
             break;
+        case T38_TIMED_STEP_CED_3:
+            /* End of CED */
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+            return 0;
         }
-        t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, DATA_TX_COUNT);
-        if (s->hdlc_tx.len)
-            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
-        fe->next_tx_samples += ms_to_samples(fe->ms_per_tx_chunk);
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_cng(t31_state_t *s)
+{
+    t31_t38_front_end_state_t *fe;
+    int delay;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_CNG:
+            /* It seems common practice to start with a no signal indicator, though
+               this is not a specified requirement of the T.38 spec. Since we should
+               be sending 200ms of silence, according to T.30, starting that delay with
+               a no signal indication makes sense. */
+            fe->timed_step = T38_TIMED_STEP_CNG_2;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            delay = 200000;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_CNG_2:
+            /* Initial short delay over. Send the CNG indicator. CNG persists until something
+               coming the other way interrupts it, or a long timeout controlled by the T.30 engine
+               expires. */
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_CNG, fe->t38.indicator_tx_count);
+            fe->current_tx_data_type = T38_DATA_NONE;
+            return delay;
+        }
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+int t31_t38_send_timeout(t31_state_t *s, int samples)
+{
+    t31_t38_front_end_state_t *fe;
+    int delay;
+
+    fe = &s->t38_fe;
+    if (fe->current_rx_type == T30_MODEM_DONE  ||  fe->current_tx_type == T30_MODEM_DONE)
+        return TRUE;
+
+    fe->samples += samples;
+    if (fe->timeout_rx_samples  &&  fe->samples > fe->timeout_rx_samples)
+    {
+        span_log(&s->logging, SPAN_LOG_FLOW, "Timeout mid-receive\n");
+        fe->timeout_rx_samples = 0;
+        front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE);
+    }
+    if (fe->timed_step == T38_TIMED_STEP_NONE)
+        return FALSE;
+    /* Wait until the right time comes along, unless we are working in "no delays" mode, while talking to an
+       IAF terminal. */
+    if (fe->ms_per_tx_chunk  &&  fe->samples < fe->next_tx_samples)
+        return FALSE;
+    /* Its time to send something */
+    delay = 0;
+    switch (fe->timed_step & 0xFFF0)
+    {
+    case T38_TIMED_STEP_NON_ECM_MODEM:
+        delay = stream_non_ecm(s);
         break;
-    case T38_TIMED_STEP_HDLC_MODEM_4:
-        /* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point.
-           A T38_IND_NO_SIGNAL should always be OK. */
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        s->hdlc_tx.len = 0;
-        //t30_front_end_status(&(s->t30), T30_FRONT_END_SEND_STEP_COMPLETE);
+    case T38_TIMED_STEP_HDLC_MODEM:
+        delay = stream_hdlc(s);
         break;
     case T38_TIMED_STEP_CED:
-        /* It seems common practice to start with a no signal indicator, though
-           this is not a specified requirement. Since we should be sending 200ms
-           of silence, starting the delay with a no signal indication makes sense.
-           We do need a 200ms delay, as that is a specification requirement. */
-        fe->timed_step = T38_TIMED_STEP_CED_2;
-        fe->next_tx_samples = fe->samples + ms_to_samples(200);
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
-        break;
-    case T38_TIMED_STEP_CED_2:
-        /* Initial 200ms delay over. Send the CED indicator */
-        fe->next_tx_samples = fe->samples + ms_to_samples(3000);
-        fe->timed_step = T38_TIMED_STEP_PAUSE;
-        t38_core_send_indicator(&fe->t38, T38_IND_CED, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
+        delay = stream_ced(s);
         break;
     case T38_TIMED_STEP_CNG:
-        /* It seems common practice to start with a no signal indicator, though
-           this is not a specified requirement. Since we should be sending 200ms
-           of silence, starting the delay with a no signal indication makes sense.
-           We do need a 200ms delay, as that is a specification requirement. */
-        fe->timed_step = T38_TIMED_STEP_CNG_2;
-        fe->next_tx_samples = fe->samples + ms_to_samples(200);
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
-        break;
-    case T38_TIMED_STEP_CNG_2:
-        /* Initial short delay over. Send the CNG indicator */
-        fe->timed_step = T38_TIMED_STEP_NONE;
-        t38_core_send_indicator(&fe->t38, T38_IND_CNG, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
+        delay = stream_cng(s);
         break;
     case T38_TIMED_STEP_PAUSE:
         /* End of timed pause */
         fe->timed_step = T38_TIMED_STEP_NONE;
-        //t30_front_end_status(&(s->t30), T30_FRONT_END_SEND_STEP_COMPLETE);
+        front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
         break;
     }
+    fe->next_tx_samples += us_to_samples(delay);
     return FALSE;
 }
 /*- End of function --------------------------------------------------------*/
@@ -682,7 +1003,10 @@
         {
             t->at_state.rx_data[t->at_state.rx_data_bytes++] = DLE;
             t->at_state.rx_data[t->at_state.rx_data_bytes++] = ETX;
-            t->at_state.at_tx_handler(&t->at_state, t->at_state.at_tx_user_data, t->at_state.rx_data, t->at_state.rx_data_bytes);
+            t->at_state.at_tx_handler(&t->at_state,
+                                      t->at_state.at_tx_user_data,
+                                      t->at_state.rx_data,
+                                      t->at_state.rx_data_bytes);
             t->at_state.rx_data_bytes = 0;
         }
         restart_modem(t, T31_SILENCE_TX);
@@ -726,7 +1050,10 @@
         {
             s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
             s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
-            s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
+            s->at_state.at_tx_handler(&s->at_state,
+                                      s->at_state.at_tx_user_data,
+                                      s->at_state.rx_data,
+                                      s->at_state.rx_data_bytes);
             s->at_state.rx_data_bytes = 0;
             at_put_response_code(&s->at_state, AT_RESPONSE_CODE_NO_CARRIER);
             t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
@@ -760,7 +1087,10 @@
         s->at_state.rx_data[s->at_state.rx_data_bytes++] = (uint8_t) s->audio.current_byte;
         if (s->at_state.rx_data_bytes >= 250)
         {
-            s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
+            s->at_state.at_tx_handler(&s->at_state,
+                                      s->at_state.at_tx_user_data,
+                                      s->at_state.rx_data,
+                                      s->at_state.rx_data_bytes);
             s->at_state.rx_data_bytes = 0;
         }
         s->audio.bit_no = 0;
@@ -769,6 +1099,32 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+static void non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len)
+{
+    t31_state_t *s;
+    int i;
+
+    s = (t31_state_t *) user_data;
+    /* Ignore any fractional bytes which may have accumulated */
+    for (i = 0;  i < len;  i++)
+    {
+        if (buf[i] == DLE)
+            s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
+        s->at_state.rx_data[s->at_state.rx_data_bytes++] = buf[i];
+        if (s->at_state.rx_data_bytes >= 250)
+        {
+            s->at_state.at_tx_handler(&s->at_state,
+                                      s->at_state.at_tx_user_data,
+                                      s->at_state.rx_data,
+                                      s->at_state.rx_data_bytes);
+            s->at_state.rx_data_bytes = 0;
+        }
+    }
+    s->audio.bit_no = 0;
+    s->audio.current_byte = 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 static int non_ecm_get_bit(void *user_data)
 {
     t31_state_t *s;
@@ -784,12 +1140,13 @@
             if (s->tx.out_bytes > T31_TX_BUF_LEN - 1)
             {
                 s->tx.out_bytes = T31_TX_BUF_LEN - 1;
-                fprintf(stderr, "End of transmit buffer reached!\n");
+                span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n");
             }
             if (s->tx.holding)
             {
-                /* See if the buffer is approaching empty. It might be time to release flow control. */
-                if (s->tx.out_bytes > 1024)
+                /* See if the buffer is approaching empty. It might be time to
+                   release flow control. */
+                if (s->tx.out_bytes > T31_TX_BUF_LOW_TIDE)
                 {
                     s->tx.holding = FALSE;
                     /* Tell the application to release further data */
@@ -820,6 +1177,56 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+static int non_ecm_get_chunk(void *user_data, uint8_t buf[], int len)
+{
+    t31_state_t *s;
+    int i;
+
+    s = (t31_state_t *) user_data;
+    for (i = 0;  i < len;  i++)
+    {
+        if (s->tx.out_bytes != s->tx.in_bytes)
+        {
+            /* There is real data available to send */
+            buf[i] = s->tx.data[s->tx.out_bytes++];
+            if (s->tx.out_bytes > T31_TX_BUF_LEN - 1)
+            {
+                s->tx.out_bytes = T31_TX_BUF_LEN - 1;
+                span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n");
+            }
+            if (s->tx.holding)
+            {
+                /* See if the buffer is approaching empty. It might be time to release flow control. */
+                if (s->tx.out_bytes > T31_TX_BUF_LOW_TIDE)
+                {
+                    s->tx.holding = FALSE;
+                    /* Tell the application to release further data */
+                    at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
+                }
+            }
+            s->tx.data_started = TRUE;
+        }
+        else
+        {
+            if (s->tx.final)
+            {
+                s->tx.final = FALSE;
+                /* This will put the modem into its shutdown sequence. When
+                   it has finally shut down, an OK response will be sent. */
+                //return SIG_STATUS_END_OF_DATA;
+                return i;
+            }
+            /* Fill with 0xFF bytes at the start of transmission, or 0x00 if we are in
+               the middle of transmission. This follows T.31 and T.30 practice. */
+            buf[i] = (s->tx.data_started)  ?  0x00  :  0xFF;
+        }
+    }
+    s->audio.bit_no = 0;
+    s->audio.current_byte = 0;
+    return len;
+}
+/*- End of function --------------------------------------------------------*/
+
 static void tone_detected(void *user_data, int on, int level, int delay)
 {
     t31_state_t *s;
@@ -958,7 +1365,7 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-static void hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok)
+static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ok)
 {
     t31_state_t *s;
     uint8_t buf[256];
@@ -1031,7 +1438,7 @@
 
 static void t31_v21_rx(t31_state_t *s)
 {
-    hdlc_rx_init(&(s->audio.modems.hdlc_rx), FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept, s);
+    hdlc_rx_init(&(s->audio.modems.hdlc_rx), FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, s);
     s->at_state.ok_is_pending = FALSE;
     s->hdlc_tx.final = FALSE;
     s->hdlc_tx.len = 0;
@@ -1044,7 +1451,7 @@
 
 static int restart_modem(t31_state_t *s, int new_modem)
 {
-    int ind;
+    int use_hdlc;
     fax_modems_state_t *t;
 
     t = &s->audio.modems;
@@ -1059,12 +1466,15 @@
     s->rx_frame_received = FALSE;
     t->rx_handler = (span_rx_handler_t *) &span_dummy_rx;
     t->rx_user_data = NULL;
+    use_hdlc = FALSE;
     switch (s->modem)
     {
     case T31_CNG_TONE:
         if (s->t38_mode)
         {
-            t38_core_send_indicator(&s->t38_fe.t38, T38_IND_CNG, INDICATOR_TX_COUNT);
+            s->t38_fe.next_tx_samples = s->t38_fe.samples;
+            s->t38_fe.timed_step = T38_TIMED_STEP_CNG;
+            s->t38_fe.current_tx_data_type = T38_DATA_NONE;
         }
         else
         {
@@ -1101,7 +1511,9 @@
     case T31_CED_TONE:
         if (s->t38_mode)
         {
-            t38_core_send_indicator(&s->t38_fe.t38, T38_IND_CED, INDICATOR_TX_COUNT);
+            s->t38_fe.next_tx_samples = s->t38_fe.samples;
+            s->t38_fe.timed_step = T38_TIMED_STEP_CED;
+            s->t38_fe.current_tx_data_type = T38_DATA_NONE;
         }
         else
         {
@@ -1115,7 +1527,11 @@
     case T31_V21_TX:
         if (s->t38_mode)
         {
-            t38_core_send_indicator(&s->t38_fe.t38, T38_IND_V21_PREAMBLE, INDICATOR_TX_COUNT);
+            s->t38_fe.next_tx_indicator = T38_IND_V21_PREAMBLE;
+            s->t38_fe.current_tx_data_type = T38_DATA_V21;
+            use_hdlc = TRUE;
+            s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
+            set_octets_per_data_packet(s, 300);
         }
         else
         {
@@ -1149,20 +1565,24 @@
             switch (s->bit_rate)
             {
             case 7200:
-                ind = (s->short_train)  ?  T38_IND_V17_7200_SHORT_TRAINING  :  T38_IND_V17_7200_LONG_TRAINING;
+                s->t38_fe.next_tx_indicator = (s->short_train)  ?  T38_IND_V17_7200_SHORT_TRAINING  :  T38_IND_V17_7200_LONG_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V17_7200;
                 break;
             case 9600:
-                ind = (s->short_train)  ?  T38_IND_V17_9600_SHORT_TRAINING  :  T38_IND_V17_9600_LONG_TRAINING;
+                s->t38_fe.next_tx_indicator = (s->short_train)  ?  T38_IND_V17_9600_SHORT_TRAINING  :  T38_IND_V17_9600_LONG_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V17_9600;
                 break;
             case 12000:
-                ind = (s->short_train)  ?  T38_IND_V17_12000_SHORT_TRAINING  :  T38_IND_V17_12000_LONG_TRAINING;
+                s->t38_fe.next_tx_indicator = (s->short_train)  ?  T38_IND_V17_12000_SHORT_TRAINING  :  T38_IND_V17_12000_LONG_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V17_12000;
                 break;
             case 14400:
-            default:
-                ind = (s->short_train)  ?  T38_IND_V17_14400_SHORT_TRAINING  :  T38_IND_V17_14400_LONG_TRAINING;
+                s->t38_fe.next_tx_indicator = (s->short_train)  ?  T38_IND_V17_14400_SHORT_TRAINING  :  T38_IND_V17_14400_LONG_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V17_14400;
                 break;
             }
-            t38_core_send_indicator(&s->t38_fe.t38, ind, INDICATOR_TX_COUNT);
+            set_octets_per_data_packet(s, s->bit_rate);
+            s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
         }
         else
         {
@@ -1192,14 +1612,16 @@
             switch (s->bit_rate)
             {
             case 2400:
-                ind = T38_IND_V27TER_2400_TRAINING;
+                s->t38_fe.next_tx_indicator = T38_IND_V27TER_2400_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V27TER_2400;
                 break;
             case 4800:
-            default:
-                ind = T38_IND_V27TER_4800_TRAINING;
+                s->t38_fe.next_tx_indicator = T38_IND_V27TER_4800_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V27TER_4800;
                 break;
             }
-            t38_core_send_indicator(&s->t38_fe.t38, ind, INDICATOR_TX_COUNT);
+            set_octets_per_data_packet(s, s->bit_rate);
+            s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
         }
         else
         {
@@ -1229,14 +1651,16 @@
             switch (s->bit_rate)
             {
             case 7200:
-                ind = T38_IND_V29_7200_TRAINING;
+                s->t38_fe.next_tx_indicator = T38_IND_V29_7200_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V29_7200;
                 break;
             case 9600:
-            default:
-                ind = T38_IND_V29_9600_TRAINING;
+                s->t38_fe.next_tx_indicator = T38_IND_V29_9600_TRAINING;
+                s->t38_fe.current_tx_data_type = T38_DATA_V29_9600;
                 break;
             }
-            t38_core_send_indicator(&s->t38_fe.t38, ind, INDICATOR_TX_COUNT);
+            set_octets_per_data_packet(s, s->bit_rate);
+            s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
         }
         else
         {
@@ -1264,6 +1688,9 @@
         if (s->t38_mode)
         {
             t38_core_send_indicator(&s->t38_fe.t38, T38_IND_NO_SIGNAL, INDICATOR_TX_COUNT);
+            s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(700);
+            s->t38_fe.timed_step = T38_TIMED_STEP_PAUSE;
+            s->t38_fe.current_tx_data_type = T38_DATA_NONE;
         }
         else
         {
@@ -1323,15 +1750,16 @@
             s->dled = FALSE;
             if (stuffed[i] == ETX)
             {
+                s->hdlc_tx.final = (s->hdlc_tx.buf[1] & 0x10);
                 if (s->t38_mode)
                 {
+                    send_hdlc(s, s->hdlc_tx.buf, s->hdlc_tx.len);
                 }
                 else
                 {
                     hdlc_tx_frame(&(s->audio.modems.hdlc_tx), s->hdlc_tx.buf, s->hdlc_tx.len);
+                    s->hdlc_tx.len = 0;
                 }
-                s->hdlc_tx.final = (s->hdlc_tx.buf[1] & 0x10);
-                s->hdlc_tx.len = 0;
             }
             else if (stuffed[i] == SUB)
             {
@@ -1379,14 +1807,14 @@
         if (s->tx.in_bytes > T31_TX_BUF_LEN - 1)
         {
             /* Oops. We hit the end of the buffer. Give up. Loose stuff. :-( */
-            fprintf(stderr, "No room in buffer for new data!\n");
+            span_log(&s->logging, SPAN_LOG_FLOW, "No room in buffer for new data!\n");
             return;
         }
     }
     if (!s->tx.holding)
     {
         /* See if the buffer is approaching full. We might need to apply flow control. */
-        if (s->tx.in_bytes > T31_TX_BUF_LEN - 1024)
+        if (s->tx.in_bytes > T31_TX_BUF_HIGH_TIDE)
         {
             s->tx.holding = TRUE;
             /* Tell the application to hold further data */
@@ -1417,7 +1845,10 @@
         {
             /* Send a specified period of silence, to space transmissions. */
             restart_modem(s, T31_SILENCE_TX);
-            silence_gen_alter(&(s->audio.modems.silence_gen), ms_to_samples(val*10));
+            if (s->t38_mode)
+                s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(val*10);
+            else
+                silence_gen_alter(&(s->audio.modems.silence_gen), ms_to_samples(val*10));
             s->at_state.transmit = TRUE;
         }
         else
@@ -1426,7 +1857,15 @@
             queue_flush(s->rx_queue);
             s->silence_awaited = ms_to_samples(val*10);
             t31_set_at_rx_mode(s, AT_MODE_DELIVERY);
-            restart_modem(s, T31_SILENCE_RX);
+            if (s->t38_mode)
+            {
+                at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
+                t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
+            }
+            else
+            {
+                restart_modem(s, T31_SILENCE_RX);
+            }
         }
         immediate_response = FALSE;
         span_log(&s->logging, SPAN_LOG_FLOW, "Silence %dms\n", val*10);
@@ -1452,7 +1891,8 @@
         if (new_transmit)
         {
             t31_set_at_rx_mode(s, AT_MODE_HDLC);
-            at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
+            if (!s->t38_mode)
+                at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
         }
         else
         {
@@ -1495,61 +1935,85 @@
         switch (val)
         {
         case 24:
+            s->t38_fe.next_tx_indicator = T38_IND_V27TER_2400_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V27TER_2400;
             new_modem = (new_transmit)  ?  T31_V27TER_TX  :  T31_V27TER_RX;
             s->short_train = FALSE;
             s->bit_rate = 2400;
             break;
         case 48:
+            s->t38_fe.next_tx_indicator = T38_IND_V27TER_4800_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V27TER_4800;
             new_modem = (new_transmit)  ?  T31_V27TER_TX  :  T31_V27TER_RX;
             s->short_train = FALSE;
             s->bit_rate = 4800;
             break;
         case 72:
+            s->t38_fe.next_tx_indicator = T38_IND_V29_7200_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V29_7200;
             new_modem = (new_transmit)  ?  T31_V29_TX  :  T31_V29_RX;
             s->short_train = FALSE;
             s->bit_rate = 7200;
             break;
         case 96:
+            s->t38_fe.next_tx_indicator = T38_IND_V29_9600_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V29_9600;
             new_modem = (new_transmit)  ?  T31_V29_TX  :  T31_V29_RX;
             s->short_train = FALSE;
             s->bit_rate = 9600;
             break;
         case 73:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_7200_LONG_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_7200;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = FALSE;
             s->bit_rate = 7200;
             break;
         case 74:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_7200_SHORT_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_7200;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = TRUE;
             s->bit_rate = 7200;
             break;
         case 97:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_9600_LONG_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_9600;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = FALSE;
             s->bit_rate = 9600;
             break;
         case 98:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_9600_SHORT_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_9600;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = TRUE;
             s->bit_rate = 9600;
             break;
         case 121:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_12000_LONG_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_12000;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = FALSE;
             s->bit_rate = 12000;
             break;
         case 122:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_12000_SHORT_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_12000;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = TRUE;
             s->bit_rate = 12000;
             break;
         case 145:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_14400_LONG_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_14400;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = FALSE;
             s->bit_rate = 14400;
             break;
         case 146:
+            s->t38_fe.next_tx_indicator = T38_IND_V17_14400_SHORT_TRAINING;
+            s->t38_fe.current_tx_data_type = T38_DATA_V17_14400;
             new_modem = (new_transmit)  ?  T31_V17_TX  :  T31_V17_RX;
             s->short_train = TRUE;
             s->bit_rate = 14400;
@@ -1766,7 +2230,7 @@
 {
     s->use_tep = use_tep;
 
-    hdlc_rx_init(&s->hdlc_rx, FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept, user_data);
+    hdlc_rx_init(&s->hdlc_rx, FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, user_data);
     hdlc_tx_init(&s->hdlc_tx, FALSE, 2, FALSE, hdlc_tx_underflow, user_data);
     fsk_rx_init(&s->v21_rx, &preset_fsk_specs[FSK_V21CH2], TRUE, (put_bit_func_t) hdlc_rx_put_bit, &s->hdlc_rx);
     fsk_rx_signal_cutoff(&s->v21_rx, -39.09);
@@ -1849,7 +2313,7 @@
         s->audio.next_tx_handler = NULL;
         return 0;
     }
-    /* If there is nothing else to change to, so use zero length silence */
+    /* There is nothing else to change to, so use zero length silence */
     silence_gen_alter(&(s->audio.modems.silence_gen), 0);
     s->audio.modems.tx_handler = (span_tx_handler_t *) &silence_gen;
     s->audio.modems.tx_user_data = &(s->audio.modems.silence_gen);
@@ -1870,40 +2334,7 @@
             /* Allow for one change of tx handler within a block */
             set_next_tx_type(s);
             if ((len += s->audio.modems.tx_handler(s->audio.modems.tx_user_data, amp + len, max_len - len)) < max_len)
-            {
-                switch (s->modem)
-                {
-                case T31_SILENCE_TX:
-                    s->modem = T31_NONE;
-                    at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
-                    if (s->at_state.do_hangup)
-                    {
-                        at_modem_control(&s->at_state, AT_MODEM_CONTROL_HANGUP, NULL);
-                        t31_set_at_rx_mode(s, AT_MODE_ONHOOK_COMMAND);
-                        s->at_state.do_hangup = FALSE;
-                    }
-                    else
-                    {
-                        t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
-                    }
-                    break;
-                case T31_CED_TONE:
-                    /* Go directly to V.21/HDLC transmit. */
-                    s->modem = T31_NONE;
-                    restart_modem(s, T31_V21_TX);
-                    t31_set_at_rx_mode(s, AT_MODE_HDLC);
-                    break;
-                case T31_V21_TX:
-                case T31_V17_TX:
-                case T31_V27TER_TX:
-                case T31_V29_TX:
-                    s->modem = T31_NONE;
-                    at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
-                    t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
-                    restart_modem(s, T31_SILENCE_TX);
-                    break;
-                }
-            }
+                front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
         }
     }
     if (s->audio.modems.transmit_on_idle)
@@ -1933,7 +2364,9 @@
     if (without_pacing)
     {
         /* Continuous streaming mode, as used for TPKT over TCP transport */
+        /* Inhibit indicator packets */
         s->t38_fe.t38.indicator_tx_count = 0;
+        s->t38_fe.t38.data_tx_count = 1;
         s->t38_fe.t38.data_end_tx_count = 1;
         s->t38_fe.ms_per_tx_chunk = 0;
     }
@@ -1941,9 +2374,74 @@
     {
         /* Paced streaming mode, as used for UDP transports */
         s->t38_fe.t38.indicator_tx_count = INDICATOR_TX_COUNT;
+        s->t38_fe.t38.data_tx_count = DATA_TX_COUNT;
         s->t38_fe.t38.data_end_tx_count = DATA_END_TX_COUNT;
         s->t38_fe.ms_per_tx_chunk = MS_PER_TX_CHUNK;
     }
+    set_octets_per_data_packet(s, 300);
+}
+/*- End of function --------------------------------------------------------*/
+
+void t31_set_mode(t31_state_t *s, int t38_mode)
+{
+    s->t38_mode = t38_mode;
+    span_log(&s->logging, SPAN_LOG_FLOW, "Mode set to %d\n", s->t38_mode);
+}
+/*- End of function --------------------------------------------------------*/
+
+logging_state_t *t31_get_logging_state(t31_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
+t38_core_state_t *t31_get_t38_core_state(t31_state_t *s)
+{
+    return &s->t38_fe.t38;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int t31_t38_fe_init(t31_state_t *t,
+                           t38_tx_packet_handler_t *tx_packet_handler,
+                           void *tx_packet_user_data)
+{
+    t31_t38_front_end_state_t *s;
+    
+    s = &t->t38_fe;
+
+    t38_core_init(&s->t38,
+                  process_rx_indicator,
+                  process_rx_data,
+                  process_rx_missing,
+                  (void *) t,
+                  tx_packet_handler,
+                  tx_packet_user_data);
+    s->t38.fastest_image_data_rate = 14400;
+
+    s->timed_step = T38_TIMED_STEP_NONE;
+    //s->iaf = T30_IAF_MODE_T37 | T30_IAF_MODE_T38;
+    s->iaf = T30_IAF_MODE_T38;
+
+    s->current_tx_data_type = T38_DATA_NONE;
+    s->next_tx_samples = 0;
+    s->chunking_modes = T38_CHUNKING_ALLOW_TEP_TIME;
+
+    t->hdlc_tx.ptr = 0;
+
+    hdlc_tx_init(&s->hdlc_tx_term,
+                 FALSE,
+                 1,
+                 FALSE,
+                 NULL,
+                 NULL);
+    hdlc_rx_init(&s->hdlc_rx_term,
+                 FALSE,
+                 TRUE,
+                 2,
+                 NULL,
+                 NULL);
+
+    return 0;
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -1999,13 +2497,9 @@
     s->at_state.dte_inactivity_timeout = DEFAULT_DTE_TIMEOUT;
     if (tx_t38_packet_handler)
     {
-        t38_core_init(&s->t38_fe.t38,
-                      process_rx_indicator,
-                      process_rx_data,
-                      process_rx_missing,
-                      (void *) s,
-                      tx_t38_packet_handler,
-                      tx_t38_packet_user_data);
+        t31_t38_fe_init(s,
+                        tx_t38_packet_handler,
+                        tx_t38_packet_user_data);
         t31_set_t38_config(s, FALSE);
     }
     s->t38_mode = FALSE;

Modified: freeswitch/trunk/libs/spandsp/src/t35.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t35.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t35.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t35.c,v 1.27 2008/05/13 13:17:23 steveu Exp $
+ * $Id: t35.c,v 1.28 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*
@@ -57,7 +57,7 @@
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>

Modified: freeswitch/trunk/libs/spandsp/src/t38_core.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t38_core.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t38_core.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_core.c,v 1.44 2008/07/02 14:48:26 steveu Exp $
+ * $Id: t38_core.c,v 1.50 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -37,13 +37,13 @@
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <memory.h>
 #include <tiffio.h>
@@ -53,8 +53,45 @@
 #include "spandsp/bit_operations.h"
 #include "spandsp/t38_core.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t38_core.h"
+
 #define ACCEPTABLE_SEQ_NO_OFFSET    2000
 
+/* The times for training, the optional TEP, and the HDLC preamble, for all the modem options, in ms.
+   Note that the preamble for V.21 is 1s+-15%, and for the other modems is 200ms+100ms. */
+static const struct
+{
+    int tep;
+    int training;
+    int flags;
+} modem_startup_time[] =
+{
+    {      0,   75000,       0},    /* T38_IND_NO_SIGNAL */
+    {      0,       0,       0},    /* T38_IND_CNG */
+    {      0, 3000000,       0},    /* T38_IND_CED */
+    {      0,       0, 1000000},    /* T38_IND_V21_PREAMBLE */ /* TODO: 850ms should be OK for this, but it causes trouble with some ATAs. Why? */
+    { 215000,  943000,  200000},    /* T38_IND_V27TER_2400_TRAINING */
+    { 215000,  708000,  200000},    /* T38_IND_V27TER_4800_TRAINING */
+    { 215000,  234000,  200000},    /* T38_IND_V29_7200_TRAINING */
+    { 215000,  234000,  200000},    /* T38_IND_V29_9600_TRAINING */
+    { 215000,  142000,  200000},    /* T38_IND_V17_7200_SHORT_TRAINING */
+    { 215000, 1393000,  200000},    /* T38_IND_V17_7200_LONG_TRAINING */
+    { 215000,  142000,  200000},    /* T38_IND_V17_9600_SHORT_TRAINING */
+    { 215000, 1393000,  200000},    /* T38_IND_V17_9600_LONG_TRAINING */
+    { 215000,  142000,  200000},    /* T38_IND_V17_12000_SHORT_TRAINING */
+    { 215000, 1393000,  200000},    /* T38_IND_V17_12000_LONG_TRAINING */
+    { 215000,  142000,  200000},    /* T38_IND_V17_14400_SHORT_TRAINING */
+    { 215000, 1393000,  200000},    /* T38_IND_V17_14400_LONG_TRAINING */
+    { 215000,       0,       0},    /* T38_IND_V8_ANSAM */
+    { 215000,       0,       0},    /* T38_IND_V8_SIGNAL */
+    { 215000,       0,       0},    /* T38_IND_V34_CNTL_CHANNEL_1200 */
+    { 215000,       0,       0},    /* T38_IND_V34_PRI_CHANNEL */
+    { 215000,       0,       0},    /* T38_IND_V34_CC_RETRAIN */
+    { 215000,       0,       0},    /* T38_IND_V33_12000_TRAINING */
+    { 215000,       0,       0}     /* T38_IND_V33_14400_TRAINING */
+};
+
 const char *t38_indicator_to_str(int indicator)
 {
     switch (indicator)
@@ -368,12 +405,17 @@
             }
             s->rx_expected_seq_no = seq_no;
         }
-        s->rx_expected_seq_no = (s->rx_expected_seq_no + 1) & 0xFFFF;
-    }
-    else
-    {
-        s->rx_expected_seq_no++;
     }
+    /* The sequence numbering is defined as rolling from 0xFFFF to 0x0000. Some implementations
+       of T.38 roll from 0xFFFF to 0x0001. Isn't standardisation a wonderful thing? The T.38
+       document specifies only a small fraction of what it should, yet then they actually nail
+       something properly, people ignore it. Developers in this industry truly deserves the ****
+       **** **** **** **** **** documents they have to live with. Anyway, when the far end has a
+       broken rollover behaviour we will get a hiccup at the rollover point. Don't worry too
+       much. We will just treat the message in progress as one with some missing data. With any
+       luck a retry will ride over the problem. Rollovers don't occur that often. It takes quite
+       a few FAX pages to reach rollover. */
+    s->rx_expected_seq_no = (s->rx_expected_seq_no + 1) & 0xFFFF;
     data_field_present = (buf[0] >> 7) & 1;
     type = (buf[0] >> 6) & 1;
     ptr = 0;
@@ -739,22 +781,37 @@
 {
     uint8_t buf[100];
     int len;
+    int delay;
 
-    /* Zero is a valid count, to suppress the transmission of indicators when the
-       transport is TCP. */       
-    if (count)
+    delay = 0;
+    /* Only send an indicator if it represents a change of state. */
+    if (s->current_tx_indicator != indicator)
     {
-        if ((len = t38_encode_indicator(s, buf, indicator)) < 0)
+        /* Zero is a valid count, to suppress the transmission of indicators when the
+           transport means they are not needed - e.g. TPKT/TCP. */
+        if (count)
         {
-            span_log(&s->logging, SPAN_LOG_FLOW, "T.38 indicator len is %d\n", len);
-            return len;
+            if ((len = t38_encode_indicator(s, buf, indicator)) < 0)
+            {
+                span_log(&s->logging, SPAN_LOG_FLOW, "T.38 indicator len is %d\n", len);
+                return len;
+            }
+            span_log(&s->logging, SPAN_LOG_FLOW, "Tx %5d: indicator %s\n", s->tx_seq_no, t38_indicator_to_str(indicator));
+            s->tx_packet_handler(s, s->tx_packet_user_data, buf, len, count);
+            s->tx_seq_no = (s->tx_seq_no + 1) & 0xFFFF;
+            delay = modem_startup_time[indicator].training;
+            if (s->allow_for_tep)
+                delay += modem_startup_time[indicator].tep;
         }
-        span_log(&s->logging, SPAN_LOG_FLOW, "Tx %5d: indicator %s\n", s->tx_seq_no, t38_indicator_to_str(indicator));
-        s->tx_packet_handler(s, s->tx_packet_user_data, buf, len, count);
-        s->tx_seq_no = (s->tx_seq_no + 1) & 0xFFFF;
+        s->current_tx_indicator = indicator;
     }
-    s->current_tx_indicator = indicator;
-    return 0;
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+int t38_core_send_flags_delay(t38_core_state_t *s, int indicator)
+{
+    return modem_startup_time[indicator].flags;
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -848,12 +905,24 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+void t38_set_tep_handling(t38_core_state_t *s, int allow_for_tep)
+{
+    s->allow_for_tep = allow_for_tep;
+}
+/*- End of function --------------------------------------------------------*/
+
 int t38_get_fastest_image_data_rate(t38_core_state_t *s)
 {
     return s->fastest_image_data_rate;
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *t38_core_get_logging_state(t38_core_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 t38_core_state_t *t38_core_init(t38_core_state_t *s,
                                 t38_rx_indicator_handler_t *rx_indicator_handler,
                                 t38_rx_data_handler_t *rx_data_handler,
@@ -871,8 +940,9 @@
     span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
     span_log_set_protocol(&s->logging, "T.38");
 
-    span_log(&s->logging, SPAN_LOG_FLOW, "Start tx document\n");
-    s->data_rate_management_method = 2;
+    /* Set some defaults for the parameters configurable from outside the
+       T.38 domain - e.g. from SDP data. */
+    s->data_rate_management_method = T38_DATA_RATE_MANAGEMENT_TRANSFERRED_TCF;
     s->data_transport_protocol = T38_TRANSPORT_UDPTL;
     s->fill_bit_removal = FALSE;
     s->mmr_transcoding = FALSE;
@@ -882,10 +952,16 @@
     s->t38_version = 0;
     s->check_sequence_numbers = TRUE;
 
+    /* Set the initial current receive states to something invalid, so the
+       first data received is seen as a change of state. */
     s->current_rx_indicator = -1;
     s->current_rx_data_type = -1;
     s->current_rx_field_type = -1;
 
+    /* Set the initial current indicator state to something invalid, so the
+       first attempt to send an indicator will work. */
+    s->current_tx_indicator = -1;
+
     s->rx_indicator_handler = rx_indicator_handler;
     s->rx_data_handler = rx_data_handler;
     s->rx_missing_handler = rx_missing_handler;
@@ -893,6 +969,9 @@
     s->tx_packet_handler = tx_packet_handler;
     s->tx_packet_user_data = tx_packet_user_data;
 
+    /* We have no initial expectation of the received packet sequence number.
+       They most often start at 0 or 1 for a UDPTL transport, but random
+       starting numbers are possible. */
     s->rx_expected_seq_no = -1;
     return s;
 }

Modified: freeswitch/trunk/libs/spandsp/src/t38_gateway.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t38_gateway.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t38_gateway.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_gateway.c,v 1.142 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t38_gateway.c,v 1.151 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -38,13 +38,13 @@
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #if defined(LOG_FAX_AUDIO)
 #include <unistd.h>
@@ -65,12 +65,12 @@
 #include "spandsp/hdlc.h"
 #include "spandsp/silence_gen.h"
 #include "spandsp/fsk.h"
-#include "spandsp/v29rx.h"
 #include "spandsp/v29tx.h"
-#include "spandsp/v27ter_rx.h"
+#include "spandsp/v29rx.h"
 #include "spandsp/v27ter_tx.h"
-#include "spandsp/v17rx.h"
+#include "spandsp/v27ter_rx.h"
 #include "spandsp/v17tx.h"
+#include "spandsp/v17rx.h"
 #include "spandsp/super_tone_rx.h"
 #include "spandsp/modem_connect_tones.h"
 #include "spandsp/t4.h"
@@ -78,12 +78,28 @@
 #include "spandsp/t35.h"
 #include "spandsp/t30.h"
 #include "spandsp/t30_logging.h"
-
 #include "spandsp/fax_modems.h"
 #include "spandsp/t38_core.h"
 #include "spandsp/t38_non_ecm_buffer.h"
 #include "spandsp/t38_gateway.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/v17tx.h"
+#include "spandsp/private/v17rx.h"
+#include "spandsp/private/v27ter_tx.h"
+#include "spandsp/private/v27ter_rx.h"
+#include "spandsp/private/v29tx.h"
+#include "spandsp/private/v29rx.h"
+#include "spandsp/private/modem_connect_tones.h"
+#include "spandsp/private/hdlc.h"
+#include "spandsp/private/fax_modems.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+#include "spandsp/private/t38_core.h"
+#include "spandsp/private/t38_non_ecm_buffer.h"
+#include "spandsp/private/t38_gateway.h"
+
 /* This is the target time per transmission chunk. The actual
    packet timing will sync to the data octets. */
 #define MS_PER_TX_CHUNK                 30
@@ -127,6 +143,15 @@
     FLAG_DATA = 0x200
 };
 
+enum
+{
+    TCF_MODE_PREDICTABLE_MODEM_START_OFF = 0,
+    TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED,
+    TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_SEEN,
+    TCF_MODE_PREDICTABLE_MODEM_START_PAST_V21_MODEM,
+    TCF_MODE_PREDICTABLE_MODEM_START_BEGIN
+};
+
 #define MAX_NSX_SUPPRESSION             10
 
 #define HDLC_FRAMING_OK_THRESHOLD       5
@@ -399,7 +424,7 @@
     }
     else
     {
-        span_log(&s->logging, SPAN_LOG_FLOW, "non-ECM mode\n");
+        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM mode\n");
         get_bit_func = t38_non_ecm_buffer_get_bit;
         get_bit_user_data = (void *) &s->core.non_ecm_to_modem;
     }
@@ -643,6 +668,18 @@
         }
         /*endswitch*/
         break;
+    case 4:
+        switch (buf[2])
+        {
+        case T30_DIS:
+            /* Make sure the V.8 capability doesn't pass through. If it
+               did then two V.34 capable FAX machines might start some
+               V.8 re-negotiation. */
+            buf[3] &= ~DISBIT6;
+            break;
+        }
+        /*endswitch*/
+        break;
     case 5:
         switch (buf[2])
         {
@@ -750,7 +787,7 @@
     if (len < 3)
         return;
     /*endif*/
-    s->core.tcf_mode_predictable_modem_start = 0;
+    s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_OFF;
     switch (buf[2])
     {
     case T30_CFR:
@@ -807,7 +844,7 @@
         s->core.image_data_mode = FALSE;
         s->core.short_train = FALSE;
         if (from_modem)
-            s->core.tcf_mode_predictable_modem_start = 2;
+            s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_BEGIN;
         /*endif*/
         break;
     case T30_PPS:
@@ -1007,11 +1044,15 @@
         if (hdlc_buf->contents != (data_type | FLAG_DATA))
         {
             queue_missing_indicator(s, data_type);
+            /* All real HDLC messages in the FAX world start with 0xFF. If this one is not starting
+               with 0xFF it would appear some octets must have been missed before this one. */
+            if (len <= 0  ||  buf[0] != 0xFF)
+                s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in].flags |= HDLC_FLAG_MISSING_DATA;
             hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
         }
         /*endif*/
         /* Check if this data would overflow the buffer. */
-        if (hdlc_buf->len + len > T38_MAX_HDLC_LEN)
+        if (len <= 0  ||  hdlc_buf->len + len > T38_MAX_HDLC_LEN)
             break;
         /*endif*/
         hdlc_buf->contents = (data_type | FLAG_DATA);
@@ -1275,7 +1316,8 @@
             queue_missing_indicator(s, data_type);
             hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
         }
-        t38_non_ecm_buffer_inject(&s->core.non_ecm_to_modem, buf, len);
+        if (len > 0)
+            t38_non_ecm_buffer_inject(&s->core.non_ecm_to_modem, buf, len);
         xx->corrupt_current_frame[0] = FALSE;
         break;
     case T38_FIELD_T4_NON_ECM_SIG_END:
@@ -1486,31 +1528,36 @@
     t38_gateway_state_t *s;
 
     s = (t38_gateway_state_t *) user_data;
+    span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM signal status is %s (%d)\n", signal_status_to_str(status), status);
     switch (status)
     {
     case SIG_STATUS_TRAINING_IN_PROGRESS:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier training in progress\n");
-        if (s->core.tcf_mode_predictable_modem_start)
-            s->core.tcf_mode_predictable_modem_start = 0;
-        else
+        if (s->core.tcf_mode_predictable_modem_start == TCF_MODE_PREDICTABLE_MODEM_START_OFF)
+        {
             announce_training(s);
+        }
+        else
+        {
+            if (s->core.tcf_mode_predictable_modem_start == TCF_MODE_PREDICTABLE_MODEM_START_PAST_V21_MODEM)
+                s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_SEEN;
+            else
+                s->core.samples_to_timeout = ms_to_samples(500);
+            set_fast_packetisation(s);
+        }
         break;
     case SIG_STATUS_TRAINING_FAILED:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier training failed\n");
         break;
     case SIG_STATUS_TRAINING_SUCCEEDED:
         /* The modem is now trained */
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier trained\n");
         s->audio.modems.rx_signal_present = TRUE;
         s->audio.modems.rx_trained = TRUE;
+        s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_OFF;
+        s->core.samples_to_timeout = 0;
         to_t38_buffer_init(&s->core.to_t38);
         break;
     case SIG_STATUS_CARRIER_UP:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier up\n");
         break;
     case SIG_STATUS_CARRIER_DOWN:
-        span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM carrier down\n");
-        s->core.tcf_mode_predictable_modem_start = 0;
         switch (s->t38x.current_tx_data_type)
         {
         case T38_DATA_V17_7200:
@@ -1521,8 +1568,13 @@
         case T38_DATA_V27TER_4800:
         case T38_DATA_V29_7200:
         case T38_DATA_V29_9600:
-            non_ecm_push_residue(s);
-            t38_core_send_indicator(&s->t38x.t38, T38_IND_NO_SIGNAL, s->t38x.t38.indicator_tx_count);
+            if (s->core.tcf_mode_predictable_modem_start != TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED)
+            {
+                /* TODO: If the carrier really did fall for good during the 500ms TEP blocking timeout, we
+                         won't declare the no-signal condition. */
+                non_ecm_push_residue(s);
+                t38_core_send_indicator(&s->t38x.t38, T38_IND_NO_SIGNAL, s->t38x.t38.indicator_tx_count);
+            }
             restart_rx_modem(s);
             break;
         }
@@ -1653,7 +1705,7 @@
     t38_gateway_state_t *s;
 
     s = (t38_gateway_state_t *) t->user_data;
-    span_log(&s->logging, SPAN_LOG_FLOW, "HDLC carrier status is %s (%d)\n", signal_status_to_str(status), status);
+    span_log(&s->logging, SPAN_LOG_FLOW, "HDLC signal status is %s (%d)\n", signal_status_to_str(status), status);
     switch (status)
     {
     case SIG_STATUS_TRAINING_IN_PROGRESS:
@@ -1686,14 +1738,15 @@
             t->framing_ok_announced = FALSE;
         }
         restart_rx_modem(s);
-        if (s->core.tcf_mode_predictable_modem_start == 2)
+        if (s->core.tcf_mode_predictable_modem_start == TCF_MODE_PREDICTABLE_MODEM_START_BEGIN)
         {
             /* If we are doing TCF, we need to announce the fast carrier training very
                quickly, to ensure it starts 75+-20ms after the HDLC carrier ends. Waiting until
                it trains will be too late. We need to announce the fast modem a fixed time after
-               the end of the V.21 carrier, in anticipation of its arrival. */
+               the end of the V.21 carrier, in anticipation of its arrival. If we announce it,
+               and it doesn't arrive, we will worry about that later. */
             s->core.samples_to_timeout = ms_to_samples(75);
-            s->core.tcf_mode_predictable_modem_start = 1;
+            s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_PAST_V21_MODEM;
         }
         break;
     default:
@@ -1975,9 +2028,25 @@
     {
         if ((s->core.samples_to_timeout -= len) <= 0)
         {
-            if (s->core.tcf_mode_predictable_modem_start == 1)
+            switch (s->core.tcf_mode_predictable_modem_start)
+            {
+            case TCF_MODE_PREDICTABLE_MODEM_START_PAST_V21_MODEM:
+                /* Timed announcement of training, 75ms after the DCS carrier fell. */
+                s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED;
                 announce_training(s);
-            /*endif*/
+                break;
+            case TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_SEEN:
+                /* Timed announcement of training, 75ms after the DCS carrier fell. */
+                /* Use a timeout to ride over TEP, if it is present */
+                s->core.samples_to_timeout = ms_to_samples(500);
+                announce_training(s);
+                break;
+            case TCF_MODE_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED:
+                s->core.tcf_mode_predictable_modem_start = TCF_MODE_PREDICTABLE_MODEM_START_OFF;
+                span_log(&s->logging, SPAN_LOG_FLOW, "TEP jamming expired\n");
+                break;
+            }
+            /*endswitch*/
         }
         /*endif*/
     }
@@ -2044,6 +2113,18 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+t38_core_state_t *t38_gateway_get_t38_core_state(t38_gateway_state_t *s)
+{
+    return &s->t38x.t38;
+}
+/*- End of function --------------------------------------------------------*/
+
+logging_state_t *t38_gateway_get_logging_state(t38_gateway_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed)
 {
     s->core.ecm_allowed = ecm_allowed;

Modified: freeswitch/trunk/libs/spandsp/src/t38_non_ecm_buffer.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t38_non_ecm_buffer.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t38_non_ecm_buffer.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_non_ecm_buffer.c,v 1.3 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t38_non_ecm_buffer.c,v 1.5 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -38,13 +38,13 @@
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #if defined(LOG_FAX_AUDIO)
 #include <unistd.h>
@@ -56,9 +56,10 @@
 #include "spandsp/dc_restore.h"
 #include "spandsp/bit_operations.h"
 #include "spandsp/async.h"
-
 #include "spandsp/t38_non_ecm_buffer.h"
 
+#include "spandsp/private/t38_non_ecm_buffer.h"
+
 static void restart_buffer(t38_non_ecm_buffer_state_t *s)
 {
     /* This should be called when draining the buffer is complete, which should

Modified: freeswitch/trunk/libs/spandsp/src/t38_terminal.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t38_terminal.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t38_terminal.c	Tue Jan 27 22:48:03 2009
@@ -5,7 +5,7 @@
  *
  * Written by Steve Underwood <steveu at coppice.org>
  *
- * Copyright (C) 2005, 2006 Steve Underwood
+ * Copyright (C) 2005, 2006, 2008 Steve Underwood
  *
  * All rights reserved.
  *
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_terminal.c,v 1.101 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t38_terminal.c,v 1.119 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -31,19 +31,19 @@
 #include "config.h"
 #endif
 
+#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <inttypes.h>
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <tiffio.h>
 
@@ -57,12 +57,12 @@
 #include "spandsp/async.h"
 #include "spandsp/hdlc.h"
 #include "spandsp/fsk.h"
-#include "spandsp/v29rx.h"
 #include "spandsp/v29tx.h"
-#include "spandsp/v27ter_rx.h"
+#include "spandsp/v29rx.h"
 #include "spandsp/v27ter_tx.h"
-#include "spandsp/v17rx.h"
+#include "spandsp/v27ter_rx.h"
 #include "spandsp/v17tx.h"
+#include "spandsp/v17rx.h"
 #include "spandsp/t4.h"
 #include "spandsp/t30_fcf.h"
 #include "spandsp/t35.h"
@@ -72,6 +72,12 @@
 #include "spandsp/t38_core.h"
 #include "spandsp/t38_terminal.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t4.h"
+#include "spandsp/private/t30.h"
+#include "spandsp/private/t38_core.h"
+#include "spandsp/private/t38_terminal.h"
+
 /* Settings suitable for paced transmission over a UDP transport */
 #define MS_PER_TX_CHUNK                         30
 
@@ -85,29 +91,46 @@
 /* Backstop timeout if reception of packets stops in the middle of a burst */
 #define MID_RX_TIMEOUT                          15000
 
-#define T38_CHUNKING_MERGE_FCS_WITH_DATA        0x0001
-#define T38_CHUNKING_WHOLE_FRAMES               0x0002
-#define T38_CHUNKING_ALLOW_TEP_TIME             0x0004
+enum
+{
+    T38_CHUNKING_MERGE_FCS_WITH_DATA    = 0x0001,
+    T38_CHUNKING_WHOLE_FRAMES           = 0x0002,
+    T38_CHUNKING_ALLOW_TEP_TIME         = 0x0004
+};
 
 enum
 {
     T38_TIMED_STEP_NONE = 0,
-    T38_TIMED_STEP_NON_ECM_MODEM,
-    T38_TIMED_STEP_NON_ECM_MODEM_2,
-    T38_TIMED_STEP_NON_ECM_MODEM_3,
-    T38_TIMED_STEP_NON_ECM_MODEM_4,
-    T38_TIMED_STEP_NON_ECM_MODEM_5,
-    T38_TIMED_STEP_HDLC_MODEM,
-    T38_TIMED_STEP_HDLC_MODEM_2,
-    T38_TIMED_STEP_HDLC_MODEM_3,
-    T38_TIMED_STEP_HDLC_MODEM_4,
-    T38_TIMED_STEP_CED,
-    T38_TIMED_STEP_CED_2,
-    T38_TIMED_STEP_CNG,
-    T38_TIMED_STEP_CNG_2,
-    T38_TIMED_STEP_PAUSE
+    T38_TIMED_STEP_NON_ECM_MODEM = 0x10,
+    T38_TIMED_STEP_NON_ECM_MODEM_2 = 0x11,
+    T38_TIMED_STEP_NON_ECM_MODEM_3 = 0x12,
+    T38_TIMED_STEP_NON_ECM_MODEM_4 = 0x13,
+    T38_TIMED_STEP_NON_ECM_MODEM_5 = 0x14,
+    T38_TIMED_STEP_HDLC_MODEM = 0x20,
+    T38_TIMED_STEP_HDLC_MODEM_2 = 0x21,
+    T38_TIMED_STEP_HDLC_MODEM_3 = 0x22,
+    T38_TIMED_STEP_HDLC_MODEM_4 = 0x23,
+    T38_TIMED_STEP_HDLC_MODEM_5 = 0x24,
+    T38_TIMED_STEP_CED = 0x30,
+    T38_TIMED_STEP_CED_2 = 0x31,
+    T38_TIMED_STEP_CED_3 = 0x32,
+    T38_TIMED_STEP_CNG = 0x40,
+    T38_TIMED_STEP_CNG_2 = 0x41,
+    T38_TIMED_STEP_PAUSE = 0x50
 };
 
+static __inline__ void front_end_status(t38_terminal_state_t *s, int status)
+{
+    t30_front_end_status(&s->t30, status);
+}
+/*- End of function --------------------------------------------------------*/
+
+static __inline__ void hdlc_accept_frame(t38_terminal_state_t *s, const uint8_t *msg, int len, int ok)
+{
+    t30_hdlc_accept(&s->t30, msg, len, ok);
+}
+/*- End of function --------------------------------------------------------*/
+
 static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len)
 {
     int bitstream;
@@ -119,7 +142,7 @@
     bitstream = 0;
     ones = 0;
     stuffed = 0;
-    /* We should really append the CRC, and included the stuffed bits for that, to get
+    /* We should really append the CRC, and include the stuffed bits for that, to get
        the exact number of bits in the frame. */
     //len = crc_itu16_append(buf, len);
     for (i = 0;  i < len;  i++)
@@ -191,23 +214,27 @@
             &&
             (fe->current_rx_type == T30_MODEM_V21  ||  fe->current_rx_type == T30_MODEM_CNG))
         {
-            t30_hdlc_accept(&s->t30, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
+            hdlc_accept_frame(s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
         }
         fe->timeout_rx_samples = 0;
-        t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_ABSENT);
+        front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
         break;
     case T38_IND_CNG:
-    case T38_IND_CED:
         /* We are completely indifferent to the startup tones. They serve no purpose for us.
            We can't even assume that the existance of a tone means the far end is achieving
            proper communication. Some T.38 gateways will just send out a CED or CNG indicator
-           without having seen anything from the far end FAX terminal. */
+           without having seen anything from the far end FAX terminal.
+           Just report them for completeness. */
+        front_end_status(s, T30_FRONT_END_CNG_PRESENT);
+        break;
+    case T38_IND_CED:
+        front_end_status(s, T30_FRONT_END_CED_PRESENT);
         break;
     case T38_IND_V21_PREAMBLE:
         /* Some T.38 implementations insert these preamble indicators between HDLC frames, so
            we need to be tolerant of that. */
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-        t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_PRESENT);
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     case T38_IND_V27TER_2400_TRAINING:
     case T38_IND_V27TER_4800_TRAINING:
@@ -226,7 +253,7 @@
         /* We really don't care what kind of modem is delivering the following image data.
            We only care that some kind of fast modem signal is coming next. */
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-        t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_PRESENT);
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     case T38_IND_V8_ANSAM:
     case T38_IND_V8_SIGNAL:
@@ -234,10 +261,10 @@
     case T38_IND_V34_PRI_CHANNEL:
     case T38_IND_V34_CC_RETRAIN:
         /* V.34 support is a work in progress. */
-        t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_PRESENT);
+        front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
         break;
     default:
-        t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_ABSENT);
+        front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
         break;
     }
     fe->hdlc_rx.len = 0;
@@ -251,7 +278,7 @@
     t38_terminal_state_t *s;
     t38_terminal_front_end_state_t *fe;
 #if defined(_MSC_VER)
-    uint8_t *buf2 = alloca(len);
+    uint8_t *buf2 = (uint8_t *) alloca(len);
 #else
     uint8_t buf2[len];
 #endif
@@ -281,7 +308,6 @@
         break;
     }
 #endif
-
     switch (field_type)
     {
     case T38_FIELD_HDLC_DATA:
@@ -291,13 +317,13 @@
                there is zero packet lost. Nasty, but true. Its a good idea to be tolerant of
                loss, though, so accepting a sudden start of HDLC data is the right thing to do. */
             fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
-            t30_front_end_status(&s->t30, T30_FRONT_END_SIGNAL_PRESENT);
+            front_end_status(s, T30_FRONT_END_SIGNAL_PRESENT);
             /* All real HDLC messages in the FAX world start with 0xFF. If this one is not starting
                with 0xFF it would appear some octets must have been missed before this one. */
-            if (buf[0] != 0xFF)
+            if (len <= 0  ||  buf[0] != 0xFF)
                 fe->rx_data_missing = TRUE;
         }
-        if (fe->hdlc_rx.len + len <= T38_MAX_HDLC_LEN)
+        if (len > 0  &&  fe->hdlc_rx.len + len <= T38_MAX_HDLC_LEN)
         {
             bit_reverse(fe->hdlc_rx.buf + fe->hdlc_rx.len, buf, len);
             fe->hdlc_rx.len += len;
@@ -317,7 +343,7 @@
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
-            t30_hdlc_accept(&s->t30, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
         }
         fe->hdlc_rx.len = 0;
         fe->rx_data_missing = FALSE;
@@ -336,7 +362,7 @@
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
-            t30_hdlc_accept(&s->t30, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
         }
         fe->hdlc_rx.len = 0;
         fe->rx_data_missing = FALSE;
@@ -355,8 +381,8 @@
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK, sig end (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
-            t30_hdlc_accept(&s->t30, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
-            t30_hdlc_accept(&s->t30, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
+            hdlc_accept_frame(s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
         }
         fe->hdlc_rx.len = 0;
         fe->rx_data_missing = FALSE;
@@ -375,8 +401,8 @@
         if (t->current_rx_data_type != data_type  ||  t->current_rx_field_type != field_type)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC bad, sig end (%s)\n", (fe->hdlc_rx.len >= 3)  ?  t30_frametype(fe->hdlc_rx.buf[2])  :  "???", (fe->rx_data_missing)  ?  "missing octets"  :  "clean");
-            t30_hdlc_accept(&s->t30, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
-            t30_hdlc_accept(&s->t30, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
+            hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
+            hdlc_accept_frame(s, NULL, SIG_STATUS_CARRIER_DOWN, TRUE);
         }
         fe->hdlc_rx.len = 0;
         fe->rx_data_missing = FALSE;
@@ -403,7 +429,7 @@
             fe->hdlc_rx.len = 0;
             fe->rx_data_missing = FALSE;
             fe->timeout_rx_samples = 0;
-            t30_front_end_status(&s->t30, T30_FRONT_END_RECEIVE_COMPLETE);
+            front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE);
         }
         break;
     case T38_FIELD_T4_NON_ECM_DATA:
@@ -412,8 +438,11 @@
             t30_non_ecm_put_bit(&s->t30, SIG_STATUS_TRAINING_SUCCEEDED);
             fe->rx_signal_present = TRUE;
         }
-        bit_reverse(buf2, buf, len);
-        t30_non_ecm_put_chunk(&s->t30, buf2, len);
+        if (len > 0)
+        {
+            bit_reverse(buf2, buf, len);
+            t30_non_ecm_put_chunk(&s->t30, buf2, len);
+        }
         fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
         break;
     case T38_FIELD_T4_NON_ECM_SIG_END:
@@ -436,7 +465,7 @@
                            they should send non-ECM signal end. It is possible they also do the opposite.
                            We need to tolerate this, so we use the generic receive complete
                            indication, rather than the specific non-ECM carrier down. */
-            t30_front_end_status(&s->t30, T30_FRONT_END_RECEIVE_COMPLETE);
+            front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE);
         }
         fe->rx_signal_present = FALSE;
         fe->timeout_rx_samples = 0;
@@ -484,88 +513,322 @@
     s = (t38_terminal_state_t *) user_data;
     if (len <= 0)
     {
-        s->t38_fe.tx.len = -1;
+        s->t38_fe.hdlc_tx.len = -1;
     }
     else
     {
-        s->t38_fe.tx.extra_bits = extra_bits_in_stuffed_frame(msg, len);
-        bit_reverse(s->t38_fe.tx.buf, msg, len);
-        s->t38_fe.tx.len = len;
-        s->t38_fe.tx.ptr = 0;
+        s->t38_fe.hdlc_tx.extra_bits = extra_bits_in_stuffed_frame(msg, len);
+        bit_reverse(s->t38_fe.hdlc_tx.buf, msg, len);
+        s->t38_fe.hdlc_tx.len = len;
+        s->t38_fe.hdlc_tx.ptr = 0;
     }
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int bits_to_samples(t38_terminal_state_t *s, int bits)
+static __inline__ int bits_to_us(t38_terminal_state_t *s, int bits)
 {
-    /* This does not handle fractions properly, so they may accumulate. They
-       shouldn't be able to accumulate far enough to be troublesome. */
-    /* TODO: Is the above statement accurate when sending a long string of
-             octets, one per IFP packet, at V.21 rate? */
     if (s->t38_fe.ms_per_tx_chunk == 0)
         return 0;
-    return bits*8000/s->t38_fe.tx_bit_rate;
+    return bits*1000000/s->t38_fe.tx_bit_rate;
 }
 /*- End of function --------------------------------------------------------*/
 
 static void set_octets_per_data_packet(t38_terminal_state_t *s, int bit_rate)
 {
     s->t38_fe.tx_bit_rate = bit_rate;
-    if (s->t38_fe.ms_per_tx_chunk == 0)
-    {
-        s->t38_fe.octets_per_data_packet = MAX_OCTETS_PER_UNPACED_CHUNK;
-    }
-    else
+    if (s->t38_fe.ms_per_tx_chunk)
     {
         s->t38_fe.octets_per_data_packet = s->t38_fe.ms_per_tx_chunk*bit_rate/(8*1000);
         /* Make sure we have a positive number (i.e. we didn't truncate to zero). */
         if (s->t38_fe.octets_per_data_packet < 1)
             s->t38_fe.octets_per_data_packet = 1;
     }
+    else
+    {
+        s->t38_fe.octets_per_data_packet = MAX_OCTETS_PER_UNPACED_CHUNK;
+    }
 }
 /*- End of function --------------------------------------------------------*/
 
-int t38_terminal_send_timeout(t38_terminal_state_t *s, int samples)
+static int stream_non_ecm(t38_terminal_state_t *s)
 {
-    int len;
-    int i;
-    int previous;
+    t38_terminal_front_end_state_t *fe;
     uint8_t buf[MAX_OCTETS_PER_UNPACED_CHUNK + 50];
+    int delay;
+    int len;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_NON_ECM_MODEM:
+            /* Create a 75ms silence */
+            if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
+                delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_2:
+            /* Switch on a fast modem, and give the training time to complete */
+            delay = t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3;
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_3:
+            /* Send a chunk of non-ECM image data */
+            /* T.38 says it is OK to send the last of the non-ECM data in the signal end message.
+               However, I think the early versions of T.38 said the signal end message should not
+               contain data. Hopefully, following the current spec will not cause compatibility
+               issues. */
+            len = t30_non_ecm_get_chunk(&s->t30, buf, fe->octets_per_data_packet);
+            if (len > 0)
+                bit_reverse(buf, buf, len);
+            if (len < fe->octets_per_data_packet)
+            {
+                /* That's the end of the image data. Do a little padding now */
+                memset(buf + len, 0, fe->octets_per_data_packet - len);
+                fe->non_ecm_trailer_bytes = 3*fe->octets_per_data_packet + len;
+                len = fe->octets_per_data_packet;
+                fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_4;
+            }
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
+            delay = bits_to_us(s, 8*len);
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_4:
+            /* This pads the end of the data with some zeros. If we just stop abruptly
+               at the end of the EOLs, some ATAs fail to clean up properly before
+               shutting down their transmit modem, and the last few rows of the image
+               are corrupted. Simply delaying the no-signal message does not help for
+               all implentations. It is usually ignored, which is probably the right
+               thing to do after receiving a message saying the signal has ended. */
+            len = fe->octets_per_data_packet;
+            fe->non_ecm_trailer_bytes -= len;
+            if (fe->non_ecm_trailer_bytes <= 0)
+            {
+                len += fe->non_ecm_trailer_bytes;
+                memset(buf, 0, len);
+                t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, buf, len, fe->t38.data_end_tx_count);
+                fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
+                /* Allow a bit more time than the data will take to play out, to ensure the far ATA does not
+                   cut things short. */
+                delay = bits_to_us(s, 8*len) + 60000;
+                front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                break;
+            }
+            memset(buf, 0, len);
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
+            delay = bits_to_us(s, 8*len);
+            break;
+        case T38_TIMED_STEP_NON_ECM_MODEM_5:
+            /* This should not be needed, since the message above indicates the end of the signal, but it
+               seems like it can improve compatibility with quirky implementations. */
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            return delay;
+        }
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_hdlc(t38_terminal_state_t *s)
+{
     t38_terminal_front_end_state_t *fe;
+    uint8_t buf[MAX_OCTETS_PER_UNPACED_CHUNK + 50];
     t38_data_field_t data_fields[2];
-    /* The times for training, the optional TEP, and the HDLC preamble, for all the modem options, in ms.
-       Note that the preamble for V.21 is 1s+-15%, and for the other modems is 200ms+100ms. */
-    static const struct
-    {
-        int tep;
-        int training;
-        int flags;
-    } startup_time[] =
-    {
-        {   0,    0,    0},     /* T38_IND_NO_SIGNAL */
-        {   0,    0,    0},     /* T38_IND_CNG */
-        {   0,    0,    0},     /* T38_IND_CED */
-        {   0,    0, 1000},     /* T38_IND_V21_PREAMBLE */ /* TODO: 850ms should be OK for this, but it causes trouble with some ATAs. Why? */
-        { 215,  943,  200},     /* T38_IND_V27TER_2400_TRAINING */
-        { 215,  708,  200},     /* T38_IND_V27TER_4800_TRAINING */
-        { 215,  234,  200},     /* T38_IND_V29_7200_TRAINING */
-        { 215,  234,  200},     /* T38_IND_V29_9600_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_7200_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_7200_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_9600_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_9600_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_12000_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_12000_LONG_TRAINING */
-        { 215,  142,  200},     /* T38_IND_V17_14400_SHORT_TRAINING */
-        { 215, 1393,  200},     /* T38_IND_V17_14400_LONG_TRAINING */
-        { 215,    0,    0},     /* T38_IND_V8_ANSAM */
-        { 215,    0,    0},     /* T38_IND_V8_SIGNAL */
-        { 215,    0,    0},     /* T38_IND_V34_CNTL_CHANNEL_1200 */
-        { 215,    0,    0},     /* T38_IND_V34_PRI_CHANNEL */
-        { 215,    0,    0},     /* T38_IND_V34_CC_RETRAIN */
-        { 215,    0,    0},     /* T38_IND_V33_12000_TRAINING */
-        { 215,    0,    0}      /* T38_IND_V33_14400_TRAINING */
-    };
+    int previous;
+    int delay;
+    int i;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_HDLC_MODEM:
+            /* Create a 75ms silence */
+            if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
+                delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_2:
+            /* Send HDLC preambling */
+            delay = t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
+            delay += t38_core_send_flags_delay(&fe->t38, fe->next_tx_indicator);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_3:
+            /* Send a chunk of HDLC data */
+            i = fe->hdlc_tx.len - fe->hdlc_tx.ptr;
+            if (fe->octets_per_data_packet >= i)
+            {
+                /* The last part of an HDLC frame */
+                if (fe->chunking_modes & T38_CHUNKING_MERGE_FCS_WITH_DATA)
+                {
+                    /* Copy the data, as we might be about to refill the buffer it is in */
+                    memcpy(buf, &fe->hdlc_tx.buf[fe->hdlc_tx.ptr], i);
+                    data_fields[0].field_type = T38_FIELD_HDLC_DATA;
+                    data_fields[0].field = buf;
+                    data_fields[0].field_len = i;
+
+                    /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
+                    previous = fe->current_tx_data_type;
+                    fe->hdlc_tx.ptr = 0;
+                    fe->hdlc_tx.len = 0;
+                    front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                    /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
+                    if (fe->hdlc_tx.len < 0)
+                    {
+                        data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END;
+                        data_fields[1].field = NULL;
+                        data_fields[1].field_len = 0;
+                        t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, fe->t38.data_tx_count);
+                        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
+                        /* We add a bit of extra time here, as with some implementations
+                           the carrier falling too abruptly causes data loss. */
+                        delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits) + 100000;
+                        front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                    }
+                    else
+                    {
+                        data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK;
+                        data_fields[1].field = NULL;
+                        data_fields[1].field_len = 0;
+                        t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, fe->t38.data_tx_count);
+                        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+                        delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits);
+                    }
+                }
+                else
+                {
+                    t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &fe->hdlc_tx.buf[fe->hdlc_tx.ptr], i, fe->t38.data_tx_count);
+                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
+                    delay = bits_to_us(s, i*8);
+                }
+                break;
+            }
+            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &fe->hdlc_tx.buf[fe->hdlc_tx.ptr], fe->octets_per_data_packet, fe->t38.data_tx_count);
+            fe->hdlc_tx.ptr += fe->octets_per_data_packet;
+            delay = bits_to_us(s, fe->octets_per_data_packet*8);
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_4:
+            /* End of HDLC frame */
+            previous = fe->current_tx_data_type;
+            fe->hdlc_tx.ptr = 0;
+            fe->hdlc_tx.len = 0;
+            front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+            /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
+            if (fe->hdlc_tx.len < 0)
+            {
+                /* End of transmission */
+                t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK_SIG_END, NULL, 0, fe->t38.data_end_tx_count);
+                fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
+                /* We add a bit of extra time here, as with some implementations
+                   the carrier falling too abruptly causes data loss. */
+                delay = bits_to_us(s, fe->hdlc_tx.extra_bits) + 100000;
+                front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+                break;
+            }
+            if (fe->hdlc_tx.len == 0)
+            {
+                /* Now, how did we get here? We have finished a frame, but have no new frame to
+                   send, and no end of transmission condition. */
+                span_log(&s->logging, SPAN_LOG_FLOW, "No new frame or end transmission condition.\n");
+            }
+            /* Finish the current frame off, and prepare for the next one. */
+            t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, fe->t38.data_tx_count);
+            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
+            /* We should now wait enough time for everything to clear through an analogue modem at the far end. */
+            delay = bits_to_us(s, fe->hdlc_tx.extra_bits);
+            break;
+        case T38_TIMED_STEP_HDLC_MODEM_5:
+            /* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point.
+               A T38_IND_NO_SIGNAL should always be OK. */
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            return delay;
+        }
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_ced(t38_terminal_state_t *s)
+{
+    t38_terminal_front_end_state_t *fe;
+    int delay;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_CED:
+            /* It seems common practice to start with a no signal indicator, though
+               this is not a specified requirement. Since we should be sending 200ms
+               of silence, starting the delay with a no signal indication makes sense.
+               We do need a 200ms delay, as that is a specification requirement. */
+            fe->timed_step = T38_TIMED_STEP_CED_2;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            delay = 200000;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_CED_2:
+            /* Initial 200ms delay over. Send the CED indicator */
+            fe->timed_step = T38_TIMED_STEP_CED_3;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_CED, fe->t38.indicator_tx_count);
+            fe->current_tx_data_type = T38_DATA_NONE;
+            break;
+        case T38_TIMED_STEP_CED_3:
+            /* End of CED */
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
+            return 0;
+        }
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int stream_cng(t38_terminal_state_t *s)
+{
+    t38_terminal_front_end_state_t *fe;
+    int delay;
+
+    fe = &s->t38_fe;
+    for (delay = 0;  delay == 0;  )
+    {
+        switch (fe->timed_step)
+        {
+        case T38_TIMED_STEP_CNG:
+            /* It seems common practice to start with a no signal indicator, though
+               this is not a specified requirement of the T.38 spec. Since we should
+               be sending 200ms of silence, according to T.30, starting that delay with
+               a no signal indication makes sense. */
+            fe->timed_step = T38_TIMED_STEP_CNG_2;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
+            delay = 200000;
+            fe->next_tx_samples = fe->samples;
+            break;
+        case T38_TIMED_STEP_CNG_2:
+            /* Initial short delay over. Send the CNG indicator. CNG persists until something
+               coming the other way interrupts it, or a long timeout controlled by the T.30 engine
+               expires. */
+            fe->timed_step = T38_TIMED_STEP_NONE;
+            delay = t38_core_send_indicator(&fe->t38, T38_IND_CNG, fe->t38.indicator_tx_count);
+            fe->current_tx_data_type = T38_DATA_NONE;
+            return delay;
+        }
+    }
+    return delay;
+}
+/*- End of function --------------------------------------------------------*/
+
+int t38_terminal_send_timeout(t38_terminal_state_t *s, int samples)
+{
+    t38_terminal_front_end_state_t *fe;
+    int delay;
 
     fe = &s->t38_fe;
     if (fe->current_rx_type == T30_MODEM_DONE  ||  fe->current_tx_type == T30_MODEM_DONE)
@@ -577,7 +840,7 @@
     {
         span_log(&s->logging, SPAN_LOG_FLOW, "Timeout mid-receive\n");
         fe->timeout_rx_samples = 0;
-        t30_front_end_status(&s->t30, T30_FRONT_END_RECEIVE_COMPLETE);
+        front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE);
     }
     if (fe->timed_step == T38_TIMED_STEP_NONE)
         return FALSE;
@@ -586,205 +849,28 @@
     if (fe->ms_per_tx_chunk  &&  fe->samples < fe->next_tx_samples)
         return FALSE;
     /* Its time to send something */
-    switch (fe->timed_step)
+    delay = 0;
+    switch (fe->timed_step & 0xFFF0)
     {
     case T38_TIMED_STEP_NON_ECM_MODEM:
-        /* Create a 75ms silence */
-        if (fe->t38.current_tx_indicator != T38_IND_NO_SIGNAL)
-            t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2;
-        fe->next_tx_samples += ms_to_samples(75);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_2:
-        /* Switch on a fast modem, and give the training time to complete */
-        t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3;
-        fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].training);
-        if ((fe->chunking_modes & T38_CHUNKING_ALLOW_TEP_TIME))
-            fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].tep);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_3:
-        /* Send a chunk of non-ECM image data */
-        /* T.38 says it is OK to send the last of the non-ECM data in the signal end message.
-           However, I think the early versions of T.38 said the signal end message should not
-           contain data. Hopefully, following the current spec will not cause compatibility
-           issues. */
-        len = t30_non_ecm_get_chunk(&s->t30, buf, fe->octets_per_data_packet);
-        bit_reverse(buf, buf, len);
-        if (len < fe->octets_per_data_packet)
-        {
-            /* That's the end of the image data. Do a little padding now */
-            memset(buf + len, 0, fe->octets_per_data_packet - len);
-            fe->non_ecm_trailer_bytes = 3*fe->octets_per_data_packet + len;
-            len = fe->octets_per_data_packet;
-            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_4;
-        }
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
-        fe->next_tx_samples += bits_to_samples(s, 8*len);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_4:
-        /* This pads the end of the data with some zeros. If we just stop abruptly
-           at the end of the EOLs, some ATAs fail to clean up properly before
-           shutting down their transmit modem, and the last few rows of the image
-           get corrupted. Simply delaying the no-signal message does not help for
-           all implentations. It often appears to be ignored. */
-        len = fe->octets_per_data_packet;
-        fe->non_ecm_trailer_bytes -= len;
-        if (fe->non_ecm_trailer_bytes <= 0)
-        {
-            len += fe->non_ecm_trailer_bytes;
-            memset(buf, 0, len);
-            t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, buf, len, fe->t38.data_end_tx_count);
-            fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
-            /* Allow a bit more time than the data will take to play out, to ensure the far ATA does not
-               cut things short. */
-            fe->next_tx_samples += (bits_to_samples(s, 8*len) + ms_to_samples(60));
-            break;
-        }
-        memset(buf, 0, len);
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, fe->t38.data_tx_count);
-        fe->next_tx_samples += bits_to_samples(s, 8*len);
-        break;
-    case T38_TIMED_STEP_NON_ECM_MODEM_5:
-        /* This should not be needed, since the message above indicates the end of the signal, but it
-           seems like it can improve compatibility with quirky implementations. */
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NONE;
-        t30_front_end_status(&s->t30, T30_FRONT_END_SEND_STEP_COMPLETE);
+        delay = stream_non_ecm(s);
         break;
     case T38_TIMED_STEP_HDLC_MODEM:
-        /* Send HDLC preambling */
-        t38_core_send_indicator(&fe->t38, fe->next_tx_indicator, fe->t38.indicator_tx_count);
-        fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].training + startup_time[fe->next_tx_indicator].flags);
-        if (fe->chunking_modes & T38_CHUNKING_ALLOW_TEP_TIME)
-            fe->next_tx_samples += ms_to_samples(startup_time[fe->next_tx_indicator].tep);
-        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM_2:
-        /* Send a chunk of HDLC data */
-        i = fe->tx.len - fe->tx.ptr;
-        if (fe->octets_per_data_packet >= i)
-        {
-            /* The last part of an HDLC frame */
-            if (fe->chunking_modes & T38_CHUNKING_MERGE_FCS_WITH_DATA)
-            {
-                /* Copy the data, as we might be about to refill the buffer it is in */
-                memcpy(buf, &fe->tx.buf[fe->tx.ptr], i);
-                data_fields[0].field_type = T38_FIELD_HDLC_DATA;
-                data_fields[0].field = buf;
-                data_fields[0].field_len = i;
-
-                /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
-                previous = fe->current_tx_data_type;
-                fe->tx.ptr = 0;
-                fe->tx.len = 0;
-                t30_front_end_status(&s->t30, T30_FRONT_END_SEND_STEP_COMPLETE);
-                /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
-                if (fe->tx.len < 0)
-                {
-                    data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END;
-                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
-                    /* We add a bit of extra time here, as with some implementations
-                       the carrier falling too abruptly causes data loss. */
-                    fe->next_tx_samples += (bits_to_samples(s, i*8 + fe->tx.extra_bits) + ms_to_samples(100));
-                }
-                else
-                {
-                    data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK;
-                    fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
-                    fe->next_tx_samples += bits_to_samples(s, i*8 + fe->tx.extra_bits);
-                }
-                data_fields[1].field = NULL;
-                data_fields[1].field_len = 0;
-                t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, fe->t38.data_tx_count);
-            }
-            else
-            {
-                t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &fe->tx.buf[fe->tx.ptr], i, fe->t38.data_tx_count);
-                fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
-                fe->next_tx_samples += bits_to_samples(s, i*8);
-            }
-            break;
-        }
-        t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &fe->tx.buf[fe->tx.ptr], fe->octets_per_data_packet, fe->t38.data_tx_count);
-        fe->tx.ptr += fe->octets_per_data_packet;
-        fe->next_tx_samples += bits_to_samples(s, fe->octets_per_data_packet*8);
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM_3:
-        /* End of HDLC frame */
-        previous = fe->current_tx_data_type;
-        fe->tx.ptr = 0;
-        fe->tx.len = 0;
-        t30_front_end_status(&s->t30, T30_FRONT_END_SEND_STEP_COMPLETE);
-        /* The above step should have got the next HDLC step ready - either another frame, or an instruction to stop transmission. */
-        if (fe->tx.len < 0)
-        {
-            /* End of transmission */
-            t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK_SIG_END, NULL, 0, fe->t38.data_end_tx_count);
-            fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
-            fe->next_tx_samples += (bits_to_samples(s, fe->tx.extra_bits) + ms_to_samples(100));
-            break;
-        }
-        if (fe->tx.len == 0)
-        {
-            /* Now, how did we get here? We have finished a frame, but have no new frame to
-               send, and no end of transmission condition. */
-            span_log(&s->logging, SPAN_LOG_FLOW, "No new frame or end transmission condition.\n");
-        }
-        /* Finish the current frame off, and prepare for the next one. */
-        t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, fe->t38.data_tx_count);
-        fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
-        /* We should now wait 3 octet times - the duration of the FCS + a flag octet - and send the
-           next chunk. To give a little more latitude, and allow for stuffing in the FCS, add
-           time for an extra flag octet. */
-        fe->next_tx_samples += bits_to_samples(s, fe->tx.extra_bits);
-        break;
-    case T38_TIMED_STEP_HDLC_MODEM_4:
-        /* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point.
-           A T38_IND_NO_SIGNAL should always be OK. */
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->timed_step = T38_TIMED_STEP_NONE;
-        t30_front_end_status(&s->t30, T30_FRONT_END_SEND_STEP_COMPLETE);
+        delay = stream_hdlc(s);
         break;
     case T38_TIMED_STEP_CED:
-        /* It seems common practice to start with a no signal indicator, though
-           this is not a specified requirement. Since we should be sending 200ms
-           of silence, starting the delay with a no signal indication makes sense.
-           We do need a 200ms delay, as that is a specification requirement. */
-        fe->timed_step = T38_TIMED_STEP_CED_2;
-        fe->next_tx_samples = fe->samples + ms_to_samples(200);
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
-        break;
-    case T38_TIMED_STEP_CED_2:
-        /* Initial 200ms delay over. Send the CED indicator */
-        fe->next_tx_samples = fe->samples + ms_to_samples(3000);
-        fe->timed_step = T38_TIMED_STEP_PAUSE;
-        t38_core_send_indicator(&fe->t38, T38_IND_CED, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
+        delay = stream_ced(s);
         break;
     case T38_TIMED_STEP_CNG:
-        /* It seems common practice to start with a no signal indicator, though
-           this is not a specified requirement. Since we should be sending 200ms
-           of silence, starting the delay with a no signal indication makes sense.
-           We do need a 200ms delay, as that is a specification requirement. */
-        fe->timed_step = T38_TIMED_STEP_CNG_2;
-        fe->next_tx_samples = fe->samples + ms_to_samples(200);
-        t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
-        break;
-    case T38_TIMED_STEP_CNG_2:
-        /* Initial short delay over. Send the CNG indicator */
-        fe->timed_step = T38_TIMED_STEP_NONE;
-        t38_core_send_indicator(&fe->t38, T38_IND_CNG, fe->t38.indicator_tx_count);
-        fe->current_tx_data_type = T38_DATA_NONE;
+        delay = stream_cng(s);
         break;
     case T38_TIMED_STEP_PAUSE:
         /* End of timed pause */
         fe->timed_step = T38_TIMED_STEP_NONE;
-        t30_front_end_status(&s->t30, T30_FRONT_END_SEND_STEP_COMPLETE);
+        front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
         break;
     }
+    fe->next_tx_samples += us_to_samples(delay);
     return FALSE;
 }
 /*- End of function --------------------------------------------------------*/
@@ -799,119 +885,122 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+static void start_tx(t38_terminal_front_end_state_t *fe, int use_hdlc)
+{
+    /* The actual transmission process depends on whether we are sending at a paced manner,
+       for interaction with a traditional FAX machine, or streaming as fast as we can, normally
+       over a TCP connection to a machine directly connected to the internet. */
+    if (fe->ms_per_tx_chunk)
+    {
+        /* Start the paced packet transmission process. */
+        fe->timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
+        if (fe->next_tx_samples < fe->samples)
+            fe->next_tx_samples = fe->samples;
+    }
+    else
+    {
+        /* Start the fast streaming transmission process. */
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
 static void set_tx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc)
 {
     t38_terminal_state_t *s;
+    t38_terminal_front_end_state_t *fe;
 
     s = (t38_terminal_state_t *) user_data;
+    fe = &s->t38_fe;
     span_log(&s->logging, SPAN_LOG_FLOW, "Set tx type %d\n", type);
-    if (s->t38_fe.current_tx_type == type)
+    if (fe->current_tx_type == type)
         return;
 
     set_octets_per_data_packet(s, bit_rate);
     switch (type)
     {
     case T30_MODEM_NONE:
-        s->t38_fe.timed_step = T38_TIMED_STEP_NONE;
-        s->t38_fe.current_tx_data_type = T38_DATA_NONE;
+        /* If a "no signal" indicator is waiting to be played out, don't disturb it. */
+        if (fe->timed_step != T38_TIMED_STEP_NON_ECM_MODEM_5  &&  fe->timed_step != T38_TIMED_STEP_HDLC_MODEM_5)
+            fe->timed_step = T38_TIMED_STEP_NONE;
+        fe->current_tx_data_type = T38_DATA_NONE;
         break;
     case T30_MODEM_PAUSE:
-        s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(short_train);
-        s->t38_fe.timed_step = T38_TIMED_STEP_PAUSE;
-        s->t38_fe.current_tx_data_type = T38_DATA_NONE;
+        fe->next_tx_samples = fe->samples + ms_to_samples(short_train);
+        fe->timed_step = T38_TIMED_STEP_PAUSE;
+        fe->current_tx_data_type = T38_DATA_NONE;
         break;
     case T30_MODEM_CED:
+        fe->next_tx_samples = fe->samples;
+        fe->timed_step = T38_TIMED_STEP_CED;
+        fe->current_tx_data_type = T38_DATA_NONE;
+        break;
     case T30_MODEM_CNG:
-        if (type == T30_MODEM_CED)
-        {
-            /* A 200ms initial delay is specified. Delay this amount before the CED indicator is sent. */
-            s->t38_fe.next_tx_samples = s->t38_fe.samples;
-            s->t38_fe.timed_step = T38_TIMED_STEP_CED;
-        }
-        else
-        {
-            /* Allow a short initial delay, so the chances of the other end actually being ready to receive
-               the CNG indicator are improved. */
-            s->t38_fe.next_tx_samples = s->t38_fe.samples;
-            s->t38_fe.timed_step = T38_TIMED_STEP_CNG;
-        }
-        s->t38_fe.current_tx_data_type = T38_DATA_NONE;
+        fe->next_tx_samples = fe->samples;
+        fe->timed_step = T38_TIMED_STEP_CNG;
+        fe->current_tx_data_type = T38_DATA_NONE;
         break;
     case T30_MODEM_V21:
-        if (s->t38_fe.current_tx_type > T30_MODEM_V21)
-        {
-            /* Pause before switching from phase C, as per T.30. If we omit this, the receiver
-               might not see the carrier fall between the high speed and low speed sections. */
-            s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(75);
-        }
-        else
-        {
-            s->t38_fe.next_tx_samples = s->t38_fe.samples;
-        }
-        s->t38_fe.next_tx_indicator = T38_IND_V21_PREAMBLE;
-        s->t38_fe.current_tx_data_type = T38_DATA_V21;
-        s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
+        fe->next_tx_indicator = T38_IND_V21_PREAMBLE;
+        fe->current_tx_data_type = T38_DATA_V21;
+        start_tx(fe, use_hdlc);
         break;
     case T30_MODEM_V27TER:
         switch (bit_rate)
         {
         case 2400:
-            s->t38_fe.next_tx_indicator = T38_IND_V27TER_2400_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V27TER_2400;
+            fe->next_tx_indicator = T38_IND_V27TER_2400_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V27TER_2400;
             break;
         case 4800:
-            s->t38_fe.next_tx_indicator = T38_IND_V27TER_4800_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V27TER_4800;
+            fe->next_tx_indicator = T38_IND_V27TER_4800_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V27TER_4800;
             break;
         }
-        s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
-        s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(30);
+        start_tx(fe, use_hdlc);
         break;
     case T30_MODEM_V29:
         switch (bit_rate)
         {
         case 7200:
-            s->t38_fe.next_tx_indicator = T38_IND_V29_7200_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V29_7200;
+            fe->next_tx_indicator = T38_IND_V29_7200_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V29_7200;
             break;
         case 9600:
-            s->t38_fe.next_tx_indicator = T38_IND_V29_9600_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V29_9600;
+            fe->next_tx_indicator = T38_IND_V29_9600_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V29_9600;
             break;
         }
-        s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
-        s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(30);
+        start_tx(fe, use_hdlc);
         break;
     case T30_MODEM_V17:
         switch (bit_rate)
         {
         case 7200:
-            s->t38_fe.next_tx_indicator = (short_train)  ?  T38_IND_V17_7200_SHORT_TRAINING  :  T38_IND_V17_7200_LONG_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V17_7200;
+            fe->next_tx_indicator = (short_train)  ?  T38_IND_V17_7200_SHORT_TRAINING  :  T38_IND_V17_7200_LONG_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V17_7200;
             break;
         case 9600:
-            s->t38_fe.next_tx_indicator = (short_train)  ?  T38_IND_V17_9600_SHORT_TRAINING  :  T38_IND_V17_9600_LONG_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V17_9600;
+            fe->next_tx_indicator = (short_train)  ?  T38_IND_V17_9600_SHORT_TRAINING  :  T38_IND_V17_9600_LONG_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V17_9600;
             break;
         case 12000:
-            s->t38_fe.next_tx_indicator = (short_train)  ?  T38_IND_V17_12000_SHORT_TRAINING  :  T38_IND_V17_12000_LONG_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V17_12000;
+            fe->next_tx_indicator = (short_train)  ?  T38_IND_V17_12000_SHORT_TRAINING  :  T38_IND_V17_12000_LONG_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V17_12000;
             break;
         case 14400:
-            s->t38_fe.next_tx_indicator = (short_train)  ?  T38_IND_V17_14400_SHORT_TRAINING  :  T38_IND_V17_14400_LONG_TRAINING;
-            s->t38_fe.current_tx_data_type = T38_DATA_V17_14400;
+            fe->next_tx_indicator = (short_train)  ?  T38_IND_V17_14400_SHORT_TRAINING  :  T38_IND_V17_14400_LONG_TRAINING;
+            fe->current_tx_data_type = T38_DATA_V17_14400;
             break;
         }
-        s->t38_fe.timed_step = (use_hdlc)  ?  T38_TIMED_STEP_HDLC_MODEM  :  T38_TIMED_STEP_NON_ECM_MODEM;
-        s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(30);
+        start_tx(fe, use_hdlc);
         break;
     case T30_MODEM_DONE:
         span_log(&s->logging, SPAN_LOG_FLOW, "FAX exchange complete\n");
-        s->t38_fe.timed_step = T38_TIMED_STEP_NONE;
-        s->t38_fe.current_tx_data_type = T38_DATA_NONE;
+        fe->timed_step = T38_TIMED_STEP_NONE;
+        fe->current_tx_data_type = T38_DATA_NONE;
         break;
     }
-    s->t38_fe.current_tx_type = type;
+    fe->current_tx_type = type;
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -944,6 +1033,7 @@
         s->t38_fe.chunking_modes |= T38_CHUNKING_ALLOW_TEP_TIME;
     else
         s->t38_fe.chunking_modes &= ~T38_CHUNKING_ALLOW_TEP_TIME;
+    t38_set_tep_handling(&s->t38_fe.t38, use_tep);
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -963,6 +1053,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+t38_core_state_t *t38_terminal_get_t38_core_state(t38_terminal_state_t *s)
+{
+    return &s->t38_fe.t38;
+}
+/*- End of function --------------------------------------------------------*/
+
 static int t38_terminal_t38_fe_init(t38_terminal_state_t *t,
                                     t38_tx_packet_handler_t *tx_packet_handler,
                                     void *tx_packet_user_data)
@@ -977,21 +1073,29 @@
                   (void *) t,
                   tx_packet_handler,
                   tx_packet_user_data);
+    s->t38.fastest_image_data_rate = 14400;
+
     s->rx_signal_present = FALSE;
     s->timed_step = T38_TIMED_STEP_NONE;
-    s->tx.ptr = 0;
-    s->iaf = T30_IAF_MODE_T37 | T30_IAF_MODE_T38;
+    //s->iaf = T30_IAF_MODE_T37 | T30_IAF_MODE_T38;
+    s->iaf = T30_IAF_MODE_T38;
 
     s->current_tx_data_type = T38_DATA_NONE;
     s->next_tx_samples = 0;
     s->chunking_modes = T38_CHUNKING_ALLOW_TEP_TIME;
 
-    s->t38.fastest_image_data_rate = 14400;
+    s->hdlc_tx.ptr = 0;
 
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *t38_terminal_get_logging_state(t38_terminal_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 t38_terminal_state_t *t38_terminal_init(t38_terminal_state_t *s,
                                         int calling_party,
                                         t38_tx_packet_handler_t *tx_packet_handler,

Modified: freeswitch/trunk/libs/spandsp/src/t4.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/t4.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/t4.c	Tue Jan 27 22:48:03 2009
@@ -24,7 +24,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t4.c,v 1.113 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t4.c,v 1.119 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*
@@ -60,7 +60,7 @@
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -72,13 +72,13 @@
 #include <time.h>
 #include <memory.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <tiffio.h>
 
 #include "spandsp/telephony.h"
@@ -87,7 +87,17 @@
 #include "spandsp/async.h"
 #include "spandsp/t4.h"
 
-#define CM_PER_INCH     2.54f
+#include "spandsp/private/logging.h"
+#include "spandsp/private/t4.h"
+
+#define CM_PER_INCH                 2.54f
+
+#define EOLS_TO_END_T4_TX_PAGE      6
+#define EOLS_TO_END_T6_TX_PAGE      2
+
+#define EOLS_TO_END_ANY_RX_PAGE     6
+#define EOLS_TO_END_T4_RX_PAGE      5
+#define EOLS_TO_END_T6_RX_PAGE      2
 
 /* Finite state machine state codes */
 enum
@@ -780,7 +790,7 @@
     s->rx_bits = 0;
     s->rx_skip_bits = 0;
     s->rx_bitstream = 0;
-    s->consecutive_eols = 5;
+    s->consecutive_eols = EOLS_TO_END_ANY_RX_PAGE;
 
     s->image_size = 0;
     return 0;
@@ -824,18 +834,23 @@
         return FALSE;
     if (s->consecutive_eols)
     {
-        /* Check if the image has already terminated */
-        if (s->consecutive_eols >= 5)
+        /* Check if the image has already terminated. */
+        if (s->consecutive_eols >= EOLS_TO_END_ANY_RX_PAGE)
             return TRUE;
+        /* Check if the image hasn't even started. */
         if (s->consecutive_eols < 0)
         {
             /* We are waiting for the very first EOL (1D or 2D only). */
+            /* We need to take this bit by bit, as the EOL could be anywhere,
+               and any junk could preceed it. */
             while ((s->rx_bitstream & 0xFFF) != 0x800)
             {
                 s->rx_bitstream >>= 1;
                 if (--s->rx_bits < 13)
                     return FALSE;
             }
+            /* We have an EOL, so now the page begins and we can proceed to
+               process the bit stream as image data. */
             s->consecutive_eols = 0;
             if (s->line_encoding == T4_COMPRESSION_ITU_T4_1D)
             {
@@ -847,7 +862,6 @@
                 s->row_is_2d = !(s->rx_bitstream & 0x1000);
                 force_drop_rx_bits(s, 13);
             }
-            /* We can proceed to processing the bit stream as an image now */
         }
     }
 
@@ -864,11 +878,39 @@
             STATE_TRACE("EOL\n");
             if (s->row_len == 0)
             {
-                if (++s->consecutive_eols >= 5)
-                    return TRUE;
+                /* A zero length row - i.e. 2 consecutive EOLs - is distinctly
+                   the end of page condition. That's all we actually get on a
+                   T.6 page. However, there are a minimum of 6 EOLs at the end of
+                   any T.4 page. We can look for more than 2 EOLs in case bit
+                   errors simulate the end of page condition at the wrong point.
+                   Such robust checking is irrelevant for a T.6 page, as it should
+                   be error free. */
+                /* Note that for a T.6 page we should get here on the very first
+                   EOL, as the row length should be zero at that point. Therefore
+                   we should count up both EOLs, unless there is some bogus partial
+                   row ahead of them. */
+                s->consecutive_eols++;
+                if (s->line_encoding == T4_COMPRESSION_ITU_T6)
+                {
+                    if (s->consecutive_eols >= EOLS_TO_END_T6_RX_PAGE)
+                    {
+                        s->consecutive_eols = EOLS_TO_END_ANY_RX_PAGE;
+                        return TRUE;
+                    }
+                }
+                else
+                {
+                    if (s->consecutive_eols >= EOLS_TO_END_T4_RX_PAGE)
+                    {
+                        s->consecutive_eols = EOLS_TO_END_ANY_RX_PAGE;
+                        return TRUE;
+                    }
+                }
             }
             else
             {
+                /* The EOLs are not back-to-back, so they are not part of the
+                   end of page condition. */
                 if (s->run_length > 0)
                     add_run_to_row(s);
                 s->consecutive_eols = 0;
@@ -876,14 +918,14 @@
                     return TRUE;
                 update_row_bit_info(s);
             }
-            if (s->line_encoding == T4_COMPRESSION_ITU_T4_1D)
+            if (s->line_encoding == T4_COMPRESSION_ITU_T4_2D)
             {
-                force_drop_rx_bits(s, 12);
+                s->row_is_2d = !(s->rx_bitstream & 0x1000);
+                force_drop_rx_bits(s, 13);
             }
             else
             {
-                s->row_is_2d = !(s->rx_bitstream & 0x1000);
-                force_drop_rx_bits(s, 13);
+                force_drop_rx_bits(s, 12);
             }
             s->its_black = FALSE;
             s->black_white = 0;
@@ -1206,7 +1248,7 @@
 
     s->row_is_2d = (s->line_encoding == T4_COMPRESSION_ITU_T6);
     /* We start at -1 EOLs for 1D and 2D decoding, as an indication we are waiting for the
-       first EOL. */
+       first EOL. T.6 coding starts without any preamble. */
     s->consecutive_eols = (s->line_encoding == T4_COMPRESSION_ITU_T6)  ?  0  :  -1;
 
     s->bad_rows = 0;
@@ -1456,8 +1498,8 @@
                         a0                  a1                      a2
 
 
-        a)	Pass mode
-	        This mode is identified when the position of b2 lies to the left of a1. When this mode
+        a)  Pass mode
+            This mode is identified when the position of b2 lies to the left of a1. When this mode
             has been coded, a0 is set on the element of the coding line below b2 in preparation for
             the next coding (i.e. on a0').
             
@@ -1478,16 +1520,16 @@
                                 Not pass mode
 
 
-        b)	Vertical mode
-	        When this mode is identified, the position of a1 is coded relative to the position of b1.
+        b)  Vertical mode
+            When this mode is identified, the position of a1 is coded relative to the position of b1.
             The relative distance a1b1 can take on one of seven values V(0), VR(1), VR(2), VR(3),
             VL(1), VL(2) and VL(3), each of which is represented by a separate code word. The
             subscripts R and L indicate that a1 is to the right or left respectively of b1, and the
             number in brackets indicates the value of the distance a1b1. After vertical mode coding
             has occurred, the position of a0 is set on a1 (see figure below).
 
-        c)	Horizontal mode
-	        When this mode is identified, both the run-lengths a0a1 and a1a2 are coded using the code
+        c)  Horizontal mode
+            When this mode is identified, both the run-lengths a0a1 and a1a2 are coded using the code
             words H + M(a0a1) + M(a1a2). H is the flag code word 001 taken from the two-dimensional
             code table. M(a0a1) and M(a1a2) are code words which represent the length and "colour"
             of the runs a0a1 and a1a2 respectively and are taken from the appropriate white or black
@@ -1901,14 +1943,14 @@
     if (s->line_encoding == T4_COMPRESSION_ITU_T6)
     {
         /* Attach an EOFB (end of facsimile block) to the end of the page */
-        encode_eol(s);
-        encode_eol(s);
+        for (i = 0;  i < EOLS_TO_END_T6_TX_PAGE;  i++)
+            encode_eol(s);
     }
     else
     {
         /* Attach a return to control (RTC == 6 x EOLs) to the end of the page */
         s->row_is_2d = FALSE;
-        for (i = 0;  i < 6;  i++)
+        for (i = 0;  i < EOLS_TO_END_T4_TX_PAGE;  i++)
             encode_eol(s);
     }
 
@@ -2079,7 +2121,7 @@
        more reliable. */
     max = 0;
     while (TIFFSetDirectory(s->tiff_file, (tdir_t) max))
-    	max++;
+        max++;
     s->pages_in_file = max;
     /* Back to the previous page */
     if (!TIFFSetDirectory(s->tiff_file, (tdir_t) s->pages_transferred))

Modified: freeswitch/trunk/libs/spandsp/src/testcpuid.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/testcpuid.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/testcpuid.c	Tue Jan 27 22:48:03 2009
@@ -23,13 +23,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: testcpuid.c,v 1.12 2008/05/13 13:17:24 steveu Exp $
+ * $Id: testcpuid.c,v 1.13 2009/01/05 13:48:31 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>

Modified: freeswitch/trunk/libs/spandsp/src/time_scale.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/time_scale.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/time_scale.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,13 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: time_scale.c,v 1.24 2008/09/19 14:02:05 steveu Exp $
+ * $Id: time_scale.c,v 1.27 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -38,18 +38,20 @@
 #include <fcntl.h>
 #include <time.h>
 #include <limits.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/time_scale.h"
 #include "spandsp/saturated.h"
 
+#include "spandsp/private/time_scale.h"
+
 /*
     Time scaling for speech, based on the Pointer Interval Controlled
     OverLap and Add (PICOLA) method, developed by Morita Naotaka.

Modified: freeswitch/trunk/libs/spandsp/src/tone_detect.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/tone_detect.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/tone_detect.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_detect.c,v 1.47 2008/07/02 14:48:26 steveu Exp $
+ * $Id: tone_detect.c,v 1.49 2009/01/28 03:41:27 steveu Exp $
  */
  
 /*! \file tone_detect.h */
@@ -33,13 +33,13 @@
 
 #include <inttypes.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <string.h>
 #include <stdio.h>
 #include <time.h>
@@ -51,6 +51,8 @@
 #include "spandsp/tone_detect.h"
 #include "spandsp/tone_generate.h"
 
+#include "spandsp/private/tone_detect.h"
+
 #if !defined(M_PI)
 /* C99 systems may not define M_PI */
 #define M_PI 3.14159265358979323846264338327

Modified: freeswitch/trunk/libs/spandsp/src/tone_generate.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/tone_generate.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/tone_generate.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_generate.c,v 1.46 2008/09/11 15:13:42 steveu Exp $
+ * $Id: tone_generate.c,v 1.48 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -37,13 +37,13 @@
 #include <stdio.h>
 #include <time.h>
 #include <fcntl.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/dc_restore.h"
@@ -51,6 +51,8 @@
 #include "spandsp/dds.h"
 #include "spandsp/tone_generate.h"
 
+#include "spandsp/private/tone_generate.h"
+
 #if !defined(M_PI)
 /* C99 systems may not define M_PI */
 #define M_PI 3.14159265358979323846264338327

Modified: freeswitch/trunk/libs/spandsp/src/v17rx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v17rx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v17rx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v17rx.c,v 1.123 2008/09/18 15:59:55 steveu Exp $
+ * $Id: v17rx.c,v 1.129 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -60,6 +60,9 @@
 #include "spandsp/v17tx.h"
 #include "spandsp/v17rx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v17rx.h"
+
 #include "v17tx_constellation_maps.h"
 #include "v17rx_constellation_maps.h"
 #if defined(SPANDSP_USE_FIXED_POINT)
@@ -111,6 +114,24 @@
 #define SYNC_CROSS_CORR_COEFF_B          0.700036f    /* alpha*sin(high_edge) */
 #define SYNC_CROSS_CORR_COEFF_C         -0.449451f    /* -alpha*sin(low_edge) */
 
+#if defined(SPANDSP_USE_FIXED_POINTx)
+static const int constellation_spacing[4] =
+{
+    ((int)(FP_FACTOR*1.414f),
+    ((int)(FP_FACTOR*2.0f)},
+    ((int)(FP_FACTOR*2.828f)},
+    ((int)(FP_FACTOR*4.0f)},
+};
+#else
+static const float constellation_spacing[4] =
+{
+    1.414f,
+    2.0f,
+    2.828f,
+    4.0f
+};
+#endif
+
 float v17_rx_carrier_frequency(v17_rx_state_t *s)
 {
     return dds_frequencyf(s->carrier_phase_rate);
@@ -777,7 +798,7 @@
         else if (s->training_count >= V17_TRAINING_SEG_2_LEN)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Long training error %f\n", s->training_error);
-            if (s->training_error < 40.0f)
+            if (s->training_error < 20.0f*1.414f*constellation_spacing[s->space_map])
             {
                 s->training_count = 0;
                 s->training_error = 0.0f;
@@ -851,10 +872,10 @@
             span_log(&s->logging, SPAN_LOG_FLOW, "Short training error %f\n", s->training_error);
             s->carrier_track_i = 100.0f;
             s->carrier_track_p = 500000.0f;
-            /* TODO: This was changed from 20.0 to 200.0 after studying real world failures.
+            /* TODO: This was increased by a factor of 10 after studying real world failures.
                      However, it is not clear why this is an improvement, If something gives
-                     a training error way over 20, surely it shouldn't decode too well? */
-            if (s->training_error < 200.0f)
+                     a huge training error, surely it shouldn't decode too well? */
+            if (s->training_error < (V17_TRAINING_SHORT_SEG_2_LEN - 8)*4.0f*constellation_spacing[s->space_map])
             {
                 s->training_count = 0;
                 s->training_stage = TRAINING_STAGE_TCM_WINDUP;
@@ -897,14 +918,10 @@
         s->training_error += powerf(&zz);
         if (++s->training_count >= V17_TRAINING_SEG_4_LEN)
         {
-#if defined(IAXMODEM_STUFF)
-            if (s->training_error < 80.0f)
-#else
-            if (s->training_error < 30.0f)
-#endif
+            if (s->training_error < V17_TRAINING_SEG_4_LEN*constellation_spacing[s->space_map])
             {
                 /* We are up and running */
-                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded (constellation mismatch %f)\n", s->training_error);
+                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded at %dbps (constellation mismatch %f)\n", s->bit_rate, s->training_error);
                 report_status_change(s, SIG_STATUS_TRAINING_SUCCEEDED);
                 /* Apply some lag to the carrier off condition, to ensure the last few bits get pushed through
                    the processing. */
@@ -1107,6 +1124,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v17_rx_get_logging_state(v17_rx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v17_rx_restart(v17_rx_state_t *s, int bit_rate, int short_train)
 {
     int i;

Modified: freeswitch/trunk/libs/spandsp/src/v17tx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v17tx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v17tx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v17tx.c,v 1.64 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v17tx.c,v 1.69 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -54,6 +54,9 @@
 
 #include "spandsp/v17tx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v17tx.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #define SPANDSP_USE_FIXED_POINTx
 #endif
@@ -106,6 +109,11 @@
     {
         1, 0, 2, 3
     };
+#if defined(SPANDSP_USE_FIXED_POINT)
+    static const complexi16_t zero = {0, 0};
+#else
+    static const complexf_t zero = {0.0f, 0.0f};
+#endif
     int bits;
     int shift;
 
@@ -121,11 +129,7 @@
             if (s->training_step <= V17_TRAINING_SEG_1)
             {
                 /* Optional segment: silence (talker echo protection) */
-#if defined(SPANDSP_USE_FIXED_POINT)
-                return complex_seti16(0, 0);
-#else
-                return complex_setf(0.0f, 0.0f);
-#endif
+                return zero;
             }
             /* Segment 1: ABAB... */
             return v17_abcd_constellation[(s->training_step & 1) ^ 1];
@@ -144,7 +148,7 @@
     }
     /* Segment 3: Bridge... */
     shift = ((s->training_step - V17_TRAINING_SEG_3 - 1) & 0x7) << 1;
-    span_log(&s->logging, SPAN_LOG_FLOW, "Seg 3 shift %d\n", shift);
+    //span_log(&s->logging, SPAN_LOG_FLOW, "Seg 3 shift %d\n", shift);
     bits = scramble(s, V17_BRIDGE_WORD >> shift);
     bits = (bits << 1) | scramble(s, V17_BRIDGE_WORD >> (shift + 1));
     s->constellation_state = (s->constellation_state + dibit_to_step[bits]) & 3;
@@ -332,6 +336,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v17_tx_get_logging_state(v17_tx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v17_tx_restart(v17_tx_state_t *s, int bit_rate, int tep, int short_train)
 {
     switch (bit_rate)

Modified: freeswitch/trunk/libs/spandsp/src/v22bis_rx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v22bis_rx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v22bis_rx.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v22bis_rx.c,v 1.42 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v22bis_rx.c,v 1.46 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -30,20 +30,20 @@
 /* THIS IS A WORK IN PROGRESS - NOT YET FUNCTIONAL! */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -58,6 +58,9 @@
 #include "spandsp/v29rx.h"
 #include "spandsp/v22bis.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v22bis.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v22bis_rx_1200_floating_rrc.h"
 #include "v22bis_rx_2400_floating_rrc.h"

Modified: freeswitch/trunk/libs/spandsp/src/v22bis_tx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v22bis_tx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v22bis_tx.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v22bis_tx.c,v 1.44 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v22bis_tx.c,v 1.49 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -30,20 +30,20 @@
 /* THIS IS A WORK IN PROGRESS - NOT YET FUNCTIONAL! */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -57,6 +57,9 @@
 #include "spandsp/v29rx.h"
 #include "spandsp/v22bis.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v22bis.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v22bis_tx_fixed_rrc.h"
 #else
@@ -603,6 +606,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v22bis_get_logging_state(v22bis_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v22bis_restart(v22bis_state_t *s, int bit_rate)
 {
     if (bit_rate != 2400  &&  bit_rate != 1200)

Modified: freeswitch/trunk/libs/spandsp/src/v27ter_rx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v27ter_rx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v27ter_rx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v27ter_rx.c,v 1.107 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v27ter_rx.c,v 1.113 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -59,6 +59,9 @@
 #include "spandsp/v29rx.h"
 #include "spandsp/v27ter_rx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v27ter_rx.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v27ter_rx_4800_fixed_rrc.h"
 #include "v27ter_rx_2400_fixed_rrc.h"
@@ -685,12 +688,14 @@
 #endif
         if (++s->training_count >= V27TER_TRAINING_SEG_6_LEN)
         {
-            if ((s->bit_rate == 4800  &&  s->training_error < 0.5f)
+            /* At 4800bps the symbols are 1.08238 (Euclidian) apart.
+               At 2400bps the symbols are 2.0 (Euclidian) apart. */
+            if ((s->bit_rate == 4800  &&  s->training_error < V27TER_TRAINING_SEG_6_LEN*0.25f)
                 ||
-                (s->bit_rate == 2400  &&  s->training_error < 1.0f))
+                (s->bit_rate == 2400  &&  s->training_error < V27TER_TRAINING_SEG_6_LEN*0.5f))
             {
                 /* We are up and running */
-                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded (constellation mismatch %f)\n", s->training_error);
+                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded at %dbps (constellation mismatch %f)\n", s->bit_rate, s->training_error);
                 report_status_change(s, SIG_STATUS_TRAINING_SUCCEEDED);
                 /* Apply some lag to the carrier off condition, to ensure the last few bits get pushed through
                    the processing. */
@@ -1016,6 +1021,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v27ter_rx_get_logging_state(v27ter_rx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v27ter_rx_restart(v27ter_rx_state_t *s, int bit_rate, int old_train)
 {
     span_log(&s->logging, SPAN_LOG_FLOW, "Restarting V.27ter\n");

Modified: freeswitch/trunk/libs/spandsp/src/v27ter_tx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v27ter_tx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v27ter_tx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v27ter_tx.c,v 1.66 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v27ter_tx.c,v 1.71 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -54,6 +54,9 @@
 
 #include "spandsp/v27ter_tx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v27ter_tx.h"
+
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v27ter_tx_4800_fixed_rrc.h"
 #include "v27ter_tx_2400_fixed_rrc.h"
@@ -148,6 +151,7 @@
         { 0000,   -1414},       /* 270deg */
         { 1000,   -1000}        /* 315deg */
     };
+    static const complexi16_t zero = {0, 0};
 #else
     static const complexf_t constellation[8] =
     {
@@ -160,6 +164,7 @@
         { 0.0f,   -1.414f},     /* 270deg */
         { 1.0f,   -1.0f}        /* 315deg */
     };
+    static const complexf_t zero = {0.0f, 0.0f};
 #endif
     int bits;
 
@@ -178,11 +183,7 @@
                 if (s->training_step <= V27TER_TRAINING_SEG_3)
                 {
                     /* Segment 2: Silence */
-#if defined(SPANDSP_USE_FIXED_POINT)
-                    return complex_seti16(0, 0);
-#else
-                    return complex_setf(0.0f, 0.0f);
-#endif
+                    return zero;
                 }
                 /* Segment 3: Regular reversals... */
                 s->constellation_state = (s->constellation_state + 4) & 7;
@@ -371,6 +372,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v27ter_tx_get_logging_state(v27ter_tx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v27ter_tx_restart(v27ter_tx_state_t *s, int bit_rate, int tep)
 {
     if (bit_rate != 4800  &&  bit_rate != 2400)

Modified: freeswitch/trunk/libs/spandsp/src/v29rx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v29rx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v29rx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v29rx.c,v 1.144 2008/09/18 14:59:30 steveu Exp $
+ * $Id: v29rx.c,v 1.150 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -58,6 +58,9 @@
 
 #include "spandsp/v29rx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v29rx.h"
+
 #include "v29tx_constellation_maps.h"
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v29rx_fixed_rrc.h"
@@ -511,7 +514,11 @@
     s->symbol_sync_dc_filter[0] = v;
     /* A little integration will now filter away much of the noise */
     s->baud_phase -= p;
+#if 0
     if (fabsf(s->baud_phase) > 100.0f)
+#else
+    if (fabsf(s->baud_phase) > 30.0f)
+#endif
     {
         if (s->baud_phase > 0.0f)
             i = (s->baud_phase > 1000.0f)  ?  5  :  1;
@@ -731,7 +738,7 @@
         if (++s->training_count >= V29_TRAINING_SEG_3_LEN)
         {
             span_log(&s->logging, SPAN_LOG_FLOW, "Constellation mismatch %f\n", s->training_error);
-            if (s->training_error < 100.0f)
+            if (s->training_error < 48.0f*2.0f)
             {
                 s->training_count = 0;
                 s->training_error = 0.0f;
@@ -772,10 +779,10 @@
 #endif
         if (++s->training_count >= V29_TRAINING_SEG_4_LEN)
         {
-            if (s->training_error < 50.0f)
+            if (s->training_error < 48.0f)
             {
                 /* We are up and running */
-                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded (constellation mismatch %f)\n", s->training_error);
+                span_log(&s->logging, SPAN_LOG_FLOW, "Training succeeded at %dbps (constellation mismatch %f)\n", s->bit_rate, s->training_error);
                 report_status_change(s, SIG_STATUS_TRAINING_SUCCEEDED);
                 /* Apply some lag to the carrier off condition, to ensure the last few bits get pushed through
                    the processing. */
@@ -1005,6 +1012,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v29_rx_get_logging_state(v29_rx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v29_rx_restart(v29_rx_state_t *s, int bit_rate, int old_train)
 {
     switch (bit_rate)

Modified: freeswitch/trunk/libs/spandsp/src/v29tx.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v29tx.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v29tx.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v29tx.c,v 1.79 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v29tx.c,v 1.84 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -54,6 +54,9 @@
 
 #include "spandsp/v29tx.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v29tx.h"
+
 #include "v29tx_constellation_maps.h"
 #if defined(SPANDSP_USE_FIXED_POINT)
 #include "v29tx_fixed_rrc.h"
@@ -113,6 +116,11 @@
     {
         0, 2, 6, 4
     };
+#if defined(SPANDSP_USE_FIXED_POINT)
+    static const complexi16_t zero = {0, 0};
+#else
+    static const complexf_t zero = {0.0f, 0.0f};
+#endif
     int bits;
     int amp;
     int bit;
@@ -132,11 +140,7 @@
                 if (s->training_step <= V29_TRAINING_SEG_2)
                 {
                     /* Segment 1: silence */
-#if defined(SPANDSP_USE_FIXED_POINT)
-                    return complex_seti16(0, 0);
-#else
-                    return complex_setf(0.0f, 0.0f);
-#endif
+                    return zero;
                 }
                 /* Segment 2: ABAB... */
                 return v29_abab_constellation[(s->training_step & 1) + s->training_offset];
@@ -310,6 +314,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v29_tx_get_logging_state(v29_tx_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 int v29_tx_restart(v29_tx_state_t *s, int bit_rate, int tep)
 {
     span_log(&s->logging, SPAN_LOG_FLOW, "Restarting V.29\n");

Modified: freeswitch/trunk/libs/spandsp/src/v42.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v42.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v42.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42.c,v 1.43 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v42.c,v 1.47 2009/01/05 13:48:32 steveu Exp $
  */
 
 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. */
@@ -30,7 +30,7 @@
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
@@ -47,6 +47,11 @@
 #include "spandsp/queue.h"
 #include "spandsp/v42.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/schedule.h"
+#include "spandsp/private/hdlc.h"
+#include "spandsp/private/v42.h"
+
 #if !defined(FALSE)
 #define FALSE   0
 #endif

Modified: freeswitch/trunk/libs/spandsp/src/v42bis.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v42bis.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v42bis.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42bis.c,v 1.32 2008/05/13 13:17:25 steveu Exp $
+ * $Id: v42bis.c,v 1.35 2009/01/05 13:48:32 steveu Exp $
  */
 
 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. 
@@ -32,7 +32,7 @@
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdio.h>
@@ -49,6 +49,9 @@
 #include "spandsp/bit_operations.h"
 #include "spandsp/v42bis.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/v42bis.h"
+
 /* Fixed parameters from the spec. */
 #define V42BIS_N3               8   /* Character size (bits) */
 #define V42BIS_N4               256 /* Number of characters in the alphabet */

Modified: freeswitch/trunk/libs/spandsp/src/v8.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/v8.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/v8.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v8.c,v 1.31 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v8.c,v 1.37 2009/01/28 03:41:27 steveu Exp $
  */
  
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <memory.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 
 #include "spandsp/telephony.h"
 #include "spandsp/logging.h"
@@ -57,6 +57,11 @@
 #include "spandsp/modem_connect_tones.h"
 #include "spandsp/v8.h"
 
+#include "spandsp/private/logging.h"
+#include "spandsp/private/fsk.h"
+#include "spandsp/private/modem_connect_tones.h"
+#include "spandsp/private/v8.h"
+
 #define ms_to_samples(t)    (((t)*SAMPLE_RATE)/1000)
 
 enum
@@ -120,21 +125,21 @@
     case V8_MOD_V21:
         return "V.21 duplex";
     case V8_MOD_V22:
-        return "V.22/V22.bis duplex";
+        return "V.22/V.22bis duplex";
     case V8_MOD_V23HALF:
         return "V.23 half-duplex";
     case V8_MOD_V23:
         return "V.23 duplex";
     case V8_MOD_V26BIS:
-        return "V.23 duplex";
+        return "V.26bis duplex";
     case V8_MOD_V26TER:
-        return "V.23 duplex";
+        return "V.26ter duplex";
     case V8_MOD_V27TER:
-        return "V.23 duplex";
+        return "V.27ter duplex";
     case V8_MOD_V29:
         return "V.29 half-duplex";
     case V8_MOD_V32:
-        return "V.32/V32.bis duplex";
+        return "V.32/V.32bis duplex";
     case V8_MOD_V34HALF:
         return "V.34 half-duplex";
     case V8_MOD_V34:
@@ -845,6 +850,12 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+logging_state_t *v8_get_logging_state(v8_state_t *s)
+{
+    return &s->logging;
+}
+/*- End of function --------------------------------------------------------*/
+
 v8_state_t *v8_init(v8_state_t *s,
                     int caller,
                     int available_modulations,
@@ -884,4 +895,14 @@
     return queue_free(s->tx_queue);
 }
 /*- End of function --------------------------------------------------------*/
+
+int v8_free(v8_state_t *s)
+{
+    int ret;
+    
+    ret = queue_free(s->tx_queue);
+    free(s);
+    return ret;
+}
+/*- End of function --------------------------------------------------------*/
 /*- End of file ------------------------------------------------------------*/

Modified: freeswitch/trunk/libs/spandsp/src/vector_float.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/vector_float.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/vector_float.c	Tue Jan 27 22:48:03 2009
@@ -22,26 +22,26 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: vector_float.c,v 1.14 2008/09/18 13:54:32 steveu Exp $
+ * $Id: vector_float.c,v 1.19 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
 #if defined(SPANDSP_USE_MMX)
@@ -55,7 +55,6 @@
 #endif
 #if defined(SPANDSP_USE_SSE3)
 #include <pmmintrin.h>
-#include <tmmintrin.h>
 #endif
 #if defined(SPANDSP_USE_SSE4_1)
 #include <smmintrin.h>
@@ -73,6 +72,32 @@
 #include "spandsp/telephony.h"
 #include "spandsp/vector_float.h"
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_copyf(float z[], const float x[], int n)
+{
+    int i;
+    __m128 n1;
+ 
+    if ((i = n & ~3))
+    {
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            _mm_storeu_ps(z + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3];
+    case 2:
+        z[n - 2] = x[n - 2];
+    case 1:
+        z[n - 1] = x[n - 1];
+    }
+}
+#else
 void vec_copyf(float z[], const float x[], int n)
 {
     int i;
@@ -80,6 +105,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = x[i];
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_copy(double z[], const double x[], int n)
@@ -102,6 +128,90 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_negatef(float z[], const float x[], int n)
+{
+    int i;
+	static const uint32_t mask = 0x80000000;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        n2 = _mm_set1_ps(*((float *) &mask));
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+		    n1 = _mm_xor_ps(n1, n2);
+            _mm_storeu_ps(z + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = -x[n - 3];
+    case 2:
+        z[n - 2] = -x[n - 2];
+    case 1:
+        z[n - 1] = -x[n - 1];
+    }
+}
+#else
+void vec_negatef(float z[], const float x[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = -x[i];
+}
+#endif
+/*- End of function --------------------------------------------------------*/
+
+void vec_negate(double z[], const double x[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = -x[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_negatel(long double z[], const long double x[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = -x[i];
+}
+/*- End of function --------------------------------------------------------*/
+#endif
+
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_zerof(float z[], int n)
+{
+    int i;
+    __m128 n1;
+ 
+    if ((i = n & ~3))
+    {
+        n1 = _mm_setzero_ps();
+        for (i -= 4;  i >= 0;  i -= 4)
+            _mm_storeu_ps(z + i, n1);
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = 0;
+    case 2:
+        z[n - 2] = 0;
+    case 1:
+        z[n - 1] = 0;
+    }
+}
+#else
 void vec_zerof(float z[], int n)
 {
     int i;
@@ -109,6 +219,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = 0.0f;
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_zero(double z[], int n)
@@ -131,6 +242,30 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_setf(float z[], float x, int n)
+{
+    int i;
+    __m128 n1;
+ 
+    if ((i = n & ~3))
+    {
+        n1 = _mm_set1_ps(x);
+        for (i -= 4;  i >= 0;  i -= 4)
+            _mm_storeu_ps(z + i, n1);
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x;
+    case 2:
+        z[n - 2] = x;
+    case 1:
+        z[n - 1] = x;
+    }
+}
+#else
 void vec_setf(float z[], float x, int n)
 {
     int i;
@@ -138,6 +273,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = x;
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_set(double z[], double x, int n)
@@ -160,6 +296,35 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_addf(float z[], const float x[], const float y[], int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n2 = _mm_add_ps(n1, n2);
+            _mm_storeu_ps(z + i, n2);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3] + y[n - 3];
+    case 2:
+        z[n - 2] = x[n - 2] + y[n - 2];
+    case 1:
+        z[n - 1] = x[n - 1] + y[n - 1];
+    }
+}
+#else
 void vec_addf(float z[], const float x[], const float y[], int n)
 {
     int i;
@@ -167,6 +332,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = x[i] + y[i];
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_add(double z[], const double x[], const double y[], int n)
@@ -187,16 +353,52 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_scaledxy_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+    __m128 n3;
+    __m128 n4;
+ 
+    if ((i = n & ~3))
+    {
+        n3 = _mm_set1_ps(x_scale);
+        n4 = _mm_set1_ps(y_scale);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n1 = _mm_mul_ps(n1, n3);
+            n2 = _mm_mul_ps(n2, n4);
+            n2 = _mm_add_ps(n1, n2);
+            _mm_storeu_ps(z + i, n2);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3]*x_scale + y[n - 3]*y_scale;
+    case 2:
+        z[n - 2] = x[n - 2]*x_scale + y[n - 2]*y_scale;
+    case 1:
+        z[n - 1] = x[n - 1]*x_scale + y[n - 1]*y_scale;
+    }
+}
+#else
+void vec_scaledxy_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
 {
     int i;
 
     for (i = 0;  i < n;  i++)
         z[i] = x[i]*x_scale + y[i]*y_scale;
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
-void vec_scaled_add(double z[], const double x[], double x_scale, const double y[], double y_scale, int n)
+void vec_scaledxy_add(double z[], const double x[], double x_scale, const double y[], double y_scale, int n)
 {
     int i;
 
@@ -206,7 +408,7 @@
 /*- End of function --------------------------------------------------------*/
 
 #if defined(HAVE_LONG_DOUBLE)
-void vec_scaled_addl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n)
+void vec_scaledxy_addl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n)
 {
     int i;
 
@@ -216,6 +418,97 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_scaledy_addf(float z[], const float x[], const float y[], float y_scale, int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+    __m128 n3;
+ 
+    if ((i = n & ~3))
+    {
+        n3 = _mm_set1_ps(y_scale);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n2 = _mm_mul_ps(n2, n3);
+            n2 = _mm_add_ps(n1, n2);
+            _mm_storeu_ps(z + i, n2);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3] + y[n - 3]*y_scale;
+    case 2:
+        z[n - 2] = x[n - 2] + y[n - 2]*y_scale;
+    case 1:
+        z[n - 1] = x[n - 1] + y[n - 1]*y_scale;
+    }
+}
+#else
+void vec_scaledy_addf(float z[], const float x[], const float y[], float y_scale, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y[i]*y_scale;
+}
+#endif
+/*- End of function --------------------------------------------------------*/
+
+void vec_scaledy_add(double z[], const double x[], const double y[], double y_scale, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y[i]*y_scale;
+}
+/*- End of function --------------------------------------------------------*/
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scaledy_addl(long double z[], const long double x[], const long double y[], long double y_scale, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y[i]*y_scale;
+}
+/*- End of function --------------------------------------------------------*/
+#endif
+
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_subf(float z[], const float x[], const float y[], int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n2 = _mm_sub_ps(n1, n2);
+            _mm_storeu_ps(z + i, n2);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3] - y[n - 3];
+    case 2:
+        z[n - 2] = x[n - 2] - y[n - 2];
+    case 1:
+        z[n - 1] = x[n - 1] - y[n - 1];
+    }
+}
+#else
 void vec_subf(float z[], const float x[], const float y[], int n)
 {
     int i;
@@ -223,6 +516,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = x[i] - y[i];
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_sub(double z[], const double x[], const double y[], int n)
@@ -245,7 +539,7 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
-void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
+void vec_scaledxy_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
 {
     int i;
 
@@ -254,7 +548,7 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-void vec_scaled_sub(double z[], const double x[], double x_scale, const double y[], double y_scale, int n)
+void vec_scaledxy_sub(double z[], const double x[], double x_scale, const double y[], double y_scale, int n)
 {
     int i;
 
@@ -264,7 +558,7 @@
 /*- End of function --------------------------------------------------------*/
 
 #if defined(HAVE_LONG_DOUBLE)
-void vec_scaled_subl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n)
+void vec_scaledxy_subl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n)
 {
     int i;
 
@@ -274,6 +568,35 @@
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_scalar_mulf(float z[], const float x[], float y, int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        n2 = _mm_set1_ps(y);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n1 = _mm_mul_ps(n1, n2);
+            _mm_storeu_ps(z + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3]*y;
+    case 2:
+        z[n - 2] = x[n - 2]*y;
+    case 1:
+        z[n - 1] = x[n - 1]*y;
+    }
+}
+#else
 void vec_scalar_mulf(float z[], const float x[], float y, int n)
 {
     int i;
@@ -281,6 +604,7 @@
     for (i = 0;  i < n;  i++)
         z[i] = x[i]*y;
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_scalar_mul(double z[], const double x[], double y, int n)
@@ -292,17 +616,154 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_scalar_addf(float z[], const float x[], float y, int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        n2 = _mm_set1_ps(y);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n1 = _mm_add_ps(n1, n2);
+            _mm_storeu_ps(z + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3] + y;
+    case 2:
+        z[n - 2] = x[n - 2] + y;
+    case 1:
+        z[n - 1] = x[n - 1] + y;
+    }
+}
+#else
+void vec_scalar_addf(float z[], const float x[], float y, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y;
+}
+#endif
+/*- End of function --------------------------------------------------------*/
+
+void vec_scalar_add(double z[], const double x[], double y, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y;
+}
+/*- End of function --------------------------------------------------------*/
+
 #if defined(HAVE_LONG_DOUBLE)
-void vec_scalar_mull(long double z[], const long double x[], long double y, int n)
+void vec_scalar_addl(long double z[], const long double x[], long double y, int n)
 {
     int i;
 
     for (i = 0;  i < n;  i++)
-        z[i] = x[i]*y;
+        z[i] = x[i] + y;
 }
 /*- End of function --------------------------------------------------------*/
 #endif
 
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_scalar_subf(float z[], const float x[], float y, int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+ 
+    if ((i = n & ~3))
+    {
+        n2 = _mm_set1_ps(y);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n1 = _mm_sub_ps(n1, n2);
+            _mm_storeu_ps(z + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3] - y;
+    case 2:
+        z[n - 2] = x[n - 2] - y;
+    case 1:
+        z[n - 1] = x[n - 1] - y;
+    }
+}
+#else
+void vec_scalar_subf(float z[], const float x[], float y, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] - y;
+}
+#endif
+/*- End of function --------------------------------------------------------*/
+
+void vec_scalar_sub(double z[], const double x[], double y, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] - y;
+}
+/*- End of function --------------------------------------------------------*/
+
+#if defined(HAVE_LONG_DOUBLE)
+void vec_scalar_subl(long double z[], const long double x[], long double y, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] - y;
+}
+/*- End of function --------------------------------------------------------*/
+#endif
+
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_mulf(float z[], const float x[], const float y[], int n)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+    __m128 n3;
+ 
+    if ((i = n & ~3))
+    {
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n3 = _mm_mul_ps(n1, n2);
+            _mm_storeu_ps(z + i, n3);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        z[n - 3] = x[n - 3]*y[n - 3];
+    case 2:
+        z[n - 2] = x[n - 2]*y[n - 2];
+    case 1:
+        z[n - 1] = x[n - 1]*y[n - 1];
+    }
+}
+#else
 void vec_mulf(float z[], const float x[], const float y[], int n)
 {
     int i;
@@ -311,6 +772,7 @@
         z[i] = x[i]*y[i];
 }
 /*- End of function --------------------------------------------------------*/
+#endif
 
 void vec_mul(double z[], const double x[], const double y[], int n)
 {
@@ -344,7 +806,7 @@
  
     z = 0.0f;
     if ((i = n & ~3))
-    {    
+    {
         n4 = _mm_setzero_ps();  //sets sum to zero
         for (i -= 4;  i >= 0;  i -= 4)
         {
@@ -357,7 +819,7 @@
         n4 = _mm_add_ss(_mm_shuffle_ps(n4, n4, 1), n4);
         _mm_store_ss(&z, n4);
     }
-    /* Now deal with the last 1 to 3 elements, which don't fill in an SSE2 register */
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
     switch (n & 3)
     {
     case 3:
@@ -419,17 +881,54 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+#define LMS_LEAK_RATE   0.9999f
+
+#if defined(__GNUC__)  &&  defined(SPANDSP_USE_SSE2)
+void vec_lmsf(const float x[], float y[], int n, float error)
+{
+    int i;
+    __m128 n1;
+    __m128 n2;
+    __m128 n3;
+    __m128 n4;
+ 
+    if ((i = n & ~3))
+    {
+        n3 = _mm_set1_ps(error);
+        n4 = _mm_set1_ps(LMS_LEAK_RATE);
+        for (i -= 4;  i >= 0;  i -= 4)
+        {
+            n1 = _mm_loadu_ps(x + i);
+            n2 = _mm_loadu_ps(y + i);
+            n1 = _mm_mul_ps(n1, n3);
+            n2 = _mm_mul_ps(n2, n4);
+            n1 = _mm_add_ps(n1, n2);
+            _mm_storeu_ps(y + i, n1);
+        }
+    }
+    /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */
+    switch (n & 3)
+    {
+    case 3:
+        y[n - 3] = y[n - 3]*LMS_LEAK_RATE + x[n - 3]*error;
+    case 2:
+        y[n - 2] = y[n - 2]*LMS_LEAK_RATE + x[n - 2]*error;
+    case 1:
+        y[n - 1] = y[n - 1]*LMS_LEAK_RATE + x[n - 1]*error;
+    }
+}
+#else
 void vec_lmsf(const float x[], float y[], int n, float error)
 {
     int i;
 
     for (i = 0;  i < n;  i++)
     {
-        y[i] += x[i]*error;
         /* Leak a little to tame uncontrolled wandering */
-        y[i] *= 0.9999f;
+        y[i] = y[i]*LMS_LEAK_RATE + x[i]*error;
     }
 }
+#endif
 /*- End of function --------------------------------------------------------*/
 
 void vec_circular_lmsf(const float x[], float y[], int n, int pos, float error)

Modified: freeswitch/trunk/libs/spandsp/src/vector_int.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/vector_int.c	(original)
+++ freeswitch/trunk/libs/spandsp/src/vector_int.c	Tue Jan 27 22:48:03 2009
@@ -22,28 +22,53 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: vector_int.c,v 1.15 2008/09/18 13:54:32 steveu Exp $
+ * $Id: vector_int.c,v 1.23 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
 
 #if defined(HAVE_CONFIG_H)
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
+#if defined(SPANDSP_USE_MMX)
+#include <mmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE)
+#include <xmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE2)
+#include <emmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE3)
+#include <pmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_1)
+#include <smmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4_2)
+#include <nmmintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE4A)
+#include <ammintrin.h>
+#endif
+#if defined(SPANDSP_USE_SSE5)
+#include <bmmintrin.h>
+#endif
+
 #include "spandsp/telephony.h"
 #include "spandsp/vector_int.h"
 
@@ -52,6 +77,105 @@
     int32_t z;
 
 #if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
+#if defined(__x86_64__)
+    __asm__ __volatile__(
+        " emms;\n"
+        " pxor %%mm0,%%mm0;\n"
+        " leaq -32(%%rsi,%%rax,2),%%rdx;\n"     /* rdx = top - 32 */
+
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 1f;\n"
+
+        /* Work in blocks of 16 int16_t's until we are near the end */
+        " .p2align 2;\n"
+        "2:\n"
+        " movq (%%rdi),%%mm1;\n"
+        " movq (%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 8(%%rdi),%%mm1;\n"
+        " movq 8(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 16(%%rdi),%%mm1;\n"
+        " movq 16(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        " movq 24(%%rdi),%%mm1;\n"
+        " movq 24(%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+
+        " addq $32,%%rsi;\n"
+        " addq $32,%%rdi;\n"
+        " cmpq %%rdx,%%rsi;\n"
+        " jbe 2b;\n"
+
+        " .p2align 2;\n"
+        "1:\n"
+        " addq $24,%%rdx;\n"                  /* Now edx = top - 8 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 3f;\n"
+
+        /* Work in blocks of 4 int16_t's until we are near the end */
+        " .p2align 2;\n"
+        "4:\n"
+        " movq (%%rdi),%%mm1;\n"
+        " movq (%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+
+        " addq $8,%%rsi;\n"
+        " addq $8,%%rdi;\n"
+        " cmpq %%rdx,%%rsi;"
+        " jbe 4b;\n"
+
+        " .p2align 2;\n"
+        "3:\n"
+        " addq $4,%%rdx;\n"                  /* Now edx = top - 4 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 5f;\n"
+
+        /* Work in a block of 2 int16_t's */
+        " movd (%%rdi),%%mm1;\n"
+        " movd (%%rsi),%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+
+        " addq $4,%%rsi;\n"
+        " addq $4,%%rdi;\n"
+
+        " .p2align 2;\n"
+        "5:\n"
+        " addq $2,%%rdx;\n"                  /* Now edx = top - 2 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 6f;\n"
+
+        /* Deal with the very last int16_t, when n is odd */
+        " movswl (%%rdi),%%eax;\n"
+        " andl $65535,%%eax;\n"
+        " movd %%eax,%%mm1;\n"
+        " movswl (%%rsi),%%eax;\n"
+        " andl $65535,%%eax;\n"
+        " movd %%eax,%%mm2;\n"
+        " pmaddwd %%mm2,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+
+        " .p2align 2;\n"
+        "6:\n"
+        /* Merge the pieces of the answer */
+        " movq %%mm0,%%mm1;\n"
+        " punpckhdq %%mm0,%%mm1;\n"
+        " paddd %%mm1,%%mm0;\n"
+        /* Et voila, eax has the final result */
+        " movd %%mm0,%%eax;\n"
+
+        " emms;\n"
+        : "=a" (z)
+        : "S" (x), "D" (y), "a" (n)
+        : "cc"
+    );
+#else
     __asm__ __volatile__(
         " emms;\n"
         " pxor %%mm0,%%mm0;\n"
@@ -149,6 +273,7 @@
         : "S" (x), "D" (y), "a" (n)
         : "cc"
     );
+#endif
 #else
     int i;
 
@@ -193,6 +318,155 @@
     static const int32_t upper_bound = 0x7FFF7FFF;
     int32_t max;
 
+#if defined(__x86_64__)
+    __asm__ __volatile__(
+        " emms;\n"
+        " pushq %%rdx;\n"
+        " leaq -8(%%rsi,%%rax,2),%%rdx;\n"
+
+        " cmpq %%rdx,%%rsi;\n"
+        " jbe 2f;\n"
+        " movd %[lower],%%mm0;\n"
+        " movd %[upper],%%mm1;\n"
+        " jmp 1f;\n"
+
+        " .p2align 2;\n"
+        "2:\n"
+        " movq (%%rsi),%%mm0;\n"   /* mm0 will be max's */
+        " movq %%mm0,%%mm1;\n"     /* mm1 will be min's */
+        " addq $8,%%rsi;\n"
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 4f;\n"
+
+        "3:\n"
+        " movq (%%rsi),%%mm2;\n"
+
+        " movq %%mm2,%%mm3;\n"
+        " pcmpgtw %%mm0,%%mm3;\n"  /* mm3 is bitmask for words where mm2 > mm0 */ 
+        " movq %%mm3,%%mm4;\n"
+        " pand %%mm2,%%mm3;\n"     /* mm3 is mm2 masked to new max's */
+        " pandn %%mm0,%%mm4;\n"    /* mm4 is mm0 masked to its max's */
+        " por %%mm3,%%mm4;\n"
+        " movq %%mm4,%%mm0;\n"     /* Now mm0 is updated max's */
+        
+        " movq %%mm1,%%mm3;\n"
+        " pcmpgtw %%mm2,%%mm3;\n"  /* mm3 is bitmask for words where mm2 < mm1 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new min's */
+        " pandn %%mm1,%%mm3;\n"    /* mm3 is mm1 masked to its min's */
+        " por %%mm3,%%mm2;\n"
+        " movq %%mm2,%%mm1;\n"     /* now mm1 is updated min's */
+
+        " addq $8,%%rsi;\n"
+        " cmpq %%rdx,%%rsi;\n"
+        " jbe 3b;\n"
+
+        " .p2align 2;\n"
+        "4:\n"
+        /* Merge down the 4-word max/mins to lower 2 words */
+        " movq %%mm0,%%mm2;\n"
+        " psrlq $32,%%mm2;\n"
+        " movq %%mm2,%%mm3;\n"
+        " pcmpgtw %%mm0,%%mm3;\n"  /* mm3 is bitmask for words where mm2 > mm0 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new max's */
+        " pandn %%mm0,%%mm3;\n"    /* mm3 is mm0 masked to its max's */
+        " por %%mm3,%%mm2;\n"
+        " movq %%mm2,%%mm0;\n"     /* now mm0 is updated max's */
+
+        " movq %%mm1,%%mm2;\n"
+        " psrlq $32,%%mm2;\n"
+        " movq %%mm1,%%mm3;\n"
+        " pcmpgtw %%mm2,%%mm3;\n"  /* mm3 is bitmask for words where mm2 < mm1 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new min's */
+        " pandn %%mm1,%%mm3;\n"    /* mm3 is mm1 masked to its min's */
+        " por %%mm3,%%mm2;\n"
+        " movq %%mm2,%%mm1;\n"     /* now mm1 is updated min's */
+
+        " .p2align 2;\n"
+        "1:\n"
+        " addq $4,%%rdx;\n"        /* now dx = top-4 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 5f;\n"
+        /* Here, there are >= 2 words of input remaining */
+        " movd (%%rsi),%%mm2;\n"
+
+        " movq %%mm2,%%mm3;\n"
+        " pcmpgtw %%mm0,%%mm3;\n"  /* mm3 is bitmask for words where mm2 > mm0 */ 
+        " movq %%mm3,%%mm4;\n"
+        " pand %%mm2,%%mm3;\n"     /* mm3 is mm2 masked to new max's */
+        " pandn %%mm0,%%mm4;\n"    /* mm4 is mm0 masked to its max's */
+        " por %%mm3,%%mm4;\n"
+        " movq %%mm4,%%mm0;\n"     /* now mm0 is updated max's */
+
+        " movq %%mm1,%%mm3;\n"
+        " pcmpgtw %%mm2,%%mm3;\n"  /* mm3 is bitmask for words where mm2 < mm1 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new min's */
+        " pandn %%mm1,%%mm3;\n"    /* mm3 is mm1 masked to its min's */
+        " por %%mm3,%%mm2;\n"
+        " movq %%mm2,%%mm1;\n"     /* now mm1 is updated min's */
+
+        " addq $4,%%rsi;\n"
+
+        " .p2align 2;\n"
+        "5:\n"
+        /* Merge down the 2-word max/mins to 1 word */
+        " movq %%mm0,%%mm2;\n"
+        " psrlq $16,%%mm2;\n"
+        " movq %%mm2,%%mm3;\n"
+        " pcmpgtw %%mm0,%%mm3;\n"  /* mm3 is bitmask for words where mm2 > mm0 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new max's */
+        " pandn %%mm0,%%mm3;\n"    /* mm3 is mm0 masked to its max's */
+        " por %%mm3,%%mm2;\n"
+        " movd %%mm2,%%ecx;\n"     /* cx is max so far */
+
+        " movq %%mm1,%%mm2;\n"
+        " psrlq $16,%%mm2;\n"
+        " movq %%mm1,%%mm3;\n"
+        " pcmpgtw %%mm2,%%mm3;\n"  /* mm3 is bitmask for words where mm2 < mm1 */ 
+        " pand %%mm3,%%mm2;\n"     /* mm2 is mm2 masked to new min's */
+        " pandn %%mm1,%%mm3;\n"    /* mm3 is mm1 masked to its min's */
+        " por %%mm3,%%mm2;\n"
+        " movd %%mm2,%%eax;\n"     /* ax is min so far */
+        
+        " addq $2,%%rdx;\n"        /* now dx = top-2 */
+        " cmpq %%rdx,%%rsi;\n"
+        " ja 6f;\n"
+
+        /* Here, there is one word of input left */
+        " cmpw (%%rsi),%%cx;\n"
+        " jge 9f;\n"
+        " movw (%%rsi),%%cx;\n"
+        " .p2align 2;\n"
+        "9:\n"
+        " cmpw (%%rsi),%%ax;\n"
+        " jle 6f;\n"
+        " movw (%%rsi),%%ax;\n"
+
+        " .p2align 2;\n"
+        "6:\n"
+        /* (finally!) cx is the max, ax the min */
+        " movswl %%cx,%%ecx;\n"
+        " movswl %%ax,%%eax;\n"
+
+        " popq %%rdx;\n"            /* ptr to output max,min vals */
+        " andq %%rdx,%%rdx;\n"
+        " jz 7f;\n"
+        " movw %%cx,(%%rdx);\n"    /* max */
+        " movw %%ax,2(%%rdx);\n"   /* min */
+        " .p2align 2;\n"
+        "7:\n"
+        /* Now calculate max absolute value */
+        " negl %%eax;\n"
+        " cmpl %%ecx,%%eax;\n"
+        " jge 8f;\n"
+        " movl %%ecx,%%eax;\n"
+        " .p2align 2;\n"
+        "8:\n"
+        " emms;\n"
+        : "=a" (max)
+        : "S" (x), "a" (n), "d" (out), [lower] "m" (lower_bound), [upper] "m" (upper_bound)
+        : "ecx"
+    );
+#else
     __asm__ __volatile__(
         " emms;\n"
         " pushl %%edx;\n"
@@ -341,6 +615,7 @@
         : "S" (x), "a" (n), "d" (out), [lower] "m" (lower_bound), [upper] "m" (upper_bound)
         : "ecx"
     );
+#endif
     return max;
 #else
     int i;
@@ -362,8 +637,11 @@
         /*endif*/
     }
     /*endfor*/
-    out[0] = max;
-    out[1] = min;
+    if (out)
+    {
+        out[0] = max;
+        out[1] = min;
+    }
     z = abs(min);
     if (z > max)
         return z;

Modified: freeswitch/trunk/libs/spandsp/tests/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/Makefile.am	(original)
+++ freeswitch/trunk/libs/spandsp/tests/Makefile.am	Tue Jan 27 22:48:03 2009
@@ -16,7 +16,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ##
-## $Id: Makefile.am,v 1.107 2008/09/18 12:05:35 steveu Exp $
+## $Id: Makefile.am,v 1.108 2008/11/30 10:17:31 steveu Exp $
 
 AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
 AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
@@ -64,9 +64,9 @@
                     line_model_tests \
                     logging_tests \
                     lpc10_tests \
-                    make_g168_css \
-                    modem_echo_tests \
                     modem_connect_tones_tests \
+                    modem_echo_tests \
+                    make_g168_css \
                     noise_tests \
                     oki_adpcm_tests \
                     playout_tests \

Modified: freeswitch/trunk/libs/spandsp/tests/adsi_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/adsi_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/adsi_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: adsi_tests.c,v 1.45 2008/08/29 09:28:13 steveu Exp $
+ * $Id: adsi_tests.c,v 1.48 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page adsi_tests_page ADSI tests
@@ -36,6 +36,9 @@
 \section adsi_tests_page_sec_2 How does it work?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -48,6 +51,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -59,8 +66,8 @@
 
 int errors = 0;
 
-adsi_rx_state_t rx_adsi;
-adsi_tx_state_t tx_adsi;
+adsi_rx_state_t *rx_adsi;
+adsi_tx_state_t *tx_adsi;
 
 int current_standard = 0;
 int good_message_received;
@@ -232,7 +239,7 @@
     printf("Message breakdown\n");
     do
     {
-        l = adsi_next_field(&rx_adsi, msg, len, l, &field_type, &field_body, &field_len);
+        l = adsi_next_field(rx_adsi, msg, len, l, &field_type, &field_body, &field_len);
         if (l > 0)
         {
             if (field_body)
@@ -626,22 +633,24 @@
        the routines visible. */
     /* Check the character encode/decode cycle */
     current_standard = ADSI_STANDARD_TDD;
-    adsi_tx_init(&tx_adsi, ADSI_STANDARD_TDD);
-    adsi_rx_init(&rx_adsi, ADSI_STANDARD_TDD, put_adsi_msg, NULL);
+    tx_adsi = adsi_tx_init(NULL, ADSI_STANDARD_TDD);
+    rx_adsi = adsi_rx_init(NULL, ADSI_STANDARD_TDD, put_adsi_msg, NULL);
     s = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()";
     while ((ch = *s++))
     {
-        xx = adsi_encode_baudot(&tx_adsi, ch);
+        xx = adsi_encode_baudot(tx_adsi, ch);
         if ((xx & 0x3E0))
         {
-            yy = adsi_decode_baudot(&rx_adsi, (xx >> 5) & 0x1F);
+            yy = adsi_decode_baudot(rx_adsi, (xx >> 5) & 0x1F);
             if (yy)
                 printf("%c", yy);
         }
-        yy = adsi_decode_baudot(&rx_adsi, xx & 0x1F);
+        yy = adsi_decode_baudot(rx_adsi, xx & 0x1F);
         if (yy)
             printf("%c", yy);
     }
+    adsi_tx_free(tx_adsi);
+    adsi_rx_free(rx_adsi);
     printf("\n");
 #endif
 
@@ -658,9 +667,11 @@
         else
             current_standard = test_standard;
 
-        adsi_rx_init(&rx_adsi, current_standard, put_adsi_msg, NULL);
-        span_log_set_level(&rx_adsi.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
-        span_log_set_tag(&rx_adsi.logging, "ADSI");
+        rx_adsi = adsi_rx_init(NULL, current_standard, put_adsi_msg, NULL);
+#if 0
+        span_log_set_level(rx_adsi.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
+        span_log_set_tag(rx_adsi.logging, "ADSI");
+#endif
         for (;;)
         {
             len = afReadFrames(inhandle,
@@ -669,13 +680,14 @@
                                BLOCK_LEN);
             if (len == 0)
                 break;
-            adsi_rx(&rx_adsi, amp, len);
+            adsi_rx(rx_adsi, amp, len);
         }
         if (afCloseFile(inhandle) != 0)
         {
             fprintf(stderr, "    Cannot close wave file '%s'\n", decode_test_file);
             exit(2);
         }
+        adsi_rx_free(rx_adsi);
     }
     else
     {
@@ -702,10 +714,10 @@
         for (current_standard = first_standard;  current_standard <= last_standard;  current_standard++)
         {
             printf("Testing %s\n", adsi_standard_to_str(current_standard));
-            adsi_tx_init(&tx_adsi, current_standard);
+            tx_adsi = adsi_tx_init(NULL, current_standard);
             if (short_preamble)
-                adsi_tx_set_preamble(&tx_adsi, 50, 20, 5, -1);
-            adsi_rx_init(&rx_adsi, current_standard, put_adsi_msg, NULL);
+                adsi_tx_set_preamble(tx_adsi, 50, 20, 5, -1);
+            rx_adsi = adsi_rx_init(NULL, current_standard, put_adsi_msg, NULL);
 
             /* Fake an OK condition for the first message test */
             good_message_received = TRUE;
@@ -714,7 +726,7 @@
             {
                 if (push == 0)
                 {
-                    if ((len = adsi_tx(&tx_adsi, amp, BLOCK_LEN)) == 0)
+                    if ((len = adsi_tx(tx_adsi, amp, BLOCK_LEN)) == 0)
                         push = 10;
                 }
                 else
@@ -729,8 +741,8 @@
                             exit(2);
                         }
                         good_message_received = FALSE;
-                        adsi_msg_len = adsi_create_message(&tx_adsi, adsi_msg);
-                        adsi_msg_len = adsi_tx_put_message(&tx_adsi, adsi_msg, adsi_msg_len);
+                        adsi_msg_len = adsi_create_message(tx_adsi, adsi_msg);
+                        adsi_msg_len = adsi_tx_put_message(tx_adsi, adsi_msg, adsi_msg_len);
                     }
                 }
                 if (len < BLOCK_LEN)
@@ -750,8 +762,10 @@
                         exit(2);
                     }
                 }
-                adsi_rx(&rx_adsi, amp, len);
+                adsi_rx(rx_adsi, amp, len);
             }
+            adsi_rx_free(rx_adsi);
+            adsi_tx_free(tx_adsi);
         }
         if (log_audio)
         {

Modified: freeswitch/trunk/libs/spandsp/tests/async_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/async_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/async_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: async_tests.c,v 1.17 2008/05/13 13:17:25 steveu Exp $
+ * $Id: async_tests.c,v 1.18 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -40,6 +40,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 async_rx_state_t rx_async;

Modified: freeswitch/trunk/libs/spandsp/tests/at_interpreter_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/at_interpreter_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/at_interpreter_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: at_interpreter_tests.c,v 1.19 2008/09/16 12:45:25 steveu Exp $
+ * $Id: at_interpreter_tests.c,v 1.20 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \file */
@@ -44,6 +44,7 @@
 #include <assert.h>
 #include <audiofile.h>
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
 #include "spandsp.h"
 
 #define DLE 0x10

Modified: freeswitch/trunk/libs/spandsp/tests/awgn_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/awgn_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/awgn_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: awgn_tests.c,v 1.17 2008/05/13 13:17:25 steveu Exp $
+ * $Id: awgn_tests.c,v 1.18 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \page awgn_tests_page AWGN tests
@@ -37,6 +37,10 @@
 #include <stdio.h>
 #include <string.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #if !defined(M_PI)

Modified: freeswitch/trunk/libs/spandsp/tests/bell_mf_rx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/bell_mf_rx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/bell_mf_rx_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bell_mf_rx_tests.c,v 1.12 2008/05/13 13:17:25 steveu Exp $
+ * $Id: bell_mf_rx_tests.c,v 1.14 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -50,6 +50,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 /* Basic Bell MF specs:
@@ -225,11 +229,11 @@
     float rrb;
     float rcfo;
     time_t now;
-    bell_mf_rx_state_t mf_state;
+    bell_mf_rx_state_t *mf_state;
     awgn_state_t noise_source;
 
     time(&now);
-    bell_mf_rx_init(&mf_state, NULL, NULL);
+    mf_state = bell_mf_rx_init(NULL, NULL, NULL);
 
     /* Test 1: Mitel's test 1 isn't really a test. Its a calibration step,
        which has no meaning here. */
@@ -251,8 +255,8 @@
         {
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            actual = bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            actual = bell_mf_rx_get(mf_state, buf, 128);
             if (actual != 1  ||  buf[0] != digit[0])
             {
                 printf ("    Sent     '%s'\n", digit);
@@ -304,16 +308,16 @@
             my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, 68);
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nplus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nplus += bell_mf_rx_get(mf_state, buf, 128);
         }
         for (nminus = 0, i = -1;  i >= -60;  i--)
         {
             my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, 68);
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nminus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nminus += bell_mf_rx_get(mf_state, buf, 128);
         }
         rrb = (float) (nplus + nminus)/10.0;
         rcfo = (float) (nplus - nminus)/10.0;
@@ -335,16 +339,16 @@
             my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, 68);
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nplus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nplus += bell_mf_rx_get(mf_state, buf, 128);
         }
         for (nminus = 0, i = -1;  i >= -60;  i--)
         {
             my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, 68);
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nminus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nminus += bell_mf_rx_get(mf_state, buf, 128);
         }
         rrb = (float) (nplus + nminus)/10.0;
         rcfo = (float) (nplus - nminus)/10.0;
@@ -380,8 +384,8 @@
 
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nplus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nplus += bell_mf_rx_get(mf_state, buf, 128);
         }
         printf("    %c normal twist  = %.2fdB\n", digit[0], (float) nplus/10.0);
         if (nplus < 60)
@@ -395,8 +399,8 @@
 
             len = my_mf_generate(amp, digit);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            nminus += bell_mf_rx_get(&mf_state, buf, 128);
+            bell_mf_rx(mf_state, amp, len);
+            nminus += bell_mf_rx_get(mf_state, buf, 128);
         }
         printf("    %c reverse twist = %.2fdB\n", digit[0], (float) nminus/10.0);
         if (nminus < 60)
@@ -421,8 +425,8 @@
         {
             len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-            if (bell_mf_rx_get(&mf_state, buf, 128) != 15)
+            bell_mf_rx(mf_state, amp, len);
+            if (bell_mf_rx_get(mf_state, buf, 128) != 15)
                 break;
             if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0)
                 break;
@@ -462,9 +466,8 @@
         {
             len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-
-            if (bell_mf_rx_get(&mf_state, buf, 128) != 15)
+            bell_mf_rx(mf_state, amp, len);
+            if (bell_mf_rx_get(mf_state, buf, 128) != 15)
                 break;
             if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0)
                 break;
@@ -495,9 +498,8 @@
             for (sample = 0;  sample < len;  sample++)
                 amp[sample] = saturate(amp[sample] + awgn(&noise_source));
             codec_munge(amp, len);
-            bell_mf_rx(&mf_state, amp, len);
-
-            if (bell_mf_rx_get(&mf_state, buf, 128) != 15)
+            bell_mf_rx(mf_state, amp, len);
+            if (bell_mf_rx_get(mf_state, buf, 128) != 15)
                 break;
             if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0)
                 break;
@@ -523,14 +525,14 @@
     printf("Test: Callback digit delivery mode.\n");
     callback_ok = FALSE;
     callback_roll = 0;
-    bell_mf_rx_init(&mf_state, digit_delivery, (void *) 0x12345678);
+    mf_state = bell_mf_rx_init(NULL, digit_delivery, (void *) 0x12345678);
     my_mf_gen_init(0.0, -10, 0.0, -10, 68, 68);
     for (i = 1;  i < 10;  i++)
     {
         len = 0;
         for (j = 0;  j < i;  j++)
             len += my_mf_generate(amp + len, ALL_POSSIBLE_DIGITS);
-        bell_mf_rx(&mf_state, amp, len);
+        bell_mf_rx(mf_state, amp, len);
         if (!callback_ok)
             break;
     }

Modified: freeswitch/trunk/libs/spandsp/tests/bell_mf_tx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/bell_mf_tx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/bell_mf_tx_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bell_mf_tx_tests.c,v 1.12 2008/08/16 15:24:15 steveu Exp $
+ * $Id: bell_mf_tx_tests.c,v 1.14 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -46,6 +46,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -53,7 +57,7 @@
 
 int main(int argc, char *argv[])
 {
-    bell_mf_tx_state_t gen;
+    bell_mf_tx_state_t *gen;
     int16_t amp[16384];
     int len;
     AFfilehandle outhandle;
@@ -66,40 +70,40 @@
         exit(2);
     }
 
-    bell_mf_tx_init(&gen);
-    len = bell_mf_tx(&gen, amp, 16384);
+    gen = bell_mf_tx_init(NULL);
+    len = bell_mf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "123", -1))
+    if (bell_mf_tx_put(gen, "123", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 16384);
+    len = bell_mf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "456", -1))
+    if (bell_mf_tx_put(gen, "456", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "789", -1))
+    if (bell_mf_tx_put(gen, "789", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "*#", -1))
+    if (bell_mf_tx_put(gen, "*#", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
@@ -108,7 +112,7 @@
     add_digits = 1;
     do
     {
-        len = bell_mf_tx(&gen, amp, 160);
+        len = bell_mf_tx(gen, amp, 160);
         printf("Generated %d samples\n", len);
         if (len > 0)
         {
@@ -119,7 +123,7 @@
         }
         if (add_digits)
         {
-            if (bell_mf_tx_put(&gen, "1234567890", -1))
+            if (bell_mf_tx_put(gen, "1234567890", -1))
             {
                 printf("Digit buffer full\n");
                 add_digits = 0;
@@ -128,48 +132,48 @@
     }
     while (len > 0);
 
-    bell_mf_tx_init(&gen);
-    len = bell_mf_tx(&gen, amp, 16384);
+    bell_mf_tx_init(gen);
+    len = bell_mf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "123", -1))
+    if (bell_mf_tx_put(gen, "123", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 16384);
+    len = bell_mf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "456", -1))
+    if (bell_mf_tx_put(gen, "456", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "789", -1))
+    if (bell_mf_tx_put(gen, "789", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "0*#", -1))
+    if (bell_mf_tx_put(gen, "0*#", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
                               amp,
                               len);
-    if (bell_mf_tx_put(&gen, "ABC", -1))
+    if (bell_mf_tx_put(gen, "ABC", -1))
         printf("Ooops\n");
-    len = bell_mf_tx(&gen, amp, 160);
+    len = bell_mf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle,
                               AF_DEFAULT_TRACK,
@@ -178,7 +182,7 @@
     add_digits = 1;
     do
     {
-        len = bell_mf_tx(&gen, amp, 160);
+        len = bell_mf_tx(gen, amp, 160);
         printf("Generated %d samples\n", len);
         if (len > 0)
         {
@@ -189,7 +193,7 @@
         }
         if (add_digits)
         {
-            if (bell_mf_tx_put(&gen, "1234567890", -1))
+            if (bell_mf_tx_put(gen, "1234567890", -1))
             {
                 printf("Digit buffer full\n");
                 add_digits = 0;

Modified: freeswitch/trunk/libs/spandsp/tests/bert_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/bert_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/bert_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: bert_tests.c,v 1.25 2008/09/07 12:45:17 steveu Exp $
+ * $Id: bert_tests.c,v 1.26 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \file */
@@ -42,6 +42,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 /* Use a local random generator, so the results are consistent across platforms */

Modified: freeswitch/trunk/libs/spandsp/tests/complex_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/complex_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/complex_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_tests.c,v 1.1 2008/09/18 12:09:51 steveu Exp $
+ * $Id: complex_tests.c,v 1.2 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \page complex_tests_page Complex arithmetic tests
@@ -39,13 +39,13 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 
 #include "spandsp.h"

Modified: freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: complex_vector_float_tests.c,v 1.1 2008/09/18 12:05:35 steveu Exp $
+ * $Id: complex_vector_float_tests.c,v 1.2 2008/10/09 13:25:19 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -37,6 +37,55 @@
 
 #include "spandsp.h"
 
+static void cvec_mulf_dumb(complexf_t z[], const complexf_t x[], const complexf_t y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+    {
+        z[i].re = x[i].re*y[i].re - x[i].im*y[i].im;
+        z[i].im = x[i].re*y[i].im + x[i].im*y[i].re;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_cvec_mulf(void)
+{
+    int i;
+    complexf_t x[100];
+    complexf_t y[100];
+    complexf_t za[100];
+    complexf_t zb[100];
+    complexf_t ratio;
+
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i].re = rand();
+        x[i].im = rand();
+        y[i].re = rand();
+        y[i].im = rand();
+    }
+    cvec_mulf(za, x, y, 99);
+    cvec_mulf_dumb(zb, x, y, 99);
+    for (i = 0;  i < 99;  i++)
+        printf("(%f,%f) (%f,%f) (%f,%f)\n", za[i].re, za[i].im, x[i].re, x[i].im, y[i].re, y[i].im);
+    for (i = 0;  i < 99;  i++)
+    {
+        ratio.re = za[i].re/zb[i].re;
+        ratio.im = za[i].im/zb[i].im;
+        if ((ratio.re < 0.9999  ||  ratio.re > 1.0001)
+            ||
+            (ratio.im < 0.9999  ||  ratio.im > 1.0001))
+        {
+            printf("cvec_mulf() - (%f,%f) (%f,%f)\n", za[i].re, za[i].im, zb[i].re, zb[i].im);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 static complexf_t cvec_dot_prodf_dumb(const complexf_t x[], const complexf_t y[], int n)
 {
     int i;
@@ -79,7 +128,7 @@
             ||
             (ratio.im < 0.9999  ||  ratio.im > 1.0001))
         {
-            printf("vec_dot_prod() - (%f,%f) (%f,%f)\n", zsa.re, zsa.im, zsb.re, zsb.im);
+            printf("cvec_dot_prodf() - (%f,%f) (%f,%f)\n", zsa.re, zsa.im, zsb.re, zsb.im);
             printf("Tests failed\n");
             exit(2);
         }
@@ -90,6 +139,7 @@
 
 int main(int argc, char *argv[])
 {
+    test_cvec_mulf();
     test_cvec_dot_prodf();
 
     printf("Tests passed.\n");

Modified: freeswitch/trunk/libs/spandsp/tests/dc_restore_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/dc_restore_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/dc_restore_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dc_restore_tests.c,v 1.23 2008/05/13 13:17:25 steveu Exp $
+ * $Id: dc_restore_tests.c,v 1.24 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \page dc_restore_tests_page DC restoration tests
@@ -38,6 +38,10 @@
 #include <memory.h>
 #include <time.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
     
 int main (int argc, char *argv[])

Modified: freeswitch/trunk/libs/spandsp/tests/dtmf_rx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/dtmf_rx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/dtmf_rx_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dtmf_rx_tests.c,v 1.42 2008/08/29 09:28:13 steveu Exp $
+ * $Id: dtmf_rx_tests.c,v 1.44 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*
@@ -96,6 +96,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -314,12 +318,12 @@
     int nminus;
     float rrb;
     float rcfo;
-    dtmf_rx_state_t dtmf_state;
+    dtmf_rx_state_t *dtmf_state;
     awgn_state_t noise_source;
 
-    dtmf_rx_init(&dtmf_state, NULL, NULL);
+    dtmf_state = dtmf_rx_init(NULL, NULL, NULL);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
 
     /* Test 1: Mitel's test 1 isn't really a test. Its a calibration step,
        which has no meaning here. */
@@ -342,9 +346,9 @@
         {
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
+            dtmf_rx(dtmf_state, amp, len);
 
-            actual = dtmf_rx_get(&dtmf_state, buf, 128);
+            actual = dtmf_rx_get(dtmf_state, buf, 128);
 
             if (actual != 1  ||  buf[0] != digit[0])
             {
@@ -396,16 +400,16 @@
             my_dtmf_gen_init((float) i/1000.0f, -17, 0.0f, -17, 50, 50);
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nplus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nplus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         for (nminus = 0, i = -1;  i >= -60;  i--)
         {
             my_dtmf_gen_init((float) i/1000.0f, -17, 0.0f, -17, 50, 50);
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nminus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nminus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         rrb = (float) (nplus + nminus)/10.0f;
         rcfo = (float) (nplus - nminus)/10.0f;
@@ -426,16 +430,16 @@
             my_dtmf_gen_init(0.0f, -17, (float) i/1000.0f, -17, 50, 50);
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nplus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nplus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         for (nminus = 0, i = -1;  i >= -60;  i--)
         {
             my_dtmf_gen_init(0.0f, -17, (float) i/1000.0f, -17, 50, 50);
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nminus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nminus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         rrb = (float) (nplus + nminus)/10.0f;
         rcfo = (float) (nplus - nminus)/10.0f;
@@ -488,8 +492,8 @@
 
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nplus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nplus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         printf("    %c normal twist  = %.2fdB\n", digit[0], (float) nplus/10.0);
         if (nplus < 80)
@@ -503,8 +507,8 @@
 
             len = my_dtmf_generate(amp, digit);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
-            nminus += dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, len);
+            nminus += dtmf_rx_get(dtmf_state, buf, 128);
         }
         printf("    %c reverse twist = %.2fdB\n", digit[0], (float) nminus/10.0);
         if (nminus < 40)
@@ -531,8 +535,8 @@
 
         len = my_dtmf_generate(amp, "1");
         codec_munge(munge, amp, len);
-        dtmf_rx(&dtmf_state, amp, len);
-        nplus += dtmf_rx_get(&dtmf_state, buf, 128);
+        dtmf_rx(dtmf_state, amp, len);
+        nplus += dtmf_rx_get(dtmf_state, buf, 128);
     }
     printf("    Dynamic range = %ddB\n", nplus);
     /* We ought to set some pass/fail condition, even if Mitel did not. If
@@ -560,8 +564,8 @@
 
         len = my_dtmf_generate(amp, "1");
         codec_munge(munge, amp, len);
-        dtmf_rx(&dtmf_state, amp, len);
-        nplus += dtmf_rx_get(&dtmf_state, buf, 128);
+        dtmf_rx(dtmf_state, amp, len);
+        nplus += dtmf_rx_get(dtmf_state, buf, 128);
     }
     printf("    Guard time = %dms\n", (500 - nplus)/10);
     printf("    Passed\n");
@@ -593,9 +597,9 @@
                 amp[sample] = saturate(amp[sample] + awgn(&noise_source));
             
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
+            dtmf_rx(dtmf_state, amp, len);
 
-            if (dtmf_rx_get(&dtmf_state, buf, 128) != 1)
+            if (dtmf_rx_get(dtmf_state, buf, 128) != 1)
                 break;
         }
         if (i == 1000)
@@ -621,11 +625,11 @@
     char buf[128 + 1];
     AFfilehandle inhandle;
     int frames;
-    dtmf_rx_state_t dtmf_state;
+    dtmf_rx_state_t *dtmf_state;
 
-    dtmf_rx_init(&dtmf_state, NULL, NULL);
+    dtmf_state = dtmf_rx_init(NULL, NULL, NULL);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
 
     /* The remainder of the Mitel tape is the talk-off test */
     /* Here we use the Bellcore test tapes (much tougher), in six
@@ -645,8 +649,8 @@
         hits = 0;
         while ((frames = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLE_RATE)))
         {
-            dtmf_rx(&dtmf_state, amp, frames);
-            len = dtmf_rx_get(&dtmf_state, buf, 128);
+            dtmf_rx(dtmf_state, amp, frames);
+            len = dtmf_rx_get(dtmf_state, buf, 128);
             if (len > 0)
             {
                 for (i = 0;  i < len;  i++)
@@ -686,13 +690,13 @@
     int len;
     int sample;
     char buf[128 + 1];
-    dtmf_rx_state_t dtmf_state;
+    dtmf_rx_state_t *dtmf_state;
     tone_gen_descriptor_t dial_tone_desc;
     tone_gen_state_t dial_tone;
 
-    dtmf_rx_init(&dtmf_state, NULL, NULL);
+    dtmf_state = dtmf_rx_init(NULL, NULL, NULL);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
 
     /* Test dial tone tolerance */
     printf("Test: Dial tone tolerance.\n");
@@ -710,9 +714,9 @@
             for (sample = 0;  sample < len;  sample++)
                 amp[sample] = saturate(amp[sample] + amp2[sample]);
             codec_munge(munge, amp, len);
-            dtmf_rx(&dtmf_state, amp, len);
+            dtmf_rx(dtmf_state, amp, len);
 
-            if (dtmf_rx_get(&dtmf_state, buf, 128) != strlen(ALL_POSSIBLE_DIGITS))
+            if (dtmf_rx_get(dtmf_state, buf, 128) != strlen(ALL_POSSIBLE_DIGITS))
                 break;
         }
         if (i != 10)
@@ -736,23 +740,23 @@
     int j;
     int len;
     int sample;
-    dtmf_rx_state_t dtmf_state;
+    dtmf_rx_state_t *dtmf_state;
 
     /* Test the callback mode for delivering detected digits */
     printf("Test: Callback digit delivery mode.\n");
     callback_hit = FALSE;
     callback_ok = TRUE;
     callback_roll = 0;
-    dtmf_rx_init(&dtmf_state, digit_delivery, (void *) 0x12345678);
+    dtmf_state = dtmf_rx_init(NULL, digit_delivery, (void *) 0x12345678);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
     my_dtmf_gen_init(0.0f, DEFAULT_DTMF_TX_LEVEL, 0.0f, DEFAULT_DTMF_TX_LEVEL, DEFAULT_DTMF_TX_ON_TIME, DEFAULT_DTMF_TX_OFF_TIME);
     for (i = 1;  i < 10;  i++)
     {
         len = 0;
         for (j = 0;  j < i;  j++)
             len += my_dtmf_generate(amp + len, ALL_POSSIBLE_DIGITS);
-        dtmf_rx(&dtmf_state, amp, len);
+        dtmf_rx(dtmf_state, amp, len);
         if (!callback_hit  ||  !callback_ok)
             break;
     }
@@ -768,10 +772,10 @@
     callback_hit = FALSE;
     callback_ok = TRUE;
     callback_roll = 0;
-    dtmf_rx_init(&dtmf_state, NULL, NULL);
-    dtmf_rx_set_realtime_callback(&dtmf_state, digit_status, (void *) 0x12345678);
+    dtmf_rx_init(dtmf_state, NULL, NULL);
+    dtmf_rx_set_realtime_callback(dtmf_state, digit_status, (void *) 0x12345678);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
     my_dtmf_gen_init(0.0f, DEFAULT_DTMF_TX_LEVEL, 0.0f, DEFAULT_DTMF_TX_LEVEL, DEFAULT_DTMF_TX_ON_TIME, DEFAULT_DTMF_TX_OFF_TIME);
     step = 0;
     for (i = 1;  i < 10;  i++)
@@ -781,7 +785,7 @@
             len += my_dtmf_generate(amp + len, ALL_POSSIBLE_DIGITS);
         for (sample = 0, j = SAMPLES_PER_CHUNK;  sample < len;  sample += SAMPLES_PER_CHUNK, j = ((len - sample) >= SAMPLES_PER_CHUNK)  ?  SAMPLES_PER_CHUNK  :  (len - sample))
         {
-            dtmf_rx(&dtmf_state, &amp[sample], j);
+            dtmf_rx(dtmf_state, &amp[sample], j);
             if (!callback_ok)
                 break;
             step += j;
@@ -801,15 +805,15 @@
 {
     int16_t amp[SAMPLES_PER_CHUNK];
     AFfilehandle inhandle;
-    dtmf_rx_state_t dtmf_state;
+    dtmf_rx_state_t *dtmf_state;
     char buf[128 + 1];
     int actual;
     int samples;
     int total;
 
-    dtmf_rx_init(&dtmf_state, NULL, NULL);
+    dtmf_state = dtmf_rx_init(NULL, NULL, NULL);
     if (use_dialtone_filter)
-        dtmf_rx_parms(&dtmf_state, TRUE, -1, -1, -99);
+        dtmf_rx_parms(dtmf_state, TRUE, -1, -1, -99);
 
     /* We will decode the audio from a wave file. */
     
@@ -823,9 +827,9 @@
     while ((samples = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLES_PER_CHUNK)) > 0)
     {
         codec_munge(munge, amp, samples);
-        dtmf_rx(&dtmf_state, amp, samples);
-        //printf("Status 0x%X\n", dtmf_rx_status(&dtmf_state));
-        if ((actual = dtmf_rx_get(&dtmf_state, buf, 128)) > 0)
+        dtmf_rx(dtmf_state, amp, samples);
+        //printf("Status 0x%X\n", dtmf_rx_status(dtmf_state));
+        if ((actual = dtmf_rx_get(dtmf_state, buf, 128)) > 0)
             printf("Received '%s'\n", buf);
         total += actual;
     }

Modified: freeswitch/trunk/libs/spandsp/tests/dtmf_tx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/dtmf_tx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/dtmf_tx_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: dtmf_tx_tests.c,v 1.20 2008/08/16 15:24:15 steveu Exp $
+ * $Id: dtmf_tx_tests.c,v 1.22 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -46,6 +46,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -53,7 +57,7 @@
 
 int main(int argc, char *argv[])
 {
-    dtmf_tx_state_t gen;
+    dtmf_tx_state_t *gen;
     int16_t amp[16384];
     int len;
     AFfilehandle outhandle;
@@ -66,34 +70,34 @@
         exit(2);
     }
 
-    dtmf_tx_init(&gen);
-    len = dtmf_tx(&gen, amp, 16384);
+    gen = dtmf_tx_init(NULL);
+    len = dtmf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "123", -1))
+    if (dtmf_tx_put(gen, "123", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 16384);
+    len = dtmf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "456", -1))
+    if (dtmf_tx_put(gen, "456", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "789", -1))
+    if (dtmf_tx_put(gen, "789", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "*#", -1))
+    if (dtmf_tx_put(gen, "*#", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
     add_digits = 1;
     do
     {
-        len = dtmf_tx(&gen, amp, 160);
+        len = dtmf_tx(gen, amp, 160);
         printf("Generated %d samples\n", len);
         if (len > 0)
         {
@@ -101,7 +105,7 @@
         }
         if (add_digits)
         {
-            if (dtmf_tx_put(&gen, "1234567890", -1))
+            if (dtmf_tx_put(gen, "1234567890", -1))
             {
                 printf("Digit buffer full\n");
                 add_digits = 0;
@@ -110,60 +114,60 @@
     }
     while (len > 0);
 
-    dtmf_tx_init(&gen);
-    len = dtmf_tx(&gen, amp, 16384);
+    dtmf_tx_init(gen);
+    len = dtmf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "123", -1))
+    if (dtmf_tx_put(gen, "123", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 16384);
+    len = dtmf_tx(gen, amp, 16384);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "456", -1))
+    if (dtmf_tx_put(gen, "456", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "789", -1))
+    if (dtmf_tx_put(gen, "789", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "0*#", -1))
+    if (dtmf_tx_put(gen, "0*#", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
-    if (dtmf_tx_put(&gen, "ABCD", -1))
+    if (dtmf_tx_put(gen, "ABCD", -1))
         printf("Ooops\n");
-    len = dtmf_tx(&gen, amp, 160);
+    len = dtmf_tx(gen, amp, 160);
     printf("Generated %d samples\n", len);
     outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
 
     /* Try modifying the level and length of the digits */
     printf("Try different levels and timing\n");
-    dtmf_tx_set_level(&gen, -20, 5);
-    dtmf_tx_set_timing(&gen, 100, 200);
-    if (dtmf_tx_put(&gen, "123", -1))
+    dtmf_tx_set_level(gen, -20, 5);
+    dtmf_tx_set_timing(gen, 100, 200);
+    if (dtmf_tx_put(gen, "123", -1))
         printf("Ooops\n");
     do
     {
-        len = dtmf_tx(&gen, amp, 160);
+        len = dtmf_tx(gen, amp, 160);
         printf("Generated %d samples\n", len);
         if (len > 0)
             outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len);
     }
     while (len > 0);
     printf("Restore normal levels and timing\n");
-    dtmf_tx_set_level(&gen, -10, 0);
-    dtmf_tx_set_timing(&gen, 50, 55);
-    if (dtmf_tx_put(&gen, "A", -1))
+    dtmf_tx_set_level(gen, -10, 0);
+    dtmf_tx_set_timing(gen, 50, 55);
+    if (dtmf_tx_put(gen, "A", -1))
         printf("Ooops\n");
 
     add_digits = TRUE;
     do
     {
-        len = dtmf_tx(&gen, amp, 160);
+        len = dtmf_tx(gen, amp, 160);
         printf("Generated %d samples\n", len);
         if (len > 0)
         {
@@ -171,7 +175,7 @@
         }
         if (add_digits)
         {
-            if (dtmf_tx_put(&gen, "1234567890", -1))
+            if (dtmf_tx_put(gen, "1234567890", -1))
             {
                 printf("Digit buffer full\n");
                 add_digits = FALSE;

Modified: freeswitch/trunk/libs/spandsp/tests/echo_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/echo_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/echo_tests.c	Tue Jan 27 22:48:03 2009
@@ -25,7 +25,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: echo_tests.c,v 1.36 2008/09/04 14:40:05 steveu Exp $
+ * $Id: echo_tests.c,v 1.37 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page echo_can_tests_page Line echo cancellation for voice tests
@@ -59,6 +59,10 @@
 #define GEN_CONST
 #include <math.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp/g168models.h"
 #include "spandsp-sim.h"

Modified: freeswitch/trunk/libs/spandsp/tests/fax_decode.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/fax_decode.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/fax_decode.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax_decode.c,v 1.48 2008/09/07 12:45:17 steveu Exp $
+ * $Id: fax_decode.c,v 1.53 2009/01/27 05:13:12 steveu Exp $
  */
 
 /*! \page fax_decode_page FAX decoder
@@ -43,6 +43,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define SAMPLES_PER_CHUNK   160
@@ -217,27 +221,10 @@
     if (len < 0)
     {
         /* Special conditions */
-        switch (len)
-        {
-        case SIG_STATUS_CARRIER_UP:
-            fprintf(stderr, "HDLC carrier up\n");
-            break;
-        case SIG_STATUS_CARRIER_DOWN:
-            fprintf(stderr, "HDLC carrier down\n");
-            break;
-        case SIG_STATUS_FRAMING_OK:
-            fprintf(stderr, "HDLC framing OK\n");
-            break;
-        case SIG_STATUS_ABORT:
-            /* Just ignore these */
-            break;
-        default:
-            fprintf(stderr, "Unexpected HDLC special length - %d!\n", len);
-            break;
-        }
+        fprintf(stderr, "HDLC status is %s (%d)\n", signal_status_to_str(len), len);
         return;
     }
-    
+
     if (ok)
     {
         if (msg[0] != 0xFF  ||  !(msg[1] == 0x03  ||  msg[1] == 0x13))
@@ -329,28 +316,12 @@
     if (bit < 0)
     {
         /* Special conditions */
+        fprintf(stderr, "V.21 rx status is %s (%d)\n", signal_status_to_str(bit), bit);
         switch (bit)
         {
-        case SIG_STATUS_TRAINING_FAILED:
-            fprintf(stderr, "V.21 Training failed\n");
-            break;
-        case SIG_STATUS_TRAINING_IN_PROGRESS:
-            fprintf(stderr, "V.21 Training in progress\n");
-            break;
-        case SIG_STATUS_TRAINING_SUCCEEDED:
-            fprintf(stderr, "V.21 Training succeeded\n");
-            t4_begin();
-            break;
-        case SIG_STATUS_CARRIER_UP:
-            fprintf(stderr, "V.21 Carrier up\n");
-            break;
         case SIG_STATUS_CARRIER_DOWN:
-            fprintf(stderr, "V.21 Carrier down\n");
             //t4_end();
             break;
-        default:
-            fprintf(stderr, "V.21 Eh!\n");
-            break;
         }
         return;
     }
@@ -365,31 +336,18 @@
     if (bit < 0)
     {
         /* Special conditions */
+        fprintf(stderr, "V.17 rx status is %s (%d)\n", signal_status_to_str(bit), bit);
         switch (bit)
         {
-        case SIG_STATUS_TRAINING_FAILED:
-            fprintf(stderr, "V.17 Training failed\n");
-            break;
-        case SIG_STATUS_TRAINING_IN_PROGRESS:
-            fprintf(stderr, "V.17 Training in progress\n");
-            break;
         case SIG_STATUS_TRAINING_SUCCEEDED:
-            fprintf(stderr, "V.17 Training succeeded\n");
             fast_trained = FAX_V17_RX;
             t4_begin();
             break;
-        case SIG_STATUS_CARRIER_UP:
-            fprintf(stderr, "V.17 Carrier up\n");
-            break;
         case SIG_STATUS_CARRIER_DOWN:
-            fprintf(stderr, "V.17 Carrier down\n");
             t4_end();
             if (fast_trained == FAX_V17_RX)
                 fast_trained = FAX_NONE;
             break;
-        default:
-            fprintf(stderr, "V.17 Eh!\n");
-            break;
         }
         return;
     }
@@ -414,31 +372,18 @@
     if (bit < 0)
     {
         /* Special conditions */
+        fprintf(stderr, "V.29 rx status is %s (%d)\n", signal_status_to_str(bit), bit);
         switch (bit)
         {
-        case SIG_STATUS_TRAINING_FAILED:
-            //fprintf(stderr, "V.29 Training failed\n");
-            break;
-        case SIG_STATUS_TRAINING_IN_PROGRESS:
-            fprintf(stderr, "V.29 Training in progress\n");
-            break;
         case SIG_STATUS_TRAINING_SUCCEEDED:
-            fprintf(stderr, "V.29 Training succeeded\n");
             fast_trained = FAX_V29_RX;
             t4_begin();
             break;
-        case SIG_STATUS_CARRIER_UP:
-            //fprintf(stderr, "V.29 Carrier up\n");
-            break;
         case SIG_STATUS_CARRIER_DOWN:
-            //fprintf(stderr, "V.29 Carrier down\n");
             t4_end();
             if (fast_trained == FAX_V29_RX)
                 fast_trained = FAX_NONE;
             break;
-        default:
-            fprintf(stderr, "V.29 Eh!\n");
-            break;
         }
         return;
     }
@@ -463,31 +408,18 @@
     if (bit < 0)
     {
         /* Special conditions */
+        fprintf(stderr, "V.27ter rx status is %s (%d)\n", signal_status_to_str(bit), bit);
         switch (bit)
         {
-        case SIG_STATUS_TRAINING_FAILED:
-            //fprintf(stderr, "V.27ter Training failed\n");
-            break;
-        case SIG_STATUS_TRAINING_IN_PROGRESS:
-            fprintf(stderr, "V.27ter Training in progress\n");
-            break;
         case SIG_STATUS_TRAINING_SUCCEEDED:
-            fprintf(stderr, "V.27ter Training succeeded\n");
             fast_trained = FAX_V27TER_RX;
             t4_begin();
             break;
-        case SIG_STATUS_CARRIER_UP:
-            //fprintf(stderr, "V.27ter Carrier up\n");
-            break;
         case SIG_STATUS_CARRIER_DOWN:
-            //fprintf(stderr, "V.27ter Carrier down\n");
             t4_end();
             if (fast_trained == FAX_V27TER_RX)
                 fast_trained = FAX_NONE;
             break;
-        default:
-            fprintf(stderr, "V.27ter Eh!\n");
-            break;
         }
         return;
     }
@@ -509,15 +441,16 @@
 
 int main(int argc, char *argv[])
 {
-    fsk_rx_state_t fsk;
-    v17_rx_state_t v17;
-    v29_rx_state_t v29;
-    v27ter_rx_state_t v27ter;
+    fsk_rx_state_t *fsk;
+    v17_rx_state_t *v17;
+    v29_rx_state_t *v29;
+    v27ter_rx_state_t *v27ter;
     int16_t amp[SAMPLES_PER_CHUNK];
     AFfilehandle inhandle;
     int len;
     const char *filename;
     float x;
+    logging_state_t *logging;
 
     filename = "fax_samp.wav";
 
@@ -549,27 +482,32 @@
     span_log_set_protocol(&t30_dummy.logging, "T.30");
 
     hdlc_rx_init(&hdlcrx, FALSE, TRUE, 5, hdlc_accept, NULL);
-    fsk_rx_init(&fsk, &preset_fsk_specs[FSK_V21CH2], TRUE, v21_put_bit, NULL);
-    v17_rx_init(&v17, 14400, v17_put_bit, NULL);
-    v29_rx_init(&v29, 9600, v29_put_bit, NULL);
-    //v29_rx_init(&v29, 7200, v29_put_bit, NULL);
-    v27ter_rx_init(&v27ter, 4800, v27ter_put_bit, NULL);
-    fsk_rx_signal_cutoff(&fsk, -45.5);
-    v17_rx_signal_cutoff(&v17, -45.5);
-    v29_rx_signal_cutoff(&v29, -45.5);
-    v27ter_rx_signal_cutoff(&v27ter, -40.0);
-
-    span_log_init(&v17.logging, SPAN_LOG_FLOW, NULL);
-    span_log_set_protocol(&v17.logging, "V.17");
-    span_log_set_level(&v17.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-
-    span_log_init(&v29.logging, SPAN_LOG_FLOW, NULL);
-    span_log_set_protocol(&v29.logging, "V.29");
-    span_log_set_level(&v29.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-
-    span_log_init(&v27ter.logging, SPAN_LOG_FLOW, NULL);
-    span_log_set_protocol(&v27ter.logging, "V.27ter");
-    span_log_set_level(&v27ter.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
+    fsk = fsk_rx_init(NULL, &preset_fsk_specs[FSK_V21CH2], TRUE, v21_put_bit, NULL);
+    v17 = v17_rx_init(NULL, 14400, v17_put_bit, NULL);
+    v29 = v29_rx_init(NULL, 9600, v29_put_bit, NULL);
+    //v29 = v29_rx_init(NULL, 7200, v29_put_bit, NULL);
+    v27ter = v27ter_rx_init(NULL, 4800, v27ter_put_bit, NULL);
+    fsk_rx_signal_cutoff(fsk, -45.5);
+    v17_rx_signal_cutoff(v17, -45.5);
+    v29_rx_signal_cutoff(v29, -45.5);
+    v27ter_rx_signal_cutoff(v27ter, -40.0);
+
+#if 1
+    logging = v17_rx_get_logging_state(v17);
+    span_log_init(logging, SPAN_LOG_FLOW, NULL);
+    span_log_set_protocol(logging, "V.17");
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
+
+    logging = v29_rx_get_logging_state(v29);
+    span_log_init(logging, SPAN_LOG_FLOW, NULL);
+    span_log_set_protocol(logging, "V.29");
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
+
+    logging = v27ter_rx_get_logging_state(v27ter);
+    span_log_init(logging, SPAN_LOG_FLOW, NULL);
+    span_log_set_protocol(logging, "V.27ter");
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
+#endif
 
     if (t4_rx_init(&t4_state, "fax_decode.tif", T4_COMPRESSION_ITU_T4_2D) == NULL)
     {
@@ -582,10 +520,10 @@
         len = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLES_PER_CHUNK);
         if (len < SAMPLES_PER_CHUNK)
             break;
-        fsk_rx(&fsk, amp, len);
-        v17_rx(&v17, amp, len);
-        v29_rx(&v29, amp, len);
-        v27ter_rx(&v27ter, amp, len);
+        fsk_rx(fsk, amp, len);
+        v17_rx(v17, amp, len);
+        v29_rx(v29, amp, len);
+        //v27ter_rx(v27ter, amp, len);
     }
     t4_rx_end(&t4_state);
 

Modified: freeswitch/trunk/libs/spandsp/tests/fax_tester.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/fax_tester.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/fax_tester.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax_tester.c,v 1.17 2008/09/12 14:41:55 steveu Exp $
+ * $Id: fax_tester.c,v 1.21 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -35,13 +35,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <fcntl.h>
 #include <time.h>
@@ -57,7 +57,12 @@
 #include <libxml/xinclude.h>
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
+
 #include "fax_tester.h"
 
 #define HDLC_FRAMING_OK_THRESHOLD       5

Modified: freeswitch/trunk/libs/spandsp/tests/fax_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/fax_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/fax_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fax_tests.c,v 1.96 2008/09/09 14:05:55 steveu Exp $
+ * $Id: fax_tests.c,v 1.100 2009/01/03 14:44:15 steveu Exp $
  */
 
 /*! \page fax_tests_page FAX tests
@@ -41,6 +41,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -57,7 +61,8 @@
     int chan;
     int16_t amp[SAMPLES_PER_CHUNK];
     int len;
-    fax_state_t fax;
+    fax_state_t *fax;
+    awgn_state_t *awgn;
     int done;
     int succeeded;
     char tag[50];
@@ -110,13 +115,16 @@
     printf("%d: Phase D: image resolution %d x %d\n", i, t.x_resolution, t.y_resolution);
     printf("%d: Phase D: bad rows %d\n", i, t.bad_rows);
     printf("%d: Phase D: longest bad row run %d\n", i, t.longest_bad_row_run);
+    printf("%d: Phase D: bad ECM frames %d\n", i, t.error_correcting_mode_retries);
     printf("%d: Phase D: compression type %d\n", i, t.encoding);
     printf("%d: Phase D: image size %d bytes\n", i, t.image_size);
     if ((u = t30_get_tx_ident(s)))
         printf("%d: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
         printf("%d: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%d: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
 
     if (use_receiver_not_ready)
         t30_set_receiver_not_ready(s, 3);
@@ -165,6 +173,7 @@
     printf("%d: Phase E: image resolution %d x %d\n", i, t.x_resolution, t.y_resolution);
     printf("%d: Phase E: bad rows %d\n", i, t.bad_rows);
     printf("%d: Phase E: longest bad row run %d\n", i, t.longest_bad_row_run);
+    printf("%d: Phase E: bad ECM frames %d\n", i, t.error_correcting_mode_retries);
     printf("%d: Phase E: coding method %s\n", i, t4_encoding_to_str(t.encoding));
     printf("%d: Phase E: image size %d bytes\n", i, t.image_size);
     if ((u = t30_get_tx_ident(s)))
@@ -234,11 +243,15 @@
     int reverse_flow;
     int use_page_limits;
     int supported_modems;
+    int signal_level;
+    int noise_level;
+    float signal_scaling;
     time_t start_time;
     time_t end_time;
     char *page_header_info;
     int opt;
     t30_state_t *t30;
+    logging_state_t *logging;
 
     log_audio = FALSE;
     input_tiff_file_name = INPUT_TIFF_FILE_NAME;
@@ -252,8 +265,10 @@
     use_transmit_on_idle = TRUE;
     use_receiver_not_ready = FALSE;
     use_page_limits = FALSE;
+    signal_level = 0;
+    noise_level = -99;
     supported_modems = T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17;
-    while ((opt = getopt(argc, argv, "ehH:i:I:lm:prRtTw:")) != -1)
+    while ((opt = getopt(argc, argv, "ehH:i:I:lm:n:prRs:tTw:")) != -1)
     {
         switch (opt)
         {
@@ -278,6 +293,9 @@
         case 'm':
             supported_modems = atoi(optarg);
             break;
+        case 'n':
+            noise_level = atoi(optarg);
+            break;
         case 'p':
             polled_mode = TRUE;
             break;
@@ -287,6 +305,9 @@
         case 'R':
             use_receiver_not_ready = TRUE;
             break;
+        case 's':
+            signal_level = atoi(optarg);
+            break;
         case 't':
             use_tep = TRUE;
             break;
@@ -332,12 +353,20 @@
         i = mc->chan + 1;
         sprintf(buf, "%d%d%d%d%d%d%d%d", i, i, i, i, i, i, i, i);
         if (reverse_flow)
-            fax_init(&mc->fax, (mc->chan & 1)  ?  TRUE  :  FALSE);
+            mc->fax = fax_init(NULL, (mc->chan & 1)  ?  TRUE  :  FALSE);
         else
-            fax_init(&mc->fax, (mc->chan & 1)  ?  FALSE  :  TRUE);
-        fax_set_transmit_on_idle(&mc->fax, use_transmit_on_idle);
-        fax_set_tep_mode(&mc->fax, use_tep);
-        t30 = fax_get_t30_state(&mc->fax);
+            mc->fax = fax_init(NULL, (mc->chan & 1)  ?  FALSE  :  TRUE);
+        mc->awgn = NULL;
+        signal_scaling = 1.0f;
+        if (noise_level > -99)
+        {
+            mc->awgn = awgn_init_dbm0(NULL, 1234567, noise_level);
+            signal_scaling = powf(10.0f, signal_level/20.0f);
+            printf("Signal scaling %f\n", signal_scaling);
+        }
+        fax_set_transmit_on_idle(mc->fax, use_transmit_on_idle);
+        fax_set_tep_mode(mc->fax, use_tep);
+        t30 = fax_get_t30_state(mc->fax);
         t30_set_tx_ident(t30, buf);
         t30_set_tx_sub_address(t30, "Sub-address");
         t30_set_tx_sender_ident(t30, "Sender ID");
@@ -413,12 +442,15 @@
         t30_set_real_time_frame_handler(t30, real_time_frame_handler, (void *) (intptr_t) mc->chan);
         t30_set_document_handler(t30, document_handler, (void *) (intptr_t) mc->chan);
         sprintf(mc->tag, "FAX-%d", j + 1);
-        span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
-        span_log_set_tag(&t30->logging, mc->tag);
-        span_log_set_level(&mc->fax.modems.v29_rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
-        span_log_set_tag(&mc->fax.modems.v29_rx.logging, mc->tag);
-        span_log_set_level(&mc->fax.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
-        span_log_set_tag(&mc->fax.logging, mc->tag);
+
+        logging = t30_get_logging_state(t30);
+        span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
+        span_log_set_tag(logging, mc->tag);
+
+        logging = fax_get_logging_state(mc->fax);
+        span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
+        span_log_set_tag(logging, mc->tag);
+
         memset(mc->amp, 0, sizeof(mc->amp));
         mc->total_audio_time = 0;
         mc->done = FALSE;
@@ -439,7 +471,12 @@
             }
             else
             {
-                mc->len = fax_tx(&mc->fax, mc->amp, SAMPLES_PER_CHUNK);
+                mc->len = fax_tx(mc->fax, mc->amp, SAMPLES_PER_CHUNK);
+                if (mc->awgn)
+                {
+                    for (k = 0;  k < mc->len;  k++)
+                        mc->amp[k] = ((int16_t) (mc->amp[k]*signal_scaling)) + awgn(mc->awgn);
+                }
             }
             mc->total_audio_time += SAMPLES_PER_CHUNK;
             if (!use_transmit_on_idle)
@@ -453,9 +490,11 @@
                     mc->len = SAMPLES_PER_CHUNK;
                 }
             }
-            span_log_bump_samples(&mc->fax.t30.logging, mc->len);
-            span_log_bump_samples(&mc->fax.modems.v29_rx.logging, mc->len);
-            span_log_bump_samples(&mc->fax.logging, mc->len);
+            t30 = fax_get_t30_state(mc->fax);
+            logging = t30_get_logging_state(t30);
+            span_log_bump_samples(logging, mc->len);
+            logging = fax_get_logging_state(mc->fax);
+            span_log_bump_samples(logging, mc->len);
 
             if (log_audio)
             {
@@ -464,10 +503,12 @@
             }
             if (machines[j ^ 1].len < SAMPLES_PER_CHUNK)
                 memset(machines[j ^ 1].amp + machines[j ^ 1].len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - machines[j ^ 1].len));
+            t30 = fax_get_t30_state(mc->fax);
+#if defined(WITH_SPANDSP_INTERNALS)
             if (use_line_hits)
             {
                 /* TODO: This applies very crude line hits. improve it */
-                if (mc->fax.t30.state == 22)
+                if (t30->state == 22)
                 {
                     if (++mc->error_delay == 100)
                     {
@@ -478,9 +519,10 @@
                     }
                 }    
             }
-            if (mc->fax.t30.state == t30_state_to_wreck)
+            if (t30->state == t30_state_to_wreck)
                 memset(machines[j ^ 1].amp, 0, sizeof(int16_t)*SAMPLES_PER_CHUNK);
-            if (fax_rx(&mc->fax, machines[j ^ 1].amp, SAMPLES_PER_CHUNK))
+#endif
+            if (fax_rx(mc->fax, machines[j ^ 1].amp, SAMPLES_PER_CHUNK))
                 break;
             if (!mc->done)
                 alldone = FALSE;
@@ -500,7 +542,7 @@
     for (j = 0;  j < FAX_MACHINES;  j++)
     {
         mc = &machines[j];
-        fax_release(&mc->fax);
+        fax_release(mc->fax);
     }
     if (log_audio)
     {

Modified: freeswitch/trunk/libs/spandsp/tests/fsk_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/fsk_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/fsk_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: fsk_tests.c,v 1.50 2008/09/07 12:45:17 steveu Exp $
+ * $Id: fsk_tests.c,v 1.53 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page fsk_tests_page FSK modem tests
@@ -53,6 +53,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -163,10 +167,10 @@
 
 int main(int argc, char *argv[])
 {
-    fsk_tx_state_t caller_tx;
-    fsk_rx_state_t caller_rx;
-    fsk_tx_state_t answerer_tx;
-    fsk_rx_state_t answerer_rx;
+    fsk_tx_state_t *caller_tx;
+    fsk_rx_state_t *caller_rx;
+    fsk_tx_state_t *answerer_tx;
+    fsk_rx_state_t *answerer_rx;
     bert_state_t caller_bert;
     bert_state_t answerer_bert;
     bert_results_t bert_results;
@@ -282,8 +286,8 @@
             fprintf(stderr, "    Cannot open wave file '%s'\n", decode_test_file);
             exit(2);
         }
-        fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_1], TRUE, put_bit, NULL);
-        fsk_rx_set_modem_status_handler(&caller_rx, rx_status, (void *) &caller_rx);
+        caller_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_1], TRUE, put_bit, NULL);
+        fsk_rx_set_modem_status_handler(caller_rx, rx_status, (void *) &caller_rx);
         test_bps = preset_fsk_specs[modem_under_test_1].baud_rate;
 
         for (;;)
@@ -296,7 +300,7 @@
                 break;
             for (i = 0;  i < samples;  i++)
                 power_meter_update(&caller_meter, caller_model_amp[i]);
-            fsk_rx(&caller_rx, caller_model_amp, samples);
+            fsk_rx(caller_rx, caller_model_amp, samples);
         }
 
         if (afCloseFile(inhandle) != 0)
@@ -308,9 +312,9 @@
     else
     {
         printf("Test cutoff level\n");
-        fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_1], TRUE, cutoff_test_put_bit, NULL);
-        fsk_rx_signal_cutoff(&caller_rx, -30.0f);
-        fsk_rx_set_modem_status_handler(&caller_rx, cutoff_test_rx_status, (void *) &caller_rx);
+        caller_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_1], TRUE, cutoff_test_put_bit, NULL);
+        fsk_rx_signal_cutoff(caller_rx, -30.0f);
+        fsk_rx_set_modem_status_handler(caller_rx, cutoff_test_rx_status, (void *) &caller_rx);
         on_at = 0;
         for (i = -40;  i < -25;  i++)
         {
@@ -328,7 +332,7 @@
             for (j = 0;  j < 10;  j++)
             {
                 samples = tone_gen(&tone_tx, caller_model_amp, 160);
-                fsk_rx(&caller_rx, caller_model_amp, samples);
+                fsk_rx(caller_rx, caller_model_amp, samples);
             }
             if (cutoff_test_carrier)
                break;
@@ -351,7 +355,7 @@
             for (j = 0;  j < 10;  j++)
             {
                 samples = tone_gen(&tone_tx, caller_model_amp, 160);
-                fsk_rx(&caller_rx, caller_model_amp, samples);
+                fsk_rx(caller_rx, caller_model_amp, samples);
             }
             if (!cutoff_test_carrier)
                 break;
@@ -370,17 +374,17 @@
         test_bps = preset_fsk_specs[modem_under_test_1].baud_rate;
         if (modem_under_test_1 >= 0)
         {
-            fsk_tx_init(&caller_tx, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
-            fsk_tx_set_modem_status_handler(&caller_tx, tx_status, (void *) &caller_tx);
-            fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
-            fsk_rx_set_modem_status_handler(&answerer_rx, rx_status, (void *) &answerer_rx);
+            caller_tx = fsk_tx_init(NULL, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
+            fsk_tx_set_modem_status_handler(caller_tx, tx_status, (void *) &caller_tx);
+            answerer_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
+            fsk_rx_set_modem_status_handler(answerer_rx, rx_status, (void *) &answerer_rx);
         }
         if (modem_under_test_2 >= 0)
         {
-            fsk_tx_init(&answerer_tx, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
-            fsk_tx_set_modem_status_handler(&answerer_tx, tx_status, (void *) &answerer_tx);
-            fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
-            fsk_rx_set_modem_status_handler(&caller_rx, rx_status, (void *) &caller_rx);
+            answerer_tx = fsk_tx_init(NULL, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
+            fsk_tx_set_modem_status_handler(answerer_tx, tx_status, (void *) &answerer_tx);
+            caller_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
+            fsk_rx_set_modem_status_handler(caller_rx, rx_status, (void *) &caller_rx);
         }
         test_bps = preset_fsk_specs[modem_under_test_1].baud_rate;
 
@@ -399,10 +403,10 @@
 
         for (;;)
         {
-            samples = fsk_tx(&caller_tx, caller_amp, BLOCK_LEN);
+            samples = fsk_tx(caller_tx, caller_amp, BLOCK_LEN);
             for (i = 0;  i < samples;  i++)
                 power_meter_update(&caller_meter, caller_amp[i]);
-            samples = fsk_tx(&answerer_tx, answerer_amp, BLOCK_LEN);
+            samples = fsk_tx(answerer_tx, answerer_amp, BLOCK_LEN);
             for (i = 0;  i < samples;  i++)
                 power_meter_update(&answerer_meter, answerer_amp[i]);
             both_ways_line_model(model,
@@ -414,13 +418,13 @@
 
             //printf("Powers %10.5fdBm0 %10.5fdBm0\n", power_meter_current_dbm0(&caller_meter), power_meter_current_dbm0(&answerer_meter));
 
-            fsk_rx(&answerer_rx, caller_model_amp, samples);
+            fsk_rx(answerer_rx, caller_model_amp, samples);
             for (i = 0;  i < samples;  i++)
                 out_amp[2*i] = caller_model_amp[i];
             for (  ;  i < BLOCK_LEN;  i++)
                 out_amp[2*i] = 0;
 
-            fsk_rx(&caller_rx, answerer_model_amp, samples);
+            fsk_rx(caller_rx, answerer_model_amp, samples);
             for (i = 0;  i < samples;  i++)
                 out_amp[2*i + 1] = answerer_model_amp[i];
             for (  ;  i < BLOCK_LEN;  i++)
@@ -485,17 +489,17 @@
                 }
                 if (modem_under_test_1 >= 0)
                 {
-                    fsk_tx_init(&caller_tx, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
-                    fsk_tx_set_modem_status_handler(&caller_tx, tx_status, (void *) &caller_tx);
-                    fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
-                    fsk_rx_set_modem_status_handler(&answerer_rx, rx_status, (void *) &answerer_rx);
+                    caller_tx = fsk_tx_init(NULL, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
+                    fsk_tx_set_modem_status_handler(caller_tx, tx_status, (void *) &caller_tx);
+                    answerer_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
+                    fsk_rx_set_modem_status_handler(answerer_rx, rx_status, (void *) &answerer_rx);
                 }
                 if (modem_under_test_2 >= 0)
                 {
-                    fsk_tx_init(&answerer_tx, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
-                    fsk_tx_set_modem_status_handler(&answerer_tx, tx_status, (void *) &answerer_tx);
-                    fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
-                    fsk_rx_set_modem_status_handler(&caller_rx, rx_status, (void *) &caller_rx);
+                    answerer_tx = fsk_tx_init(NULL, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
+                    fsk_tx_set_modem_status_handler(answerer_tx, tx_status, (void *) &answerer_tx);
+                    caller_rx = fsk_rx_init(NULL, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
+                    fsk_rx_set_modem_status_handler(caller_rx, rx_status, (void *) &caller_rx);
                 }
                 noise_level++;
                 if ((model = both_ways_line_model_init(line_model_no, (float) noise_level, line_model_no, noise_level, channel_codec, 0)) == NULL)

Modified: freeswitch/trunk/libs/spandsp/tests/g1050_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/g1050_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/g1050_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g1050_tests.c,v 1.16 2008/05/13 13:17:25 steveu Exp $
+ * $Id: g1050_tests.c,v 1.17 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -44,6 +44,10 @@
 #define GEN_CONST
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/g168_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/g168_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/g168_tests.c	Tue Jan 27 22:48:03 2009
@@ -24,7 +24,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g168_tests.c,v 1.18 2008/09/04 14:40:05 steveu Exp $
+ * $Id: g168_tests.c,v 1.19 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -36,6 +36,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp/g168models.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/g711_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/g711_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/g711_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g711_tests.c,v 1.14 2008/08/16 15:24:15 steveu Exp $
+ * $Id: g711_tests.c,v 1.15 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page g711_tests_page A-law and u-law conversion tests
@@ -41,6 +41,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/g722_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/g722_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/g722_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g722_tests.c,v 1.27 2008/09/19 14:02:05 steveu Exp $
+ * $Id: g722_tests.c,v 1.29 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \file */
@@ -56,6 +56,9 @@
 and the resulting audio stored in post_g722.wav.
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -70,6 +73,10 @@
 
 #include "spandsp.h"
 
+#if 1 //defined(WITH_SPANDSP_INTERNALS)
+#include "spandsp/private/g722.h"
+#endif
+
 #define G722_SAMPLE_RATE    16000
 
 #define BLOCK_LEN           320
@@ -230,6 +237,7 @@
     int outframes;
     int samples;
     int mode;
+    int opt;
     int itutests;
     int bit_rate;
     int eight_k_in;
@@ -239,58 +247,43 @@
     int16_t outdata[BLOCK_LEN];
     uint8_t adpcmdata[BLOCK_LEN];
 
-    i = 1;
     bit_rate = 64000;
     eight_k_in = FALSE;
     eight_k_out = FALSE;
     itutests = TRUE;
-    while (argc > i)
+    while ((opt = getopt(argc, argv, "b:i:o:")) != -1)
     {
-        if (strcmp(argv[i], "-48") == 0)
-        {
-            bit_rate = 48000;
-            itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-56") == 0)
+        switch (opt)
         {
-            bit_rate = 56000;
-            itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-64") == 0)
-        {
-            bit_rate = 64000;
+        case 'b':
+            bit_rate = atoi(optarg);
+            if (bit_rate != 48000  &&  bit_rate != 56000  &&  bit_rate != 64000)
+            {
+                fprintf(stderr, "Invalid bit rate selected. Only 48000, 56000 and 64000 are valid.\n");
+                exit(2);
+            }
             itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-8k8k") == 0)
-        {
-            eight_k_in = TRUE;
-            eight_k_out = TRUE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-8k16k") == 0)
-        {
-            eight_k_in = TRUE;
-            eight_k_out = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-16k8k") == 0)
-        {
-            eight_k_in = FALSE;
-            eight_k_out = TRUE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-16k16k") == 0)
-        {
-            eight_k_in = FALSE;
-            eight_k_out = FALSE;
-            i++;
-        }
-        else
-        {
-            fprintf(stderr, "Unknown parameter %s specified.\n", argv[i]);
+            break;
+        case 'i':
+            i = atoi(optarg);
+            if (i != 8000  &&  i != 16000)
+            {
+                fprintf(stderr, "Invalid incoming sample rate. Only 8000 and 16000 are valid.\n");
+                exit(2);
+            }
+            eight_k_in = (i == 8000);            
+            break;
+        case 'o':
+            i = atoi(optarg);
+            if (i != 8000  &&  i != 16000)
+            {
+                fprintf(stderr, "Invalid incoming sample rate. Only 8000 and 16000 are valid.\n");
+                exit(2);
+            }
+            eight_k_out = (i == 8000);            
+            break;
+        default:
+            //usage();
             exit(2);
         }
     }

Modified: freeswitch/trunk/libs/spandsp/tests/g726_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/g726_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/g726_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: g726_tests.c,v 1.28 2008/09/28 14:36:25 steveu Exp $
+ * $Id: g726_tests.c,v 1.31 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \file */
@@ -60,6 +60,9 @@
 decompressed, and the resulting audio stored in post_g726.wav.
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -72,6 +75,10 @@
 #include <ctype.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -1078,6 +1085,7 @@
     int len3;
     int i;
     int test;
+    int opt;
     int bits_per_code;
     int itutests;
     int bit_rate;
@@ -1097,45 +1105,27 @@
     bit_rate = 32000;
     itutests = TRUE;
     packing = G726_PACKING_NONE;
-    while (argc > i)
+    while ((opt = getopt(argc, argv, "b:lr")) != -1)
     {
-        if (strcmp(argv[i], "-16") == 0)
-        {
-            bit_rate = 16000;
-            itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-24") == 0)
-        {
-            bit_rate = 24000;
-            itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-32") == 0)
-        {
-            bit_rate = 32000;
-            itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-40") == 0)
+        switch (opt)
         {
-            bit_rate = 40000;
+        case 'b':
+            bit_rate = atoi(optarg);
+            if (bit_rate != 16000  &&  bit_rate != 24000  &&  bit_rate != 32000  &&  bit_rate != 40000)
+            {
+                fprintf(stderr, "Invalid bit rate selected. Only 16000, 24000, 32000 and 40000 are valid.\n");
+                exit(2);
+            }
             itutests = FALSE;
-            i++;
-        }
-        else if (strcmp(argv[i], "-l") == 0)
-        {
+            break;
+        case 'l':
             packing = G726_PACKING_LEFT;
-            i++;
-        }
-        else if (strcmp(argv[i], "-r") == 0)
-        {
+            break;
+        case 'r':
             packing = G726_PACKING_RIGHT;
-            i++;
-        }
-        else
-        {
-            fprintf(stderr, "Unknown parameter %s specified.\n", argv[i]);
+            break;
+        default:
+            //usage();
             exit(2);
         }
     }

Modified: freeswitch/trunk/libs/spandsp/tests/gsm0610_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/gsm0610_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/gsm0610_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: gsm0610_tests.c,v 1.19 2008/08/29 09:28:13 steveu Exp $
+ * $Id: gsm0610_tests.c,v 1.23 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \file */
@@ -35,9 +35,6 @@
     - A generally audio quality test, consisting of compressing and decompressing a speeech
       file for audible comparison.
 
-The speech file should be recorded at 16 bits/sample, 8000 samples/second, and named
-"pre_gsm0610.wav".
-
 \section gsm0610_tests_page_sec_2 How is it used?
 To perform the tests in the GSM 06.10 specification you need to obtain the test data files from the
 specification. These are copyright material, and so cannot be distributed with this test software.
@@ -128,6 +125,10 @@
 #include <ctype.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -521,31 +522,32 @@
     AFfilehandle outhandle;
     int frames;
     int outframes;
+    int bytes;
     int16_t pre_amp[HIST_LEN];
     int16_t post_amp[HIST_LEN];
     uint8_t gsm0610_data[HIST_LEN];
     gsm0610_state_t *gsm0610_enc_state;
     gsm0610_state_t *gsm0610_dec_state;
+    int opt;
     int etsitests;
     int packing;
-    int i;
 
     etsitests = TRUE;
     packing = GSM0610_PACKING_NONE;
-    for (i = 1;  i < argc;  i++)
+    while ((opt = getopt(argc, argv, "lp:")) != -1)
     {
-        if (strcmp(argv[i], "-l") == 0)
+        switch (opt)
         {
+        case 'l':
             etsitests = FALSE;
-            continue;
-        }
-        if (strcmp(argv[i], "-p") == 0)
-        {
-            packing = atoi(argv[++i]);
-            continue;
+            break;
+        case 'p':
+            packing = atoi(optarg);
+            break;
+        default:
+            //usage();
+            exit(2);
         }
-        fprintf(stderr, "Unknown parameter %s specified.\n", argv[i]);
-        exit(2);
     }
 
     if (etsitests)
@@ -597,8 +599,8 @@
 
         while ((frames = afReadFrames(inhandle, AF_DEFAULT_TRACK, pre_amp, 2*BLOCK_LEN)))
         {
-            gsm0610_encode(gsm0610_enc_state, gsm0610_data, pre_amp, (packing == GSM0610_PACKING_WAV49)  ?  BLOCK_LEN  :  2*BLOCK_LEN);
-            gsm0610_decode(gsm0610_dec_state, post_amp, gsm0610_data, (packing == GSM0610_PACKING_WAV49)  ?  33  :  65);
+            bytes = gsm0610_encode(gsm0610_enc_state, gsm0610_data, pre_amp, frames);
+            gsm0610_decode(gsm0610_dec_state, post_amp, gsm0610_data, bytes);
             outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, post_amp, frames);
         }
     

Modified: freeswitch/trunk/libs/spandsp/tests/hdlc_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/hdlc_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/hdlc_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: hdlc_tests.c,v 1.46 2008/09/07 12:55:13 steveu Exp $
+ * $Id: hdlc_tests.c,v 1.48 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \file */
@@ -43,6 +43,7 @@
 #include <string.h>
 
 #include "spandsp.h"
+#include "spandsp/private/hdlc.h"
 
 int ref_len;
 uint8_t buf[1000];
@@ -789,6 +790,8 @@
 
 static void decode_handler(void *user_data, const uint8_t *pkt, int len, int ok)
 {
+    int i;
+
     if (len < 0)
     {
         /* Special conditions */
@@ -798,6 +801,10 @@
     if (ok)
     {
         printf("Good frame, len = %d\n", len);
+        printf("HDLC:  ");
+        for (i = 0;  i < len;  i++)
+            printf("%02X ", pkt[i]);
+        printf("\n");
     }
     else
     {
@@ -819,7 +826,7 @@
         exit(2);
     }
 
-    hdlc_rx_init(&rx, TRUE, TRUE, 2, decode_handler, NULL);
+    hdlc_rx_init(&rx, FALSE, TRUE, 2, decode_handler, NULL);
     while (fgets(buf, 1024, in))
     {
         if (sscanf(buf, "Rx bit %*d - %d", &bit) == 1)

Modified: freeswitch/trunk/libs/spandsp/tests/ima_adpcm_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/ima_adpcm_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/ima_adpcm_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: ima_adpcm_tests.c,v 1.34 2008/08/29 09:28:13 steveu Exp $
+ * $Id: ima_adpcm_tests.c,v 1.35 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -51,6 +51,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/line_model_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/line_model_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/line_model_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: line_model_tests.c,v 1.24 2008/05/13 13:17:26 steveu Exp $
+ * $Id: line_model_tests.c,v 1.26 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \page line_model_tests_page Telephony line model tests
@@ -45,6 +45,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -339,38 +343,35 @@
     int line_model_no;
     int speech_test;
     int log_audio;
-    int i;
+    int opt;
 
+    channel_codec = MUNGE_CODEC_NONE;
+    log_audio = FALSE;
     line_model_no = 0;
+    rbs_pattern = 0;
     speech_test = FALSE;
-    log_audio = FALSE;
-    channel_codec = MUNGE_CODEC_NONE;
-    for (i = 1;  i < argc;  i++)
+    while ((opt = getopt(argc, argv, "c:lm:r:s:")) != -1)
     {
-        if (strcmp(argv[i], "-c") == 0)
-        {
-            channel_codec = atoi(argv[++i]);
-            continue;
-        }
-        if (strcmp(argv[i], "-l") == 0)
+        switch (opt)
         {
+        case 'c':
+            channel_codec = atoi(optarg);
+            break;
+        case 'l':
             log_audio = TRUE;
-            continue;
-        }
-        if (strcmp(argv[i], "-m") == 0)
-        {
-            line_model_no = atoi(argv[++i]);
-            continue;
-        }
-        if (strcmp(argv[i], "-r") == 0)
-        {
-            rbs_pattern = atoi(argv[++i]);
-            continue;
-        }
-        if (strcmp(argv[i], "-s") == 0)
-        {
-            speech_test = TRUE;
-            continue;
+            break;
+        case 'm':
+            line_model_no = atoi(optarg);
+            break;
+        case 'r':
+            rbs_pattern = atoi(optarg);
+            break;
+        case 's':
+            speech_test = atoi(optarg);
+            break;
+        default:
+            //usage();
+            exit(2);
         }
     }
     complexify_tests();

Modified: freeswitch/trunk/libs/spandsp/tests/logging_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/logging_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/logging_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: logging_tests.c,v 1.14 2008/05/13 13:17:26 steveu Exp $
+ * $Id: logging_tests.c,v 1.15 2008/11/30 13:44:35 steveu Exp $
  */
 
 /*! \page logging_tests_page Logging tests
@@ -42,6 +42,10 @@
 #include <memory.h>
 #include <time.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 static int tests_failed = FALSE;

Modified: freeswitch/trunk/libs/spandsp/tests/lpc10_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/lpc10_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/lpc10_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: lpc10_tests.c,v 1.21 2008/08/29 09:28:13 steveu Exp $
+ * $Id: lpc10_tests.c,v 1.23 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \file */
@@ -48,6 +48,10 @@
 #include <ctype.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -89,6 +93,7 @@
     int compress_file;
     int decompress_file;
     int len;
+    int opt;
     int enc_len;
     int dec_len;
 
@@ -96,27 +101,25 @@
     decompress = FALSE;
     log_error = TRUE;
     in_file_name = IN_FILE_NAME;
-    for (i = 1;  i < argc;  i++)
+    while ((opt = getopt(argc, argv, "cdi:l")) != -1)
     {
-        if (strcmp(argv[i], "-c") == 0)
+        switch (opt)
         {
+        case 'c':
             compress = TRUE;
-            continue;
-        }
-        if (strcmp(argv[i], "-d") == 0)
-        {
+            break;
+        case 'd':
             decompress = TRUE;
-            continue;
-        }
-        if (strcmp(argv[i], "-i") == 0)
-        {
-            in_file_name = argv[++i];
-            continue;
-        }
-        if (strcmp(argv[i], "-l") == 0)
-        {
+            break;
+        case 'i':
+            in_file_name = optarg;
+            break;
+        case 'l':
             log_error = FALSE;
-            continue;
+            break;
+        default:
+            //usage();
+            exit(2);
         }
     }
 

Modified: freeswitch/trunk/libs/spandsp/tests/make_g168_css.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/make_g168_css.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/make_g168_css.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: make_g168_css.c,v 1.15 2008/08/29 09:28:13 steveu Exp $
+ * $Id: make_g168_css.c,v 1.16 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \page makecss_page CSS construction for G.168 testing
@@ -53,6 +53,10 @@
 #define GEN_CONST
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp/g168models.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/modem_connect_tones_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/modem_connect_tones_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/modem_connect_tones_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: modem_connect_tones_tests.c,v 1.27 2008/08/29 09:28:13 steveu Exp $
+ * $Id: modem_connect_tones_tests.c,v 1.29 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page modem_connect_tones_tests_page Modem connect tones tests
@@ -30,6 +30,9 @@
 These tests...
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -41,6 +44,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/modem_echo_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/modem_echo_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/modem_echo_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: modem_echo_tests.c,v 1.30 2008/08/29 09:28:13 steveu Exp $
+ * $Id: modem_echo_tests.c,v 1.31 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page modem_echo_can_tests_page Line echo cancellation for modems tests
@@ -92,9 +92,14 @@
 #define GEN_CONST
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp/g168models.h"
 #include "spandsp-sim.h"
+
 #if defined(ENABLE_GUI)
 #include "echo_monitor.h"
 #endif

Modified: freeswitch/trunk/libs/spandsp/tests/noise_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/noise_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/noise_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: noise_tests.c,v 1.16 2008/08/17 14:21:26 steveu Exp $
+ * $Id: noise_tests.c,v 1.17 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page noise_tests_page Noise generator tests
@@ -38,6 +38,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/oki_adpcm_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/oki_adpcm_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/oki_adpcm_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: oki_adpcm_tests.c,v 1.35 2008/09/04 14:40:05 steveu Exp $
+ * $Id: oki_adpcm_tests.c,v 1.36 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -52,6 +52,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/playout_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/playout_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/playout_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: playout_tests.c,v 1.26 2008/07/28 15:14:30 steveu Exp $
+ * $Id: playout_tests.c,v 1.27 2008/11/15 14:27:29 steveu Exp $
  */
 
 /*! \page playout_tests_page Playout (jitter buffering) tests
@@ -42,6 +42,8 @@
 
 #include "spandsp.h"
 
+#include "spandsp/private/time_scale.h"
+
 #define INPUT_FILE_NAME     "playout_in.wav"
 #define OUTPUT_FILE_NAME    "playout_out.wav"
 

Modified: freeswitch/trunk/libs/spandsp/tests/power_meter_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/power_meter_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/power_meter_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: power_meter_tests.c,v 1.21 2008/05/13 13:17:26 steveu Exp $
+ * $Id: power_meter_tests.c,v 1.22 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page power_meter_tests_page Power meter tests
@@ -43,6 +43,10 @@
 #include <memory.h>
 #include <time.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 int main(int argc, char *argv[])

Modified: freeswitch/trunk/libs/spandsp/tests/queue_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/queue_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/queue_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: queue_tests.c,v 1.11 2008/08/10 03:42:38 steveu Exp $
+ * $Id: queue_tests.c,v 1.12 2008/11/30 13:08:42 steveu Exp $
  */
 
 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. */
@@ -43,6 +43,10 @@
 #include <pthread.h>
 #include <sched.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define BUF_LEN     10000

Modified: freeswitch/trunk/libs/spandsp/tests/r2_mf_rx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/r2_mf_rx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/r2_mf_rx_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: r2_mf_rx_tests.c,v 1.10 2008/05/13 13:17:26 steveu Exp $
+ * $Id: r2_mf_rx_tests.c,v 1.12 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -39,6 +39,9 @@
 a fair test of performance in a real PSTN channel.
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -50,6 +53,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 /* R2 tone generation specs.

Modified: freeswitch/trunk/libs/spandsp/tests/r2_mf_tx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/r2_mf_tx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/r2_mf_tx_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: r2_mf_tx_tests.c,v 1.13 2008/08/16 15:24:16 steveu Exp $
+ * $Id: r2_mf_tx_tests.c,v 1.15 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -35,6 +35,9 @@
 ???.
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -46,6 +49,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/regression_tests.sh
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/regression_tests.sh	(original)
+++ freeswitch/trunk/libs/spandsp/tests/regression_tests.sh	Tue Jan 27 22:48:03 2009
@@ -17,7 +17,7 @@
 # License along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
-# $Id: regression_tests.sh,v 1.53 2008/09/18 12:09:51 steveu Exp $
+# $Id: regression_tests.sh,v 1.54 2009/01/12 17:20:59 steveu Exp $
 #
 
 ITUTESTS_TIF=../test-data/itu/fax/itutests.tif
@@ -665,28 +665,28 @@
 #echo tone_generate_tests completed OK
 echo tone_generate_tests not enabled
 
-./v17_tests -s -42 14400 >$STDOUT_DEST 2>$STDERR_DEST
+./v17_tests -b 14400 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v17_tests failed!
     exit $RETVAL
 fi
-./v17_tests -s -42 12000 >$STDOUT_DEST 2>$STDERR_DEST
+./v17_tests -b 12000 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v17_tests failed!
     exit $RETVAL
 fi
-./v17_tests -s -42 9600 >$STDOUT_DEST 2>$STDERR_DEST
+./v17_tests -b 9600 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v17_tests failed!
     exit $RETVAL
 fi
-./v17_tests -s -42 7200 >$STDOUT_DEST 2>$STDERR_DEST
+./v17_tests -b 7200 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
@@ -695,7 +695,14 @@
 fi
 echo v17_tests completed OK
 
-#./v22bis_tests >$STDOUT_DEST 2>$STDERR_DEST
+#./v22bis_tests -b 2400 >$STDOUT_DEST 2>$STDERR_DEST
+#RETVAL=$?
+#if [ $RETVAL != 0 ]
+#then
+#    echo v22bis_tests failed!
+#    exit $RETVAL
+#fi
+#./v22bis_tests -b 1200 >$STDOUT_DEST 2>$STDERR_DEST
 #RETVAL=$?
 #if [ $RETVAL != 0 ]
 #then
@@ -705,14 +712,14 @@
 #echo v22bis_tests completed OK
 echo v22bis_tests not enabled
 
-./v27ter_tests -s -42 2400 >$STDOUT_DEST 2>$STDERR_DEST
+./v27ter_tests -b 4800 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v27ter_tests failed!
     exit $RETVAL
 fi
-./v27ter_tests -s -42 4800 >$STDOUT_DEST 2>$STDERR_DEST
+./v27ter_tests -b 2400 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
@@ -721,21 +728,21 @@
 fi
 echo v27ter_tests completed OK
 
-./v29_tests -s -42 4800 >$STDOUT_DEST 2>$STDERR_DEST
+./v29_tests -b 9600 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v29_tests failed!
     exit $RETVAL
 fi
-./v29_tests -s -42 7200 >$STDOUT_DEST 2>$STDERR_DEST
+./v29_tests -b 7200 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then
     echo v29_tests failed!
     exit $RETVAL
 fi
-./v29_tests -s -42 9600 >$STDOUT_DEST 2>$STDERR_DEST
+./v29_tests -b 4800 -s -42 >$STDOUT_DEST 2>$STDERR_DEST
 RETVAL=$?
 if [ $RETVAL != 0 ]
 then

Modified: freeswitch/trunk/libs/spandsp/tests/rfc2198_sim_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/rfc2198_sim_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/rfc2198_sim_tests.c	Tue Jan 27 22:48:03 2009
@@ -24,7 +24,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: rfc2198_sim_tests.c,v 1.5 2008/05/13 13:17:26 steveu Exp $
+ * $Id: rfc2198_sim_tests.c,v 1.6 2008/11/30 10:17:31 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -46,6 +46,10 @@
 #define GEN_CONST
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/schedule_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/schedule_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/schedule_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: schedule_tests.c,v 1.19 2008/05/13 13:17:26 steveu Exp $
+ * $Id: schedule_tests.c,v 1.20 2008/11/30 05:43:37 steveu Exp $
  */
 
 /*! \page schedule_tests_page Event scheduler tests
@@ -41,6 +41,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
 #include "spandsp.h"
 
 uint64_t when1;

Modified: freeswitch/trunk/libs/spandsp/tests/sig_tone_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/sig_tone_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/sig_tone_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: sig_tone_tests.c,v 1.23 2008/08/16 14:59:50 steveu Exp $
+ * $Id: sig_tone_tests.c,v 1.24 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -44,6 +44,10 @@
 #include <memory.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/super_tone_rx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/super_tone_rx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/super_tone_rx_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_rx_tests.c,v 1.29 2008/08/30 16:47:35 steveu Exp $
+ * $Id: super_tone_rx_tests.c,v 1.30 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -55,6 +55,10 @@
 #include <libxml/xinclude.h>
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define IN_FILE_NAME    "super_tone.wav"

Modified: freeswitch/trunk/libs/spandsp/tests/super_tone_tx_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/super_tone_tx_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/super_tone_tx_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: super_tone_tx_tests.c,v 1.23 2008/08/16 15:24:16 steveu Exp $
+ * $Id: super_tone_tx_tests.c,v 1.24 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \file */
@@ -56,6 +56,10 @@
 #include <libxml/xinclude.h>
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/t31_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t31_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t31_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t31_tests.c,v 1.63 2008/09/13 14:32:53 steveu Exp $
+ * $Id: t31_tests.c,v 1.69 2009/01/23 16:07:14 steveu Exp $
  */
 
 /*! \file */
@@ -31,6 +31,9 @@
 \section t31_tests_page_sec_1 What does it do?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -47,6 +50,10 @@
 #include <assert.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp/t30_fcf.h"
 #include "spandsp-sim.h"
@@ -193,14 +200,14 @@
 
 int test_seq_ptr = 0;
 
-t31_state_t t31_state;
+t31_state_t *t31_state;
 
 static int phase_b_handler(t30_state_t *s, void *user_data, int result)
 {
     int i;
     
-    i = (intptr_t) user_data;
-    printf("Phase B handler on channel %d - (0x%X) %s\n", i, result, t30_frametype(result));
+    i = (int) (intptr_t) user_data;
+    printf("%c: Phase B handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -224,10 +231,12 @@
     printf("%c: Phase D: coding method %s\n", i, t4_encoding_to_str(t.encoding));
     printf("%c: Phase D: image size %d\n", i, t.image_size);
     if ((u = t30_get_tx_ident(s)))
-        printf("%d: Phase D: local ident '%s'\n", i, u);
+        printf("%c: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
-        printf("%d: Phase D: remote ident '%s'\n", i, u);
+        printf("%c: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%c: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -237,7 +246,7 @@
     int i;
     
     i = (intptr_t) user_data;
-    printf("Phase E handler on channel %d\n", i);
+    printf("Phase E handler on channel %c\n", i);
     //exit(0);
 }
 /*- End of function --------------------------------------------------------*/
@@ -252,7 +261,7 @@
         break;
     case AT_MODEM_CONTROL_CALL:
         printf("\nModem control - Dialing '%s'\n", num);
-        t31_call_event(&t31_state, AT_CALL_EVENT_CONNECTED);
+        t31_call_event(t31_state, AT_CALL_EVENT_CONNECTED);
         break;
     case AT_MODEM_CONTROL_HANGUP:
         printf("\nModem control - Hanging up\n");
@@ -354,13 +363,13 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
+static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
 {
-    t38_terminal_state_t *t;
+    t31_state_t *t;
     int i;
 
     /* This routine queues messages between two instances of T.38 processing */
-    t = (t38_terminal_state_t *) user_data;
+    t = (t31_state_t *) user_data;
     span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
 
     for (i = 0;  i < count;  i++)
@@ -372,45 +381,125 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-static int t38_tests(int use_gui, int test_sending)
+static int t31_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
+{
+    //t38_terminal_state_t *t;
+    int i;
+
+    /* This routine queues messages between two instances of T.38 processing */
+    //t = (t38_terminal_state_t *) user_data;
+    span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
+
+    for (i = 0;  i < count;  i++)
+    {
+        if (g1050_put(path_b_to_a, buf, len, s->tx_seq_no, when) < 0)
+            printf("Lost packet %d\n", s->tx_seq_no);
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int t38_tests(int use_gui, int test_sending, int model_no, int speed_pattern_no)
 {
-    t38_terminal_state_t t38_state;
+    t38_terminal_state_t *t38_state;
     int fast_send;
     int fast_blocks;
     uint8_t fast_buf[1000];
+    int msg_len;
+    uint8_t msg[1024];
+    int t38_version;
+    int without_pacing;
+    int use_tep;
+    int seq_no;
+    double tx_when;
+    double rx_when;
     t30_state_t *t30;
+    t38_core_state_t *t38_core;
+    logging_state_t *logging;
 
-    if (t31_init(&t31_state, at_tx_handler, NULL, modem_call_control, NULL, NULL, NULL) == NULL)
+    t38_version = 1;
+    without_pacing = FALSE;
+    use_tep = FALSE;
+
+    srand48(0x1234567);
+    if ((path_a_to_b = g1050_init(model_no, speed_pattern_no, 100, 33)) == NULL)
     {
-        fprintf(stderr, "    Cannot start the T.31 FAX modem\n");
+        fprintf(stderr, "Failed to start IP network path model\n");
         exit(2);
     }
-    span_log_set_level(&t31_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-    span_log_set_tag(&t31_state.logging, "T.31");
+    if ((path_b_to_a = g1050_init(model_no, speed_pattern_no, 100, 33)) == NULL)
+    {
+        fprintf(stderr, "Failed to start IP network path model\n");
+        exit(2);
+    }
+    if ((t31_state = t31_init(NULL, at_tx_handler, NULL, modem_call_control, NULL, t31_tx_packet_handler, NULL)) == NULL)
+    {
+        fprintf(stderr, "    Cannot start the T.31 T.38 modem\n");
+        exit(2);
+    }
+    logging = t31_get_logging_state(t31_state);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.31");
+
+    t38_core = t31_get_t38_core_state(t31_state);
+    span_log_set_level(&t38_core->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(&t38_core->logging, "T.31");
 
+    span_log_set_level(&t31_state->at_state.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(&t31_state->at_state.logging, "T.31");
 
-    if (t38_terminal_init(&t38_state, TRUE, tx_packet_handler, &t31_state) == NULL)
+    t31_set_mode(t31_state, TRUE);
+    t38_set_t38_version(t38_core, t38_version);
+
+    if (test_sending)
     {
-        fprintf(stderr, "Cannot start the T.38 channel\n");
-        exit(2);
+        if ((t38_state = t38_terminal_init(NULL, FALSE, t38_tx_packet_handler, t31_state)) == NULL)
+        {
+            fprintf(stderr, "Cannot start the T.38 channel\n");
+            exit(2);
+        }
+        t30 = t38_terminal_get_t30_state(t38_state);
+        t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1);
+        fax_test_seq = fax_send_test_seq;
+        countdown = 0;
+    }
+    else
+    {
+        if ((t38_state = t38_terminal_init(NULL, TRUE, t38_tx_packet_handler, t31_state)) == NULL)
+        {
+            fprintf(stderr, "Cannot start the T.38 channel\n");
+            exit(2);
+        }
+        t30 = t38_terminal_get_t30_state(t38_state);
+        t30_set_tx_file(t30, INPUT_FILE_NAME, -1, -1);
+        fax_test_seq = fax_receive_test_seq;
+        countdown = 250;
     }
-    t30 = t38_terminal_get_t30_state(&t38_state);
-    span_log_set_level(&t38_state.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state.logging, "T.38");
-    span_log_set_level(&t38_state.t38_fe.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state.t38_fe.t38.logging, "T.38-A");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "T.38");
+
+    t30 = t38_terminal_get_t30_state(t38_state);
+    t38_core = t38_terminal_get_t38_core_state(t38_state);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_terminal_set_config(t38_state, without_pacing);
+    t38_terminal_set_tep_mode(t38_state, use_tep);
 
     t30_set_tx_ident(t30, "11111111");
-    t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
-    t30_set_tx_file(t30, INPUT_FILE_NAME, -1, -1);
-    t30_set_phase_b_handler(t30, phase_b_handler, (void *) (intptr_t) 'A');
-    t30_set_phase_d_handler(t30, phase_d_handler, (void *) (intptr_t) 'A');
-    t30_set_phase_e_handler(t30, phase_e_handler, (void *) (intptr_t) 'A');
-    //t30_set_ecm_capability(t30, use_ecm);
-    //if (use_ecm)
-    //    t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
+    t30_set_supported_modems(t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17);
+    //t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
+    t30_set_phase_b_handler(t30, phase_b_handler, (void *) 'A');
+    t30_set_phase_d_handler(t30, phase_d_handler, (void *) 'A');
+    t30_set_phase_e_handler(t30, phase_e_handler, (void *) 'A');
+
+    logging = t38_terminal_get_logging_state(t38_state);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38");
+
+    t38_core = t38_terminal_get_t38_core_state(t38_state);
+    span_log_set_level(&t38_core->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(&t38_core->logging, "T.38");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38");
 
     fast_send = FALSE;
     fast_blocks = 0;
@@ -421,6 +510,27 @@
 #endif
     while (!done)
     {
+        logging = t38_terminal_get_logging_state(t38_state);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_terminal_get_t38_core_state(t38_state);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = t38_terminal_get_t30_state(t38_state);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+
+        logging = t31_get_logging_state(t31_state);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t31_get_t38_core_state(t31_state);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        span_log_bump_samples(&t31_state->at_state.logging, SAMPLES_PER_CHUNK);
+
+        t38_terminal_send_timeout(t38_state, SAMPLES_PER_CHUNK);
+        t31_t38_send_timeout(t31_state, SAMPLES_PER_CHUNK);
+
+        when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
+
         if (kick)
         {
             kick = FALSE;
@@ -429,7 +539,7 @@
                 if (fax_test_seq[test_seq_ptr].command[0])
                 {
                     printf("%s\n", fax_test_seq[test_seq_ptr].command);
-                    t31_at_rx(&t31_state, fax_test_seq[test_seq_ptr].command, fax_test_seq[test_seq_ptr].len_command);
+                    t31_at_rx(t31_state, fax_test_seq[test_seq_ptr].command, fax_test_seq[test_seq_ptr].len_command);
                 }
             }
             else
@@ -455,35 +565,47 @@
                 fast_buf[19] =
                 fast_buf[16] = 1;
             }
-            t31_at_rx(&t31_state, (char *) fast_buf, 36);
+            t31_at_rx(t31_state, (char *) fast_buf, 36);
             if (--fast_blocks == 0)
                 fast_send = FALSE;
         }
-        //t30_len = fax_tx(&fax_state, t30_amp, SAMPLES_PER_CHUNK);
-        //if (t31_rx(&t31_state, t30_amp, t30_len))
-        //    break;
         if (countdown)
         {
             if (answered)
             {
                 countdown = 0;
-                t31_call_event(&t31_state, AT_CALL_EVENT_ANSWERED);
+                t31_call_event(t31_state, AT_CALL_EVENT_ANSWERED);
             }
             else if (--countdown == 0)
             {
-                t31_call_event(&t31_state, AT_CALL_EVENT_ALERTING);
+                t31_call_event(t31_state, AT_CALL_EVENT_ALERTING);
                 countdown = 250;
             }
         }
-
-        //t31_len = t31_tx(&t31_state, t31_amp, SAMPLES_PER_CHUNK);
-        //if (fax_rx(&fax_state, t31_amp, SAMPLES_PER_CHUNK))
-        //    break;
+        while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
+        {
+#if defined(ENABLE_GUI)
+            if (use_gui)
+                media_monitor_rx(seq_no, tx_when, rx_when);
+#endif
+            t38_core = t31_get_t38_core_state(t31_state);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
+        }
+        while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
+        {
+#if defined(ENABLE_GUI)
+            if (use_gui)
+                media_monitor_rx(seq_no, tx_when, rx_when);
+#endif
+            t38_core = t38_terminal_get_t38_core_state(t38_state);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
+        }
 #if defined(ENABLE_GUI)
         if (use_gui)
             media_monitor_update_display();
 #endif
     }
+    t38_terminal_release(t38_state);
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
@@ -492,7 +614,7 @@
 {
     int k;
     int outframes;
-    fax_state_t fax_state;
+    fax_state_t *fax_state;
     int16_t t30_amp[SAMPLES_PER_CHUNK];
     int16_t t31_amp[SAMPLES_PER_CHUNK];
     int16_t silence[SAMPLES_PER_CHUNK];
@@ -505,6 +627,7 @@
     int fast_blocks;
     uint8_t fast_buf[1000];
     t30_state_t *t30;
+    logging_state_t *logging;
 
     wave_handle = AF_NULL_FILEHANDLE;
     if (log_audio)
@@ -528,26 +651,27 @@
         }
     }
 
-    if (t31_init(&t31_state, at_tx_handler, NULL, modem_call_control, NULL, NULL, NULL) == NULL)
+    if ((t31_state = t31_init(NULL, at_tx_handler, NULL, modem_call_control, NULL, NULL, NULL)) == NULL)
     {
         fprintf(stderr, "    Cannot start the T.31 FAX modem\n");
         exit(2);
     }
-    span_log_set_level(&t31_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-    span_log_set_tag(&t31_state.logging, "T.31");
+    logging = t31_get_logging_state(t31_state);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.31");
 
     if (test_sending)
     {
-        fax_init(&fax_state, FALSE);
-        t30 = fax_get_t30_state(&fax_state);
+        fax_state = fax_init(NULL, FALSE);
+        t30 = fax_get_t30_state(fax_state);
         t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1);
         fax_test_seq = fax_send_test_seq;
         countdown = 0;
     }
     else
     {
-        fax_init(&fax_state, TRUE);
-        t30 = fax_get_t30_state(&fax_state);
+        fax_state = fax_init(NULL, TRUE);
+        t30 = fax_get_t30_state(fax_state);
         t30_set_tx_file(t30, INPUT_FILE_NAME, -1, -1);
         fax_test_seq = fax_receive_test_seq;
         countdown = 250;
@@ -555,15 +679,18 @@
     
     t30_set_tx_ident(t30, "11111111");
     t30_set_supported_modems(t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17);
-    t30_set_phase_b_handler(t30, phase_b_handler, (void *) 0);
-    t30_set_phase_d_handler(t30, phase_d_handler, (void *) 0);
-    t30_set_phase_e_handler(t30, phase_e_handler, (void *) 0);
+    t30_set_phase_b_handler(t30, phase_b_handler, (void *) 'A');
+    t30_set_phase_d_handler(t30, phase_d_handler, (void *) 'A');
+    t30_set_phase_e_handler(t30, phase_e_handler, (void *) 'A');
     memset(t30_amp, 0, sizeof(t30_amp));
     
-    span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-    span_log_set_tag(&t30->logging, "FAX");
-    span_log_set_level(&fax_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
-    span_log_set_tag(&fax_state.logging, "FAX");
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX");
+
+    logging = fax_get_logging_state(fax_state);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX");
 
     fast_send = FALSE;
     fast_blocks = 0;
@@ -578,7 +705,7 @@
                 if (fax_test_seq[test_seq_ptr].command[0])
                 {
                     printf("%s\n", fax_test_seq[test_seq_ptr].command);
-                    t31_at_rx(&t31_state, fax_test_seq[test_seq_ptr].command, fax_test_seq[test_seq_ptr].len_command);
+                    t31_at_rx(t31_state, fax_test_seq[test_seq_ptr].command, fax_test_seq[test_seq_ptr].len_command);
                 }
             }
             else
@@ -604,11 +731,11 @@
                 fast_buf[19] =
                 fast_buf[16] = 1;
             }
-            t31_at_rx(&t31_state, (char *) fast_buf, 36);
+            t31_at_rx(t31_state, (char *) fast_buf, 36);
             if (--fast_blocks == 0)
                 fast_send = FALSE;
         }
-        t30_len = fax_tx(&fax_state, t30_amp, SAMPLES_PER_CHUNK);
+        t30_len = fax_tx(fax_state, t30_amp, SAMPLES_PER_CHUNK);
         /* The receive side always expects a full block of samples, but the
            transmit side may not be sending any when it doesn't need to. We
            may need to pad with some silence. */
@@ -622,23 +749,23 @@
             for (k = 0;  k < t30_len;  k++)
                 out_amp[2*k] = t30_amp[k];
         }
-        if (t31_rx(&t31_state, t30_amp, t30_len))
+        if (t31_rx(t31_state, t30_amp, t30_len))
             break;
         if (countdown)
         {
             if (answered)
             {
                 countdown = 0;
-                t31_call_event(&t31_state, AT_CALL_EVENT_ANSWERED);
+                t31_call_event(t31_state, AT_CALL_EVENT_ANSWERED);
             }
             else if (--countdown == 0)
             {
-                t31_call_event(&t31_state, AT_CALL_EVENT_ALERTING);
+                t31_call_event(t31_state, AT_CALL_EVENT_ALERTING);
                 countdown = 250;
             }
         }
 
-        t31_len = t31_tx(&t31_state, t31_amp, SAMPLES_PER_CHUNK);
+        t31_len = t31_tx(t31_state, t31_amp, SAMPLES_PER_CHUNK);
         if (t31_len < SAMPLES_PER_CHUNK)
         {
             memset(t31_amp + t31_len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t31_len));
@@ -649,7 +776,7 @@
             for (k = 0;  k < t31_len;  k++)
                 out_amp[2*k + 1] = t31_amp[k];
         }
-        if (fax_rx(&fax_state, t31_amp, SAMPLES_PER_CHUNK))
+        if (fax_rx(fax_state, t31_amp, SAMPLES_PER_CHUNK))
             break;
 
         if (log_audio)
@@ -727,7 +854,7 @@
     }
 
     if (t38_mode)
-        t38_tests(use_gui, test_sending);
+        t38_tests(use_gui, test_sending, 0, 1);
     else
         t30_tests(log_audio, test_sending);
     if (done)

Modified: freeswitch/trunk/libs/spandsp/tests/t38_core_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_core_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_core_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_core_tests.c,v 1.13 2008/05/13 13:17:26 steveu Exp $
+ * $Id: t38_core_tests.c,v 1.14 2008/11/30 13:44:35 steveu Exp $
  */
 
 /*! \file */
@@ -53,6 +53,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define MAX_FIELDS      42

Modified: freeswitch/trunk/libs/spandsp/tests/t38_gateway_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_gateway_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_gateway_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_gateway_tests.c,v 1.76 2008/08/16 15:24:16 steveu Exp $
+ * $Id: t38_gateway_tests.c,v 1.79 2009/01/07 12:50:53 steveu Exp $
  */
 
 /*! \file */
@@ -34,6 +34,9 @@
     FAX machine <-> T.38 gateway <-> T.38 gateway <-> FAX machine
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -60,6 +63,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -77,10 +84,10 @@
 #define OUTPUT_FILE_NAME_T30B   "t38_gateway_t30b.wav"
 #define OUTPUT_FILE_NAME_T38B   "t38_gateway_t38b.wav"
 
-fax_state_t fax_state_a;
-t38_gateway_state_t t38_state_a;
-t38_gateway_state_t t38_state_b;
-fax_state_t fax_state_b;
+fax_state_t *fax_state_a;
+t38_gateway_state_t *t38_state_a;
+t38_gateway_state_t *t38_state_b;
+fax_state_t *fax_state_b;
 
 g1050_state_t *path_a_to_b;
 g1050_state_t *path_b_to_a;
@@ -124,7 +131,9 @@
         printf("%c: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
         printf("%c: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%c: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -269,7 +278,11 @@
     int use_gui;
     int opt;
     t38_stats_t stats;
+    fax_state_t *fax;
     t30_state_t *t30;
+    t38_gateway_state_t *t38;
+    t38_core_state_t *t38_core;
+    logging_state_t *logging;
 
     log_audio = FALSE;
     use_ecm = FALSE;
@@ -363,14 +376,15 @@
         exit(2);
     }
 
-    if (fax_init(&fax_state_a, TRUE) == NULL)
+    if ((fax_state_a = fax_init(NULL, TRUE)) == NULL)
     {
         fprintf(stderr, "Cannot start FAX\n");
         exit(2);
     }
-    t30 = fax_get_t30_state(&fax_state_a);
-    fax_set_transmit_on_idle(&fax_state_a, use_transmit_on_idle);
-    fax_set_tep_mode(&fax_state_a, use_tep);
+    fax = fax_state_a;
+    t30 = fax_get_t30_state(fax);
+    fax_set_transmit_on_idle(fax, use_transmit_on_idle);
+    fax_set_tep_mode(fax, use_tep);
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "11111111");
     t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
@@ -383,57 +397,75 @@
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
     t30_set_minimum_scan_line_time(t30, 40);
     //t30_set_iaf_mode(t30, T30_IAF_MODE_NO_FILL_BITS);
-    span_log_set_level(&fax_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&fax_state_a.logging, "FAX-A ");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "FAX-A ");
+
+    logging = fax_get_logging_state(fax);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-A ");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-A ");
+
     memset(t30_amp_a, 0, sizeof(t30_amp_a));
     memset(t38_amp_hist_a, 0, sizeof(t38_amp_hist_a));
     memset(t38_amp_hist_b, 0, sizeof(t38_amp_hist_b));
 
-    if (t38_gateway_init(&t38_state_a, tx_packet_handler_a, &t38_state_b) == NULL)
+    if ((t38_state_a = t38_gateway_init(NULL, tx_packet_handler_a, t38_state_b)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t38_gateway_set_transmit_on_idle(&t38_state_a, use_transmit_on_idle);
-    t38_gateway_set_supported_modems(&t38_state_a, supported_modems);
-    //t38_gateway_set_nsx_suppression(&t38_state_a, NULL, 0, NULL, 0);
-    t38_gateway_set_fill_bit_removal(&t38_state_a, fill_removal);
-    t38_gateway_set_real_time_frame_handler(&t38_state_a, real_time_frame_handler, NULL);
-    t38_set_t38_version(&t38_state_a.t38x.t38, t38_version);
-    t38_gateway_set_ecm_capability(&t38_state_a, use_ecm);
-    span_log_set_level(&t38_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.logging, "T.38-A");
-    span_log_set_level(&t38_state_a.t38x.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.t38x.t38.logging, "T.38-A");
+    t38 = t38_state_a;
+    t38_core = t38_gateway_get_t38_core_state(t38);
+    t38_gateway_set_transmit_on_idle(t38, use_transmit_on_idle);
+    t38_gateway_set_supported_modems(t38, supported_modems);
+    //t38_gateway_set_nsx_suppression(t38, NULL, 0, NULL, 0);
+    t38_gateway_set_fill_bit_removal(t38, fill_removal);
+    t38_gateway_set_real_time_frame_handler(t38, real_time_frame_handler, NULL);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_gateway_set_ecm_capability(t38, use_ecm);
+
+    logging = t38_gateway_get_logging_state(t38);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
     memset(t38_amp_a, 0, sizeof(t38_amp_a));
 
-    if (t38_gateway_init(&t38_state_b, tx_packet_handler_b, &t38_state_a) == NULL)
+    if ((t38_state_b = t38_gateway_init(NULL, tx_packet_handler_b, t38_state_a)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t38_gateway_set_transmit_on_idle(&t38_state_b, use_transmit_on_idle);
-    t38_gateway_set_supported_modems(&t38_state_b, supported_modems);
-    //t38_gateway_set_nsx_suppression(&t38_state_b, FALSE);
-    t38_gateway_set_fill_bit_removal(&t38_state_b, fill_removal);
-    t38_set_t38_version(&t38_state_b.t38x.t38, t38_version);
-    t38_gateway_set_ecm_capability(&t38_state_b, use_ecm);
-    span_log_set_level(&t38_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.logging, "T.38-B");
-    span_log_set_level(&t38_state_b.t38x.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.t38x.t38.logging, "T.38-B");
+    t38 = t38_state_b;
+    t38_core = t38_gateway_get_t38_core_state(t38);
+    t38_gateway_set_transmit_on_idle(t38, use_transmit_on_idle);
+    t38_gateway_set_supported_modems(t38, supported_modems);
+    //t38_gateway_set_nsx_suppression(t38, FALSE);
+    t38_gateway_set_fill_bit_removal(t38, fill_removal);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_gateway_set_ecm_capability(t38, use_ecm);
+
+    logging = t38_gateway_get_logging_state(t38);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
     memset(t38_amp_b, 0, sizeof(t38_amp_b));
 
-    if (fax_init(&fax_state_b, FALSE) == NULL)
+    if ((fax_state_b = fax_init(NULL, FALSE)) == NULL)
     {
         fprintf(stderr, "Cannot start FAX\n");
         exit(2);
     }
-    t30 = fax_get_t30_state(&fax_state_b);
-    fax_set_transmit_on_idle(&fax_state_b, use_transmit_on_idle);
-    fax_set_tep_mode(&fax_state_b, use_tep);
+    fax = fax_state_b;
+    t30 = fax_get_t30_state(fax);
+    fax_set_transmit_on_idle(fax, use_transmit_on_idle);
+    fax_set_tep_mode(fax, use_tep);
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "22222222");
     t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
@@ -445,10 +477,15 @@
     if (use_ecm)
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
     t30_set_minimum_scan_line_time(t30, 40);
-    span_log_set_level(&fax_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&fax_state_b.logging, "FAX-B ");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "FAX-B ");
+
+    logging = fax_get_logging_state(fax);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-B ");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-B ");
+
     memset(t30_amp_b, 0, sizeof(t30_amp_b));
 
 #if defined(ENABLE_GUI)
@@ -458,19 +495,29 @@
     hist_ptr = 0;
     for (;;)
     {
-        t30 = fax_get_t30_state(&fax_state_a);
-        span_log_bump_samples(&fax_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t30->logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t38x.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t38x.t38.logging, SAMPLES_PER_CHUNK);
-        t30 = fax_get_t30_state(&fax_state_b);
-        span_log_bump_samples(&fax_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t30->logging, SAMPLES_PER_CHUNK);
+        logging = fax_get_logging_state(fax_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = fax_get_t30_state(fax_state_a);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_gateway_get_logging_state(t38_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_gateway_get_t38_core_state(t38_state_a);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_gateway_get_logging_state(t38_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_gateway_get_t38_core_state(t38_state_b);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = fax_get_logging_state(fax_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = fax_get_t30_state(fax_state_b);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
         memset(out_amp, 0, sizeof(out_amp));
 
-        t30_len_a = fax_tx(&fax_state_a, t30_amp_a, SAMPLES_PER_CHUNK);
+        t30_len_a = fax_tx(fax_state_a, t30_amp_a, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             /* The receive side always expects a full block of samples, but the
@@ -493,10 +540,10 @@
                 t30_amp_a[i] += t38_amp_hist_a[hist_ptr][i] >> 1;
             memcpy(t38_amp_hist_a[hist_ptr], t38_amp_a, sizeof(int16_t)*SAMPLES_PER_CHUNK);
         }
-        if (t38_gateway_rx(&t38_state_a, t30_amp_a, t30_len_a))
+        if (t38_gateway_rx(t38_state_a, t30_amp_a, t30_len_a))
             break;
 
-        t38_len_a = t38_gateway_tx(&t38_state_a, t38_amp_a, SAMPLES_PER_CHUNK);
+        t38_len_a = t38_gateway_tx(t38_state_a, t38_amp_a, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             if (t38_len_a < SAMPLES_PER_CHUNK)
@@ -510,10 +557,10 @@
             for (i = 0;  i < t38_len_a;  i++)
                 out_amp[i*4 + 1] = t38_amp_a[i];
         }
-        if (fax_rx(&fax_state_a, t38_amp_a, SAMPLES_PER_CHUNK))
+        if (fax_rx(fax_state_a, t38_amp_a, SAMPLES_PER_CHUNK))
             break;
 
-        t30_len_b = fax_tx(&fax_state_b, t30_amp_b, SAMPLES_PER_CHUNK);
+        t30_len_b = fax_tx(fax_state_b, t30_amp_b, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             /* The receive side always expects a full block of samples, but the
@@ -536,10 +583,10 @@
                 t30_amp_b[i] += t38_amp_hist_b[hist_ptr][i] >> 1;
             memcpy(t38_amp_hist_b[hist_ptr], t38_amp_b, sizeof(int16_t)*SAMPLES_PER_CHUNK);
         }
-        if (t38_gateway_rx(&t38_state_b, t30_amp_b, t30_len_b))
+        if (t38_gateway_rx(t38_state_b, t30_amp_b, t30_len_b))
             break;
 
-        t38_len_b = t38_gateway_tx(&t38_state_b, t38_amp_b, SAMPLES_PER_CHUNK);
+        t38_len_b = t38_gateway_tx(t38_state_b, t38_amp_b, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             if (t38_len_b < SAMPLES_PER_CHUNK)
@@ -553,10 +600,10 @@
             for (i = 0;  i < t38_len_b;  i++)
                 out_amp[i*4 + 2] = t38_amp_b[i];
         }
-        if (fax_rx(&fax_state_b, t38_amp_b, SAMPLES_PER_CHUNK))
+        if (fax_rx(fax_state_b, t38_amp_b, SAMPLES_PER_CHUNK))
             break;
 
-        when += 0.02;
+        when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
 
         while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -564,7 +611,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_b.t38x.t38, msg, msg_len, seq_no);
+            t38_core = t38_gateway_get_t38_core_state(t38_state_b);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -572,7 +620,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_a.t38x.t38, msg, msg_len, seq_no);
+            t38_core = t38_gateway_get_t38_core_state(t38_state_a);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         if (log_audio)
         {
@@ -590,18 +639,18 @@
         if (++hist_ptr > 3)
             hist_ptr = 0;
     }
-    t38_gateway_get_transfer_statistics(&t38_state_a, &stats);
+    t38_gateway_get_transfer_statistics(t38_state_a, &stats);
     printf("A side exchanged %d pages at %dbps, in %s mode\n",
            stats.pages_transferred,
            stats.bit_rate,
            (stats.error_correcting_mode)  ?  "ECM"  :  "non-ECM");
-    t38_gateway_get_transfer_statistics(&t38_state_a, &stats);
+    t38_gateway_get_transfer_statistics(t38_state_a, &stats);
     printf("B side exchanged %d pages at %dbps, in %s mode\n",
            stats.pages_transferred,
            stats.bit_rate,
            (stats.error_correcting_mode)  ?  "ECM"  :  "non-ECM");
-    fax_release(&fax_state_a);
-    fax_release(&fax_state_b);
+    fax_release(fax_state_a);
+    fax_release(fax_state_b);
     if (log_audio)
     {
         if (afCloseFile(wave_handle) != 0)

Modified: freeswitch/trunk/libs/spandsp/tests/t38_gateway_to_terminal_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_gateway_to_terminal_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_gateway_to_terminal_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_gateway_to_terminal_tests.c,v 1.60 2008/08/16 15:24:16 steveu Exp $
+ * $Id: t38_gateway_to_terminal_tests.c,v 1.63 2009/01/07 12:50:53 steveu Exp $
  */
 
 /*! \file */
@@ -34,6 +34,9 @@
     FAX machine -> T.38 gateway -> T.38 termination
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -60,6 +63,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -73,9 +80,9 @@
 #define OUTPUT_FILE_NAME        "t38.tif"
 #define OUTPUT_FILE_NAME_WAVE   "t38_gateway_to_terminal.wav"
 
-fax_state_t fax_state_a;
-t38_gateway_state_t t38_state_a;
-t38_terminal_state_t t38_state_b;
+fax_state_t *fax_state_a;
+t38_gateway_state_t *t38_state_a;
+t38_terminal_state_t *t38_state_b;
 
 g1050_state_t *path_a_to_b;
 g1050_state_t *path_b_to_a;
@@ -119,7 +126,9 @@
         printf("%c: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
         printf("%c: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%c: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -237,6 +246,8 @@
     int use_gui;
     int opt;
     t30_state_t *t30;
+    t38_core_state_t *t38_core;
+    logging_state_t *logging;
 
     log_audio = FALSE;
     t38_version = 1;
@@ -325,14 +336,14 @@
         exit(2);
     }
 
-    if (fax_init(&fax_state_a, TRUE) == NULL)
+    if ((fax_state_a = fax_init(NULL, TRUE)) == NULL)
     {
         fprintf(stderr, "Cannot start FAX\n");
         exit(2);
     }
-    t30 = fax_get_t30_state(&fax_state_a);
-    fax_set_transmit_on_idle(&fax_state_a, use_transmit_on_idle);
-    fax_set_tep_mode(&fax_state_a, use_tep);
+    t30 = fax_get_t30_state(fax_state_a);
+    fax_set_transmit_on_idle(fax_state_a, use_transmit_on_idle);
+    fax_set_tep_mode(fax_state_a, use_tep);
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "11111111");
     t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
@@ -343,39 +354,57 @@
     t30_set_ecm_capability(t30, use_ecm);
     if (use_ecm)
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
-    span_log_set_level(&fax_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&fax_state_a.logging, "FAX-A ");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "FAX-A ");
+
+    logging = fax_get_logging_state(fax_state_a);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-A ");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-A ");
+
     memset(t30_amp_a, 0, sizeof(t30_amp_a));
 
-    if (t38_gateway_init(&t38_state_a, tx_packet_handler_a, &t38_state_b) == NULL)
+    if ((t38_state_a = t38_gateway_init(NULL, tx_packet_handler_a, t38_state_b)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t38_gateway_set_transmit_on_idle(&t38_state_a, use_transmit_on_idle);
-    t38_set_t38_version(&t38_state_a.t38x.t38, t38_version);
-    t38_gateway_set_ecm_capability(&t38_state_a, use_ecm);
-    span_log_set_level(&t38_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.logging, "T.38-A");
-    span_log_set_level(&t38_state_a.t38x.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.t38x.t38.logging, "T.38-A");
+    t38_core = t38_gateway_get_t38_core_state(t38_state_a);
+    t38_gateway_set_transmit_on_idle(t38_state_a, use_transmit_on_idle);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_gateway_set_ecm_capability(t38_state_a, use_ecm);
+
+    logging = t38_gateway_get_logging_state(t38_state_a);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
     memset(t38_amp_a, 0, sizeof(t38_amp_a));
 
-    if (t38_terminal_init(&t38_state_b, FALSE, tx_packet_handler_b, &t38_state_a) == NULL)
+    if ((t38_state_b = t38_terminal_init(NULL, FALSE, tx_packet_handler_b, t38_state_a)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t30 = t38_terminal_get_t30_state(&t38_state_b);
-    t38_set_t38_version(&t38_state_b.t38_fe.t38, t38_version);
-    span_log_set_level(&t38_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.logging, "T.38-B");
-    span_log_set_level(&t38_state_b.t38_fe.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.t38_fe.t38.logging, "T.38-B");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "T.38-B");
+    t30 = t38_terminal_get_t30_state(t38_state_b);
+    t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+    t38_set_t38_version(t38_core, t38_version);
+
+    logging = t38_terminal_get_logging_state(t38_state_b);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
 
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "22222222");
@@ -393,18 +422,29 @@
 #endif
     for (;;)
     {
-        span_log_bump_samples(&fax_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&fax_state_a.t30.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t38x.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t38_fe.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t30.logging, SAMPLES_PER_CHUNK);
+        logging = fax_get_logging_state(fax_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = fax_get_t30_state(fax_state_a);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_gateway_get_logging_state(t38_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_gateway_get_t38_core_state(t38_state_a);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_terminal_get_logging_state(t38_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = t38_terminal_get_t30_state(t38_state_b);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
         memset(out_amp, 0, sizeof(out_amp));
 
-        t38_terminal_send_timeout(&t38_state_b, SAMPLES_PER_CHUNK);
+        t38_terminal_send_timeout(t38_state_b, SAMPLES_PER_CHUNK);
 
-        t30_len_a = fax_tx(&fax_state_a, t30_amp_a, SAMPLES_PER_CHUNK);
+        t30_len_a = fax_tx(fax_state_a, t30_amp_a, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             /* The receive side always expects a full block of samples, but the
@@ -426,10 +466,10 @@
             for (i = 0;  i < t30_len_a;  i++)
                 t30_amp_a[i] += t38_amp_a[i] >> 1;
         }
-        if (t38_gateway_rx(&t38_state_a, t30_amp_a, t30_len_a))
+        if (t38_gateway_rx(t38_state_a, t30_amp_a, t30_len_a))
             break;
     
-        t38_len_a = t38_gateway_tx(&t38_state_a, t38_amp_a, SAMPLES_PER_CHUNK);
+        t38_len_a = t38_gateway_tx(t38_state_a, t38_amp_a, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             if (t38_len_a < SAMPLES_PER_CHUNK)
@@ -443,10 +483,10 @@
             for (i = 0;  i < t38_len_a;  i++)
                 out_amp[2*i + 1] = t38_amp_a[i];
         }
-        if (fax_rx(&fax_state_a, t38_amp_a, SAMPLES_PER_CHUNK))
+        if (fax_rx(fax_state_a, t38_amp_a, SAMPLES_PER_CHUNK))
             break;
 
-        when += 0.02;
+        when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
 
         while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -454,7 +494,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_b.t38_fe.t38, msg, msg_len, seq_no);
+            t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -462,7 +503,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_a.t38x.t38, msg, msg_len, seq_no);
+            t38_core = t38_gateway_get_t38_core_state(t38_state_a);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         if (log_audio)
         {
@@ -478,8 +520,8 @@
             media_monitor_update_display();
 #endif
     }
-    fax_release(&fax_state_a);
-    t38_terminal_release(&t38_state_b);
+    fax_release(fax_state_a);
+    t38_terminal_release(t38_state_b);
     if (log_audio)
     {
         if (afCloseFile(wave_handle) != 0)

Modified: freeswitch/trunk/libs/spandsp/tests/t38_non_ecm_buffer_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_non_ecm_buffer_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_non_ecm_buffer_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_non_ecm_buffer_tests.c,v 1.2 2008/09/02 13:56:10 steveu Exp $
+ * $Id: t38_non_ecm_buffer_tests.c,v 1.4 2008/11/30 13:44:35 steveu Exp $
  */
 
 /*! \file */
@@ -55,6 +55,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 int main(int argc, char *argv[])

Modified: freeswitch/trunk/libs/spandsp/tests/t38_terminal_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_terminal_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_terminal_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_terminal_tests.c,v 1.61 2008/08/16 14:59:50 steveu Exp $
+ * $Id: t38_terminal_tests.c,v 1.64 2009/01/07 12:50:53 steveu Exp $
  */
 
 /*! \file */
@@ -34,6 +34,9 @@
     T.38 termination <-> T.38 termination
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -60,6 +63,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -72,8 +79,8 @@
 #define INPUT_FILE_NAME         "../test-data/itu/fax/itutests.tif"
 #define OUTPUT_FILE_NAME        "t38.tif"
 
-t38_terminal_state_t t38_state_a;
-t38_terminal_state_t t38_state_b;
+t38_terminal_state_t *t38_state_a;
+t38_terminal_state_t *t38_state_b;
 
 g1050_state_t *path_a_to_b;
 g1050_state_t *path_b_to_a;
@@ -117,7 +124,9 @@
         printf("%c: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
         printf("%c: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%c: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -229,6 +238,8 @@
     int supported_modems;
     int opt;
     t30_state_t *t30;
+    t38_core_state_t *t38_core;
+    logging_state_t *logging;
 
     t38_version = 1;
     without_pacing = FALSE;
@@ -302,21 +313,28 @@
         exit(2);
     }
 
-    if (t38_terminal_init(&t38_state_a, TRUE, tx_packet_handler_a, &t38_state_b) == NULL)
+    if ((t38_state_a = t38_terminal_init(NULL, TRUE, tx_packet_handler_a, t38_state_b)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t30 = t38_terminal_get_t30_state(&t38_state_a);
-    t38_set_t38_version(&t38_state_a.t38_fe.t38, t38_version);
-    t38_terminal_set_config(&t38_state_a, without_pacing);
-    t38_terminal_set_tep_mode(&t38_state_a, use_tep);
-    span_log_set_level(&t38_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.logging, "T.38-A");
-    span_log_set_level(&t38_state_a.t38_fe.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.t38_fe.t38.logging, "T.38-A");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "T.38-A");
+    t30 = t38_terminal_get_t30_state(t38_state_a);
+    t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_terminal_set_config(t38_state_a, without_pacing);
+    t38_terminal_set_tep_mode(t38_state_a, use_tep);
+    
+    logging = t38_terminal_get_logging_state(t38_state_a);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
 
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "11111111");
@@ -329,21 +347,28 @@
     if (use_ecm)
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
 
-    if (t38_terminal_init(&t38_state_b, FALSE, tx_packet_handler_b, &t38_state_a) == NULL)
+    if ((t38_state_b = t38_terminal_init(NULL, FALSE, tx_packet_handler_b, t38_state_a)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t30 = t38_terminal_get_t30_state(&t38_state_b);
-    t38_set_t38_version(&t38_state_b.t38_fe.t38, t38_version);
-    t38_terminal_set_config(&t38_state_b, without_pacing);
-    t38_terminal_set_tep_mode(&t38_state_b, use_tep);
-    span_log_set_level(&t38_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.logging, "T.38-B");
-    span_log_set_level(&t38_state_b.t38_fe.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.t38_fe.t38.logging, "T.38-B");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "T.38-B");
+    t30 = t38_terminal_get_t30_state(t38_state_b);
+    t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_terminal_set_config(t38_state_b, without_pacing);
+    t38_terminal_set_tep_mode(t38_state_b, use_tep);
+
+    logging = t38_terminal_get_logging_state(t38_state_b);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
 
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "22222222");
@@ -362,17 +387,27 @@
 #endif
     for (;;)
     {
-        span_log_bump_samples(&t38_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t38_fe.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t30.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t38_fe.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t30.logging, SAMPLES_PER_CHUNK);
+        logging = t38_terminal_get_logging_state(t38_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = t38_terminal_get_t30_state(t38_state_a);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_terminal_get_logging_state(t38_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = t38_terminal_get_t30_state(t38_state_b);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
 
-        done[0] = t38_terminal_send_timeout(&t38_state_a, SAMPLES_PER_CHUNK);
-        done[1] = t38_terminal_send_timeout(&t38_state_b, SAMPLES_PER_CHUNK);
+        done[0] = t38_terminal_send_timeout(t38_state_a, SAMPLES_PER_CHUNK);
+        done[1] = t38_terminal_send_timeout(t38_state_b, SAMPLES_PER_CHUNK);
 
-        when += 0.02;
+        when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
 
         while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -380,7 +415,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_b.t38_fe.t38, msg, msg_len, seq_no);
+            t38_core = t38_terminal_get_t38_core_state(t38_state_b);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -388,7 +424,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_a.t38_fe.t38, msg, msg_len, seq_no);
+            t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         if (done[0]  &&  done[1])
             break;
@@ -397,8 +434,8 @@
             media_monitor_update_display();
 #endif
     }
-    t38_terminal_release(&t38_state_a);
-    t38_terminal_release(&t38_state_b);
+    t38_terminal_release(t38_state_a);
+    t38_terminal_release(t38_state_b);
     if (!succeeded[0]  ||  !succeeded[1])
     {
         printf("Tests failed\n");

Modified: freeswitch/trunk/libs/spandsp/tests/t38_terminal_to_gateway_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t38_terminal_to_gateway_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t38_terminal_to_gateway_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t38_terminal_to_gateway_tests.c,v 1.59 2008/08/16 15:24:16 steveu Exp $
+ * $Id: t38_terminal_to_gateway_tests.c,v 1.62 2009/01/07 12:50:53 steveu Exp $
  */
 
 /*! \file */
@@ -34,6 +34,9 @@
     T.38 termination -> T.38 gateway -> FAX machine
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include <config.h>
 #endif
@@ -60,6 +63,10 @@
 #include <sys/time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -73,9 +80,9 @@
 #define OUTPUT_FILE_NAME        "t38.tif"
 #define OUTPUT_FILE_NAME_WAVE   "t38_terminal_to_gateway.wav"
 
-t38_terminal_state_t t38_state_a;
-t38_gateway_state_t t38_state_b;
-fax_state_t fax_state_b;
+t38_terminal_state_t *t38_state_a;
+t38_gateway_state_t *t38_state_b;
+fax_state_t *fax_state_b;
 
 g1050_state_t *path_a_to_b;
 g1050_state_t *path_b_to_a;
@@ -119,7 +126,9 @@
         printf("%c: Phase D: local ident '%s'\n", i, u);
     if ((u = t30_get_rx_ident(s)))
         printf("%c: Phase D: remote ident '%s'\n", i, u);
+#if defined(WITH_SPANDSP_INTERNALS)
     printf("%c: Phase D: bits per row - min %d, max %d\n", i, s->t4.min_row_bits, s->t4.max_row_bits);
+#endif
     return T30_ERR_OK;
 }
 /*- End of function --------------------------------------------------------*/
@@ -237,6 +246,8 @@
     int supported_modems;
     int opt;
     t30_state_t *t30;
+    t38_core_state_t *t38_core;
+    logging_state_t *logging;
 
     log_audio = FALSE;
     t38_version = 1;
@@ -325,19 +336,26 @@
         exit(2);
     }
 
-    if (t38_terminal_init(&t38_state_a, TRUE, tx_packet_handler_a, &t38_state_b) == NULL)
+    if ((t38_state_a = t38_terminal_init(NULL, TRUE, tx_packet_handler_a, &t38_state_b)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t30 = t38_terminal_get_t30_state(&t38_state_a);
-    t38_set_t38_version(&t38_state_a.t38_fe.t38, t38_version);
-    span_log_set_level(&t38_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.logging, "T.38-A");
-    span_log_set_level(&t38_state_a.t38_fe.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_a.t38_fe.t38.logging, "T.38-A");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "T.38-A");
+    t30 = t38_terminal_get_t30_state(t38_state_a);
+    t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+    t38_set_t38_version(t38_core, t38_version);
+
+    logging = t38_terminal_get_logging_state(t38_state_a);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-A");
 
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "11111111");
@@ -349,28 +367,34 @@
     if (use_ecm)
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
 
-    if (t38_gateway_init(&t38_state_b, tx_packet_handler_b, &t38_state_a) == NULL)
+    if ((t38_state_b = t38_gateway_init(NULL, tx_packet_handler_b, &t38_state_a)) == NULL)
     {
         fprintf(stderr, "Cannot start the T.38 channel\n");
         exit(2);
     }
-    t38_gateway_set_transmit_on_idle(&t38_state_b, use_transmit_on_idle);
-    t38_set_t38_version(&t38_state_b.t38x.t38, t38_version);
-    t38_gateway_set_ecm_capability(&t38_state_b, use_ecm);
-    span_log_set_level(&t38_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.logging, "T.38-B");
-    span_log_set_level(&t38_state_b.t38x.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t38_state_b.t38x.t38.logging, "T.38-B");
+    t38_core = t38_gateway_get_t38_core_state(t38_state_b);
+    t38_gateway_set_transmit_on_idle(t38_state_b, use_transmit_on_idle);
+    t38_set_t38_version(t38_core, t38_version);
+    t38_gateway_set_ecm_capability(t38_state_b, use_ecm);
+
+    logging = t38_gateway_get_logging_state(t38_state_b);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
+    logging = t38_core_get_logging_state(t38_core);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "T.38-B");
+
     memset(t38_amp_b, 0, sizeof(t38_amp_b));
 
-    if (fax_init(&fax_state_b, FALSE) == NULL)
+    if ((fax_state_b = fax_init(NULL, FALSE)) == NULL)
     {
         fprintf(stderr, "Cannot start FAX\n");
         exit(2);
     }
-    t30 = fax_get_t30_state(&fax_state_b);
-    fax_set_transmit_on_idle(&fax_state_b, use_transmit_on_idle);
-    fax_set_tep_mode(&fax_state_b, use_tep);
+    t30 = fax_get_t30_state(fax_state_b);
+    fax_set_transmit_on_idle(fax_state_b, use_transmit_on_idle);
+    fax_set_tep_mode(fax_state_b, use_tep);
     t30_set_supported_modems(t30, supported_modems);
     t30_set_tx_ident(t30, "22222222");
     t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
@@ -381,10 +405,15 @@
     t30_set_ecm_capability(t30, use_ecm);
     if (use_ecm)
         t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
-    span_log_set_level(&fax_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&fax_state_b.logging, "FAX-B ");
-    span_log_set_level(&t30->logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
-    span_log_set_tag(&t30->logging, "FAX-B ");
+
+    logging = fax_get_logging_state(fax_state_b);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-B ");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
+    span_log_set_tag(logging, "FAX-B ");
+
     memset(t30_amp_b, 0, sizeof(t30_amp_b));
 
 #if defined(ENABLE_GUI)
@@ -393,18 +422,29 @@
 #endif
     for (;;)
     {
-        span_log_bump_samples(&t38_state_a.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t38_fe.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_a.t30.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&t38_state_b.t38x.t38.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&fax_state_b.logging, SAMPLES_PER_CHUNK);
-        span_log_bump_samples(&fax_state_b.t30.logging, SAMPLES_PER_CHUNK);
+        logging = t38_terminal_get_logging_state(t38_state_a);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = t38_terminal_get_t30_state(t38_state_a);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = t38_gateway_get_logging_state(t38_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t38_core = t38_gateway_get_t38_core_state(t38_state_b);
+        logging = t38_core_get_logging_state(t38_core);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        logging = fax_get_logging_state(fax_state_b);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+        t30 = fax_get_t30_state(fax_state_b);
+        logging = t30_get_logging_state(t30);
+        span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
         memset(out_amp, 0, sizeof(out_amp));
 
-        t38_terminal_send_timeout(&t38_state_a, SAMPLES_PER_CHUNK);
+        t38_terminal_send_timeout(t38_state_a, SAMPLES_PER_CHUNK);
 
-        t30_len_b = fax_tx(&fax_state_b, t30_amp_b, SAMPLES_PER_CHUNK);
+        t30_len_b = fax_tx(fax_state_b, t30_amp_b, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             /* The receive side always expects a full block of samples, but the
@@ -426,10 +466,10 @@
             for (i = 0;  i < t30_len_b;  i++)
                 out_amp[2*i + 1] = t30_amp_b[i];
         }
-        if (t38_gateway_rx(&t38_state_b, t30_amp_b, t30_len_b))
+        if (t38_gateway_rx(t38_state_b, t30_amp_b, t30_len_b))
             break;
     
-        t38_len_b = t38_gateway_tx(&t38_state_b, t38_amp_b, SAMPLES_PER_CHUNK);
+        t38_len_b = t38_gateway_tx(t38_state_b, t38_amp_b, SAMPLES_PER_CHUNK);
         if (!use_transmit_on_idle)
         {
             if (t38_len_b < SAMPLES_PER_CHUNK)
@@ -443,10 +483,10 @@
             for (i = 0;  i < t38_len_b;  i++)
                 out_amp[2*i] = t38_amp_b[i];
         }
-        if (fax_rx(&fax_state_b, t38_amp_b, SAMPLES_PER_CHUNK))
+        if (fax_rx(fax_state_b, t38_amp_b, SAMPLES_PER_CHUNK))
             break;
 
-        when += 0.02;
+        when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
 
         while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -454,7 +494,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_b.t38x.t38, msg, msg_len, seq_no);
+            t38_core = t38_gateway_get_t38_core_state(t38_state_b);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
         {
@@ -462,7 +503,8 @@
             if (use_gui)
                 media_monitor_rx(seq_no, tx_when, rx_when);
 #endif
-            t38_core_rx_ifp_packet(&t38_state_a.t38_fe.t38, msg, msg_len, seq_no);
+            t38_core = t38_terminal_get_t38_core_state(t38_state_a);
+            t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
         }
         if (log_audio)
         {
@@ -478,8 +520,8 @@
             media_monitor_update_display();
 #endif
     }
-    t38_terminal_release(&t38_state_a);
-    fax_release(&fax_state_b);
+    t38_terminal_release(t38_state_a);
+    fax_release(fax_state_b);
     if (log_audio)
     {
         if (afCloseFile(wave_handle) != 0)

Modified: freeswitch/trunk/libs/spandsp/tests/t4_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/t4_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/t4_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: t4_tests.c,v 1.60 2008/09/07 12:45:17 steveu Exp $
+ * $Id: t4_tests.c,v 1.65 2009/01/05 13:48:32 steveu Exp $
  */
 
 /*! \file */
@@ -43,6 +43,10 @@
 #include <unistd.h>
 #include <memory.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define IN_FILE_NAME    "../test-data/itu/fax/itutests.tif"
@@ -215,6 +219,8 @@
     int bit_error_rate;
     int dump_as_xxx;
     int tests_failed;
+    unsigned int last_pkt_no;
+    unsigned int pkt_no;
 
     tests_failed = 0;
     decode_test = FALSE;
@@ -295,9 +301,10 @@
 
         page_no = 1;
         t4_rx_start_page(&receive_state);
+        last_pkt_no = 0;
         while (fgets(buf, 1024, stdin))
         {
-            if (sscanf(buf, "HDLC:  FCD: 06 %x", (unsigned int *) &bit) == 1)
+            if (sscanf(buf, "HDLC:  FCD: 06 %x", &pkt_no) == 1)
             {
                 /* Useful for breaking up T.38 ECM logs */
                 for (i = 0;  i < 256;  i++)
@@ -308,12 +315,26 @@
                         break;
                 }
             }
-            else if (strlen(buf) > 62  &&  sscanf(buf + 62, "Rx %*d: IFP %*x %*x") == 3)
+            else if (sscanf(buf, "HDLC:  %x", &pkt_no) == 1)
+            {
+                /* Useful for breaking up HDLC decodes of ECM logs */
+                for (i = 0;  i < 256;  i++)
+                {
+                    if (sscanf(&buf[19 + 3*i], "%x", (unsigned int *) &bit) != 1)
+                        break;
+                    if ((end_of_page = t4_rx_put_byte(&receive_state, bit)))
+                        break;
+                }
+            }
+            else if (strlen(buf) > 62  &&  sscanf(buf + 57, "Rx %d: IFP %x %x", &pkt_no, (unsigned int *) &bit, (unsigned int *) &bit) == 3)
             {
                 /* Useful for breaking up T.38 non-ECM logs */
+                if (pkt_no != last_pkt_no + 1)
+                    printf("Packet %u\n", pkt_no);
+                last_pkt_no = pkt_no;
                 for (i = 0;  i < 256;  i++)
                 {
-                    if (sscanf(&buf[62 + 29 + 3*i], "%x", (unsigned int *) &bit) != 1)
+                    if (sscanf(&buf[57 + 29 + 3*i], "%x", (unsigned int *) &bit) != 1)
                         break;
                     bit = bit_reverse8(bit);
                     if ((end_of_page = t4_rx_put_byte(&receive_state, bit)))

Modified: freeswitch/trunk/libs/spandsp/tests/time_scale_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/time_scale_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/time_scale_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: time_scale_tests.c,v 1.22 2008/07/28 15:14:30 steveu Exp $
+ * $Id: time_scale_tests.c,v 1.23 2008/11/15 14:27:29 steveu Exp $
  */
 
 /*! \page time_scale_tests_page Time scaling tests
@@ -48,6 +48,8 @@
 
 #include "spandsp.h"
 
+#include "spandsp/private/time_scale.h"
+
 #define BLOCK_LEN       160
 
 #define IN_FILE_NAME    "../test-data/local/short_nb_voice.wav"

Modified: freeswitch/trunk/libs/spandsp/tests/tone_detect_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/tone_detect_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/tone_detect_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_detect_tests.c,v 1.10 2008/05/13 13:17:26 steveu Exp $
+ * $Id: tone_detect_tests.c,v 1.11 2008/11/30 12:38:27 steveu Exp $
  */
 
 /*! \page tone_detect_tests_page Tone detection tests
@@ -40,6 +40,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 #define DEC_SAMPLE_RATE     800

Modified: freeswitch/trunk/libs/spandsp/tests/tone_generate_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/tone_generate_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/tone_generate_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tone_generate_tests.c,v 1.20 2008/09/11 15:13:42 steveu Exp $
+ * $Id: tone_generate_tests.c,v 1.21 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page tone_generate_tests_page Tone generation tests
@@ -40,6 +40,10 @@
 #include <time.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 

Modified: freeswitch/trunk/libs/spandsp/tests/tsb85_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/tsb85_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/tsb85_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: tsb85_tests.c,v 1.24 2008/09/12 14:41:55 steveu Exp $
+ * $Id: tsb85_tests.c,v 1.28 2009/01/28 03:41:27 steveu Exp $
  */
 
 /*! \file */
@@ -36,13 +36,13 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#include "floating_fudge.h"
 #if defined(HAVE_TGMATH_H)
 #include <tgmath.h>
 #endif
 #if defined(HAVE_MATH_H)
 #include <math.h>
 #endif
+#include "floating_fudge.h"
 #include <assert.h>
 #include <fcntl.h>
 #include <time.h>
@@ -59,8 +59,13 @@
 #include <libxml/xinclude.h>
 #endif
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
+
 #include "fax_tester.h"
 
 #define OUTPUT_TIFF_FILE_NAME   "tsb85.tif"
@@ -76,7 +81,7 @@
 
 const char *output_tiff_file_name;
 
-fax_state_t fax;
+fax_state_t *fax;
 faxtester_state_t state;
 
 uint8_t image[1000000];
@@ -391,10 +396,11 @@
 static void fax_prepare(void)
 {
     t30_state_t *t30;
+    logging_state_t *logging;
 
-    t30 = fax_get_t30_state(&fax);
-    fax_set_transmit_on_idle(&fax, TRUE);
-    fax_set_tep_mode(&fax, TRUE);
+    t30 = fax_get_t30_state(fax);
+    fax_set_transmit_on_idle(fax, TRUE);
+    fax_set_tep_mode(fax, TRUE);
 #if 0
     t30_set_tx_ident(t30, "1234567890");
     t30_set_tx_sub_address(t30, "Sub-address");
@@ -439,16 +445,22 @@
     t30_set_real_time_frame_handler(t30, t30_real_time_frame_handler, (void *) (intptr_t) 1);
     t30_set_document_handler(t30, document_handler, (void *) (intptr_t) 1);
 
-    span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
-    span_log_set_tag(&t30->logging, "A");
+    logging = fax_get_logging_state(fax);
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
+    span_log_set_tag(logging, "A");
+
+    logging = t30_get_logging_state(t30);
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
+    span_log_set_tag(logging, "A");
+
+#if 0
     span_log_set_level(&fax.modems.v27ter_rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
     span_log_set_tag(&fax.modems.v27ter_rx.logging, "A");
     span_log_set_level(&fax.modems.v29_rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
     span_log_set_tag(&fax.modems.v29_rx.logging, "A");
     span_log_set_level(&fax.modems.v17_rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
     span_log_set_tag(&fax.modems.v17_rx.logging, "A");
-    span_log_set_level(&fax.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
-    span_log_set_tag(&fax.logging, "A");
+#endif
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -862,7 +874,7 @@
 
         if (strcasecmp((const char *) type, "SET") == 0)
         {
-            t30 = fax_get_t30_state(&fax);
+            t30 = fax_get_t30_state(fax);
             if (strcasecmp((const char *) tag, "IDENT") == 0)
                 t30_set_tx_ident(t30, (const char *) value);
             else if (strcasecmp((const char *) tag, "SUB") == 0)
@@ -891,10 +903,10 @@
         }
         else if (strcasecmp((const char *) type, "CALL") == 0)
         {
-            fax_init(&fax, FALSE);
+            fax = fax_init(NULL, FALSE);
             fax_prepare();
             next_tx_file[0] = '\0';
-            t30 = fax_get_t30_state(&fax);
+            t30 = fax_get_t30_state(fax);
             t30_set_rx_file(t30, output_tiff_file_name, -1);
             /* Avoid libtiff 3.8.2 and earlier bug on complex 2D lines. */
             t30_set_rx_encoding(t30, T4_COMPRESSION_ITU_T4_1D);
@@ -907,10 +919,10 @@
         }
         else if (strcasecmp((const char *) type, "ANSWER") == 0)
         {
-            fax_init(&fax, TRUE);
+            fax = fax_init(NULL, TRUE);
             fax_prepare();
             next_tx_file[0] = '\0';
-            t30 = fax_get_t30_state(&fax);
+            t30 = fax_get_t30_state(fax);
             /* Avoid libtiff 3.8.2 and earlier bug on complex 2D lines. */
             t30_set_rx_encoding(t30, T4_COMPRESSION_ITU_T4_1D);
             if (value)
@@ -1071,6 +1083,7 @@
     int i;
     int total_audio_time;
     int log_audio;
+    logging_state_t *logging;
 
     log_audio = TRUE;
     output_tiff_file_name = OUTPUT_TIFF_FILE_NAME;
@@ -1093,7 +1106,7 @@
     faxtester_set_front_end_step_complete_handler(&state, faxtester_front_end_step_complete_handler, NULL);
     faxtester_set_front_end_step_timeout_handler(&state, faxtester_front_end_step_timeout_handler, NULL);
 
-    fax_init(&fax, FALSE);
+    fax = fax_init(NULL, FALSE);
     fax_prepare();
     next_tx_file[0] = '\0';
 
@@ -1102,7 +1115,7 @@
     /*endwhile*/
     for (;;)
     {
-        len = fax_tx(&fax, amp, SAMPLES_PER_CHUNK);
+        len = fax_tx(fax, amp, SAMPLES_PER_CHUNK);
         faxtester_rx(s, amp, len);
         if (log_audio)
         {
@@ -1113,15 +1126,21 @@
         /*endif*/
 
         total_audio_time += SAMPLES_PER_CHUNK;
-        span_log_bump_samples(&fax.t30.logging, len);
+
+        logging = t30_get_logging_state(fax_get_t30_state(fax));
+        span_log_bump_samples(logging, len);
+#if 0
         span_log_bump_samples(&fax.modems.v27ter_rx.logging, len);
         span_log_bump_samples(&fax.modems.v29_rx.logging, len);
         span_log_bump_samples(&fax.modems.v17_rx.logging, len);
-        span_log_bump_samples(&fax.logging, len);
+#endif
+        logging = fax_get_logging_state(fax);
+        span_log_bump_samples(logging, len);
+
         span_log_bump_samples(&s->logging, len);
                 
         len = faxtester_tx(s, amp, 160);
-        if (fax_rx(&fax, amp, len))
+        if (fax_rx(fax, amp, len))
             break;
         /*endif*/
         if (log_audio)

Modified: freeswitch/trunk/libs/spandsp/tests/v17_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v17_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v17_tests.c	Tue Jan 27 22:48:03 2009
@@ -23,7 +23,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v17_tests.c,v 1.90 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v17_tests.c,v 1.98 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \page v17_tests_page V.17 modem tests
@@ -46,6 +46,9 @@
 \section v17_tests_page_sec_2 How is it used?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -61,6 +64,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -96,39 +103,12 @@
 {
     switch (reason)
     {
-    case BERT_REPORT_SYNCED:
-        printf("BERT report synced\n");
-        break;
-    case BERT_REPORT_UNSYNCED:
-        printf("BERT report unsync'ed\n");
-        break;
     case BERT_REPORT_REGULAR:
         printf("BERT report regular - %d bits, %d bad bits, %d resyncs\n", results->total_bits, results->bad_bits, results->resyncs);
         memcpy(&latest_results, results, sizeof(latest_results));
         break;
-    case BERT_REPORT_GT_10_2:
-        printf("BERT report > 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_2:
-        printf("BERT report < 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_3:
-        printf("BERT report < 1 in 10^3\n");
-        break;
-    case BERT_REPORT_LT_10_4:
-        printf("BERT report < 1 in 10^4\n");
-        break;
-    case BERT_REPORT_LT_10_5:
-        printf("BERT report < 1 in 10^5\n");
-        break;
-    case BERT_REPORT_LT_10_6:
-        printf("BERT report < 1 in 10^6\n");
-        break;
-    case BERT_REPORT_LT_10_7:
-        printf("BERT report < 1 in 10^7\n");
-        break;
     default:
-        printf("BERT report reason %d\n", reason);
+        printf("BERT report %s\n", bert_event_to_str(reason));
         break;
     }
 }
@@ -243,8 +223,8 @@
 
 int main(int argc, char *argv[])
 {
-    v17_rx_state_t rx;
-    v17_tx_state_t tx;
+    v17_rx_state_t *rx;
+    v17_tx_state_t *tx;
     bert_results_t bert_results;
     int16_t gen_amp[BLOCK_LEN];
     int16_t amp[BLOCK_LEN];
@@ -262,6 +242,7 @@
     int channel_codec;
     int rbs_pattern;
     int opt;
+    logging_state_t *logging;
 
     channel_codec = MUNGE_CODEC_NONE;
     rbs_pattern = 0;
@@ -274,11 +255,19 @@
     signal_level = -13;
     bits_per_test = 50000;
     log_audio = FALSE;
-    while ((opt = getopt(argc, argv, "b:c:d:glm:n:r:s:t")) != -1)
+    while ((opt = getopt(argc, argv, "b:B:c:d:glm:n:r:s:t")) != -1)
     {
         switch (opt)
         {
         case 'b':
+            test_bps = atoi(optarg);
+            if (test_bps != 14400  &&  test_bps != 12000  &&  test_bps != 9600  &&  test_bps != 7200)
+            {
+                fprintf(stderr, "Invalid bit rate specified\n");
+                exit(2);
+            }
+            break;
+        case 'B':
             bits_per_test = atoi(optarg);
             break;
         case 'c':
@@ -319,24 +308,6 @@
             break;
         }
     }
-    argc -= optind;
-    argv += optind;
-    if (argc > 0)
-    {
-        if (strcmp(argv[0], "14400") == 0)
-            test_bps = 14400;
-        else if (strcmp(argv[0], "12000") == 0)
-            test_bps = 12000;
-        else if (strcmp(argv[0], "9600") == 0)
-            test_bps = 9600;
-        else if (strcmp(argv[0], "7200") == 0)
-            test_bps = 7200;
-        else
-        {
-            fprintf(stderr, "Invalid bit rate\n");
-            exit(2);
-        }
-    }
     inhandle = NULL;
     outhandle = NULL;
 
@@ -352,6 +323,7 @@
     if (decode_test_file)
     {
         /* We will decode the audio from a wave file. */
+        tx = NULL;
         if ((inhandle = afOpenFile_telephony_read(decode_test_file, 1)) == AF_NULL_FILEHANDLE)
         {
             fprintf(stderr, "    Cannot open wave file '%s'\n", decode_test_file);
@@ -361,12 +333,17 @@
     else
     {
         /* We will generate V.17 audio, and add some noise to it. */
-        v17_tx_init(&tx, test_bps, tep, v17getbit, NULL);
-        v17_tx_power(&tx, signal_level);
-        v17_tx_set_modem_status_handler(&tx, v17_tx_status, (void *) &tx);
+        tx = v17_tx_init(NULL, test_bps, tep, v17getbit, NULL);
+        logging = v17_tx_get_logging_state(tx);
+        span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
+        span_log_set_tag(logging, "V.17 tx");
+        v17_tx_power(tx, signal_level);
+        v17_tx_set_modem_status_handler(tx, v17_tx_status, (void *) tx);
+#if defined(WITH_SPANDSP_INTERNALS)
         /* Move the carrier off a bit */
-        tx.carrier_phase_rate = dds_phase_ratef(1792.0f);
-        tx.carrier_phase = 0x40000000;
+        tx->carrier_phase_rate = dds_phase_ratef(1792.0f);
+        tx->carrier_phase = 0x40000000;
+#endif
 
         bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
         bert_set_report(&bert, 10000, reporter, NULL);
@@ -382,11 +359,12 @@
 #endif
     }
 
-    v17_rx_init(&rx, test_bps, v17putbit, &rx);
-    v17_rx_set_modem_status_handler(&rx, v17_rx_status, (void *) &rx);
-    v17_rx_set_qam_report_handler(&rx, qam_report, (void *) &rx);
-    span_log_set_level(&rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
-    span_log_set_tag(&rx.logging, "V.17 rx");
+    rx = v17_rx_init(NULL, test_bps, v17putbit, NULL);
+    v17_rx_set_modem_status_handler(rx, v17_rx_status, (void *) rx);
+    v17_rx_set_qam_report_handler(rx, qam_report, (void *) rx);
+    logging = v17_rx_get_logging_state(rx);
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
+    span_log_set_tag(logging, "V.17 rx");
 
 #if defined(ENABLE_GUI)
     if (use_gui)
@@ -418,7 +396,7 @@
         }
         else
         {
-            samples = v17_tx(&tx, gen_amp, BLOCK_LEN);
+            samples = v17_tx(tx, gen_amp, BLOCK_LEN);
 #if defined(ENABLE_GUI)
             if (use_gui)
                 qam_monitor_update_audio_level(qam_monitor, gen_amp, samples);
@@ -429,7 +407,7 @@
 
                 /* Push a little silence through, to ensure all the data bits get out of the buffers */
                 memset(amp, 0, BLOCK_LEN*sizeof(int16_t));
-                v17_rx(&rx, amp, BLOCK_LEN);
+                v17_rx(rx, amp, BLOCK_LEN);
 
                 /* Note that we might get a few bad bits as the carrier shuts down. */
                 bert_result(&bert, &bert_results);
@@ -449,12 +427,14 @@
                     break;
                 }
                 memset(&latest_results, 0, sizeof(latest_results));
+#if defined(WITH_SPANDSP_INTERNALS)
                 signal_level--;
                 /* Bump the receiver AGC gain by 1dB, to compensate for the above */
-                rx.agc_scaling_save *= 1.122f;
-                v17_tx_restart(&tx, test_bps, tep, TRUE);
-                v17_tx_power(&tx, signal_level);
-                v17_rx_restart(&rx, test_bps, TRUE);
+                rx->agc_scaling_save *= 1.122f;
+#endif
+                v17_tx_restart(tx, test_bps, tep, TRUE);
+                v17_tx_power(tx, signal_level);
+                v17_rx_restart(rx, test_bps, TRUE);
                 //rx.eq_put_step = rand()%(192*10/3);
                 bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
                 bert_set_report(&bert, 10000, reporter, NULL);
@@ -469,7 +449,7 @@
             {
                 outframes = afWriteFrames(outhandle,
                                           AF_DEFAULT_TRACK,
-                                          amp,
+                                          gen_amp,
                                           samples);
                 if (outframes != samples)
                 {
@@ -483,7 +463,7 @@
         if (use_gui  &&  !decode_test_file)
             line_model_monitor_line_spectrum_update(amp, samples);
 #endif
-        v17_rx(&rx, amp, samples);
+        v17_rx(rx, amp, samples);
     }
     if (!decode_test_file)
     {

Modified: freeswitch/trunk/libs/spandsp/tests/v22bis_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v22bis_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v22bis_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v22bis_tests.c,v 1.52 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v22bis_tests.c,v 1.54 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \page v22bis_tests_page V.22bis modem tests
@@ -52,6 +52,7 @@
 #include <string.h>
 #include <audiofile.h>
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -232,11 +233,19 @@
     signal_level = -13;
     bits_per_test = 50000;
     log_audio = FALSE;
-    while ((opt = getopt(argc, argv, "b:c:glm:n:s:")) != -1)
+    while ((opt = getopt(argc, argv, "b:B:c:glm:n:s:")) != -1)
     {
         switch (opt)
         {
         case 'b':
+            test_bps = atoi(optarg);
+            if (test_bps != 2400  &&  test_bps != 1200)
+            {
+                fprintf(stderr, "Invalid bit rate specified\n");
+                exit(2);
+            }
+            break;
+        case 'B':
             bits_per_test = atoi(optarg);
             break;
         case 'c':
@@ -268,20 +277,6 @@
             break;
         }
     }
-    argc -= optind;
-    argv += optind;
-    if (argc > 0)
-    {
-        if (strcmp(argv[0], "2400") == 0)
-            test_bps = 2400;
-        else if (strcmp(argv[0], "1200") == 0)
-            test_bps = 1200;
-        else
-        {
-            fprintf(stderr, "Invalid bit rate\n");
-            exit(2);
-        }
-    }
     outhandle = AF_NULL_FILEHANDLE;
     if (log_audio)
     {

Modified: freeswitch/trunk/libs/spandsp/tests/v27ter_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v27ter_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v27ter_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v27ter_tests.c,v 1.93 2008/09/07 06:39:52 steveu Exp $
+ * $Id: v27ter_tests.c,v 1.99 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \page v27ter_tests_page V.27ter modem tests
@@ -45,6 +45,9 @@
 \section v27ter_tests_page_sec_2 How is it used?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -60,6 +63,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -92,39 +99,12 @@
 {
     switch (reason)
     {
-    case BERT_REPORT_SYNCED:
-        printf("BERT report synced\n");
-        break;
-    case BERT_REPORT_UNSYNCED:
-        printf("BERT report unsync'ed\n");
-        break;
     case BERT_REPORT_REGULAR:
         printf("BERT report regular - %d bits, %d bad bits, %d resyncs\n", results->total_bits, results->bad_bits, results->resyncs);
         memcpy(&latest_results, results, sizeof(latest_results));
         break;
-    case BERT_REPORT_GT_10_2:
-        printf("BERT report > 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_2:
-        printf("BERT report < 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_3:
-        printf("BERT report < 1 in 10^3\n");
-        break;
-    case BERT_REPORT_LT_10_4:
-        printf("BERT report < 1 in 10^4\n");
-        break;
-    case BERT_REPORT_LT_10_5:
-        printf("BERT report < 1 in 10^5\n");
-        break;
-    case BERT_REPORT_LT_10_6:
-        printf("BERT report < 1 in 10^6\n");
-        break;
-    case BERT_REPORT_LT_10_7:
-        printf("BERT report < 1 in 10^7\n");
-        break;
     default:
-        printf("BERT report reason %d\n", reason);
+        printf("BERT report %s\n", bert_event_to_str(reason));
         break;
     }
 }
@@ -209,7 +189,9 @@
         printf("Equalizer B:\n");
         for (i = 0;  i < len;  i++)
             printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i]));
+#if defined(WITH_SPANDSP_INTERNALS)
         printf("Gardtest %d %f %d\n", symbol_no, v27ter_rx_symbol_timing_correction(rx), rx->gardner_integrate);
+#endif
         printf("Carcar %d %f\n", symbol_no, v27ter_rx_carrier_frequency(rx));
 #if defined(ENABLE_GUI)
         if (use_gui)
@@ -240,8 +222,8 @@
 
 int main(int argc, char *argv[])
 {
-    v27ter_rx_state_t rx;
-    v27ter_tx_state_t tx;
+    v27ter_rx_state_t *rx;
+    v27ter_tx_state_t *tx;
     bert_results_t bert_results;
     int16_t gen_amp[BLOCK_LEN];
     int16_t amp[BLOCK_LEN];
@@ -260,6 +242,7 @@
     int channel_codec;
     int rbs_pattern;
     int opt;
+    logging_state_t *logging;
 
     channel_codec = MUNGE_CODEC_NONE;
     rbs_pattern = 0;
@@ -272,11 +255,19 @@
     signal_level = -13;
     bits_per_test = 50000;
     log_audio = FALSE;
-    while ((opt = getopt(argc, argv, "b:c:d:glm:n:r:s:t")) != -1)
+    while ((opt = getopt(argc, argv, "b:B:c:d:glm:n:r:s:t")) != -1)
     {
         switch (opt)
         {
         case 'b':
+            test_bps = atoi(optarg);
+            if (test_bps != 4800  &&  test_bps != 2400)
+            {
+                fprintf(stderr, "Invalid bit rate specified\n");
+                exit(2);
+            }
+            break;
+        case 'B':
             bits_per_test = atoi(optarg);
             break;
         case 'c':
@@ -317,21 +308,6 @@
             break;
         }
     }
-    argc -= optind;
-    argv += optind;
-    if (argc > 0)
-    {
-        if (strcmp(argv[0], "4800") == 0)
-            test_bps = 4800;
-        else if (strcmp(argv[0], "2400") == 0)
-            test_bps = 2400;
-        else
-        {
-            fprintf(stderr, "Invalid bit rate\n");
-            exit(2);
-        }
-    }
-
     inhandle = NULL;
     outhandle = NULL;
 
@@ -347,6 +323,7 @@
     if (decode_test_file)
     {
         /* We will decode the audio from a wave file. */
+        tx = NULL;
         if ((inhandle = afOpenFile_telephony_read(decode_test_file, 1)) == AF_NULL_FILEHANDLE)
         {
             fprintf(stderr, "    Cannot open wave file '%s'\n", decode_test_file);
@@ -356,12 +333,13 @@
     else
     {
         /* We will generate V.27ter audio, and add some noise to it. */
-        v27ter_tx_init(&tx, test_bps, tep, v27tergetbit, NULL);
-        v27ter_tx_power(&tx, signal_level);
-        v27ter_tx_set_modem_status_handler(&tx, v27ter_tx_status, (void *) &tx);
+        tx = v27ter_tx_init(NULL, test_bps, tep, v27tergetbit, NULL);
+        v27ter_tx_power(tx, signal_level);
+        v27ter_tx_set_modem_status_handler(tx, v27ter_tx_status, (void *) tx);
         /* Move the carrier off a bit */
-        tx.carrier_phase_rate = dds_phase_ratef(1810.0f);
-
+#if defined(WITH_SPANDSP_INTERNALS)
+        tx->carrier_phase_rate = dds_phase_ratef(1810.0f);
+#endif
         bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
         bert_set_report(&bert, 10000, reporter, NULL);
 
@@ -372,11 +350,12 @@
         }
     }
 
-    v27ter_rx_init(&rx, test_bps, v27terputbit, NULL);
-    v27ter_rx_set_modem_status_handler(&rx, v27ter_rx_status, (void *) &rx);
-    v27ter_rx_set_qam_report_handler(&rx, qam_report, (void *) &rx);
-    span_log_set_level(&rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
-    span_log_set_tag(&rx.logging, "V.27ter-rx");
+    rx = v27ter_rx_init(NULL, test_bps, v27terputbit, NULL);
+    v27ter_rx_set_modem_status_handler(rx, v27ter_rx_status, (void *) rx);
+    v27ter_rx_set_qam_report_handler(rx, qam_report, (void *) rx);
+    logging = v27ter_rx_get_logging_state(rx);
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
+    span_log_set_tag(logging, "V.27ter-rx");
 
 #if defined(ENABLE_GUI)
     if (use_gui)
@@ -408,7 +387,7 @@
         }
         else
         {
-            samples = v27ter_tx(&tx, gen_amp, BLOCK_LEN);
+            samples = v27ter_tx(tx, gen_amp, BLOCK_LEN);
 #if defined(ENABLE_GUI)
             if (use_gui)
                 qam_monitor_update_audio_level(qam_monitor, gen_amp, samples);
@@ -419,9 +398,9 @@
 
                 /* Push a little silence through, to ensure all the data bits get out of the buffers */
                 memset(amp, 0, BLOCK_LEN*sizeof(int16_t));
-                v27ter_rx(&rx, amp, BLOCK_LEN);
-                v27ter_rx(&rx, amp, BLOCK_LEN);
-                v27ter_rx(&rx, amp, BLOCK_LEN);
+                v27ter_rx(rx, amp, BLOCK_LEN);
+                v27ter_rx(rx, amp, BLOCK_LEN);
+                v27ter_rx(rx, amp, BLOCK_LEN);
 
                 /* Note that we might get a few bad bits as the carrier shuts down. */
                 bert_result(&bert, &bert_results);
@@ -442,9 +421,9 @@
                 }
                 memset(&latest_results, 0, sizeof(latest_results));
                 signal_level--;
-                v27ter_tx_restart(&tx, test_bps, tep);
-                v27ter_tx_power(&tx, signal_level);
-                v27ter_rx_restart(&rx, test_bps, FALSE);
+                v27ter_tx_restart(tx, test_bps, tep);
+                v27ter_tx_power(tx, signal_level);
+                v27ter_rx_restart(rx, test_bps, FALSE);
                 bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
                 bert_set_report(&bert, 10000, reporter, NULL);
                 one_way_line_model_release(line_model);
@@ -473,7 +452,7 @@
         if (use_gui  &&  !decode_test_file)
             line_model_monitor_line_spectrum_update(amp, samples);
 #endif
-        v27ter_rx(&rx, amp, samples);
+        v27ter_rx(rx, amp, samples);
     }
     if (!decode_test_file)
     {

Modified: freeswitch/trunk/libs/spandsp/tests/v29_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v29_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v29_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v29_tests.c,v 1.106 2008/09/07 12:45:17 steveu Exp $
+ * $Id: v29_tests.c,v 1.113 2009/01/12 17:20:59 steveu Exp $
  */
 
 /*! \page v29_tests_page V.29 modem tests
@@ -45,6 +45,9 @@
 \section v29_tests_page_sec_2 How is it used?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -60,6 +63,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -91,39 +98,12 @@
 {
     switch (reason)
     {
-    case BERT_REPORT_SYNCED:
-        printf("BERT report synced\n");
-        break;
-    case BERT_REPORT_UNSYNCED:
-        printf("BERT report unsync'ed\n");
-        break;
     case BERT_REPORT_REGULAR:
         printf("BERT report regular - %d bits, %d bad bits, %d resyncs\n", results->total_bits, results->bad_bits, results->resyncs);
         memcpy(&latest_results, results, sizeof(latest_results));
         break;
-    case BERT_REPORT_GT_10_2:
-        printf("BERT report > 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_2:
-        printf("BERT report < 1 in 10^2\n");
-        break;
-    case BERT_REPORT_LT_10_3:
-        printf("BERT report < 1 in 10^3\n");
-        break;
-    case BERT_REPORT_LT_10_4:
-        printf("BERT report < 1 in 10^4\n");
-        break;
-    case BERT_REPORT_LT_10_5:
-        printf("BERT report < 1 in 10^5\n");
-        break;
-    case BERT_REPORT_LT_10_6:
-        printf("BERT report < 1 in 10^6\n");
-        break;
-    case BERT_REPORT_LT_10_7:
-        printf("BERT report < 1 in 10^7\n");
-        break;
     default:
-        printf("BERT report reason %d\n", reason);
+        printf("BERT report %s\n", bert_event_to_str(reason));
         break;
     }
 }
@@ -265,8 +245,8 @@
 
 int main(int argc, char *argv[])
 {
-    v29_rx_state_t rx;
-    v29_tx_state_t tx;
+    v29_rx_state_t *rx;
+    v29_tx_state_t *tx;
     bert_results_t bert_results;
     int16_t gen_amp[BLOCK_LEN];
     int16_t amp[BLOCK_LEN];
@@ -285,6 +265,7 @@
     int channel_codec;
     int rbs_pattern;
     int opt;
+    logging_state_t *logging;
     
     channel_codec = MUNGE_CODEC_NONE;
     rbs_pattern = 0;
@@ -297,11 +278,19 @@
     signal_level = -13;
     bits_per_test = 50000;
     log_audio = FALSE;
-    while ((opt = getopt(argc, argv, "b:c:d:glm:n:r:s:t")) != -1)
+    while ((opt = getopt(argc, argv, "b:B:c:d:glm:n:r:s:t")) != -1)
     {
         switch (opt)
         {
         case 'b':
+            test_bps = atoi(optarg);
+            if (test_bps != 9600  &&  test_bps != 7200  &&  test_bps != 4800)
+            {
+                fprintf(stderr, "Invalid bit rate specified\n");
+                exit(2);
+            }
+            break;
+        case 'B':
             bits_per_test = atoi(optarg);
             break;
         case 'c':
@@ -342,22 +331,6 @@
             break;
         }
     }
-    argc -= optind;
-    argv += optind;
-    if (argc > 0)
-    {
-        if (strcmp(argv[0], "9600") == 0)
-            test_bps = 9600;
-        else if (strcmp(argv[0], "7200") == 0)
-            test_bps = 7200;
-        else if (strcmp(argv[0], "4800") == 0)
-            test_bps = 4800;
-        else
-        {
-            fprintf(stderr, "Invalid bit rate\n");
-            exit(2);
-        }
-    }
     inhandle = NULL;
     outhandle = NULL;
 
@@ -373,6 +346,7 @@
     if (decode_test_file)
     {
         /* We will decode the audio from a wave file. */
+        tx = NULL;
         if ((inhandle = afOpenFile_telephony_read(decode_test_file, 1)) == AF_NULL_FILEHANDLE)
         {
             fprintf(stderr, "    Cannot open wave file '%s'\n", decode_test_file);
@@ -382,12 +356,14 @@
     else
     {
         /* We will generate V.29 audio, and add some noise to it. */
-        v29_tx_init(&tx, test_bps, tep, v29getbit, NULL);
-        v29_tx_power(&tx, signal_level);
-        v29_tx_set_modem_status_handler(&tx, v29_tx_status, (void *) &tx);
+        tx = v29_tx_init(NULL, test_bps, tep, v29getbit, NULL);
+        v29_tx_power(tx, signal_level);
+        v29_tx_set_modem_status_handler(tx, v29_tx_status, (void *) tx);
+#if defined(WITH_SPANDSP_INTERNALS)
         /* Move the carrier off a bit */
-        tx.carrier_phase_rate = dds_phase_ratef(1710.0f);
-        tx.carrier_phase = 0;
+        tx->carrier_phase_rate = dds_phase_ratef(1710.0f);
+        tx->carrier_phase = 0;
+#endif
 
         bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
         bert_set_report(&bert, 10000, reporter, NULL);
@@ -399,14 +375,17 @@
         }
     }
 
-    v29_rx_init(&rx, test_bps, v29putbit, &rx);
-    v29_rx_signal_cutoff(&rx, -45.5f);
-    v29_rx_set_modem_status_handler(&rx, v29_rx_status, (void *) &rx);
-    v29_rx_set_qam_report_handler(&rx, qam_report, (void *) &rx);
+    rx = v29_rx_init(NULL, test_bps, v29putbit, NULL);
+    v29_rx_signal_cutoff(rx, -45.5f);
+    v29_rx_set_modem_status_handler(rx, v29_rx_status, (void *) rx);
+    v29_rx_set_qam_report_handler(rx, qam_report, (void *) rx);
+#if defined(WITH_SPANDSP_INTERNALS)
     /* Rotate the starting phase */
-    rx.carrier_phase = 0x80000000;
-    span_log_set_level(&rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
-    span_log_set_tag(&rx.logging, "V.29-rx");
+    rx->carrier_phase = 0x80000000;
+#endif
+    logging = v29_rx_get_logging_state(rx);
+    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
+    span_log_set_tag(logging, "V.29-rx");
 
 #if defined(ENABLE_GUI)
     if (use_gui)
@@ -438,7 +417,7 @@
         }
         else
         {
-            samples = v29_tx(&tx, gen_amp, BLOCK_LEN);
+            samples = v29_tx(tx, gen_amp, BLOCK_LEN);
 #if defined(ENABLE_GUI)
             if (use_gui)
                 qam_monitor_update_audio_level(qam_monitor, gen_amp, samples);
@@ -447,7 +426,7 @@
             {
                 /* Push a little silence through, to ensure all the data bits get out of the buffers */
                 memset(amp, 0, BLOCK_LEN*sizeof(int16_t));
-                v29_rx(&rx, amp, BLOCK_LEN);
+                v29_rx(rx, amp, BLOCK_LEN);
 
                 /* Note that we might get a few bad bits as the carrier shuts down. */
                 bert_result(&bert, &bert_results);
@@ -468,10 +447,12 @@
                 }
                 memset(&latest_results, 0, sizeof(latest_results));
                 signal_level--;
-                v29_tx_restart(&tx, test_bps, tep);
-                v29_tx_power(&tx, signal_level);
-                v29_rx_restart(&rx, test_bps, FALSE);
-                rx.eq_put_step = rand()%(48*10/3);
+                v29_tx_restart(tx, test_bps, tep);
+                v29_tx_power(tx, signal_level);
+                v29_rx_restart(rx, test_bps, FALSE);
+#if defined(WITH_SPANDSP_INTERNALS)
+                rx->eq_put_step = rand()%(48*10/3);
+#endif
                 bert_init(&bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20);
                 bert_set_report(&bert, 10000, reporter, NULL);
                 one_way_line_model_release(line_model);
@@ -499,7 +480,7 @@
         if (use_gui  &&  !decode_test_file)
             line_model_monitor_line_spectrum_update(amp, samples);
 #endif
-        v29_rx(&rx, amp, samples);
+        v29_rx(rx, amp, samples);
     }
     if (!decode_test_file)
     {

Modified: freeswitch/trunk/libs/spandsp/tests/v42_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v42_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v42_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42_tests.c,v 1.25 2008/05/13 13:17:26 steveu Exp $
+ * $Id: v42_tests.c,v 1.28 2008/11/30 10:17:31 steveu Exp $
  */
 
 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. */
@@ -42,6 +42,10 @@
 #include <string.h>
 #include <assert.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 
 v42_state_t caller;

Modified: freeswitch/trunk/libs/spandsp/tests/v42bis_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v42bis_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v42bis_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v42bis_tests.c,v 1.23 2008/05/13 13:17:27 steveu Exp $
+ * $Id: v42bis_tests.c,v 1.24 2008/11/15 14:43:08 steveu Exp $
  */
 
 /* THIS IS A WORK IN PROGRESS. IT IS NOT FINISHED. */
@@ -50,6 +50,8 @@
 
 #include "spandsp.h"
 
+#include "spandsp/private/v42bis.h"
+
 #define COMPRESSED_FILE_NAME        "v42bis_tests.v42bis"
 #define OUTPUT_FILE_NAME            "v42bis_tests.out"
 

Modified: freeswitch/trunk/libs/spandsp/tests/v8_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/v8_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/v8_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,13 +22,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: v8_tests.c,v 1.28 2008/08/29 09:28:13 steveu Exp $
+ * $Id: v8_tests.c,v 1.31 2008/11/30 10:17:31 steveu Exp $
  */
 
 /*! \page v8_tests_page V.8 tests
 \section v8_tests_page_sec_1 What does it do?
 */
 
+/* Enable the following definition to enable direct probing into the FAX structures */
+//#define WITH_SPANDSP_INTERNALS
+
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
 #endif
@@ -40,6 +43,10 @@
 #include <string.h>
 #include <audiofile.h>
 
+//#if defined(WITH_SPANDSP_INTERNALS)
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+//#endif
+
 #include "spandsp.h"
 #include "spandsp-sim.h"
 
@@ -84,8 +91,8 @@
     int i;
     int16_t amp[SAMPLES_PER_CHUNK];
     int16_t out_amp[2*SAMPLES_PER_CHUNK];
-    v8_state_t v8_caller;
-    v8_state_t v8_answerer;
+    v8_state_t *v8_caller;
+    v8_state_t *v8_answerer;
     int outframes;
     int samples;
     int remnant;
@@ -95,7 +102,8 @@
     AFfilehandle outhandle;
     int opt;
     char *decode_test_file;
-    
+    logging_state_t *logging;
+
     decode_test_file = NULL;
     while ((opt = getopt(argc, argv, "d:")) != -1)
     {
@@ -148,31 +156,33 @@
             exit(2);
         }
     
-        v8_init(&v8_caller, TRUE, caller_available_modulations, handler, (void *) "caller");
-        v8_init(&v8_answerer, FALSE, answerer_available_modulations, handler, (void *) "answerer");
-        span_log_set_level(&v8_caller.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
-        span_log_set_tag(&v8_caller.logging, "caller");
-        span_log_set_level(&v8_answerer.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
-        span_log_set_tag(&v8_answerer.logging, "answerer");
+        v8_caller = v8_init(NULL, TRUE, caller_available_modulations, handler, (void *) "caller");
+        v8_answerer = v8_init(NULL, FALSE, answerer_available_modulations, handler, (void *) "answerer");
+        logging = v8_get_logging_state(v8_caller);
+        span_log_set_level(logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
+        span_log_set_tag(logging, "caller");
+        logging = v8_get_logging_state(v8_answerer);
+        span_log_set_level(logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
+        span_log_set_tag(logging, "answerer");
         for (i = 0;  i < 1000;  i++)
         {
-            samples = v8_tx(&v8_caller, amp, SAMPLES_PER_CHUNK);
+            samples = v8_tx(v8_caller, amp, SAMPLES_PER_CHUNK);
             if (samples < SAMPLES_PER_CHUNK)
             {
                 memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples));
                 samples = SAMPLES_PER_CHUNK;
             }
-            remnant = v8_rx(&v8_answerer, amp, samples);
+            remnant = v8_rx(v8_answerer, amp, samples);
             for (i = 0;  i < samples;  i++)
                 out_amp[2*i] = amp[i];
             
-            samples = v8_tx(&v8_answerer, amp, SAMPLES_PER_CHUNK);
+            samples = v8_tx(v8_answerer, amp, SAMPLES_PER_CHUNK);
             if (samples < SAMPLES_PER_CHUNK)
             {
                 memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples));
                 samples = SAMPLES_PER_CHUNK;
             }
-            if (v8_rx(&v8_caller, amp, samples)  &&  remnant)
+            if (v8_rx(v8_caller, amp, samples)  &&  remnant)
                 break;
             for (i = 0;  i < samples;  i++)
                 out_amp[2*i + 1] = amp[i];
@@ -193,8 +203,8 @@
             exit(2);
         }
         
-        v8_release(&v8_caller);
-        v8_release(&v8_answerer);
+        v8_free(v8_caller);
+        v8_free(v8_answerer);
         
         if (negotiations_ok != 2)
         {
@@ -206,9 +216,10 @@
     else
     {
         printf("Decode file '%s'\n", decode_test_file);
-        v8_init(&v8_answerer, FALSE, answerer_available_modulations, handler, (void *) "answerer");
-        span_log_set_level(&v8_answerer.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
-        span_log_set_tag(&v8_answerer.logging, "decoder");
+        v8_answerer = v8_init(NULL, FALSE, answerer_available_modulations, handler, (void *) "answerer");
+        logging = v8_get_logging_state(v8_answerer);
+        span_log_set_level(logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
+        span_log_set_tag(logging, "decoder");
         if ((inhandle = afOpenFile_telephony_read(decode_test_file, 1)) == AF_NULL_FILEHANDLE)
         {
             fprintf(stderr, "    Cannot open speech file '%s'\n", decode_test_file);
@@ -218,11 +229,11 @@
 
         while ((samples = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLES_PER_CHUNK)))
         {
-            remnant = v8_rx(&v8_answerer, amp, samples);
+            remnant = v8_rx(v8_answerer, amp, samples);
         }
         /*endwhile*/
 
-        v8_release(&v8_answerer);
+        v8_free(v8_answerer);
         if (afCloseFile(inhandle) != 0)
         {
             fprintf(stderr, "    Cannot close speech file '%s'\n", decode_test_file);

Modified: freeswitch/trunk/libs/spandsp/tests/vector_float_tests.c
==============================================================================
--- freeswitch/trunk/libs/spandsp/tests/vector_float_tests.c	(original)
+++ freeswitch/trunk/libs/spandsp/tests/vector_float_tests.c	Tue Jan 27 22:48:03 2009
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: vector_float_tests.c,v 1.10 2008/09/16 15:21:52 steveu Exp $
+ * $Id: vector_float_tests.c,v 1.12 2008/10/09 13:25:19 steveu Exp $
  */
 
 #if defined(HAVE_CONFIG_H)
@@ -37,6 +37,242 @@
 
 #include "spandsp.h"
 
+static void vec_copyf_dumb(float z[], const float x[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_copyf(void)
+{
+    int i;
+    float x[100];
+    float za[100];
+    float zb[100];
+
+    printf("Testing vec_copyf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = i;
+        za[i] = -1.0f;
+        zb[i] = -1.0f;
+    }
+    vec_copyf_dumb(za + 3, x + 1, 0);
+    vec_copyf(zb + 3, x + 1, 0);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_copyf_dumb(za + 3, x + 1, 1);
+    vec_copyf(zb + 3, x + 1, 1);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_copyf_dumb(za + 3, x + 1, 29);
+    vec_copyf(zb + 3, x + 1, 29);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_negatef_dumb(float z[], const float x[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = -x[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_negatef(void)
+{
+    int i;
+    float x[100];
+    float za[100];
+    float zb[100];
+
+    printf("Testing vec_negatef()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = i;
+        za[i] = -1.0f;
+        zb[i] = -1.0f;
+    }
+    vec_negatef_dumb(za + 3, x + 1, 0);
+    vec_negatef(zb + 3, x + 1, 0);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_negatef() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_negatef_dumb(za + 3, x + 1, 1);
+    vec_negatef(zb + 3, x + 1, 1);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_megatef() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_negatef_dumb(za + 3, x + 1, 29);
+    vec_negatef(zb + 3, x + 1, 29);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_negatef() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_zerof_dumb(float z[], int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = 0.0f;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_zerof(void)
+{
+    int i;
+    float za[100];
+    float zb[100];
+
+    printf("Testing vec_zerof()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        za[i] = -1.0f;
+        zb[i] = -1.0f;
+    }
+    vec_zerof_dumb(za + 3, 0);
+    vec_zerof(zb + 3, 0);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_zerof() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_zerof_dumb(za + 3, 1);
+    vec_zerof(zb + 3, 1);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_zerof() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_zerof_dumb(za + 3, 29);
+    vec_zerof(zb + 3, 29);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_zerof() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_setf_dumb(float z[], float x, int n)
+{
+    int i;
+    
+    for (i = 0;  i < n;  i++)
+        z[i] = x;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_setf(void)
+{
+    int i;
+    float za[100];
+    float zb[100];
+
+    printf("Testing vec_setf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        za[i] = -1.0f;
+        zb[i] = -1.0f;
+    }
+    vec_setf_dumb(za + 3, 42.0f, 0);
+    vec_setf(zb + 3, 42.0f, 0);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_setf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_setf_dumb(za + 3, 42.0f, 1);
+    vec_setf(zb + 3, 42.0f, 1);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_setf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    vec_setf_dumb(za + 3, 42.0f, 29);
+    vec_setf(zb + 3, 42.0f, 29);
+    for (i = 0;  i < 99;  i++)
+    {
+        if (za[i] != zb[i])
+        {
+            printf("vec_setf() - %d %f %f\n", i, za[i], zb[i]);
+            printf("Tests failed\n");
+            exit(2);
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 static double vec_dot_prod_dumb(const double x[], const double y[], int n)
 {
     int i;
@@ -58,6 +294,7 @@
     double zsb;
     double ratio;
 
+    printf("Testing vec_dot_prod()\n");
     for (i = 0;  i < 99;  i++)
     {
         x[i] = rand();
@@ -100,6 +337,7 @@
     float zsb;
     float ratio;
 
+    printf("Testing vec_dot_prodf()\n");
     for (i = 0;  i < 99;  i++)
     {
         x[i] = rand();
@@ -121,10 +359,292 @@
 }
 /*- End of function --------------------------------------------------------*/
 
+static void vec_addf_dumb(float z[], const float x[], const float y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_addf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float y[100];
+    float zsa[100];
+    float zsb[100];
+    float ratio;
+
+    printf("Testing vec_addf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        y[i] = rand();
+    }
+    for (i = 1;  i < 90;  i++)
+    {
+        /* Force address misalignment, to check this works OK */
+        vec_addf(zsa + 1, x + 1, y + 1, i);
+        vec_addf_dumb(zsb + 1, x + 1, y + 1, i);
+        for (j = 1;  j <= i;  j++)
+        {
+            ratio = zsa[j]/zsb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_mulf() - %d %e %e\n", j, zsa[j], zsb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_subf_dumb(float z[], const float x[], const float y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] - y[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_subf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float y[100];
+    float zsa[100];
+    float zsb[100];
+    float ratio;
+
+    printf("Testing vec_subf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        y[i] = rand();
+    }
+    for (i = 1;  i < 90;  i++)
+    {
+        /* Force address misalignment, to check this works OK */
+        vec_subf(zsa + 1, x + 1, y + 1, i);
+        vec_subf_dumb(zsb + 1, x + 1, y + 1, i);
+        for (j = 1;  j <= i;  j++)
+        {
+            ratio = zsa[j]/zsb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_mulf() - %d %e %e\n", j, zsa[j], zsb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_mulf_dumb(float z[], const float x[], const float y[], int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i]*y[i];
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_mulf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float y[100];
+    float zsa[100];
+    float zsb[100];
+    float ratio;
+
+    printf("Testing vec_mulf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        y[i] = rand();
+    }
+    for (i = 1;  i < 90;  i++)
+    {
+        /* Force address misalignment, to check this works OK */
+        vec_mulf(zsa + 1, x + 1, y + 1, i);
+        vec_mulf_dumb(zsb + 1, x + 1, y + 1, i);
+        for (j = 1;  j <= i;  j++)
+        {
+            ratio = zsa[j]/zsb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_mulf() - %d %e %e\n", j, zsa[j], zsb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+#define LMS_LEAK_RATE 0.9999f
+
+static void vec_lmsf_dumb(const float x[], float y[], int n, float error)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+    {
+        /* Leak a little to tame uncontrolled wandering */
+        y[i] = y[i]*LMS_LEAK_RATE + x[i]*error;
+    }
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_lmsf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float ya[100];
+    float yb[100];
+    float ratio;
+
+    printf("Testing vec_lmsf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        ya[i] =
+        yb[i] = rand();
+    }
+    for (i = 1;  i < 99;  i++)
+    {
+        vec_lmsf(x, ya, i, 0.1f);
+        vec_lmsf_dumb(x, yb, i, 0.1f);
+        for (j = 0;  j < i;  j++)
+        {
+            ratio = ya[j]/yb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_lmsf() - %d %e %e\n", j, ya[j], yb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_scaledxy_addf_dumb(float z[], const float x[], float x_scale, const float y[], float y_scale, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i]*x_scale + y[i]*y_scale;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_scaledxy_addf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float y[100];
+    float za[100];
+    float zb[100];
+    float ratio;
+
+    printf("Testing vec_scaledxy_addf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        y[i] = rand();
+    }
+    for (i = 1;  i < 99;  i++)
+    {
+        vec_scaledxy_addf(za, x, 2.5f, y, 1.5f, i);
+        vec_scaledxy_addf_dumb(zb, x, 2.5f, y, 1.5f, i);
+        for (j = 0;  j < i;  j++)
+        {
+            ratio = za[j]/zb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_scaledxy_addf() - %d %e %e\n", j, za[j], zb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void vec_scaledy_addf_dumb(float z[], const float x[], const float y[], float y_scale, int n)
+{
+    int i;
+
+    for (i = 0;  i < n;  i++)
+        z[i] = x[i] + y[i]*y_scale;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_vec_scaledy_addf(void)
+{
+    int i;
+    int j;
+    float x[100];
+    float y[100];
+    float za[100];
+    float zb[100];
+    float ratio;
+
+    printf("Testing vec_scaledy_addf()\n");
+    for (i = 0;  i < 99;  i++)
+    {
+        x[i] = rand();
+        y[i] = rand();
+    }
+    for (i = 1;  i < 99;  i++)
+    {
+        vec_scaledy_addf(za, x, y, 1.5f, i);
+        vec_scaledy_addf_dumb(zb, x, y, 1.5f, i);
+        for (j = 0;  j < i;  j++)
+        {
+            ratio = za[j]/zb[j];
+            if (ratio < 0.9999f  ||  ratio > 1.0001f)
+            {
+                printf("vec_scaledy_addf() - %d %e %e\n", j, za[j], zb[j]);
+                printf("Tests failed\n");
+                exit(2);
+            }
+        }
+    }
+    return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
 int main(int argc, char *argv[])
 {
+    test_vec_copyf();
+    test_vec_negatef();
+    test_vec_zerof();
+    test_vec_setf();
+    test_vec_addf();
+    test_vec_subf();
+    test_vec_mulf();
+    test_vec_scaledxy_addf();
+    test_vec_scaledy_addf();
     test_vec_dot_prod();
     test_vec_dot_prodf();
+    test_vec_lmsf();
 
     printf("Tests passed.\n");
     return 0;



More information about the Freeswitch-svn mailing list