view dmw/gen-dmw-bin.c @ 57:a64e5ed217c0 default tip

top Makefile: add fr-sid
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 22 Aug 2024 06:43:31 +0000
parents e81a8c274fa6
children
line wrap: on
line source

/*
 * This program generates a binary G.711 file containing the standard
 * DMW (digital milliwatt) sequence repeated for the specified number
 * of times; the number of repetitions will be the total duration
 * of the output in milliseconds.
 */

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

static uint8_t dmw_alaw[8] = {0x34, 0x21, 0x21, 0x34, 0xB4, 0xA1, 0xA1, 0xB4};
static uint8_t dmw_ulaw[8] = {0x1E, 0x0B, 0x0B, 0x1E, 0x9E, 0x8B, 0x8B, 0x9E};

main(argc, argv)
	char **argv;
{
	FILE *outf;
	unsigned total_ms, n;
	uint8_t *seq;

	if (argc != 4) {
usage:		fprintf(stderr, "usage: outfile alaw|ulaw number-of-ms\n",
			argv[0]);
		exit(1);
	}
	outf = fopen(argv[1], "w");
	if (!outf) {
		perror(argv[1]);
		exit(1);
	}
	if (!strcmp(argv[2], "alaw"))
		seq = dmw_alaw;
	else if (!strcmp(argv[2], "ulaw"))
		seq = dmw_ulaw;
	else
		goto usage;
	total_ms = atoi(argv[3]);
	for (n = 0; n < total_ms; n++)
		fwrite(seq, 1, 8, outf);
	exit(0);
}