view sw/mcsi-rxtx/record.c @ 15:8b49ea8aeb99

fc-mcsi-rxtx: more reliable fflush(stdout) in main loop
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2024 23:43:10 +0000
parents 315428573a25
children
line wrap: on
line source

/*
 * Here we implement the functionality of recording MCSI Rx streams
 * into robe files.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

extern u_short rx_pcm_samples[160];

static FILE *record_file;

void
record_process()
{
	unsigned n, samp;

	if (!record_file)
		return;
	for (n = 0; n < 160; n++) {
		samp = rx_pcm_samples[n];
		putc(samp >> 8, record_file);
		putc(samp, record_file);
	}
}

void
record_auto_stop()
{
	if (!record_file)
		return;
	fclose(record_file);
	record_file = 0;
}

void
cmd_record(argc, argv)
	char **argv;
{
	if (record_file) {
		printf("error: recording already in progress\n");
		return;
	}
	record_file = fopen(argv[1], "w");
	if (!record_file)
		perror(argv[1]);
}

void
cmd_record_stop()
{
	if (!record_file) {
		printf("error: no recording in progress\n");
		return;
	}
	fclose(record_file);
	record_file = 0;
}