view dev/xmaxc-tables.c @ 484:20d44cfc219c

CHANGES: list all new command line utils
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 May 2024 01:42:38 +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);
}