66 lines
1.5 KiB
C
66 lines
1.5 KiB
C
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <math.h>
|
|
|
|
#include "bpsk.h"
|
|
|
|
#define clear() printf("\033[H\033[J")
|
|
#define gotoxy(x, y) printf("\033[%d;%dH", (y), (x))
|
|
|
|
static uint8_t wave_header[44];
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char *wave_file_name = "modulated.wav";
|
|
struct stat statbuf;
|
|
int16_t *wave_buffer;
|
|
|
|
if (argc > 1)
|
|
{
|
|
wave_file_name = argv[1];
|
|
}
|
|
|
|
printf("Opening %s for demodulation...\n", wave_file_name);
|
|
int fd = open(wave_file_name, O_RDONLY);
|
|
if (fd == -1)
|
|
{
|
|
perror("unable to open wave file");
|
|
return 1;
|
|
}
|
|
|
|
if (-1 == fstat(fd, &statbuf))
|
|
{
|
|
perror("unable to determine size of buffer");
|
|
return 1;
|
|
}
|
|
|
|
// Read the .wav header (44 bytes) into the wave header array.
|
|
// This effectively discards it.
|
|
if (read(fd, wave_header, sizeof(wave_header)) != sizeof(wave_header))
|
|
{
|
|
fprintf(stderr, "couldn't read wave header");
|
|
}
|
|
|
|
// Allocate a buffer for the remainder of the wave file.
|
|
int wave_len_bytes = statbuf.st_size - sizeof(wave_header);
|
|
wave_buffer = malloc(wave_len_bytes);
|
|
if (read(fd, wave_buffer, wave_len_bytes) != wave_len_bytes)
|
|
{
|
|
fprintf(stderr, "short read of wave file\n");
|
|
return 1;
|
|
}
|
|
|
|
// Perform a BPSK run on it.
|
|
bpsk_init();
|
|
bpsk_run(wave_buffer, wave_len_bytes / sizeof(uint16_t));
|
|
|
|
printf("\n");
|
|
return 0;
|
|
}
|