FreeCalypso > hg > ice1-trau-tester
changeset 40:e1eabf554a75
libhr: small subset of WIP libgsmhr1
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 16:41:56 +0000 |
parents | 1e83071186cf |
children | 50a72d4ff498 |
files | libhr/Makefile libhr/pack_frame.c libhr/paramval_common.c libhr/paramval_dec.c libhr/tw_gsmhr.h |
diffstat | 5 files changed, 227 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libhr/Makefile Fri Aug 30 16:41:56 2024 +0000 @@ -0,0 +1,15 @@ +OBJS= pack_frame.o paramval_common.o paramval_dec.o +LIB= libhr.a + +include ../config.defs + +CPPFLAGS=${OSMO_INCLUDE} + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libhr/pack_frame.c Fri Aug 30 16:41:56 2024 +0000 @@ -0,0 +1,77 @@ +/* + * This module holds our gsmhr_pack_ts101318() function: packing a single + * GSM-HR codec frame from an array of broken-down parameters into TS 101 318 + * format. + */ + +#include <stdint.h> +#include "tw_gsmhr.h" + +void gsmhr_pack_ts101318(const int16_t *params, uint8_t *payload) +{ + uint8_t *c = payload; + + if (params[5]) { + /* voiced modes */ + *c++ = ((params[0] & 0x1F) << 3) + | ((params[1] >> 8) & 0x7); + *c++ = params[1] & 0xFF; + *c++ = ((params[2] >> 1) & 0xFF); + *c++ = ((params[2] & 0x1) << 7) + | ((params[3] >> 1) & 0x7F); + *c++ = ((params[3] & 0x1) << 7) + | ((params[4] & 0x1) << 6) + | ((params[5] & 0x3) << 4) + | ((params[6] >> 4) & 0xF); + *c++ = ((params[6] & 0xF) << 4) + | ((params[7] >> 5) & 0xF); + *c++ = ((params[7] & 0x1F) << 3) + | ((params[8] >> 2) & 0x7); + *c++ = ((params[8] & 0x3) << 6) + | ((params[9] & 0xF) << 2) + | ((params[10] >> 7) & 0x3); + *c++ = ((params[10] & 0x7F) << 1) + | ((params[11] >> 4) & 0x1); + *c++ = ((params[11] & 0xF) << 4) + | (params[12] & 0xF); + *c++ = ((params[13] >> 1) & 0xFF); + *c++ = ((params[13] & 0x1) << 7) + | ((params[14] & 0x1F) << 2) + | ((params[15] >> 2) & 0x3); + *c++ = ((params[15] & 0x3) << 6) + | ((params[16] >> 3) & 0x3F); + *c++ = ((params[16] & 0x7) << 5) + | (params[17] & 0x1F); + } else { + /* unvoiced mode */ + *c++ = ((params[0] & 0x1F) << 3) + | ((params[1] >> 8) & 0x7); + *c++ = params[1] & 0xFF; + *c++ = ((params[2] >> 1) & 0xFF); + *c++ = ((params[2] & 0x1) << 7) + | ((params[3] >> 1) & 0x7F); + *c++ = ((params[3] & 0x1) << 7) + | ((params[4] & 0x1) << 6) + | ((params[5] & 0x3) << 4) + | ((params[6] >> 3) & 0xF); + *c++ = ((params[6] & 0x7) << 5) + | ((params[7] >> 2) & 0x1F); + *c++ = ((params[7] & 0x3) << 6) + | ((params[8] & 0x1F) << 1) + | ((params[9] >> 6) & 0x1); + *c++ = ((params[9] & 0x3F) << 2) + | ((params[10] >> 5) & 0x3); + *c++ = ((params[10] & 0x1F) << 3) + | ((params[11] >> 2) & 0x7); + *c++ = ((params[11] & 0x3) << 6) + | ((params[12] >> 1) & 0x3F); + *c++ = ((params[12] & 0x1) << 7) + | (params[13] & 0x7F); + *c++ = ((params[14] & 0x1F) << 3) + | ((params[15] >> 4) & 0x7); + *c++ = ((params[15] & 0xF) << 4) + | ((params[16] >> 3) & 0xF); + *c++ = ((params[16] & 0x7) << 5) + | (params[17] & 0x1F); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libhr/paramval_common.c Fri Aug 30 16:41:56 2024 +0000 @@ -0,0 +1,90 @@ +/* + * The function implemented in this module examines an array of 18 codec + * parameters in the int16_t representation used in this library, and checks + * if the unused upper bits of each int16_t word are cleared as they should be. + * This function, or higher-level wrappers around it, should be used when + * reading from ETSI-format *.cod and *.dec files, to guard against reading + * garbage or wrong endian. + */ + +#include <stdint.h> +#include "tw_gsmhr.h" + +int gsmhr_check_common_params(const int16_t *params) +{ + /* common parameters for all modes */ + if (params[0] & 0xFFE0) + return -1; + if (params[1] & 0xF800) + return -1; + if (params[2] & 0xFE00) + return -1; + if (params[3] & 0xFF00) + return -1; + if (params[4] & 0xFFFE) + return -1; + if (params[5] & 0xFFFC) + return -1; + if (params[5]) { + /* voiced modes */ + /* subframe 1 */ + if (params[6] & 0xFF00) + return -1; + if (params[7] & 0xFE00) + return -1; + if (params[8] & 0xFFE0) + return -1; + /* subframe 2 */ + if (params[9] & 0xFFF0) + return -1; + if (params[10] & 0xFE00) + return -1; + if (params[11] & 0xFFE0) + return -1; + /* subframe 3 */ + if (params[12] & 0xFFF0) + return -1; + if (params[13] & 0xFE00) + return -1; + if (params[14] & 0xFFE0) + return -1; + /* subframe 4 */ + if (params[15] & 0xFFF0) + return -1; + if (params[16] & 0xFE00) + return -1; + if (params[17] & 0xFFE0) + return -1; + } else { + /* unvoiced mode */ + /* subframe 1 */ + if (params[6] & 0xFF80) + return -1; + if (params[7] & 0xFF80) + return -1; + if (params[8] & 0xFFE0) + return -1; + /* subframe 2 */ + if (params[9] & 0xFF80) + return -1; + if (params[10] & 0xFF80) + return -1; + if (params[11] & 0xFFE0) + return -1; + /* subframe 3 */ + if (params[12] & 0xFF80) + return -1; + if (params[13] & 0xFF80) + return -1; + if (params[14] & 0xFFE0) + return -1; + /* subframe 4 */ + if (params[15] & 0xFF80) + return -1; + if (params[16] & 0xFF80) + return -1; + if (params[17] & 0xFFE0) + return -1; + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libhr/paramval_dec.c Fri Aug 30 16:41:56 2024 +0000 @@ -0,0 +1,23 @@ +/* + * The function implemented in this module examines a frame of 22 int16_t words + * that corresponds to GSM-HR decoder input format, and checks if the unused + * upper bits of each int16_t word are cleared as they should be. + * This function should be used when reading from ETSI-format *.dec files, + * to guard against reading garbage or wrong endian. + */ + +#include <stdint.h> +#include "tw_gsmhr.h" + +int gsmhr_check_decoder_params(const int16_t *params) +{ + if (params[18] < 0 || params[18] > 2) /* BFI */ + return -1; + if (params[19] < 0 || params[19] > 1) /* UFI */ + return -1; + if (params[20] < 0 || params[20] > 2) /* SID */ + return -1; + if (params[21] < 0 || params[21] > 1) /* TAF */ + return -1; + return gsmhr_check_common_params(params); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libhr/tw_gsmhr.h Fri Aug 30 16:41:56 2024 +0000 @@ -0,0 +1,22 @@ +/* + * This header file is a reduced subset version of <tw_gsmhr.h> + * from work-in-progress libgsmhr1, reduced to just the few functions + * needed for itt-ater-8. + */ + +#pragma once + +#include <stdint.h> + +#define GSMHR_NUM_PARAMS 18 /* actual codec parameters */ +#define GSMHR_NUM_PARAMS_ENC 20 /* output from the encoder */ +#define GSMHR_NUM_PARAMS_DEC 22 /* input to the decoder */ + +#define GSMHR_FRAME_LEN_RPF 14 /* raw packed format */ +#define GSMHR_FRAME_LEN_5993 15 /* RFC 5993 and TW-TS-002 */ + +/* the few functions we've imported from WIP libgsmhr1 */ + +void gsmhr_pack_ts101318(const int16_t *param, uint8_t *payload); +int gsmhr_check_common_params(const int16_t *params); +int gsmhr_check_decoder_params(const int16_t *params);