mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-17 17:42:02 -05:00
Cleaning up the soundin routine.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/jtms3@2480 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
f8c1b6ed23
commit
6703d4850d
@ -194,13 +194,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
// Assign input device and start input thread
|
||||
soundInThread.setInputDevice(m_paInDevice);
|
||||
if(m_fs96000) soundInThread.setRate(96000.0);
|
||||
if(!m_fs96000) soundInThread.setRate(95238.1);
|
||||
soundInThread.setBufSize(10*7056);
|
||||
soundInThread.setNetwork(m_network);
|
||||
soundInThread.setPort(m_udpPort);
|
||||
if(!m_xpol) soundInThread.setNrx(1);
|
||||
if(m_xpol) soundInThread.setNrx(2);
|
||||
soundInThread.start(QThread::HighestPriority);
|
||||
|
||||
// Assign output device and start output thread
|
||||
@ -363,20 +356,12 @@ void MainWindow::readSettings()
|
||||
m_dPhi=settings.value("dPhi",0).toInt();
|
||||
m_fCal=settings.value("Fcal",0).toInt();
|
||||
m_fAdd=settings.value("FAdd",0).toDouble();
|
||||
soundInThread.setFadd(m_fAdd);
|
||||
m_network = settings.value("NetworkInput",true).toBool();
|
||||
m_fs96000 = settings.value("FSam96000",true).toBool();
|
||||
m_nDevIn = settings.value("SoundInIndex", 0).toInt();
|
||||
m_paInDevice = settings.value("paInDevice",0).toInt();
|
||||
m_nDevOut = settings.value("SoundOutIndex", 0).toInt();
|
||||
m_paOutDevice = settings.value("paOutDevice",0).toInt();
|
||||
m_IQswap = settings.value("IQswap",false).toBool();
|
||||
m_10db = settings.value("Plus10dB",false).toBool();
|
||||
m_initIQplus = settings.value("InitIQplus",false).toBool();
|
||||
m_udpPort = settings.value("UDPport",50004).toInt();
|
||||
soundInThread.setSwapIQ(m_IQswap);
|
||||
soundInThread.set10db(m_10db);
|
||||
soundInThread.setPort(m_udpPort);
|
||||
ui->actionCuteSDR->setChecked(settings.value(
|
||||
"PaletteCuteSDR",true).toBool());
|
||||
ui->actionLinrad->setChecked(settings.value(
|
||||
@ -556,20 +541,10 @@ void MainWindow::on_actionDeviceSetup_triggered() //Setup Dialog
|
||||
m_paInDevice=dlg.m_paInDevice;
|
||||
m_nDevOut=dlg.m_nDevOut;
|
||||
m_paOutDevice=dlg.m_paOutDevice;
|
||||
g_pWideGraph->m_mult570=m_mult570;
|
||||
g_pWideGraph->m_cal570=m_cal570;
|
||||
soundInThread.setSwapIQ(m_IQswap);
|
||||
soundInThread.set10db(m_10db);
|
||||
|
||||
if(dlg.m_restartSoundIn) {
|
||||
soundInThread.quit();
|
||||
soundInThread.wait(1000);
|
||||
soundInThread.setNetwork(m_network);
|
||||
if(m_fs96000) soundInThread.setRate(96000.0);
|
||||
if(!m_fs96000) soundInThread.setRate(95238.1);
|
||||
soundInThread.setFadd(m_fAdd);
|
||||
if(!m_xpol) soundInThread.setNrx(1);
|
||||
if(m_xpol) soundInThread.setNrx(2);
|
||||
soundInThread.setInputDevice(m_paInDevice);
|
||||
soundInThread.start(QThread::HighestPriority);
|
||||
}
|
||||
@ -1310,8 +1285,6 @@ void MainWindow::guiUpdate()
|
||||
}
|
||||
|
||||
if(nsec != m_sec0) { //Once per second
|
||||
soundInThread.setForceCenterFreqMHz(g_pWideGraph->m_dForceCenterFreq);
|
||||
soundInThread.setForceCenterFreqBool(g_pWideGraph->m_bForceCenterFreq);
|
||||
|
||||
if(m_pctZap>30.0 and !m_transmitting) {
|
||||
lab4->setStyleSheet("QLabel{background-color: #ff0000}");
|
||||
@ -1332,7 +1305,6 @@ void MainWindow::guiUpdate()
|
||||
lab1->setText(s);
|
||||
} else if(m_monitoring) {
|
||||
lab1->setStyleSheet("QLabel{background-color: #00ff00}");
|
||||
m_nrx=soundInThread.nrx();
|
||||
khsym=soundInThread.mhsym();
|
||||
QString t;
|
||||
if(m_network) {
|
||||
|
187
soundin.cpp
187
soundin.cpp
@ -71,6 +71,8 @@ extern "C" int a2dCallback( const void *inputBuffer, void *outputBuffer,
|
||||
float tmp;
|
||||
float fac;
|
||||
|
||||
if(framesToProcess != -99) return paContinue; //###
|
||||
|
||||
if( (statusFlags&paInputOverflow) != 0) {
|
||||
qDebug() << "Input Overflow";
|
||||
}
|
||||
@ -135,15 +137,8 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
{
|
||||
quitExecution = false;
|
||||
|
||||
if (m_net) {
|
||||
// qDebug() << "Start inputUDP()";
|
||||
inputUDP();
|
||||
// qDebug() << "Finished inputUDP()";
|
||||
return;
|
||||
}
|
||||
|
||||
//---------------------------------------------------- Soundcard Setup
|
||||
// qDebug() << "Start souncard input";
|
||||
qDebug() << "Start souncard input";
|
||||
|
||||
PaError paerr;
|
||||
PaStreamParameters inParam;
|
||||
@ -152,17 +147,14 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
|
||||
udata.kin=0; //Buffer pointer
|
||||
udata.bzero=false; //Flag to request reset of kin
|
||||
udata.nrx=m_nrx; //Number of polarizations
|
||||
udata.iqswap=m_IQswap;
|
||||
udata.b10db=m_10db;
|
||||
|
||||
inParam.device=m_nDevIn; //### Input Device Number ###
|
||||
inParam.channelCount=2*m_nrx; //Number of analog channels
|
||||
inParam.channelCount=2; //Number of analog channels
|
||||
inParam.sampleFormat=paFloat32; //Get floats from Portaudio
|
||||
inParam.suggestedLatency=0.05;
|
||||
inParam.hostApiSpecificStreamInfo=NULL;
|
||||
|
||||
paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0);
|
||||
paerr=Pa_IsFormatSupported(&inParam,NULL,48000.0);
|
||||
if(paerr<0) {
|
||||
emit error("PortAudio says requested soundcard format not supported.");
|
||||
// return;
|
||||
@ -170,7 +162,7 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
paerr=Pa_OpenStream(&inStream, //Input stream
|
||||
&inParam, //Input parameters
|
||||
NULL, //No output parameters
|
||||
96000.0, //Sample rate
|
||||
48000.0, //Sample rate
|
||||
FRAMES_PER_BUFFER, //Frames per buffer
|
||||
// paClipOff+paDitherOff, //No clipping or dithering
|
||||
paClipOff, //No clipping
|
||||
@ -185,10 +177,10 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
// const PaStreamInfo* p=Pa_GetStreamInfo(inStream);
|
||||
|
||||
bool qe = quitExecution;
|
||||
int n60z=99;
|
||||
int n30z=99;
|
||||
int k=0;
|
||||
int nsec;
|
||||
int n60;
|
||||
int n30;
|
||||
int nBusy=0;
|
||||
int nhsym0=0;
|
||||
|
||||
@ -198,206 +190,51 @@ void SoundInThread::run() //SoundInThread::run()
|
||||
if (qe) break;
|
||||
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
|
||||
nsec = ms/1000; // Time according to this computer
|
||||
n60 = nsec % 60;
|
||||
n30 = nsec % 30;
|
||||
|
||||
// Reset buffer pointer and symbol number at start of minute
|
||||
if(n60 < n60z or !m_monitoring) {
|
||||
if(n30 < n30z or !m_monitoring) {
|
||||
nhsym0=0;
|
||||
udata.bzero=true;
|
||||
}
|
||||
k=udata.kin;
|
||||
udata.iqswap=m_IQswap;
|
||||
udata.b10db=m_10db;
|
||||
if(m_monitoring) {
|
||||
if(m_bForceCenterFreq) {
|
||||
datcom_.fcenter=m_dForceCenterFreq;\
|
||||
} else {
|
||||
datcom_.fcenter=144.125;
|
||||
}
|
||||
m_hsym=(k-2048)*11025.0/(2048.0*m_rate);
|
||||
if(m_hsym != nhsym0) {
|
||||
if(m_dataSinkBusy) {
|
||||
nBusy++;
|
||||
} else {
|
||||
m_dataSinkBusy=true;
|
||||
emit readyForFFT(k); //Signal to compute new FFTs
|
||||
// emit readyForFFT(k); //Signal to compute new FFTs
|
||||
}
|
||||
nhsym0=m_hsym;
|
||||
}
|
||||
}
|
||||
msleep(100);
|
||||
n60z=n60;
|
||||
n30z=n30;
|
||||
}
|
||||
Pa_StopStream(inStream);
|
||||
Pa_CloseStream(inStream);
|
||||
}
|
||||
|
||||
void SoundInThread::setSwapIQ(bool b)
|
||||
{
|
||||
m_IQswap=b;
|
||||
}
|
||||
|
||||
void SoundInThread::set10db(bool b)
|
||||
{
|
||||
m_10db=b;
|
||||
}
|
||||
void SoundInThread::setPort(int n) //setPort()
|
||||
{
|
||||
if (isRunning()) return;
|
||||
this->m_udpPort=n;
|
||||
}
|
||||
|
||||
void SoundInThread::setInputDevice(int n) //setInputDevice()
|
||||
{
|
||||
if (isRunning()) return;
|
||||
this->m_nDevIn=n;
|
||||
}
|
||||
|
||||
void SoundInThread::setRate(double rate) //setRate()
|
||||
{
|
||||
if (isRunning()) return;
|
||||
this->m_rate = rate;
|
||||
}
|
||||
|
||||
void SoundInThread::setBufSize(unsigned n) //setBufSize()
|
||||
{
|
||||
if (isRunning()) return;
|
||||
this->bufSize = n;
|
||||
}
|
||||
|
||||
void SoundInThread::setFadd(double x)
|
||||
{
|
||||
m_fAdd=x;
|
||||
}
|
||||
|
||||
|
||||
void SoundInThread::quit() //quit()
|
||||
{
|
||||
quitExecution = true;
|
||||
}
|
||||
|
||||
void SoundInThread::setNetwork(bool b) //setNetwork()
|
||||
{
|
||||
m_net = b;
|
||||
}
|
||||
|
||||
void SoundInThread::setMonitoring(bool b) //setMonitoring()
|
||||
{
|
||||
m_monitoring = b;
|
||||
}
|
||||
|
||||
void SoundInThread::setForceCenterFreqBool(bool b)
|
||||
{
|
||||
m_bForceCenterFreq=b;
|
||||
|
||||
}
|
||||
|
||||
void SoundInThread::setForceCenterFreqMHz(double d)
|
||||
{
|
||||
m_dForceCenterFreq=d;
|
||||
}
|
||||
|
||||
void SoundInThread::setNrx(int n) //setNrx()
|
||||
{
|
||||
m_nrx = n;
|
||||
}
|
||||
|
||||
int SoundInThread::nrx()
|
||||
{
|
||||
return m_nrx;
|
||||
}
|
||||
|
||||
int SoundInThread::mhsym()
|
||||
{
|
||||
return m_hsym;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------- inputUDP()
|
||||
void SoundInThread::inputUDP()
|
||||
{
|
||||
udpSocket = new QUdpSocket();
|
||||
if(!udpSocket->bind(m_udpPort,QUdpSocket::ShareAddress) )
|
||||
{
|
||||
emit error(tr("UDP Socket bind failed."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Set this socket's total buffer space for received UDP packets
|
||||
int v=141600;
|
||||
::setsockopt(udpSocket->socketDescriptor(), SOL_SOCKET, SO_RCVBUF,
|
||||
(char *)&v, sizeof(v));
|
||||
|
||||
bool qe = quitExecution;
|
||||
struct linradBuffer {
|
||||
double cfreq;
|
||||
int msec;
|
||||
float userfreq;
|
||||
int iptr;
|
||||
quint16 iblk;
|
||||
qint8 nrx;
|
||||
char iusb;
|
||||
double d8[174];
|
||||
} b;
|
||||
|
||||
int n60z=99;
|
||||
int k=0;
|
||||
int nsec;
|
||||
int n60;
|
||||
int nhsym0=0;
|
||||
int iz=174;
|
||||
int nBusy=0;
|
||||
|
||||
// Main loop for input of UDP packets over the network:
|
||||
while (!qe) {
|
||||
qe = quitExecution;
|
||||
if (qe) break;
|
||||
if (!udpSocket->hasPendingDatagrams()) {
|
||||
msleep(2); // Sleep if no packet available
|
||||
} else {
|
||||
int nBytesRead = udpSocket->readDatagram((char *)&b,1416);
|
||||
if (nBytesRead != 1416) qDebug() << "UDP Read Error:" << nBytesRead;
|
||||
|
||||
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
|
||||
nsec = ms/1000; // Time according to this computer
|
||||
n60 = nsec % 60;
|
||||
|
||||
// Reset buffer pointer and symbol number at start of minute
|
||||
if(n60 < n60z) {
|
||||
k=0;
|
||||
nhsym0=0;
|
||||
}
|
||||
n60z=n60;
|
||||
|
||||
if(m_monitoring) {
|
||||
m_nrx=b.nrx;
|
||||
if(m_nrx == +1) iz=348; //One RF channel, i*2 data
|
||||
if(m_nrx == -1 or m_nrx == +2) iz=174; //One Rf channel, r*4 data
|
||||
// or 2 RF channels, i*2 data
|
||||
if(m_nrx == -2) iz=87; // Two RF channels, r*4 data
|
||||
|
||||
// If buffer will not overflow, move data into datcom_
|
||||
if ((k+iz) <= 60*96000) {
|
||||
int nsam=-1;
|
||||
recvpkt_(&nsam, &b.iblk, &b.nrx, &k, b.d8, b.d8, b.d8);
|
||||
if(m_bForceCenterFreq) {
|
||||
datcom_.fcenter=m_dForceCenterFreq;
|
||||
} else {
|
||||
datcom_.fcenter=b.cfreq + m_fAdd;
|
||||
}
|
||||
}
|
||||
|
||||
m_hsym=(k-2048)*11025.0/(2048.0*m_rate);
|
||||
if(m_hsym != nhsym0) {
|
||||
if(m_dataSinkBusy) {
|
||||
nBusy++;
|
||||
} else {
|
||||
m_dataSinkBusy=true;
|
||||
emit readyForFFT(k); //Signal to compute new FFTs
|
||||
}
|
||||
nhsym0=m_hsym;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete udpSocket;
|
||||
}
|
||||
|
15
soundin.h
15
soundin.h
@ -2,7 +2,6 @@
|
||||
#define SOUNDIN_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtNetwork/QUdpSocket>
|
||||
#include <QDebug>
|
||||
#include <valarray>
|
||||
|
||||
@ -35,19 +34,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void setSwapIQ(bool b);
|
||||
void set10db(bool b);
|
||||
void setPort(qint32 n);
|
||||
void setInputDevice(qint32 n);
|
||||
void setRate(double rate);
|
||||
void setBufSize(unsigned bufSize);
|
||||
void setNetwork(bool b);
|
||||
void setMonitoring(bool b);
|
||||
void setFadd(double x);
|
||||
void setNrx(int n);
|
||||
void setForceCenterFreqBool(bool b);
|
||||
void setForceCenterFreqMHz(double d);
|
||||
int nrx();
|
||||
int mhsym();
|
||||
|
||||
signals:
|
||||
@ -60,7 +48,6 @@ public slots:
|
||||
void quit();
|
||||
|
||||
private:
|
||||
void inputUDP();
|
||||
|
||||
double m_fAdd;
|
||||
bool m_net;
|
||||
@ -72,9 +59,7 @@ private:
|
||||
qint32 m_nrx;
|
||||
qint32 m_hsym;
|
||||
qint32 m_nDevIn;
|
||||
qint32 m_udpPort;
|
||||
|
||||
QUdpSocket *udpSocket;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
Loading…
Reference in New Issue
Block a user