FreeCalypso > hg > ice1-trau-tester
diff libhr/pack_frame.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/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); + } +}