view libgsmhr1/paramval_common.c @ 585:3c6bf0d26ee7 default tip

TW-TS-005 reader: fix maximum line length bug TW-TS-005 section 4.1 states: The maximum allowed length of each line is 80 characters, not including the OS-specific newline encoding. The implementation of this line length limit in the TW-TS-005 hex file reader function in the present suite was wrong, such that lines of the full maximum length could not be read. Fix it. Note that this bug affects comment lines too, not just actual RTP payloads. Neither Annex A nor Annex B features an RTP payload format that goes to the maximum of 40 bytes, but if a comment line goes to the maximum allowed length of 80 characters not including the terminating newline, the bug will be triggered, necessitating the present fix.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 25 Feb 2025 07:49:28 +0000
parents 4f0ab833bec0
children
line wrap: on
line source

/*
 * The function implemented in this module examines an array of 18 codec
 * parameters in the int16_t representation used in this library, and checks
 * if the unused upper bits of each int16_t word are cleared as they should be.
 * This function, or higher-level wrappers around it, should be used when
 * reading from ETSI-format *.cod and *.dec files, to guard against reading
 * garbage or wrong endian.
 */

#include <stdint.h>
#include "tw_gsmhr.h"

int gsmhr_check_common_params(const int16_t *params)
{
	/* common parameters for all modes */
	if (params[0] & 0xFFE0)
		return -1;
	if (params[1] & 0xF800)
		return -1;
	if (params[2] & 0xFE00)
		return -1;
	if (params[3] & 0xFF00)
		return -1;
	if (params[4] & 0xFFFE)
		return -1;
	if (params[5] & 0xFFFC)
		return -1;
	if (params[5]) {
		/* voiced modes */
		/* subframe 1 */
		if (params[6] & 0xFF00)
			return -1;
		if (params[7] & 0xFE00)
			return -1;
		if (params[8] & 0xFFE0)
			return -1;
		/* subframe 2 */
		if (params[9] & 0xFFF0)
			return -1;
		if (params[10] & 0xFE00)
			return -1;
		if (params[11] & 0xFFE0)
			return -1;
		/* subframe 3 */
		if (params[12] & 0xFFF0)
			return -1;
		if (params[13] & 0xFE00)
			return -1;
		if (params[14] & 0xFFE0)
			return -1;
		/* subframe 4 */
		if (params[15] & 0xFFF0)
			return -1;
		if (params[16] & 0xFE00)
			return -1;
		if (params[17] & 0xFFE0)
			return -1;
	} else {
		/* unvoiced mode */
		/* subframe 1 */
		if (params[6] & 0xFF80)
			return -1;
		if (params[7] & 0xFF80)
			return -1;
		if (params[8] & 0xFFE0)
			return -1;
		/* subframe 2 */
		if (params[9] & 0xFF80)
			return -1;
		if (params[10] & 0xFF80)
			return -1;
		if (params[11] & 0xFFE0)
			return -1;
		/* subframe 3 */
		if (params[12] & 0xFF80)
			return -1;
		if (params[13] & 0xFF80)
			return -1;
		if (params[14] & 0xFFE0)
			return -1;
		/* subframe 4 */
		if (params[15] & 0xFF80)
			return -1;
		if (params[16] & 0xFF80)
			return -1;
		if (params[17] & 0xFFE0)
			return -1;
	}
	return 0;
}