FreeCalypso > hg > gsm-codec-lib
view amrconv/cod-read.c @ 320:ee64aabcc7a0
libtwamr: integrate c2_9pf.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Apr 2024 19:31:03 +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++; } }