view libgsmfrp/good_frame.c @ 128:a5ffec18e4cd

test programs: use printf %d format for codec parameters Even though all codec params (both FR and EFR) are small unsigned integers, we use signed int16_t data type for both, for interface reasons: in the case of FR it's the gsm_signal type of libgsm, and in the case of EFR it's the Word16 type of ETSI codec guts. Therefore, the correct printf format is %d, not %u, when the objective is to see what's in the variables (what the compiler sees) and catch any bugs.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Dec 2022 04:00:13 +0000
parents 4812e00bc100
children f081a6850fb5
line wrap: on
line source

/*
 * In this module we implement preprocessing of received good frames.
 */

#include <stdint.h>
#include <string.h>
#include "gsm_fr_preproc.h"
#include "internal.h"

void gsmfr_preproc_good_frame(struct gsmfr_preproc_state *st, gsm_byte *frame)
{
	int sid;

	/* always set correct magic */
	frame[0] = 0xD0 | frame[0] & 0x0F;
	/* now classify by SID */
	sid = gsmfr_preproc_sid_classify(frame);
	switch (sid) {
	case 0:		/* good speech frame */
		memcpy(&st->speech_frame, frame, sizeof(gsm_frame));
		st->rx_state = SPEECH;
		return;
	case 1:		/* invalid SID frame */
		if (st->got_valid_sid) {
			st->rx_state = COMFORT_NOISE;
			gsmfr_preproc_gen_cn(st, frame);
		} else {
			st->rx_state = NO_DATA;
			memcpy(frame, &gsmfr_preproc_silence_frame,
				sizeof(gsm_frame));
		}
		return;
	case 2:		/* valid SID frame */
		st->got_valid_sid = 1;
		memcpy(st->sid_prefix, frame, 5);
		st->sid_xmaxc[0] = ((frame[6] & 0x1F) << 1) | (frame[7] >> 7);
		st->sid_xmaxc[1] = ((frame[13] & 0x1F) << 1) | (frame[14] >> 7);
		st->sid_xmaxc[2] = ((frame[20] & 0x1F) << 1) | (frame[21] >> 7);
		st->sid_xmaxc[3] = ((frame[27] & 0x1F) << 1) | (frame[28] >> 7);
		st->rx_state = COMFORT_NOISE;
		gsmfr_preproc_gen_cn(st, frame);
		return;
	}
}