diff test-fsk/modem_rx.c @ 6:ba66d297fe57

test-fsk: first attempt at modem Rx
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 04 Mar 2024 23:21:07 -0800
parents
children 6d832abad660
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-fsk/modem_rx.c	Mon Mar 04 23:21:07 2024 -0800
@@ -0,0 +1,47 @@
+/*
+ * In this module we implement modem Rx handling, revolving around
+ * FSK demodulation via SpanDSP.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <spandsp.h>
+#include "../include/pstn_defs.h"
+
+extern int fsk_mode_rx;
+
+static fsk_rx_state_t *fsk_rx_state;
+
+static void
+byte_rx_func(user_data, byte)
+	void *user_data;
+	int byte;
+{
+	if (byte < 0) {
+		printf("Modem state change: %s\n", signal_status_to_str(byte));
+		return;
+	}
+	printf("Rx byte: 0x%02X\n", byte);
+}
+
+void
+init_modem_rx()
+{
+	fsk_rx_state = fsk_rx_init(NULL, &preset_fsk_specs[fsk_mode_rx],
+				   FSK_FRAME_MODE_FRAMED, byte_rx_func, NULL);
+	if (!fsk_rx_state) {
+		fprintf(stderr, "error: fsk_rx_init() failed!\n");
+		exit(1);
+	}
+}
+
+void
+process_rx_frame(samples)
+	int16_t *samples;
+{
+	fsk_rx(fsk_rx_state, samples, FRAME_20MS);
+}