codec: Add functions for AMR s->d bits and d->s bits

These functions implement re-ordering of bits as per TS 06.90 / 26.101
based on the already existing tables we've had in libosmocoding.

Change-Id: Ia4ac2aea2e96f9185f082a07ca64dfc5276efb46
diff --git a/tests/codec/codec_test.c b/tests/codec/codec_test.c
index 7a10fc5..5579e99 100644
--- a/tests/codec/codec_test.c
+++ b/tests/codec/codec_test.c
@@ -190,6 +190,42 @@
 	}
 }
 
+
+
+static void test_amr_s_d(void)
+{
+	ubit_t in[244];
+	ubit_t mid[244];
+	ubit_t out[244];
+	int i, j;
+
+	for (j = AMR_4_75; j <= AMR_12_2; j++) {
+		unsigned int n_bits = gsm690_bitlength[j];
+
+		printf("=> AMR Mode %d (%d bits)\n", j, n_bits);
+		/* set a single bit in the input buffer */
+		for (i = 0; i < n_bits; i++) {
+
+			memset(in, 0, sizeof(in));
+			in[i] = 1;
+
+			/* re-order from s to d */
+			osmo_amr_s_to_d(mid, in, n_bits, j);
+
+			/* and back to d */
+			osmo_amr_d_to_s(out, mid, n_bits, j);
+
+			if (memcmp(in, out, n_bits)) {
+				printf("Error in bit %d of mode %d!\n", i, j);
+				printf("inp s-bits: %s\n", osmo_ubit_dump(in, n_bits));
+				printf("mid d-bits: %s\n", osmo_ubit_dump(mid, n_bits));
+				printf("out s-bits: %s\n", osmo_ubit_dump(out, n_bits));
+				//OSMO_ASSERT(0);
+			}
+		}
+	}
+}
+
 int main(int argc, char **argv)
 {
 	printf("AMR RTP payload decoder test:\n");
@@ -213,6 +249,9 @@
 	printf("FR RTP payload SID test:\n");
 	test_sid_fr();
 
+	printf("AMR s/d bit re-ordering test:\n");
+	test_amr_s_d();
+
 	return 0;
 }