view amrconv/cod-read.c @ 282:9ee8ad3d4d30

frtest: rm gsmfr-hand-test and gsmfr-max-out utils These hack programs were never properly documented and were written only as part of a debug chase, in pursuit of a bug that ultimately turned out to be in our then-hacky patch to osmo-bts-sysmo, before beginning of proper patches in Osmocom. These hack programs need to be dropped from the present sw package because they depend on old libgsm, and we are eliminating that dependency.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 05:44:47 +0000
parents 0beafaa0623f
children
line wrap: on
line source

/*
 * In this module we implement utility functions for reading ETSI/3GPP
 * *.cod files (AMR version) in either LE or BE format.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "amr_defs.h"

read_cod_bits(inf, big_endian, bitvec, filename_for_errs)
	FILE *inf;
	uint8_t *bitvec;
	char *filename_for_errs;
{
	uint8_t file_bytes[COD_FORMAT_NWORDS * 2], *sp;
	int cc;
	unsigned n, upper;

	cc = fread(file_bytes, 2, COD_FORMAT_NWORDS, inf);
	if (cc == 0)
		return 0;
	if (cc != COD_FORMAT_NWORDS) {
		fprintf(stderr, "error: short read from %s\n",
			filename_for_errs);
		exit(1);
	}
	sp = file_bytes;
	for (n = 0; n < COD_FORMAT_NWORDS; n++) {
		if (big_endian) {
			upper = sp[0];
			bitvec[n] = sp[1];
		} else {
			bitvec[n] = sp[0];
			upper = sp[1];
		}
		if (upper && (sp[0] != 0xFF || sp[1] != 0xFF)) {
			fprintf(stderr,
		"error in %s: non-zero in what should be %s upper byte\n",
				filename_for_errs, big_endian ? "BE" : "LE");
			exit(1);
		}
		sp += 2;
	}
	return 1;
}

void
preen_frame_bits(input_bits, nbits, filename_for_errs, frame_no)
	uint8_t *input_bits;
	char *filename_for_errs;
	unsigned nbits, frame_no;
{
	uint8_t *sp;
	unsigned nb;

	sp = input_bits;
	for (nb = 0; nb < nbits; nb++) {
		if (*sp > 1) {
			fprintf(stderr, "error in %s frame #%u: data bit > 1\n",
				filename_for_errs, frame_no);
			exit(1);
		}
		sp++;
	}
}