SSB_HighSpeed_Modem/hsmodem/hsmodem.h

257 lines
7.2 KiB
C
Raw Normal View History

2020-11-14 19:32:47 -05:00
#pragma once
2020-11-05 13:11:57 -05:00
#ifdef _WIN32
#define _WIN32_
// ignore senseless warnings invented by M$ to confuse developers
2021-01-18 09:36:29 -05:00
// I love LINUX :-) which works 100000x better than Windows
2020-11-05 13:11:57 -05:00
#pragma warning( disable : 4091 )
#pragma warning( disable : 4003 )
#else
#define _LINUX_
#endif
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
2020-12-19 16:46:34 -05:00
#include <sys/stat.h>
2020-11-05 13:11:57 -05:00
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <wchar.h>
#ifdef _WIN32_
#include "Winsock2.h"
#include "io.h"
#include <Windows.h>
#include <iostream>
#include <process.h>
#include <Tlhelp32.h>
#include <winbase.h>
#include <Shlobj.h>
#define _USE_MATH_DEFINES
#include <math.h>
#pragma comment(lib, "libliquid.lib")
2020-12-10 13:14:40 -05:00
#pragma comment(lib, "libsoundio.lib")
2020-11-05 13:11:57 -05:00
#pragma comment(lib, "fftw_lib/libfftw3-3.lib")
2020-11-21 13:54:47 -05:00
#pragma comment(lib, "opus.lib")
#pragma comment(lib, "libcodec2.lib")
2020-11-05 13:11:57 -05:00
#endif
#ifdef _LINUX_
#include <sys/socket.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/file.h>
#include <pthread.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <pwd.h>
#include <math.h>
#endif
2020-11-27 13:31:22 -05:00
#include "opus.h"
2020-11-05 13:11:57 -05:00
#include "liquid.h"
#include "frameformat.h"
#include "fec.h"
#include "udp.h"
2020-11-14 19:32:47 -05:00
#include "symboltracker.h"
2020-11-21 13:54:47 -05:00
#include "codec2.h"
2021-01-15 16:15:58 -05:00
#include "libkmaudio/soundio.h"
2021-01-02 18:34:35 -05:00
#include "baudot.h"
2021-02-22 09:58:19 -05:00
#include "fifo.h"
2021-01-15 16:15:58 -05:00
#include "libkmaudio/libkmaudio.h"
2021-02-22 09:58:19 -05:00
#include "websocket/websocketserver.h"
2020-11-05 13:11:57 -05:00
#define jpg_tempfilename "rxdata.jpg"
#define CRC16TX 0
#define CRC16RX 1
#define CRC16FILE 2
2020-11-07 12:07:55 -05:00
// definitions for audio
2020-12-10 13:14:40 -05:00
#define MAXDEVSTRLEN 5000
2020-11-07 12:07:55 -05:00
#define CHANNELS 1 // no of channels used
2020-11-21 13:54:47 -05:00
// voice audio sampling rate
#define VOICE_SAMPRATE 48000 // do NOT change, OPUS works with 48k only
2020-12-11 16:53:26 -05:00
#define AUDIO_SAMPRATE 48000 // do NOT change, WASAPI VACs work with 48k only
2020-11-21 13:54:47 -05:00
enum _VOICEMODES_ {
VOICEMODE_OFF,
VOICEMODE_LISTENAUDIOIN,
VOICEMODE_INTERNALLOOP,
VOICEMODE_CODECLOOP,
VOICEMODE_DV_FULLDUPLEX,
2020-12-19 16:46:34 -05:00
VOICEMODE_DV_RXONLY,
VOICEMODE_RECORD,
VOICEMODE_PLAYBACK
2020-11-21 13:54:47 -05:00
};
2020-11-05 13:11:57 -05:00
void init_packer();
2020-12-12 06:36:16 -05:00
uint8_t* Pack(uint8_t* payload, int type, int status, int* plen, int repeat);
2020-11-05 13:11:57 -05:00
uint8_t* unpack_data(uint8_t* rxd, int len);
void convertBytesToSyms_QPSK(uint8_t* bytes, uint8_t* syms, int bytenum);
void convertBytesToSyms_8PSK(uint8_t* bytes, uint8_t* syms, int bytenum);
uint8_t* convertQPSKSymToBytes(uint8_t* rxsymbols);
uint8_t* convert8PSKSymToBytes(uint8_t* rxsymbols, int len);
2020-12-19 16:46:34 -05:00
uint8_t* rotateBackBPSK(uint8_t* buf, int len, int rotations);
uint8_t* convertBPSKSymToBytes(uint8_t* rxsymbols);
void convertBytesToSyms_BPSK(uint8_t* bytes, uint8_t* syms, int bytenum);
void rotateBPSKsyms(uint8_t* src, uint8_t* dst, int len);
2020-11-05 13:11:57 -05:00
void rotateQPSKsyms(uint8_t* src, uint8_t* dst, int len);
void rotate8PSKsyms(uint8_t* src, uint8_t* dst, int len);
void rotate8APSKsyms(uint8_t* src, uint8_t* dst, int len);
uint8_t* rotateBackQPSK(uint8_t* buf, int len, int rotations);
uint8_t* rotateBack8PSK(uint8_t* buf, int len, int rotations);
uint8_t* rotateBack8APSK(uint8_t* buf, int len, int rotations);
void TX_Scramble(uint8_t* data, int len);
uint8_t* RX_Scramble(uint8_t* data, int len);
uint16_t Crc16_messagecalc(int rxtx, uint8_t* data, int len);
2020-11-21 13:54:47 -05:00
void showbytestring(char* title, uint8_t* data, int totallen, int anz);
2020-11-07 12:07:55 -05:00
void measure_speed_syms(int len);
void measure_speed_bps(int len);
2020-11-05 13:11:57 -05:00
void initFEC();
void GetFEC(uint8_t* txblock, int len, uint8_t* destArray);
int cfec_Reconstruct(uint8_t* darr, uint8_t* destination);
2021-01-15 16:15:58 -05:00
2020-12-10 13:14:40 -05:00
void io_setPBvolume(int v);
void io_setCAPvolume(int v);
2021-01-15 16:15:58 -05:00
void io_setLSvolume(int v);
void io_setMICvolume(int v);
2020-12-10 13:14:40 -05:00
2020-11-09 20:23:21 -05:00
void sendAnnouncement();
2020-11-05 13:11:57 -05:00
void sleep_ms(int ms);
2020-12-20 09:16:04 -05:00
uint64_t getms();
2020-11-05 13:11:57 -05:00
void GRdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock);
2020-12-12 06:36:16 -05:00
void toGR_sendData(uint8_t* data, int type, int status, int repeat);
2020-11-05 13:11:57 -05:00
void modulator(uint8_t sym_in);
2021-01-15 16:15:58 -05:00
2020-11-05 13:11:57 -05:00
void init_dsp();
int demodulator();
2021-02-22 09:58:19 -05:00
void _sendToModulator(uint8_t* d, int len);
2020-11-05 13:11:57 -05:00
void resetModem();
void close_dsp();
2020-12-19 16:46:34 -05:00
void _init_fft();
void _exit_fft();
2020-12-10 13:14:40 -05:00
void showbytestringf(char* title, float* data, int totallen, int anz);
2020-11-05 13:11:57 -05:00
uint16_t* make_waterfall(float fre, int* retlen);
2021-02-22 09:58:19 -05:00
void sendPSKdata(uint8_t* data, int len, int fifoID);
void modem_sendPSKData(uint8_t* data, int type, int status, int repeat, int fifoID);
2020-11-05 13:11:57 -05:00
2020-11-21 13:54:47 -05:00
void toCodecDecoder(uint8_t* pdata, int len);
void init_voiceproc();
void encode(float f);
void init_codec2();
void encode_codec2(float f);
void toCodecDecoder_codec2(uint8_t* pdata, int len);
void closeAllandTerminate();
void close_voiceproc();
void close_codec2();
2021-01-02 18:34:35 -05:00
SYMTRACK* km_symtrack_cccf_create( int _ftype,
unsigned int _k,
unsigned int _m,
float _beta,
int _ms);
void km_symtrack_cccf_reset(SYMTRACK*, int mode);
void km_symtrack_cccf_set_bandwidth(SYMTRACK* , float _bw);
void km_symtrack_execute(SYMTRACK* ,liquid_float_complex _x, liquid_float_complex* _y, unsigned int* _ny, unsigned int* psym_out);
void km_symtrack_cccf_destroy(SYMTRACK*);
2020-11-05 13:11:57 -05:00
2021-01-15 16:15:58 -05:00
void io_saveStream(float *fa, int anz);
2020-12-19 16:46:34 -05:00
void playIntro();
2020-12-21 09:59:35 -05:00
float do_tuning(int send);
void init_tune();
float singleFrequency();
2020-12-22 12:30:00 -05:00
void showbytestring16(char* title, uint16_t* data, int anz);
2021-01-02 18:34:35 -05:00
void init_rtty();
void make_FFTdata(float f);
void close_rtty();
void close_a();
void rtty_modifyRXfreq(int);
void showbitstring(char* title, uint8_t* data, int totallen, int anz);
void fmtest();
2021-01-15 16:15:58 -05:00
void initVoice();
2021-01-18 09:36:29 -05:00
void sendStationInfo();
2021-02-22 09:58:19 -05:00
void ext_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock);
void init_distributor();
void ext_modemRX(uint8_t* pdata);
int fifo_dataavail(int pipenum);
void showbytestring32(char* title, uint32_t* data, int anz);
void start_timer(int mSec, void(*timer_func_handler)(void));
2020-12-19 16:46:34 -05:00
2020-12-10 13:14:40 -05:00
2020-11-05 13:11:57 -05:00
extern int speedmode;
extern int bitsPerSymbol;
extern int constellationSize;
extern int speed;
extern int keeprunning;
extern int caprate;
extern int BC_sock_AppToModem;
2020-11-21 13:54:47 -05:00
extern int DATA_sock_AppToModem;
2020-11-05 13:11:57 -05:00
extern int UdpDataPort_ModemToApp;
extern int txinterpolfactor;
extern int rxPreInterpolfactor;
extern char appIP[20];
2020-11-09 20:23:21 -05:00
extern int announcement;
extern int ann_running;
extern int transmissions;
extern int linespeed;
2020-11-14 19:32:47 -05:00
extern uint8_t maxLevel;
2020-12-12 06:36:16 -05:00
extern uint8_t maxTXLevel;
2020-11-21 13:54:47 -05:00
extern int VoiceAudioMode;
extern int opusbitrate;
extern int init_voice_result;
extern int initialLSvol;
extern int initialMICvol;
extern int codec;
2020-11-24 10:07:52 -05:00
extern int trigger_resetmodem;
extern int rxlevel_deteced;
extern int rx_in_sync;
2020-12-11 16:53:26 -05:00
extern int restart_modems;
2020-12-19 16:46:34 -05:00
extern char homepath[];
extern int sendIntro;
2020-12-21 09:59:35 -05:00
extern int tuning;
extern uint32_t tuning_runtime;
extern int marker;
2021-01-02 18:34:35 -05:00
extern int rtty_txoff;
extern int rtty_txidx;
extern int rtty_frequency;
extern int rtty_autosync;
2021-01-15 16:15:58 -05:00
extern int io_capidx;
extern int io_pbidx;
extern int voice_capidx;
extern int voice_pbidx;
extern float pbvol;
extern float capvol;
extern float lsvol;
extern float micvol;
2021-02-22 09:58:19 -05:00
extern int extData_active;
2020-11-05 13:11:57 -05:00
#ifdef _LINUX_
int isRunning(char* prgname);
void install_signal_handler();
#endif