Add GSM HR reference codec that is automatically downloaded from 3gpp.org
This commit is contained in:
parent
3196efde7b
commit
278f2cbeca
|
@ -1,4 +1,5 @@
|
|||
core
|
||||
*.swp
|
||||
*.o
|
||||
*.po
|
||||
*.so
|
||||
|
@ -27,3 +28,6 @@ gentones
|
|||
genwave
|
||||
lcr
|
||||
lcradmin
|
||||
libtool
|
||||
libgsmhr/refsrc
|
||||
ltmain.sh
|
||||
|
|
18
Makefile.am
18
Makefile.am
|
@ -43,6 +43,12 @@ INSTALLATION_DEFINES = \
|
|||
-DLOG_DIR="\"$(LOGdir)\"" \
|
||||
-DEXTENSION_DATA="\"$(EXTENSIONdir)\""
|
||||
|
||||
SUBDIRS = include
|
||||
|
||||
if ENABLE_GSMHR
|
||||
SUBDIRS += libgsmhr
|
||||
endif
|
||||
|
||||
if ENABLE_MISDN
|
||||
|
||||
MISDN_INCLUDE = -DWITH_MISDN -DWITH_CRYPT
|
||||
|
@ -59,7 +65,7 @@ GSM_LIB =
|
|||
|
||||
if ENABLE_GSM
|
||||
|
||||
#if ENABLE_GSMHR
|
||||
#if ENABLE_GSMFR
|
||||
|
||||
GSM_INCLUDE += -DWITH_GSMFR
|
||||
|
||||
|
@ -69,6 +75,16 @@ SUBDIRS += libgsmfr
|
|||
|
||||
#endif
|
||||
|
||||
if ENABLE_GSMHR
|
||||
|
||||
GSM_INCLUDE += -DWITH_GSMHR
|
||||
|
||||
GSM_LIB += libgsmhr/libgsmhr.a
|
||||
|
||||
SUBDIRS += libgsmhr
|
||||
|
||||
endif
|
||||
|
||||
if ENABLE_GSMAMR
|
||||
|
||||
GSM_INCLUDE += -DWITH_GSMAMR
|
||||
|
|
17
configure.ac
17
configure.ac
|
@ -44,6 +44,7 @@ AC_PROG_CXX
|
|||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_LIBTOOL
|
||||
dnl required, if per binary CFLAGS are used
|
||||
dnl AM_PROG_CC_C_O
|
||||
|
||||
|
@ -191,6 +192,19 @@ if test "$found_opencore_amrnb" = yes; then
|
|||
AC_DEFINE(HAVE_OPENCORE_AMRNB, 1, [Define to 1 if OpenCore AMR-NB library is available])
|
||||
fi
|
||||
|
||||
# check for HR codec
|
||||
AC_ARG_ENABLE(gsmhr,
|
||||
[AS_HELP_STRING(
|
||||
[--enable-gsmhr],
|
||||
[Enable support for GSM HR codec using reference code]
|
||||
)],
|
||||
[enable_gsmhr=1], [enable_gsmhr=0])
|
||||
AM_CONDITIONAL(ENABLE_GSMHR, test "x$enable_gsmhr" = "x1")
|
||||
if test "x$enable_gsmhr" = "x1"; then
|
||||
AM_PATH_PYTHON([2.4])
|
||||
AC_DEFINE(HAVE_LIBGSMHR, 1, [Define to 1 if libgsmhr is available])
|
||||
fi
|
||||
|
||||
# check for ss5
|
||||
AC_ARG_WITH([ss5],
|
||||
[AS_HELP_STRING([--with-ss5],
|
||||
|
@ -248,13 +262,14 @@ AC_FUNC_VPRINTF
|
|||
AC_CHECK_FUNCS([gettimeofday memmove memset mkdir socket strcasecmp strchr strerror strncasecmp strstr strtol strtoul])
|
||||
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_CONFIG_FILES([Makefile include/Makefile include/gsmhr/Makefile libgsmhr/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
|
||||
AS_IF([test "x$with_misdn" == xyes],[AC_MSG_NOTICE( Compiled with mISDN support )],[AC_MSG_NOTICE( Not compiled with mISDN support)])
|
||||
AS_IF([test "x$with_gsm_bs" == xyes],[AC_MSG_NOTICE( Compiled with GSM network side support )],[AC_MSG_NOTICE( Not compiled with GSM network side support)])
|
||||
AS_IF([test "x$with_gsm_ms" == xyes],[AC_MSG_NOTICE( Compiled with GSM mobile side support )],[AC_MSG_NOTICE( Not compiled with GSM mobile side support)])
|
||||
AS_IF([test "x$enable_gsmhr" == x1],[AC_MSG_NOTICE( Compiled with GSM half rate codec support )],[AC_MSG_NOTICE( Not compiled with GSM half rate codec support)])
|
||||
AS_IF([test "x$found_opencore_amrnb" == xyes],[AC_MSG_NOTICE( Compiled with GSM AMR codec support )],[AC_MSG_NOTICE( Not compiled with GSM AMR codec support)])
|
||||
AS_IF([test "x$with_asterisk" == xyes],[AC_MSG_NOTICE( Compiled with Asterisk channel driver support )],[AC_MSG_NOTICE( Not compiled with Asterisk channel driver support)])
|
||||
AS_IF([test "x$with_ss5" == xyes],[AC_MSG_NOTICE( Compiled with CCITT No.5 support )],[AC_MSG_NOTICE( Not compiled with CCITT No.5 support)])
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
SUBDIRS =
|
||||
|
||||
if ENABLE_GSMHR
|
||||
SUBDIRS += gsmhr
|
||||
endif
|
|
@ -0,0 +1 @@
|
|||
noinst_HEADERS = gsmhr.h
|
|
@ -0,0 +1,40 @@
|
|||
/* HR (GSM 06.20) codec */
|
||||
|
||||
/*
|
||||
* This file is part of gapk (GSM Audio Pocket Knife).
|
||||
*
|
||||
* gapk 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.
|
||||
*
|
||||
* gapk 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 gapk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GSM_HR_H__
|
||||
#define __GSM_HR_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct gsmhr;
|
||||
|
||||
struct gsmhr *gsmhr_init(void);
|
||||
void gsmhr_exit(struct gsmhr *state);
|
||||
int gsmhr_encode(struct gsmhr *state, int16_t *hr_params, const int16_t *pcm);
|
||||
int gsmhr_decode(struct gsmhr *state, int16_t *pcm, const int16_t *hr_params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __GSM_HR_H__ */
|
|
@ -0,0 +1,23 @@
|
|||
INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
|
||||
AM_CFLAGS = -fPIC -Wall ${SYMBOL_VISIBILITY}
|
||||
|
||||
LIBVERSION=0:0:0
|
||||
|
||||
REFSRC_PATH=refsrc
|
||||
REFSRC_SRC=refsrc/dtx.c refsrc/globdefs.c refsrc/host.c refsrc/mathhalf.c refsrc/sp_enc.c refsrc/sp_rom.c refsrc/vad.c refsrc/err_conc.c refsrc/homing.c refsrc/mathdp31.c refsrc/sp_dec.c refsrc/sp_frm.c refsrc/sp_sfrm.c
|
||||
|
||||
${REFSRC_PATH}/.downloaded:
|
||||
./fetch_sources.py "${REFSRC_PATH}"
|
||||
for f in "${REFSRC_PATH}"/*.{c,h}; do \
|
||||
sed -i -e"s/round/round_l2s/" "$$f"; \
|
||||
done
|
||||
sed -i -e"s/long int/int/" -e"s/long/int/" "${REFSRC_PATH}/typedefs.h"
|
||||
touch $@
|
||||
|
||||
${REFSRC_PATH}/dtx.c: ${REFSRC_PATH}/.downloaded
|
||||
|
||||
lib_LTLIBRARIES = libgsmhr.la
|
||||
libgsmhr_la_SOURCES = $(REFSRC_SRC) libgsmhr.c
|
||||
|
||||
clean-local:
|
||||
-rm -rf ${REFSRC_PATH}
|
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import urllib2
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
try:
|
||||
import cStringIO as StringIO
|
||||
except:
|
||||
import StringIO
|
||||
|
||||
|
||||
SRC = "http://ftp.3gpp.org/Specs/2001-06/Ph2/06_series/0606-421/0606_421.zip"
|
||||
|
||||
|
||||
def get_zipfile(data):
|
||||
return zipfile.ZipFile(StringIO.StringIO(data))
|
||||
|
||||
|
||||
def get_subfile_data(data, filename):
|
||||
z = get_zipfile(data)
|
||||
return z.read(filename)
|
||||
|
||||
|
||||
def process_file(z, e):
|
||||
fh = open(e.filename.lower(), 'w')
|
||||
d = z.read(e).replace('\r','')
|
||||
fh.write(d)
|
||||
fh.close()
|
||||
|
||||
|
||||
def main(*args):
|
||||
|
||||
# Args
|
||||
if len(args) != 2:
|
||||
print "Usage: %s target_dir" % args[0]
|
||||
return
|
||||
|
||||
tgt = args[1]
|
||||
|
||||
# Create and go to target dir
|
||||
if not os.path.isdir(tgt):
|
||||
os.mkdir(tgt)
|
||||
os.chdir(tgt)
|
||||
|
||||
# Get the original data
|
||||
u = urllib2.urlopen(SRC)
|
||||
d = u.read()
|
||||
|
||||
# Get DISK.zip
|
||||
d = get_subfile_data(d, 'DISK.zip')
|
||||
|
||||
# Get Dir_C.zip
|
||||
d = get_subfile_data(d, 'Dir_C.zip')
|
||||
|
||||
# Get zip file object
|
||||
z = get_zipfile(d)
|
||||
|
||||
# Save each file
|
||||
for e in z.filelist:
|
||||
process_file(z, e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(*sys.argv)
|
|
@ -0,0 +1,111 @@
|
|||
/* HR (GSM 06.20) codec wrapper */
|
||||
|
||||
/*
|
||||
* This file is part of gapk (GSM Audio Pocket Knife).
|
||||
*
|
||||
* gapk 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.
|
||||
*
|
||||
* gapk 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 gapk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gsmhr/gsmhr.h>
|
||||
|
||||
#include "refsrc/typedefs.h"
|
||||
#include "refsrc/homing.h"
|
||||
#include "refsrc/sp_dec.h"
|
||||
#include "refsrc/sp_enc.h"
|
||||
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
|
||||
|
||||
struct gsmhr {
|
||||
int dec_reset_flg;
|
||||
};
|
||||
|
||||
EXPORT struct gsmhr *
|
||||
gsmhr_init(void)
|
||||
{
|
||||
struct gsmhr *state;
|
||||
|
||||
state = calloc(1, sizeof(struct gsmhr));
|
||||
if (!state)
|
||||
return NULL;
|
||||
|
||||
state->dec_reset_flg = 1;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
EXPORT void
|
||||
gsmhr_exit(struct gsmhr *state)
|
||||
{
|
||||
free(state);
|
||||
}
|
||||
|
||||
EXPORT int
|
||||
gsmhr_encode(struct gsmhr *state, int16_t *hr_params, const int16_t *pcm)
|
||||
{
|
||||
int enc_reset_flg;
|
||||
Shortword pcm_b[F_LEN];
|
||||
|
||||
memcpy(pcm_b, pcm, F_LEN*sizeof(int16_t));
|
||||
|
||||
enc_reset_flg = encoderHomingFrameTest(pcm_b);
|
||||
|
||||
speechEncoder(pcm_b, hr_params);
|
||||
|
||||
if (enc_reset_flg)
|
||||
resetEnc();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT int
|
||||
gsmhr_decode(struct gsmhr *state, int16_t *pcm, const int16_t *hr_params)
|
||||
{
|
||||
#define WHOLE_FRAME 18
|
||||
#define TO_FIRST_SUBFRAME 9
|
||||
|
||||
int dec_reset_flg;
|
||||
Shortword hr_params_b[22];
|
||||
|
||||
memcpy(hr_params_b, hr_params, 22*sizeof(int16_t));
|
||||
|
||||
if (state->dec_reset_flg)
|
||||
dec_reset_flg = decoderHomingFrameTest(hr_params_b, TO_FIRST_SUBFRAME);
|
||||
else
|
||||
dec_reset_flg = 0;
|
||||
|
||||
if (dec_reset_flg && state->dec_reset_flg) {
|
||||
int i;
|
||||
for (i=0; i<F_LEN; i++)
|
||||
pcm[i] = EHF_MASK;
|
||||
} else {
|
||||
speechDecoder(hr_params_b, pcm);
|
||||
}
|
||||
|
||||
if (!state->dec_reset_flg)
|
||||
dec_reset_flg = decoderHomingFrameTest(hr_params_b, WHOLE_FRAME);
|
||||
|
||||
if (dec_reset_flg)
|
||||
resetDec();
|
||||
|
||||
state->dec_reset_flg = dec_reset_flg;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue