view trau-decode/parse-amr.c @ 78:00fd38c7c8fe

trau-decode: factor out parse-amr.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Feb 2025 06:22:45 +0000
parents trau-decode/parse-main.c@729dbac9df82
children 8c1f20e845a1
line wrap: on
line source

/*
 * This module contains a bit of code that has been factored out of
 * trau-parse program; it handles AMR frames.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

static unsigned
bits_to_num(bits, nbits)
	uint8_t *bits;
	unsigned nbits;
{
	unsigned accum;
	unsigned n;

	accum = 0;
	for (n = 0; n < nbits; n++) {
		accum <<= 1;
		if (*bits)
			accum |= 1;
		bits++;
	}
	return accum;
}

void
print_amr_frame(frame_bits)
	uint8_t *frame_bits;
{
	unsigned c6_11;

	c6_11 = bits_to_num(frame_bits + 22, 6);
	printf("  C6-C11: %u\n", c6_11);
	printf("  RIF=%u C13=%u Config_Prot=%u%u%u Msg_No=%u%u\n",
		frame_bits[28], frame_bits[29], frame_bits[30],
		frame_bits[31], frame_bits[33], frame_bits[34],
		frame_bits[35]);
	printf("  DTXd=%u TFOE=%u FClass=%u%u CMI/CMR=%u%u%u\n",
		frame_bits[36], frame_bits[37], frame_bits[38],
		frame_bits[39], frame_bits[40], frame_bits[41],
		frame_bits[42]);
	if (!frame_bits[38] && !frame_bits[39])
		printf("  No_Spch_Class=%u%u%u CMI=%u%u%u CMR=%u%u%u\n",
			frame_bits[76], frame_bits[77], frame_bits[78],
			frame_bits[79], frame_bits[81], frame_bits[82],
			frame_bits[83], frame_bits[84], frame_bits[85]);
	printf("  T1=%u T2=%u T3=%u T4=%u\n", frame_bits[316],
		frame_bits[317], frame_bits[318], frame_bits[319]);
}