mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
Working codec2 support
This commit is contained in:
53
libs/libcodec2/src/Makefile.am
Normal file
53
libs/libcodec2/src/Makefile.am
Normal file
@@ -0,0 +1,53 @@
|
||||
AM_CFLAGS = -I../src -Wall -DFLOATING_POINT -DVAR_ARRAYS
|
||||
AUTOMAKE_OPTS = gnu
|
||||
NAME = libcodec2
|
||||
AM_CPPFLAGS = $(AM_CFLAGS)
|
||||
|
||||
lib_LTLIBRARIES = libcodec2.la
|
||||
libcodec2_la_SOURCES = dump.c \
|
||||
lpc.c \
|
||||
nlp.c \
|
||||
postfilter.c \
|
||||
sine.c \
|
||||
codec2.c \
|
||||
four1.c \
|
||||
interp.c \
|
||||
lsp.c \
|
||||
phase.c \
|
||||
quantise.c \
|
||||
pack.c \
|
||||
codebook.c
|
||||
|
||||
libcodec2_la_CFLAGS = $(AM_CFLAGS)
|
||||
libcodec2_la_LDFLAGS = $(LIBS)
|
||||
|
||||
library_includedir = $(prefix)
|
||||
library_include_HEADERS = codec2.h \
|
||||
defines.h \
|
||||
four1.h \
|
||||
interp.h \
|
||||
lsp.h \
|
||||
phase.h \
|
||||
quantise.h \
|
||||
comp.h \
|
||||
dump.h \
|
||||
globals.h \
|
||||
lpc.h \
|
||||
nlp.h \
|
||||
postfilter.h \
|
||||
sine.h \
|
||||
codebook.h
|
||||
|
||||
bin_PROGRAMS = c2dec c2enc c2sim
|
||||
|
||||
c2dec_SOURCES = c2dec.c
|
||||
c2dec_LDADD = $(lib_LTLIBRARIES)
|
||||
c2dec_LDFLAGS = $(LIBS)
|
||||
|
||||
c2enc_SOURCES = c2enc.c
|
||||
c2enc_LDADD = $(lib_LTLIBRARIES)
|
||||
c2enc_LDFLAGS = $(LIBS)
|
||||
|
||||
c2sim_SOURCES = c2sim.c
|
||||
c2sim_LDADD = $(lib_LTLIBRARIES)
|
||||
c2sim_LDFLAGS = $(LIBS)
|
690
libs/libcodec2/src/Makefile.in
Normal file
690
libs/libcodec2/src/Makefile.in
Normal file
@@ -0,0 +1,690 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = c2dec$(EXEEXT) c2enc$(EXEEXT) c2sim$(EXEEXT)
|
||||
subdir = src
|
||||
DIST_COMMON = $(library_include_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
|
||||
"$(DESTDIR)$(library_includedir)"
|
||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libcodec2_la_LIBADD =
|
||||
am_libcodec2_la_OBJECTS = libcodec2_la-dump.lo libcodec2_la-lpc.lo \
|
||||
libcodec2_la-nlp.lo libcodec2_la-postfilter.lo \
|
||||
libcodec2_la-sine.lo libcodec2_la-codec2.lo \
|
||||
libcodec2_la-four1.lo libcodec2_la-interp.lo \
|
||||
libcodec2_la-lsp.lo libcodec2_la-phase.lo \
|
||||
libcodec2_la-quantise.lo libcodec2_la-pack.lo \
|
||||
libcodec2_la-codebook.lo
|
||||
libcodec2_la_OBJECTS = $(am_libcodec2_la_OBJECTS)
|
||||
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am_c2dec_OBJECTS = c2dec.$(OBJEXT)
|
||||
c2dec_OBJECTS = $(am_c2dec_OBJECTS)
|
||||
am__DEPENDENCIES_1 = libcodec2.la
|
||||
c2dec_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_c2enc_OBJECTS = c2enc.$(OBJEXT)
|
||||
c2enc_OBJECTS = $(am_c2enc_OBJECTS)
|
||||
c2enc_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_c2sim_OBJECTS = c2sim.$(OBJEXT)
|
||||
c2sim_OBJECTS = $(am_c2sim_OBJECTS)
|
||||
c2sim_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) $(c2enc_SOURCES) \
|
||||
$(c2sim_SOURCES)
|
||||
DIST_SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) \
|
||||
$(c2enc_SOURCES) $(c2sim_SOURCES)
|
||||
library_includeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||
HEADERS = $(library_include_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
GREP = @GREP@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
AM_CFLAGS = -I../src -Wall -DFLOATING_POINT -DVAR_ARRAYS
|
||||
AUTOMAKE_OPTS = gnu
|
||||
NAME = libcodec2
|
||||
AM_CPPFLAGS = $(AM_CFLAGS)
|
||||
lib_LTLIBRARIES = libcodec2.la
|
||||
libcodec2_la_SOURCES = dump.c \
|
||||
lpc.c \
|
||||
nlp.c \
|
||||
postfilter.c \
|
||||
sine.c \
|
||||
codec2.c \
|
||||
four1.c \
|
||||
interp.c \
|
||||
lsp.c \
|
||||
phase.c \
|
||||
quantise.c \
|
||||
pack.c \
|
||||
codebook.c
|
||||
|
||||
libcodec2_la_CFLAGS = $(AM_CFLAGS)
|
||||
libcodec2_la_LDFLAGS = $(LIBS)
|
||||
library_includedir = $(prefix)
|
||||
library_include_HEADERS = codec2.h \
|
||||
defines.h \
|
||||
four1.h \
|
||||
interp.h \
|
||||
lsp.h \
|
||||
phase.h \
|
||||
quantise.h \
|
||||
comp.h \
|
||||
dump.h \
|
||||
globals.h \
|
||||
lpc.h \
|
||||
nlp.h \
|
||||
postfilter.h \
|
||||
sine.h \
|
||||
codebook.h
|
||||
|
||||
c2dec_SOURCES = c2dec.c
|
||||
c2dec_LDADD = $(lib_LTLIBRARIES)
|
||||
c2dec_LDFLAGS = $(LIBS)
|
||||
c2enc_SOURCES = c2enc.c
|
||||
c2enc_LDADD = $(lib_LTLIBRARIES)
|
||||
c2enc_LDFLAGS = $(LIBS)
|
||||
c2sim_SOURCES = c2sim.c
|
||||
c2sim_LDADD = $(lib_LTLIBRARIES)
|
||||
c2sim_LDFLAGS = $(LIBS)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu src/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
p=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
|
||||
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
|
||||
done
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libcodec2.la: $(libcodec2_la_OBJECTS) $(libcodec2_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libcodec2_la_LDFLAGS) $(libcodec2_la_OBJECTS) $(libcodec2_la_LIBADD) $(LIBS)
|
||||
install-binPROGRAMS: $(bin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
if test -f $$p \
|
||||
|| test -f $$p1 \
|
||||
; then \
|
||||
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-binPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(bindir)/$$f"; \
|
||||
done
|
||||
|
||||
clean-binPROGRAMS:
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
echo " rm -f $$p $$f"; \
|
||||
rm -f $$p $$f ; \
|
||||
done
|
||||
c2dec$(EXEEXT): $(c2dec_OBJECTS) $(c2dec_DEPENDENCIES)
|
||||
@rm -f c2dec$(EXEEXT)
|
||||
$(LINK) $(c2dec_LDFLAGS) $(c2dec_OBJECTS) $(c2dec_LDADD) $(LIBS)
|
||||
c2enc$(EXEEXT): $(c2enc_OBJECTS) $(c2enc_DEPENDENCIES)
|
||||
@rm -f c2enc$(EXEEXT)
|
||||
$(LINK) $(c2enc_LDFLAGS) $(c2enc_OBJECTS) $(c2enc_LDADD) $(LIBS)
|
||||
c2sim$(EXEEXT): $(c2sim_OBJECTS) $(c2sim_DEPENDENCIES)
|
||||
@rm -f c2sim$(EXEEXT)
|
||||
$(LINK) $(c2sim_LDFLAGS) $(c2sim_OBJECTS) $(c2sim_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2dec.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2enc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2sim.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebook.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codec2.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-dump.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-four1.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-interp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-lpc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-lsp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-nlp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-pack.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-phase.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-postfilter.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-quantise.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-sine.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
libcodec2_la-dump.lo: dump.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-dump.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-dump.Tpo" -c -o libcodec2_la-dump.lo `test -f 'dump.c' || echo '$(srcdir)/'`dump.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-dump.Tpo" "$(DEPDIR)/libcodec2_la-dump.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-dump.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dump.c' object='libcodec2_la-dump.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-dump.lo `test -f 'dump.c' || echo '$(srcdir)/'`dump.c
|
||||
|
||||
libcodec2_la-lpc.lo: lpc.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-lpc.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-lpc.Tpo" -c -o libcodec2_la-lpc.lo `test -f 'lpc.c' || echo '$(srcdir)/'`lpc.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-lpc.Tpo" "$(DEPDIR)/libcodec2_la-lpc.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-lpc.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lpc.c' object='libcodec2_la-lpc.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-lpc.lo `test -f 'lpc.c' || echo '$(srcdir)/'`lpc.c
|
||||
|
||||
libcodec2_la-nlp.lo: nlp.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-nlp.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-nlp.Tpo" -c -o libcodec2_la-nlp.lo `test -f 'nlp.c' || echo '$(srcdir)/'`nlp.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-nlp.Tpo" "$(DEPDIR)/libcodec2_la-nlp.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-nlp.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nlp.c' object='libcodec2_la-nlp.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-nlp.lo `test -f 'nlp.c' || echo '$(srcdir)/'`nlp.c
|
||||
|
||||
libcodec2_la-postfilter.lo: postfilter.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-postfilter.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-postfilter.Tpo" -c -o libcodec2_la-postfilter.lo `test -f 'postfilter.c' || echo '$(srcdir)/'`postfilter.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-postfilter.Tpo" "$(DEPDIR)/libcodec2_la-postfilter.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-postfilter.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='postfilter.c' object='libcodec2_la-postfilter.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-postfilter.lo `test -f 'postfilter.c' || echo '$(srcdir)/'`postfilter.c
|
||||
|
||||
libcodec2_la-sine.lo: sine.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-sine.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-sine.Tpo" -c -o libcodec2_la-sine.lo `test -f 'sine.c' || echo '$(srcdir)/'`sine.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-sine.Tpo" "$(DEPDIR)/libcodec2_la-sine.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-sine.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sine.c' object='libcodec2_la-sine.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-sine.lo `test -f 'sine.c' || echo '$(srcdir)/'`sine.c
|
||||
|
||||
libcodec2_la-codec2.lo: codec2.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-codec2.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-codec2.Tpo" -c -o libcodec2_la-codec2.lo `test -f 'codec2.c' || echo '$(srcdir)/'`codec2.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-codec2.Tpo" "$(DEPDIR)/libcodec2_la-codec2.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-codec2.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='codec2.c' object='libcodec2_la-codec2.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-codec2.lo `test -f 'codec2.c' || echo '$(srcdir)/'`codec2.c
|
||||
|
||||
libcodec2_la-four1.lo: four1.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-four1.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-four1.Tpo" -c -o libcodec2_la-four1.lo `test -f 'four1.c' || echo '$(srcdir)/'`four1.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-four1.Tpo" "$(DEPDIR)/libcodec2_la-four1.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-four1.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='four1.c' object='libcodec2_la-four1.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-four1.lo `test -f 'four1.c' || echo '$(srcdir)/'`four1.c
|
||||
|
||||
libcodec2_la-interp.lo: interp.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-interp.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-interp.Tpo" -c -o libcodec2_la-interp.lo `test -f 'interp.c' || echo '$(srcdir)/'`interp.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-interp.Tpo" "$(DEPDIR)/libcodec2_la-interp.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-interp.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='interp.c' object='libcodec2_la-interp.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-interp.lo `test -f 'interp.c' || echo '$(srcdir)/'`interp.c
|
||||
|
||||
libcodec2_la-lsp.lo: lsp.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-lsp.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-lsp.Tpo" -c -o libcodec2_la-lsp.lo `test -f 'lsp.c' || echo '$(srcdir)/'`lsp.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-lsp.Tpo" "$(DEPDIR)/libcodec2_la-lsp.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-lsp.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lsp.c' object='libcodec2_la-lsp.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-lsp.lo `test -f 'lsp.c' || echo '$(srcdir)/'`lsp.c
|
||||
|
||||
libcodec2_la-phase.lo: phase.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-phase.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-phase.Tpo" -c -o libcodec2_la-phase.lo `test -f 'phase.c' || echo '$(srcdir)/'`phase.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-phase.Tpo" "$(DEPDIR)/libcodec2_la-phase.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-phase.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='phase.c' object='libcodec2_la-phase.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-phase.lo `test -f 'phase.c' || echo '$(srcdir)/'`phase.c
|
||||
|
||||
libcodec2_la-quantise.lo: quantise.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-quantise.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-quantise.Tpo" -c -o libcodec2_la-quantise.lo `test -f 'quantise.c' || echo '$(srcdir)/'`quantise.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-quantise.Tpo" "$(DEPDIR)/libcodec2_la-quantise.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-quantise.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='quantise.c' object='libcodec2_la-quantise.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-quantise.lo `test -f 'quantise.c' || echo '$(srcdir)/'`quantise.c
|
||||
|
||||
libcodec2_la-pack.lo: pack.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-pack.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-pack.Tpo" -c -o libcodec2_la-pack.lo `test -f 'pack.c' || echo '$(srcdir)/'`pack.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-pack.Tpo" "$(DEPDIR)/libcodec2_la-pack.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-pack.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pack.c' object='libcodec2_la-pack.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-pack.lo `test -f 'pack.c' || echo '$(srcdir)/'`pack.c
|
||||
|
||||
libcodec2_la-codebook.lo: codebook.c
|
||||
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-codebook.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-codebook.Tpo" -c -o libcodec2_la-codebook.lo `test -f 'codebook.c' || echo '$(srcdir)/'`codebook.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-codebook.Tpo" "$(DEPDIR)/libcodec2_la-codebook.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-codebook.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='codebook.c' object='libcodec2_la-codebook.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-codebook.lo `test -f 'codebook.c' || echo '$(srcdir)/'`codebook.c
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
install-library_includeHEADERS: $(library_include_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(library_includedir)" || $(mkdir_p) "$(DESTDIR)$(library_includedir)"
|
||||
@list='$(library_include_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(library_includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(library_includedir)/$$f'"; \
|
||||
$(library_includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(library_includedir)/$$f"; \
|
||||
done
|
||||
|
||||
uninstall-library_includeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(library_include_HEADERS)'; for p in $$list; do \
|
||||
f=$(am__strip_dir) \
|
||||
echo " rm -f '$(DESTDIR)$(library_includedir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(library_includedir)/$$f"; \
|
||||
done
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
|
||||
install-binPROGRAMS: install-libLTLIBRARIES
|
||||
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(library_includedir)"; do \
|
||||
test -z "$$dir" || $(mkdir_p) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
|
||||
clean-libtool mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-library_includeHEADERS
|
||||
|
||||
install-exec-am: install-binPROGRAMS install-libLTLIBRARIES
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-binPROGRAMS uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES uninstall-library_includeHEADERS
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
|
||||
clean-generic clean-libLTLIBRARIES clean-libtool ctags \
|
||||
distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-binPROGRAMS \
|
||||
install-data install-data-am install-exec install-exec-am \
|
||||
install-info install-info-am install-libLTLIBRARIES \
|
||||
install-library_includeHEADERS install-man install-strip \
|
||||
installcheck installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am uninstall-binPROGRAMS \
|
||||
uninstall-info-am uninstall-libLTLIBRARIES \
|
||||
uninstall-library_includeHEADERS
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
80
libs/libcodec2/src/c2dec.c
Normal file
80
libs/libcodec2/src/c2dec.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: c2dec.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/8/2010
|
||||
|
||||
Decodes a file of bits to a file of raw speech samples using codec2. Demo
|
||||
program for codec2.
|
||||
|
||||
NOTE: the bit file is not packed, 51 bits/frame actually consumes 51
|
||||
bytes/frame on disk. If you are using this for a real world
|
||||
application you may want to pack the 51 bytes into 7 bytes.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "codec2.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
static const int bitsSize = ((CODEC2_BITS_PER_FRAME + 7) / 8);
|
||||
void *codec2;
|
||||
FILE *fin;
|
||||
FILE *fout;
|
||||
short buf[CODEC2_SAMPLES_PER_FRAME];
|
||||
unsigned char bits[bitsSize];
|
||||
|
||||
if (argc != 3) {
|
||||
printf("usage: %s InputBitFile OutputRawSpeechFile\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( (fin = fopen(argv[1],"rb")) == NULL ) {
|
||||
fprintf(stderr, "Error opening input bit file: %s: %s.\n",
|
||||
argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( (fout = fopen(argv[2],"wb")) == NULL ) {
|
||||
fprintf(stderr, "Error opening output speech file: %s: %s.\n",
|
||||
argv[2], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
codec2 = codec2_create();
|
||||
|
||||
while(fread(bits, sizeof(char), bitsSize, fin) == bitsSize) {
|
||||
codec2_decode(codec2, buf, bits);
|
||||
fwrite(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fout);
|
||||
}
|
||||
|
||||
codec2_destroy(codec2);
|
||||
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
return 0;
|
||||
}
|
82
libs/libcodec2/src/c2enc.c
Normal file
82
libs/libcodec2/src/c2enc.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: c2enc.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/8/2010
|
||||
|
||||
Encodes a file of raw speech samples using codec2 and ouputs a file
|
||||
of bits (each bit is stored in the LSB or each output byte). Demo
|
||||
program for codec2.
|
||||
|
||||
NOTE: the bit file is not packed, 51 bits/frame actually consumes 51
|
||||
bytes/frame on disk. If you are using this for a real world
|
||||
application you may want to pack the 51 bytes into 7 bytes.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "codec2.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
static const int bitsSize = ((CODEC2_BITS_PER_FRAME + 7) / 8);
|
||||
void *codec2;
|
||||
FILE *fin;
|
||||
FILE *fout;
|
||||
short buf[CODEC2_SAMPLES_PER_FRAME];
|
||||
unsigned char bits[bitsSize];
|
||||
|
||||
if (argc != 3) {
|
||||
printf("usage: %s InputRawspeechFile OutputBitFile\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( (fin = fopen(argv[1],"rb")) == NULL ) {
|
||||
fprintf(stderr, "Error opening input bit file: %s: %s.\n",
|
||||
argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( (fout = fopen(argv[2],"wb")) == NULL ) {
|
||||
fprintf(stderr, "Error opening output speech file: %s: %s.\n",
|
||||
argv[2], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
codec2 = codec2_create();
|
||||
|
||||
while(fread(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fin) ==
|
||||
CODEC2_SAMPLES_PER_FRAME) {
|
||||
codec2_encode(codec2, bits, buf);
|
||||
fwrite(bits, sizeof(char), bitsSize, fout);
|
||||
}
|
||||
|
||||
codec2_destroy(codec2);
|
||||
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
return 0;
|
||||
}
|
408
libs/libcodec2/src/c2sim.c
Normal file
408
libs/libcodec2/src/c2sim.c
Normal file
@@ -0,0 +1,408 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: c2sim.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 20/8/2010
|
||||
|
||||
Codec2 simulation. Combines encoder and decoder and allows switching in
|
||||
out various algorithms and quantisation steps.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "sine.h"
|
||||
#include "nlp.h"
|
||||
#include "dump.h"
|
||||
#include "lpc.h"
|
||||
#include "lsp.h"
|
||||
#include "quantise.h"
|
||||
#include "phase.h"
|
||||
#include "postfilter.h"
|
||||
#include "interp.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
switch_present()
|
||||
|
||||
Searches the command line arguments for a "switch". If the switch is
|
||||
found, returns the command line argument where it ws found, else returns
|
||||
NULL.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int switch_present(sw,argc,argv)
|
||||
register char sw[]; /* switch in string form */
|
||||
register int argc; /* number of command line arguments */
|
||||
register char *argv[]; /* array of command line arguments in string form */
|
||||
{
|
||||
register int i; /* loop variable */
|
||||
|
||||
for(i=1; i<argc; i++)
|
||||
if (!strcmp(sw,argv[i]))
|
||||
return(i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
MAIN
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fout; /* output speech file */
|
||||
FILE *fin; /* input speech file */
|
||||
short buf[N]; /* input/output buffer */
|
||||
float Sn[M]; /* float input speech samples */
|
||||
COMP Sw[FFT_ENC]; /* DFT of Sn[] */
|
||||
float w[M]; /* time domain hamming window */
|
||||
COMP W[FFT_ENC]; /* DFT of w[] */
|
||||
MODEL model;
|
||||
float Pn[2*N]; /* trapezoidal synthesis window */
|
||||
float Sn_[2*N]; /* synthesised speech */
|
||||
int i; /* loop variable */
|
||||
int frames;
|
||||
float prev_Wo;
|
||||
float pitch;
|
||||
int voiced1;
|
||||
|
||||
char out_file[MAX_STR];
|
||||
int arg;
|
||||
float snr;
|
||||
float sum_snr;
|
||||
|
||||
int lpc_model, order;
|
||||
int lsp, lsp_quantiser;
|
||||
float ak[LPC_MAX];
|
||||
COMP Sw_[FFT_ENC];
|
||||
|
||||
int dump;
|
||||
|
||||
int phase0;
|
||||
float ex_phase[MAX_AMP+1];
|
||||
|
||||
int postfilt;
|
||||
float bg_est;
|
||||
|
||||
int hand_voicing;
|
||||
FILE *fvoicing;
|
||||
|
||||
MODEL prev_model, interp_model;
|
||||
int decimate;
|
||||
|
||||
void *nlp_states;
|
||||
|
||||
for(i=0; i<M; i++)
|
||||
Sn[i] = 1.0;
|
||||
for(i=0; i<2*N; i++)
|
||||
Sn_[i] = 0;
|
||||
|
||||
prev_Wo = TWO_PI/P_MAX;
|
||||
|
||||
prev_model.Wo = TWO_PI/P_MIN;
|
||||
prev_model.L = floor(PI/prev_model.Wo);
|
||||
for(i=1; i<=prev_model.L; i++) {
|
||||
prev_model.A[i] = 0.0;
|
||||
prev_model.phi[i] = 0.0;
|
||||
}
|
||||
for(i=1; i<=MAX_AMP; i++) {
|
||||
ex_phase[i] = 0.0;
|
||||
}
|
||||
|
||||
nlp_states = nlp_create();
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "\nCodec2 - 2400 bit/s speech codec - Simulation Program\n"
|
||||
"\thttp://rowetel.com/codec2.html\n\n"
|
||||
"usage: %s InputFile [-o OutputFile]\n"
|
||||
"\t[-o lpc Order]\n"
|
||||
"\t[--lsp]\n"
|
||||
"\t[--phase0]\n"
|
||||
"\t[--postfilter]\n"
|
||||
"\t[--hand_voicing]\n"
|
||||
"\t[--dec]\n"
|
||||
"\t[--dump DumpFilePrefix]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Interpret command line arguments -------------------------------------*/
|
||||
|
||||
/* Input file */
|
||||
|
||||
if ((fin = fopen(argv[1],"rb")) == NULL) {
|
||||
fprintf(stderr, "Error opening input bit file: %s: %s.\n",
|
||||
argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Output file */
|
||||
|
||||
if ((arg = switch_present("-o",argc,argv))) {
|
||||
if ((fout = fopen(argv[arg+1],"wb")) == NULL) {
|
||||
fprintf(stderr, "Error opening output speech file: %s: %s.\n",
|
||||
argv[arg+1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
strcpy(out_file,argv[arg+1]);
|
||||
}
|
||||
else
|
||||
fout = NULL;
|
||||
|
||||
lpc_model = 0;
|
||||
if ((arg = switch_present("--lpc",argc,argv))) {
|
||||
lpc_model = 1;
|
||||
order = atoi(argv[arg+1]);
|
||||
if ((order < 4) || (order > 20)) {
|
||||
fprintf(stderr, "Error in lpc order: %d\n", order);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
dump = switch_present("--dump",argc,argv);
|
||||
if (dump)
|
||||
dump_on(argv[dump+1]);
|
||||
|
||||
lsp = switch_present("--lsp",argc,argv);
|
||||
lsp_quantiser = 0;
|
||||
|
||||
phase0 = switch_present("--phase0",argc,argv);
|
||||
if (phase0) {
|
||||
ex_phase[0] = 0;
|
||||
}
|
||||
|
||||
hand_voicing = switch_present("--hand_voicing",argc,argv);
|
||||
if (hand_voicing) {
|
||||
fvoicing = fopen(argv[hand_voicing+1],"rt");
|
||||
assert(fvoicing != NULL);
|
||||
}
|
||||
|
||||
bg_est = 0.0;
|
||||
postfilt = switch_present("--postfilter",argc,argv);
|
||||
|
||||
decimate = switch_present("--dec",argc,argv);
|
||||
|
||||
/* Initialise ------------------------------------------------------------*/
|
||||
|
||||
make_analysis_window(w,W);
|
||||
make_synthesis_window(Pn);
|
||||
quantise_init();
|
||||
|
||||
/* Main loop ------------------------------------------------------------*/
|
||||
|
||||
frames = 0;
|
||||
sum_snr = 0;
|
||||
while(fread(buf,sizeof(short),N,fin)) {
|
||||
frames++;
|
||||
|
||||
/* Read input speech */
|
||||
|
||||
for(i=0; i<M-N; i++)
|
||||
Sn[i] = Sn[i+N];
|
||||
for(i=0; i<N; i++)
|
||||
Sn[i+M-N] = buf[i];
|
||||
|
||||
/* Estimate pitch */
|
||||
|
||||
nlp(nlp_states,Sn,N,M,P_MIN,P_MAX,&pitch,Sw,&prev_Wo);
|
||||
prev_Wo = TWO_PI/pitch;
|
||||
model.Wo = TWO_PI/pitch;
|
||||
|
||||
/* estimate model parameters */
|
||||
|
||||
dft_speech(Sw, Sn, w);
|
||||
two_stage_pitch_refinement(&model, Sw);
|
||||
estimate_amplitudes(&model, Sw, W);
|
||||
dump_Sn(Sn); dump_Sw(Sw); dump_model(&model);
|
||||
|
||||
/* optional zero-phase modelling */
|
||||
|
||||
if (phase0) {
|
||||
float Wn[M]; /* windowed speech samples */
|
||||
float Rk[LPC_ORD+1]; /* autocorrelation coeffs */
|
||||
|
||||
dump_phase(&model.phi[0], model.L);
|
||||
|
||||
/* find aks here, these are overwritten if LPC modelling is enabled */
|
||||
|
||||
for(i=0; i<M; i++)
|
||||
Wn[i] = Sn[i]*w[i];
|
||||
autocorrelate(Wn,Rk,M,LPC_ORD);
|
||||
levinson_durbin(Rk,ak,LPC_ORD);
|
||||
|
||||
if (lpc_model)
|
||||
assert(order == LPC_ORD);
|
||||
|
||||
dump_ak(ak, LPC_ORD);
|
||||
|
||||
/* determine voicing */
|
||||
|
||||
snr = est_voicing_mbe(&model, Sw, W, (FS/TWO_PI)*model.Wo, Sw_);
|
||||
dump_Sw_(Sw_);
|
||||
dump_snr(snr);
|
||||
|
||||
/* just to make sure we are not cheating - kill all phases */
|
||||
|
||||
for(i=0; i<MAX_AMP; i++)
|
||||
model.phi[i] = 0;
|
||||
|
||||
if (hand_voicing) {
|
||||
fscanf(fvoicing,"%d\n",&model.voiced);
|
||||
}
|
||||
}
|
||||
|
||||
/* optional LPC model amplitudes */
|
||||
|
||||
if (lpc_model) {
|
||||
int lpc_correction;
|
||||
float e;
|
||||
float lsps[LPC_ORD];
|
||||
int lsp_indexes[LPC_ORD];
|
||||
|
||||
e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
|
||||
lpc_correction = need_lpc_correction(&model, ak, e);
|
||||
|
||||
if (lsp) {
|
||||
encode_lsps(lsp_indexes, lsps, LPC_ORD);
|
||||
/*
|
||||
for(i=0; i<LPC_ORD; i++)
|
||||
printf("lsps[%d] = %f lsp_indexes[%d] = %d\n",
|
||||
i, lsps[i], i, lsp_indexes[i]);
|
||||
printf("\n");
|
||||
*/
|
||||
decode_lsps(lsps, lsp_indexes, LPC_ORD);
|
||||
bw_expand_lsps(lsps, LPC_ORD);
|
||||
lsp_to_lpc(lsps, ak, LPC_ORD);
|
||||
}
|
||||
|
||||
e = decode_energy(encode_energy(e));
|
||||
model.Wo = decode_Wo(encode_Wo(model.Wo));
|
||||
|
||||
aks_to_M2(ak, order, &model, e, &snr, 1);
|
||||
apply_lpc_correction(&model, lpc_correction);
|
||||
sum_snr += snr;
|
||||
dump_quantised_model(&model);
|
||||
}
|
||||
|
||||
/* option decimation to 20ms rate, which enables interpolation
|
||||
routine to synthesise in between frame */
|
||||
|
||||
if (decimate) {
|
||||
if (!phase0) {
|
||||
printf("needs --phase0 to resample phase for interpolated Wo\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* odd frame - interpolate */
|
||||
|
||||
if (frames%2) {
|
||||
|
||||
#ifdef TEST
|
||||
model.voiced = 1;
|
||||
prev_model.voiced = 1;
|
||||
if (fabs(prev_model.Wo - model.Wo) < 0.1*model.Wo) {
|
||||
interp_model.voiced = 1;
|
||||
interpolate(&interp_model, &prev_model, &model);
|
||||
for(i=0; i<=interp_model.L; i++) {
|
||||
interp_model.phi[i] = phi1[i];
|
||||
}
|
||||
printf("interp\n");
|
||||
}
|
||||
else
|
||||
interp_model = tmp_model;
|
||||
#endif
|
||||
|
||||
interp_model.voiced = voiced1;
|
||||
interpolate(&interp_model, &prev_model, &model);
|
||||
|
||||
if (phase0)
|
||||
phase_synth_zero_order(&interp_model, ak, ex_phase);
|
||||
if (postfilt)
|
||||
postfilter(&interp_model, &bg_est);
|
||||
synth_one_frame(buf, &interp_model, Sn_, Pn);
|
||||
if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
|
||||
|
||||
if (phase0)
|
||||
phase_synth_zero_order(&model, ak, ex_phase);
|
||||
if (postfilt)
|
||||
postfilter(&model, &bg_est);
|
||||
synth_one_frame(buf, &model, Sn_, Pn);
|
||||
if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
|
||||
|
||||
prev_model = model;
|
||||
}
|
||||
else {
|
||||
voiced1 = model.voiced;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (phase0)
|
||||
phase_synth_zero_order(&model, ak, ex_phase);
|
||||
if (postfilt)
|
||||
postfilter(&model, &bg_est);
|
||||
synth_one_frame(buf, &model, Sn_, Pn);
|
||||
if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
|
||||
}
|
||||
}
|
||||
|
||||
if (fout != NULL)
|
||||
fclose(fout);
|
||||
|
||||
if (lpc_model)
|
||||
printf("SNR av = %5.2f dB\n", sum_snr/frames);
|
||||
|
||||
if (dump)
|
||||
dump_off();
|
||||
|
||||
if (hand_voicing)
|
||||
fclose(fvoicing);
|
||||
|
||||
nlp_destroy(nlp_states);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[])
|
||||
{
|
||||
int i;
|
||||
|
||||
synthesise(Sn_, model, Pn, 1);
|
||||
|
||||
for(i=0; i<N; i++) {
|
||||
if (Sn_[i] > 32767.0)
|
||||
buf[i] = 32767;
|
||||
else if (Sn_[i] < -32767.0)
|
||||
buf[i] = -32767;
|
||||
else
|
||||
buf[i] = Sn_[i];
|
||||
}
|
||||
|
||||
}
|
9
libs/libcodec2/src/codeall.sh
Executable file
9
libs/libcodec2/src/codeall.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# codeall.sh
|
||||
# David Rowe 24 sep 2009
|
||||
# Code all samples using various processing steps
|
||||
./code.sh hts1a
|
||||
./code.sh hts2a
|
||||
./code.sh mmt1
|
||||
./code.sh morig
|
||||
./code.sh forig
|
162
libs/libcodec2/src/codebook.c
Normal file
162
libs/libcodec2/src/codebook.c
Normal file
@@ -0,0 +1,162 @@
|
||||
float codebook_lsp1[] = {
|
||||
225,
|
||||
250,
|
||||
275,
|
||||
300,
|
||||
325,
|
||||
350,
|
||||
375,
|
||||
400,
|
||||
425,
|
||||
450,
|
||||
475,
|
||||
500,
|
||||
525,
|
||||
550,
|
||||
575,
|
||||
600,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp2[] = {
|
||||
325,
|
||||
350,
|
||||
375,
|
||||
400,
|
||||
425,
|
||||
450,
|
||||
475,
|
||||
500,
|
||||
525,
|
||||
550,
|
||||
575,
|
||||
600,
|
||||
625,
|
||||
650,
|
||||
675,
|
||||
700,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp3[] = {
|
||||
500,
|
||||
550,
|
||||
600,
|
||||
650,
|
||||
700,
|
||||
750,
|
||||
800,
|
||||
850,
|
||||
900,
|
||||
950,
|
||||
1000,
|
||||
1050,
|
||||
1100,
|
||||
1150,
|
||||
1200,
|
||||
1250,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp4[] = {
|
||||
700,
|
||||
800,
|
||||
900,
|
||||
1000,
|
||||
1100,
|
||||
1200,
|
||||
1300,
|
||||
1400,
|
||||
1500,
|
||||
1600,
|
||||
1700,
|
||||
1800,
|
||||
1900,
|
||||
2000,
|
||||
2100,
|
||||
2200,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp5[] = {
|
||||
950,
|
||||
1050,
|
||||
1150,
|
||||
1250,
|
||||
1350,
|
||||
1450,
|
||||
1550,
|
||||
1650,
|
||||
1750,
|
||||
1850,
|
||||
1950,
|
||||
2050,
|
||||
2150,
|
||||
2250,
|
||||
2350,
|
||||
2450,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp6[] = {
|
||||
1100,
|
||||
1200,
|
||||
1300,
|
||||
1400,
|
||||
1500,
|
||||
1600,
|
||||
1700,
|
||||
1800,
|
||||
1900,
|
||||
2000,
|
||||
2100,
|
||||
2200,
|
||||
2300,
|
||||
2400,
|
||||
2500,
|
||||
2600,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp7[] = {
|
||||
1500,
|
||||
1600,
|
||||
1700,
|
||||
1800,
|
||||
1900,
|
||||
2000,
|
||||
2100,
|
||||
2200,
|
||||
2300,
|
||||
2400,
|
||||
2500,
|
||||
2600,
|
||||
2700,
|
||||
2800,
|
||||
2900,
|
||||
3000,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp8[] = {
|
||||
2300,
|
||||
2400,
|
||||
2500,
|
||||
2600,
|
||||
2700,
|
||||
2800,
|
||||
2900,
|
||||
3000,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp9[] = {
|
||||
2500,
|
||||
2600,
|
||||
2700,
|
||||
2800,
|
||||
2900,
|
||||
3000,
|
||||
3100,
|
||||
3200,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
float codebook_lsp10[] = {
|
||||
2900,
|
||||
3100,
|
||||
3300,
|
||||
3500,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
15
libs/libcodec2/src/codebook.h
Normal file
15
libs/libcodec2/src/codebook.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef CODEBOOK_H
|
||||
#define CODEBOOK_H
|
||||
|
||||
extern float codebook_lsp1[];
|
||||
extern float codebook_lsp2[];
|
||||
extern float codebook_lsp3[];
|
||||
extern float codebook_lsp4[];
|
||||
extern float codebook_lsp5[];
|
||||
extern float codebook_lsp6[];
|
||||
extern float codebook_lsp7[];
|
||||
extern float codebook_lsp8[];
|
||||
extern float codebook_lsp9[];
|
||||
extern float codebook_lsp10[];
|
||||
|
||||
#endif
|
337
libs/libcodec2/src/codec2.c
Normal file
337
libs/libcodec2/src/codec2.c
Normal file
@@ -0,0 +1,337 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: codec2.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Codec2 fully quantised encoder and decoder functions. If you want use
|
||||
codec2, the codec2_xxx functions are for you.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "sine.h"
|
||||
#include "nlp.h"
|
||||
#include "dump.h"
|
||||
#include "lpc.h"
|
||||
#include "quantise.h"
|
||||
#include "phase.h"
|
||||
#include "interp.h"
|
||||
#include "postfilter.h"
|
||||
#include "codec2.h"
|
||||
|
||||
typedef struct {
|
||||
float Sn[M]; /* input speech */
|
||||
float w[M]; /* time domain hamming window */
|
||||
COMP W[FFT_ENC]; /* DFT of w[] */
|
||||
float Pn[2*N]; /* trapezoidal synthesis window */
|
||||
float Sn_[2*N]; /* synthesised speech */
|
||||
float prev_Wo; /* previous frame's pitch estimate */
|
||||
float ex_phase; /* excitation model phase track */
|
||||
float bg_est; /* background noise estimate for post filter */
|
||||
MODEL prev_model; /* model parameters from 20ms ago */
|
||||
void *nlp; /* pitch predictor states */
|
||||
} CODEC2;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION HEADERS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[]);
|
||||
void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model,float ak[]);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: codec2_create
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Create and initialise an instance of the codec. Returns a pointer
|
||||
to the codec states or NULL on failure. One set of states is
|
||||
sufficient for a full duuplex codec (i.e. an encoder and decoder).
|
||||
You don't need separate states for encoders and decoders. See
|
||||
c2enc.c and c2dec.c for examples.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void *codec2_create()
|
||||
{
|
||||
CODEC2 *c2;
|
||||
int i,l;
|
||||
|
||||
c2 = (CODEC2*)malloc(sizeof(CODEC2));
|
||||
if (c2 == NULL)
|
||||
return NULL;
|
||||
|
||||
for(i=0; i<M; i++)
|
||||
c2->Sn[i] = 1.0;
|
||||
for(i=0; i<2*N; i++)
|
||||
c2->Sn_[i] = 0;
|
||||
make_analysis_window(c2->w,c2->W);
|
||||
make_synthesis_window(c2->Pn);
|
||||
quantise_init();
|
||||
c2->prev_Wo = 0.0;
|
||||
c2->bg_est = 0.0;
|
||||
c2->ex_phase = 0.0;
|
||||
|
||||
for(l=1; l<=MAX_AMP; l++)
|
||||
c2->prev_model.A[l] = 0.0;
|
||||
c2->prev_model.Wo = TWO_PI/P_MAX;
|
||||
|
||||
c2->nlp = nlp_create();
|
||||
if (c2->nlp == NULL) {
|
||||
free (c2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void*)c2;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: codec2_create
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Destroy an instance of the codec.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void codec2_destroy(void *codec2_state)
|
||||
{
|
||||
CODEC2 *c2;
|
||||
|
||||
assert(codec2_state != NULL);
|
||||
c2 = (CODEC2*)codec2_state;
|
||||
nlp_destroy(c2->nlp);
|
||||
free(codec2_state);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: codec2_encode
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Encodes 160 speech samples (20ms of speech) into 51 bits.
|
||||
|
||||
The codec2 algorithm actually operates internally on 10ms (80
|
||||
sample) frames, so we run the encoding algorithm twice. On the
|
||||
first frame we just send the voicing bit. One the second frame we
|
||||
send all model parameters.
|
||||
|
||||
The bit allocation is:
|
||||
|
||||
Parameter bits/frame
|
||||
--------------------------------------
|
||||
Harmonic magnitudes (LSPs) 36
|
||||
Low frequency LPC correction 1
|
||||
Energy 5
|
||||
Wo (fundamental frequnecy) 7
|
||||
Voicing (10ms update) 2
|
||||
TOTAL 51
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void codec2_encode(void *codec2_state, unsigned char * bits, short speech[])
|
||||
{
|
||||
CODEC2 *c2;
|
||||
MODEL model;
|
||||
int voiced1, voiced2;
|
||||
int lsp_indexes[LPC_ORD];
|
||||
int lpc_correction;
|
||||
int energy_index;
|
||||
int Wo_index;
|
||||
int i;
|
||||
unsigned int nbit = 0;
|
||||
|
||||
assert(codec2_state != NULL);
|
||||
c2 = (CODEC2*)codec2_state;
|
||||
|
||||
/* first 10ms analysis frame - we just want voicing */
|
||||
|
||||
analyse_one_frame(c2, &model, speech);
|
||||
voiced1 = model.voiced;
|
||||
|
||||
/* second 10ms analysis frame */
|
||||
|
||||
analyse_one_frame(c2, &model, &speech[N]);
|
||||
voiced2 = model.voiced;
|
||||
|
||||
Wo_index = encode_Wo(model.Wo);
|
||||
encode_amplitudes(lsp_indexes,
|
||||
&lpc_correction,
|
||||
&energy_index,
|
||||
&model,
|
||||
c2->Sn,
|
||||
c2->w);
|
||||
memset(bits, '\0', ((CODEC2_BITS_PER_FRAME + 7) / 8));
|
||||
pack(bits, &nbit, Wo_index, WO_BITS);
|
||||
for(i=0; i<LPC_ORD; i++) {
|
||||
pack(bits, &nbit, lsp_indexes[i], lsp_bits(i));
|
||||
}
|
||||
pack(bits, &nbit, lpc_correction, 1);
|
||||
pack(bits, &nbit, energy_index, E_BITS);
|
||||
pack(bits, &nbit, voiced1, 1);
|
||||
pack(bits, &nbit, voiced2, 1);
|
||||
|
||||
assert(nbit == CODEC2_BITS_PER_FRAME);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: codec2_decode
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Decodes frames of 51 bits into 160 samples (20ms) of speech.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void codec2_decode(void *codec2_state, short speech[],
|
||||
const unsigned char * bits)
|
||||
{
|
||||
CODEC2 *c2;
|
||||
MODEL model;
|
||||
int voiced1, voiced2;
|
||||
int lsp_indexes[LPC_ORD];
|
||||
int lpc_correction;
|
||||
int energy_index;
|
||||
int Wo_index;
|
||||
float ak[LPC_ORD+1];
|
||||
int i;
|
||||
unsigned int nbit = 0;
|
||||
MODEL model_interp;
|
||||
|
||||
assert(codec2_state != NULL);
|
||||
c2 = (CODEC2*)codec2_state;
|
||||
|
||||
Wo_index = unpack(bits, &nbit, WO_BITS);
|
||||
for(i=0; i<LPC_ORD; i++) {
|
||||
lsp_indexes[i] = unpack(bits, &nbit, lsp_bits(i));
|
||||
}
|
||||
lpc_correction = unpack(bits, &nbit, 1);
|
||||
energy_index = unpack(bits, &nbit, E_BITS);
|
||||
voiced1 = unpack(bits, &nbit, 1);
|
||||
voiced2 = unpack(bits, &nbit, 1);
|
||||
assert(nbit == CODEC2_BITS_PER_FRAME);
|
||||
|
||||
model.Wo = decode_Wo(Wo_index);
|
||||
model.L = PI/model.Wo;
|
||||
decode_amplitudes(&model,
|
||||
ak,
|
||||
lsp_indexes,
|
||||
lpc_correction,
|
||||
energy_index);
|
||||
|
||||
model.voiced = voiced2;
|
||||
model_interp.voiced = voiced1;
|
||||
interpolate(&model_interp, &c2->prev_model, &model);
|
||||
|
||||
synthesise_one_frame(c2, speech, &model_interp, ak);
|
||||
synthesise_one_frame(c2, &speech[N], &model, ak);
|
||||
|
||||
memcpy(&c2->prev_model, &model, sizeof(MODEL));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: synthesise_one_frame()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/8/2010
|
||||
|
||||
Synthesise 80 speech samples (10ms) from model parameters.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model, float ak[])
|
||||
{
|
||||
int i;
|
||||
|
||||
phase_synth_zero_order(model, ak, &c2->ex_phase);
|
||||
postfilter(model, &c2->bg_est);
|
||||
synthesise(c2->Sn_, model, c2->Pn, 1);
|
||||
|
||||
for(i=0; i<N; i++) {
|
||||
if (c2->Sn_[i] > 32767.0)
|
||||
speech[i] = 32767;
|
||||
else if (c2->Sn_[i] < -32767.0)
|
||||
speech[i] = -32767;
|
||||
else
|
||||
speech[i] = c2->Sn_[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: analyse_one_frame()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/8/2010
|
||||
|
||||
Extract sinusoidal model parameters from 80 speech samples (10ms of
|
||||
speech).
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[])
|
||||
{
|
||||
COMP Sw[FFT_ENC];
|
||||
COMP Sw_[FFT_ENC];
|
||||
float pitch;
|
||||
int i;
|
||||
|
||||
/* Read input speech */
|
||||
|
||||
for(i=0; i<M-N; i++)
|
||||
c2->Sn[i] = c2->Sn[i+N];
|
||||
for(i=0; i<N; i++)
|
||||
c2->Sn[i+M-N] = speech[i];
|
||||
dft_speech(Sw, c2->Sn, c2->w);
|
||||
|
||||
/* Estimate pitch */
|
||||
|
||||
nlp(c2->nlp,c2->Sn,N,M,P_MIN,P_MAX,&pitch,Sw,&c2->prev_Wo);
|
||||
c2->prev_Wo = TWO_PI/pitch;
|
||||
model->Wo = TWO_PI/pitch;
|
||||
model->L = PI/model->Wo;
|
||||
|
||||
/* estimate model parameters */
|
||||
|
||||
dft_speech(Sw, c2->Sn, c2->w);
|
||||
two_stage_pitch_refinement(model, Sw);
|
||||
estimate_amplitudes(model, Sw, c2->W);
|
||||
est_voicing_mbe(model, Sw, c2->W, (FS/TWO_PI)*model->Wo, Sw_);
|
||||
}
|
43
libs/libcodec2/src/codec2.h
Normal file
43
libs/libcodec2/src/codec2.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: codec2.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 21/8/2010
|
||||
|
||||
Codec2 fully quantised encoder and decoder functions. If you want use
|
||||
codec2, these are the functions you need to call.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __CODEC2__
|
||||
#define __CODEC2__
|
||||
#include "codebook.h"
|
||||
|
||||
#define CODEC2_SAMPLES_PER_FRAME 160
|
||||
#define CODEC2_BITS_PER_FRAME 51
|
||||
|
||||
void *codec2_create();
|
||||
void codec2_destroy(void *codec2_state);
|
||||
void codec2_encode(void *codec2_state, unsigned char * bits, short speech_in[]);
|
||||
void codec2_decode(void *codec2_state, short speech_out[],
|
||||
const unsigned char * bits);
|
||||
|
||||
#endif
|
39
libs/libcodec2/src/comp.h
Normal file
39
libs/libcodec2/src/comp.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: comp.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/08/09
|
||||
|
||||
Complex number definition.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __COMP__
|
||||
#define __COMP__
|
||||
|
||||
/* Complex number */
|
||||
|
||||
typedef struct {
|
||||
float real;
|
||||
float imag;
|
||||
} COMP;
|
||||
|
||||
#endif
|
84
libs/libcodec2/src/defines.h
Normal file
84
libs/libcodec2/src/defines.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: defines.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/4/93
|
||||
|
||||
Defines and structures used throughout the codec.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __DEFINES__
|
||||
#define __DEFINES__
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
DEFINES
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/* General defines */
|
||||
|
||||
#define N 80 /* number of samples per frame */
|
||||
#define MAX_AMP 80 /* maximum number of harmonics */
|
||||
#define PI 3.141592654 /* mathematical constant */
|
||||
#define TWO_PI 6.283185307 /* mathematical constant */
|
||||
#define FS 8000 /* sample rate in Hz */
|
||||
#define MAX_STR 256 /* maximum string size */
|
||||
|
||||
#define NW 279 /* analysis window size */
|
||||
#define FFT_ENC 512 /* size of FFT used for encoder */
|
||||
#define FFT_DEC 512 /* size of FFT used in decoder */
|
||||
#define TW 40 /* Trapezoidal synthesis window overlap */
|
||||
#define V_THRESH 4.0 /* voicing threshold in dB */
|
||||
#define LPC_MAX 20 /* maximum LPC order */
|
||||
#define LPC_ORD 10 /* phase modelling LPC order */
|
||||
|
||||
/* Pitch estimation defines */
|
||||
|
||||
#define M 320 /* pitch analysis frame size */
|
||||
#define P_MIN 20 /* minimum pitch */
|
||||
#define P_MAX 160 /* maximum pitch */
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
TYPEDEFS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Complex number */
|
||||
|
||||
typedef struct {
|
||||
float real;
|
||||
float imag;
|
||||
} COMP;
|
||||
|
||||
/* Structure to hold model parameters for one frame */
|
||||
|
||||
typedef struct {
|
||||
float Wo; /* fundamental frequency estimate in radians */
|
||||
int L; /* number of harmonics */
|
||||
float A[MAX_AMP]; /* amplitiude of each harmonic */
|
||||
float phi[MAX_AMP]; /* phase of each harmonic */
|
||||
int voiced; /* non-zero if this frame is voiced */
|
||||
} MODEL;
|
||||
|
||||
#endif
|
402
libs/libcodec2/src/dump.c
Normal file
402
libs/libcodec2/src/dump.c
Normal file
@@ -0,0 +1,402 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: dump.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 25/8/09
|
||||
|
||||
Routines to dump data to text files for Octave analysis.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#include "dump.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
static int dumpon = 0;
|
||||
|
||||
static FILE *fsn = NULL;
|
||||
static FILE *fsw = NULL;
|
||||
static FILE *fsw_ = NULL;
|
||||
static FILE *fmodel = NULL;
|
||||
static FILE *fqmodel = NULL;
|
||||
static FILE *fpw = NULL;
|
||||
static FILE *flsp = NULL;
|
||||
static FILE *fphase = NULL;
|
||||
static FILE *fphase_ = NULL;
|
||||
static FILE *ffw = NULL;
|
||||
static FILE *fe = NULL;
|
||||
static FILE *fsq = NULL;
|
||||
static FILE *fdec = NULL;
|
||||
static FILE *fsnr = NULL;
|
||||
static FILE *fak = NULL;
|
||||
static FILE *fbg = NULL;
|
||||
static FILE *fE = NULL;
|
||||
|
||||
static char prefix[MAX_STR];
|
||||
|
||||
void dump_on(char p[]) {
|
||||
dumpon = 1;
|
||||
strcpy(prefix, p);
|
||||
}
|
||||
|
||||
void dump_off(){
|
||||
if (fsn != NULL)
|
||||
fclose(fsn);
|
||||
if (fsw != NULL)
|
||||
fclose(fsw);
|
||||
if (fsw_ != NULL)
|
||||
fclose(fsw_);
|
||||
if (fmodel != NULL)
|
||||
fclose(fmodel);
|
||||
if (fqmodel != NULL)
|
||||
fclose(fqmodel);
|
||||
if (fpw != NULL)
|
||||
fclose(fpw);
|
||||
if (flsp != NULL)
|
||||
fclose(flsp);
|
||||
if (fphase != NULL)
|
||||
fclose(fphase);
|
||||
if (fphase_ != NULL)
|
||||
fclose(fphase_);
|
||||
if (ffw != NULL)
|
||||
fclose(ffw);
|
||||
if (fe != NULL)
|
||||
fclose(fe);
|
||||
if (fsq != NULL)
|
||||
fclose(fsq);
|
||||
if (fdec != NULL)
|
||||
fclose(fdec);
|
||||
if (fsnr != NULL)
|
||||
fclose(fsnr);
|
||||
if (fak != NULL)
|
||||
fclose(fak);
|
||||
if (fbg != NULL)
|
||||
fclose(fbg);
|
||||
if (fE != NULL)
|
||||
fclose(fE);
|
||||
}
|
||||
|
||||
void dump_Sn(float Sn[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fsn == NULL) {
|
||||
sprintf(s,"%s_sn.txt", prefix);
|
||||
fsn = fopen(s, "wt");
|
||||
assert(fsn != NULL);
|
||||
}
|
||||
|
||||
/* split across two lines to avoid max line length problems */
|
||||
/* reconstruct in Octave */
|
||||
|
||||
for(i=0; i<M/2; i++)
|
||||
fprintf(fsn,"%f\t",Sn[i]);
|
||||
fprintf(fsn,"\n");
|
||||
for(i=M/2; i<M; i++)
|
||||
fprintf(fsn,"%f\t",Sn[i]);
|
||||
fprintf(fsn,"\n");
|
||||
}
|
||||
|
||||
void dump_Sw(COMP Sw[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fsw == NULL) {
|
||||
sprintf(s,"%s_sw.txt", prefix);
|
||||
fsw = fopen(s, "wt");
|
||||
assert(fsw != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<FFT_ENC/2; i++)
|
||||
fprintf(fsw,"%f\t",
|
||||
10.0*log10(Sw[i].real*Sw[i].real + Sw[i].imag*Sw[i].imag));
|
||||
fprintf(fsw,"\n");
|
||||
}
|
||||
|
||||
void dump_Sw_(COMP Sw_[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fsw_ == NULL) {
|
||||
sprintf(s,"%s_sw_.txt", prefix);
|
||||
fsw_ = fopen(s, "wt");
|
||||
assert(fsw_ != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<FFT_ENC/2; i++)
|
||||
fprintf(fsw_,"%f\t",
|
||||
10.0*log10(Sw_[i].real*Sw_[i].real + Sw_[i].imag*Sw_[i].imag));
|
||||
fprintf(fsw_,"\n");
|
||||
}
|
||||
|
||||
void dump_model(MODEL *model) {
|
||||
int l;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fmodel == NULL) {
|
||||
sprintf(s,"%s_model.txt", prefix);
|
||||
fmodel = fopen(s, "wt");
|
||||
assert(fmodel != NULL);
|
||||
}
|
||||
|
||||
fprintf(fmodel,"%f\t%d\t", model->Wo, model->L);
|
||||
for(l=1; l<=model->L; l++)
|
||||
fprintf(fmodel,"%f\t",model->A[l]);
|
||||
for(l=model->L+1; l<MAX_AMP; l++)
|
||||
fprintf(fmodel,"0.0\t");
|
||||
fprintf(fmodel,"%d\t",model->voiced);
|
||||
fprintf(fmodel,"\n");
|
||||
}
|
||||
|
||||
void dump_quantised_model(MODEL *model) {
|
||||
int l;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fqmodel == NULL) {
|
||||
sprintf(s,"%s_qmodel.txt", prefix);
|
||||
fqmodel = fopen(s, "wt");
|
||||
assert(fqmodel != NULL);
|
||||
}
|
||||
|
||||
fprintf(fqmodel,"%f\t%d\t", model->Wo, model->L);
|
||||
for(l=1; l<=model->L; l++)
|
||||
fprintf(fqmodel,"%f\t",model->A[l]);
|
||||
for(l=model->L+1; l<MAX_AMP; l++)
|
||||
fprintf(fqmodel,"0.0\t");
|
||||
fprintf(fqmodel,"\n");
|
||||
}
|
||||
|
||||
void dump_phase(float phase[], int L) {
|
||||
int l;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fphase == NULL) {
|
||||
sprintf(s,"%s_phase.txt", prefix);
|
||||
fphase = fopen(s, "wt");
|
||||
assert(fphase != NULL);
|
||||
}
|
||||
|
||||
for(l=1; l<=L; l++)
|
||||
fprintf(fphase,"%f\t",phase[l]);
|
||||
for(l=L+1; l<MAX_AMP; l++)
|
||||
fprintf(fphase,"%f\t",0.0);
|
||||
fprintf(fphase,"\n");
|
||||
}
|
||||
|
||||
void dump_phase_(float phase_[], int L) {
|
||||
int l;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fphase_ == NULL) {
|
||||
sprintf(s,"%s_phase_.txt", prefix);
|
||||
fphase_ = fopen(s, "wt");
|
||||
assert(fphase_ != NULL);
|
||||
}
|
||||
|
||||
for(l=1; l<=L; l++)
|
||||
fprintf(fphase_,"%f\t",phase_[l]);
|
||||
for(l=L+1; l<MAX_AMP; l++)
|
||||
fprintf(fphase_,"%f\t",0.0);
|
||||
fprintf(fphase_,"\n");
|
||||
}
|
||||
|
||||
void dump_snr(float snr) {
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fsnr == NULL) {
|
||||
sprintf(s,"%s_snr.txt", prefix);
|
||||
fsnr = fopen(s, "wt");
|
||||
assert(fsnr != NULL);
|
||||
}
|
||||
|
||||
fprintf(fsnr,"%f\n",snr);
|
||||
}
|
||||
|
||||
void dump_Pw(COMP Pw[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fpw == NULL) {
|
||||
sprintf(s,"%s_pw.txt", prefix);
|
||||
fpw = fopen(s, "wt");
|
||||
assert(fpw != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<FFT_DEC/2; i++)
|
||||
fprintf(fpw,"%f\t",Pw[i].real);
|
||||
fprintf(fpw,"\n");
|
||||
}
|
||||
|
||||
void dump_lsp(float lsp[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (flsp == NULL) {
|
||||
sprintf(s,"%s_lsp.txt", prefix);
|
||||
flsp = fopen(s, "wt");
|
||||
assert(flsp != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<10; i++)
|
||||
fprintf(flsp,"%f\t",lsp[i]);
|
||||
fprintf(flsp,"\n");
|
||||
}
|
||||
|
||||
void dump_ak(float ak[], int order) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fak == NULL) {
|
||||
sprintf(s,"%s_ak.txt", prefix);
|
||||
fak = fopen(s, "wt");
|
||||
assert(fak != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<=order; i++)
|
||||
fprintf(fak,"%f\t",ak[i]);
|
||||
fprintf(fak,"\n");
|
||||
}
|
||||
|
||||
void dump_Fw(COMP Fw[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (ffw == NULL) {
|
||||
sprintf(s,"%s_fw.txt", prefix);
|
||||
ffw = fopen(s, "wt");
|
||||
assert(ffw != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<256; i++)
|
||||
fprintf(ffw,"%f\t",Fw[i].real);
|
||||
fprintf(ffw,"\n");
|
||||
}
|
||||
|
||||
void dump_e(float e_hz[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fe == NULL) {
|
||||
sprintf(s,"%s_e.txt", prefix);
|
||||
fe = fopen(s, "wt");
|
||||
assert(fe != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<500/2; i++)
|
||||
fprintf(fe,"%f\t",e_hz[i]);
|
||||
fprintf(fe,"\n");
|
||||
for(i=500/2; i<500; i++)
|
||||
fprintf(fe,"%f\t",e_hz[i]);
|
||||
fprintf(fe,"\n");
|
||||
}
|
||||
|
||||
void dump_sq(float sq[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fsq == NULL) {
|
||||
sprintf(s,"%s_sq.txt", prefix);
|
||||
fsq = fopen(s, "wt");
|
||||
assert(fsq != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<M/2; i++)
|
||||
fprintf(fsq,"%f\t",sq[i]);
|
||||
fprintf(fsq,"\n");
|
||||
for(i=M/2; i<M; i++)
|
||||
fprintf(fsq,"%f\t",sq[i]);
|
||||
fprintf(fsq,"\n");
|
||||
}
|
||||
|
||||
void dump_dec(COMP Fw[]) {
|
||||
int i;
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fdec == NULL) {
|
||||
sprintf(s,"%s_dec.txt", prefix);
|
||||
fdec = fopen(s, "wt");
|
||||
assert(fdec != NULL);
|
||||
}
|
||||
|
||||
for(i=0; i<320/5; i++)
|
||||
fprintf(fdec,"%f\t",Fw[i].real);
|
||||
fprintf(fdec,"\n");
|
||||
}
|
||||
|
||||
void dump_bg(float e, float bg_est, float percent_uv) {
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fbg == NULL) {
|
||||
sprintf(s,"%s_bg.txt", prefix);
|
||||
fbg = fopen(s, "wt");
|
||||
assert(fbg != NULL);
|
||||
}
|
||||
|
||||
fprintf(fbg,"%f\t%f\t%f\n", e, bg_est, percent_uv);
|
||||
}
|
||||
|
||||
void dump_E(float E) {
|
||||
char s[MAX_STR];
|
||||
|
||||
if (!dumpon) return;
|
||||
|
||||
if (fE == NULL) {
|
||||
sprintf(s,"%s_E.txt", prefix);
|
||||
fE = fopen(s, "wt");
|
||||
assert(fE != NULL);
|
||||
}
|
||||
|
||||
fprintf(fE,"%f\n", 10.0*log10(E));
|
||||
}
|
63
libs/libcodec2/src/dump.h
Normal file
63
libs/libcodec2/src/dump.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: dump.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 25/8/09
|
||||
|
||||
Routines to dump data to text files for Octave analysis.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __DUMP__
|
||||
#define __DUMP__
|
||||
|
||||
void dump_on(char filename_prefix[]);
|
||||
void dump_off();
|
||||
|
||||
void dump_Sn(float Sn[]);
|
||||
void dump_Sw(COMP Sw[]);
|
||||
void dump_Sw_(COMP Sw_[]);
|
||||
|
||||
/* amplitude modelling */
|
||||
|
||||
void dump_model(MODEL *m);
|
||||
void dump_quantised_model(MODEL *m);
|
||||
void dump_Pw(COMP Pw[]);
|
||||
void dump_lsp(float lsp[]);
|
||||
void dump_ak(float ak[], int order);
|
||||
void dump_E(float E);
|
||||
|
||||
/* phase modelling */
|
||||
|
||||
void dump_snr(float snr);
|
||||
void dump_phase(float phase[], int L);
|
||||
void dump_phase_(float phase[], int L);
|
||||
|
||||
/* NLP states */
|
||||
|
||||
void dump_sq(float sq[]);
|
||||
void dump_dec(COMP Fw[]);
|
||||
void dump_Fw(COMP Fw[]);
|
||||
void dump_e(float e_hz[]);
|
||||
|
||||
/* post filter */
|
||||
|
||||
void dump_bg(float e, float bg_est, float percent_uv);
|
||||
|
||||
#endif
|
64
libs/libcodec2/src/four1.c
Normal file
64
libs/libcodec2/src/four1.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: four1.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 20/2/95
|
||||
|
||||
Numerical Recipies in C FFT function. I have a nasty licence so please
|
||||
replace me.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
|
||||
|
||||
void four1(data,nn,isign)
|
||||
float data[];
|
||||
int nn,isign;
|
||||
{
|
||||
int n,mmax,m,j,istep,i;
|
||||
double wtemp,wr,wpr,wpi,wi,theta;
|
||||
float tempr,tempi;
|
||||
|
||||
n=nn << 1;
|
||||
j=1;
|
||||
for (i=1;i<n;i+=2) {
|
||||
if (j > i) {
|
||||
SWAP(data[j],data[i]);
|
||||
SWAP(data[j+1],data[i+1]);
|
||||
}
|
||||
m=n >> 1;
|
||||
while (m >= 2 && j > m) {
|
||||
j -= m;
|
||||
m >>= 1;
|
||||
}
|
||||
j += m;
|
||||
}
|
||||
mmax=2;
|
||||
while (n > mmax) {
|
||||
istep=2*mmax;
|
||||
theta=6.28318530717959/(isign*mmax);
|
||||
wtemp=sin(0.5*theta);
|
||||
wpr = -2.0*wtemp*wtemp;
|
||||
wpi=sin(theta);
|
||||
wr=1.0;
|
||||
wi=0.0;
|
||||
for (m=1;m<mmax;m+=2) {
|
||||
for (i=m;i<=n;i+=istep) {
|
||||
j=i+mmax;
|
||||
tempr=wr*data[j]-wi*data[j+1];
|
||||
tempi=wr*data[j+1]+wi*data[j];
|
||||
data[j]=data[i]-tempr;
|
||||
data[j+1]=data[i+1]-tempi;
|
||||
data[i] += tempr;
|
||||
data[i+1] += tempi;
|
||||
}
|
||||
wr=(wtemp=wr)*wpr-wi*wpi+wr;
|
||||
wi=wi*wpr+wtemp*wpi+wi;
|
||||
}
|
||||
mmax=istep;
|
||||
}
|
||||
}
|
||||
|
||||
#undef SWAP
|
18
libs/libcodec2/src/four1.h
Normal file
18
libs/libcodec2/src/four1.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: four1.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 20/2/95
|
||||
|
||||
Numerical Recipies in C FFT function. I have a nasty licence so please
|
||||
replace me.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __FOUR1__
|
||||
#define __FOUR1__
|
||||
|
||||
void four1(float x[], int n, int isign);
|
||||
|
||||
#endif /* __FOUR1__ */
|
||||
|
8
libs/libcodec2/src/fq20.sh
Executable file
8
libs/libcodec2/src/fq20.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# fq20.shsh
|
||||
# David Rowe 27 July 2010
|
||||
#
|
||||
# Decode a file with fully quantised codec at 20ms frame rate
|
||||
|
||||
../src/sinedec ../raw/$1.raw $1.mdl -o $1_phase0_lsp_20_EWo2.raw --phase 0 --lpc 10 --lsp --postfilter --dec
|
||||
|
50
libs/libcodec2/src/globals.c
Normal file
50
libs/libcodec2/src/globals.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: globals.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 11/5/94
|
||||
|
||||
Globals for sinusoidal speech coder.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "sine.h" /* global defines for coder */
|
||||
|
||||
/* Globals used in encoder and decoder */
|
||||
|
||||
int frames; /* number of frames processed so far */
|
||||
float Sn[M]; /* float input speech samples */
|
||||
MODEL model; /* model parameters for the current frame */
|
||||
int Nw; /* number of samples in analysis window */
|
||||
float sig; /* energy of current frame */
|
||||
|
||||
/* Globals used in encoder */
|
||||
|
||||
float w[M]; /* time domain hamming window */
|
||||
COMP W[FFT_ENC]; /* DFT of w[] */
|
||||
COMP Sw[FFT_ENC]; /* DFT of current frame */
|
||||
|
||||
/* Globals used in decoder */
|
||||
|
||||
COMP Sw_[FFT_ENC]; /* DFT of all voiced synthesised signal */
|
||||
float Sn_[AW_DEC]; /* synthesised speech */
|
||||
float Pn[AW_DEC]; /* time domain Parzen (trapezoidal) window */
|
||||
|
48
libs/libcodec2/src/globals.h
Normal file
48
libs/libcodec2/src/globals.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: globals.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 1/11/94
|
||||
|
||||
Globals for sinusoidal speech coder.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
/* Globals used in encoder and decoder */
|
||||
|
||||
extern int frames; /* number of frames processed so far */
|
||||
extern float Sn[]; /* float input speech samples */
|
||||
extern MODEL model; /* model parameters for the current frame */
|
||||
extern int Nw; /* number of samples in analysis window */
|
||||
extern float sig; /* energy of current frame */
|
||||
|
||||
/* Globals used in encoder */
|
||||
|
||||
extern float w[]; /* time domain hamming window */
|
||||
extern COMP W[]; /* frequency domain hamming window */
|
||||
extern COMP Sw[]; /* DFT of current frame */
|
||||
extern COMP Sw_[]; /* DFT of all voiced synthesised signal */
|
||||
|
||||
/* Globals used in decoder */
|
||||
|
||||
extern float Sn_[]; /* output synthesised speech samples */
|
||||
extern float Pn[]; /* time domain Parzen (trapezoidal) window */
|
||||
|
122
libs/libcodec2/src/interp.c
Normal file
122
libs/libcodec2/src/interp.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: interp.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 9/10/09
|
||||
|
||||
Interpolation of 20ms frames to 10ms frames.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "interp.h"
|
||||
|
||||
float sample_log_amp(MODEL *model, float w);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: interp()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/10
|
||||
|
||||
Given two frames decribed by model parameters 20ms apart, determines
|
||||
the model parameters of the 10ms frame between them. Assumes
|
||||
voicing is available for middle (interpolated) frame. Outputs are
|
||||
amplitudes and Wo for the interpolated frame.
|
||||
|
||||
This version can interpolate the amplitudes between two frames of
|
||||
different Wo and L.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void interpolate(
|
||||
MODEL *interp, /* interpolated model params */
|
||||
MODEL *prev, /* previous frames model params */
|
||||
MODEL *next /* next frames model params */
|
||||
)
|
||||
{
|
||||
int l;
|
||||
float w,log_amp;
|
||||
|
||||
/* Wo depends on voicing of this and adjacent frames */
|
||||
|
||||
if (interp->voiced) {
|
||||
if (prev->voiced && next->voiced)
|
||||
interp->Wo = (prev->Wo + next->Wo)/2.0;
|
||||
if (!prev->voiced && next->voiced)
|
||||
interp->Wo = next->Wo;
|
||||
if (prev->voiced && !next->voiced)
|
||||
interp->Wo = prev->Wo;
|
||||
}
|
||||
else {
|
||||
interp->Wo = TWO_PI/P_MAX;
|
||||
}
|
||||
interp->L = PI/interp->Wo;
|
||||
|
||||
/* Interpolate amplitudes using linear interpolation in log domain */
|
||||
|
||||
for(l=1; l<=interp->L; l++) {
|
||||
w = l*interp->Wo;
|
||||
log_amp = (sample_log_amp(prev, w) + sample_log_amp(next, w))/2.0;
|
||||
interp->A[l] = pow(10.0, log_amp);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: sample_log_amp()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/10
|
||||
|
||||
Samples the amplitude envelope at an arbitrary frequency w. Uses
|
||||
linear interpolation in the log domain to sample between harmonic
|
||||
amplitudes.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float sample_log_amp(MODEL *model, float w)
|
||||
{
|
||||
int m;
|
||||
float f, log_amp;
|
||||
|
||||
assert(w > 0.0); assert (w <= PI);
|
||||
|
||||
m = floor(w/model->Wo + 0.5);
|
||||
f = (w - m*model->Wo)/w;
|
||||
assert(f <= 1.0);
|
||||
|
||||
if (m < 1) {
|
||||
log_amp = f*log10(model->A[1]);
|
||||
}
|
||||
else if ((m+1) > model->L) {
|
||||
log_amp = (1.0-f)*log10(model->A[model->L]);
|
||||
}
|
||||
else {
|
||||
log_amp = (1.0-f)*log10(model->A[m]) + f*log10(model->A[m+1]);
|
||||
}
|
||||
|
||||
return log_amp;
|
||||
}
|
||||
|
34
libs/libcodec2/src/interp.h
Normal file
34
libs/libcodec2/src/interp.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: interp.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 9/10/09
|
||||
|
||||
Interpolation of 20ms frames to 10ms frames.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __INTERP__
|
||||
#define __INTERP__
|
||||
|
||||
void interpolate(MODEL *interp, MODEL *prev, MODEL *next);
|
||||
|
||||
#endif
|
9
libs/libcodec2/src/listen.sh
Normal file
9
libs/libcodec2/src/listen.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# listensim.sh
|
||||
# David Rowe 10 Sep 2009
|
||||
#
|
||||
# Listen to files processed with sim.sh
|
||||
|
||||
../script/menu.sh ../raw/$1.raw $1_uq.raw $1_phase0.raw $1_lpc10.raw $1_lsp.raw $1_phase0_lpc10.raw $1_phase0_lsp.raw $1_phase0_lsp.raw $2 $3
|
||||
|
||||
|
15
libs/libcodec2/src/listen1.sh
Executable file
15
libs/libcodec2/src/listen1.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# listen1.sh
|
||||
# David Rowe 10 Sep 2009
|
||||
#
|
||||
# Run menu with common sample file options, headphone version
|
||||
|
||||
#../script/menu.sh ../raw/$1.raw $1_uq.raw $1_phase0.raw $1_lpc10.raw $1_lsp.raw $1_phase0_lpc10.raw $1_phase0_lsp.raw ../raw/$1_g729a.raw $2 $3 -d /dev/dsp1
|
||||
|
||||
# compare to other codecs
|
||||
|
||||
#../script/menu.sh ../raw/$1.raw $1_phase0_lsp.raw $1_phase0_lsp_20.raw ../raw/$1_g729a.raw ../raw/$1_gsm13k.raw ../raw/$1_speex_8k.raw $2 $3 -d /dev/dsp1
|
||||
|
||||
../script/menu.sh ../raw/$1.raw $1_uq.raw $1_phase0.raw $1_test.raw ../raw/$1_g729a.raw $2 $3 -d /dev/dsp1
|
||||
|
||||
|
9
libs/libcodec2/src/listensim.sh
Executable file
9
libs/libcodec2/src/listensim.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# listensim.sh
|
||||
# David Rowe 10 Sep 2009
|
||||
#
|
||||
# Listen to files processed with sim.sh
|
||||
|
||||
../script/menu.sh ../raw/$1.raw $1_uq.raw $1_phase0.raw $1_lpc10.raw $1_lsp.raw $1_phase0_lpc10.raw $1_phase0_lsp.raw $1_phase0_lsp_dec.raw $2 $3
|
||||
|
||||
|
253
libs/libcodec2/src/lpc.c
Normal file
253
libs/libcodec2/src/lpc.c
Normal file
@@ -0,0 +1,253 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: lpc.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 30/9/90
|
||||
|
||||
Linear Prediction functions written in C.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#define LPC_MAX_N 512 /* maximum no. of samples in frame */
|
||||
#define PI 3.141592654 /* mathematical constant */
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include "defines.h"
|
||||
#include "lpc.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
hanning_window()
|
||||
|
||||
Hanning windows a frame of speech samples.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void hanning_window(
|
||||
float Sn[], /* input frame of speech samples */
|
||||
float Wn[], /* output frame of windowed samples */
|
||||
int Nsam /* number of samples */
|
||||
)
|
||||
{
|
||||
int i; /* loop variable */
|
||||
|
||||
for(i=0; i<Nsam; i++)
|
||||
Wn[i] = Sn[i]*(0.5 - 0.5*cos(2*PI*(float)i/(Nsam-1)));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
autocorrelate()
|
||||
|
||||
Finds the first P autocorrelation values of an array of windowed speech
|
||||
samples Sn[].
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void autocorrelate(
|
||||
float Sn[], /* frame of Nsam windowed speech samples */
|
||||
float Rn[], /* array of P+1 autocorrelation coefficients */
|
||||
int Nsam, /* number of windowed samples to use */
|
||||
int order /* order of LPC analysis */
|
||||
)
|
||||
{
|
||||
int i,j; /* loop variables */
|
||||
|
||||
for(j=0; j<order+1; j++) {
|
||||
Rn[j] = 0.0;
|
||||
for(i=0; i<Nsam-j; i++)
|
||||
Rn[j] += Sn[i]*Sn[i+j];
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
levinson_durbin()
|
||||
|
||||
Given P+1 autocorrelation coefficients, finds P Linear Prediction Coeff.
|
||||
(LPCs) where P is the order of the LPC all-pole model. The Levinson-Durbin
|
||||
algorithm is used, and is described in:
|
||||
|
||||
J. Makhoul
|
||||
"Linear prediction, a tutorial review"
|
||||
Proceedings of the IEEE
|
||||
Vol-63, No. 4, April 1975
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void levinson_durbin(
|
||||
float R[], /* order+1 autocorrelation coeff */
|
||||
float lpcs[], /* order+1 LPC's */
|
||||
int order /* order of the LPC analysis */
|
||||
)
|
||||
{
|
||||
float E[LPC_MAX+1];
|
||||
float k[LPC_MAX+1];
|
||||
float a[LPC_MAX+1][LPC_MAX+1];
|
||||
float sum;
|
||||
int i,j; /* loop variables */
|
||||
|
||||
E[0] = R[0]; /* Equation 38a, Makhoul */
|
||||
|
||||
for(i=1; i<=order; i++) {
|
||||
sum = 0.0;
|
||||
for(j=1; j<=i-1; j++)
|
||||
sum += a[i-1][j]*R[i-j];
|
||||
k[i] = -1.0*(R[i] + sum)/E[i-1]; /* Equation 38b, Makhoul */
|
||||
if (fabs(k[i]) > 1.0)
|
||||
k[i] = 0.0;
|
||||
|
||||
a[i][i] = k[i];
|
||||
|
||||
for(j=1; j<=i-1; j++)
|
||||
a[i][j] = a[i-1][j] + k[i]*a[i-1][i-j]; /* Equation 38c, Makhoul */
|
||||
|
||||
E[i] = (1-k[i]*k[i])*E[i-1]; /* Equation 38d, Makhoul */
|
||||
}
|
||||
|
||||
for(i=1; i<=order; i++)
|
||||
lpcs[i] = a[order][i];
|
||||
lpcs[0] = 1.0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
inverse_filter()
|
||||
|
||||
Inverse Filter, A(z). Produces an array of residual samples from an array
|
||||
of input samples and linear prediction coefficients.
|
||||
|
||||
The filter memory is stored in the first order samples of the input array.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void inverse_filter(
|
||||
float Sn[], /* Nsam input samples */
|
||||
float a[], /* LPCs for this frame of samples */
|
||||
int Nsam, /* number of samples */
|
||||
float res[], /* Nsam residual samples */
|
||||
int order /* order of LPC */
|
||||
)
|
||||
{
|
||||
int i,j; /* loop variables */
|
||||
|
||||
for(i=0; i<Nsam; i++) {
|
||||
res[i] = 0.0;
|
||||
for(j=0; j<=order; j++)
|
||||
res[i] += Sn[i-j]*a[j];
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
synthesis_filter()
|
||||
|
||||
C version of the Speech Synthesis Filter, 1/A(z). Given an array of
|
||||
residual or excitation samples, and the the LP filter coefficients, this
|
||||
function will produce an array of speech samples. This filter structure is
|
||||
IIR.
|
||||
|
||||
The synthesis filter has memory as well, this is treated in the same way
|
||||
as the memory for the inverse filter (see inverse_filter() notes above).
|
||||
The difference is that the memory for the synthesis filter is stored in
|
||||
the output array, wheras the memory of the inverse filter is stored in the
|
||||
input array.
|
||||
|
||||
Note: the calling function must update the filter memory.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void synthesis_filter(
|
||||
float res[], /* Nsam input residual (excitation) samples */
|
||||
float a[], /* LPCs for this frame of speech samples */
|
||||
int Nsam, /* number of speech samples */
|
||||
int order, /* LPC order */
|
||||
float Sn_[] /* Nsam output synthesised speech samples */
|
||||
)
|
||||
{
|
||||
int i,j; /* loop variables */
|
||||
|
||||
/* Filter Nsam samples */
|
||||
|
||||
for(i=0; i<Nsam; i++) {
|
||||
Sn_[i] = res[i]*a[0];
|
||||
for(j=1; j<=order; j++)
|
||||
Sn_[i] -= Sn_[i-j]*a[j];
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
find_aks()
|
||||
|
||||
This function takes a frame of samples, and determines the linear
|
||||
prediction coefficients for that frame of samples.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void find_aks(
|
||||
float Sn[], /* Nsam samples with order sample memory */
|
||||
float a[], /* order+1 LPCs with first coeff 1.0 */
|
||||
int Nsam, /* number of input speech samples */
|
||||
int order, /* order of the LPC analysis */
|
||||
float *E /* residual energy */
|
||||
)
|
||||
{
|
||||
float Wn[LPC_MAX_N]; /* windowed frame of Nsam speech samples */
|
||||
float R[LPC_MAX+1]; /* order+1 autocorrelation values of Sn[] */
|
||||
int i;
|
||||
|
||||
assert(order < LPC_MAX);
|
||||
assert(Nsam < LPC_MAX_N);
|
||||
|
||||
hanning_window(Sn,Wn,Nsam);
|
||||
autocorrelate(Wn,R,Nsam,order);
|
||||
levinson_durbin(R,a,order);
|
||||
|
||||
*E = 0.0;
|
||||
for(i=0; i<=order; i++)
|
||||
*E += a[i]*R[i];
|
||||
if (*E < 0.0)
|
||||
*E = 1E-12;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
weight()
|
||||
|
||||
Weights a vector of LPCs.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void weight(
|
||||
float ak[], /* vector of order+1 LPCs */
|
||||
float gamma, /* weighting factor */
|
||||
int order, /* num LPCs (excluding leading 1.0) */
|
||||
float akw[] /* weighted vector of order+1 LPCs */
|
||||
)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=1; i<=order; i++)
|
||||
akw[i] = ak[i]*pow(gamma,(float)i);
|
||||
}
|
||||
|
42
libs/libcodec2/src/lpc.h
Normal file
42
libs/libcodec2/src/lpc.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: lpc.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/8/09
|
||||
|
||||
Linear Prediction functions written in C.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __LPC__
|
||||
#define __LPC__
|
||||
|
||||
#define LPC_MAX_ORDER 20
|
||||
|
||||
void hanning_window(float Sn[], float Wn[], int Nsam);
|
||||
void autocorrelate(float Sn[], float Rn[], int Nsam, int order);
|
||||
void levinson_durbin(float R[], float lpcs[], int order);
|
||||
void inverse_filter(float Sn[], float a[], int Nsam, float res[], int order);
|
||||
void synthesis_filter(float res[], float a[], int Nsam, int order, float Sn_[]);
|
||||
void find_aks(float Sn[], float a[], int Nsam, int order, float *E);
|
||||
void weight(float ak[], float gamma, int order, float akw[]);
|
||||
|
||||
#endif
|
323
libs/libcodec2/src/lsp.c
Normal file
323
libs/libcodec2/src/lsp.c
Normal file
@@ -0,0 +1,323 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: lsp.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/2/93
|
||||
|
||||
|
||||
This file contains functions for LPC to LSP conversion and LSP to
|
||||
LPC conversion. Note that the LSP coefficients are not in radians
|
||||
format but in the x domain of the unit circle.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "defines.h"
|
||||
#include "lsp.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
Introduction to Line Spectrum Pairs (LSPs)
|
||||
------------------------------------------
|
||||
|
||||
LSPs are used to encode the LPC filter coefficients {ak} for
|
||||
transmission over the channel. LSPs have several properties (like
|
||||
less sensitivity to quantisation noise) that make them superior to
|
||||
direct quantisation of {ak}.
|
||||
|
||||
A(z) is a polynomial of order lpcrdr with {ak} as the coefficients.
|
||||
|
||||
A(z) is transformed to P(z) and Q(z) (using a substitution and some
|
||||
algebra), to obtain something like:
|
||||
|
||||
A(z) = 0.5[P(z)(z+z^-1) + Q(z)(z-z^-1)] (1)
|
||||
|
||||
As you can imagine A(z) has complex zeros all over the z-plane. P(z)
|
||||
and Q(z) have the very neat property of only having zeros _on_ the
|
||||
unit circle. So to find them we take a test point z=exp(jw) and
|
||||
evaluate P (exp(jw)) and Q(exp(jw)) using a grid of points between 0
|
||||
and pi.
|
||||
|
||||
The zeros (roots) of P(z) also happen to alternate, which is why we
|
||||
swap coefficients as we find roots. So the process of finding the
|
||||
LSP frequencies is basically finding the roots of 5th order
|
||||
polynomials.
|
||||
|
||||
The root so P(z) and Q(z) occur in symmetrical pairs at +/-w, hence
|
||||
the name Line Spectrum Pairs (LSPs).
|
||||
|
||||
To convert back to ak we just evaluate (1), "clocking" an impulse
|
||||
thru it lpcrdr times gives us the impulse response of A(z) which is
|
||||
{ak}.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: cheb_poly_eva()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/2/93
|
||||
|
||||
This function evalutes a series of chebyshev polynomials
|
||||
|
||||
FIXME: performing memory allocation at run time is very inefficient,
|
||||
replace with stack variables of MAX_P size.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
float cheb_poly_eva(float *coef,float x,int m)
|
||||
/* float coef[] coefficients of the polynomial to be evaluated */
|
||||
/* float x the point where polynomial is to be evaluated */
|
||||
/* int m order of the polynomial */
|
||||
{
|
||||
int i;
|
||||
float *T,*t,*u,*v,sum;
|
||||
|
||||
/* Allocate memory for chebyshev series formulation */
|
||||
|
||||
if((T = (float *)malloc((m/2+1)*sizeof(float))) == NULL){
|
||||
fprintf(stderr, "not enough memory to allocate buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Initialise pointers */
|
||||
|
||||
t = T; /* T[i-2] */
|
||||
*t++ = 1.0;
|
||||
u = t--; /* T[i-1] */
|
||||
*u++ = x;
|
||||
v = u--; /* T[i] */
|
||||
|
||||
/* Evaluate chebyshev series formulation using iterative approach */
|
||||
|
||||
for(i=2;i<=m/2;i++)
|
||||
*v++ = (2*x)*(*u++) - *t++; /* T[i] = 2*x*T[i-1] - T[i-2] */
|
||||
|
||||
sum=0.0; /* initialise sum to zero */
|
||||
t = T; /* reset pointer */
|
||||
|
||||
/* Evaluate polynomial and return value also free memory space */
|
||||
|
||||
for(i=0;i<=m/2;i++)
|
||||
sum+=coef[(m/2)-i]**t++;
|
||||
|
||||
free(T);
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: lpc_to_lsp()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/2/93
|
||||
|
||||
This function converts LPC coefficients to LSP coefficients.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
|
||||
/* float *a lpc coefficients */
|
||||
/* int lpcrdr order of LPC coefficients (10) */
|
||||
/* float *freq LSP frequencies in radians */
|
||||
/* int nb number of sub-intervals (4) */
|
||||
/* float delta grid spacing interval (0.02) */
|
||||
{
|
||||
float psuml,psumr,psumm,temp_xr,xl,xr,xm;
|
||||
float temp_psumr;
|
||||
int i,j,m,flag,k;
|
||||
float *Q; /* ptrs for memory allocation */
|
||||
float *P;
|
||||
float *px; /* ptrs of respective P'(z) & Q'(z) */
|
||||
float *qx;
|
||||
float *p;
|
||||
float *q;
|
||||
float *pt; /* ptr used for cheb_poly_eval()
|
||||
whether P' or Q' */
|
||||
int roots=0; /* number of roots found */
|
||||
flag = 1;
|
||||
m = lpcrdr/2; /* order of P'(z) & Q'(z) polynimials */
|
||||
|
||||
/* Allocate memory space for polynomials */
|
||||
|
||||
Q = (float *) malloc((m+1)*sizeof(float));
|
||||
P = (float *) malloc((m+1)*sizeof(float));
|
||||
if( (P == NULL) || (Q == NULL) ) {
|
||||
fprintf(stderr,"not enough memory to allocate buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* determine P'(z)'s and Q'(z)'s coefficients where
|
||||
P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */
|
||||
|
||||
px = P; /* initilaise ptrs */
|
||||
qx = Q;
|
||||
p = px;
|
||||
q = qx;
|
||||
*px++ = 1.0;
|
||||
*qx++ = 1.0;
|
||||
for(i=1;i<=m;i++){
|
||||
*px++ = a[i]+a[lpcrdr+1-i]-*p++;
|
||||
*qx++ = a[i]-a[lpcrdr+1-i]+*q++;
|
||||
}
|
||||
px = P;
|
||||
qx = Q;
|
||||
for(i=0;i<m;i++){
|
||||
*px = 2**px;
|
||||
*qx = 2**qx;
|
||||
px++;
|
||||
qx++;
|
||||
}
|
||||
px = P; /* re-initialise ptrs */
|
||||
qx = Q;
|
||||
|
||||
/* Search for a zero in P'(z) polynomial first and then alternate to Q'(z).
|
||||
Keep alternating between the two polynomials as each zero is found */
|
||||
|
||||
xr = 0; /* initialise xr to zero */
|
||||
xl = 1.0; /* start at point xl = 1 */
|
||||
|
||||
|
||||
for(j=0;j<lpcrdr;j++){
|
||||
if(j%2) /* determines whether P' or Q' is eval. */
|
||||
pt = qx;
|
||||
else
|
||||
pt = px;
|
||||
|
||||
psuml = cheb_poly_eva(pt,xl,lpcrdr); /* evals poly. at xl */
|
||||
flag = 1;
|
||||
while(flag && (xr >= -1.0)){
|
||||
xr = xl - delta ; /* interval spacing */
|
||||
psumr = cheb_poly_eva(pt,xr,lpcrdr);/* poly(xl-delta_x) */
|
||||
temp_psumr = psumr;
|
||||
temp_xr = xr;
|
||||
|
||||
/* if no sign change increment xr and re-evaluate
|
||||
poly(xr). Repeat til sign change. if a sign change has
|
||||
occurred the interval is bisected and then checked again
|
||||
for a sign change which determines in which interval the
|
||||
zero lies in. If there is no sign change between poly(xm)
|
||||
and poly(xl) set interval between xm and xr else set
|
||||
interval between xl and xr and repeat till root is located
|
||||
within the specified limits */
|
||||
|
||||
if((psumr*psuml)<0.0){
|
||||
roots++;
|
||||
|
||||
psumm=psuml;
|
||||
for(k=0;k<=nb;k++){
|
||||
xm = (xl+xr)/2; /* bisect the interval */
|
||||
psumm=cheb_poly_eva(pt,xm,lpcrdr);
|
||||
if(psumm*psuml>0.){
|
||||
psuml=psumm;
|
||||
xl=xm;
|
||||
}
|
||||
else{
|
||||
psumr=psumm;
|
||||
xr=xm;
|
||||
}
|
||||
}
|
||||
|
||||
/* once zero is found, reset initial interval to xr */
|
||||
freq[j] = (xm);
|
||||
xl = xm;
|
||||
flag = 0; /* reset flag for next search */
|
||||
}
|
||||
else{
|
||||
psuml=temp_psumr;
|
||||
xl=temp_xr;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(P); /* free memory space */
|
||||
free(Q);
|
||||
|
||||
/* convert from x domain to radians */
|
||||
|
||||
for(i=0; i<lpcrdr; i++) {
|
||||
freq[i] = acos(freq[i]);
|
||||
}
|
||||
|
||||
return(roots);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: lsp_to_lpc()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/2/93
|
||||
|
||||
This function converts LSP coefficients to LPC coefficients. In the
|
||||
Speex code we worked out a wayto simplify this significantly.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void lsp_to_lpc(float *freq, float *ak, int lpcrdr)
|
||||
/* float *freq array of LSP frequencies in radians */
|
||||
/* float *ak array of LPC coefficients */
|
||||
/* int lpcrdr order of LPC coefficients */
|
||||
|
||||
|
||||
{
|
||||
int i,j;
|
||||
float xout1,xout2,xin1,xin2;
|
||||
float *Wp;
|
||||
float *pw,*n1,*n2,*n3,*n4;
|
||||
int m = lpcrdr/2;
|
||||
|
||||
/* convert from radians to the x=cos(w) domain */
|
||||
|
||||
for(i=0; i<lpcrdr; i++)
|
||||
freq[i] = cos(freq[i]);
|
||||
|
||||
if((Wp = (float *) malloc((4*m+2)*sizeof(float))) == NULL){
|
||||
printf("not enough memory to allocate buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
pw = Wp;
|
||||
|
||||
/* initialise contents of array */
|
||||
|
||||
for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */
|
||||
*pw++ = 0.0;
|
||||
}
|
||||
|
||||
/* Set pointers up */
|
||||
|
||||
pw = Wp;
|
||||
xin1 = 1.0;
|
||||
xin2 = 1.0;
|
||||
|
||||
/* reconstruct P(z) and Q(z) by cascading second order polynomials
|
||||
in form 1 - 2xz(-1) +z(-2), where x is the LSP coefficient */
|
||||
|
||||
for(j=0;j<=lpcrdr;j++){
|
||||
for(i=0;i<m;i++){
|
||||
n1 = pw+(i*4);
|
||||
n2 = n1 + 1;
|
||||
n3 = n2 + 1;
|
||||
n4 = n3 + 1;
|
||||
xout1 = xin1 - 2*(freq[2*i]) * *n1 + *n2;
|
||||
xout2 = xin2 - 2*(freq[2*i+1]) * *n3 + *n4;
|
||||
*n2 = *n1;
|
||||
*n4 = *n3;
|
||||
*n1 = xin1;
|
||||
*n3 = xin2;
|
||||
xin1 = xout1;
|
||||
xin2 = xout2;
|
||||
}
|
||||
xout1 = xin1 + *(n4+1);
|
||||
xout2 = xin2 - *(n4+2);
|
||||
ak[j] = (xout1 + xout2)*0.5;
|
||||
*(n4+1) = xin1;
|
||||
*(n4+2) = xin2;
|
||||
|
||||
xin1 = 0.0;
|
||||
xin2 = 0.0;
|
||||
}
|
||||
free(Wp);
|
||||
}
|
||||
|
20
libs/libcodec2/src/lsp.h
Normal file
20
libs/libcodec2/src/lsp.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: lsp.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 24/2/93
|
||||
|
||||
|
||||
This file contains functions for LPC to LSP conversion and LSP to
|
||||
LPC conversion. Note that the LSP coefficients are not in radians
|
||||
format but in the x domain of the unit circle.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LSP__
|
||||
#define __LSP__
|
||||
|
||||
int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta);
|
||||
void lsp_to_lpc(float *freq, float *ak, int lpcrdr);
|
||||
|
||||
#endif
|
361
libs/libcodec2/src/nlp.c
Normal file
361
libs/libcodec2/src/nlp.c
Normal file
@@ -0,0 +1,361 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: nlp.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/3/93
|
||||
|
||||
Non Linear Pitch (NLP) estimation functions.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#include "nlp.h"
|
||||
#include "dump.h"
|
||||
#include "four1.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
DEFINES
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#define PMAX_M 600 /* maximum NLP analysis window size */
|
||||
#define COEFF 0.95 /* notch filter parameter */
|
||||
#define PE_FFT_SIZE 512 /* DFT size for pitch estimation */
|
||||
#define DEC 5 /* decimation factor */
|
||||
#define SAMPLE_RATE 8000
|
||||
#define PI 3.141592654 /* mathematical constant */
|
||||
#define T 0.1 /* threshold for local minima candidate */
|
||||
#define F0_MAX 500
|
||||
#define CNLP 0.3 /* post processor constant */
|
||||
#define NLP_NTAP 48 /* Decimation LPF order */
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
GLOBALS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/* 48 tap 600Hz low pass FIR filter coefficients */
|
||||
|
||||
float nlp_fir[] = {
|
||||
-1.0818124e-03,
|
||||
-1.1008344e-03,
|
||||
-9.2768838e-04,
|
||||
-4.2289438e-04,
|
||||
5.5034190e-04,
|
||||
2.0029849e-03,
|
||||
3.7058509e-03,
|
||||
5.1449415e-03,
|
||||
5.5924666e-03,
|
||||
4.3036754e-03,
|
||||
8.0284511e-04,
|
||||
-4.8204610e-03,
|
||||
-1.1705810e-02,
|
||||
-1.8199275e-02,
|
||||
-2.2065282e-02,
|
||||
-2.0920610e-02,
|
||||
-1.2808831e-02,
|
||||
3.2204775e-03,
|
||||
2.6683811e-02,
|
||||
5.5520624e-02,
|
||||
8.6305944e-02,
|
||||
1.1480192e-01,
|
||||
1.3674206e-01,
|
||||
1.4867556e-01,
|
||||
1.4867556e-01,
|
||||
1.3674206e-01,
|
||||
1.1480192e-01,
|
||||
8.6305944e-02,
|
||||
5.5520624e-02,
|
||||
2.6683811e-02,
|
||||
3.2204775e-03,
|
||||
-1.2808831e-02,
|
||||
-2.0920610e-02,
|
||||
-2.2065282e-02,
|
||||
-1.8199275e-02,
|
||||
-1.1705810e-02,
|
||||
-4.8204610e-03,
|
||||
8.0284511e-04,
|
||||
4.3036754e-03,
|
||||
5.5924666e-03,
|
||||
5.1449415e-03,
|
||||
3.7058509e-03,
|
||||
2.0029849e-03,
|
||||
5.5034190e-04,
|
||||
-4.2289438e-04,
|
||||
-9.2768838e-04,
|
||||
-1.1008344e-03,
|
||||
-1.0818124e-03
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
float sq[PMAX_M]; /* squared speech samples */
|
||||
float mem_x,mem_y; /* memory for notch filter */
|
||||
float mem_fir[NLP_NTAP]; /* decimation FIR filter memory */
|
||||
} NLP;
|
||||
|
||||
float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax);
|
||||
float post_process_sub_multiples(COMP Fw[],
|
||||
int pmin, int pmax, float gmax, int gmax_bin,
|
||||
float *prev_Wo);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
nlp_create()
|
||||
|
||||
Initialisation function for NLP pitch estimator.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void *nlp_create()
|
||||
{
|
||||
NLP *nlp;
|
||||
int i;
|
||||
|
||||
nlp = (NLP*)malloc(sizeof(NLP));
|
||||
if (nlp == NULL)
|
||||
return NULL;
|
||||
|
||||
for(i=0; i<PMAX_M; i++)
|
||||
nlp->sq[i] = 0.0;
|
||||
nlp->mem_x = 0.0;
|
||||
nlp->mem_y = 0.0;
|
||||
for(i=0; i<NLP_NTAP; i++)
|
||||
nlp->mem_fir[i] = 0.0;
|
||||
|
||||
return (void*)nlp;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
nlp_destory()
|
||||
|
||||
Initialisation function for NLP pitch estimator.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void nlp_destroy(void *nlp_state)
|
||||
{
|
||||
assert(nlp_state != NULL);
|
||||
free(nlp_state);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
nlp()
|
||||
|
||||
Determines the pitch in samples using the Non Linear Pitch (NLP)
|
||||
algorithm [1]. Returns the fundamental in Hz. Note that the actual
|
||||
pitch estimate is for the centre of the M sample Sn[] vector, not
|
||||
the current N sample input vector. This is (I think) a delay of 2.5
|
||||
frames with N=80 samples. You should align further analysis using
|
||||
this pitch estimate to be centred on the middle of Sn[].
|
||||
|
||||
Two post processors have been tried, the MBE version (as discussed
|
||||
in [1]), and a post processor that checks sub-multiples. Both
|
||||
suffer occasional gross pitch errors (i.e. neither are perfect). In
|
||||
the presence of background noise the sub-multiple algorithm tends
|
||||
towards low F0 which leads to better sounding background noise than
|
||||
the MBE post processor.
|
||||
|
||||
A good way to test and develop the NLP pitch estimator is using the
|
||||
tnlp (codec2/unittest) and the codec2/octave/plnlp.m Octave script.
|
||||
|
||||
A pitch tracker searching a few frames forward and backward in time
|
||||
would be a useful addition.
|
||||
|
||||
References:
|
||||
|
||||
[1] http://www.itr.unisa.edu.au/~steven/thesis/dgr.pdf Chapter 4
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float nlp(
|
||||
void *nlp_state,
|
||||
float Sn[], /* input speech vector */
|
||||
int n, /* frames shift (no. new samples in Sn[]) */
|
||||
int m, /* analysis window size */
|
||||
int pmin, /* minimum pitch value */
|
||||
int pmax, /* maximum pitch value */
|
||||
float *pitch, /* estimated pitch period in samples */
|
||||
COMP Sw[], /* Freq domain version of Sn[] */
|
||||
float *prev_Wo
|
||||
)
|
||||
{
|
||||
NLP *nlp;
|
||||
float notch; /* current notch filter output */
|
||||
COMP Fw[PE_FFT_SIZE]; /* DFT of squared signal */
|
||||
float gmax;
|
||||
int gmax_bin;
|
||||
int i,j;
|
||||
float best_f0;
|
||||
|
||||
assert(nlp_state != NULL);
|
||||
nlp = (NLP*)nlp_state;
|
||||
|
||||
/* Square, notch filter at DC, and LP filter vector */
|
||||
|
||||
for(i=m-n; i<M; i++) /* square latest speech samples */
|
||||
nlp->sq[i] = Sn[i]*Sn[i];
|
||||
|
||||
for(i=m-n; i<m; i++) { /* notch filter at DC */
|
||||
notch = nlp->sq[i] - nlp->mem_x;
|
||||
notch += COEFF*nlp->mem_y;
|
||||
nlp->mem_x = nlp->sq[i];
|
||||
nlp->mem_y = notch;
|
||||
nlp->sq[i] = notch;
|
||||
}
|
||||
|
||||
for(i=m-n; i<m; i++) { /* FIR filter vector */
|
||||
|
||||
for(j=0; j<NLP_NTAP-1; j++)
|
||||
nlp->mem_fir[j] = nlp->mem_fir[j+1];
|
||||
nlp->mem_fir[NLP_NTAP-1] = nlp->sq[i];
|
||||
|
||||
nlp->sq[i] = 0.0;
|
||||
for(j=0; j<NLP_NTAP; j++)
|
||||
nlp->sq[i] += nlp->mem_fir[j]*nlp_fir[j];
|
||||
}
|
||||
|
||||
/* Decimate and DFT */
|
||||
|
||||
for(i=0; i<PE_FFT_SIZE; i++) {
|
||||
Fw[i].real = 0.0;
|
||||
Fw[i].imag = 0.0;
|
||||
}
|
||||
for(i=0; i<m/DEC; i++) {
|
||||
Fw[i].real = nlp->sq[i*DEC]*(0.5 - 0.5*cos(2*PI*i/(m/DEC-1)));
|
||||
}
|
||||
dump_dec(Fw);
|
||||
four1(&Fw[-1].imag,PE_FFT_SIZE,1);
|
||||
for(i=0; i<PE_FFT_SIZE; i++)
|
||||
Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
|
||||
|
||||
dump_sq(nlp->sq);
|
||||
dump_Fw(Fw);
|
||||
|
||||
/* find global peak */
|
||||
|
||||
gmax = 0.0;
|
||||
gmax_bin = PE_FFT_SIZE*DEC/pmax;
|
||||
for(i=PE_FFT_SIZE*DEC/pmax; i<=PE_FFT_SIZE*DEC/pmin; i++) {
|
||||
if (Fw[i].real > gmax) {
|
||||
gmax = Fw[i].real;
|
||||
gmax_bin = i;
|
||||
}
|
||||
}
|
||||
|
||||
best_f0 = post_process_sub_multiples(Fw, pmin, pmax, gmax, gmax_bin,
|
||||
prev_Wo);
|
||||
|
||||
/* Shift samples in buffer to make room for new samples */
|
||||
|
||||
for(i=0; i<m-n; i++)
|
||||
nlp->sq[i] = nlp->sq[i+n];
|
||||
|
||||
/* return pitch and F0 estimate */
|
||||
|
||||
*pitch = (float)SAMPLE_RATE/best_f0;
|
||||
return(best_f0);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
post_process_sub_multiples()
|
||||
|
||||
Given the global maximma of Fw[] we search interger submultiples for
|
||||
local maxima. If local maxima exist and they are above an
|
||||
experimentally derived threshold (OK a magic number I pulled out of
|
||||
the air) we choose the submultiple as the F0 estimate.
|
||||
|
||||
The rational for this is that the lowest frequency peak of Fw[]
|
||||
should be F0, as Fw[] can be considered the autocorrelation function
|
||||
of Sw[] (the speech spectrum). However sometimes due to phase
|
||||
effects the lowest frequency maxima may not be the global maxima.
|
||||
|
||||
This works OK in practice and favours low F0 values in the presence
|
||||
of background noise which means the sinusoidal codec does an OK job
|
||||
of synthesising the background noise. High F0 in background noise
|
||||
tends to sound more periodic introducing annoying artifacts.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float post_process_sub_multiples(COMP Fw[],
|
||||
int pmin, int pmax, float gmax, int gmax_bin,
|
||||
float *prev_Wo)
|
||||
{
|
||||
int min_bin, cmax_bin;
|
||||
int mult;
|
||||
float thresh, best_f0;
|
||||
int b, bmin, bmax, lmax_bin;
|
||||
float lmax, cmax;
|
||||
int prev_f0_bin;
|
||||
|
||||
/* post process estimate by searching submultiples */
|
||||
|
||||
mult = 2;
|
||||
min_bin = PE_FFT_SIZE*DEC/pmax;
|
||||
cmax_bin = gmax_bin;
|
||||
prev_f0_bin = *prev_Wo*(4000.0/PI)*(PE_FFT_SIZE*DEC)/SAMPLE_RATE;
|
||||
|
||||
while(gmax_bin/mult >= min_bin) {
|
||||
|
||||
b = gmax_bin/mult; /* determine search interval */
|
||||
bmin = 0.8*b;
|
||||
bmax = 1.2*b;
|
||||
if (bmin < min_bin)
|
||||
bmin = min_bin;
|
||||
|
||||
/* lower threshold to favour previous frames pitch estimate,
|
||||
this is a form of pitch tracking */
|
||||
|
||||
if ((prev_f0_bin > bmin) && (prev_f0_bin < bmax))
|
||||
thresh = CNLP*0.5*gmax;
|
||||
else
|
||||
thresh = CNLP*gmax;
|
||||
|
||||
lmax = 0;
|
||||
lmax_bin = bmin;
|
||||
for (b=bmin; b<=bmax; b++) /* look for maximum in interval */
|
||||
if (Fw[b].real > lmax) {
|
||||
lmax = Fw[b].real;
|
||||
lmax_bin = b;
|
||||
}
|
||||
|
||||
if (lmax > thresh)
|
||||
if ((lmax > Fw[lmax_bin-1].real) && (lmax > Fw[lmax_bin+1].real)) {
|
||||
cmax = lmax;
|
||||
cmax_bin = lmax_bin;
|
||||
}
|
||||
|
||||
mult++;
|
||||
}
|
||||
|
||||
best_f0 = (float)cmax_bin*SAMPLE_RATE/(PE_FFT_SIZE*DEC);
|
||||
|
||||
return best_f0;
|
||||
}
|
||||
|
38
libs/libcodec2/src/nlp.h
Normal file
38
libs/libcodec2/src/nlp.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: nlp.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 23/3/93
|
||||
|
||||
Non Linear Pitch (NLP) estimation functions.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __NLP__
|
||||
#define __NLP__
|
||||
|
||||
void *nlp_create();
|
||||
void nlp_destroy(void *nlp_state);
|
||||
float nlp(void *nlp_state, float Sn[], int n, int m, int pmin, int pmax,
|
||||
float *pitch, COMP Sw[], float *prev_Wo);
|
||||
float test_candidate_mbe(COMP Sw[], float f0, COMP Sw_[]);
|
||||
|
||||
#endif
|
104
libs/libcodec2/src/pack.c
Normal file
104
libs/libcodec2/src/pack.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright (C) 2010 Perens LLC <bruce@perens.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
#include "defines.h"
|
||||
#include "quantise.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* Compile-time constants */
|
||||
/* Size of unsigned char in bits. Assumes 8 bits-per-char. */
|
||||
static const unsigned int WordSize = 8;
|
||||
|
||||
/* Mask to pick the bit component out of bitIndex. */
|
||||
static const unsigned int IndexMask = 0x7;
|
||||
|
||||
/* Used to pick the word component out of bitIndex. */
|
||||
static const unsigned int ShiftRight = 3;
|
||||
|
||||
/** Pack a bit field into a bit string, encoding the field in Gray code.
|
||||
*
|
||||
* The output is an array of unsigned char data. The fields are efficiently
|
||||
* packed into the bit string. The Gray coding is a naive attempt to reduce
|
||||
* the effect of single-bit errors, we expect to do a better job as the
|
||||
* codec develops.
|
||||
*
|
||||
* This code would be simpler if it just set one bit at a time in the string,
|
||||
* but would hit the same cache line more often. I'm not sure the complexity
|
||||
* gains us anything here.
|
||||
*
|
||||
* Although field is currently of int type rather than unsigned for
|
||||
* compatibility with the rest of the code, indices are always expected to
|
||||
* be >= 0.
|
||||
*/
|
||||
void
|
||||
pack(
|
||||
unsigned char * bitArray, /* The output bit string. */
|
||||
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||
int field, /* The bit field to be packed. */
|
||||
unsigned int fieldWidth/* Width of the field in BITS, not bytes. */
|
||||
)
|
||||
{
|
||||
/* Convert the field to Gray code */
|
||||
field = (field >> 1) ^ field;
|
||||
|
||||
do {
|
||||
unsigned int bI = *bitIndex;
|
||||
unsigned int bitsLeft = WordSize - (bI & IndexMask);
|
||||
unsigned int sliceWidth =
|
||||
bitsLeft < fieldWidth ? bitsLeft : fieldWidth;
|
||||
unsigned int wordIndex = bI >> ShiftRight;
|
||||
|
||||
bitArray[wordIndex] |=
|
||||
((unsigned char)((field >> (fieldWidth - sliceWidth))
|
||||
<< (bitsLeft - sliceWidth)));
|
||||
|
||||
*bitIndex = bI + sliceWidth;
|
||||
fieldWidth -= sliceWidth;
|
||||
} while ( fieldWidth != 0 );
|
||||
}
|
||||
|
||||
/** Unpack a field from a bit string, converting from Gray code to binary.
|
||||
*
|
||||
*/
|
||||
int
|
||||
unpack(
|
||||
const unsigned char * bitArray, /* The input bit string. */
|
||||
unsigned int * bitIndex, /* Index into the string in BITS, not bytes.*/
|
||||
unsigned int fieldWidth/* Width of the field in BITS, not bytes. */
|
||||
)
|
||||
{
|
||||
unsigned int field = 0;
|
||||
|
||||
do {
|
||||
unsigned int bI = *bitIndex;
|
||||
unsigned int bitsLeft = WordSize - (bI & IndexMask);
|
||||
unsigned int sliceWidth =
|
||||
bitsLeft < fieldWidth ? bitsLeft : fieldWidth;
|
||||
|
||||
field |= (((bitArray[bI >> ShiftRight] >> (bitsLeft - sliceWidth)) & ((1 << sliceWidth) - 1)) << (fieldWidth - sliceWidth));
|
||||
|
||||
*bitIndex = bI + sliceWidth;
|
||||
fieldWidth -= sliceWidth;
|
||||
} while ( fieldWidth != 0 );
|
||||
|
||||
/* Convert from Gray code to binary. Works for maximum 8-bit fields. */
|
||||
unsigned int t = field ^ (field >> 8);
|
||||
t ^= (t >> 4);
|
||||
t ^= (t >> 2);
|
||||
t ^= (t >> 1);
|
||||
return t;
|
||||
}
|
254
libs/libcodec2/src/phase.c
Normal file
254
libs/libcodec2/src/phase.c
Normal file
@@ -0,0 +1,254 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: phase.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 1/2/09
|
||||
|
||||
Functions for modelling and synthesising phase.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#include "phase.h"
|
||||
#include "four1.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define VTHRESH 4.0
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
aks_to_H()
|
||||
|
||||
Samples the complex LPC synthesis filter spectrum at the harmonic
|
||||
frequencies.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void aks_to_H(
|
||||
MODEL *model, /* model parameters */
|
||||
float aks[], /* LPC's */
|
||||
float G, /* energy term */
|
||||
COMP H[], /* complex LPC spectral samples */
|
||||
int order
|
||||
)
|
||||
{
|
||||
COMP Pw[FFT_DEC]; /* power spectrum */
|
||||
int i,m; /* loop variables */
|
||||
int am,bm; /* limits of current band */
|
||||
float r; /* no. rads/bin */
|
||||
float Em; /* energy in band */
|
||||
float Am; /* spectral amplitude sample */
|
||||
int b; /* centre bin of harmonic */
|
||||
float phi_; /* phase of LPC spectra */
|
||||
|
||||
r = TWO_PI/(FFT_DEC);
|
||||
|
||||
/* Determine DFT of A(exp(jw)) ------------------------------------------*/
|
||||
|
||||
for(i=0; i<FFT_DEC; i++) {
|
||||
Pw[i].real = 0.0;
|
||||
Pw[i].imag = 0.0;
|
||||
}
|
||||
|
||||
for(i=0; i<=order; i++)
|
||||
Pw[i].real = aks[i];
|
||||
|
||||
four1(&Pw[-1].imag,FFT_DEC,-1);
|
||||
|
||||
/* Sample magnitude and phase at harmonics */
|
||||
|
||||
for(m=1; m<=model->L; m++) {
|
||||
am = floor((m - 0.5)*model->Wo/r + 0.5);
|
||||
bm = floor((m + 0.5)*model->Wo/r + 0.5);
|
||||
b = floor(m*model->Wo/r + 0.5);
|
||||
|
||||
Em = 0.0;
|
||||
for(i=am; i<bm; i++)
|
||||
Em += G/(Pw[i].real*Pw[i].real + Pw[i].imag*Pw[i].imag);
|
||||
Am = sqrt(fabs(Em/(bm-am)));
|
||||
|
||||
phi_ = -atan2(Pw[b].imag,Pw[b].real);
|
||||
H[m].real = Am*cos(phi_);
|
||||
H[m].imag = Am*sin(phi_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
phase_synth_zero_order()
|
||||
|
||||
Synthesises phases based on SNR and a rule based approach. No phase
|
||||
parameters are required apart from the SNR (which can be reduced to a
|
||||
1 bit V/UV decision per frame).
|
||||
|
||||
The phase of each harmonic is modelled as the phase of a LPC
|
||||
synthesis filter excited by an impulse. Unlike the first order
|
||||
model the position of the impulse is not transmitted, so we create
|
||||
an excitation pulse train using a rule based approach.
|
||||
|
||||
Consider a pulse train with a pulse starting time n=0, with pulses
|
||||
repeated at a rate of Wo, the fundamental frequency. A pulse train
|
||||
in the time domain is equivalent to harmonics in the frequency
|
||||
domain. We can make an excitation pulse train using a sum of
|
||||
sinsusoids:
|
||||
|
||||
for(m=1; m<=L; m++)
|
||||
ex[n] = cos(m*Wo*n)
|
||||
|
||||
Note: the Octave script ../octave/phase.m is an example of this if
|
||||
you would like to try making a pulse train.
|
||||
|
||||
The phase of each excitation harmonic is:
|
||||
|
||||
arg(E[m]) = mWo
|
||||
|
||||
where E[m] are the complex excitation (freq domain) samples,
|
||||
arg(x), just returns the phase of a complex sample x.
|
||||
|
||||
As we don't transmit the pulse position for this model, we need to
|
||||
synthesise it. Now the excitation pulses occur at a rate of Wo.
|
||||
This means the phase of the first harmonic advances by N samples
|
||||
over a synthesis frame of N samples. For example if Wo is pi/20
|
||||
(200 Hz), then over a 10ms frame (N=80 samples), the phase of the
|
||||
first harmonic would advance (pi/20)*80 = 4*pi or two complete
|
||||
cycles.
|
||||
|
||||
We generate the excitation phase of the fundamental (first
|
||||
harmonic):
|
||||
|
||||
arg[E[1]] = Wo*N;
|
||||
|
||||
We then relate the phase of the m-th excitation harmonic to the
|
||||
phase of the fundamental as:
|
||||
|
||||
arg(E[m]) = m*arg(E[1])
|
||||
|
||||
This E[m] then gets passed through the LPC synthesis filter to
|
||||
determine the final harmonic phase.
|
||||
|
||||
For a while there were prolems with low pitched males like hts1
|
||||
sounding "clicky". The synthesied time domain waveform also looked
|
||||
clicky. Many methods were tried to improve the sounds quality of
|
||||
low pitched males. Finally adding a small amount of jitter to each
|
||||
harmonic worked.
|
||||
|
||||
The current result sounds very close to the original phases, with
|
||||
only 1 voicing bit per frame. For example hts1a using original
|
||||
amplitudes and this phase model produces speech hard to distinguish
|
||||
from speech synthesise with the orginal phases. The sound quality
|
||||
of this patrtiallyuantised codec (nb original amplitudes) is higher
|
||||
than g729, even though all the phase information has been
|
||||
discarded.
|
||||
|
||||
NOTES:
|
||||
|
||||
1/ This synthesis model is effectvely the same as simple LPC-10
|
||||
vocoders, and yet sounds much better. Why?
|
||||
|
||||
2/ I am pretty sure the Lincoln Lab sinusoidal coding guys (like xMBE
|
||||
also from MIT) first described this zero phase model, I need to look
|
||||
up the paper.
|
||||
|
||||
3/ Note that this approach could cause some discontinuities in
|
||||
the phase at the edge of synthesis frames, as no attempt is made
|
||||
to make sure that the phase tracks are continuous (the excitation
|
||||
phases are continuous, but not the final phases after filtering
|
||||
by the LPC spectra). Technically this is a bad thing. However
|
||||
this may actually be a good thing, disturbing the phase tracks a
|
||||
bit. More research needed, e.g. test a synthesis model that adds
|
||||
a small delta-W to make phase tracks line up for voiced
|
||||
harmonics.
|
||||
|
||||
4/ Why does this sound so great with 1 V/UV decision? Conventional
|
||||
wisdom says mixed voicing is required for high qaulity speech.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void phase_synth_zero_order(
|
||||
MODEL *model,
|
||||
float aks[],
|
||||
float *ex_phase /* excitation phase of fundamental */
|
||||
)
|
||||
{
|
||||
int m;
|
||||
float new_phi;
|
||||
COMP Ex[MAX_AMP]; /* excitation samples */
|
||||
COMP A_[MAX_AMP]; /* synthesised harmonic samples */
|
||||
COMP H[MAX_AMP]; /* LPC freq domain samples */
|
||||
float G;
|
||||
float jitter;
|
||||
|
||||
G = 1.0;
|
||||
aks_to_H(model,aks,G,H,LPC_ORD);
|
||||
|
||||
/*
|
||||
Update excitation fundamental phase track, this sets the position
|
||||
of each pitch pulse during voiced speech. After much experiment
|
||||
I found that using just this frame Wo improved quality for UV
|
||||
sounds compared to interpolating two frames Wo like this:
|
||||
|
||||
ex_phase[0] += (*prev_Wo+mode->Wo)*N/2;
|
||||
*/
|
||||
|
||||
ex_phase[0] += (model->Wo)*N;
|
||||
ex_phase[0] -= TWO_PI*floor(ex_phase[0]/TWO_PI + 0.5);
|
||||
|
||||
for(m=1; m<=model->L; m++) {
|
||||
|
||||
/* generate excitation */
|
||||
|
||||
if (model->voiced) {
|
||||
/* This method of adding jitter really helped remove the clicky
|
||||
sound in low pitched makes like hts1a. This moves the onset
|
||||
of each harmonic over at +/- 0.25 of a sample.
|
||||
*/
|
||||
jitter = 0.25*(1.0 - 2.0*rand()/RAND_MAX);
|
||||
Ex[m].real = cos(ex_phase[0]*m - jitter*model->Wo*m);
|
||||
Ex[m].imag = sin(ex_phase[0]*m - jitter*model->Wo*m);
|
||||
}
|
||||
else {
|
||||
|
||||
/* When a few samples were tested I found that LPC filter
|
||||
phase is not needed in the unvoiced case, but no harm in
|
||||
keeping it.
|
||||
*/
|
||||
float phi = TWO_PI*(float)rand()/RAND_MAX;
|
||||
Ex[m].real = cos(phi);
|
||||
Ex[m].imag = sin(phi);
|
||||
}
|
||||
|
||||
/* filter using LPC filter */
|
||||
|
||||
A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag;
|
||||
A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag;
|
||||
|
||||
/* modify sinusoidal phase */
|
||||
|
||||
new_phi = atan2(A_[m].imag, A_[m].real+1E-12);
|
||||
model->phi[m] = new_phi;
|
||||
}
|
||||
|
||||
}
|
34
libs/libcodec2/src/phase.h
Normal file
34
libs/libcodec2/src/phase.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: phase.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 1/2/09
|
||||
|
||||
Functions for modelling phase.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __PHASE__
|
||||
#define __PHASE__
|
||||
|
||||
void phase_synth_zero_order(MODEL *model, float aks[], float *ex_phase);
|
||||
|
||||
#endif
|
131
libs/libcodec2/src/postfilter.c
Normal file
131
libs/libcodec2/src/postfilter.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: postfilter.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 13/09/09
|
||||
|
||||
Postfilter to improve sound quality for speech with high levels of
|
||||
background noise. Unlike mixed-excitation models requires no bits
|
||||
to be transmitted to handle background noise.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "dump.h"
|
||||
#include "postfilter.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
DEFINES
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#define BG_THRESH 40.0 /* only consider low levels signals for bg_est */
|
||||
#define BG_BETA 0.1 /* averaging filter constant */
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
postfilter()
|
||||
|
||||
The post filter is designed to help with speech corrupted by
|
||||
background noise. The zero phase model tends to make speech with
|
||||
background noise sound "clicky". With high levels of background
|
||||
noise the low level inter-formant parts of the spectrum will contain
|
||||
noise rather than speech harmonics, so modelling them as voiced
|
||||
(i.e. a continuous, non-random phase track) is inaccurate.
|
||||
|
||||
Some codecs (like MBE) have a mixed voicing model that breaks the
|
||||
spectrum into voiced and unvoiced regions. Several bits/frame
|
||||
(5-12) are required to transmit the frequency selective voicing
|
||||
information. Mixed excitation also requires accurate voicing
|
||||
estimation (parameter estimators always break occasionally under
|
||||
exceptional condition).
|
||||
|
||||
In our case we use a post filter approach which requires no
|
||||
additional bits to be transmitted. The decoder measures the average
|
||||
level of the background noise during unvoiced frames. If a harmonic
|
||||
is less than this level it is made unvoiced by randomising it's
|
||||
phases.
|
||||
|
||||
This idea is rather experimental. Some potential problems that may
|
||||
happen:
|
||||
|
||||
1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track
|
||||
up to speech level? This would be a bad thing.
|
||||
|
||||
2/ If background noise suddenly dissapears from the source speech does
|
||||
estimate drop quickly? What is noise suddenly re-appears?
|
||||
|
||||
3/ Background noise with a non-flat sepctrum. Current algorithm just
|
||||
comsiders scpetrum as a whole, but this could be broken up into
|
||||
bands, each with their own estimator.
|
||||
|
||||
4/ Males and females with the same level of background noise. Check
|
||||
performance the same. Changing Wo affects width of each band, may
|
||||
affect bg energy estimates.
|
||||
|
||||
5/ Not sure what happens during long periods of voiced speech
|
||||
e.g. "sshhhhhhh"
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void postfilter(
|
||||
MODEL *model,
|
||||
float *bg_est
|
||||
)
|
||||
{
|
||||
int m, uv;
|
||||
float e;
|
||||
|
||||
/* determine average energy across spectrum */
|
||||
|
||||
e = 0.0;
|
||||
for(m=1; m<=model->L; m++)
|
||||
e += model->A[m]*model->A[m];
|
||||
|
||||
e = 10.0*log10(e/model->L);
|
||||
|
||||
/* If beneath threhold, update bg estimate. The idea
|
||||
of the threshold is to prevent updating during high level
|
||||
speech. */
|
||||
|
||||
if ((e < BG_THRESH) && !model->voiced)
|
||||
*bg_est = *bg_est*(1.0 - BG_BETA) + e*BG_BETA;
|
||||
|
||||
/* now mess with phases during voiced frames to make any harmonics
|
||||
less then our background estimate unvoiced.
|
||||
*/
|
||||
|
||||
uv = 0;
|
||||
if (model->voiced)
|
||||
for(m=1; m<=model->L; m++)
|
||||
if (20.0*log10(model->A[m]) < *bg_est) {
|
||||
model->phi[m] = TWO_PI*(float)rand()/RAND_MAX;
|
||||
uv++;
|
||||
}
|
||||
|
||||
dump_bg(e, *bg_est, 100.0*uv/model->L);
|
||||
|
||||
}
|
34
libs/libcodec2/src/postfilter.h
Normal file
34
libs/libcodec2/src/postfilter.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: postfilter.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 13/09/09
|
||||
|
||||
Postfilter header file.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __POSTFILTER__
|
||||
#define __POSTFILTER__
|
||||
|
||||
void postfilter(MODEL *model, float *bg_est);
|
||||
|
||||
#endif
|
868
libs/libcodec2/src/quantise.c
Normal file
868
libs/libcodec2/src/quantise.c
Normal file
@@ -0,0 +1,868 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: quantise.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 31/5/92
|
||||
|
||||
Quantisation functions for the sinusoidal coder.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "dump.h"
|
||||
#include "quantise.h"
|
||||
#include "lpc.h"
|
||||
#include "lsp.h"
|
||||
#include "four1.h"
|
||||
#include "codebook.h"
|
||||
|
||||
#define LSP_DELTA1 0.01 /* grid spacing for LSP root searches */
|
||||
#define MAX_CB 20 /* max number of codebooks */
|
||||
|
||||
/* describes each codebook */
|
||||
|
||||
typedef struct {
|
||||
int k; /* dimension of vector */
|
||||
int log2m; /* number of bits in m */
|
||||
int m; /* elements in codebook */
|
||||
float *fn; /* file name of text file storing the VQ */
|
||||
} LSP_CB;
|
||||
|
||||
/* lsp_q describes entire quantiser made up of several codebooks */
|
||||
|
||||
#ifdef OLDER
|
||||
/* 10+10+6+6 = 32 bit LSP difference split VQ */
|
||||
|
||||
LSP_CB lsp_q[] = {
|
||||
{3, 1024, "/usr/src/freeswitch/libs/libcodec2-1.0/unittest/lspd123.txt"},
|
||||
{3, 1024, "/usr/src/freeswitch/libs/libcodec2-1.0/unittest/lspd456.txt"},
|
||||
{2, 64, "/usr/src/freeswitch/libs/libcodec2-1.0/unittest/lspd78.txt"},
|
||||
{2, 64, "/usr/src/freeswitch/libs/libcodec2-1.0/unittest/lspd910.txt"},
|
||||
{0, 0, ""}
|
||||
};
|
||||
#endif
|
||||
|
||||
LSP_CB lsp_q[] = {
|
||||
{1,4,16, codebook_lsp1 },
|
||||
{1,4,16, codebook_lsp2 },
|
||||
{1,4,16, codebook_lsp3 },
|
||||
{1,4,16, codebook_lsp4 },
|
||||
{1,4,16, codebook_lsp5 },
|
||||
{1,4,16, codebook_lsp6 },
|
||||
{1,4,16, codebook_lsp7 },
|
||||
{1,3,8, codebook_lsp8 },
|
||||
{1,3,8, codebook_lsp9 },
|
||||
{1,2,4, codebook_lsp10 },
|
||||
{0,0,0, NULL },
|
||||
};
|
||||
|
||||
/* ptr to each codebook */
|
||||
|
||||
static float *plsp_cb[MAX_CB];
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION HEADERS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float speech_to_uq_lsps(float lsp[], float ak[], float Sn[], float w[],
|
||||
int order);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int lsp_bits(int i) {
|
||||
return lsp_q[i].log2m;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
quantise_uniform
|
||||
|
||||
Simulates uniform quantising of a float.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void quantise_uniform(float *val, float min, float max, int bits)
|
||||
{
|
||||
int levels = 1 << (bits-1);
|
||||
float norm;
|
||||
int index;
|
||||
|
||||
/* hard limit to quantiser range */
|
||||
|
||||
printf("min: %f max: %f val: %f ", min, max, val[0]);
|
||||
if (val[0] < min) val[0] = min;
|
||||
if (val[0] > max) val[0] = max;
|
||||
|
||||
norm = (*val - min)/(max-min);
|
||||
printf("%f norm: %f ", val[0], norm);
|
||||
index = fabs(levels*norm + 0.5);
|
||||
|
||||
*val = min + index*(max-min)/levels;
|
||||
|
||||
printf("index %d val_: %f\n", index, val[0]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
lspd_quantise
|
||||
|
||||
Simulates differential lsp quantiser
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void lsp_quantise(
|
||||
float lsp[],
|
||||
float lsp_[],
|
||||
int order
|
||||
)
|
||||
{
|
||||
int i;
|
||||
float dlsp[LPC_MAX];
|
||||
float dlsp_[LPC_MAX];
|
||||
|
||||
dlsp[0] = lsp[0];
|
||||
for(i=1; i<order; i++)
|
||||
dlsp[i] = lsp[i] - lsp[i-1];
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
dlsp_[i] = dlsp[i];
|
||||
|
||||
quantise_uniform(&dlsp_[0], 0.1, 0.5, 5);
|
||||
|
||||
lsp_[0] = dlsp_[0];
|
||||
for(i=1; i<order; i++)
|
||||
lsp_[i] = lsp_[i-1] + dlsp_[i];
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
scan_line()
|
||||
|
||||
This function reads a vector of floats from a line in a text file.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void scan_line(FILE *fp, float f[], int n)
|
||||
/* FILE *fp; file ptr to text file */
|
||||
/* float f[]; array of floats to return */
|
||||
/* int n; number of floats in line */
|
||||
{
|
||||
char s[MAX_STR];
|
||||
char *ps,*pe;
|
||||
int i;
|
||||
|
||||
fgets(s,MAX_STR,fp);
|
||||
ps = pe = s;
|
||||
for(i=0; i<n; i++) {
|
||||
while( isspace(*pe)) pe++;
|
||||
while( !isspace(*pe)) pe++;
|
||||
sscanf(ps,"%f",&f[i]);
|
||||
ps = pe;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
load_cb
|
||||
|
||||
Loads a single codebook (LSP vector quantiser) into memory.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void load_cb(float *source, float *cb, int k, int m)
|
||||
{
|
||||
int lines;
|
||||
int i;
|
||||
|
||||
lines = 0;
|
||||
for(i=0; i<m; i++) {
|
||||
cb[k*lines++] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
quantise_init
|
||||
|
||||
Loads the entire LSP quantiser comprised of several vector quantisers
|
||||
(codebooks).
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void quantise_init()
|
||||
{
|
||||
int i,k,m;
|
||||
|
||||
i = 0;
|
||||
while(lsp_q[i].k) {
|
||||
k = lsp_q[i].k;
|
||||
m = lsp_q[i].m;
|
||||
plsp_cb[i] = (float*)malloc(sizeof(float)*k*m);
|
||||
assert(plsp_cb[i] != NULL);
|
||||
load_cb(lsp_q[i].fn, plsp_cb[i], k, m);
|
||||
i++;
|
||||
assert(i < MAX_CB);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
quantise
|
||||
|
||||
Quantises vec by choosing the nearest vector in codebook cb, and
|
||||
returns the vector index. The squared error of the quantised vector
|
||||
is added to se.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
long quantise(float cb[], float vec[], float w[], int k, int m, float *se)
|
||||
/* float cb[][K]; current VQ codebook */
|
||||
/* float vec[]; vector to quantise */
|
||||
/* float w[]; weighting vector */
|
||||
/* int k; dimension of vectors */
|
||||
/* int m; size of codebook */
|
||||
/* float *se; accumulated squared error */
|
||||
{
|
||||
float e; /* current error */
|
||||
long besti; /* best index so far */
|
||||
float beste; /* best error so far */
|
||||
long j;
|
||||
int i;
|
||||
|
||||
besti = 0;
|
||||
beste = 1E32;
|
||||
for(j=0; j<m; j++) {
|
||||
e = 0.0;
|
||||
for(i=0; i<k; i++)
|
||||
e += pow((cb[j*k+i]-vec[i])*w[i],2.0);
|
||||
if (e < beste) {
|
||||
beste = e;
|
||||
besti = j;
|
||||
}
|
||||
}
|
||||
|
||||
*se += beste;
|
||||
|
||||
return(besti);
|
||||
}
|
||||
|
||||
static float gmin=PI;
|
||||
|
||||
float get_gmin(void) { return gmin; }
|
||||
|
||||
void min_lsp_dist(float lsp[], int order)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=1; i<order; i++)
|
||||
if ((lsp[i]-lsp[i-1]) < gmin)
|
||||
gmin = lsp[i]-lsp[i-1];
|
||||
}
|
||||
|
||||
void check_lsp_order(float lsp[], int lpc_order)
|
||||
{
|
||||
int i;
|
||||
float tmp;
|
||||
|
||||
for(i=1; i<lpc_order; i++)
|
||||
if (lsp[i] < lsp[i-1]) {
|
||||
printf("swap %d\n",i);
|
||||
tmp = lsp[i-1];
|
||||
lsp[i-1] = lsp[i]-0.05;
|
||||
lsp[i] = tmp+0.05;
|
||||
}
|
||||
}
|
||||
|
||||
void force_min_lsp_dist(float lsp[], int lpc_order)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=1; i<lpc_order; i++)
|
||||
if ((lsp[i]-lsp[i-1]) < 0.01) {
|
||||
lsp[i] += 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
lpc_model_amplitudes
|
||||
|
||||
Derive a LPC model for amplitude samples then estimate amplitude samples
|
||||
from this model with optional LSP quantisation.
|
||||
|
||||
Returns the spectral distortion for this frame.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float lpc_model_amplitudes(
|
||||
float Sn[], /* Input frame of speech samples */
|
||||
float w[],
|
||||
MODEL *model, /* sinusoidal model parameters */
|
||||
int order, /* LPC model order */
|
||||
int lsp_quant, /* optional LSP quantisation if non-zero */
|
||||
float ak[] /* output aks */
|
||||
)
|
||||
{
|
||||
float Wn[M];
|
||||
float R[LPC_MAX+1];
|
||||
float E;
|
||||
int i,j;
|
||||
float snr;
|
||||
float lsp[LPC_MAX];
|
||||
float lsp_hz[LPC_MAX];
|
||||
float lsp_[LPC_MAX];
|
||||
int roots; /* number of LSP roots found */
|
||||
int index;
|
||||
float se;
|
||||
int k,m;
|
||||
float *cb;
|
||||
float wt[LPC_MAX];
|
||||
|
||||
for(i=0; i<M; i++)
|
||||
Wn[i] = Sn[i]*w[i];
|
||||
autocorrelate(Wn,R,M,order);
|
||||
levinson_durbin(R,ak,order);
|
||||
|
||||
E = 0.0;
|
||||
for(i=0; i<=order; i++)
|
||||
E += ak[i]*R[i];
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
wt[i] = 1.0;
|
||||
|
||||
if (lsp_quant) {
|
||||
roots = lpc_to_lsp(ak, order, lsp, 5, LSP_DELTA1);
|
||||
if (roots != order)
|
||||
printf("LSP roots not found\n");
|
||||
|
||||
/* convert from radians to Hz to make quantisers more
|
||||
human readable */
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
lsp_hz[i] = (4000.0/PI)*lsp[i];
|
||||
|
||||
/* simple uniform scalar quantisers */
|
||||
|
||||
for(i=0; i<10; i++) {
|
||||
k = lsp_q[i].k;
|
||||
m = lsp_q[i].m;
|
||||
cb = plsp_cb[i];
|
||||
index = quantise(cb, &lsp_hz[i], wt, k, m, &se);
|
||||
lsp_hz[i] = cb[index*k];
|
||||
}
|
||||
|
||||
/* experiment: simulating uniform quantisation error
|
||||
for(i=0; i<order; i++)
|
||||
lsp[i] += PI*(12.5/4000.0)*(1.0 - 2.0*(float)rand()/RAND_MAX);
|
||||
*/
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
lsp[i] = (PI/4000.0)*lsp_hz[i];
|
||||
|
||||
/* Bandwidth Expansion (BW). Prevents any two LSPs getting too
|
||||
close together after quantisation. We know from experiment
|
||||
that LSP quantisation errors < 12.5Hz (25Hz setp size) are
|
||||
inaudible so we use that as the minimum LSP separation.
|
||||
*/
|
||||
|
||||
for(i=1; i<5; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(12.5/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(12.5/4000.0);
|
||||
}
|
||||
|
||||
/* as quantiser gaps increased, larger BW expansion was required
|
||||
to prevent twinkly noises */
|
||||
|
||||
for(i=5; i<8; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(25.0/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(25.0/4000.0);
|
||||
}
|
||||
for(i=8; i<order; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(75.0/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(75.0/4000.0);
|
||||
}
|
||||
|
||||
for(j=0; j<order; j++)
|
||||
lsp_[j] = lsp[j];
|
||||
|
||||
lsp_to_lpc(lsp_, ak, order);
|
||||
dump_lsp(lsp);
|
||||
}
|
||||
|
||||
dump_E(E);
|
||||
#ifdef SIM_QUANT
|
||||
/* simulated LPC energy quantisation */
|
||||
{
|
||||
float e = 10.0*log10(E);
|
||||
e += 2.0*(1.0 - 2.0*(float)rand()/RAND_MAX);
|
||||
E = pow(10.0,e/10.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
aks_to_M2(ak,order,model,E,&snr, 1); /* {ak} -> {Am} LPC decode */
|
||||
|
||||
return snr;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
aks_to_M2()
|
||||
|
||||
Transforms the linear prediction coefficients to spectral amplitude
|
||||
samples. This function determines A(m) from the average energy per
|
||||
band using an FFT.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void aks_to_M2(
|
||||
float ak[], /* LPC's */
|
||||
int order,
|
||||
MODEL *model, /* sinusoidal model parameters for this frame */
|
||||
float E, /* energy term */
|
||||
float *snr, /* signal to noise ratio for this frame in dB */
|
||||
int dump /* true to dump sample to dump file */
|
||||
)
|
||||
{
|
||||
COMP Pw[FFT_DEC]; /* power spectrum */
|
||||
int i,m; /* loop variables */
|
||||
int am,bm; /* limits of current band */
|
||||
float r; /* no. rads/bin */
|
||||
float Em; /* energy in band */
|
||||
float Am; /* spectral amplitude sample */
|
||||
float signal, noise;
|
||||
|
||||
r = TWO_PI/(FFT_DEC);
|
||||
|
||||
/* Determine DFT of A(exp(jw)) --------------------------------------------*/
|
||||
|
||||
for(i=0; i<FFT_DEC; i++) {
|
||||
Pw[i].real = 0.0;
|
||||
Pw[i].imag = 0.0;
|
||||
}
|
||||
|
||||
for(i=0; i<=order; i++)
|
||||
Pw[i].real = ak[i];
|
||||
four1(&Pw[-1].imag,FFT_DEC,1);
|
||||
|
||||
/* Determine power spectrum P(w) = E/(A(exp(jw))^2 ------------------------*/
|
||||
|
||||
for(i=0; i<FFT_DEC/2; i++)
|
||||
Pw[i].real = E/(Pw[i].real*Pw[i].real + Pw[i].imag*Pw[i].imag);
|
||||
if (dump)
|
||||
dump_Pw(Pw);
|
||||
|
||||
/* Determine magnitudes by linear interpolation of P(w) -------------------*/
|
||||
|
||||
signal = noise = 0.0;
|
||||
for(m=1; m<=model->L; m++) {
|
||||
am = floor((m - 0.5)*model->Wo/r + 0.5);
|
||||
bm = floor((m + 0.5)*model->Wo/r + 0.5);
|
||||
Em = 0.0;
|
||||
|
||||
for(i=am; i<bm; i++)
|
||||
Em += Pw[i].real;
|
||||
Am = sqrt(Em);
|
||||
|
||||
signal += pow(model->A[m],2.0);
|
||||
noise += pow(model->A[m] - Am,2.0);
|
||||
model->A[m] = Am;
|
||||
}
|
||||
*snr = 10.0*log10(signal/noise);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: encode_Wo()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Encodes Wo using a WO_LEVELS quantiser.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int encode_Wo(float Wo)
|
||||
{
|
||||
int index;
|
||||
float Wo_min = TWO_PI/P_MAX;
|
||||
float Wo_max = TWO_PI/P_MIN;
|
||||
float norm;
|
||||
|
||||
norm = (Wo - Wo_min)/(Wo_max - Wo_min);
|
||||
index = floor(WO_LEVELS * norm + 0.5);
|
||||
if (index < 0 ) index = 0;
|
||||
if (index > (WO_LEVELS-1)) index = WO_LEVELS-1;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: decode_Wo()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Decodes Wo using a WO_LEVELS quantiser.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float decode_Wo(int index)
|
||||
{
|
||||
float Wo_min = TWO_PI/P_MAX;
|
||||
float Wo_max = TWO_PI/P_MIN;
|
||||
float step;
|
||||
float Wo;
|
||||
|
||||
step = (Wo_max - Wo_min)/WO_LEVELS;
|
||||
Wo = Wo_min + step*(index);
|
||||
|
||||
return Wo;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: speech_to_uq_lsps()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Analyse a windowed frame of time domain speech to determine LPCs
|
||||
which are the converted to LSPs for quantisation and transmission
|
||||
over the channel.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float speech_to_uq_lsps(float lsp[],
|
||||
float ak[],
|
||||
float Sn[],
|
||||
float w[],
|
||||
int order
|
||||
)
|
||||
{
|
||||
int i, roots;
|
||||
float Wn[M];
|
||||
float R[LPC_MAX+1];
|
||||
float E;
|
||||
|
||||
for(i=0; i<M; i++)
|
||||
Wn[i] = Sn[i]*w[i];
|
||||
autocorrelate(Wn, R, M, order);
|
||||
levinson_durbin(R, ak, order);
|
||||
|
||||
E = 0.0;
|
||||
for(i=0; i<=order; i++)
|
||||
E += ak[i]*R[i];
|
||||
|
||||
roots = lpc_to_lsp(ak, order, lsp, 5, LSP_DELTA1);
|
||||
// assert(roots == order);
|
||||
|
||||
return E;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: encode_lsps()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
From a vector of unquantised (floating point) LSPs finds the quantised
|
||||
LSP indexes.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void encode_lsps(int indexes[], float lsp[], int order)
|
||||
{
|
||||
int i,k,m;
|
||||
float wt[1];
|
||||
float lsp_hz[LPC_MAX];
|
||||
float *cb, se;
|
||||
|
||||
/* convert from radians to Hz so we can use human readable
|
||||
frequencies */
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
lsp_hz[i] = (4000.0/PI)*lsp[i];
|
||||
|
||||
/* simple uniform scalar quantisers */
|
||||
|
||||
wt[0] = 1.0;
|
||||
for(i=0; i<order; i++) {
|
||||
k = lsp_q[i].k;
|
||||
m = lsp_q[i].m;
|
||||
cb = plsp_cb[i];
|
||||
indexes[i] = quantise(cb, &lsp_hz[i], wt, k, m, &se);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: decode_lsps()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
From a vector of quantised LSP indexes, returns the quantised
|
||||
(floating point) LSPs.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void decode_lsps(float lsp[], int indexes[], int order)
|
||||
{
|
||||
int i,k;
|
||||
float lsp_hz[LPC_MAX];
|
||||
float *cb;
|
||||
|
||||
for(i=0; i<order; i++) {
|
||||
k = lsp_q[i].k;
|
||||
cb = plsp_cb[i];
|
||||
lsp_hz[i] = cb[indexes[i]*k];
|
||||
}
|
||||
|
||||
/* convert back to radians */
|
||||
|
||||
for(i=0; i<order; i++)
|
||||
lsp[i] = (PI/4000.0)*lsp_hz[i];
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: bw_expand_lsps()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Applies Bandwidth Expansion (BW) to a vector of LSPs. Prevents any
|
||||
two LSPs getting too close together after quantisation. We know
|
||||
from experiment that LSP quantisation errors < 12.5Hz (25Hz setp
|
||||
size) are inaudible so we use that as the minimum LSP separation.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void bw_expand_lsps(float lsp[],
|
||||
int order
|
||||
)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=1; i<5; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(12.5/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(12.5/4000.0);
|
||||
}
|
||||
|
||||
/* As quantiser gaps increased, larger BW expansion was required
|
||||
to prevent twinkly noises. This may need more experiment for
|
||||
different quanstisers.
|
||||
*/
|
||||
|
||||
for(i=5; i<8; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(25.0/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(25.0/4000.0);
|
||||
}
|
||||
for(i=8; i<order; i++) {
|
||||
if (lsp[i] - lsp[i-1] < PI*(75.0/4000.0))
|
||||
lsp[i] = lsp[i-1] + PI*(75.0/4000.0);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: need_lpc_correction()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Determine if we need LPC correction of first harmonic.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int need_lpc_correction(MODEL *model, float ak[], float E)
|
||||
{
|
||||
MODEL tmp;
|
||||
float snr,E1;
|
||||
|
||||
/* Find amplitudes so we can check if we need LPC correction.
|
||||
TODO: replace call to aks_to_M2() by a single DFT calculation
|
||||
of E/A(exp(jWo)) to make much more efficient. We only need
|
||||
A[1].
|
||||
*/
|
||||
|
||||
memcpy(&tmp, model, sizeof(MODEL));
|
||||
aks_to_M2(ak, LPC_ORD, &tmp, E, &snr, 0);
|
||||
|
||||
/*
|
||||
Attenuate fundamental by 30dB if F0 < 150 Hz and LPC modelling
|
||||
error for A[1] is larger than 6dB.
|
||||
|
||||
LPC modelling often makes big errors on 1st harmonic, for example
|
||||
when the fundamental has been removed by analog high pass
|
||||
filtering before sampling. However on unfiltered speech from
|
||||
high quality sources we would like to keep the fundamental to
|
||||
maintain the speech quality. So we check the error in A[1] and
|
||||
attenuate it if the error is large to avoid annoying low
|
||||
frequency energy after LPC modelling.
|
||||
|
||||
This requires a single bit to quantise, on top of the other
|
||||
spectral magnitude bits (i.e. LSP bits + 1 total).
|
||||
*/
|
||||
|
||||
E1 = fabs(20.0*log10(model->A[1]) - 20.0*log10(tmp.A[1]));
|
||||
if (E1 > 6.0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: apply_lpc_correction()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Apply first harmonic LPC correction at decoder.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void apply_lpc_correction(MODEL *model, int lpc_correction)
|
||||
{
|
||||
if (lpc_correction) {
|
||||
if (model->Wo < (PI*150.0/4000)) {
|
||||
model->A[1] *= 0.032;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: encode_energy()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Encodes LPC energy using an E_LEVELS quantiser.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
int encode_energy(float e)
|
||||
{
|
||||
int index;
|
||||
float e_min = E_MIN_DB;
|
||||
float e_max = E_MAX_DB;
|
||||
float norm;
|
||||
|
||||
e = 10.0*log10(e);
|
||||
norm = (e - e_min)/(e_max - e_min);
|
||||
index = floor(E_LEVELS * norm + 0.5);
|
||||
if (index < 0 ) index = 0;
|
||||
if (index > (E_LEVELS-1)) index = E_LEVELS-1;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: decode_energy()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Decodes energy using a WO_BITS quantiser.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float decode_energy(int index)
|
||||
{
|
||||
float e_min = E_MIN_DB;
|
||||
float e_max = E_MAX_DB;
|
||||
float step;
|
||||
float e;
|
||||
|
||||
step = (e_max - e_min)/E_LEVELS;
|
||||
e = e_min + step*(index);
|
||||
e = pow(10.0,e/10.0);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: encode_amplitudes()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Time domain LPC is used model the amplitudes which are then
|
||||
converted to LSPs and quantised. So we don't actually encode the
|
||||
amplitudes directly, rather we derive an equivalent representation
|
||||
from the time domain speech.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void encode_amplitudes(int lsp_indexes[],
|
||||
int *lpc_correction,
|
||||
int *energy_index,
|
||||
MODEL *model,
|
||||
float Sn[],
|
||||
float w[])
|
||||
{
|
||||
float lsps[LPC_ORD];
|
||||
float ak[LPC_ORD+1];
|
||||
float e;
|
||||
|
||||
e = speech_to_uq_lsps(lsps, ak, Sn, w, LPC_ORD);
|
||||
encode_lsps(lsp_indexes, lsps, LPC_ORD);
|
||||
*lpc_correction = need_lpc_correction(model, ak, e);
|
||||
*energy_index = encode_energy(e);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: decode_amplitudes()
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 22/8/2010
|
||||
|
||||
Given the amplitude quantiser indexes recovers the harmonic
|
||||
amplitudes.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float decode_amplitudes(MODEL *model,
|
||||
float ak[],
|
||||
int lsp_indexes[],
|
||||
int lpc_correction,
|
||||
int energy_index
|
||||
)
|
||||
{
|
||||
float lsps[LPC_ORD];
|
||||
float e;
|
||||
float snr;
|
||||
|
||||
decode_lsps(lsps, lsp_indexes, LPC_ORD);
|
||||
bw_expand_lsps(lsps, LPC_ORD);
|
||||
lsp_to_lpc(lsps, ak, LPC_ORD);
|
||||
e = decode_energy(energy_index);
|
||||
aks_to_M2(ak, LPC_ORD, model, e, &snr, 1);
|
||||
apply_lpc_correction(model, lpc_correction);
|
||||
|
||||
return snr;
|
||||
}
|
84
libs/libcodec2/src/quantise.h
Normal file
84
libs/libcodec2/src/quantise.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: quantise.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 31/5/92
|
||||
|
||||
Quantisation functions for the sinusoidal coder.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __QUANTISE__
|
||||
#define __QUANTISE__
|
||||
|
||||
#define WO_BITS 7
|
||||
#define WO_LEVELS (1<<WO_BITS)
|
||||
#define E_BITS 5
|
||||
#define E_LEVELS (1<<E_BITS)
|
||||
#define E_MIN_DB -10.0
|
||||
#define E_MAX_DB 40.0
|
||||
|
||||
void quantise_init();
|
||||
float lpc_model_amplitudes(float Sn[], float w[], MODEL *model, int order,
|
||||
int lsp,float ak[]);
|
||||
void aks_to_M2(float ak[], int order, MODEL *model, float E, float *snr,
|
||||
int dump);
|
||||
float get_gmin(void);
|
||||
|
||||
int encode_Wo(float Wo);
|
||||
float decode_Wo(int index);
|
||||
|
||||
void encode_lsps(int indexes[], float lsp[], int order);
|
||||
void decode_lsps(float lsp[], int indexes[], int order);
|
||||
|
||||
int encode_energy(float e);
|
||||
float decode_energy(int index);
|
||||
|
||||
void encode_amplitudes(int lsp_indexes[],
|
||||
int *lpc_correction,
|
||||
int *energy_index,
|
||||
MODEL *model,
|
||||
float Sn[],
|
||||
float w[]);
|
||||
|
||||
float decode_amplitudes(MODEL *model,
|
||||
float ak[],
|
||||
int lsp_indexes[],
|
||||
int lpc_correction,
|
||||
int energy_index);
|
||||
|
||||
void pack(unsigned char * bits, unsigned int *nbit, int index, unsigned int index_bits);
|
||||
int unpack(const unsigned char * bits, unsigned int *nbit, unsigned int index_bits);
|
||||
|
||||
int lsp_bits(int i);
|
||||
|
||||
int need_lpc_correction(MODEL *model, float ak[], float E);
|
||||
void apply_lpc_correction(MODEL *model, int lpc_correction);
|
||||
float speech_to_uq_lsps(float lsp[],
|
||||
float ak[],
|
||||
float Sn[],
|
||||
float w[],
|
||||
int order
|
||||
);
|
||||
void bw_expand_lsps(float lsp[],
|
||||
int order
|
||||
);
|
||||
void decode_lsps(float lsp[], int indexes[], int order);
|
||||
|
||||
#endif
|
18
libs/libcodec2/src/sim.sh
Executable file
18
libs/libcodec2/src/sim.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# sim.sh
|
||||
# David Rowe 10 Sep 2009
|
||||
|
||||
# Process a source file using the codec 2 simulation. An output
|
||||
# speech file is generated for each major processing step, from the
|
||||
# unquantised siusoidal model to fully quantised. This way we can
|
||||
# listen to the effect of each processing step. Use listensim.sh to
|
||||
# test the output files.
|
||||
|
||||
../src/c2sim ../raw/$1.raw -o $1_uq.raw
|
||||
../src/c2sim ../raw/$1.raw --phase0 -o $1_phase0.raw --postfilter
|
||||
../src/c2sim ../raw/$1.raw --lpc 10 -o $1_lpc10.raw
|
||||
../src/c2sim ../raw/$1.raw --lpc 10 --lsp -o $1_lsp.raw
|
||||
../src/c2sim ../raw/$1.raw --phase0 --lpc 10 -o $1_phase0_lpc10.raw --postfilter
|
||||
../src/c2sim ../raw/$1.raw --phase0 --lpc 10 --lsp -o $1_phase0_lsp.raw --postfilter
|
||||
../src/c2sim ../raw/$1.raw --phase0 --lpc 10 --lsp -o $1_phase0_lsp_dec.raw --postfilter --dec
|
||||
|
530
libs/libcodec2/src/sine.c
Normal file
530
libs/libcodec2/src/sine.c
Normal file
@@ -0,0 +1,530 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: sine.c
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 19/8/2010
|
||||
|
||||
Sinusoidal analysis and synthesis functions.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1990-2010 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
INCLUDES
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "sine.h"
|
||||
#include "four1.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
HEADERS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax,
|
||||
float pstep);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: make_analysis_window
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 11/5/94
|
||||
|
||||
Init function that generates the time domain analysis window and it's DFT.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void make_analysis_window(float w[],COMP W[])
|
||||
{
|
||||
float m;
|
||||
COMP temp;
|
||||
int i,j;
|
||||
|
||||
/*
|
||||
Generate Hamming window centered on M-sample pitch analysis window
|
||||
|
||||
0 M/2 M-1
|
||||
|-------------|-------------|
|
||||
|-------|-------|
|
||||
NW samples
|
||||
|
||||
All our analysis/synthsis is centred on the M/2 sample.
|
||||
*/
|
||||
|
||||
m = 0.0;
|
||||
for(i=0; i<M/2-NW/2; i++)
|
||||
w[i] = 0.0;
|
||||
for(i=M/2-NW/2,j=0; i<M/2+NW/2; i++,j++) {
|
||||
w[i] = 0.5 - 0.5*cos(TWO_PI*j/(NW-1));
|
||||
m += w[i]*w[i];
|
||||
}
|
||||
for(i=M/2+NW/2; i<M; i++)
|
||||
w[i] = 0.0;
|
||||
|
||||
/* Normalise - makes freq domain amplitude estimation straight
|
||||
forward */
|
||||
|
||||
m = 1.0/sqrt(m*FFT_ENC);
|
||||
for(i=0; i<M; i++) {
|
||||
w[i] *= m;
|
||||
}
|
||||
|
||||
/*
|
||||
Generate DFT of analysis window, used for later processing. Note
|
||||
we modulo FFT_ENC shift the time domain window w[], this makes the
|
||||
imaginary part of the DFT W[] equal to zero as the shifted w[] is
|
||||
even about the n=0 time axis if NW is odd. Having the imag part
|
||||
of the DFT W[] makes computation easier.
|
||||
|
||||
0 FFT_ENC-1
|
||||
|-------------------------|
|
||||
|
||||
----\ /----
|
||||
\ /
|
||||
\ / <- shifted version of window w[n]
|
||||
\ /
|
||||
\ /
|
||||
-------
|
||||
|
||||
|---------| |---------|
|
||||
NW/2 NW/2
|
||||
*/
|
||||
|
||||
for(i=0; i<FFT_ENC; i++) {
|
||||
W[i].real = 0.0;
|
||||
W[i].imag = 0.0;
|
||||
}
|
||||
for(i=0; i<NW/2; i++)
|
||||
W[i].real = w[i+M/2];
|
||||
for(i=FFT_ENC-NW/2,j=M/2-NW/2; i<FFT_ENC; i++,j++)
|
||||
W[i].real = w[j];
|
||||
|
||||
four1(&W[-1].imag,FFT_ENC,-1); /* "Numerical Recipes in C" FFT */
|
||||
|
||||
/*
|
||||
Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later
|
||||
analysis convenient.
|
||||
|
||||
Before:
|
||||
|
||||
|
||||
0 FFT_ENC-1
|
||||
|----------|---------|
|
||||
__ _
|
||||
\ /
|
||||
\_______________/
|
||||
|
||||
After:
|
||||
|
||||
0 FFT_ENC-1
|
||||
|----------|---------|
|
||||
___
|
||||
/ \
|
||||
________/ \_______
|
||||
|
||||
*/
|
||||
|
||||
|
||||
for(i=0; i<FFT_ENC/2; i++) {
|
||||
temp.real = W[i].real;
|
||||
temp.imag = W[i].imag;
|
||||
W[i].real = W[i+FFT_ENC/2].real;
|
||||
W[i].imag = W[i+FFT_ENC/2].imag;
|
||||
W[i+FFT_ENC/2].real = temp.real;
|
||||
W[i+FFT_ENC/2].imag = temp.imag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: dft_speech
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 27/5/94
|
||||
|
||||
Finds the DFT of the current speech input speech frame.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void dft_speech(COMP Sw[], float Sn[], float w[])
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<FFT_ENC; i++) {
|
||||
Sw[i].real = 0.0;
|
||||
Sw[i].imag = 0.0;
|
||||
}
|
||||
|
||||
/* Centre analysis window on time axis, we need to arrange input
|
||||
to FFT this way to make FFT phases correct */
|
||||
|
||||
/* move 2nd half to start of FFT input vector */
|
||||
|
||||
for(i=0; i<NW/2; i++)
|
||||
Sw[i].real = Sn[i+M/2]*w[i+M/2];
|
||||
|
||||
/* move 1st half to end of FFT input vector */
|
||||
|
||||
for(i=0; i<NW/2; i++)
|
||||
Sw[FFT_ENC-NW/2+i].real = Sn[i+M/2-NW/2]*w[i+M/2-NW/2];
|
||||
|
||||
four1(&Sw[-1].imag,FFT_ENC,-1);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: two_stage_pitch_refinement
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 27/5/94
|
||||
|
||||
Refines the current pitch estimate using the harmonic sum pitch
|
||||
estimation technique.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void two_stage_pitch_refinement(MODEL *model, COMP Sw[])
|
||||
{
|
||||
float pmin,pmax,pstep; /* pitch refinment minimum, maximum and step */
|
||||
|
||||
/* Coarse refinement */
|
||||
|
||||
pmax = TWO_PI/model->Wo + 5;
|
||||
pmin = TWO_PI/model->Wo - 5;
|
||||
pstep = 1.0;
|
||||
hs_pitch_refinement(model,Sw,pmin,pmax,pstep);
|
||||
|
||||
/* Fine refinement */
|
||||
|
||||
pmax = TWO_PI/model->Wo + 1;
|
||||
pmin = TWO_PI/model->Wo - 1;
|
||||
pstep = 0.25;
|
||||
hs_pitch_refinement(model,Sw,pmin,pmax,pstep);
|
||||
|
||||
/* Limit range */
|
||||
|
||||
if (model->Wo < TWO_PI/P_MAX)
|
||||
model->Wo = TWO_PI/P_MAX;
|
||||
if (model->Wo > TWO_PI/P_MIN)
|
||||
model->Wo = TWO_PI/P_MIN;
|
||||
|
||||
model->L = floor(PI/model->Wo);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: hs_pitch_refinement
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 27/5/94
|
||||
|
||||
Harmonic sum pitch refinement function.
|
||||
|
||||
pmin pitch search range minimum
|
||||
pmax pitch search range maximum
|
||||
step pitch search step size
|
||||
model current pitch estimate in model.Wo
|
||||
|
||||
model refined pitch estimate in model.Wo
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void hs_pitch_refinement(MODEL *model, COMP Sw[], float pmin, float pmax, float pstep)
|
||||
{
|
||||
int m; /* loop variable */
|
||||
int b; /* bin for current harmonic centre */
|
||||
float E; /* energy for current pitch*/
|
||||
float Wo; /* current "test" fundamental freq. */
|
||||
float Wom; /* Wo that maximises E */
|
||||
float Em; /* mamimum energy */
|
||||
float r; /* number of rads/bin */
|
||||
float p; /* current pitch */
|
||||
|
||||
/* Initialisation */
|
||||
|
||||
model->L = PI/model->Wo; /* use initial pitch est. for L */
|
||||
Wom = model->Wo;
|
||||
Em = 0.0;
|
||||
r = TWO_PI/FFT_ENC;
|
||||
|
||||
/* Determine harmonic sum for a range of Wo values */
|
||||
|
||||
for(p=pmin; p<=pmax; p+=pstep) {
|
||||
E = 0.0;
|
||||
Wo = TWO_PI/p;
|
||||
|
||||
/* Sum harmonic magnitudes */
|
||||
|
||||
for(m=1; m<=model->L; m++) {
|
||||
b = floor(m*Wo/r + 0.5);
|
||||
E += Sw[b].real*Sw[b].real + Sw[b].imag*Sw[b].imag;
|
||||
}
|
||||
|
||||
/* Compare to see if this is a maximum */
|
||||
|
||||
if (E > Em) {
|
||||
Em = E;
|
||||
Wom = Wo;
|
||||
}
|
||||
}
|
||||
|
||||
model->Wo = Wom;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: estimate_amplitudes
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 27/5/94
|
||||
|
||||
Estimates the complex amplitudes of the harmonics.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[])
|
||||
{
|
||||
int i,m; /* loop variables */
|
||||
int am,bm; /* bounds of current harmonic */
|
||||
int b; /* DFT bin of centre of current harmonic */
|
||||
float den; /* denominator of amplitude expression */
|
||||
float r; /* number of rads/bin */
|
||||
int offset;
|
||||
COMP Am;
|
||||
|
||||
r = TWO_PI/FFT_ENC;
|
||||
|
||||
for(m=1; m<=model->L; m++) {
|
||||
den = 0.0;
|
||||
am = floor((m - 0.5)*model->Wo/r + 0.5);
|
||||
bm = floor((m + 0.5)*model->Wo/r + 0.5);
|
||||
b = floor(m*model->Wo/r + 0.5);
|
||||
|
||||
/* Estimate ampltude of harmonic */
|
||||
|
||||
den = 0.0;
|
||||
Am.real = Am.imag = 0.0;
|
||||
for(i=am; i<bm; i++) {
|
||||
den += Sw[i].real*Sw[i].real + Sw[i].imag*Sw[i].imag;
|
||||
offset = i + FFT_ENC/2 - floor(m*model->Wo/r + 0.5);
|
||||
Am.real += Sw[i].real*W[offset].real;
|
||||
Am.imag += Sw[i].imag*W[offset].real;
|
||||
}
|
||||
|
||||
model->A[m] = sqrt(den);
|
||||
|
||||
/* Estimate phase of harmonic */
|
||||
|
||||
model->phi[m] = atan2(Sw[b].imag,Sw[b].real);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
est_voicing_mbe()
|
||||
|
||||
Returns the error of the MBE cost function for a fiven F0.
|
||||
|
||||
Note: I think a lot of the operations below can be simplified as
|
||||
W[].imag = 0 and has been normalised such that den always equals 1.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
float est_voicing_mbe(
|
||||
MODEL *model,
|
||||
COMP Sw[],
|
||||
COMP W[],
|
||||
float f0,
|
||||
COMP Sw_[] /* DFT of all voiced synthesised signal for f0 */
|
||||
/* useful for debugging/dump file */
|
||||
)
|
||||
{
|
||||
int i,l,al,bl,m; /* loop variables */
|
||||
COMP Am; /* amplitude sample for this band */
|
||||
int offset; /* centers Hw[] about current harmonic */
|
||||
float den; /* denominator of Am expression */
|
||||
float error; /* accumulated error between originl and synthesised */
|
||||
float Wo; /* current "test" fundamental freq. */
|
||||
int L;
|
||||
float sig, snr;
|
||||
|
||||
sig = 0.0;
|
||||
for(l=1; l<=model->L/4; l++) {
|
||||
sig += model->A[l]*model->A[l];
|
||||
}
|
||||
|
||||
for(i=0; i<FFT_ENC; i++) {
|
||||
Sw_[i].real = 0.0;
|
||||
Sw_[i].imag = 0.0;
|
||||
}
|
||||
|
||||
L = floor((FS/2.0)/f0);
|
||||
Wo = f0*(TWO_PI/FS);
|
||||
|
||||
error = 0.0;
|
||||
|
||||
/* Just test across the harmonics in the first 1000 Hz (L/4) */
|
||||
|
||||
for(l=1; l<=L/4; l++) {
|
||||
Am.real = 0.0;
|
||||
Am.imag = 0.0;
|
||||
den = 0.0;
|
||||
al = ceil((l - 0.5)*Wo*FFT_ENC/TWO_PI);
|
||||
bl = ceil((l + 0.5)*Wo*FFT_ENC/TWO_PI);
|
||||
|
||||
/* Estimate amplitude of harmonic assuming harmonic is totally voiced */
|
||||
|
||||
for(m=al; m<bl; m++) {
|
||||
offset = FFT_ENC/2 + m - l*Wo*FFT_ENC/TWO_PI + 0.5;
|
||||
Am.real += Sw[m].real*W[offset].real + Sw[m].imag*W[offset].imag;
|
||||
Am.imag += Sw[m].imag*W[offset].real - Sw[m].real*W[offset].imag;
|
||||
den += W[offset].real*W[offset].real + W[offset].imag*W[offset].imag;
|
||||
}
|
||||
|
||||
Am.real = Am.real/den;
|
||||
Am.imag = Am.imag/den;
|
||||
|
||||
/* Determine error between estimated harmonic and original */
|
||||
|
||||
for(m=al; m<bl; m++) {
|
||||
offset = FFT_ENC/2 + m - l*Wo*FFT_ENC/TWO_PI + 0.5;
|
||||
Sw_[m].real = Am.real*W[offset].real - Am.imag*W[offset].imag;
|
||||
Sw_[m].imag = Am.real*W[offset].imag + Am.imag*W[offset].real;
|
||||
error += (Sw[m].real - Sw_[m].real)*(Sw[m].real - Sw_[m].real);
|
||||
error += (Sw[m].imag - Sw_[m].imag)*(Sw[m].imag - Sw_[m].imag);
|
||||
}
|
||||
}
|
||||
|
||||
snr = 10.0*log10(sig/error);
|
||||
if (snr > V_THRESH)
|
||||
model->voiced = 1;
|
||||
else
|
||||
model->voiced = 0;
|
||||
|
||||
return snr;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: make_synthesis_window
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 11/5/94
|
||||
|
||||
Init function that generates the trapezoidal (Parzen) sythesis window.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void make_synthesis_window(float Pn[])
|
||||
{
|
||||
int i;
|
||||
float win;
|
||||
|
||||
/* Generate Parzen window in time domain */
|
||||
|
||||
win = 0.0;
|
||||
for(i=0; i<N/2-TW; i++)
|
||||
Pn[i] = 0.0;
|
||||
win = 0.0;
|
||||
for(i=N/2-TW; i<N/2+TW; win+=1.0/(2*TW), i++ )
|
||||
Pn[i] = win;
|
||||
for(i=N/2+TW; i<3*N/2-TW; i++)
|
||||
Pn[i] = 1.0;
|
||||
win = 1.0;
|
||||
for(i=3*N/2-TW; i<3*N/2+TW; win-=1.0/(2*TW), i++)
|
||||
Pn[i] = win;
|
||||
for(i=3*N/2+TW; i<2*N; i++)
|
||||
Pn[i] = 0.0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FUNCTION....: synthesise
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 20/2/95
|
||||
|
||||
Synthesise a speech signal in the frequency domain from the
|
||||
sinusodal model parameters. Uses overlap-add a triangular window to
|
||||
smoothly interpolate betwen frames.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
void synthesise(
|
||||
float Sn_[], /* time domain synthesised signal */
|
||||
MODEL *model, /* ptr to model parameters for this frame */
|
||||
float Pn[], /* time domain Parzen window */
|
||||
int shift /* used to handle transition frames */
|
||||
)
|
||||
{
|
||||
int i,l,j,b; /* loop variables */
|
||||
COMP Sw_[FFT_DEC]; /* DFT of synthesised signal */
|
||||
|
||||
if (shift) {
|
||||
/* Update memories */
|
||||
|
||||
for(i=0; i<N-1; i++) {
|
||||
Sn_[i] = Sn_[i+N];
|
||||
}
|
||||
Sn_[N-1] = 0.0;
|
||||
}
|
||||
|
||||
for(i=0; i<FFT_DEC; i++) {
|
||||
Sw_[i].real = 0.0;
|
||||
Sw_[i].imag = 0.0;
|
||||
}
|
||||
|
||||
/* Now set up frequency domain synthesised speech */
|
||||
|
||||
for(l=1; l<=model->L; l++) {
|
||||
b = floor(l*model->Wo*FFT_DEC/TWO_PI + 0.5);
|
||||
Sw_[b].real = model->A[l]*cos(model->phi[l]);
|
||||
Sw_[b].imag = model->A[l]*sin(model->phi[l]);
|
||||
Sw_[FFT_DEC-b].real = Sw_[b].real;
|
||||
Sw_[FFT_DEC-b].imag = -Sw_[b].imag;
|
||||
}
|
||||
|
||||
/* Perform inverse DFT */
|
||||
|
||||
four1(&Sw_[-1].imag,FFT_DEC,1);
|
||||
|
||||
/* Overlap add to previous samples */
|
||||
|
||||
for(i=0; i<N-1; i++) {
|
||||
Sn_[i] += Sw_[FFT_DEC-N+1+i].real*Pn[i];
|
||||
}
|
||||
|
||||
if (shift)
|
||||
for(i=N-1,j=0; i<2*N; i++,j++)
|
||||
Sn_[i] = Sw_[j].real*Pn[i];
|
||||
else
|
||||
for(i=N-1,j=0; i<2*N; i++,j++)
|
||||
Sn_[i] += Sw_[j].real*Pn[i];
|
||||
}
|
||||
|
40
libs/libcodec2/src/sine.h
Normal file
40
libs/libcodec2/src/sine.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
|
||||
FILE........: sine.h
|
||||
AUTHOR......: David Rowe
|
||||
DATE CREATED: 1/11/94
|
||||
|
||||
Header file for sinusoidal analysis and synthesis functions.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2009 David Rowe
|
||||
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#ifndef __SINE__
|
||||
#define __SINE__
|
||||
|
||||
void make_analysis_window(float w[], COMP W[]);
|
||||
void dft_speech(COMP Sw[], float Sn[], float w[]);
|
||||
void two_stage_pitch_refinement(MODEL *model, COMP Sw[]);
|
||||
void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[]);
|
||||
float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], float f0, COMP Sw_[]);
|
||||
void make_synthesis_window(float Pn[]);
|
||||
void synthesise(float Sn_[], MODEL *model, float Pn[], int shift);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user