mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 20:50:41 +00:00
A bunch of tweaks to the G.722.1 codec
This commit is contained in:
parent
d24af1e1c2
commit
5d5485708d
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.6 2008/09/30 14:06:39 steveu Exp $
|
||||
|
||||
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
|
||||
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
|
||||
@ -26,6 +24,7 @@ noinst_SCRIPTS = g722_1.spec
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
EXTRA_DIST = autogen.sh \
|
||||
g722_1.pc \
|
||||
g722_1.spec \
|
||||
unpack_g722_1_data.sh \
|
||||
wrapper.xsl \
|
||||
@ -50,6 +49,9 @@ SUBDIRS = src $(MAYBE_DOC) $(MAYBE_TESTS)
|
||||
|
||||
DIST_SUBDIRS = src doc tests test-data
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = g722_1.pc
|
||||
|
||||
faq: faq.xml
|
||||
cd faq ; xsltproc ../wrapper.xsl ../faq.xml
|
||||
|
||||
|
@ -16,11 +16,6 @@
|
||||
# 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: autogen.sh,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $
|
||||
#
|
||||
|
||||
UNAME=`uname`
|
||||
|
||||
if [ "x$UNAME" = "xFreeBSD" ]; then
|
||||
echo ""
|
||||
|
@ -15,17 +15,11 @@
|
||||
# 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: configure.ac,v 1.9 2008/10/09 14:17:12 steveu Exp $
|
||||
|
||||
# @start 1
|
||||
|
||||
AC_INIT
|
||||
|
||||
CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
|
||||
LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
|
||||
|
||||
m4_include(config/ax_compiler_vendor.m4)
|
||||
m4_include(config/ax_check_real_file.m4)
|
||||
m4_include(config/ax_fixed_point_machine.m4)
|
||||
@ -111,6 +105,22 @@ else
|
||||
CXXFLAGS=${CXXFLAGS-"-g -O2"}
|
||||
fi
|
||||
|
||||
AC_DEFUN([REMOVE_FROM_VAR],[
|
||||
new_val=""
|
||||
removed=0
|
||||
for i in $$1; do
|
||||
if test "x$i" != "x$2"; then
|
||||
new_val="$new_val $i"
|
||||
else
|
||||
removed=1
|
||||
fi
|
||||
done
|
||||
if test $removed = "1"; then
|
||||
echo " removed \"$2\" from $1"
|
||||
$1=$new_val
|
||||
fi
|
||||
])
|
||||
|
||||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
AC_C_VOLATILE
|
||||
@ -190,7 +200,7 @@ AC_CHECK_HEADERS([audiofile.h])
|
||||
|
||||
AC_LANG([C])
|
||||
|
||||
if test "${build}" = "${host}"
|
||||
if test "${build}" == "${host}"
|
||||
then
|
||||
case "${host}" in
|
||||
x86_64-*)
|
||||
@ -270,6 +280,7 @@ sun)
|
||||
COMP_VENDOR_CFLAGS="-native -fast $COMP_VENDOR_CFLAGS"
|
||||
fi
|
||||
COMP_VENDOR_LDFLAGS=
|
||||
REMOVE_FROM_VAR(CFLAGS, -Xc)
|
||||
;;
|
||||
*)
|
||||
COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes"
|
||||
@ -293,20 +304,14 @@ AM_CONDITIONAL([COND_SSE5], [test "$enable_sse5" = yes])
|
||||
if test "$enable_fixed_point" = "yes" ; then
|
||||
AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point])
|
||||
G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1"
|
||||
fixed = "yes"
|
||||
G722_1_VECTORS_FOR_TESTS="fixed"
|
||||
else
|
||||
AX_FIXED_POINT_MACHINE([$host],
|
||||
[
|
||||
AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point])
|
||||
G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1"
|
||||
fixed = "yes"
|
||||
],
|
||||
[AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point])
|
||||
G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1"],
|
||||
[G722_1_USE_FIXED_POINT="#undef G722_1_USE_FIXED_POINT"])
|
||||
G722_1_VECTORS_FOR_TESTS="floating"
|
||||
fi
|
||||
AM_CONDITIONAL([COND_FIXED], [test "$fixed" = "yes"])
|
||||
|
||||
AX_MISALIGNED_ACCESS_FAILS([$host],
|
||||
[AC_DEFINE([G722_1_MISALIGNED_ACCESS_FAILS], [1], [Do not expect a misaligned memory access to work correctly])
|
||||
G722_1_MISALIGNED_ACCESS_FAILS="#define G722_1_MISALIGNED_ACCESS_FAILS 1"],
|
||||
@ -363,6 +368,7 @@ AC_CONFIG_FILES([Makefile
|
||||
src/Makefile
|
||||
src/g722_1.h
|
||||
tests/Makefile
|
||||
g722_1.pc
|
||||
g722_1.spec])
|
||||
|
||||
AC_CONFIG_FILES([tests/regression_tests.sh], [chmod +x tests/regression_tests.sh])
|
||||
|
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $
|
||||
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
|
@ -47,14 +47,13 @@ rm -rf %{buildroot}
|
||||
|
||||
%{_libdir}/libg722_1.so.*
|
||||
|
||||
%{_datadir}/libg722_1
|
||||
|
||||
%files devel
|
||||
%defattr(-,root,root,-)
|
||||
%doc doc/api
|
||||
%{_includedir}/g722_1.h
|
||||
%{_includedir}/g722_1
|
||||
%{_libdir}/libg722_1.so
|
||||
%{_libdir}/pkgconfig/g722_1.pc
|
||||
|
||||
%post -p /sbin/ldconfig
|
||||
|
||||
|
@ -15,18 +15,19 @@
|
||||
## 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: Makefile.am,v 1.10 2008/10/16 15:46:12 steveu Exp $
|
||||
|
||||
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
|
||||
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
|
||||
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
EXTRA_DIST = g722_1/version.h.in \
|
||||
EXTRA_DIST = make_tables.c \
|
||||
g722_1/version.h.in \
|
||||
libg722_1.dsp \
|
||||
libg722_1.sln \
|
||||
libg722_1.vcproj \
|
||||
libg722_1.2005.sln \
|
||||
libg722_1.2008.sln \
|
||||
libg722_1.2005.vcproj \
|
||||
libg722_1.2008.vcproj \
|
||||
msvc/gettimeofday.c \
|
||||
msvc/inttypes.h \
|
||||
msvc/tgmath.h \
|
||||
@ -36,13 +37,16 @@ EXTRA_DIST = g722_1/version.h.in \
|
||||
msvc/msvcproj.head \
|
||||
msvc/msvcproj.foot \
|
||||
msvc/vc8proj.head \
|
||||
msvc/vc8proj.foot
|
||||
msvc/vc8proj.foot \
|
||||
msvc/vc9proj.head \
|
||||
msvc/vc9proj.foot
|
||||
|
||||
INCLUDES = -I$(top_builddir)
|
||||
|
||||
lib_LTLIBRARIES = libg722_1.la
|
||||
|
||||
libg722_1_la_SOURCES = bitstream.c \
|
||||
libg722_1_la_SOURCES = basop32.c \
|
||||
bitstream.c \
|
||||
coef2sam.c \
|
||||
common.c \
|
||||
commonf.c \
|
||||
@ -55,11 +59,9 @@ libg722_1_la_SOURCES = bitstream.c \
|
||||
encoderf.c \
|
||||
huff_tab.c \
|
||||
sam2coef.c \
|
||||
tables.c
|
||||
tables.c \
|
||||
utilities.c
|
||||
|
||||
if COND_FIXED
|
||||
libg722_1_la_SOURCES += basop32.c
|
||||
endif
|
||||
libg722_1_la_LDFLAGS = -version-info @G722_1_LT_CURRENT@:@G722_1_LT_REVISION@:@G722_1_LT_AGE@ $(COMP_VENDOR_LDFLAGS)
|
||||
|
||||
nobase_include_HEADERS = g722_1/g722_1.h \
|
||||
@ -76,10 +78,10 @@ noinst_HEADERS = basop32.h \
|
||||
defs.h \
|
||||
huff_tab.h \
|
||||
sam2coef.h \
|
||||
tables.h
|
||||
tables.h \
|
||||
utilities.h
|
||||
|
||||
noinst_PROGRAMS = make_dct4_tables \
|
||||
make_tables
|
||||
noinst_PROGRAMS = make_dct4_tables
|
||||
|
||||
dct4.$(OBJEXT): dct4.h
|
||||
|
||||
@ -88,6 +90,9 @@ dct4.lo: dct4.h
|
||||
dct4.h: make_dct4_tables$(EXEEXT)
|
||||
./make_dct4_tables$(EXEEXT) >dct4.h
|
||||
|
||||
make_dct4_tables$(EXEEXT): $(top_srcdir)/src/make_dct4_tables.c
|
||||
$(CC_FOR_BUILD) -o make_dct4_tables$(EXEEXT) $(top_srcdir)/src/make_dct4_tables.c -DHAVE_CONFIG_H -I$(top_builddir)/src -lm
|
||||
|
||||
#coef2sam.h: make_tables$(EXEEXT)
|
||||
# ./make_tables$(EXEEXT) coef2sam >coef2samx.h
|
||||
|
||||
@ -95,13 +100,15 @@ dct4.h: make_dct4_tables$(EXEEXT)
|
||||
# ./make_tables$(EXEEXT) sam2coef >sam2coefx.h
|
||||
|
||||
DSP = libg722_1.dsp
|
||||
VCPROJ = libg722_1.vcproj
|
||||
VCPROJ8 = libg722_1.2005.vcproj
|
||||
VCPROJ9 = libg722_1.2008.vcproj
|
||||
|
||||
WIN32SOURCES = $(libg722_1_la_SOURCES) msvc/gettimeofday.c
|
||||
WIN32HEADERS = $(nobase_include_HEADERS) g722_1.h
|
||||
|
||||
DSPOUT = | awk '{printf("%s\r\n", $$0)}' >> $(DSP)
|
||||
VCPROJOUT = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ)
|
||||
VCPROJOUT8 = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ8)
|
||||
VCPROJOUT9 = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ9)
|
||||
|
||||
$(DSP): msvc/msvcproj.head msvc/msvcproj.foot Makefile.am
|
||||
echo "creating $(DSP)"
|
||||
@ -124,26 +131,38 @@ $(DSP): msvc/msvcproj.head msvc/msvcproj.foot Makefile.am
|
||||
echo "# End Group" $(DSPOUT); \
|
||||
cat $(srcdir)/msvc/msvcproj.foot $(DSPOUT) )
|
||||
|
||||
$(VCPROJ): msvc/vc8proj.head msvc/vc8proj.foot Makefile.am
|
||||
echo "creating $(VCPROJ)"
|
||||
@(cp $(srcdir)/msvc/vc8proj.head $(VCPROJ); \
|
||||
$(VCPROJ8): msvc/vc8proj.head msvc/vc8proj.foot Makefile.am
|
||||
echo "creating $(VCPROJ8)"
|
||||
@(cp $(srcdir)/msvc/vc8proj.head $(VCPROJ8); \
|
||||
for file in $(WIN32SOURCES); do \
|
||||
echo "<File RelativePath=\""$$file"\"></File>" $(VCPROJOUT); \
|
||||
myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \
|
||||
echo "<File RelativePath=\""$$myfile"\"></File>" $(VCPROJOUT8); \
|
||||
done; \
|
||||
echo "</Filter><Filter Name=\"Header Files\">" $(VCPROJOUT); \
|
||||
echo "</Filter><Filter Name=\"Header Files\">" $(VCPROJOUT8); \
|
||||
for file in $(WIN32HEADERS); do \
|
||||
echo "<File RelativePath=\""$$file"\"></File>" $(VCPROJOUT); \
|
||||
myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \
|
||||
echo "<File RelativePath=\""$$myfile"\"></File>" $(VCPROJOUT8); \
|
||||
done; \
|
||||
cat $(srcdir)/msvc/vc8proj.foot $(VCPROJOUT) )
|
||||
cat $(srcdir)/msvc/vc8proj.foot $(VCPROJOUT8) )
|
||||
|
||||
$(VCPROJ9): msvc/vc9proj.head msvc/vc9proj.foot Makefile.am
|
||||
echo "creating $(VCPROJ9)"
|
||||
@(cp $(srcdir)/msvc/vc9proj.head $(VCPROJ9); \
|
||||
for file in $(WIN32SOURCES); do \
|
||||
myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \
|
||||
echo "<File RelativePath=\""$$myfile"\"></File>" $(VCPROJOUT9); \
|
||||
done; \
|
||||
echo "</Filter><Filter Name=\"Header Files\">" $(VCPROJOUT9); \
|
||||
for file in $(WIN32HEADERS); do \
|
||||
myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \
|
||||
echo "<File RelativePath=\""$$myfile"\"></File>" $(VCPROJOUT9); \
|
||||
done; \
|
||||
cat $(srcdir)/msvc/vc9proj.foot $(VCPROJOUT9) )
|
||||
|
||||
dist-hook: g722_1/version.h
|
||||
|
||||
g722_1/version.h:
|
||||
NOWDATE=`date --utc +"%Y%m%d"` ; \
|
||||
NOWTIME=`date --utc +"%H%M%S"` ; \
|
||||
sed 's/$$G722_1_RELEASE_DATE/'$$NOWDATE'/;s/$$G722_1_RELEASE_TIME/'$$NOWTIME'/' \
|
||||
<g722_1/version.h.in >g722_1/version.h
|
||||
|
||||
dist-hook:
|
||||
NOWDATE=`date --utc +"%Y%m%d"` ; \
|
||||
NOWTIME=`date --utc +"%H%M%S"` ; \
|
||||
sed 's/$$G722_1_RELEASE_DATE/'$$NOWDATE'/;s/$$G722_1_RELEASE_TIME/'$$NOWTIME'/' \
|
||||
<g722_1/version.h.in >g722_1/version.h
|
||||
<$(srcdir)/g722_1/version.h.in >$@
|
||||
|
@ -9,8 +9,6 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id: basop32.c,v 1.5 2008/09/22 13:08:31 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: basop32.h,v 1.3 2008/09/22 13:08:31 steveu Exp $
|
||||
*/
|
||||
|
||||
#if !defined(BASOP32_H_DEFINED)
|
||||
@ -104,14 +102,14 @@ static __inline__ int32_t L_mac(int32_t L_var3, int16_t var1, int16_t var2)
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
int16_t shl(int16_t var1, int16_t var2); /* Short shift left, 1 */
|
||||
int16_t shr(int16_t var1, int16_t var2); /* Short shift right, 1 */
|
||||
int32_t L_sub(int32_t L_var1, int32_t L_var2); /* Long sub, 2 */
|
||||
int32_t L_shl(int32_t L_var1, int16_t var2); /* Long shift left, 2 */
|
||||
int32_t L_shr(int32_t L_var1, int16_t var2); /* Long shift right, 2*/
|
||||
int16_t norm_s(int16_t var1); /* Short norm, 15 */
|
||||
int16_t div_s(int16_t var1, int16_t var2); /* Short division, 18 */
|
||||
int16_t norm_l(int32_t L_var1); /* Long norm, 30 */
|
||||
int16_t shl(int16_t var1, int16_t var2); /* Short shift left, 1 */
|
||||
int16_t shr(int16_t var1, int16_t var2); /* Short shift right, 1 */
|
||||
int32_t L_sub(int32_t L_var1, int32_t L_var2); /* Long sub, 2 */
|
||||
int32_t L_shl(int32_t L_var1, int16_t var2); /* Long shift left, 2 */
|
||||
int32_t L_shr(int32_t L_var1, int16_t var2); /* Long shift right, 2 */
|
||||
int16_t norm_s(int16_t var1); /* Short norm, 15 */
|
||||
int16_t div_s(int16_t var1, int16_t var2); /* Short division, 18 */
|
||||
int16_t norm_l(int32_t L_var1); /* Long norm, 30 */
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -8,8 +8,6 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id: bitstream.c,v 1.2 2008/10/17 13:18:21 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
@ -8,8 +8,6 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id: bitstream.h,v 1.2 2008/10/17 13:18:21 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: coef2sam.c,v 1.10 2008/10/02 11:43:54 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -29,18 +27,16 @@
|
||||
|
||||
#include "defs.h"
|
||||
#include "coef2sam.h"
|
||||
#include "utilities.h"
|
||||
|
||||
/*************************************************************************************
|
||||
/* Convert Reversed MLT (Modulated Lapped Transform) Coefficients to Samples
|
||||
|
||||
Purpose: Convert Reversed MLT (Modulated Lapped Transform) Coefficients to Samples
|
||||
|
||||
The "Reversed MLT" is an overlapped block transform which uses even symmetry
|
||||
on the left, odd symmetry on the right and a Type IV DCT as the block transform.
|
||||
It is thus similar to a MLT which uses odd symmetry on the left, even symmetry
|
||||
on the right and a Type IV DST as the block transform. In fact, it is equivalent
|
||||
to reversing the order of the samples, performing an MLT and then negating all
|
||||
the even-numbered coefficients.
|
||||
***************************************************************************/
|
||||
The "Reversed MLT" is an overlapped block transform which uses even symmetry
|
||||
on the left, odd symmetry on the right and a Type IV DCT as the block transform.
|
||||
It is thus similar to a MLT which uses odd symmetry on the left, even symmetry
|
||||
on the right and a Type IV DST as the block transform. In fact, it is equivalent
|
||||
to reversing the order of the samples, performing an MLT and then negating all
|
||||
the even-numbered coefficients. */
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
void rmlt_coefs_to_samples(int16_t coefs[],
|
||||
@ -73,29 +69,23 @@ void rmlt_coefs_to_samples(int16_t coefs[],
|
||||
new_samples[i] = shl(new_samples[i], mag_shift);
|
||||
}
|
||||
|
||||
if (dct_length == DCT_LENGTH)
|
||||
win = rmlt_to_samples_window;
|
||||
else
|
||||
win = max_rmlt_to_samples_window;
|
||||
win = (dct_length == DCT_LENGTH) ? rmlt_to_samples_window : max_rmlt_to_samples_window;
|
||||
last = half_dct_length - 1;
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
{
|
||||
/* Get the first half of the windowed samples */
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, win[i], new_samples[last - i]);
|
||||
sum = L_mult(win[i], new_samples[last - i]);
|
||||
sum = L_mac(sum, win[dct_length - i - 1], old_samples[i]);
|
||||
out_samples[i] = xround(L_shl(sum, 2));
|
||||
/* Get the second half of the windowed samples */
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, win[half_dct_length + i], new_samples[i]);
|
||||
sum = L_mult(win[half_dct_length + i], new_samples[i]);
|
||||
sum = L_mac(sum, negate(win[last - i]), old_samples[last - i]);
|
||||
out_samples[half_dct_length + i] = xround(L_shl(sum, 2));
|
||||
}
|
||||
|
||||
/* Save the second half of the new samples for
|
||||
next time, when they will be the old samples. */
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
old_samples[i] = new_samples[half_dct_length + i];
|
||||
vec_copyi16(old_samples, &new_samples[half_dct_length], half_dct_length);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
#else
|
||||
@ -116,10 +106,7 @@ void rmlt_coefs_to_samples(float coefs[],
|
||||
/* Perform a Type IV (inverse) DCT on the coefficients */
|
||||
dct_type_iv(coefs, new_samples, dct_length);
|
||||
|
||||
if (dct_length == DCT_LENGTH)
|
||||
win = rmlt_to_samples_window;
|
||||
else
|
||||
win = max_rmlt_to_samples_window;
|
||||
win = (dct_length == DCT_LENGTH) ? rmlt_to_samples_window : max_rmlt_to_samples_window;
|
||||
last = half_dct_length - 1;
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
{
|
||||
@ -135,8 +122,7 @@ void rmlt_coefs_to_samples(float coefs[],
|
||||
|
||||
/* Save the second half of the new samples for next time, when they will
|
||||
be the old samples. */
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
old_samples[i] = new_samples[half_dct_length + i];
|
||||
vec_copyf(old_samples, &new_samples[half_dct_length], half_dct_length);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
#endif
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: coef2sam.h,v 1.2 2008/10/02 11:43:54 steveu Exp $
|
||||
*/
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: common.c,v 1.6 2008/09/30 14:06:39 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -38,41 +36,7 @@ static void compute_raw_pow_categories(int16_t *power_categories,
|
||||
int16_t number_of_regions,
|
||||
int16_t offset);
|
||||
|
||||
/****************************************************************************************
|
||||
Function: categorize
|
||||
|
||||
Syntax: void categorize(int16_t number_of_available_bits,
|
||||
int16_t number_of_regions,
|
||||
int16_t num_categorization_control_possibilities,
|
||||
int16_t rms_index,
|
||||
int16_t power_categories,
|
||||
int16_t category_balances)
|
||||
|
||||
inputs: number_of_regions
|
||||
num_categorization_control_possibilities
|
||||
number_of_available_bits
|
||||
rms_index[MAX_NUMBER_OF_REGIONS]
|
||||
|
||||
outputs: power_categories[MAX_NUMBER_OF_REGIONS]
|
||||
category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES-1]
|
||||
|
||||
Description: Computes a series of categorizations
|
||||
|
||||
WMOPS: 7kHz | 24kbit | 32kbit
|
||||
-------|--------------|----------------
|
||||
AVG | 0.14 | 0.14
|
||||
-------|--------------|----------------
|
||||
MAX | 0.15 | 0.15
|
||||
-------|--------------|----------------
|
||||
|
||||
14kHz | 24kbit | 32kbit | 48kbit
|
||||
-------|--------------|----------------|----------------
|
||||
AVG | 0.42 | 0.45 | 0.48
|
||||
-------|--------------|----------------|----------------
|
||||
MAX | 0.47 | 0.52 | 0.52
|
||||
-------|--------------|----------------|----------------
|
||||
|
||||
****************************************************************************************/
|
||||
/* Compute a series of categorizations */
|
||||
void categorize(int16_t number_of_available_bits,
|
||||
int16_t number_of_regions,
|
||||
int16_t num_categorization_control_possibilities,
|
||||
@ -88,10 +52,7 @@ void categorize(int16_t number_of_available_bits,
|
||||
/* At higher bit rates, there is an increase for most categories in average bit
|
||||
consumption per region. We compensate for this by pretending we have fewer
|
||||
available bits. */
|
||||
if (number_of_regions == NUMBER_OF_REGIONS)
|
||||
frame_size = DCT_LENGTH;
|
||||
else
|
||||
frame_size = MAX_DCT_LENGTH;
|
||||
frame_size = (number_of_regions == NUMBER_OF_REGIONS) ? DCT_LENGTH : MAX_DCT_LENGTH;
|
||||
|
||||
temp = sub(number_of_available_bits, frame_size);
|
||||
if (temp > 0)
|
||||
@ -114,45 +75,7 @@ void categorize(int16_t number_of_available_bits,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************
|
||||
Function: comp_powercat_and_catbalance
|
||||
|
||||
Syntax: void comp_powercat_and_catbalance(int16_t *power_categories,
|
||||
int16_t *category_balances,
|
||||
int16_t *rms_index,
|
||||
int16_t number_of_available_bits,
|
||||
int16_t number_of_regions,
|
||||
int16_t num_categorization_control_possibilities,
|
||||
int16_t offset)
|
||||
|
||||
|
||||
inputs: *rms_index
|
||||
number_of_available_bits
|
||||
number_of_regions
|
||||
num_categorization_control_possibilities
|
||||
offset
|
||||
|
||||
outputs: *power_categories
|
||||
*category_balances
|
||||
|
||||
|
||||
Description: Computes the power_categories and the category balances
|
||||
|
||||
WMOPS: 7kHz | 24kbit | 32kbit
|
||||
-------|--------------|----------------
|
||||
AVG | 0.10 | 0.10
|
||||
-------|--------------|----------------
|
||||
MAX | 0.11 | 0.11
|
||||
-------|--------------|----------------
|
||||
|
||||
14kHz | 24kbit | 32kbit | 48kbit
|
||||
-------|--------------|----------------|----------------
|
||||
AVG | 0.32 | 0.35 | 0.38
|
||||
-------|--------------|----------------|----------------
|
||||
MAX | 0.38 | 0.42 | 0.43
|
||||
-------|--------------|----------------|----------------
|
||||
|
||||
***************************************************************************/
|
||||
/* Compute the power_categories and the category balances */
|
||||
void comp_powercat_and_catbalance(int16_t *power_categories,
|
||||
int16_t *category_balances,
|
||||
int16_t *rms_index,
|
||||
@ -161,7 +84,6 @@ void comp_powercat_and_catbalance(int16_t *power_categories,
|
||||
int16_t num_categorization_control_possibilities,
|
||||
int16_t offset)
|
||||
{
|
||||
|
||||
int16_t expected_number_of_code_bits;
|
||||
int16_t region;
|
||||
int16_t max_region;
|
||||
@ -190,7 +112,6 @@ void comp_powercat_and_catbalance(int16_t *power_categories,
|
||||
for (region = 0; region < number_of_regions; region++)
|
||||
expected_number_of_code_bits = add(expected_number_of_code_bits, expected_bits_table[power_categories[region]]);
|
||||
|
||||
|
||||
for (region = 0; region < number_of_regions; region++)
|
||||
{
|
||||
max_rate_categories[region] = power_categories[region];
|
||||
@ -277,42 +198,16 @@ void comp_powercat_and_catbalance(int16_t *power_categories,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************
|
||||
Function: calc_offset
|
||||
|
||||
Syntax: offset=calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t available_bits)
|
||||
|
||||
input: int16_t *rms_index
|
||||
int16_t number_of_regions
|
||||
int16_t available_bits
|
||||
|
||||
output: int16_t offset
|
||||
|
||||
Description: Calculates the the category offset. This is the shift required
|
||||
To get the most out of the number of available bits. A binary
|
||||
type search is used to find the offset.
|
||||
|
||||
WMOPS: 7kHz | 24kbit | 32kbit
|
||||
-------|--------------|----------------
|
||||
AVG | 0.04 | 0.04
|
||||
-------|--------------|----------------
|
||||
MAX | 0.04 | 0.04
|
||||
-------|--------------|----------------
|
||||
|
||||
14kHz | 24kbit | 32kbit | 48kbit
|
||||
-------|--------------|----------------|----------------
|
||||
AVG | 0.08 | 0.08 | 0.08
|
||||
-------|--------------|----------------|----------------
|
||||
MAX | 0.09 | 0.09 | 0.09
|
||||
-------|--------------|----------------|----------------
|
||||
|
||||
***************************************************************************/
|
||||
int16_t calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t available_bits)
|
||||
/* Calculate the the category offset. This is the shift required
|
||||
To get the most out of the number of available bits. A binary
|
||||
type search is used to find the offset. */
|
||||
int16_t calc_offset(int16_t *rms_index, int16_t number_of_regions, int16_t available_bits)
|
||||
{
|
||||
int16_t answer;
|
||||
int16_t delta;
|
||||
int16_t test_offset;
|
||||
int16_t region,j;
|
||||
int16_t region;
|
||||
int16_t j;
|
||||
int16_t power_cats[MAX_NUMBER_OF_REGIONS];
|
||||
int16_t bits;
|
||||
int16_t offset;
|
||||
@ -360,40 +255,9 @@ int16_t calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t availab
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************
|
||||
Function: compute_raw_pow_categories
|
||||
|
||||
Syntax: void compute_raw_pow_categories(int16_t *power_categories,
|
||||
int16_t *rms_index,
|
||||
int16_t number_of_regions,
|
||||
int16_t offset)
|
||||
inputs: *rms_index
|
||||
number_of_regions
|
||||
offset
|
||||
|
||||
outputs: *power_categories
|
||||
|
||||
|
||||
|
||||
Description: This function computes the power categories given the offset
|
||||
This is kind of redundant since they were already computed
|
||||
in calc_offset to determine the offset.
|
||||
|
||||
WMOPS: | 24kbit | 32kbit
|
||||
-------|--------------|----------------
|
||||
AVG | 0.01 | 0.01
|
||||
-------|--------------|----------------
|
||||
MAX | 0.01 | 0.01
|
||||
-------|--------------|----------------
|
||||
|
||||
14kHz | 24kbit | 32kbit | 48kbit
|
||||
-------|--------------|----------------|----------------
|
||||
AVG | 0.01 | 0.01 | 0.01
|
||||
-------|--------------|----------------|----------------
|
||||
MAX | 0.01 | 0.01 | 0.01
|
||||
-------|--------------|----------------|----------------
|
||||
|
||||
***************************************************************************/
|
||||
/* Compute the power categories given the offset
|
||||
This is kind of redundant since they were already computed
|
||||
in calc_offset to determine the offset. */
|
||||
static void compute_raw_pow_categories(int16_t *power_categories, int16_t *rms_index, int16_t number_of_regions, int16_t offset)
|
||||
{
|
||||
int16_t region;
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: commonf.c,v 1.11 2008/09/30 14:06:39 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -34,9 +32,7 @@
|
||||
|
||||
#if !defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
/****************************************************************************************
|
||||
Description: Computes a series of categorizations
|
||||
****************************************************************************************/
|
||||
/* Compute a series of categorizations */
|
||||
void categorize(int number_of_regions,
|
||||
int number_of_available_bits,
|
||||
int rms_index[MAX_NUMBER_OF_REGIONS],
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C)2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: dct4.c,v 1.8 2008/09/29 16:09:26 steveu Exp $
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
@ -29,6 +27,7 @@
|
||||
#include "g722_1/g722_1.h"
|
||||
|
||||
#include "defs.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#if !defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
@ -52,9 +51,7 @@ static const cos_msin_t *cos_msin_table[] =
|
||||
cos_msin_640
|
||||
};
|
||||
|
||||
/*********************************************************************************
|
||||
Description: Discrete Cosine Transform, Type IV
|
||||
*********************************************************************************/
|
||||
/* Discrete Cosine Transform, Type IV */
|
||||
void dct_type_iv(float input[], float output[], int dct_length)
|
||||
{
|
||||
float buffer_a[MAX_DCT_LENGTH];
|
||||
@ -64,22 +61,20 @@ void dct_type_iv(float input[], float output[], int dct_length)
|
||||
float *in_ptr_low;
|
||||
float *in_ptr_high;
|
||||
float *next_in_base;
|
||||
float *out_ptr_low;
|
||||
float *out_ptr_high;
|
||||
float *out_ptr;
|
||||
float *next_out_base;
|
||||
float *out_buffer;
|
||||
float *in_buffer;
|
||||
float *buffer_swap;
|
||||
float *fptr0;
|
||||
const float *fptr2;
|
||||
const float *core_a;
|
||||
float in_val_low;
|
||||
float in_val_high;
|
||||
float cos_even;
|
||||
float cos_odd;
|
||||
float msin_even;
|
||||
float msin_odd;
|
||||
float sum;
|
||||
const float *fptr2;
|
||||
const float *core_a;
|
||||
const cos_msin_t **table_ptr_ptr;
|
||||
const cos_msin_t *cos_msin_ptr;
|
||||
int set_span;
|
||||
@ -120,29 +115,24 @@ void dct_type_iv(float input[], float output[], int dct_length)
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up output pointers for the current set */
|
||||
out_ptr_low = next_out_base;
|
||||
out_ptr = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
|
||||
/* Loop over all the butterflies in the current set */
|
||||
do
|
||||
for (i = 0; i < (set_span >> 1); i++)
|
||||
{
|
||||
in_val_low = *in_ptr++;
|
||||
in_val_high = *in_ptr++;
|
||||
*out_ptr_low++ = in_val_low + in_val_high;
|
||||
*--out_ptr_high = in_val_low - in_val_high;
|
||||
out_ptr[i] = in_val_low + in_val_high;
|
||||
out_ptr[set_span - 1 - i] = in_val_low - in_val_high;
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
}
|
||||
|
||||
/* Decide which buffers to use as input and output next time.
|
||||
Except for the first time (when the input buffer is the
|
||||
subroutine input) we just alternate the local buffers. */
|
||||
in_buffer = out_buffer;
|
||||
if (out_buffer == buffer_a)
|
||||
out_buffer = buffer_b;
|
||||
else
|
||||
out_buffer = buffer_a;
|
||||
out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a;
|
||||
}
|
||||
|
||||
/* Do dct_size/10 ten-point transforms */
|
||||
@ -153,11 +143,8 @@ void dct_type_iv(float input[], float output[], int dct_length)
|
||||
fptr2 = core_a;
|
||||
for (k = 0; k < CORE_SIZE; k++)
|
||||
{
|
||||
sum = 0;
|
||||
for (i = 0; i < CORE_SIZE; i++)
|
||||
sum += fptr0[i]*fptr2[i];
|
||||
buffer_swap[k] = vec_dot_prodf(fptr0, fptr2, CORE_SIZE);
|
||||
fptr2 += CORE_SIZE;
|
||||
buffer_swap[k] = sum;
|
||||
}
|
||||
fptr0 += CORE_SIZE;
|
||||
buffer_swap += CORE_SIZE;
|
||||
@ -172,14 +159,10 @@ void dct_type_iv(float input[], float output[], int dct_length)
|
||||
{
|
||||
/* Initialization for the loop over sets at the current size */
|
||||
set_span = dct_length >> set_count_log;
|
||||
|
||||
set_count = 1 << set_count_log;
|
||||
next_in_base = in_buffer;
|
||||
if (set_count_log == 0)
|
||||
next_out_base = output;
|
||||
else
|
||||
next_out_base = out_buffer;
|
||||
++table_ptr_ptr;
|
||||
next_out_base = (set_count_log == 0) ? output : out_buffer;
|
||||
table_ptr_ptr++;
|
||||
|
||||
/* Loop over all the sets of this size */
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
@ -187,26 +170,23 @@ void dct_type_iv(float input[], float output[], int dct_length)
|
||||
/* Set up the pointers for the current set */
|
||||
in_ptr_low = next_in_base;
|
||||
in_ptr_high = in_ptr_low + (set_span >> 1);
|
||||
next_in_base += set_span;
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
out_ptr = next_out_base;
|
||||
cos_msin_ptr = *table_ptr_ptr;
|
||||
|
||||
/* Loop over all the butterfly pairs in the current set */
|
||||
do
|
||||
for (i = 0; i < (set_span >> 1); i += 2)
|
||||
{
|
||||
cos_even = (*cos_msin_ptr).cosine;
|
||||
msin_even = (*cos_msin_ptr++).minus_sine;
|
||||
*out_ptr_low++ = cos_even * *in_ptr_low - msin_even * *in_ptr_high;
|
||||
*--out_ptr_high = msin_even * *in_ptr_low++ + cos_even * *in_ptr_high++;
|
||||
|
||||
cos_odd = (*cos_msin_ptr).cosine;
|
||||
msin_odd = (*cos_msin_ptr++).minus_sine;
|
||||
*out_ptr_low++ = cos_odd * *in_ptr_low + msin_odd * *in_ptr_high;
|
||||
*--out_ptr_high = msin_odd * *in_ptr_low++ - cos_odd * *in_ptr_high++;
|
||||
cos_even = cos_msin_ptr[i].cosine;
|
||||
msin_even = cos_msin_ptr[i].minus_sine;
|
||||
cos_odd = cos_msin_ptr[i + 1].cosine;
|
||||
msin_odd = cos_msin_ptr[i + 1].minus_sine;
|
||||
out_ptr[i] = cos_even*in_ptr_low[i] - msin_even*in_ptr_high[i];
|
||||
out_ptr[set_span - 1 - i] = msin_even*in_ptr_low[i] + cos_even*in_ptr_high[i];
|
||||
out_ptr[i + 1] = cos_odd*in_ptr_low[i + 1] + msin_odd*in_ptr_high[i + 1];
|
||||
out_ptr[set_span - 2 - i] = msin_odd*in_ptr_low[i + 1] - cos_odd*in_ptr_high[i + 1];
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
next_in_base += set_span;
|
||||
next_out_base += set_span;
|
||||
}
|
||||
|
||||
/* Swap input and output buffers for next time */
|
||||
|
@ -6,29 +6,23 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: dct4_a.c,v 1.8 2008/09/30 14:06:39 steveu Exp $
|
||||
*/
|
||||
|
||||
/*********************************************************************************
|
||||
* Filename: dct_type_iv_a.c
|
||||
*
|
||||
* Purpose: Discrete Cosine Transform, Type IV used for MLT
|
||||
*
|
||||
* The basis functions are
|
||||
*
|
||||
* cos(PI*(t+0.5)*(k+0.5)/block_length)
|
||||
*
|
||||
* for time t and basis function number k. Due to the symmetry of the expression
|
||||
* in t and k, it is clear that the forward and inverse transforms are the same.
|
||||
*
|
||||
*********************************************************************************/
|
||||
/* Discrete Cosine Transform, Type IV used for MLT
|
||||
|
||||
The basis functions are
|
||||
|
||||
cos(PI*(t+0.5)*(k+0.5)/block_length)
|
||||
|
||||
for time t and basis function number k. Due to the symmetry of the
|
||||
expression in t and k, it is clear that the forward and inverse transforms
|
||||
are the same. */
|
||||
|
||||
/*! \file */
|
||||
|
||||
@ -47,51 +41,31 @@
|
||||
|
||||
#include "dct4_a.h"
|
||||
|
||||
/*********************************************************************************
|
||||
Function: dct_type_iv_a
|
||||
|
||||
Syntax: void dct_type_iv_a (input, output, dct_length)
|
||||
int16_t input[], output[], dct_length;
|
||||
|
||||
Description: Discrete Cosine Transform, Type IV used for MLT
|
||||
*********************************************************************************/
|
||||
|
||||
/* Discrete Cosine Transform, Type IV used for MLT */
|
||||
void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length)
|
||||
{
|
||||
int16_t buffer_a[MAX_DCT_LENGTH];
|
||||
int16_t buffer_b[MAX_DCT_LENGTH];
|
||||
int16_t buffer_c[MAX_DCT_LENGTH];
|
||||
int16_t *in_ptr;
|
||||
int16_t *in_ptr_low;
|
||||
int16_t *in_ptr_high;
|
||||
int16_t *next_in_base;
|
||||
int16_t *out_ptr_low;
|
||||
int16_t *out_ptr_high;
|
||||
int16_t *next_out_base;
|
||||
int16_t *out_buffer;
|
||||
int16_t *out_ptr;
|
||||
int16_t *in_buffer;
|
||||
int16_t *out_buffer;
|
||||
int16_t *buffer_swap;
|
||||
int16_t in_val_low;
|
||||
int16_t in_val_high;
|
||||
int16_t out_val_low;
|
||||
int16_t out_val_high;
|
||||
int16_t in_low_even;
|
||||
int16_t in_low_odd;
|
||||
int16_t in_high_even;
|
||||
int16_t in_high_odd;
|
||||
int16_t out_low_even;
|
||||
int16_t out_low_odd;
|
||||
int16_t out_high_even;
|
||||
int16_t out_high_odd;
|
||||
int16_t *pair_ptr;
|
||||
int16_t cos_even;
|
||||
int16_t cos_odd;
|
||||
int16_t msin_even;
|
||||
int16_t msin_odd;
|
||||
int16_t neg_cos_odd;
|
||||
int16_t neg_msin_even;
|
||||
int32_t sum;
|
||||
int16_t set_span;
|
||||
int16_t half_span;
|
||||
int16_t set_count;
|
||||
int16_t set_count_log;
|
||||
int16_t pairs_left;
|
||||
@ -99,15 +73,15 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length)
|
||||
int16_t i;
|
||||
int16_t k;
|
||||
int16_t index;
|
||||
const cos_msin_t **table_ptr_ptr;
|
||||
const cos_msin_t *cos_msin_ptr;
|
||||
int16_t temp;
|
||||
int32_t acca;
|
||||
int16_t dct_length_log;
|
||||
const cos_msin_t **table_ptr_ptr;
|
||||
const cos_msin_t *cos_msin_ptr;
|
||||
|
||||
/* Do the sum/difference butterflies, the first part of */
|
||||
/* converting one N-point transform into N/2 two-point */
|
||||
/* transforms, where N = 1 << DCT_LENGTH_LOG. = 64/128 */
|
||||
/* Do the sum/difference butterflies, the first part of
|
||||
converting one N-point transform into N/2 two-point
|
||||
transforms, where N = 1 << DCT_LENGTH_LOG. = 64/128 */
|
||||
if (dct_length == DCT_LENGTH)
|
||||
{
|
||||
dct_length_log = DCT_LENGTH_LOG;
|
||||
@ -123,62 +97,45 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length)
|
||||
index = 0L;
|
||||
in_buffer = input;
|
||||
out_buffer = buffer_a;
|
||||
temp = sub(dct_length_log, 2);
|
||||
temp = dct_length_log - 2;
|
||||
for (set_count_log = 0; set_count_log <= temp; set_count_log++)
|
||||
{
|
||||
/* Initialization for the loop over sets at the current size */
|
||||
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
|
||||
set_span = shr(dct_length, set_count_log);
|
||||
|
||||
set_count = shl(1, set_count_log);
|
||||
/* Loop over all the sets at the current size */
|
||||
set_span = dct_length >> set_count_log;
|
||||
set_count = 1 << set_count_log;
|
||||
half_span = set_span >> 1;
|
||||
in_ptr = in_buffer;
|
||||
next_out_base = out_buffer;
|
||||
out_ptr = out_buffer;
|
||||
|
||||
/* Loop over all the sets of this size */
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up output pointers for the current set */
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base = next_out_base + set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
|
||||
/* Loop over all the butterflies in the current set */
|
||||
do
|
||||
for (i = 0; i < half_span; i++)
|
||||
{
|
||||
in_val_low = *in_ptr++;
|
||||
in_val_high = *in_ptr++;
|
||||
acca = L_add(in_val_low, in_val_high);
|
||||
acca = L_shr(acca, 1);
|
||||
out_val_low = (int16_t) acca;
|
||||
in_val_low = *in_ptr++;
|
||||
in_val_high = *in_ptr++;
|
||||
|
||||
acca = L_sub(in_val_low, in_val_high);
|
||||
acca = L_shr(acca, 1);
|
||||
out_val_high = (int16_t) acca;
|
||||
acca = L_add(in_val_low, in_val_high);
|
||||
out_ptr[i] = (int16_t) L_shr(acca, 1);
|
||||
|
||||
*out_ptr_low++ = out_val_low;
|
||||
*--out_ptr_high = out_val_high;
|
||||
acca = L_sub(in_val_low, in_val_high);
|
||||
out_ptr[set_span - 1 - i] = (int16_t) L_shr(acca, 1);
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
out_ptr += set_span;
|
||||
}
|
||||
|
||||
/* Decide which buffers to use as input and output next time. */
|
||||
/* Except for the first time (when the input buffer is the */
|
||||
/* subroutine input) we just alternate the local buffers. */
|
||||
/* Decide which buffers to use as input and output next time.
|
||||
Except for the first time (when the input buffer is the
|
||||
subroutine input) we just alternate the local buffers. */
|
||||
in_buffer = out_buffer;
|
||||
if (out_buffer == buffer_a)
|
||||
out_buffer = buffer_b;
|
||||
else
|
||||
out_buffer = buffer_a;
|
||||
out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a;
|
||||
index = add(index, 1);
|
||||
}
|
||||
|
||||
/* Do N/2 two-point transforms, */
|
||||
/* where N = 1 << DCT_LENGTH_LOG */
|
||||
/* Do N/2 two-point transforms, where N = 1 << DCT_LENGTH_LOG */
|
||||
pair_ptr = in_buffer;
|
||||
buffer_swap = buffer_c;
|
||||
temp = sub(dct_length_log, 1);
|
||||
temp = shl(1, temp);
|
||||
|
||||
temp = 1 << (dct_length_log - 1);
|
||||
for (pairs_left = temp; pairs_left > 0; pairs_left--)
|
||||
{
|
||||
for (k = 0; k < CORE_SIZE; k++)
|
||||
@ -188,7 +145,6 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length)
|
||||
sum = L_mac(sum, pair_ptr[i], dct_core_a[i][k]);
|
||||
buffer_swap[k] = xround(sum);
|
||||
}
|
||||
/* Address arithmetic */
|
||||
pair_ptr += CORE_SIZE;
|
||||
buffer_swap += CORE_SIZE;
|
||||
}
|
||||
@ -202,77 +158,53 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length)
|
||||
temp = sub(dct_length_log, 2);
|
||||
for (set_count_log = temp; set_count_log >= 0; set_count_log--)
|
||||
{
|
||||
/* Initialization for the loop over sets at the current size */
|
||||
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
|
||||
set_span = shr(dct_length, set_count_log);
|
||||
set_count = shl(1, set_count_log);
|
||||
next_in_base = in_buffer;
|
||||
next_out_base = (set_count_log == 0) ? output : out_buffer;
|
||||
/* Loop over all the sets at the current size */
|
||||
set_span = dct_length >> set_count_log;
|
||||
set_count = 1 << set_count_log;
|
||||
half_span = set_span >> 1;
|
||||
in_ptr = in_buffer;
|
||||
out_ptr = (set_count_log == 0) ? output : out_buffer;
|
||||
cos_msin_ptr = *table_ptr_ptr++;
|
||||
|
||||
/* Loop over all the sets of this size */
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up the pointers for the current set */
|
||||
in_ptr_low = next_in_base;
|
||||
temp = shr(set_span, 1);
|
||||
|
||||
/* Address arithmetic */
|
||||
in_ptr_high = in_ptr_low + temp;
|
||||
next_in_base += set_span;
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
cos_msin_ptr = *table_ptr_ptr;
|
||||
|
||||
/* Loop over all the butterfly pairs in the current set */
|
||||
do
|
||||
for (i = 0; i < half_span; i += 2)
|
||||
{
|
||||
/* Address arithmetic */
|
||||
in_low_even = *in_ptr_low++;
|
||||
in_low_odd = *in_ptr_low++;
|
||||
in_high_even = *in_ptr_high++;
|
||||
in_high_odd = *in_ptr_high++;
|
||||
cos_even = cos_msin_ptr[0].cosine;
|
||||
msin_even = cos_msin_ptr[0].minus_sine;
|
||||
cos_odd = cos_msin_ptr[1].cosine;
|
||||
msin_odd = cos_msin_ptr[1].minus_sine;
|
||||
cos_msin_ptr += 2;
|
||||
in_low_even = in_ptr[i];
|
||||
in_low_odd = in_ptr[i + 1];
|
||||
in_high_even = in_ptr[half_span + i];
|
||||
in_high_odd = in_ptr[half_span + i + 1];
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, cos_even, in_low_even);
|
||||
neg_msin_even = negate(msin_even);
|
||||
sum = L_mac(sum, neg_msin_even, in_high_even);
|
||||
out_low_even = xround(sum);
|
||||
cos_even = cos_msin_ptr[i].cosine;
|
||||
msin_even = cos_msin_ptr[i].minus_sine;
|
||||
cos_odd = cos_msin_ptr[i + 1].cosine;
|
||||
msin_odd = cos_msin_ptr[i + 1].minus_sine;
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, msin_even,in_low_even);
|
||||
sum = L_mult(cos_even, in_low_even);
|
||||
sum = L_mac(sum, -msin_even, in_high_even);
|
||||
out_ptr[i] = xround(sum);
|
||||
|
||||
sum = L_mult(msin_even,in_low_even);
|
||||
sum = L_mac(sum, cos_even, in_high_even);
|
||||
out_high_even = xround(sum);
|
||||
out_ptr[set_span - 1 - i] = xround(sum);
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, cos_odd, in_low_odd);
|
||||
sum = L_mult(cos_odd, in_low_odd);
|
||||
sum = L_mac(sum, msin_odd, in_high_odd);
|
||||
out_low_odd = xround(sum);
|
||||
out_ptr[i + 1] = xround(sum);
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, msin_odd, in_low_odd);
|
||||
neg_cos_odd = negate(cos_odd);
|
||||
sum = L_mac(sum, neg_cos_odd, in_high_odd);
|
||||
out_high_odd = xround(sum);
|
||||
|
||||
*out_ptr_low++ = out_low_even;
|
||||
*--out_ptr_high = out_high_even;
|
||||
*out_ptr_low++ = out_low_odd;
|
||||
*--out_ptr_high = out_high_odd;
|
||||
sum = L_mult(msin_odd, in_low_odd);
|
||||
sum = L_mac(sum, -cos_odd, in_high_odd);
|
||||
out_ptr[set_span - 2 - i] = xround(sum);
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
in_ptr += set_span;
|
||||
out_ptr += set_span;
|
||||
}
|
||||
|
||||
/* Swap input and output buffers for next time */
|
||||
buffer_swap = in_buffer;
|
||||
in_buffer = out_buffer;
|
||||
out_buffer = buffer_swap;
|
||||
table_ptr_ptr++;
|
||||
}
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: dct4_a.h,v 1.4 2008/09/25 15:56:31 steveu Exp $
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
|
@ -6,29 +6,23 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: dct4_s.c,v 1.8 2008/09/30 14:06:39 steveu Exp $
|
||||
*/
|
||||
|
||||
/********************************************************************************
|
||||
* Filename: dct_type_iv_s.c
|
||||
*
|
||||
* Purpose: Discrete Cosine Transform, Type IV used for inverse MLT
|
||||
*
|
||||
* The basis functions are
|
||||
*
|
||||
* cos(PI*(t+0.5)*(k+0.5)/block_length)
|
||||
*
|
||||
* for time t and basis function number k. Due to the symmetry of the expression
|
||||
* in t and k, it is clear that the forward and inverse transforms are the same.
|
||||
*
|
||||
*********************************************************************************/
|
||||
/* Discrete Cosine Transform, Type IV used for inverse MLT
|
||||
|
||||
The basis functions are
|
||||
|
||||
cos(PI*(t+0.5)*(k+0.5)/block_length)
|
||||
|
||||
for time t and basis function number k. Due to the symmetry of the
|
||||
expression in t and k, it is clear that the forward and inverse transforms
|
||||
are the same. */
|
||||
|
||||
/*! \file */
|
||||
|
||||
@ -45,67 +39,51 @@
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
#include "dct4_s.h"
|
||||
#include "utilities.h"
|
||||
|
||||
/********************************************************************************
|
||||
Function: dct_type_iv_s
|
||||
|
||||
Syntax: void dct_type_iv_s (int16_t *input,int16_t *output,int16_t dct_length)
|
||||
|
||||
|
||||
Description: Discrete Cosine Transform, Type IV used for inverse MLT
|
||||
********************************************************************************/
|
||||
/* Discrete Cosine Transform, Type IV used for inverse MLT */
|
||||
void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length)
|
||||
{
|
||||
int16_t buffer_a[MAX_DCT_LENGTH];
|
||||
int16_t buffer_b[MAX_DCT_LENGTH];
|
||||
int16_t buffer_c[MAX_DCT_LENGTH];
|
||||
int16_t *in_ptr;
|
||||
int16_t *in_ptr_low;
|
||||
int16_t *in_ptr_high;
|
||||
int16_t *next_in_base;
|
||||
int16_t *out_ptr_low;
|
||||
int16_t *out_ptr_high;
|
||||
int16_t *next_out_base;
|
||||
int16_t *out_buffer;
|
||||
int16_t *out_ptr;
|
||||
int16_t *in_buffer;
|
||||
int16_t *out_buffer;
|
||||
int16_t *buffer_swap;
|
||||
int16_t in_val_low;
|
||||
int16_t in_val_high;
|
||||
int16_t out_val_low;
|
||||
int16_t out_val_high;
|
||||
int16_t in_low_even;
|
||||
int16_t in_low_odd;
|
||||
int16_t in_high_even;
|
||||
int16_t in_high_odd;
|
||||
int16_t out_low_even;
|
||||
int16_t out_low_odd;
|
||||
int16_t out_high_even;
|
||||
int16_t out_high_odd;
|
||||
int16_t *pair_ptr;
|
||||
int16_t cos_even;
|
||||
int16_t cos_odd;
|
||||
int16_t msin_even;
|
||||
int16_t msin_odd;
|
||||
int16_t set_span;
|
||||
int16_t half_span;
|
||||
int16_t set_count;
|
||||
int16_t set_count_log;
|
||||
int16_t pairs_left;
|
||||
int16_t sets_left;
|
||||
int16_t i;
|
||||
int16_t j;
|
||||
int16_t k;
|
||||
int16_t index;
|
||||
int16_t dummy;
|
||||
int16_t dct_length_log;
|
||||
int32_t sum;
|
||||
int32_t acca;
|
||||
const cos_msin_t **table_ptr_ptr;
|
||||
const cos_msin_t *cos_msin_ptr;
|
||||
int32_t acca;
|
||||
int16_t temp;
|
||||
int16_t dct_length_log;
|
||||
const int16_t *dither_ptr;
|
||||
|
||||
/* Do the sum/difference butterflies, the first part of */
|
||||
/* converting one N-point transform into 32 - 10 point transforms */
|
||||
/* transforms, where N = 1 << DCT_LENGTH_LOG. */
|
||||
/* Do the sum/difference butterflies, the first part of
|
||||
converting one N-point transform into 32 - 10 point transforms
|
||||
transforms, where N = 1 << DCT_LENGTH_LOG. */
|
||||
if (dct_length == DCT_LENGTH)
|
||||
{
|
||||
dct_length_log = DCT_LENGTH_LOG;
|
||||
@ -122,92 +100,61 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length)
|
||||
|
||||
index = 0;
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
||||
for (set_count_log = 0; set_count_log <= dct_length_log - 2; set_count_log++)
|
||||
{
|
||||
/* Initialization for the loop over sets at the current size */
|
||||
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
|
||||
set_span = shr(dct_length, set_count_log);
|
||||
|
||||
set_count = shl(1, set_count_log);
|
||||
/* Loop over all the sets at the current size */
|
||||
set_span = dct_length >> set_count_log;
|
||||
set_count = 1 << set_count_log;
|
||||
half_span = set_span >> 1;
|
||||
in_ptr = in_buffer;
|
||||
next_out_base = out_buffer;
|
||||
out_ptr = out_buffer;
|
||||
|
||||
/* Loop over all the sets of this size */
|
||||
temp = sub(index, 1);
|
||||
if (temp < 0)
|
||||
if (index < 1)
|
||||
{
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up output pointers for the current set */
|
||||
/* pointer arithmetic */
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
|
||||
/* Loop over all the butterflies in the current set */
|
||||
do
|
||||
for (i = 0; i < half_span; i++)
|
||||
{
|
||||
in_val_low = *in_ptr++;
|
||||
in_val_high = *in_ptr++;
|
||||
|
||||
/* BEST METHOD OF GETTING RID OF BIAS, BUT COMPUTATIONALLY UNPLEASANT */
|
||||
/* ALTERNATIVE METHOD, SMEARS BIAS OVER THE ENTIRE FRAME, COMPUTATIONALLY SIMPLEST. */
|
||||
/* IF THIS WORKS, IT'S PREFERABLE */
|
||||
|
||||
dummy = add(in_val_low, dither_ptr[i++]);
|
||||
dummy = add(in_val_low, dither_ptr[j++]);
|
||||
acca = L_add(dummy, in_val_high);
|
||||
out_val_low = (int16_t) L_shr(acca, 1);
|
||||
out_ptr[i] = (int16_t) L_shr(acca, 1);
|
||||
|
||||
dummy = add(in_val_low, dither_ptr[i++]);
|
||||
acca = L_add(dummy, -in_val_high);
|
||||
out_val_high = (int16_t) L_shr(acca, 1);
|
||||
|
||||
*out_ptr_low++ = out_val_low;
|
||||
*--out_ptr_high = out_val_high;
|
||||
|
||||
/* this involves comparison of pointers */
|
||||
/* pointer arithmetic */
|
||||
dummy = add(in_val_low, dither_ptr[j++]);
|
||||
acca = L_sub(dummy, in_val_high);
|
||||
out_ptr[set_span - 1 - i] = (int16_t) L_shr(acca, 1);
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
out_ptr += set_span;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up output pointers for the current set */
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
|
||||
/* Loop over all the butterflies in the current set */
|
||||
do
|
||||
for (i = 0; i < half_span; i++)
|
||||
{
|
||||
in_val_low = *in_ptr++;
|
||||
in_val_high = *in_ptr++;
|
||||
|
||||
out_val_low = add(in_val_low, in_val_high);
|
||||
out_val_high = add(in_val_low, negate(in_val_high));
|
||||
|
||||
*out_ptr_low++ = out_val_low;
|
||||
*--out_ptr_high = out_val_high;
|
||||
out_ptr[i] = add(in_val_low, in_val_high);
|
||||
out_ptr[set_span - 1 - i] = sub(in_val_low, in_val_high);
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
out_ptr += set_span;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decide which buffers to use as input and output next time. */
|
||||
/* Except for the first time (when the input buffer is the */
|
||||
/* subroutine input) we just alternate the local buffers. */
|
||||
/* Decide which buffers to use as input and output next time.
|
||||
Except for the first time (when the input buffer is the
|
||||
subroutine input) we just alternate the local buffers. */
|
||||
in_buffer = out_buffer;
|
||||
|
||||
if (out_buffer == buffer_a)
|
||||
out_buffer = buffer_b;
|
||||
else
|
||||
out_buffer = buffer_a;
|
||||
|
||||
index = add(index, 1);
|
||||
out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a;
|
||||
index++;
|
||||
}
|
||||
|
||||
/* Do 32 - 10 point transforms */
|
||||
@ -228,8 +175,7 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length)
|
||||
buffer_swap += CORE_SIZE;
|
||||
}
|
||||
|
||||
for (i = 0; i < dct_length; i++)
|
||||
in_buffer[i] = buffer_c[i];
|
||||
vec_copyi16(in_buffer, buffer_c, dct_length);
|
||||
|
||||
table_ptr_ptr = s_cos_msin_table;
|
||||
|
||||
@ -238,90 +184,61 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length)
|
||||
for (set_count_log = dct_length_log - 2; set_count_log >= 0; set_count_log--)
|
||||
{
|
||||
/* Initialization for the loop over sets at the current size */
|
||||
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
|
||||
set_span = shr(dct_length, set_count_log);
|
||||
|
||||
set_count = shl(1, set_count_log);
|
||||
next_in_base = in_buffer;
|
||||
if (set_count_log == 0)
|
||||
next_out_base = output;
|
||||
else
|
||||
next_out_base = out_buffer;
|
||||
set_span = dct_length >> set_count_log;
|
||||
set_count = 1 << set_count_log;
|
||||
half_span = set_span >> 1;
|
||||
in_ptr = in_buffer;
|
||||
out_ptr = (set_count_log == 0) ? output : out_buffer;
|
||||
cos_msin_ptr = *table_ptr_ptr++;
|
||||
|
||||
/* Loop over all the sets of this size */
|
||||
for (sets_left = set_count; sets_left > 0; sets_left--)
|
||||
{
|
||||
/* Set up the pointers for the current set */
|
||||
in_ptr_low = next_in_base;
|
||||
temp = shr(set_span, 1);
|
||||
in_ptr_high = in_ptr_low + temp;
|
||||
next_in_base += set_span;
|
||||
out_ptr_low = next_out_base;
|
||||
next_out_base += set_span;
|
||||
out_ptr_high = next_out_base;
|
||||
cos_msin_ptr = *table_ptr_ptr;
|
||||
|
||||
/* Loop over all the butterfly pairs in the current set */
|
||||
do
|
||||
for (i = 0; i < half_span; i += 2)
|
||||
{
|
||||
in_low_even = *in_ptr_low++;
|
||||
in_low_odd = *in_ptr_low++;
|
||||
in_high_even = *in_ptr_high++;
|
||||
in_high_odd = *in_ptr_high++;
|
||||
cos_even = cos_msin_ptr[0].cosine;
|
||||
msin_even = cos_msin_ptr[0].minus_sine;
|
||||
cos_odd = cos_msin_ptr[1].cosine;
|
||||
msin_odd = cos_msin_ptr[1].minus_sine;
|
||||
cos_msin_ptr += 2;
|
||||
in_low_even = in_ptr[i];
|
||||
in_low_odd = in_ptr[i + 1];
|
||||
in_high_even = in_ptr[half_span + i];
|
||||
in_high_odd = in_ptr[half_span + i + 1];
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, cos_even, in_low_even);
|
||||
sum = L_mac(sum, negate(msin_even), in_high_even);
|
||||
out_low_even = xround(L_shl(sum, 1));
|
||||
cos_even = cos_msin_ptr[i].cosine;
|
||||
msin_even = cos_msin_ptr[i].minus_sine;
|
||||
cos_odd = cos_msin_ptr[i + 1].cosine;
|
||||
msin_odd = cos_msin_ptr[i + 1].minus_sine;
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, msin_even, in_low_even);
|
||||
sum = L_mult(cos_even, in_low_even);
|
||||
sum = L_mac(sum, -msin_even, in_high_even);
|
||||
out_ptr[i] = xround(L_shl(sum, 1));
|
||||
|
||||
sum = L_mult(msin_even, in_low_even);
|
||||
sum = L_mac(sum, cos_even, in_high_even);
|
||||
out_high_even = xround(L_shl(sum, 1));
|
||||
out_ptr[set_span - 1 - i] = xround(L_shl(sum, 1));
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, cos_odd, in_low_odd);
|
||||
sum = L_mult(cos_odd, in_low_odd);
|
||||
sum = L_mac(sum, msin_odd, in_high_odd);
|
||||
out_low_odd = xround(L_shl(sum, 1));
|
||||
out_ptr[i + 1] = xround(L_shl(sum, 1));
|
||||
|
||||
sum = 0L;
|
||||
sum = L_mac(sum, msin_odd, in_low_odd);
|
||||
sum = L_mac(sum, negate(cos_odd), in_high_odd);
|
||||
out_high_odd = xround(L_shl(sum, 1));
|
||||
|
||||
*out_ptr_low++ = out_low_even;
|
||||
*--out_ptr_high = out_high_even;
|
||||
*out_ptr_low++ = out_low_odd;
|
||||
*--out_ptr_high = out_high_odd;
|
||||
sum = L_mult(msin_odd, in_low_odd);
|
||||
sum = L_mac(sum, -cos_odd, in_high_odd);
|
||||
out_ptr[set_span - 2 - i] = xround(L_shl(sum, 1));
|
||||
}
|
||||
while (out_ptr_low < out_ptr_high);
|
||||
in_ptr += set_span;
|
||||
out_ptr += set_span;
|
||||
}
|
||||
/* Swap input and output buffers for next time */
|
||||
buffer_swap = in_buffer;
|
||||
in_buffer = out_buffer;
|
||||
out_buffer = buffer_swap;
|
||||
|
||||
index = add(index, 1);
|
||||
table_ptr_ptr++;
|
||||
index++;
|
||||
}
|
||||
/* ADD IN BIAS FOR OUTPUT */
|
||||
/* Add in bias for output */
|
||||
if (dct_length == DCT_LENGTH)
|
||||
{
|
||||
for (i = 0; i < 320; i++)
|
||||
for (i = 0; i < DCT_LENGTH; i++)
|
||||
{
|
||||
sum = L_add(output[i], syn_bias_7khz[i]);
|
||||
acca = L_sub(sum, 32767);
|
||||
if (acca > 0)
|
||||
sum = 32767L;
|
||||
acca = L_add(sum, 32768L);
|
||||
if (acca < 0)
|
||||
sum = -32768L;
|
||||
output[i] = (int16_t) sum;
|
||||
output[i] = saturate(sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: dct4_s.h,v 1.4 2008/09/25 15:56:31 steveu Exp $
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
@ -196,11 +194,9 @@ static const int16_t max_dither[MAX_DCT_LENGTH] =
|
||||
for (index = 0;index < length;index++)
|
||||
{
|
||||
angle = scale * ((double)index + 0.5);
|
||||
table[index].cosine = (short) (FTOI((18427)* cos(angle)));
|
||||
table[index].minus_sine = (short) (FTOI((18427)*(-sin(angle))));
|
||||
table[index].cosine = (int16_t) (FTOI((18427)* cos(angle)));
|
||||
table[index].minus_sine = (int16_t) (FTOI((18427)*(-sin(angle))));
|
||||
}
|
||||
|
||||
|
||||
********************************************************************************/
|
||||
|
||||
static const cos_msin_t s_cos_msin_2[DCT_LENGTH_DIV_32] =
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C)2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: decoder.c,v 1.21 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -94,9 +92,7 @@ static void decoder(g722_1_decode_state_t *s,
|
||||
int16_t old_decoder_mlt_coefs[],
|
||||
int frame_error_flag);
|
||||
|
||||
/***************************************************************************
|
||||
Description: Decodes the out_words into mlt coefs using G.722.1 Annex C
|
||||
***************************************************************************/
|
||||
/* Decodes the out_words into MLT coefs using G.722.1 Annex C */
|
||||
void decoder(g722_1_decode_state_t *s,
|
||||
int16_t number_of_regions,
|
||||
int16_t decoder_mlt_coefs[],
|
||||
@ -109,11 +105,11 @@ void decoder(g722_1_decode_state_t *s,
|
||||
int16_t absolute_region_power_index[MAX_NUMBER_OF_REGIONS];
|
||||
int16_t decoder_power_categories[MAX_NUMBER_OF_REGIONS];
|
||||
int16_t decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES - 1];
|
||||
uint16_t categorization_control;
|
||||
int16_t num_categorization_control_bits;
|
||||
int16_t num_categorization_control_possibilities;
|
||||
int16_t number_of_coefs;
|
||||
int16_t number_of_valid_coefs;
|
||||
uint16_t categorization_control;
|
||||
|
||||
number_of_valid_coefs = number_of_regions*REGION_SIZE;
|
||||
|
||||
@ -184,9 +180,7 @@ void decoder(g722_1_decode_state_t *s,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
/***************************************************************************
|
||||
Description: Recover differential_region_power_index from code bits
|
||||
***************************************************************************/
|
||||
/* Recover differential_region_power_index from code bits */
|
||||
static void decode_envelope(g722_1_decode_state_t *s,
|
||||
int16_t number_of_regions,
|
||||
int16_t *decoder_region_standard_deviation,
|
||||
@ -262,7 +256,7 @@ static void decode_envelope(g722_1_decode_state_t *s,
|
||||
while ((i >= 0) && ((temp1 >= 0) || (temp2 > 0)))
|
||||
{
|
||||
i = sub(i, 1);
|
||||
temp = shr(temp, 1);
|
||||
temp >>= 1;
|
||||
max_index = sub(max_index, 2);
|
||||
temp1 = sub(temp, 8);
|
||||
temp2 = sub(max_index, 28);
|
||||
@ -365,12 +359,12 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s,
|
||||
if (g722_1_bitstream_get(&s->bitstream, &(s->code_ptr), 1) == 0)
|
||||
{
|
||||
temp = shl(index, 1);
|
||||
index = (int16_t) *(decoder_table_ptr + temp);
|
||||
index = decoder_table_ptr[temp];
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = shl(index, 1);
|
||||
index = (int16_t) *(decoder_table_ptr + temp + 1);
|
||||
index = decoder_table_ptr[temp + 1];
|
||||
}
|
||||
s->number_of_bits_left--;
|
||||
}
|
||||
@ -406,7 +400,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s,
|
||||
{
|
||||
if ((signs_index & bit) == 0)
|
||||
decoder_mlt_value = negate(decoder_mlt_value);
|
||||
bit = shr(bit, 1);
|
||||
bit >>= 1;
|
||||
}
|
||||
*decoder_mlt_ptr++ = decoder_mlt_value;
|
||||
}
|
||||
@ -440,7 +434,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s,
|
||||
if (*decoder_mlt_ptr == 0)
|
||||
{
|
||||
*decoder_mlt_ptr = ((random_word & 1) == 0) ? noifillneg : noifillpos;
|
||||
random_word = shr(random_word, 1);
|
||||
random_word >>= 1;
|
||||
}
|
||||
/* pointer arithmetic */
|
||||
decoder_mlt_ptr++;
|
||||
@ -451,7 +445,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s,
|
||||
if (*decoder_mlt_ptr == 0)
|
||||
{
|
||||
*decoder_mlt_ptr = ((random_word & 1) == 0) ? noifillneg : noifillpos;
|
||||
random_word = shr(random_word,1);
|
||||
random_word >>= 1;
|
||||
}
|
||||
/* pointer arithmetic */
|
||||
decoder_mlt_ptr++;
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: decoderf.c,v 1.22 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -33,6 +31,7 @@
|
||||
#include "huff_tab.h"
|
||||
#include "tables.h"
|
||||
#include "bitstream.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#if !defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
@ -84,12 +83,12 @@ static void decoder(g722_1_decode_state_t *s,
|
||||
int absolute_region_power_index[MAX_NUMBER_OF_REGIONS];
|
||||
int decoder_power_categories[MAX_NUMBER_OF_REGIONS];
|
||||
int decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES - 1];
|
||||
int rate_control;
|
||||
int num_categorization_control_bits;
|
||||
int num_categorization_control_possibilities;
|
||||
int number_of_coefs;
|
||||
int number_of_valid_coefs;
|
||||
int rmlt_scale_factor;
|
||||
int rate_control;
|
||||
|
||||
number_of_valid_coefs = s->number_of_regions*REGION_SIZE;
|
||||
|
||||
@ -451,7 +450,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s,
|
||||
|
||||
if (category == NUM_CATEGORIES - 1)
|
||||
{
|
||||
noifillpos = standard_deviation*0.70711f;
|
||||
noifillpos = standard_deviation*0.70711;
|
||||
noifillneg = -noifillpos;
|
||||
|
||||
/* This assumes region_size = 20 */
|
||||
@ -555,27 +554,21 @@ static void error_handling(int number_of_coefs,
|
||||
float *decoder_mlt_coefs,
|
||||
float *old_decoder_mlt_coefs)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If both the current and previous frames are errored,
|
||||
set the mlt coefficients to 0. If only the current frame
|
||||
is errored, repeat the previous frame's MLT coefficients. */
|
||||
if (*frame_error_flag)
|
||||
{
|
||||
for (i = 0; i < number_of_valid_coefs; i++)
|
||||
decoder_mlt_coefs[i] = old_decoder_mlt_coefs[i];
|
||||
for (i = 0; i < number_of_valid_coefs; i++)
|
||||
old_decoder_mlt_coefs[i] = 0.0f;
|
||||
vec_copyf(decoder_mlt_coefs, old_decoder_mlt_coefs, number_of_valid_coefs);
|
||||
vec_zerof(old_decoder_mlt_coefs, number_of_valid_coefs);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Store in case the next frame has errors. */
|
||||
for (i = 0; i < number_of_valid_coefs; i++)
|
||||
old_decoder_mlt_coefs[i] = decoder_mlt_coefs[i];
|
||||
vec_copyf(old_decoder_mlt_coefs, decoder_mlt_coefs, number_of_valid_coefs);
|
||||
}
|
||||
/* Zero out the upper 1/8 of the spectrum. */
|
||||
for (i = number_of_valid_coefs; i < number_of_coefs; i++)
|
||||
decoder_mlt_coefs[i] = 0.0f;
|
||||
vec_zerof(&decoder_mlt_coefs[number_of_valid_coefs], number_of_coefs - number_of_valid_coefs);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: defs.h,v 1.16 2008/10/01 15:31:10 steveu Exp $
|
||||
*/
|
||||
|
||||
#define MAX(a,b) (a > b ? a : b)
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: encoder.c,v 1.26 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -32,6 +30,7 @@
|
||||
#include "huff_tab.h"
|
||||
#include "tables.h"
|
||||
#include "bitstream.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
@ -99,9 +98,8 @@ static void bits_to_words(g722_1_encode_state_t *s,
|
||||
drp_num_bits[number_of_regions] = num_categorization_control_bits;
|
||||
drp_code_bits[number_of_regions] = categorization_control;
|
||||
|
||||
bit_count = 0;
|
||||
/* These code bits are right justified. */
|
||||
for (region = 0; region <= number_of_regions; region++)
|
||||
for (bit_count = 0, region = 0; region <= number_of_regions; region++)
|
||||
{
|
||||
g722_1_bitstream_put(&s->bitstream, &out_code, drp_code_bits[region], drp_num_bits[region]);
|
||||
bit_count += drp_num_bits[region];
|
||||
@ -247,14 +245,11 @@ void adjust_abs_region_power_index(int16_t *absolute_region_power_index,
|
||||
|
||||
for (region = 0; region < number_of_regions; region++)
|
||||
{
|
||||
n = sub(absolute_region_power_index[region], 39);
|
||||
n = shr(n, 1);
|
||||
n = sub(absolute_region_power_index[region], 39) >> 1;
|
||||
if (n > 0)
|
||||
{
|
||||
temp = (int16_t) L_mult0(region, REGION_SIZE);
|
||||
|
||||
raw_mlt_ptr = &mlt_coefs[temp];
|
||||
|
||||
for (i = 0; i < REGION_SIZE; i++)
|
||||
{
|
||||
acca = L_shl(*raw_mlt_ptr, 16);
|
||||
@ -264,8 +259,7 @@ void adjust_abs_region_power_index(int16_t *absolute_region_power_index,
|
||||
*raw_mlt_ptr++ = (int16_t) acca;
|
||||
}
|
||||
|
||||
temp = sub(absolute_region_power_index[region], shl(n, 1));
|
||||
absolute_region_power_index[region] = temp;
|
||||
absolute_region_power_index[region] = sub(absolute_region_power_index[region], shl(n, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,7 +275,6 @@ static int16_t compute_region_powers(int16_t *mlt_coefs,
|
||||
{
|
||||
int16_t *input_ptr;
|
||||
int32_t long_accumulator;
|
||||
int16_t itemp1;
|
||||
int16_t power_shift;
|
||||
int16_t region;
|
||||
int16_t j;
|
||||
@ -295,12 +288,8 @@ static int16_t compute_region_powers(int16_t *mlt_coefs,
|
||||
input_ptr = mlt_coefs;
|
||||
for (region = 0; region < number_of_regions; region++)
|
||||
{
|
||||
long_accumulator = 0;
|
||||
for (j = 0; j < REGION_SIZE; j++)
|
||||
{
|
||||
itemp1 = *input_ptr++;
|
||||
long_accumulator = L_mac0(long_accumulator, itemp1, itemp1);
|
||||
}
|
||||
long_accumulator = vec_dot_prodi16(input_ptr, input_ptr, REGION_SIZE);
|
||||
input_ptr += REGION_SIZE;
|
||||
|
||||
power_shift = 0;
|
||||
acca = long_accumulator & 0x7FFF0000L;
|
||||
@ -348,7 +337,7 @@ static int16_t compute_region_powers(int16_t *mlt_coefs,
|
||||
}
|
||||
|
||||
/* The MLT is currently scaled too low by the factor
|
||||
ENCODER_SCALE_FACTOR(=18318)/32768 * (1./sqrt(160).
|
||||
ENCODER_SCALE_FACTOR(=18318)/32768 * (1.0/sqrt(160).
|
||||
This is the ninth power of 1 over the square root of 2.
|
||||
So later we will add ESF_ADJUSTMENT_TO_RMS_INDEX (now 9)
|
||||
to drp_code_bits[0]. */
|
||||
@ -520,7 +509,8 @@ static int16_t vector_huffman(int16_t category,
|
||||
int16_t num_vecs;
|
||||
int16_t kmax;
|
||||
int16_t kmax_plus_one;
|
||||
int16_t index,signs_index;
|
||||
int16_t index;
|
||||
int16_t signs_index;
|
||||
const int16_t *bitcount_table_ptr;
|
||||
const uint16_t *code_table_ptr;
|
||||
int32_t code_bits;
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: encoderf.c,v 1.22 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -33,6 +31,7 @@
|
||||
#include "huff_tab.h"
|
||||
#include "tables.h"
|
||||
#include "bitstream.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#if !defined(G722_1_USE_FIXED_POINT)
|
||||
|
||||
@ -218,7 +217,6 @@ static int compute_region_powers(int number_of_regions,
|
||||
float *input_ptr;
|
||||
int iterations;
|
||||
float ftemp0;
|
||||
float ftemp1;
|
||||
int index;
|
||||
int index_min;
|
||||
int index_max;
|
||||
@ -230,13 +228,9 @@ static int compute_region_powers(int number_of_regions,
|
||||
input_ptr = mlt_coefs;
|
||||
for (region = 0; region < number_of_regions; region++)
|
||||
{
|
||||
ftemp0 = 0.0f;
|
||||
for (j = 0; j < REGION_SIZE; j++)
|
||||
{
|
||||
ftemp1 = *input_ptr++;
|
||||
ftemp0 += ftemp1*ftemp1;
|
||||
}
|
||||
ftemp0 = vec_dot_prodf(input_ptr, input_ptr, REGION_SIZE);
|
||||
ftemp0 *= REGION_SIZE_INVERSE;
|
||||
input_ptr += REGION_SIZE;
|
||||
|
||||
index_min = 0;
|
||||
index_max = REGION_POWER_TABLE_SIZE;
|
||||
@ -260,7 +254,7 @@ static int compute_region_powers(int number_of_regions,
|
||||
}
|
||||
|
||||
/* The MLT is currently scaled too low by the factor
|
||||
ENCODER_SCALE_FACTOR(=18318)/32768 * (1./sqrt(160).
|
||||
ENCODER_SCALE_FACTOR(=18318)/32768 * (1.0/sqrt(160).
|
||||
This is the ninth power of 1 over the square root of 2.
|
||||
So later we will add ESF_ADJUSTMENT_TO_RMS_INDEX (now 9)
|
||||
to drp_code_bits[0]. */
|
||||
@ -448,7 +442,7 @@ static int vector_huffman(int category,
|
||||
number_of_non_zero = 0;
|
||||
for (j = 0; j < vec_dim; j++)
|
||||
{
|
||||
k = (int) (fabs(*raw_mlt_ptr) * inv_of_step_size_times_std_dev + dead_zone[category]);
|
||||
k = (int) (fabs(*raw_mlt_ptr)*inv_of_step_size_times_std_dev + dead_zone[category]);
|
||||
if (k != 0)
|
||||
{
|
||||
number_of_non_zero++;
|
||||
@ -458,12 +452,12 @@ static int vector_huffman(int category,
|
||||
if (k > kmax)
|
||||
k = kmax;
|
||||
}
|
||||
index = index*(kmax_plus_one) + k;
|
||||
index = index*kmax_plus_one + k;
|
||||
raw_mlt_ptr++;
|
||||
}
|
||||
|
||||
code_bits = *(code_table_ptr + index);
|
||||
number_of_code_bits = *(bitcount_table_ptr + index) + number_of_non_zero;
|
||||
code_bits = code_table_ptr[index];
|
||||
number_of_code_bits = bitcount_table_ptr[index] + number_of_non_zero;
|
||||
number_of_region_bits += number_of_code_bits;
|
||||
|
||||
code_bits = (code_bits << number_of_non_zero) + signs_index;
|
||||
|
@ -7,8 +7,6 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id: g722_1.h.in,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: g722_1.h,v 1.14 2008/10/17 13:18:21 steveu Exp $
|
||||
*/
|
||||
|
||||
#if !defined(_G722_1_G722_1_H_)
|
||||
|
@ -9,8 +9,6 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id: version.h.in,v 1.2 2008/09/20 16:52:51 steveu Exp $
|
||||
*/
|
||||
|
||||
#if !defined(_G722_1_VERSION_H_)
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: huff_tab.c,v 1.7 2008/09/30 14:06:40 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: huff_tab.h,v 1.4 2008/09/30 14:06:40 steveu Exp $
|
||||
*/
|
||||
|
||||
#define REGION_POWER_STEPSIZE_DB 3.010299957
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: make_dct4_tables.c,v 1.2 2008/10/02 11:43:54 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -29,7 +27,11 @@
|
||||
|
||||
#include "g722_1/g722_1.h"
|
||||
|
||||
#if defined(PI)
|
||||
#undef PI
|
||||
#endif
|
||||
#define PI 3.141592653589793238462
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static void set_up_one_table(int length)
|
||||
@ -99,6 +101,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (i = 0; i <= length_log; i++)
|
||||
set_up_one_table(dct_size << i);
|
||||
return 0;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
/*- End of file ------------------------------------------------------------*/
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: make_tables.c,v 1.5 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -37,6 +35,7 @@
|
||||
#undef PI
|
||||
#endif
|
||||
#define PI 3.141592653589793238462
|
||||
|
||||
/* These may have been defined in the main header for the codec, so we clear out
|
||||
any pre-existing definitions here. */
|
||||
#if defined(ENCODER_SCALE_FACTOR)
|
||||
@ -124,7 +123,7 @@ static void generate_sam2coef_tables(void)
|
||||
for (i = 0; i < DCT_LENGTH; i++)
|
||||
{
|
||||
angle = (PI/2.0)*((double) i + 0.5)/(double) DCT_LENGTH;
|
||||
printf(" %.15e,\n", sin(angle));
|
||||
printf(" %.15ef,\n", sin(angle));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -132,7 +131,7 @@ static void generate_sam2coef_tables(void)
|
||||
for (i = 0; i < MAX_DCT_LENGTH; i++)
|
||||
{
|
||||
angle = (PI/2.0)*((double) i + 0.5)/(double) MAX_DCT_LENGTH;
|
||||
printf(" %.15le,\n", sin(angle));
|
||||
printf(" %.15ef,\n", sin(angle));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -180,7 +179,7 @@ static void generate_coef2sam_tables(void)
|
||||
for (i = 0; i < DCT_LENGTH; i++)
|
||||
{
|
||||
angle = (PI/2.0)*((double) i + 0.5)/(double) DCT_LENGTH;
|
||||
printf(" %.15e,\n", sin(angle));
|
||||
printf(" %.15ef,\n", sin(angle));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -188,7 +187,7 @@ static void generate_coef2sam_tables(void)
|
||||
for (i = 0; i < MAX_DCT_LENGTH; i++)
|
||||
{
|
||||
angle = (PI/2.0)*((double) i + 0.5)/(double) MAX_DCT_LENGTH;
|
||||
printf(" %.15e,\n", sin(angle));
|
||||
printf(" %.15ef,\n", sin(angle));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -218,7 +217,7 @@ int main(int argc, char *argv[])
|
||||
for (i = 0; i < REGION_POWER_TABLE_SIZE; i++)
|
||||
{
|
||||
value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES));
|
||||
printf(" %.15e,\n", sqrt(value));
|
||||
printf(" %.15ef,\n", sqrt(value));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -226,7 +225,7 @@ int main(int argc, char *argv[])
|
||||
for (i = 0; i < REGION_POWER_TABLE_SIZE; i++)
|
||||
{
|
||||
value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES));
|
||||
printf(" %.15e,\n", 1.0/sqrt(value));
|
||||
printf(" %.15ef,\n", 1.0/sqrt(value));
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -259,14 +258,14 @@ int main(int argc, char *argv[])
|
||||
printf("const float step_size[NUM_CATEGORIES] =\n{\n");
|
||||
for (i = 0; i < NUM_CATEGORIES; i++)
|
||||
{
|
||||
printf(" %.15e,\n", step_size[i]);
|
||||
printf(" %.15ef,\n", step_size[i]);
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
printf("const float step_size_inverse_table[NUM_CATEGORIES] =\n{\n");
|
||||
for (i = 0; i < NUM_CATEGORIES; i++)
|
||||
{
|
||||
printf(" %.15e,\n", 1.0/step_size[i]);
|
||||
printf(" %.15ef,\n", 1.0/step_size[i]);
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -275,7 +274,7 @@ int main(int argc, char *argv[])
|
||||
for (i = 0; i < REGION_POWER_TABLE_SIZE; i++)
|
||||
{
|
||||
value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES));
|
||||
printf(" %.15e,\n", value);
|
||||
printf(" %.15ef,\n", value);
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
@ -283,9 +282,10 @@ int main(int argc, char *argv[])
|
||||
for (i = 0; i < REGION_POWER_TABLE_SIZE - 1; i++)
|
||||
{
|
||||
value = (float) pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(0.5 + (i - REGION_POWER_TABLE_NUM_NEGATIVES)));
|
||||
printf(" %.15e,\n", value);
|
||||
printf(" %.15ef,\n", value);
|
||||
}
|
||||
printf("};\n\n");
|
||||
return 0;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
/*- End of file ------------------------------------------------------------*/
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sam2coef.c,v 1.12 2008/10/02 11:43:54 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -29,17 +27,16 @@
|
||||
|
||||
#include "defs.h"
|
||||
#include "sam2coef.h"
|
||||
#include "utilities.h"
|
||||
|
||||
/************************************************************************************
|
||||
Purpose: Convert Samples to Reversed MLT (Modulated Lapped Transform) Coefficients
|
||||
/* Convert Samples to Reversed MLT (Modulated Lapped Transform) Coefficients
|
||||
|
||||
The "Reversed MLT" is an overlapped block transform which uses even symmetry
|
||||
on the left, odd symmetry on the right and a Type IV DCT as the block transform.
|
||||
It is thus similar to a MLT which uses odd symmetry on the left, even symmetry
|
||||
on the right and a Type IV DST as the block transform. In fact, it is equivalent
|
||||
to reversing the order of the samples, performing an MLT and then negating all
|
||||
the even-numbered coefficients.
|
||||
***************************************************************************/
|
||||
The "Reversed MLT" is an overlapped block transform which uses even symmetry
|
||||
on the left, odd symmetry on the right and a Type IV DCT as the block transform.
|
||||
It is thus similar to a MLT which uses odd symmetry on the left, even symmetry
|
||||
on the right and a Type IV DST as the block transform. In fact, it is equivalent
|
||||
to reversing the order of the samples, performing an MLT and then negating all
|
||||
the even-numbered coefficients. */
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
int16_t samples_to_rmlt_coefs(const int16_t new_samples[],
|
||||
@ -62,34 +59,26 @@ int16_t samples_to_rmlt_coefs(const int16_t new_samples[],
|
||||
|
||||
half_dct_length = dct_length >> 1;
|
||||
|
||||
if (dct_length == DCT_LENGTH)
|
||||
win = samples_to_rmlt_window;
|
||||
else
|
||||
win = max_samples_to_rmlt_window;
|
||||
win = (dct_length == DCT_LENGTH) ? samples_to_rmlt_window : max_samples_to_rmlt_window;
|
||||
/* Get the first half of the windowed samples */
|
||||
last = half_dct_length - 1;
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
{
|
||||
acca = 0L;
|
||||
acca = L_mac(acca, win[last - i], old_samples[last - i]);
|
||||
acca = L_mult(win[last - i], old_samples[last - i]);
|
||||
acca = L_mac(acca, win[half_dct_length + i], old_samples[half_dct_length + i]);
|
||||
temp = xround(acca);
|
||||
windowed_data[i] = temp;
|
||||
windowed_data[i] = xround(acca);
|
||||
}
|
||||
/* Get the second half of the windowed samples */
|
||||
last = dct_length - 1;
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
{
|
||||
acca = 0L;
|
||||
acca = L_mac(acca, win[last - i], new_samples[i]);
|
||||
acca = L_mult(win[last - i], new_samples[i]);
|
||||
acca = L_mac(acca, negate(win[i]), new_samples[last - i]);
|
||||
temp = xround(acca);
|
||||
windowed_data[half_dct_length + i] = temp;
|
||||
windowed_data[half_dct_length + i] = xround(acca);
|
||||
}
|
||||
|
||||
/* Save the new samples for next time, when they will be the old samples. */
|
||||
for (i = 0; i < dct_length; i++)
|
||||
old_samples[i] = new_samples[i];
|
||||
vec_copyi16(old_samples, new_samples, dct_length);
|
||||
|
||||
/* Calculate how many bits to shift up the input to the DCT. */
|
||||
temp1 = 0;
|
||||
@ -156,10 +145,7 @@ void samples_to_rmlt_coefs(const float new_samples[],
|
||||
|
||||
half_dct_length = dct_length >> 1;
|
||||
|
||||
if (dct_length == DCT_LENGTH)
|
||||
win = samples_to_rmlt_window;
|
||||
else
|
||||
win = max_samples_to_rmlt_window;
|
||||
win = (dct_length == DCT_LENGTH) ? samples_to_rmlt_window : max_samples_to_rmlt_window;
|
||||
/* Get the first half of the windowed samples. */
|
||||
last = half_dct_length - 1;
|
||||
for (i = 0; i < half_dct_length; i++)
|
||||
@ -177,8 +163,7 @@ void samples_to_rmlt_coefs(const float new_samples[],
|
||||
windowed_data[half_dct_length + i] = sum;
|
||||
}
|
||||
/* Save the new samples for next time, when they will be the old samples. */
|
||||
for (i = 0; i < dct_length; i++)
|
||||
old_samples[i] = new_samples[i];
|
||||
vec_copyf(old_samples, new_samples, dct_length);
|
||||
|
||||
/* Perform a Type IV DCT on the windowed data to get the coefficients. */
|
||||
dct_type_iv(windowed_data, coefs, dct_length);
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sam2coef.h,v 1.2 2008/10/02 11:43:54 steveu Exp $
|
||||
*/
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: tables.c,v 1.11 2008/09/30 14:06:40 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -65,70 +63,70 @@ const int16_t int_region_standard_deviation_table[REGION_POWER_TABLE_SIZE] =
|
||||
#else
|
||||
const float region_standard_deviation_table[REGION_POWER_TABLE_SIZE] =
|
||||
{
|
||||
2.441406247570224e-04f,
|
||||
3.452669826719395e-04f,
|
||||
4.882812495545411e-04f,
|
||||
6.905339654011486e-04f,
|
||||
9.765624991900746e-04f,
|
||||
1.381067930916839e-03f,
|
||||
1.953124998542134e-03f,
|
||||
2.762135862062757e-03f,
|
||||
3.906249997408239e-03f,
|
||||
5.524271724583683e-03f,
|
||||
7.812499995464418e-03f,
|
||||
1.104854345008369e-02f,
|
||||
1.562499999222472e-02f,
|
||||
2.209708690200003e-02f,
|
||||
3.124999998704119e-02f,
|
||||
4.419417380766535e-02f,
|
||||
6.249999997926591e-02f,
|
||||
8.838834762266132e-02f,
|
||||
1.249999999688989e-01f,
|
||||
1.767766952599839e-01f,
|
||||
2.499999999585318e-01f,
|
||||
3.535533905492901e-01f,
|
||||
4.999999999585318e-01f,
|
||||
7.071067811572251e-01f,
|
||||
1.000000000000000e+00f,
|
||||
1.414213562431740e+00f,
|
||||
2.000000000165873e+00f,
|
||||
2.828427125098059e+00f,
|
||||
4.000000000663491e+00f,
|
||||
5.656854250665278e+00f,
|
||||
8.000000001990472e+00f,
|
||||
1.131370850226887e+01f,
|
||||
1.600000000530792e+01f,
|
||||
2.262741700641438e+01f,
|
||||
3.200000001326981e+01f,
|
||||
4.525483401658204e+01f,
|
||||
6.400000003184756e+01f,
|
||||
9.050966804067060e+01f,
|
||||
1.280000000743110e+02f,
|
||||
1.810193360963542e+02f,
|
||||
2.560000001698536e+02f,
|
||||
3.620386722227349e+02f,
|
||||
5.120000003821707e+02f,
|
||||
7.240773445055215e+02f,
|
||||
1.024000000849268e+03f,
|
||||
1.448154689131149e+03f,
|
||||
2.048000001868390e+03f,
|
||||
2.896309378502505e+03f,
|
||||
4.096000004076487e+03f,
|
||||
5.792618757485434e+03f,
|
||||
8.192000008832390e+03f,
|
||||
1.158523751593169e+04f,
|
||||
1.638400001902361e+04f,
|
||||
2.317047503378509e+04f,
|
||||
3.276800004076484e+04f,
|
||||
4.634095007141347e+04f,
|
||||
6.553600008696507e+04f,
|
||||
9.268190015051374e+04f,
|
||||
1.310720001848009e+05f,
|
||||
1.853638003164007e+05f,
|
||||
2.621440003913428e+05f,
|
||||
3.707276006635486e+05f,
|
||||
5.242880008261676e+05f,
|
||||
7.414552013885899e+05f
|
||||
2.441406247570224e-04,
|
||||
3.452669826719395e-04,
|
||||
4.882812495545411e-04,
|
||||
6.905339654011486e-04,
|
||||
9.765624991900746e-04,
|
||||
1.381067930916839e-03,
|
||||
1.953124998542134e-03,
|
||||
2.762135862062757e-03,
|
||||
3.906249997408239e-03,
|
||||
5.524271724583683e-03,
|
||||
7.812499995464418e-03,
|
||||
1.104854345008369e-02,
|
||||
1.562499999222472e-02,
|
||||
2.209708690200003e-02,
|
||||
3.124999998704119e-02,
|
||||
4.419417380766535e-02,
|
||||
6.249999997926591e-02,
|
||||
8.838834762266132e-02,
|
||||
1.249999999688989e-01,
|
||||
1.767766952599839e-01,
|
||||
2.499999999585318e-01,
|
||||
3.535533905492901e-01,
|
||||
4.999999999585318e-01,
|
||||
7.071067811572251e-01,
|
||||
1.000000000000000e+00,
|
||||
1.414213562431740e+00,
|
||||
2.000000000165873e+00,
|
||||
2.828427125098059e+00,
|
||||
4.000000000663491e+00,
|
||||
5.656854250665278e+00,
|
||||
8.000000001990472e+00,
|
||||
1.131370850226887e+01,
|
||||
1.600000000530792e+01,
|
||||
2.262741700641438e+01,
|
||||
3.200000001326981e+01,
|
||||
4.525483401658204e+01,
|
||||
6.400000003184756e+01,
|
||||
9.050966804067060e+01,
|
||||
1.280000000743110e+02,
|
||||
1.810193360963542e+02,
|
||||
2.560000001698536e+02,
|
||||
3.620386722227349e+02,
|
||||
5.120000003821707e+02,
|
||||
7.240773445055215e+02,
|
||||
1.024000000849268e+03,
|
||||
1.448154689131149e+03,
|
||||
2.048000001868390e+03,
|
||||
2.896309378502505e+03,
|
||||
4.096000004076487e+03,
|
||||
5.792618757485434e+03,
|
||||
8.192000008832390e+03,
|
||||
1.158523751593169e+04,
|
||||
1.638400001902361e+04,
|
||||
2.317047503378509e+04,
|
||||
3.276800004076484e+04,
|
||||
4.634095007141347e+04,
|
||||
6.553600008696507e+04,
|
||||
9.268190015051374e+04,
|
||||
1.310720001848009e+05,
|
||||
1.853638003164007e+05,
|
||||
2.621440003913428e+05,
|
||||
3.707276006635486e+05,
|
||||
5.242880008261676e+05,
|
||||
7.414552013885899e+05
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -146,70 +144,70 @@ const int16_t standard_deviation_inverse_table[REGION_POWER_TABLE_SIZE] =
|
||||
#else
|
||||
const float standard_deviation_inverse_table[REGION_POWER_TABLE_SIZE] =
|
||||
{
|
||||
4.096000004076488e+03f,
|
||||
2.896309378502504e+03f,
|
||||
2.048000001868390e+03f,
|
||||
1.448154689131149e+03f,
|
||||
1.024000000849268e+03f,
|
||||
7.240773445055215e+02f,
|
||||
5.120000003821708e+02f,
|
||||
3.620386722227349e+02f,
|
||||
2.560000001698537e+02f,
|
||||
1.810193360963542e+02f,
|
||||
1.280000000743110e+02f,
|
||||
9.050966804067060e+01f,
|
||||
6.400000003184756e+01f,
|
||||
4.525483401658203e+01f,
|
||||
3.200000001326982e+01f,
|
||||
2.262741700641438e+01f,
|
||||
1.600000000530793e+01f,
|
||||
1.131370850226887e+01f,
|
||||
8.000000001990474e+00f,
|
||||
5.656854250665277e+00f,
|
||||
4.000000000663491e+00f,
|
||||
2.828427125098059e+00f,
|
||||
2.000000000165873e+00f,
|
||||
1.414213562431740e+00f,
|
||||
1.000000000000000e+00f,
|
||||
7.071067811572251e-01f,
|
||||
4.999999999585318e-01f,
|
||||
3.535533905492901e-01f,
|
||||
2.499999999585318e-01f,
|
||||
1.767766952599838e-01f,
|
||||
1.249999999688989e-01f,
|
||||
8.838834762266132e-02f,
|
||||
6.249999997926592e-02f,
|
||||
4.419417380766535e-02f,
|
||||
3.124999998704120e-02f,
|
||||
2.209708690200002e-02f,
|
||||
1.562499999222472e-02f,
|
||||
1.104854345008369e-02f,
|
||||
7.812499995464418e-03f,
|
||||
5.524271724583683e-03f,
|
||||
3.906249997408239e-03f,
|
||||
2.762135862062757e-03f,
|
||||
1.953124998542134e-03f,
|
||||
1.381067930916839e-03f,
|
||||
9.765624991900747e-04f,
|
||||
6.905339654011486e-04f,
|
||||
4.882812495545411e-04f,
|
||||
3.452669826719394e-04f,
|
||||
2.441406247570224e-04f,
|
||||
1.726334913216520e-04f,
|
||||
1.220703123683871e-04f,
|
||||
8.631674565366727e-05f,
|
||||
6.103515617913153e-05f,
|
||||
4.315837282325419e-05f,
|
||||
3.051757808703478e-05f,
|
||||
2.157918640983742e-05f,
|
||||
1.525878904225187e-05f,
|
||||
1.078959320402385e-05f,
|
||||
7.629394520493171e-06f,
|
||||
5.394796601564505e-06f,
|
||||
3.814697259930213e-06f,
|
||||
2.697398300558537e-06f,
|
||||
1.907348629806920e-06f,
|
||||
1.348699150167414e-06f
|
||||
4.096000004076488e+03,
|
||||
2.896309378502504e+03,
|
||||
2.048000001868390e+03,
|
||||
1.448154689131149e+03,
|
||||
1.024000000849268e+03,
|
||||
7.240773445055215e+02,
|
||||
5.120000003821708e+02,
|
||||
3.620386722227349e+02,
|
||||
2.560000001698537e+02,
|
||||
1.810193360963542e+02,
|
||||
1.280000000743110e+02,
|
||||
9.050966804067060e+01,
|
||||
6.400000003184756e+01,
|
||||
4.525483401658203e+01,
|
||||
3.200000001326982e+01,
|
||||
2.262741700641438e+01,
|
||||
1.600000000530793e+01,
|
||||
1.131370850226887e+01,
|
||||
8.000000001990474e+00,
|
||||
5.656854250665277e+00,
|
||||
4.000000000663491e+00,
|
||||
2.828427125098059e+00,
|
||||
2.000000000165873e+00,
|
||||
1.414213562431740e+00,
|
||||
1.000000000000000e+00,
|
||||
7.071067811572251e-01,
|
||||
4.999999999585318e-01,
|
||||
3.535533905492901e-01,
|
||||
2.499999999585318e-01,
|
||||
1.767766952599838e-01,
|
||||
1.249999999688989e-01,
|
||||
8.838834762266132e-02,
|
||||
6.249999997926592e-02,
|
||||
4.419417380766535e-02,
|
||||
3.124999998704120e-02,
|
||||
2.209708690200002e-02,
|
||||
1.562499999222472e-02,
|
||||
1.104854345008369e-02,
|
||||
7.812499995464418e-03,
|
||||
5.524271724583683e-03,
|
||||
3.906249997408239e-03,
|
||||
2.762135862062757e-03,
|
||||
1.953124998542134e-03,
|
||||
1.381067930916839e-03,
|
||||
9.765624991900747e-04,
|
||||
6.905339654011486e-04,
|
||||
4.882812495545411e-04,
|
||||
3.452669826719394e-04,
|
||||
2.441406247570224e-04,
|
||||
1.726334913216520e-04,
|
||||
1.220703123683871e-04,
|
||||
8.631674565366727e-05,
|
||||
6.103515617913153e-05,
|
||||
4.315837282325419e-05,
|
||||
3.051757808703478e-05,
|
||||
2.157918640983742e-05,
|
||||
1.525878904225187e-05,
|
||||
1.078959320402385e-05,
|
||||
7.629394520493171e-06,
|
||||
5.394796601564505e-06,
|
||||
3.814697259930213e-06,
|
||||
2.697398300558537e-06,
|
||||
1.907348629806920e-06,
|
||||
1.348699150167414e-06
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -241,14 +239,14 @@ const float step_size[NUM_CATEGORIES] =
|
||||
|
||||
const float step_size_inverse_table[NUM_CATEGORIES] =
|
||||
{
|
||||
2.82805443e+00f,
|
||||
2.00000000e+00f,
|
||||
1.41422713e+00f,
|
||||
1.00000000e+00f,
|
||||
7.07113564e-01f,
|
||||
5.00000000e-01f,
|
||||
3.53556782e-01f,
|
||||
3.53556782e-01f
|
||||
2.82805443e+00,
|
||||
2.00000000e+00,
|
||||
1.41422713e+00,
|
||||
1.00000000e+00,
|
||||
7.07113564e-01,
|
||||
5.00000000e-01,
|
||||
3.53556782e-01,
|
||||
3.53556782e-01
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -279,137 +277,137 @@ const float dead_zone[NUM_CATEGORIES] =
|
||||
#if !defined(G722_1_USE_FIXED_POINT)
|
||||
const float region_power_table[REGION_POWER_TABLE_SIZE] =
|
||||
{
|
||||
5.96046448e-08f,
|
||||
1.19209290e-07f,
|
||||
2.38418579e-07f,
|
||||
4.76837158e-07f,
|
||||
9.53674316e-07f,
|
||||
1.90734863e-06f,
|
||||
3.81469727e-06f,
|
||||
7.62939453e-06f,
|
||||
1.52587891e-05f,
|
||||
3.05175781e-05f,
|
||||
6.10351562e-05f,
|
||||
1.22070312e-04f,
|
||||
2.44140625e-04f,
|
||||
4.88281250e-04f,
|
||||
9.76562500e-04f,
|
||||
1.95312500e-03f,
|
||||
3.90625000e-03f,
|
||||
7.81250000e-03f,
|
||||
1.56250000e-02f,
|
||||
3.12500000e-02f,
|
||||
6.25000000e-02f,
|
||||
1.25000000e-01f,
|
||||
2.50000000e-01f,
|
||||
5.00000000e-01f,
|
||||
1.00000000e+00f,
|
||||
2.00000000e+00f,
|
||||
4.00000000e+00f,
|
||||
8.00000000e+00f,
|
||||
1.60000000e+01f,
|
||||
3.20000000e+01f,
|
||||
6.40000000e+01f,
|
||||
1.28000000e+02f,
|
||||
2.56000000e+02f,
|
||||
5.12000000e+02f,
|
||||
1.02400000e+03f,
|
||||
2.04800000e+03f,
|
||||
4.09600000e+03f,
|
||||
8.19200000e+03f,
|
||||
1.63840000e+04f,
|
||||
3.27680000e+04f,
|
||||
6.55360000e+04f,
|
||||
1.31072000e+05f,
|
||||
2.62144000e+05f,
|
||||
5.24288000e+05f,
|
||||
1.04857600e+06f,
|
||||
2.09715200e+06f,
|
||||
4.19430400e+06f,
|
||||
8.38860800e+06f,
|
||||
1.67772160e+07f,
|
||||
3.35544320e+07f,
|
||||
6.71088640e+07f,
|
||||
1.34217728e+08f,
|
||||
2.68435456e+08f,
|
||||
5.36870912e+08f,
|
||||
1.07374182e+09f,
|
||||
2.14748365e+09f,
|
||||
4.29496730e+09f,
|
||||
8.58993459e+09f,
|
||||
1.71798692e+10f,
|
||||
3.43597384e+10f,
|
||||
6.87194767e+10f,
|
||||
1.37438953e+11f,
|
||||
2.74877907e+11f,
|
||||
5.49755814e+11f
|
||||
5.96046448e-08,
|
||||
1.19209290e-07,
|
||||
2.38418579e-07,
|
||||
4.76837158e-07,
|
||||
9.53674316e-07,
|
||||
1.90734863e-06,
|
||||
3.81469727e-06,
|
||||
7.62939453e-06,
|
||||
1.52587891e-05,
|
||||
3.05175781e-05,
|
||||
6.10351562e-05,
|
||||
1.22070312e-04,
|
||||
2.44140625e-04,
|
||||
4.88281250e-04,
|
||||
9.76562500e-04,
|
||||
1.95312500e-03,
|
||||
3.90625000e-03,
|
||||
7.81250000e-03,
|
||||
1.56250000e-02,
|
||||
3.12500000e-02,
|
||||
6.25000000e-02,
|
||||
1.25000000e-01,
|
||||
2.50000000e-01,
|
||||
5.00000000e-01,
|
||||
1.00000000e+00,
|
||||
2.00000000e+00,
|
||||
4.00000000e+00,
|
||||
8.00000000e+00,
|
||||
1.60000000e+01,
|
||||
3.20000000e+01,
|
||||
6.40000000e+01,
|
||||
1.28000000e+02,
|
||||
2.56000000e+02,
|
||||
5.12000000e+02,
|
||||
1.02400000e+03,
|
||||
2.04800000e+03,
|
||||
4.09600000e+03,
|
||||
8.19200000e+03,
|
||||
1.63840000e+04,
|
||||
3.27680000e+04,
|
||||
6.55360000e+04,
|
||||
1.31072000e+05,
|
||||
2.62144000e+05,
|
||||
5.24288000e+05,
|
||||
1.04857600e+06,
|
||||
2.09715200e+06,
|
||||
4.19430400e+06,
|
||||
8.38860800e+06,
|
||||
1.67772160e+07,
|
||||
3.35544320e+07,
|
||||
6.71088640e+07,
|
||||
1.34217728e+08,
|
||||
2.68435456e+08,
|
||||
5.36870912e+08,
|
||||
1.07374182e+09,
|
||||
2.14748365e+09,
|
||||
4.29496730e+09,
|
||||
8.58993459e+09,
|
||||
1.71798692e+10,
|
||||
3.43597384e+10,
|
||||
6.87194767e+10,
|
||||
1.37438953e+11,
|
||||
2.74877907e+11,
|
||||
5.49755814e+11
|
||||
};
|
||||
|
||||
const float region_power_table_boundary[REGION_POWER_TABLE_SIZE - 1] =
|
||||
{
|
||||
8.42936956e-08f,
|
||||
1.68587391e-07f,
|
||||
3.37174782e-07f,
|
||||
6.74349565e-07f,
|
||||
1.34869913e-06f,
|
||||
2.69739826e-06f,
|
||||
5.39479652e-06f,
|
||||
1.07895930e-05f,
|
||||
2.15791861e-05f,
|
||||
4.31583721e-05f,
|
||||
8.63167443e-05f,
|
||||
1.72633489e-04f,
|
||||
3.45266977e-04f,
|
||||
6.90533954e-04f,
|
||||
1.38106791e-03f,
|
||||
2.76213582e-03f,
|
||||
5.52427163e-03f,
|
||||
1.10485433e-02f,
|
||||
2.20970865e-02f,
|
||||
4.41941731e-02f,
|
||||
8.83883461e-02f,
|
||||
1.76776692e-01f,
|
||||
3.53553385e-01f,
|
||||
7.07106769e-01f,
|
||||
1.41421354e+00f,
|
||||
2.82842708e+00f,
|
||||
5.65685415e+00f,
|
||||
1.13137083e+01f,
|
||||
2.26274166e+01f,
|
||||
4.52548332e+01f,
|
||||
9.05096664e+01f,
|
||||
1.81019333e+02f,
|
||||
3.62038666e+02f,
|
||||
7.24077332e+02f,
|
||||
1.44815466e+03f,
|
||||
2.89630933e+03f,
|
||||
5.79261865e+03f,
|
||||
1.15852373e+04f,
|
||||
2.31704746e+04f,
|
||||
4.63409492e+04f,
|
||||
9.26818984e+04f,
|
||||
1.85363797e+05f,
|
||||
3.70727594e+05f,
|
||||
7.41455188e+05f,
|
||||
1.48291038e+06f,
|
||||
2.96582075e+06f,
|
||||
5.93164150e+06f,
|
||||
1.18632830e+07f,
|
||||
2.37265660e+07f,
|
||||
4.74531320e+07f,
|
||||
9.49062640e+07f,
|
||||
1.89812528e+08f,
|
||||
3.79625056e+08f,
|
||||
7.59250112e+08f,
|
||||
1.51850022e+09f,
|
||||
3.03700045e+09f,
|
||||
6.07400090e+09f,
|
||||
1.21480018e+10f,
|
||||
2.42960036e+10f,
|
||||
4.85920072e+10f,
|
||||
9.71840143e+10f,
|
||||
1.94368029e+11f,
|
||||
3.88736057e+11f
|
||||
8.42936956e-08,
|
||||
1.68587391e-07,
|
||||
3.37174782e-07,
|
||||
6.74349565e-07,
|
||||
1.34869913e-06,
|
||||
2.69739826e-06,
|
||||
5.39479652e-06,
|
||||
1.07895930e-05,
|
||||
2.15791861e-05,
|
||||
4.31583721e-05,
|
||||
8.63167443e-05,
|
||||
1.72633489e-04,
|
||||
3.45266977e-04,
|
||||
6.90533954e-04,
|
||||
1.38106791e-03,
|
||||
2.76213582e-03,
|
||||
5.52427163e-03,
|
||||
1.10485433e-02,
|
||||
2.20970865e-02,
|
||||
4.41941731e-02,
|
||||
8.83883461e-02,
|
||||
1.76776692e-01,
|
||||
3.53553385e-01,
|
||||
7.07106769e-01,
|
||||
1.41421354e+00,
|
||||
2.82842708e+00,
|
||||
5.65685415e+00,
|
||||
1.13137083e+01,
|
||||
2.26274166e+01,
|
||||
4.52548332e+01,
|
||||
9.05096664e+01,
|
||||
1.81019333e+02,
|
||||
3.62038666e+02,
|
||||
7.24077332e+02,
|
||||
1.44815466e+03,
|
||||
2.89630933e+03,
|
||||
5.79261865e+03,
|
||||
1.15852373e+04,
|
||||
2.31704746e+04,
|
||||
4.63409492e+04,
|
||||
9.26818984e+04,
|
||||
1.85363797e+05,
|
||||
3.70727594e+05,
|
||||
7.41455188e+05,
|
||||
1.48291038e+06,
|
||||
2.96582075e+06,
|
||||
5.93164150e+06,
|
||||
1.18632830e+07,
|
||||
2.37265660e+07,
|
||||
4.74531320e+07,
|
||||
9.49062640e+07,
|
||||
1.89812528e+08,
|
||||
3.79625056e+08,
|
||||
7.59250112e+08,
|
||||
1.51850022e+09,
|
||||
3.03700045e+09,
|
||||
6.07400090e+09,
|
||||
1.21480018e+10,
|
||||
2.42960036e+10,
|
||||
4.85920072e+10,
|
||||
9.71840143e+10,
|
||||
1.94368029e+11,
|
||||
3.88736057e+11
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: tables.h,v 1.7 2008/09/26 17:37:31 steveu Exp $
|
||||
*/
|
||||
|
||||
#define REGION_POWER_TABLE_SIZE 64
|
||||
|
467
libs/libg722_1/src/utilities.c
Normal file
467
libs/libg722_1/src/utilities.c
Normal file
@ -0,0 +1,467 @@
|
||||
/*
|
||||
* g722_1 - a library for the G.722.1 and Annex C codecs
|
||||
*
|
||||
* utilities.c
|
||||
*
|
||||
* Copyright (C) 2006 Steve Underwood
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(G722_1_USE_MMX)
|
||||
#include <mmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE)
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE2)
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE3)
|
||||
#include <pmmintrin.h>
|
||||
#include <tmmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE4_1)
|
||||
#include <smmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE4_2)
|
||||
#include <nmmintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE4A)
|
||||
#include <ammintrin.h>
|
||||
#endif
|
||||
#if defined(G722_1_USE_SSE5)
|
||||
#include <bmmintrin.h>
|
||||
#endif
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
void vec_copyi16(int16_t z[], const int16_t x[], int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
z[i] = x[i];
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n)
|
||||
{
|
||||
int32_t z;
|
||||
|
||||
#if defined(__GNUC__) && defined(G722_1_USE_MMX)
|
||||
#if defined(__x86_64__)
|
||||
__asm__ __volatile__(
|
||||
" emms;\n"
|
||||
" pxor %%mm0,%%mm0;\n"
|
||||
" leal -32(%%rsi,%%eax,2),%%edx;\n" /* edx = top - 32 */
|
||||
|
||||
" cmpl %%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"
|
||||
|
||||
" addl $32,%%rsi;\n"
|
||||
" addl $32,%%rdi;\n"
|
||||
" cmpl %%rdx,%%rsi;\n"
|
||||
" jbe 2b;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"1:\n"
|
||||
" addl $24,%%rdx;\n" /* Now edx = top - 8 */
|
||||
" cmpl %%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"
|
||||
|
||||
" addl $8,%%rsi;\n"
|
||||
" addl $8,%%rdi;\n"
|
||||
" cmpl %%rdx,%%rsi;"
|
||||
" jbe 4b;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"3:\n"
|
||||
" addl $4,%%rdx;\n" /* Now edx = top - 4 */
|
||||
" cmpl %%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"
|
||||
|
||||
" addl $4,%%rsi;\n"
|
||||
" addl $4,%%rdi;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"5:\n"
|
||||
" addl $2,%%rdx;\n" /* Now edx = top - 2 */
|
||||
" cmpl %%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"
|
||||
" leal -32(%%esi,%%eax,2),%%edx;\n" /* edx = top - 32 */
|
||||
|
||||
" cmpl %%edx,%%esi;\n"
|
||||
" ja 1f;\n"
|
||||
|
||||
/* Work in blocks of 16 int16_t's until we are near the end */
|
||||
" .p2align 2;\n"
|
||||
"2:\n"
|
||||
" movq (%%edi),%%mm1;\n"
|
||||
" movq (%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
" movq 8(%%edi),%%mm1;\n"
|
||||
" movq 8(%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
" movq 16(%%edi),%%mm1;\n"
|
||||
" movq 16(%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
" movq 24(%%edi),%%mm1;\n"
|
||||
" movq 24(%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
|
||||
" addl $32,%%esi;\n"
|
||||
" addl $32,%%edi;\n"
|
||||
" cmpl %%edx,%%esi;\n"
|
||||
" jbe 2b;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"1:\n"
|
||||
" addl $24,%%edx;\n" /* Now edx = top - 8 */
|
||||
" cmpl %%edx,%%esi;\n"
|
||||
" ja 3f;\n"
|
||||
|
||||
/* Work in blocks of 4 int16_t's until we are near the end */
|
||||
" .p2align 2;\n"
|
||||
"4:\n"
|
||||
" movq (%%edi),%%mm1;\n"
|
||||
" movq (%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
|
||||
" addl $8,%%esi;\n"
|
||||
" addl $8,%%edi;\n"
|
||||
" cmpl %%edx,%%esi;"
|
||||
" jbe 4b;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"3:\n"
|
||||
" addl $4,%%edx;\n" /* Now edx = top - 4 */
|
||||
" cmpl %%edx,%%esi;\n"
|
||||
" ja 5f;\n"
|
||||
|
||||
/* Work in a block of 2 int16_t's */
|
||||
" movd (%%edi),%%mm1;\n"
|
||||
" movd (%%esi),%%mm2;\n"
|
||||
" pmaddwd %%mm2,%%mm1;\n"
|
||||
" paddd %%mm1,%%mm0;\n"
|
||||
|
||||
" addl $4,%%esi;\n"
|
||||
" addl $4,%%edi;\n"
|
||||
|
||||
" .p2align 2;\n"
|
||||
"5:\n"
|
||||
" addl $2,%%edx;\n" /* Now edx = top - 2 */
|
||||
" cmpl %%edx,%%esi;\n"
|
||||
" ja 6f;\n"
|
||||
|
||||
/* Deal with the very last int16_t, when n is odd */
|
||||
" movswl (%%edi),%%eax;\n"
|
||||
" andl $65535,%%eax;\n"
|
||||
" movd %%eax,%%mm1;\n"
|
||||
" movswl (%%esi),%%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"
|
||||
);
|
||||
#endif
|
||||
#else
|
||||
int i;
|
||||
|
||||
z = 0;
|
||||
for (i = 0; i < n; i++)
|
||||
z += (int32_t) x[i]*(int32_t) y[i];
|
||||
#endif
|
||||
return z;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
#else
|
||||
#if defined(__GNUC__) && defined(G722_1_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;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
z[i] = x[i];
|
||||
}
|
||||
#endif
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
#if defined(__GNUC__) && defined(G722_1_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;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
z[i] = 0.0f;
|
||||
}
|
||||
#endif
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
void vec_subf(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 --------------------------------------------------------*/
|
||||
|
||||
#if defined(__GNUC__) && defined(G722_1_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;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
z[i] = x[i]*y[i];
|
||||
}
|
||||
#endif
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
#if defined(__GNUC__) && defined(G722_1_USE_SSE2)
|
||||
float vec_dot_prodf(const float x[], const float y[], int n)
|
||||
{
|
||||
int i;
|
||||
float z;
|
||||
__m128 n1;
|
||||
__m128 n2;
|
||||
__m128 n3;
|
||||
__m128 n4;
|
||||
|
||||
z = 0.0f;
|
||||
if ((i = n & ~3))
|
||||
{
|
||||
n4 = _mm_setzero_ps(); //sets sum to zero
|
||||
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);
|
||||
n4 = _mm_add_ps(n4, n3);
|
||||
}
|
||||
n4 = _mm_add_ps(_mm_movehl_ps(n4, n4), n4);
|
||||
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 an SSE2 register */
|
||||
switch (n & 3)
|
||||
{
|
||||
case 3:
|
||||
z += x[n - 3]*y[n - 3];
|
||||
case 2:
|
||||
z += x[n - 2]*y[n - 2];
|
||||
case 1:
|
||||
z += x[n - 1]*y[n - 1];
|
||||
}
|
||||
return z;
|
||||
}
|
||||
#else
|
||||
float vec_dot_prodf(const float x[], const float y[], int n)
|
||||
{
|
||||
int i;
|
||||
float z;
|
||||
|
||||
z = 0.0f;
|
||||
for (i = 0; i < n; i++)
|
||||
z += x[i]*y[i];
|
||||
return z;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
void vec_scalar_mulf(float z[], const float x[], float y, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
z[i] = x[i]*y;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
void vec_scaled_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;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
void vec_scaled_subf(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 --------------------------------------------------------*/
|
||||
#endif
|
||||
/*- End of file ------------------------------------------------------------*/
|
32
libs/libg722_1/src/utilities.h
Normal file
32
libs/libg722_1/src/utilities.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* g722_1 - a library for the G.722.1 and Annex C codecs
|
||||
*
|
||||
* utilities.h
|
||||
*
|
||||
* Copyright (C) 2006 Steve Underwood
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if !defined(__UTILITIES_H__)
|
||||
#define __UTILITIES_H__
|
||||
|
||||
/* Prototypes for some general purpose signal and vector functions */
|
||||
#if defined(G722_1_USE_FIXED_POINT)
|
||||
void vec_copyi16(int16_t z[], const int16_t x[], int n);
|
||||
int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
|
||||
#else
|
||||
void vec_copyf(float z[], const float x[], int n);
|
||||
void vec_zerof(float z[], int n);
|
||||
void vec_subf(float z[], const float x[], const float y[], int n);
|
||||
void vec_scalar_mulf(float z[], const float x[], float y, int n);
|
||||
void vec_mulf(float z[], const float x[], const float y[], int n);
|
||||
float vec_dot_prodf(const float x[], const float y[], int n);
|
||||
void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
|
||||
void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*- End of file ------------------------------------------------------------*/
|
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.2 2008/09/20 16:31:19 steveu Exp $
|
||||
|
||||
SUBDIRS = itu local
|
||||
|
||||
|
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.3 2008/09/23 16:03:04 steveu Exp $
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.3 2008/09/24 16:12:52 steveu Exp $
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
@ -15,8 +15,6 @@
|
||||
## 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: Makefile.am,v 1.4 2008/10/19 04:05:02 steveu Exp $
|
||||
|
||||
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
|
||||
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)
|
||||
@ -33,8 +31,8 @@ LIBDIR = -L$(top_builddir)/src
|
||||
|
||||
noinst_PROGRAMS = g722_1_tests
|
||||
|
||||
noinst_HEADERS = itu_bit_stream.c \
|
||||
noinst_HEADERS = g192_bit_stream.h \
|
||||
timing.h
|
||||
|
||||
g722_1_tests_SOURCES = g722_1_tests.c itu_bit_stream.c
|
||||
g722_1_tests_SOURCES = g722_1_tests.c g192_bit_stream.c
|
||||
g722_1_tests_LDADD = $(LIBDIR) -lg722_1
|
||||
|
177
libs/libg722_1/tests/g192_bit_stream.c
Normal file
177
libs/libg722_1/tests/g192_bit_stream.c
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* broadvoice - a library for the BroadVoice 16 and 32 codecs
|
||||
*
|
||||
* g192_bit_stream.c
|
||||
*
|
||||
* Copyright 2008-2009 Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <audiofile.h>
|
||||
|
||||
#include "g192_bit_stream.h"
|
||||
|
||||
#if !defined(FALSE)
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#if !defined(TRUE)
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
G192_FRAME_ERASURE = 0x6B20,
|
||||
G192_FRAME_SYNC_1 = 0x6B21,
|
||||
G192_FRAME_SYNC_2 = 0x6B22,
|
||||
G192_FRAME_SYNC_3 = 0x6B23,
|
||||
G192_FRAME_SYNC_4 = 0x6B24,
|
||||
G192_FRAME_SYNC_5 = 0x6B25,
|
||||
G192_FRAME_SYNC_6 = 0x6B26,
|
||||
G192_FRAME_SYNC_7 = 0x6B27,
|
||||
G192_FRAME_SYNC_8 = 0x6B28,
|
||||
G192_FRAME_SYNC_9 = 0x6B29,
|
||||
G192_FRAME_SYNC_10 = 0x6B2A,
|
||||
G192_FRAME_SYNC_11 = 0x6B2B,
|
||||
G192_FRAME_SYNC_12 = 0x6B2C,
|
||||
G192_FRAME_SYNC_13 = 0x6B2D,
|
||||
G192_FRAME_SYNC_14 = 0x6B2E,
|
||||
G192_FRAME_SYNC_15 = 0x6B2F,
|
||||
G192_HARD_ZERO = 0x7F,
|
||||
G192_INDETERMINATE = 0x00,
|
||||
G192_HARD_ONE = 0x81
|
||||
};
|
||||
|
||||
int itu_codec_bitstream_write(const uint8_t out_data[],
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int bit_count;
|
||||
int number_of_bytes;
|
||||
uint8_t packed_word;
|
||||
int16_t out_array[2 + number_of_bits + 7];
|
||||
|
||||
number_of_bytes = (number_of_bits + 7)/8;
|
||||
if (mode == ITU_CODEC_BITSTREAM_PACKED)
|
||||
{
|
||||
return fwrite(out_data, 1, number_of_bytes, fp_bitstream);
|
||||
}
|
||||
j = 0;
|
||||
out_array[j++] = G192_FRAME_SYNC_1;
|
||||
out_array[j++] = number_of_bits;
|
||||
for (i = 0; i < number_of_bytes; i++)
|
||||
{
|
||||
packed_word = out_data[i];
|
||||
for (bit_count = 7; bit_count >= 0; bit_count--)
|
||||
out_array[j++] = ((packed_word >> bit_count) & 1) ? G192_HARD_ONE : G192_HARD_ZERO;
|
||||
}
|
||||
|
||||
return fwrite(out_array, sizeof(int16_t), number_of_bits + 2, fp_bitstream);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
int itu_codec_bitstream_read(uint8_t in_data[],
|
||||
int16_t *erasure,
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int bit_pos;
|
||||
int nsamp;
|
||||
int limit;
|
||||
int rem;
|
||||
int len;
|
||||
int erased_frame;
|
||||
int16_t packed_word;
|
||||
int16_t bit;
|
||||
int16_t in_array[2 + number_of_bits];
|
||||
|
||||
*erasure = FALSE;
|
||||
if (mode == ITU_CODEC_BITSTREAM_PACKED)
|
||||
{
|
||||
nsamp = fread(in_data, 1, number_of_bits/8, fp_bitstream);
|
||||
if (nsamp <= 0)
|
||||
return -1;
|
||||
return nsamp*8;
|
||||
}
|
||||
|
||||
nsamp = fread(in_array, sizeof(int16_t), 2, fp_bitstream);
|
||||
if (nsamp < 2)
|
||||
return -1;
|
||||
if (in_array[0] < G192_FRAME_ERASURE || in_array[0] > G192_FRAME_SYNC_15)
|
||||
{
|
||||
*erasure = TRUE;
|
||||
return 0;
|
||||
}
|
||||
erased_frame = (in_array[0] == G192_FRAME_ERASURE);
|
||||
len = in_array[1];
|
||||
if (len > number_of_bits)
|
||||
{
|
||||
*erasure = TRUE;
|
||||
return 0;
|
||||
}
|
||||
nsamp = fread(in_array, sizeof(int16_t), len, fp_bitstream);
|
||||
if (nsamp != len)
|
||||
{
|
||||
*erasure = TRUE;
|
||||
return nsamp;
|
||||
}
|
||||
|
||||
limit = (nsamp + 7)/8;
|
||||
for (i = 0, j = 0; i < limit; i++)
|
||||
{
|
||||
packed_word = 0;
|
||||
rem = (i == (limit - 1)) ? (limit*8 - nsamp) : 0;
|
||||
for (bit_pos = 7; bit_pos >= rem; bit_pos--)
|
||||
{
|
||||
bit = in_array[j++];
|
||||
if (bit >= 0x0001 && bit <= G192_HARD_ZERO)
|
||||
{
|
||||
/* Its a zero */
|
||||
}
|
||||
else if (bit >= G192_HARD_ONE && bit <= 0x00FF)
|
||||
{
|
||||
/* Its a one */
|
||||
packed_word |= (1 << bit_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bad bit */
|
||||
*erasure = 1;
|
||||
}
|
||||
}
|
||||
in_data[i] = packed_word;
|
||||
}
|
||||
if (erased_frame)
|
||||
*erasure = TRUE;
|
||||
return nsamp;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
/*- End of file ------------------------------------------------------------*/
|
75
libs/libg722_1/tests/g192_bit_stream.h
Normal file
75
libs/libg722_1/tests/g192_bit_stream.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* broadvoice - a library for the BroadVoice 16 and 32 codecs
|
||||
*
|
||||
* g192_bit_stream.h
|
||||
*
|
||||
* Copyright 2008-2009 Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#if !defined(_G192_BIT_STREAM_H_)
|
||||
#define _G192_BIT_STREAM_H_
|
||||
|
||||
/*! \page g192_bit_stream_page ITU G.192 codec bit stream handling
|
||||
\section g192_bit_stream_page_sec_1 What does it do?
|
||||
|
||||
\section g192_bit_stream_page_sec_2 How does it work?
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
ITU_CODEC_BITSTREAM_PACKED = 0,
|
||||
ITU_CODEC_BITSTREAM_G192 = 1
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*! \brief Write a frame of data to an output file.
|
||||
\param out_data The buffer for the data to be written.
|
||||
\param number_of_bits The number of bits to be written.
|
||||
\param mode 0 = continuous, 1 = ITU G.192 codec bitstream format.
|
||||
\param fp_bitstream The file context to be written to.
|
||||
\return The number of words written. */
|
||||
int itu_codec_bitstream_write(const uint8_t out_data[],
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream);
|
||||
|
||||
/*! \brief Read a frame of data from an input file.
|
||||
\param in_data The buffer for the data to be read.
|
||||
\param p_erasure Set to TRUE if there is a frame erasure, else set to FALSE.
|
||||
\param number_of_bits The number of bits to be read.
|
||||
\param mode 0 = continuous, 1 = ITU G.192 codec bitstream format.
|
||||
\param fp_bitstream The file context to be read from.
|
||||
\return The number of words read. */
|
||||
int itu_codec_bitstream_read(uint8_t in_data[],
|
||||
int16_t *p_erasure,
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*- End of file ------------------------------------------------------------*/
|
@ -6,14 +6,12 @@
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* (C) 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: g722_1_tests.c,v 1.14 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@ -36,7 +34,7 @@
|
||||
#include <g722_1.h>
|
||||
|
||||
#include "timing.h"
|
||||
#include "itu_bit_stream.h"
|
||||
#include "g192_bit_stream.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -227,7 +225,7 @@ static void parse_command_line(char *argv[], coder_control_t *control)
|
||||
}
|
||||
else if (strcasecmp(*argv, "i") == 0)
|
||||
{
|
||||
control->encoded_format = ITU_CODEC_BITSTREAM_ITU;
|
||||
control->encoded_format = ITU_CODEC_BITSTREAM_G192;
|
||||
printf("Encoding format = ITU-format bitstream\n");
|
||||
}
|
||||
else
|
||||
|
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* g722_1 - a library for the G.722.1 and Annex C codecs
|
||||
*
|
||||
* itu_bit_stream.c
|
||||
*
|
||||
* Adapted by Steve Underwood <steveu@coppice.org> from the reference
|
||||
* code supplied with ITU G.722.1, which is:
|
||||
*
|
||||
* © 2004 Polycom, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: itu_bit_stream.c,v 1.6 2008/11/21 15:30:22 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <audiofile.h>
|
||||
|
||||
#include "itu_bit_stream.h"
|
||||
|
||||
static const int16_t frame_start = 0x6B21;
|
||||
static const int16_t erased_frame_start = 0x6B20;
|
||||
static const int16_t one = 0x0081;
|
||||
static const int16_t zero = 0x007F;
|
||||
|
||||
void itu_codec_bitstream_write(const uint8_t out_data[],
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int bit_count;
|
||||
int number_of_bytes;
|
||||
uint8_t packed_word;
|
||||
int16_t out_array[2 + number_of_bits + 7];
|
||||
|
||||
number_of_bytes = (number_of_bits + 7)/8;
|
||||
if (mode == ITU_CODEC_BITSTREAM_PACKED)
|
||||
{
|
||||
fwrite(out_data, 1, number_of_bytes, fp_bitstream);
|
||||
return;
|
||||
}
|
||||
j = 0;
|
||||
out_array[j++] = frame_start;
|
||||
out_array[j++] = number_of_bits;
|
||||
for (i = 0; i < number_of_bytes; i++)
|
||||
{
|
||||
packed_word = out_data[i];
|
||||
for (bit_count = 7; bit_count >= 0; bit_count--)
|
||||
out_array[j++] = ((packed_word >> bit_count) & 1) ? one : zero;
|
||||
}
|
||||
|
||||
fwrite(out_array, sizeof(int16_t), number_of_bits + 2, fp_bitstream);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
int itu_codec_bitstream_read(uint8_t in_data[],
|
||||
int16_t *p_frame_error_flag,
|
||||
int number_of_bits,
|
||||
int mode,
|
||||
FILE *fp_bitstream)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int bit_count;
|
||||
int nsamp;
|
||||
int len;
|
||||
int erased_frame;
|
||||
int16_t packed_word;
|
||||
int16_t bit;
|
||||
int16_t in_array[2 + number_of_bits];
|
||||
|
||||
if (mode == ITU_CODEC_BITSTREAM_PACKED)
|
||||
return fread(in_data, 1, number_of_bits/8, fp_bitstream)*8;
|
||||
|
||||
nsamp = fread(in_array, sizeof(int16_t), 2, fp_bitstream);
|
||||
if (nsamp < 2)
|
||||
return -1;
|
||||
if (in_array[0] != frame_start && in_array[0] != erased_frame_start)
|
||||
{
|
||||
*p_frame_error_flag = 1;
|
||||
return 0;
|
||||
}
|
||||
erased_frame = (in_array[0] == erased_frame_start);
|
||||
len = in_array[1];
|
||||
if (len > number_of_bits)
|
||||
{
|
||||
*p_frame_error_flag = 1;
|
||||
return 0;
|
||||
}
|
||||
nsamp = fread(in_array, sizeof(int16_t), len, fp_bitstream);
|
||||
if (nsamp != len)
|
||||
{
|
||||
*p_frame_error_flag = 1;
|
||||
return nsamp;
|
||||
}
|
||||
*p_frame_error_flag = 0;
|
||||
|
||||
for (i = 0, j = 0; i < nsamp/8; i++)
|
||||
{
|
||||
packed_word = 0;
|
||||
bit_count = 7;
|
||||
while (bit_count >= 0)
|
||||
{
|
||||
bit = in_array[j++];
|
||||
if (bit == zero)
|
||||
bit = 0;
|
||||
else if (bit == one)
|
||||
bit = 1;
|
||||
else
|
||||
{
|
||||
/* Bad bit */
|
||||
bit = 1;
|
||||
*p_frame_error_flag = 1;
|
||||
/* printf("read_ITU_format: bit not zero or one: %4x\n", bit); */
|
||||
}
|
||||
packed_word = (packed_word << 1) | bit;
|
||||
bit_count--;
|
||||
}
|
||||
in_data[i] = packed_word;
|
||||
}
|
||||
if (erased_frame)
|
||||
*p_frame_error_flag = 1;
|
||||
return nsamp;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
/*- End of file ------------------------------------------------------------*/
|
@ -16,9 +16,6 @@
|
||||
# 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: regression_tests.sh.in,v 1.4 2008/11/21 15:30:22 steveu Exp $
|
||||
#
|
||||
|
||||
STDOUT_DEST=xyzzy
|
||||
STDERR_DEST=xyzzy2
|
||||
@ -33,7 +30,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_32000.itu
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests E failed!
|
||||
echo g722_1_tests encode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
./g722_1_tests E I 24000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_in.pcm $TMP_FILE
|
||||
@ -41,17 +38,17 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_24000.itu
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests E failed!
|
||||
echo g722_1_tests encode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
echo g722_1_tests E completed OK
|
||||
echo g722_1_tests encode completed OK
|
||||
|
||||
./g722_1_tests D I 24000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_24000.itu $TMP_FILE
|
||||
diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_24000.pcm
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests D failed!
|
||||
echo g722_1_tests decode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
./g722_1_tests D I 32000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_32000.itu $TMP_FILE
|
||||
@ -59,7 +56,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_32000.pcm
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests D failed!
|
||||
echo g722_1_tests decode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
|
||||
@ -68,7 +65,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_24000_fe.pcm
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests D failed!
|
||||
echo g722_1_tests decode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
./g722_1_tests D I 32000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_in_32000_fe.itu $TMP_FILE
|
||||
@ -76,28 +73,28 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_32000_fe.pcm
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests D failed!
|
||||
echo g722_1_tests decode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
echo g722_1_tests D completed OK
|
||||
echo g722_1_tests decode completed OK
|
||||
|
||||
./g722_1_tests E I 32000 16000 ../test-data/local/short_wb_voice.wav $TMP_FILE
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests E failed!
|
||||
echo g722_1_tests encode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
echo g722_1_tests E completed OK
|
||||
echo g722_1_tests encode completed OK
|
||||
|
||||
./g722_1_tests D I 32000 16000 $TMP_FILE test.au
|
||||
RETVAL=$?
|
||||
if [ $RETVAL != 0 ]
|
||||
then
|
||||
echo g722_1_tests D failed!
|
||||
echo g722_1_tests decode failed!
|
||||
exit $RETVAL
|
||||
fi
|
||||
echo g722_1_tests D completed OK
|
||||
echo g722_1_tests decode completed OK
|
||||
|
||||
echo
|
||||
echo All regression tests successfully completed
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SpanDSP - a series of DSP components for telephony
|
||||
* g722_1 - a library for the G.722.1 and Annex C codecs
|
||||
*
|
||||
* timing.h - Provide access to the Pentium/Athlon TSC timer register
|
||||
*
|
||||
@ -21,8 +21,6 @@
|
||||
* 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: timing.h,v 1.1 2008/10/17 15:17:39 steveu Exp $
|
||||
*/
|
||||
|
||||
#if !defined(_TIMING_H_)
|
||||
|
@ -16,9 +16,6 @@
|
||||
# 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: unpack_g722_1_data.sh,v 1.2 2008/09/26 12:09:29 steveu Exp $
|
||||
#
|
||||
|
||||
ITUDATA="../../../T-REC-G.722.1-200505-I!!SOFT-ZST-E.zip"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user