view dev/xmaxc-tables.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 56d3fbacd115
children
line wrap: on
line source

/*
 * For libgsmfrp: if we are going to initiate comfort noise generation
 * upon receiving an invalid SID, and if we are going to harvest the
 * needed LARc and Xmaxc parameters from the last speech frame, we'll
 * need a way to compute a single mean Xmaxc from the 4 subframe Xmaxc
 * parameters of that last speech frame.
 *
 * This program generates Xmaxc dequantization and requantization tables
 * that are specifically optimized for performing this mean manipulation.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

static uint16_t dequant_table[64];
static uint8_t requant_table[1024];

static void
compute_dequant()
{
	unsigned xmaxc, dequant, step;

	dequant = 0;
	step = 1;
	for (xmaxc = 0; xmaxc < 64; xmaxc++) {
		dequant_table[xmaxc] = dequant;
		dequant += step;
		if ((xmaxc & 7) == 7 && xmaxc != 7)
			step <<= 1;
	}
}

static void
compute_requant()
{
	unsigned x, c;

	for (x = 0; x < 1024; x++) {
		for (c = 0; c < 63; c++) {
			if (x < dequant_table[c+1])
				break;
		}
		requant_table[x] = c;
	}
}

static void
print_dequant()
{
	unsigned c, r;

	puts("const uint16_t dequant_table[64] = {");
	for (c = 0; c < 64; c++) {
		r = c & 7;
		if (!r)
			putchar('\t');
		printf("%3u,", dequant_table[c]);
		if (r == 7)
			putchar('\n');
		else
			putchar(' ');
	}
	fputs("};\n\n", stdout);
}

static void
print_requant()
{
	unsigned x, r;

	puts("const uint8_t requant_table[1024] = {");
	for (x = 0; x < 1024; x++) {
		r = x & 15;
		if (!r)
			putchar('\t');
		printf("%2u,", requant_table[x]);
		if (r == 15)
			putchar('\n');
		else
			putchar(' ');
	}
	fputs("};\n", stdout);
}

main(argc, argv)
	char **argv;
{
	compute_dequant();
	compute_requant();
	print_dequant();
	print_requant();
	exit(0);
}