FreeCalypso > hg > ice1-trau-tester
diff libhr/paramval_common.c @ 40:e1eabf554a75
libhr: small subset of WIP libgsmhr1
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 16:41:56 +0000 |
parents | |
children |
line wrap: on
line diff
--- /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; +}