# HG changeset patch # User Mychaela Falconia # Date 1709618899 28800 # Node ID 030d52b96a236c78617df25df68370cbb31b2b95 # Parent cc997f9ae1863fc51b7b1a3b2861012a820562be test-fsk: implement SpanDSP Tx output diff -r cc997f9ae186 -r 030d52b96a23 include/pstn_defs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/pstn_defs.h Mon Mar 04 22:08:19 2024 -0800 @@ -0,0 +1,3 @@ +/* misc PSTN definitions */ + +#define FRAME_20MS 160 /* samples per RTP packet */ diff -r cc997f9ae186 -r 030d52b96a23 test-fsk/Makefile --- a/test-fsk/Makefile Mon Mar 04 21:22:27 2024 -0800 +++ b/test-fsk/Makefile Mon Mar 04 22:08:19 2024 -0800 @@ -9,7 +9,7 @@ all: ${PROG} ${PROG}: ${OBJS} ${LIBS} - ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} -lspandsp -lm install: install -c -m 755 ${PROG} ${INSTBIN} diff -r cc997f9ae186 -r 030d52b96a23 test-fsk/main.c --- a/test-fsk/main.c Mon Mar 04 21:22:27 2024 -0800 +++ b/test-fsk/main.c Mon Mar 04 22:08:19 2024 -0800 @@ -13,6 +13,7 @@ #include #include #include +#include #include "../libsip/out_msg.h" #include "../libsip/sdp.h" @@ -30,6 +31,7 @@ unsigned max_forwards = 70; int declare_100rel_supp; int pcma_codec_pref, pcma_codec_force; +int fsk_mode_rx, fsk_mode_tx; send_invite_req() { @@ -75,6 +77,23 @@ } static void +select_modulation(modname) + char *modname; +{ + if (!strcmp(modname, "v21")) { + fsk_mode_rx = FSK_V21CH2; + fsk_mode_tx = FSK_V21CH1; + } else if (!strcmp(modname, "bell103")) { + fsk_mode_rx = FSK_BELL103CH2; + fsk_mode_tx = FSK_BELL103CH1; + } else { + fprintf(stderr, "error: modulation name \"%s\" unknown\n", + modname); + exit(1); + } +} + +static void preliminary_proc(argc, argv) char **argv; { @@ -104,12 +123,12 @@ default: usage: fprintf(stderr, - "usage: %s [options] dest-conf from-num to-num\n", + "usage: %s [options] dest-conf from-num to-num mode\n", argv[0]); exit(1); } } - if (argc != optind + 3) + if (argc != optind + 4) goto usage; read_config_file(argv[optind]); open_sip_udp_socket(); @@ -120,6 +139,7 @@ sprintf(from_uri, ";tag=out%u", argv[optind+1], 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]); if (logfile) { rc = open_sip_log_file(logfile); if (rc < 0) diff -r cc997f9ae186 -r 030d52b96a23 test-fsk/rtp_tx.c --- a/test-fsk/rtp_tx.c Mon Mar 04 21:22:27 2024 -0800 +++ b/test-fsk/rtp_tx.c Mon Mar 04 22:08:19 2024 -0800 @@ -12,19 +12,23 @@ #include #include #include +#include #include "../include/tmgw_const.h" #include "../include/rtp_defs.h" +#include "../include/pstn_defs.h" #include "../libutil/osmo_bits.h" extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; extern struct timeval cur_event_time; +extern int fsk_mode_tx; static uint32_t rtp_ssrc; static uint32_t rtp_out_ts; static uint16_t rtp_out_seq; -static uint8_t pcm_fill_octet; +static fsk_tx_state_t *fsk_tx_state; +static g711_state_t *g711_enc_state; void assign_rtpout_ssrc() @@ -32,13 +36,26 @@ rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); } +static int +supply_bit() +{ + return 1; +} + void -init_pcm_fill_octet() +init_pcm_tx() { - if (pcma_selected) - pcm_fill_octet = 0xD5; - else - pcm_fill_octet = 0xFF; + fsk_tx_state = fsk_tx_init(NULL, &preset_fsk_specs[fsk_mode_tx], + supply_bit, NULL); + if (!fsk_tx_state) { + fprintf(stderr, "error: fsk_tx_init() failed!\n"); + exit(1); + } + g711_enc_state = g711_init(NULL, pcma_selected ? G711_ALAW : G711_ULAW); + if (!g711_enc_state) { + fprintf(stderr, "error: g711_init() failed!\n"); + exit(1); + } } void @@ -46,22 +63,17 @@ { struct rtp_packet pkt; socklen_t addrlen; + int16_t linear[FRAME_20MS]; pkt.v_p_x_cc = 0x80; pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; pkt.seq = htons(rtp_out_seq++); pkt.tstamp = htonl(rtp_out_ts); - rtp_out_ts += 160; + rtp_out_ts += FRAME_20MS; pkt.ssrc = rtp_ssrc; - memset(pkt.payload, pcm_fill_octet, RTP_MAX_PAYLOAD); + fsk_tx(fsk_tx_state, linear, FRAME_20MS); + g711_encode(g711_enc_state, pkt.payload, linear, FRAME_20MS); addrlen = sizeof(struct sockaddr_in); sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, (struct sockaddr *) &rtp_remote_addr, addrlen); } - -void -set_pcm_fill_octet(oct) - unsigned oct; -{ - pcm_fill_octet = oct; -} diff -r cc997f9ae186 -r 030d52b96a23 test-fsk/sdp_in.c --- a/test-fsk/sdp_in.c Mon Mar 04 21:22:27 2024 -0800 +++ b/test-fsk/sdp_in.c Mon Mar 04 22:08:19 2024 -0800 @@ -81,5 +81,5 @@ } rtp_out_enable = 1; assign_rtpout_ssrc(); - init_pcm_fill_octet(); + init_pcm_tx(); } diff -r cc997f9ae186 -r 030d52b96a23 test-fsk/user_cmd.c --- a/test-fsk/user_cmd.c Mon Mar 04 21:22:27 2024 -0800 +++ b/test-fsk/user_cmd.c Mon Mar 04 22:08:19 2024 -0800 @@ -53,8 +53,6 @@ send_bye_req(); else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel")) send_cancel_req(); - else if (!strncmp(cp, "pcm-fill", 8) && isspace(cp[8])) - pcm_fill_cmd(cp + 9); else fprintf(stderr, "error: non-understood stdin command\n"); }