This commit is contained in:
Kurt Moraw
2020-11-24 16:07:52 +01:00
parent 13fc720d65
commit e6fb6550e0
79 changed files with 309 additions and 157 deletions
+32 -10
View File
@@ -49,6 +49,8 @@ HSTREAM stream = 0;
int openpbdev = -1;
int opencapdev = -1;
float softwareCAPvolume = 0.5;
void showDeviceInfo(BASS_DEVICEINFO info)
{
printf("Name:%s driver:%s flags:%d:", info.name, info.driver,info.flags);
@@ -377,16 +379,28 @@ int ret = 0;
}
#ifdef _LINUX_
void selectPBdevice()
int selectPBdevice()
{
if (!BASS_SetDevice(openpbdev))
{
printf("BASS_SetDevice: %d err:%d\n", openpbdev, BASS_ErrorGetCode());
}
else
return 1;
return 0;
}
void selectCAPdevice()
int selectCAPdevice()
{
if (!BASS_SetDevice(opencapdev))
printf("BASS_SetDevice: %d err:%d\n", opencapdev, BASS_ErrorGetCode());
{
//printf("BASS_SetDevice: %d err:%d\n", opencapdev, BASS_ErrorGetCode());
}
else
return 1;
return 0;
}
void close_audio()
@@ -416,9 +430,9 @@ void setPBvolume(int v)
//printf("set PB volume to:%d / %f [0..1]\n", v, vf );
selectPBdevice();
if (!BASS_SetVolume(vf))
printf("setPBvolume: %d err:%d\n", openpbdev, BASS_ErrorGetCode());
if(selectPBdevice())
if (!BASS_SetVolume(vf))
printf("setPBvolume: %d err:%d\n", openpbdev, BASS_ErrorGetCode());
}
void setCAPvolume(int v)
@@ -430,9 +444,18 @@ void setCAPvolume(int v)
//printf("set CAP volume to:%d / %f [0..1]\n", v, vf);
selectCAPdevice();
if (!BASS_RecordSetInput(-1,BASS_INPUT_ON,vf))
printf("setCAPvolume: %d err:%d\n", opencapdev, BASS_ErrorGetCode());
if (selectCAPdevice())
{
if (!BASS_RecordSetInput(-1, BASS_INPUT_ON, vf))
printf("setCAPvolume: %d err:%d\n", opencapdev, BASS_ErrorGetCode());
else
softwareCAPvolume = 1;
}
else
{
softwareCAPvolume = (float)v;
softwareCAPvolume /= 50;
}
}
// capture callback
@@ -588,7 +611,6 @@ int cap_fifo_usedPercent()
int fs = cap_fifo_freespace();
int used = AUDIO_CAPTURE_BUFLEN - fs;
used = (used * 100) / AUDIO_CAPTURE_BUFLEN;
if (used < 5) printf("used:%d\n", used);
return used;
}
-4
View File
@@ -44,10 +44,6 @@ float maxCAPvol = 99;
extern int openpbdev;
extern int opencapdev;
float softwareCAPvolume = 0.5;
int init_wasapi(int pbdev, int capdev)
{
int ret = 0;
Binary file not shown.
+45 -3
View File
@@ -39,8 +39,11 @@ fftw_plan plan = NULL;
int fftidx = 0;
int fftcnt = fft_rate/2+1; // number of output values
uint16_t fftout[FFT_AUDIOSAMPLERATE / 10/2+1];
float f_fftout[FFT_AUDIOSAMPLERATE / 10 / 2 + 1];
int downsamp = 0;
int downphase = 0;
int rxlevel_deteced = 0;
int rx_in_sync = 0;
uint16_t *make_waterfall(float fre, int *retlen)
{
@@ -50,9 +53,8 @@ uint16_t *make_waterfall(float fre, int *retlen)
// caprate 44,1k: downsample by 5,5
if (caprate == 48000)
{
if (++downsamp < 6) return NULL;
}
if (caprate == 44100)
{
if (downphase <= 1100)
@@ -76,7 +78,7 @@ uint16_t *make_waterfall(float fre, int *retlen)
if(fftidx == fft_rate)
{
fftidx = 0;
// the fft buffer is full, execute the FFT
fftw_execute(plan);
@@ -88,9 +90,49 @@ uint16_t *make_waterfall(float fre, int *retlen)
float mag = sqrt((fre * fre) + (fim * fim));
fftout[j] = (uint16_t)mag;
f_fftout[j] = mag;
fftrdy = 1;
}
// signal detection
// measure level at band edges
float edgelevel = 0;
for (int e = 0; e < 10; e++)
edgelevel += f_fftout[e];
for (int e = 390; e < fftcnt; e++)
edgelevel += f_fftout[e];
edgelevel /= 20;
// measure level at mid band
float midlevel = 0;
for (int e = 100; e < 300; e++)
midlevel += f_fftout[e];
midlevel /= 20;
//calc difference in %
int idiff = (int)((edgelevel * 100) / midlevel);
//printf("diff:%d %% edge:%10.6f midband:%10.6f\n", ldiff, idiff,edgelevel, midlevel);
// IC9700 ... noise makes about 5% idiff
// Signal makes 0-2%, so we take the decision at 3%
const int maxchecks = 3;
static int rxstat = 0;
if (idiff < 3)
{
if (rxstat == maxchecks)
{
printf("===>>> level detected, reset modem\n");
trigger_resetmodem = 1;
rxlevel_deteced = 1;
}
if(rxstat <= maxchecks) rxstat++;
}
else
{
rxstat = 0;
rxlevel_deteced = 0;
}
}
if(fftrdy == 1)
+22 -7
View File
@@ -28,6 +28,9 @@
* it can be compiled under Linux: make
* and under Windows: Visual-Studio
*
* !!! compile x86 (32bit) version !!! all supplied dlls are 32 bit !!!
* ====================================================================
*
* 3rd party libraries:
* 1) BASS Audio from https://www.un4seen.com/
copy bass.h and bass.lib into source directory
@@ -92,6 +95,7 @@ char ownfilename[] = { "hsmodem" };
char appIP[20] = { 0 };
int fixappIP = 0;
int restart_modems = 0;
int trigger_resetmodem = 0;
int caprate = 44100;
int txinterpolfactor = 20;
@@ -239,11 +243,12 @@ int main(int argc, char* argv[])
}
int dret = demodulator();
#ifdef _LINUX_
if(dret == 0)
usleep(1);
#endif
if (dret == 0)
{
// no new data in fifo
// not important how long to sleep, 10ms is fine
sleep_ms(10);
}
}
printf("stopped: %d\n", keeprunning);
@@ -411,8 +416,10 @@ void appdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
if (type == 19)
{
// shut down this modem PC
#ifdef _LINUX_
int r = system("sudo shutdown now");
exit(r);
#endif
}
if (type == 20)
@@ -545,19 +552,27 @@ void GRdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
toCodecDecoder(pl + 10, PAYLOADLEN);
}
fnd = 0;
trigger_resetmodem = 0;
rx_in_sync = 1;
}
else
{
// no frame found
// if longer ws seconds nothing found, reset liquid RX modem
// comes here with symbol rate, i.e. 4000 S/s
int ws = 4;
int ws = 5;
int wt = sr[speedmode].audio / sr[speedmode].tx;
if (++fnd >= (wt * ws))
if (++fnd >= (wt * ws) || trigger_resetmodem)
{
fnd = 0;
trigger_resetmodem = 0;
rx_in_sync = 0;
printf("no signal detected %d, reset RX modem\n", wt);
resetModem();
}
else if (fnd >= wt)
{
rx_in_sync = 0;
}
}
}
+3 -1
View File
@@ -215,7 +215,9 @@ extern int init_voice_result;
extern int initialLSvol;
extern int initialMICvol;
extern int codec;
extern int trigger_resetmodem;
extern int rxlevel_deteced;
extern int rx_in_sync;
// audio device description table
typedef struct {
+2 -1
View File
@@ -124,12 +124,13 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>wsock32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/NODEFAULTLIB:libcmt.lib %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+5 -3
View File
@@ -198,6 +198,7 @@ void modulator(uint8_t sym_in)
while(1)
{
fs = pb_fifo_freespace(0);
// wait until there is space in fifo
if(fs) break;
sleep_ms(10);
}
@@ -287,6 +288,9 @@ void make_FFTdata(float f)
if (us > 255) us = 255;
txpl[bidx++] = us; // usage of TX fifo
txpl[bidx++] = rxlevel_deteced; // RX level present
txpl[bidx++] = rx_in_sync;
for (int i = 0; i < fftlen; i++)
{
txpl[bidx++] = fft[i] >> 8;
@@ -339,9 +343,7 @@ static int ccol_idx = 0;
// input volume
#ifdef _WIN32_
f *= softwareCAPvolume;
#endif
getMax(f);
@@ -393,7 +395,7 @@ static int ccol_idx = 0;
// we have about 2000 S/s, but this many points would make the GUI slow
// so we send only every x
static int ev = 0;
if (++ev >= 2)
if (++ev >= 10)
{
ev = 0;
uint32_t re = (uint32_t)(syms.real * 16777216.0);
+10
View File
@@ -90,8 +90,18 @@ void closeAllandTerminate()
// close liquid-SDR
close_dsp();
// close network sockets
#ifdef _LINUX_
close(BC_sock_AppToModem);
#endif
#ifdef _WIN32_
closesocket(BC_sock_AppToModem);
#endif
#ifdef _LINUX_
close(DATA_sock_AppToModem);
#endif
#ifdef _WIN32_
closesocket(DATA_sock_AppToModem);
#endif
exit(0);
}