FreeCalypso > hg > gsm-codec-lib
diff amrconv/cod-read.c @ 211:78d1a6513393
amrconv: new program amr-cod-parse
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 20 Apr 2023 01:30:46 +0000 |
parents | efrtest/etsi-bit-rd.c@8ed838709897 |
children | 0beafaa0623f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/cod-read.c Thu Apr 20 01:30:46 2023 +0000 @@ -0,0 +1,66 @@ +/* + * 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) { + 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++; + } +}