[Freeswitch-svn] [commit] r9771 - in freeswitch/trunk/libs/spandsp: . doc src src/spandsp tests
Freeswitch SVN
anthm at freeswitch.org
Wed Oct 1 00:06:53 EDT 2008
Author: anthm
Date: Wed Oct 1 00:06:53 2008
New Revision: 9771
Added:
freeswitch/trunk/libs/spandsp/src/complex_vector_int.c
freeswitch/trunk/libs/spandsp/src/g722.c
freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj
freeswitch/trunk/libs/spandsp/tests/complex_tests.c
freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c
freeswitch/trunk/libs/spandsp/tests/complex_vector_int_tests.c
Modified:
freeswitch/trunk/libs/spandsp/.update
freeswitch/trunk/libs/spandsp/Makefile.am
freeswitch/trunk/libs/spandsp/doc/Makefile.am
freeswitch/trunk/libs/spandsp/src/Makefile.am
freeswitch/trunk/libs/spandsp/src/spandsp/g722.h
freeswitch/trunk/libs/spandsp/src/spandsp/version.h
Log:
update to snapshot spandsp-20080920.tar.gz
Modified: freeswitch/trunk/libs/spandsp/.update
==============================================================================
--- freeswitch/trunk/libs/spandsp/.update (original)
+++ freeswitch/trunk/libs/spandsp/.update Wed Oct 1 00:06:53 2008
@@ -1 +1 @@
-Tue Sep 30 23:59:24 EDT 2008
+Wed Oct 1 00:06:28 EDT 2008
Modified: freeswitch/trunk/libs/spandsp/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/Makefile.am (original)
+++ freeswitch/trunk/libs/spandsp/Makefile.am Wed Oct 1 00:06:53 2008
@@ -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.40 2008/07/15 14:28:20 steveu Exp $
+## $Id: Makefile.am,v 1.43 2008/09/20 15:44:40 steveu Exp $
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
@@ -30,26 +30,10 @@
README.testdata \
spandsp.spec \
wrapper.xsl \
- libspandsp.vcproj \
unpack_g722_data.sh \
unpack_g726_data.sh \
unpack_gsm0610_data.sh \
unpack_v56ter_data.sh \
- doc/doxygen.in \
- src/floating_fudge.h \
- src/spandsp/version.h.in \
- src/libspandsp.dsp \
- src/libspandsp.sln \
- src/msvc/gettimeofday.c \
- src/msvc/inttypes.h \
- src/msvc/tgmath.h \
- src/msvc/unistd.h \
- src/msvc/sys/time.h \
- src/msvc/spandsp.def \
- src/msvc/msvcproj.head \
- src/msvc/msvcproj.foot \
- src/msvc/vc8proj.head \
- src/msvc/vc8proj.foot \
spandsp/global-tones.xml \
spandsp/tones.dtd \
spandsp/tsb85.xml \
Modified: freeswitch/trunk/libs/spandsp/doc/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/doc/Makefile.am (original)
+++ freeswitch/trunk/libs/spandsp/doc/Makefile.am Wed Oct 1 00:06:53 2008
@@ -16,11 +16,12 @@
## 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.11 2008/06/21 10:28:34 steveu Exp $
+## $Id: Makefile.am,v 1.12 2008/09/20 15:44:40 steveu Exp $
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = css.css \
+ doxygen.in \
t38-gateway.dia \
t38-terminal.dia \
t38_manual.xml \
Modified: freeswitch/trunk/libs/spandsp/src/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/spandsp/src/Makefile.am (original)
+++ freeswitch/trunk/libs/spandsp/src/Makefile.am Wed Oct 1 00:06:53 2008
@@ -16,13 +16,29 @@
## 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.103 2008/09/19 14:02:05 steveu Exp $
+## $Id: Makefile.am,v 1.104 2008/09/20 15:44:40 steveu Exp $
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
MAINTAINERCLEANFILES = Makefile.in
+EXTRA_DIST = floating_fudge.h \
+ spandsp/version.h.in \
+ libspandsp.dsp \
+ libspandsp.sln \
+ libspandsp.vcproj \
+ msvc/gettimeofday.c \
+ msvc/inttypes.h \
+ msvc/tgmath.h \
+ msvc/unistd.h \
+ msvc/sys/time.h \
+ msvc/spandsp.def \
+ msvc/msvcproj.head \
+ msvc/msvcproj.foot \
+ msvc/vc8proj.head \
+ msvc/vc8proj.foot
+
INCLUDES = -I$(top_builddir)
lib_LTLIBRARIES = libspandsp.la
Added: freeswitch/trunk/libs/spandsp/src/complex_vector_int.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/complex_vector_int.c Wed Oct 1 00:06:53 2008
@@ -0,0 +1,113 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * complex_vector_int.c - Integer complex vector arithmetic 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: complex_vector_int.c,v 1.3 2008/09/18 13:54:32 steveu Exp $
+ */
+
+/*! \file */
+
+#if defined(HAVE_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 <assert.h>
+
+#include "spandsp/telephony.h"
+#include "spandsp/logging.h"
+#include "spandsp/complex.h"
+#include "spandsp/vector_int.h"
+#include "spandsp/complex_vector_int.h"
+
+complexi32_t cvec_dot_prodi16(const complexi16_t x[], const complexi16_t y[], int n)
+{
+ int i;
+ complexi32_t z;
+
+ z = complex_seti32(0, 0);
+ for (i = 0; i < n; i++)
+ {
+ z.re += ((int32_t) x[i].re*(int32_t) y[i].re - (int32_t) x[i].im*(int32_t) y[i].im);
+ z.im += ((int32_t) x[i].re*(int32_t) y[i].im + (int32_t) x[i].im*(int32_t) y[i].re);
+ }
+ return z;
+}
+/*- End of function --------------------------------------------------------*/
+
+complexi32_t cvec_dot_prodi32(const complexi32_t x[], const complexi32_t y[], int n)
+{
+ int i;
+ complexi32_t z;
+
+ z = complex_seti32(0, 0);
+ for (i = 0; i < n; i++)
+ {
+ z.re += (x[i].re*y[i].re - x[i].im*y[i].im);
+ z.im += (x[i].re*y[i].im + x[i].im*y[i].re);
+ }
+ return z;
+}
+/*- End of function --------------------------------------------------------*/
+
+complexi32_t cvec_circular_dot_prodi16(const complexi16_t x[], const complexi16_t y[], int n, int pos)
+{
+ complexi32_t z;
+ complexi32_t z1;
+
+ z = cvec_dot_prodi16(&x[pos], &y[0], n - pos);
+ z1 = cvec_dot_prodi16(&x[0], &y[n - pos], pos);
+ z = complex_addi32(&z, &z1);
+ return z;
+}
+/*- End of function --------------------------------------------------------*/
+
+void cvec_lmsi16(const complexi16_t x[], complexi16_t y[], int n, const complexi16_t *error)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ y[i].re += ((int32_t) x[i].im*(int32_t) error->im + (int32_t) x[i].re*(int32_t) error->re) >> 12;
+ y[i].im += ((int32_t) x[i].re*(int32_t) error->im - (int32_t) x[i].im*(int32_t) error->re) >> 12;
+ }
+}
+/*- End of function --------------------------------------------------------*/
+
+void cvec_circular_lmsi16(const complexi16_t x[], complexi16_t y[], int n, int pos, const complexi16_t *error)
+{
+ cvec_lmsi16(&x[pos], &y[0], n - pos, error);
+ cvec_lmsi16(&x[0], &y[n - pos], pos, error);
+}
+/*- End of function --------------------------------------------------------*/
+/*- End of file ------------------------------------------------------------*/
Added: freeswitch/trunk/libs/spandsp/src/g722.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/g722.c Wed Oct 1 00:06:53 2008
@@ -0,0 +1,609 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * g722.c - 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 in part on a single channel G.722 codec which is:
+ *
+ * Copyright (c) CMU 1993
+ * Computer Science, Speech Group
+ * Chengxiang Lu and Alex Hauptmann
+ *
+ * $Id: g722.c,v 1.2 2008/09/19 16:24:25 steveu Exp $
+ */
+
+/*! \file */
+
+#if defined(HAVE_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 "spandsp/telephony.h"
+#include "spandsp/saturated.h"
+#include "spandsp/vector_int.h"
+#include "spandsp/g722.h"
+
+static const int16_t qmf_coeffs_fwd[12] =
+{
+ 3, -11, 12, 32, -210, 951, 3876, -805, 362, -156, 53, -11,
+};
+
+static const int16_t qmf_coeffs_rev[12] =
+{
+ -11, 53, -156, 362, -805, 3876, 951, -210, 32, 12, -11, 3
+};
+
+static const int16_t qm2[4] =
+{
+ -7408, -1616, 7408, 1616
+};
+
+static const int16_t qm4[16] =
+{
+ 0, -20456, -12896, -8968,
+ -6288, -4240, -2584, -1200,
+ 20456, 12896, 8968, 6288,
+ 4240, 2584, 1200, 0
+};
+
+static const int16_t qm5[32] =
+{
+ -280, -280, -23352, -17560,
+ -14120, -11664, -9752, -8184,
+ -6864, -5712, -4696, -3784,
+ -2960, -2208, -1520, -880,
+ 23352, 17560, 14120, 11664,
+ 9752, 8184, 6864, 5712,
+ 4696, 3784, 2960, 2208,
+ 1520, 880, 280, -280
+};
+
+static const int16_t qm6[64] =
+{
+ -136, -136, -136, -136,
+ -24808, -21904, -19008, -16704,
+ -14984, -13512, -12280, -11192,
+ -10232, -9360, -8576, -7856,
+ -7192, -6576, -6000, -5456,
+ -4944, -4464, -4008, -3576,
+ -3168, -2776, -2400, -2032,
+ -1688, -1360, -1040, -728,
+ 24808, 21904, 19008, 16704,
+ 14984, 13512, 12280, 11192,
+ 10232, 9360, 8576, 7856,
+ 7192, 6576, 6000, 5456,
+ 4944, 4464, 4008, 3576,
+ 3168, 2776, 2400, 2032,
+ 1688, 1360, 1040, 728,
+ 432, 136, -432, -136
+};
+
+static const int16_t q6[32] =
+{
+ 0, 35, 72, 110,
+ 150, 190, 233, 276,
+ 323, 370, 422, 473,
+ 530, 587, 650, 714,
+ 786, 858, 940, 1023,
+ 1121, 1219, 1339, 1458,
+ 1612, 1765, 1980, 2195,
+ 2557, 2919, 0, 0
+};
+
+static const int16_t ilb[32] =
+{
+ 2048, 2093, 2139, 2186,
+ 2233, 2282, 2332, 2383,
+ 2435, 2489, 2543, 2599,
+ 2656, 2714, 2774, 2834,
+ 2896, 2960, 3025, 3091,
+ 3158, 3228, 3298, 3371,
+ 3444, 3520, 3597, 3676,
+ 3756, 3838, 3922, 4008
+};
+
+static const int16_t iln[32] =
+{
+ 0, 63, 62, 31, 30, 29, 28, 27,
+ 26, 25, 24, 23, 22, 21, 20, 19,
+ 18, 17, 16, 15, 14, 13, 12, 11,
+ 10, 9, 8, 7, 6, 5, 4, 0
+};
+
+static const int16_t ilp[32] =
+{
+ 0, 61, 60, 59, 58, 57, 56, 55,
+ 54, 53, 52, 51, 50, 49, 48, 47,
+ 46, 45, 44, 43, 42, 41, 40, 39,
+ 38, 37, 36, 35, 34, 33, 32, 0
+};
+
+static const int16_t ihn[3] =
+{
+ 0, 1, 0
+};
+
+static const int16_t ihp[3] =
+{
+ 0, 3, 2
+};
+
+static const int16_t wl[8] =
+{
+ -60, -30, 58, 172, 334, 538, 1198, 3042
+};
+
+static const int16_t rl42[16] =
+{
+ 0, 7, 6, 5, 4, 3, 2, 1,
+ 7, 6, 5, 4, 3, 2, 1, 0
+};
+
+static const int16_t wh[3] =
+{
+ 0, -214, 798
+};
+
+static const int16_t rh2[4] =
+{
+ 2, 1, 2, 1
+};
+
+static void block4(g722_band_t *s, int16_t dx)
+{
+ int16_t wd1;
+ int16_t wd2;
+ int16_t wd3;
+ int16_t sp;
+ int16_t r;
+ int16_t p;
+ int16_t ap[2];
+ int32_t wd32;
+ int32_t sz;
+ int i;
+
+ /* RECONS */
+ r = saturated_add16(s->s, dx);
+ /* PARREC */
+ p = saturated_add16(s->sz, dx);
+
+ /* UPPOL2 */
+ wd1 = saturate((int32_t) s->a[0] << 2);
+ wd32 = ((p ^ s->p[0]) & 0x8000) ? wd1 : -wd1;
+ if (wd32 > 32767)
+ wd32 = 32767;
+ wd3 = (((p ^ s->p[1]) & 0x8000) ? -128 : 128)
+ + (wd32 >> 7)
+ + (((int32_t) s->a[1]*(int32_t) 32512) >> 15);
+ if (abs(wd3) > 12288)
+ wd3 = (wd3 < 0) ? -12288 : 12288;
+ ap[1] = wd3;
+
+ /* UPPOL1 */
+ wd1 = ((p ^ s->p[0]) & 0x8000) ? -192 : 192;
+ wd2 = ((int32_t) s->a[0]*(int32_t) 32640) >> 15;
+ ap[0] = saturated_add16(wd1, wd2);
+
+ wd3 = saturated_sub16(15360, ap[1]);
+ if (abs(ap[0]) > wd3)
+ ap[0] = (ap[0] < 0) ? -wd3 : wd3;
+
+ /* FILTEP */
+ wd1 = saturated_add16(r, r);
+ wd1 = ((int32_t) ap[0]*(int32_t) wd1) >> 15;
+ wd2 = saturated_add16(s->r, s->r);
+ wd2 = ((int32_t) ap[1]*(int32_t) wd2) >> 15;
+ sp = saturated_add16(wd1, wd2);
+ s->r = r;
+ s->a[1] = ap[1];
+ s->a[0] = ap[0];
+ s->p[1] = s->p[0];
+ s->p[0] = p;
+
+ /* UPZERO */
+ /* DELAYA */
+ /* FILTEZ */
+ wd1 = (dx == 0) ? 0 : 128;
+ s->d[0] = dx;
+ sz = 0;
+ for (i = 5; i >= 0; i--)
+ {
+ wd2 = ((s->d[i + 1] ^ dx) & 0x8000) ? -wd1 : wd1;
+ wd3 = ((int32_t) s->b[i]*(int32_t) 32640) >> 15;
+ s->b[i] = saturated_add16(wd2, wd3);
+ wd3 = saturated_add16(s->d[i], s->d[i]);
+ sz += ((int32_t) s->b[i]*(int32_t) wd3) >> 15;
+ s->d[i + 1] = s->d[i];
+ }
+ s->sz = saturate(sz);
+
+ /* PREDIC */
+ s->s = saturated_add16(sp, s->sz);
+}
+/*- End of function --------------------------------------------------------*/
+
+g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options)
+{
+ if (s == NULL)
+ {
+ if ((s = (g722_decode_state_t *) malloc(sizeof(*s))) == NULL)
+ return NULL;
+ }
+ memset(s, 0, sizeof(*s));
+ if (rate == 48000)
+ s->bits_per_sample = 6;
+ else if (rate == 56000)
+ s->bits_per_sample = 7;
+ else
+ s->bits_per_sample = 8;
+ if ((options & G722_SAMPLE_RATE_8000))
+ s->eight_k = TRUE;
+ if ((options & G722_PACKED) && s->bits_per_sample != 8)
+ s->packed = TRUE;
+ else
+ s->packed = FALSE;
+ s->band[0].det = 32;
+ s->band[1].det = 8;
+ return s;
+}
+/*- End of function --------------------------------------------------------*/
+
+int g722_decode_release(g722_decode_state_t *s)
+{
+ free(s);
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len)
+{
+ int rlow;
+ int ihigh;
+ int16_t dlow;
+ int16_t dhigh;
+ int rhigh;
+ int wd1;
+ int wd2;
+ int wd3;
+ int code;
+ int outlen;
+ int j;
+
+ outlen = 0;
+ rhigh = 0;
+ for (j = 0; j < len; )
+ {
+ if (s->packed)
+ {
+ /* Unpack the code bits */
+ if (s->in_bits < s->bits_per_sample)
+ {
+ s->in_buffer |= (g722_data[j++] << s->in_bits);
+ s->in_bits += 8;
+ }
+ code = s->in_buffer & ((1 << s->bits_per_sample) - 1);
+ s->in_buffer >>= s->bits_per_sample;
+ s->in_bits -= s->bits_per_sample;
+ }
+ else
+ {
+ code = g722_data[j++];
+ }
+
+ switch (s->bits_per_sample)
+ {
+ default:
+ case 8:
+ wd1 = code & 0x3F;
+ ihigh = (code >> 6) & 0x03;
+ wd2 = qm6[wd1];
+ wd1 >>= 2;
+ break;
+ case 7:
+ wd1 = code & 0x1F;
+ ihigh = (code >> 5) & 0x03;
+ wd2 = qm5[wd1];
+ wd1 >>= 1;
+ break;
+ case 6:
+ wd1 = code & 0x0F;
+ ihigh = (code >> 4) & 0x03;
+ wd2 = qm4[wd1];
+ break;
+ }
+ /* Block 5L, LOW BAND INVQBL */
+ wd2 = ((int32_t) s->band[0].det*(int32_t) wd2) >> 15;
+ /* Block 5L, RECONS */
+ /* Block 6L, LIMIT */
+ rlow = saturate15(s->band[0].s + wd2);
+
+ /* Block 2L, INVQAL */
+ wd2 = qm4[wd1];
+ dlow = ((int32_t) s->band[0].det*(int32_t) wd2) >> 15;
+
+ /* Block 3L, LOGSCL */
+ wd2 = rl42[wd1];
+ wd1 = ((int32_t) s->band[0].nb*(int32_t) 127) >> 7;
+ wd1 += wl[wd2];
+ if (wd1 < 0)
+ wd1 = 0;
+ else if (wd1 > 18432)
+ wd1 = 18432;
+ s->band[0].nb = wd1;
+
+ /* Block 3L, SCALEL */
+ wd1 = (s->band[0].nb >> 6) & 31;
+ wd2 = 8 - (s->band[0].nb >> 11);
+ wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
+ s->band[0].det = wd3 << 2;
+
+ block4(&s->band[0], dlow);
+
+ if (!s->eight_k)
+ {
+ /* Block 2H, INVQAH */
+ wd2 = qm2[ihigh];
+ dhigh = ((int32_t) s->band[1].det*(int32_t) wd2) >> 15;
+ /* Block 5H, RECONS */
+ /* Block 6H, LIMIT */
+ rhigh = saturate15(dhigh + s->band[1].s);
+
+ /* Block 2H, INVQAH */
+ wd2 = rh2[ihigh];
+ wd1 = ((int32_t) s->band[1].nb*(int32_t) 127) >> 7;
+ wd1 += wh[wd2];
+ if (wd1 < 0)
+ wd1 = 0;
+ else if (wd1 > 22528)
+ wd1 = 22528;
+ s->band[1].nb = wd1;
+
+ /* Block 3H, SCALEH */
+ wd1 = (s->band[1].nb >> 6) & 31;
+ wd2 = 10 - (s->band[1].nb >> 11);
+ wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
+ s->band[1].det = wd3 << 2;
+
+ block4(&s->band[1], dhigh);
+ }
+
+ if (s->itu_test_mode)
+ {
+ amp[outlen++] = (int16_t) (rlow << 1);
+ amp[outlen++] = (int16_t) (rhigh << 1);
+ }
+ else
+ {
+ if (s->eight_k)
+ {
+ amp[outlen++] = (int16_t) rlow;
+ }
+ else
+ {
+ /* Apply the QMF to build the final signal */
+ s->x[s->ptr] = rlow + rhigh;
+ s->y[s->ptr] = rlow - rhigh;
+ if (++s->ptr >= 12)
+ s->ptr = 0;
+ amp[outlen++] = (int16_t) (vec_circular_dot_prodi16(s->y, qmf_coeffs_rev, 12, s->ptr) >> 12);
+ amp[outlen++] = (int16_t) (vec_circular_dot_prodi16(s->x, qmf_coeffs_fwd, 12, s->ptr) >> 12);
+ }
+ }
+ }
+ return outlen;
+}
+/*- End of function --------------------------------------------------------*/
+
+g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options)
+{
+ if (s == NULL)
+ {
+ if ((s = (g722_encode_state_t *) malloc(sizeof(*s))) == NULL)
+ return NULL;
+ }
+ memset(s, 0, sizeof(*s));
+ if (rate == 48000)
+ s->bits_per_sample = 6;
+ else if (rate == 56000)
+ s->bits_per_sample = 7;
+ else
+ s->bits_per_sample = 8;
+ if ((options & G722_SAMPLE_RATE_8000))
+ s->eight_k = TRUE;
+ if ((options & G722_PACKED) && s->bits_per_sample != 8)
+ s->packed = TRUE;
+ else
+ s->packed = FALSE;
+ s->band[0].det = 32;
+ s->band[1].det = 8;
+ return s;
+}
+/*- End of function --------------------------------------------------------*/
+
+int g722_encode_release(g722_encode_state_t *s)
+{
+ free(s);
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len)
+{
+ int16_t dlow;
+ int16_t dhigh;
+ int el;
+ int wd;
+ int wd1;
+ int ril;
+ int wd2;
+ int il4;
+ int ih2;
+ int wd3;
+ int eh;
+ int g722_bytes;
+ int ihigh;
+ int ilow;
+ int code;
+ /* Low and high band PCM from the QMF */
+ int16_t xlow;
+ int16_t xhigh;
+ int32_t sumeven;
+ int32_t sumodd;
+ int mih;
+ int i;
+ int j;
+
+ g722_bytes = 0;
+ xhigh = 0;
+ for (j = 0; j < len; )
+ {
+ if (s->itu_test_mode)
+ {
+ xlow =
+ xhigh = amp[j++] >> 1;
+ }
+ else
+ {
+ if (s->eight_k)
+ {
+ xlow = amp[j++];
+ }
+ else
+ {
+ /* Apply the transmit QMF */
+ s->x[s->ptr] = amp[j++];
+ s->y[s->ptr] = amp[j++];
+ if (++s->ptr >= 12)
+ s->ptr = 0;
+ sumodd = vec_circular_dot_prodi16(s->x, qmf_coeffs_fwd, 12, s->ptr);
+ sumeven = vec_circular_dot_prodi16(s->y, qmf_coeffs_rev, 12, s->ptr);
+ xlow = (sumeven + sumodd) >> 13;
+ xhigh = (sumeven - sumodd) >> 13;
+ }
+ }
+ /* Block 1L, SUBTRA */
+ el = saturated_sub16(xlow, s->band[0].s);
+
+ /* Block 1L, QUANTL */
+ wd = (el >= 0) ? el : ~el;
+
+ for (i = 1; i < 30; i++)
+ {
+ wd1 = ((int32_t) q6[i]*(int32_t) s->band[0].det) >> 12;
+ if (wd < wd1)
+ break;
+ }
+ ilow = (el < 0) ? iln[i] : ilp[i];
+
+ /* Block 2L, INVQAL */
+ ril = ilow >> 2;
+ wd2 = qm4[ril];
+ dlow = ((int32_t) s->band[0].det*(int32_t) wd2) >> 15;
+
+ /* Block 3L, LOGSCL */
+ il4 = rl42[ril];
+ wd = ((int32_t) s->band[0].nb*(int32_t) 127) >> 7;
+ s->band[0].nb = wd + wl[il4];
+ if (s->band[0].nb < 0)
+ s->band[0].nb = 0;
+ else if (s->band[0].nb > 18432)
+ s->band[0].nb = 18432;
+
+ /* Block 3L, SCALEL */
+ wd1 = (s->band[0].nb >> 6) & 31;
+ wd2 = 8 - (s->band[0].nb >> 11);
+ wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
+ s->band[0].det = wd3 << 2;
+
+ block4(&s->band[0], dlow);
+
+ if (s->eight_k)
+ {
+ /* Just leave the high bits as zero */
+ code = (0xC0 | ilow) >> (8 - s->bits_per_sample);
+ }
+ else
+ {
+ /* Block 1H, SUBTRA */
+ eh = saturated_sub16(xhigh, s->band[1].s);
+
+ /* Block 1H, QUANTH */
+ wd = (eh >= 0) ? eh : ~eh;
+ wd1 = (564*s->band[1].det) >> 12;
+ mih = (wd >= wd1) ? 2 : 1;
+ ihigh = (eh < 0) ? ihn[mih] : ihp[mih];
+
+ /* Block 2H, INVQAH */
+ wd2 = qm2[ihigh];
+ dhigh = ((int32_t) s->band[1].det*(int32_t) wd2) >> 15;
+
+ /* Block 3H, LOGSCH */
+ ih2 = rh2[ihigh];
+ wd = ((int32_t) s->band[1].nb*(int32_t) 127) >> 7;
+ s->band[1].nb = wd + wh[ih2];
+ if (s->band[1].nb < 0)
+ s->band[1].nb = 0;
+ else if (s->band[1].nb > 22528)
+ s->band[1].nb = 22528;
+
+ /* Block 3H, SCALEH */
+ wd1 = (s->band[1].nb >> 6) & 31;
+ wd2 = 10 - (s->band[1].nb >> 11);
+ wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
+ s->band[1].det = wd3 << 2;
+
+ block4(&s->band[1], dhigh);
+ code = ((ihigh << 6) | ilow) >> (8 - s->bits_per_sample);
+ }
+
+ if (s->packed)
+ {
+ /* Pack the code bits */
+ s->out_buffer |= (code << s->out_bits);
+ s->out_bits += s->bits_per_sample;
+ if (s->out_bits >= 8)
+ {
+ g722_data[g722_bytes++] = (uint8_t) (s->out_buffer & 0xFF);
+ s->out_bits -= 8;
+ s->out_buffer >>= 8;
+ }
+ }
+ else
+ {
+ g722_data[g722_bytes++] = (uint8_t) code;
+ }
+ }
+ return g722_bytes;
+}
+/*- End of function --------------------------------------------------------*/
+/*- End of file ------------------------------------------------------------*/
Added: freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/src/libspandsp.vcproj Wed Oct 1 00:06:53 2008
@@ -0,0 +1,348 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C"
+ Version="9.00"
+ Name="libspandsp"
+ ProjectGUID="{CF70F278-3364-4395-A2E1-23501C9B8AD2}"
+ RootNamespace="libspandsp"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="src; src\spandsp; src\msvc;..\libtiff\include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_MATH_H;HAVE_TGMATH_H"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ ModuleDefinitionFile="src/msvc/spandsp.def"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="src; src\spandsp; src\msvc;..\libtiff\include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_MATH_H;HAVE_TGMATH_H"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ ModuleDefinitionFile="src/msvc/spandsp.def"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+<File RelativePath="adsi.c"></File>
+<File RelativePath="async.c"></File>
+<File RelativePath="at_interpreter.c"></File>
+<File RelativePath="awgn.c"></File>
+<File RelativePath="bell_r2_mf.c"></File>
+<File RelativePath="bert.c"></File>
+<File RelativePath="bit_operations.c"></File>
+<File RelativePath="bitstream.c"></File>
+<File RelativePath="complex_filters.c"></File>
+<File RelativePath="complex_vector_float.c"></File>
+<File RelativePath="complex_vector_int.c"></File>
+<File RelativePath="crc.c"></File>
+<File RelativePath="dds_float.c"></File>
+<File RelativePath="dds_int.c"></File>
+<File RelativePath="dtmf.c"></File>
+<File RelativePath="echo.c"></File>
+<File RelativePath="fax.c"></File>
+<File RelativePath="fsk.c"></File>
+<File RelativePath="g711.c"></File>
+<File RelativePath="g722.c"></File>
+<File RelativePath="g726.c"></File>
+<File RelativePath="gsm0610_decode.c"></File>
+<File RelativePath="gsm0610_encode.c"></File>
+<File RelativePath="gsm0610_long_term.c"></File>
+<File RelativePath="gsm0610_lpc.c"></File>
+<File RelativePath="gsm0610_preprocess.c"></File>
+<File RelativePath="gsm0610_rpe.c"></File>
+<File RelativePath="gsm0610_short_term.c"></File>
+<File RelativePath="hdlc.c"></File>
+<File RelativePath="ima_adpcm.c"></File>
+<File RelativePath="logging.c"></File>
+<File RelativePath="lpc10_analyse.c"></File>
+<File RelativePath="lpc10_decode.c"></File>
+<File RelativePath="lpc10_encode.c"></File>
+<File RelativePath="lpc10_placev.c"></File>
+<File RelativePath="lpc10_voicing.c"></File>
+<File RelativePath="modem_echo.c"></File>
+<File RelativePath="modem_connect_tones.c"></File>
+<File RelativePath="noise.c"></File>
+<File RelativePath="oki_adpcm.c"></File>
+<File RelativePath="playout.c"></File>
+<File RelativePath="plc.c"></File>
+<File RelativePath="power_meter.c"></File>
+<File RelativePath="queue.c"></File>
+<File RelativePath="schedule.c"></File>
+<File RelativePath="sig_tone.c"></File>
+<File RelativePath="silence_gen.c"></File>
+<File RelativePath="super_tone_rx.c"></File>
+<File RelativePath="super_tone_tx.c"></File>
+<File RelativePath="t4.c"></File>
+<File RelativePath="t30.c"></File>
+<File RelativePath="t30_api.c"></File>
+<File RelativePath="t30_logging.c"></File>
+<File RelativePath="t31.c"></File>
+<File RelativePath="t35.c"></File>
+<File RelativePath="t38_core.c"></File>
+<File RelativePath="t38_gateway.c"></File>
+<File RelativePath="t38_non_ecm_buffer.c"></File>
+<File RelativePath="t38_terminal.c"></File>
+<File RelativePath="testcpuid.c"></File>
+<File RelativePath="time_scale.c"></File>
+<File RelativePath="tone_detect.c"></File>
+<File RelativePath="tone_generate.c"></File>
+<File RelativePath="v17rx.c"></File>
+<File RelativePath="v17tx.c"></File>
+<File RelativePath="v22bis_rx.c"></File>
+<File RelativePath="v22bis_tx.c"></File>
+<File RelativePath="v27ter_rx.c"></File>
+<File RelativePath="v27ter_tx.c"></File>
+<File RelativePath="v29rx.c"></File>
+<File RelativePath="v29tx.c"></File>
+<File RelativePath="v42.c"></File>
+<File RelativePath="v42bis.c"></File>
+<File RelativePath="v8.c"></File>
+<File RelativePath="vector_float.c"></File>
+<File RelativePath="vector_int.c"></File>
+<File RelativePath="msvc/gettimeofday.c"></File>
+</Filter><Filter Name="Header Files">
+<File RelativePath="spandsp/adsi.h"></File>
+<File RelativePath="spandsp/async.h"></File>
+<File RelativePath="spandsp/arctan2.h"></File>
+<File RelativePath="spandsp/at_interpreter.h"></File>
+<File RelativePath="spandsp/awgn.h"></File>
+<File RelativePath="spandsp/bell_r2_mf.h"></File>
+<File RelativePath="spandsp/bert.h"></File>
+<File RelativePath="spandsp/biquad.h"></File>
+<File RelativePath="spandsp/bit_operations.h"></File>
+<File RelativePath="spandsp/bitstream.h"></File>
+<File RelativePath="spandsp/crc.h"></File>
+<File RelativePath="spandsp/complex.h"></File>
+<File RelativePath="spandsp/complex_filters.h"></File>
+<File RelativePath="spandsp/complex_vector_float.h"></File>
+<File RelativePath="spandsp/complex_vector_int.h"></File>
+<File RelativePath="spandsp/dc_restore.h"></File>
+<File RelativePath="spandsp/dds.h"></File>
+<File RelativePath="spandsp/dtmf.h"></File>
+<File RelativePath="spandsp/echo.h"></File>
+<File RelativePath="spandsp/fax.h"></File>
+<File RelativePath="spandsp/fax_modems.h"></File>
+<File RelativePath="spandsp/fir.h"></File>
+<File RelativePath="spandsp/fsk.h"></File>
+<File RelativePath="spandsp/g168models.h"></File>
+<File RelativePath="spandsp/g711.h"></File>
+<File RelativePath="spandsp/g722.h"></File>
+<File RelativePath="spandsp/g726.h"></File>
+<File RelativePath="spandsp/gsm0610.h"></File>
+<File RelativePath="spandsp/hdlc.h"></File>
+<File RelativePath="spandsp/ima_adpcm.h"></File>
+<File RelativePath="spandsp/logging.h"></File>
+<File RelativePath="spandsp/lpc10.h"></File>
+<File RelativePath="spandsp/modem_echo.h"></File>
+<File RelativePath="spandsp/modem_connect_tones.h"></File>
+<File RelativePath="spandsp/noise.h"></File>
+<File RelativePath="spandsp/oki_adpcm.h"></File>
+<File RelativePath="spandsp/playout.h"></File>
+<File RelativePath="spandsp/plc.h"></File>
+<File RelativePath="spandsp/power_meter.h"></File>
+<File RelativePath="spandsp/queue.h"></File>
+<File RelativePath="spandsp/schedule.h"></File>
+<File RelativePath="spandsp/sig_tone.h"></File>
+<File RelativePath="spandsp/silence_gen.h"></File>
+<File RelativePath="spandsp/super_tone_rx.h"></File>
+<File RelativePath="spandsp/super_tone_tx.h"></File>
+<File RelativePath="spandsp/t4.h"></File>
+<File RelativePath="spandsp/t30.h"></File>
+<File RelativePath="spandsp/t30_api.h"></File>
+<File RelativePath="spandsp/t30_fcf.h"></File>
+<File RelativePath="spandsp/t30_logging.h"></File>
+<File RelativePath="spandsp/t31.h"></File>
+<File RelativePath="spandsp/t35.h"></File>
+<File RelativePath="spandsp/t38_core.h"></File>
+<File RelativePath="spandsp/t38_gateway.h"></File>
+<File RelativePath="spandsp/t38_non_ecm_buffer.h"></File>
+<File RelativePath="spandsp/t38_terminal.h"></File>
+<File RelativePath="spandsp/telephony.h"></File>
+<File RelativePath="spandsp/time_scale.h"></File>
+<File RelativePath="spandsp/timing.h"></File>
+<File RelativePath="spandsp/tone_detect.h"></File>
+<File RelativePath="spandsp/tone_generate.h"></File>
+<File RelativePath="spandsp/v17rx.h"></File>
+<File RelativePath="spandsp/v17tx.h"></File>
+<File RelativePath="spandsp/v22bis.h"></File>
+<File RelativePath="spandsp/v27ter_rx.h"></File>
+<File RelativePath="spandsp/v27ter_tx.h"></File>
+<File RelativePath="spandsp/v29rx.h"></File>
+<File RelativePath="spandsp/v29tx.h"></File>
+<File RelativePath="spandsp/v42.h"></File>
+<File RelativePath="spandsp/v42bis.h"></File>
+<File RelativePath="spandsp/v8.h"></File>
+<File RelativePath="spandsp/vector_float.h"></File>
+<File RelativePath="spandsp/vector_int.h"></File>
+<File RelativePath="spandsp/version.h"></File>
+<File RelativePath="spandsp.h"></File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\src\msvc\spandsp.def"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
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 Wed Oct 1 00:06:53 2008
@@ -28,7 +28,7 @@
* Computer Science, Speech Group
* Chengxiang Lu and Alex Hauptmann
*
- * $Id: g722.h,v 1.20 2008/09/19 14:02:05 steveu Exp $
+ * $Id: g722.h,v 1.21 2008/09/19 16:24:25 steveu Exp $
*/
@@ -59,15 +59,15 @@
/*! 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[3];
- int16_t a[3];
- int16_t p[3];
+ int16_t r;
+ int16_t p[2];
+ int16_t a[2];
+ int16_t b[6];
int16_t d[7];
- int16_t b[7];
- int16_t nb;
- int16_t det;
} g722_band_t;
typedef struct
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 Wed Oct 1 00:06:53 2008
@@ -30,8 +30,8 @@
/* The date and time of the version are in UTC form. */
-#define SPANDSP_RELEASE_DATE 20080919
-#define SPANDSP_RELEASE_TIME 142905
+#define SPANDSP_RELEASE_DATE 20080920
+#define SPANDSP_RELEASE_TIME 154737
#endif
/*- End of file ------------------------------------------------------------*/
Added: freeswitch/trunk/libs/spandsp/tests/complex_tests.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/tests/complex_tests.c Wed Oct 1 00:06:53 2008
@@ -0,0 +1,81 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * complex.c
+ *
+ * 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 General Public License version 2, 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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 $
+ */
+
+/*! \page complex_tests_page Complex arithmetic tests
+\section complex_tests_page_sec_1 What does it do?
+
+\section complex_tests_page_sec_2 How is it used?
+*/
+
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#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 <assert.h>
+
+#include "spandsp.h"
+
+int main(int argc, char *argv[])
+{
+ complexf_t fa;
+ complexf_t fb;
+ complexf_t fz;
+ complexi16_t i16a;
+ complexi16_t i16b;
+ complexi16_t i16z;
+#if 0
+ complexi32_t i32a;
+ complexi32_t i32b;
+ complexi32_t i32z;
+#endif
+
+ fa = complex_setf(0.5f, 0.25f);
+ fb = complex_setf(0.25f, 0.5f);
+ fz = complex_mulf(&fa, &fb);
+ printf("(%f, %f) * (%f, %f) => (%f, %f)\n", fa.re, fa.im, fb.re, fb.im, fz.re, fz.im);
+
+ i16a = complex_seti16(16383, 8191);
+ i16b = complex_seti16(8191, 16383);
+ i16z = complex_mul_q1_15(&i16a, &i16b);
+ printf("(%f, %f) * (%f, %f) => (%f, %f)\n", i16a.re/32768.0, i16a.im/32768.0, i16b.re/32768.0, i16b.im/32768.0, i16z.re/32768.0, i16z.im/32768.0);
+
+ printf("Tests passed.\n");
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+/*- End of file ------------------------------------------------------------*/
Added: freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/tests/complex_vector_float_tests.c Wed Oct 1 00:06:53 2008
@@ -0,0 +1,99 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * complex_vector_float_tests.c
+ *
+ * Written by Steve Underwood <steveu at coppice.org>
+ *
+ * Copyright (C) 2006,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 General Public License version 2, 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public 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_tests.c,v 1.1 2008/09/18 12:05:35 steveu Exp $
+ */
+
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <audiofile.h>
+
+#include "spandsp.h"
+
+static complexf_t cvec_dot_prodf_dumb(const complexf_t x[], const complexf_t y[], int n)
+{
+ int i;
+ complexf_t z;
+ complexf_t z1;
+
+ z = complex_setf(0.0f, 0.0f);
+ for (i = 0; i < n; i++)
+ {
+ z1 = complex_mulf(&x[i], &y[i]);
+ z = complex_addf(&z, &z1);
+ }
+ return z;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_cvec_dot_prodf(void)
+{
+ int i;
+ complexf_t x[100];
+ complexf_t y[100];
+ complexf_t zsa;
+ complexf_t zsb;
+ 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();
+ }
+ for (i = 1; i < 99; i++)
+ {
+ zsa = cvec_dot_prodf(x, y, i);
+ zsb = cvec_dot_prodf_dumb(x, y, i);
+ ratio.re = zsa.re/zsb.re;
+ ratio.im = zsa.im/zsb.im;
+ if ((ratio.re < 0.9999 || ratio.re > 1.0001)
+ ||
+ (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("Tests failed\n");
+ exit(2);
+ }
+ }
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+int main(int argc, char *argv[])
+{
+ test_cvec_dot_prodf();
+
+ printf("Tests passed.\n");
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+/*- End of file ------------------------------------------------------------*/
Added: freeswitch/trunk/libs/spandsp/tests/complex_vector_int_tests.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/spandsp/tests/complex_vector_int_tests.c Wed Oct 1 00:06:53 2008
@@ -0,0 +1,137 @@
+/*
+ * SpanDSP - a series of DSP components for telephony
+ *
+ * complex_vector_int_tests.c
+ *
+ * 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 General Public License version 2, 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public 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_tests.c,v 1.1 2008/09/18 12:05:35 steveu Exp $
+ */
+
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <audiofile.h>
+
+#include "spandsp.h"
+
+static complexi32_t cvec_dot_prodi16_dumb(const complexi16_t x[], const complexi16_t y[], int n)
+{
+ complexi32_t z;
+ int i;
+
+ z = complex_seti32(0, 0);
+ for (i = 0; i < n; i++)
+ {
+ z.re += ((int32_t) x[i].re*(int32_t) y[i].re - (int32_t) x[i].im*(int32_t) y[i].im);
+ z.im += ((int32_t) x[i].re*(int32_t) y[i].im + (int32_t) x[i].im*(int32_t) y[i].re);
+ }
+ return z;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_cvec_dot_prodi16(void)
+{
+ int i;
+ complexi32_t za;
+ complexi32_t zb;
+ complexi16_t x[99];
+ complexi16_t y[99];
+
+ for (i = 0; i < 99; i++)
+ {
+ x[i].re = rand();
+ x[i].im = rand();
+ y[i].re = rand();
+ y[i].im = rand();
+ }
+
+ for (i = 1; i < 99; i++)
+ {
+ za = cvec_dot_prodi16(x, y, i);
+ zb = cvec_dot_prodi16_dumb(x, y, i);
+ if (za.re != zb.re || za.im != zb.im)
+ {
+ printf("Tests failed\n");
+ exit(2);
+ }
+ }
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static int test_cvec_circular_dot_prodi16(void)
+{
+ int i;
+ int j;
+ int pos;
+ int len;
+ complexi32_t za;
+ complexi32_t zb;
+ complexi16_t x[99];
+ complexi16_t y[99];
+
+ /* Verify that we can do circular sample buffer "dot" linear coefficient buffer
+ operations properly, by doing two sub-dot products. */
+ for (i = 0; i < 99; i++)
+ {
+ x[i].re = rand();
+ x[i].im = rand();
+ y[i].re = rand();
+ y[i].im = rand();
+ }
+
+ len = 95;
+ for (pos = 0; pos < len; pos++)
+ {
+ za = cvec_circular_dot_prodi16(x, y, len, pos);
+ zb = complex_seti32(0, 0);
+ for (i = 0; i < len; i++)
+ {
+ j = (pos + i) % len;
+ zb.re += ((int32_t) x[j].re*(int32_t) y[i].re - (int32_t) x[j].im*(int32_t) y[i].im);
+ zb.im += ((int32_t) x[j].re*(int32_t) y[i].im + (int32_t) x[j].im*(int32_t) y[i].re);
+ }
+
+ if (za.re != zb.re || za.im != zb.im)
+ {
+ printf("Tests failed\n");
+ exit(2);
+ }
+ }
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+int main(int argc, char *argv[])
+{
+ test_cvec_dot_prodi16();
+ test_cvec_circular_dot_prodi16();
+
+ printf("Tests passed.\n");
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+/*- End of file ------------------------------------------------------------*/
More information about the Freeswitch-svn
mailing list