view amrdiff/etsi-bit-rd.c @ 12:db5772dac3c3

ringing: generate WAV decodings of FR&EFR ringing signals for playback testing and subjective quality evaluation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Apr 2024 19:28:20 +0000
parents a03c87a2abc6
children
line wrap: on
line source

/*
 * The utility function in this module reads the bits from ETSI *.cod
 * files, both AMR and EFR versions, either LE or BE.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "etsi.h"
#include "amr_defs.h"

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

	cc = fread(file_bytes, 2, nwords, inf);
	if (cc == 0)
		return 0;
	if (cc != nwords) {
		fprintf(stderr, "error: short read from %s\n",
			filename_for_errs);
		exit(1);
	}
	sp = file_bytes;
	for (n = 0; n < 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;
}