changeset 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 e80b0051cd92
children 6d832abad660
files test-fsk/Makefile test-fsk/main.c test-fsk/modem_rx.c test-fsk/rtp_rx.c
diffstat 4 files changed, 63 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/test-fsk/Makefile	Mon Mar 04 22:25:53 2024 -0800
+++ b/test-fsk/Makefile	Mon Mar 04 23:21:07 2024 -0800
@@ -1,8 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	sipout-test-fsk
-OBJS=	bye_in.o disc_cmd.o main.o readconf.o reinvite.o rtp_rx.o rtp_tx.o \
-	sdp_in.o sip_log.o sip_udp.o uac.o uas.o user_cmd.o
+OBJS=	bye_in.o disc_cmd.o main.o modem_rx.o readconf.o reinvite.o rtp_rx.o \
+	rtp_tx.o sdp_in.o sip_log.o sip_udp.o uac.o uas.o user_cmd.o
 LIBS=	../libsip/libsip.a ../librtpalloc/librtpalloc.a ../libutil/libutil.a
 INSTBIN=/opt/themwi/bin
 
--- a/test-fsk/main.c	Mon Mar 04 22:25:53 2024 -0800
+++ b/test-fsk/main.c	Mon Mar 04 23:21:07 2024 -0800
@@ -140,6 +140,7 @@
 		inet_ntoa(sip_bind_ip), ntohs(rtp_local_addr.sin_port));
 	sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain);
 	select_modulation(argv[optind+3]);
+	init_modem_rx();
 	if (logfile) {
 		rc = open_sip_log_file(logfile);
 		if (rc < 0)
--- /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);
+}
--- a/test-fsk/rtp_rx.c	Mon Mar 04 22:25:53 2024 -0800
+++ b/test-fsk/rtp_rx.c	Mon Mar 04 23:21:07 2024 -0800
@@ -14,8 +14,12 @@
 #include <strings.h>
 #include "../include/tmgw_const.h"
 #include "../include/rtp_defs.h"
+#include "../include/pstn_defs.h"
 #include "../librtpalloc/rtp_alloc_simple.h"
 
+extern const uint16_t pcmu_decode_table[256];
+extern const uint16_t pcma_decode_table[256];
+
 struct sockaddr_in rtp_local_addr;
 int rtp_udp_fd, rtcp_udp_fd;
 
@@ -49,6 +53,9 @@
 	socklen_t addrlen;
 	int16_t seq_delta;
 	int32_t ts_delta;
+	const uint16_t *pcm_dec_table;
+	int16_t pcm_samples[FRAME_20MS];
+	unsigned n;
 	int rc;
 
 	addrlen = sizeof(struct sockaddr_in);
@@ -67,7 +74,10 @@
 		goto bad_rtp_pkt;
 	switch (pkt.m_pt & 0x7F) {
 	case PSTN_CODEC_PCMU:
+		pcm_dec_table = pcmu_decode_table;
+		break;
 	case PSTN_CODEC_PCMA:
+		pcm_dec_table = pcma_decode_table;
 		break;
 	default:
 		goto bad_rtp_pkt;
@@ -114,6 +124,9 @@
 			rtp_last_seq, rtp_last_ts);
 		rtp_start_flag = 1;
 	}
+	for (n = 0; n < FRAME_20MS; n++)
+		pcm_samples[n] = pcm_dec_table[pkt.payload[n]];
+	process_rx_frame(pcm_samples);
 }
 
 void