falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/39669?usp=email )
Change subject: trau_frame encode8_hr: simplify setting of C5 for odd parity ......................................................................
trau_frame encode8_hr: simplify setting of C5 for odd parity
As detailed in the previous commit, the API "contract" of osmo_trau_frame_encode() for OSMO_TRAU8_SPEECH in DL direction immortalizes a strange choice where C4 is controlled by the user while C1..C3 and C5 are overridden by the function. C5 is the odd parity bit; because C1..C3 are fixed and only C4 comes from the user, the correct odd parity bit C5 can be set more efficiently by simply inverting C4, skipping full computation of OP.
Change-Id: I30c7dfdaaadd0fd4cb084cf02c66c0f19a40ae42 --- M src/trau/trau_frame.c 1 file changed, 6 insertions(+), 18 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/69/39669/1
diff --git a/src/trau/trau_frame.c b/src/trau/trau_frame.c index 652c703..3e8364a 100644 --- a/src/trau/trau_frame.c +++ b/src/trau/trau_frame.c @@ -812,23 +812,6 @@ return 0; }
-/* compute the odd parity bit of the given input bit sequence */ -static ubit_t compute_odd_parity(const ubit_t *in, unsigned int num_bits) -{ - int i; - unsigned int sum = 0; - - for (i = 0; i < num_bits; i++) { - if (in[i]) - sum++; - } - - if (sum & 1) - return 0; - else - return 1; -} - /* TS 08.61 Section 5.2.1.1 */ static int encode8_hr(ubit_t *trau_bits, const struct osmo_trau_frame *fr, bool is_tfo) { @@ -855,11 +838,16 @@ cbits_out[4] = 0; } } else { + /* Per backward-compatible API "contract", we consider only + * fr->c_bits[3] set by the user, and override the other 4 + * bits. C1..C3 are constant frame type code; C5 is odd + * parity, which in this case is always the inverse of C4. + */ cbits_out[0] = 0; cbits_out[1] = 0; cbits_out[2] = 0; cbits_out[3] = fr->c_bits[3]; - cbits_out[4] = compute_odd_parity(cbits_out, 4); + cbits_out[4] = !fr->c_bits[3]; }
/* XC1 .. XC2 */