view libtwamr/tseq_in.c @ 477:4c9222d95647

libtwamr encoder: always emit frame->mode = mode; In the original implementation of amr_encode_frame(), the 'mode' member of the output struct was set to 0xFF if the output frame type is TX_NO_DATA. This design was made to mimic the mode field (16-bit word) being set to 0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends on this struct member being set in any way, and amr_frame_to_tseq() generates the needed 0xFFFF on its own, based on frame->type being equal to TX_NO_DATA. It is simpler and more efficient to always set frame->mode to the actual encoding mode in amr_encode_frame(), and this new behavior has already been documented in doc/AMR-library-API description in anticipation of the present change.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 May 2024 22:30:42 +0000
parents 3ce30a95769e
children
line wrap: on
line source

/*
 * In this module we implement decoder input conversion from 3GPP
 * test sequence format to our internal struct amr_param_frame.
 */

#include <stdint.h>
#include <string.h>
#include "tw_amr.h"
#include "namespace.h"
#include "typedef.h"
#include "cnst.h"
#include "bits2prm.h"

int amr_frame_from_tseq(const uint16_t *cod, int use_rxtype,
			struct amr_param_frame *frame)
{
	enum RXFrameType rx_type;
	int rc;

	if (use_rxtype) {
		if (cod[0] >= RX_N_FRAMETYPES)
			return -1;
		rx_type = cod[0];
	} else {
		rc = amr_txtype_to_rxtype(cod[0], &rx_type);
		if (rc < 0)
			return -1;
	}
	frame->type = rx_type;
	if (rx_type == RX_NO_DATA) {
		frame->mode = 0xFF;
		return 0;
	}
	if (cod[MAX_SERIAL_SIZE+1] > 7)
		return -2;
	frame->mode = cod[MAX_SERIAL_SIZE+1];
	switch (rx_type) {
	case RX_SPEECH_GOOD:
	case RX_SPEECH_DEGRADED:
	case RX_SPEECH_BAD:
		Bits2prm(frame->mode, cod + 1, frame->param);
		break;
	case RX_SID_UPDATE:
	case RX_SID_BAD:
		Bits2prm(MRDTX, cod + 1, frame->param);
		break;
	}
	return 0;
}