diff options
Diffstat (limited to 'map65/soundin.cpp')
| -rw-r--r-- | map65/soundin.cpp | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/map65/soundin.cpp b/map65/soundin.cpp index ff233d20..ee1886e8 100644 --- a/map65/soundin.cpp +++ b/map65/soundin.cpp @@ -10,7 +10,6 @@ #include <sys/socket.h> #endif -#define NFFT 32768 #define FRAMES_PER_BUFFER 1024 #include <portaudio.h> @@ -50,6 +49,7 @@ extern "C" int a2dCallback(const void* inputBuffer, void* outputBuffer, } if (udata->bzero) { // Start of a new minute + advance_live_input_generation(); udata->kin = 0; // Reset buffer pointer udata->bzero = false; } @@ -114,6 +114,14 @@ extern "C" int a2dCallback(const void* inputBuffer, void* outputBuffer, namespace { + constexpr int symspecLookaheadSamples = 512; + + int symspecReadyPointer(int acquiredSamples) + { + // symspec's final 1024-sample window extends one 512-sample hop past k. + return acquiredSamples - symspecLookaheadSamples; + } + struct COMWrapper { explicit COMWrapper () @@ -173,7 +181,7 @@ void SoundInThread::run() //SoundInThread::run() inParam.suggestedLatency=device_info->defaultHighInputLatency; inParam.hostApiSpecificStreamInfo=NULL; - paerr=Pa_IsFormatSupported(&inParam,NULL,96000.0); + paerr=Pa_IsFormatSupported(&inParam,NULL,double(g_sampleRate)); if(paerr<0) { QString error_message; if (paUnanticipatedHostError == paerr) @@ -191,7 +199,7 @@ void SoundInThread::run() //SoundInThread::run() &inStream, &inParam, NULL, - 96000.0, + double(g_sampleRate), FRAMES_PER_BUFFER, paClipOff, a2dCallback, @@ -208,47 +216,44 @@ void SoundInThread::run() //SoundInThread::run() int k=0; int nsec; int ntr; - int nhsym0=0; + Map65HalfSymbolScheduler spectrumScheduler; //---------------------------------------------- Soundcard input loop while (!qe) { qe = quitExecution; if (qe) break; + qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000; - nsec = ms/1000; // Time according to this computer + nsec = ms/1000; ntr = nsec % m_TRperiod; -// Reset buffer pointer and symbol number at start of minute if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) { - nhsym0=0; + spectrumScheduler.reset (); udata.bzero=true; m_TRperiod0=m_TRperiod; } + k=udata.kin; + udata.iqswap= (m_IQswap != 0); udata.dB=m_dB; + if(m_monitoring) { - double fcenter; - if(m_bForceCenterFreq) { - fcenter = m_dForceCenterFreq; - } else { - fcenter = 144.125; // default center - } + double fcenter = m_bForceCenterFreq ? m_dForceCenterFreq : 144.125; set_fcenter(fcenter); - m_hsym=(k-2048)*11025.0/(2048.0*m_rate); - if(m_hsym != nhsym0) { - if(m_dataSinkBusy) { - } else { - m_dataSinkBusy=true; - emit readyForFFT(k); //Signal to compute new FFTs - } - nhsym0=m_hsym; + int const fftPointer=symspecReadyPointer(k); + m_hsym=(fftPointer-2048)*11025.0/(2048.0*m_rate); + + if (spectrumScheduler.claim_next (m_hsym, m_dataSinkBusy)) { + emit readyForFFT(fftPointer); } } + msleep(100); ntr0=ntr; } + Pa_StopStream(inStream); Pa_CloseStream(inStream); } @@ -304,12 +309,15 @@ void SoundInThread::setNetwork(bool b) //setNetwork() void SoundInThread::setMonitoring(bool b) //setMonitoring() { m_monitoring = b; + qDebug() << "m_monitoring set to" << m_monitoring << "at" << Q_FUNC_INFO; + } void SoundInThread::setForceCenterFreqBool(bool b) { m_bForceCenterFreq=b; + } void SoundInThread::setForceCenterFreqMHz(double d) @@ -368,7 +376,7 @@ void SoundInThread::inputUDP() int k=0; int nsec; int ntr; - int nhsym0=0; + Map65HalfSymbolScheduler spectrumScheduler; int iz=174; // Main loop for input of UDP packets over the network: @@ -390,8 +398,9 @@ void SoundInThread::inputUDP() // Reset buffer pointer and symbol number at start of minute if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) { + advance_live_input_generation(); k=0; - nhsym0=0; + spectrumScheduler.reset (); m_TRperiod0=m_TRperiod; } ntr0=ntr; @@ -404,7 +413,7 @@ void SoundInThread::inputUDP() 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) { + if ((k + iz) <= 60 * m_rate) { int nsam=-1; recvpkt_(&nsam, &b.iblk, &b.nrx, &k, b.d8, b.d8, b.d8); double fcenter; @@ -416,18 +425,11 @@ void SoundInThread::inputUDP() set_fcenter(fcenter); } -m_hsym = (k-2048)*11025.0/(2048.0*m_rate); -if (m_hsym != nhsym0) { - if (m_dataSinkBusy) { - } else { - m_dataSinkBusy = true; - - QDateTime now = QDateTime::currentDateTime(); - QString ts = now.toString("yyyy-MM-dd hh:mm:ss.zzz"); - - emit readyForFFT(k); - } - nhsym0 = m_hsym; +double hsym = 2048.0 * m_rate / 11025.0; +int const fftPointer=symspecReadyPointer(k); +m_hsym = (fftPointer - 2048) / hsym; +if (spectrumScheduler.claim_next (m_hsym, m_dataSinkBusy)) { + emit readyForFFT(fftPointer); } } |
