From fd239d9c072ca3028bcf75c0803054b29cec2739 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Tue, 2 Apr 2019 11:39:28 -0400 Subject: [PATCH] Clean up some timing issues with time-synchronized FT4. --- Modulator.cpp | 31 +++++++++++++++---------------- widgets/mainwindow.cpp | 26 ++++++++++++-------------- widgets/mainwindow.h | 2 +- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Modulator.cpp b/Modulator.cpp index 8811d16a3..725de9e42 100644 --- a/Modulator.cpp +++ b/Modulator.cpp @@ -92,11 +92,9 @@ void Modulator::start (unsigned symbolsLength, double framesPerSymbol, if (synchronize && !m_tuning && !m_bFastMode) { m_silentFrames = m_ic + m_frameRate / (1000 / delay_ms) - (mstr * (m_frameRate / 1000)); } - if((symbolsLength==103 or symbolsLength==105) and framesPerSymbol==512 + if(symbolsLength==105 and framesPerSymbol==512 and (toneSpacing==12000.0/512.0 or toneSpacing==-2.0)) { //### FT4 parameters - delay_ms=100; - mstr=5000; m_ic=0; m_silentFrames=0; } @@ -159,6 +157,8 @@ qint64 Modulator::readData (char * data, qint64 maxSize) qint16 * end (samples + numFrames * (bytesPerFrame () / sizeof (qint16))); qint64 framesGenerated (0); +// if(m_ic==0) qDebug() << "Modulator::readData" << 0.001*(QDateTime::currentMSecsSinceEpoch() % (1000*m_TRperiod)); + switch (m_state) { case Synchronizing: @@ -180,8 +180,7 @@ qint64 Modulator::readData (char * data, qint64 maxSize) case Active: { unsigned int isym=0; -// qDebug() << "Mod A" << m_toneSpacing << m_frequency << m_nsps -// << m_ic << m_symbolsLength << icw[0]; + if(!m_tuning) isym=m_ic/(4.0*m_nsps); // Actual fsample=48000 bool slowCwId=((isym >= m_symbolsLength) && (icw[0] > 0)) && (!m_bFastMode); if(m_TRperiod==3) slowCwId=false; @@ -192,6 +191,8 @@ qint64 Modulator::readData (char * data, qint64 maxSize) if(m_bFastMode and (icw[0]>0) and (tsec>(m_TRperiod-5.0))) fastCwId=true; if(!m_bFastMode) m_nspd=2560; // 22.5 WPM +// qDebug() << "Mod A" << m_ic << isym << tsec; + if(slowCwId or fastCwId) { // Transmit CW ID? m_dphi = m_twoPi*m_frequency/m_frameRate; if(m_bFastMode and !bCwId) { @@ -263,10 +264,10 @@ qint64 Modulator::readData (char * data, qint64 maxSize) } qint16 sample; + for (unsigned i = 0; i < numFrames && m_ic <= i1; ++i) { isym=0; - if(!m_tuning and m_TRperiod!=3) isym=m_ic / (4.0 * m_nsps); //Actual - //fsample=48000 + if(!m_tuning and m_TRperiod!=3) isym=m_ic/(4.0*m_nsps); //Actual fsample=48000 if(m_bFastMode) isym=isym%m_symbolsLength; if (isym != m_isym0 || m_frequency != m_frequency0) { if(itone[0]>=100) { @@ -278,8 +279,6 @@ qint64 Modulator::readData (char * data, qint64 maxSize) m_toneFrequency0=m_frequency + itone[isym]*m_toneSpacing; } } -// qDebug() << "Mod B" << m_bFastMode << m_ic << numFrames << isym << itone[isym] -// << m_toneFrequency0 << m_nsps; m_dphi = m_twoPi * m_toneFrequency0 / m_frameRate; m_isym0 = isym; m_frequency0 = m_frequency; //??? @@ -302,10 +301,10 @@ qint64 Modulator::readData (char * data, qint64 maxSize) sample=qRound(m_amp*qSin(m_phi)); //Here's where we transmit from a precomputed wave[] array: - if(!m_tuning and (m_toneSpacing < 0)) sample=qRound(m_amp*foxcom_.wave[m_ic]); -// if(m_ic < 10) qDebug() << "Mod Tx" << m_ic << m_amp -// << foxcom_.wave[m_ic] << sample -// << m_toneSpacing; + if(!m_tuning and (m_toneSpacing < 0)) { + m_amp=32767.0; + sample=qRound(m_amp*foxcom_.wave[m_ic]); + } samples = load(postProcessSample(sample), samples); ++framesGenerated; @@ -322,9 +321,9 @@ qint64 Modulator::readData (char * data, qint64 maxSize) } m_frequency0 = m_frequency; - // done for this chunk - continue on next call -// qint64 ms1=QDateTime::currentMSecsSinceEpoch() - m_ms0; -// if(m_ic>=4*144*160) qDebug() << "Modulator finished" << m_ic << 0.001*ms1; +// done for this chunk - continue on next call + +// qDebug() << "Mod B" << m_ic << i1 << 0.001*(QDateTime::currentMSecsSinceEpoch() % (1000*m_TRperiod)); while (samples != end) // pad block with silence { diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index ae580e19c..9d0585ebd 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -1331,7 +1331,7 @@ void MainWindow::fixStop() } else if (m_mode=="FT8") { m_hsymStop=50; } else if (m_mode=="FT4") { - m_hsymStop=17; + m_hsymStop=18; } } @@ -1340,8 +1340,7 @@ void MainWindow::dataSink(qint64 frames) { static float s[NSMAX]; char line[80]; - - int k (frames); + int k(frames); QString fname {QDir::toNativeSeparators(m_config.writeable_data_dir ().absoluteFilePath ("refspec.dat"))}; QByteArray bafname = fname.toLatin1(); const char *c_fname = bafname.data(); @@ -3396,7 +3395,7 @@ void MainWindow::guiUpdate() if(m_TRperiod==0) m_TRperiod=60; txDuration=0.0; - if(m_modeTx=="FT4") txDuration=0.25 + 103*512/12000.0; // FT4 + if(m_modeTx=="FT4") txDuration=0.35 + 105*512/12000.0; // FT4 if(m_modeTx=="FT8") txDuration=1.0 + 79*1920/12000.0; // FT8 if(m_modeTx=="JT4") txDuration=1.0 + 207.0*2520/11025.0; // JT4 if(m_modeTx=="JT9") txDuration=1.0 + 85.0*m_nsps/12000.0; // JT9 @@ -5650,7 +5649,7 @@ void MainWindow::on_actionFT4_triggered() m_nsps=6912; m_FFTSize = m_nsps/2; Q_EMIT FFTSize (m_FFTSize); - m_hsymStop=17; + m_hsymStop=18; setup_status_bar (bVHF); m_toneSpacing=12000.0/512.0; ui->actionFT4->setChecked(true); @@ -6787,18 +6786,17 @@ void MainWindow::setFreq4(int rxFreq, int txFreq) void MainWindow::handle_transceiver_update (Transceiver::TransceiverState const& s) { - // qDebug () << "MainWindow::handle_transceiver_update:" << s; Transceiver::TransceiverState old_state {m_rigState}; //transmitDisplay (s.ptt ()); - if (s.ptt () && !m_rigState.ptt ()) // safe to start audio - // (caveat - DX Lab Suite Commander) - { - if (m_tx_when_ready && g_iptt) // waiting to Tx and still needed - { - ptt1Timer.start(1000 * m_config.txDelay ()); //Start-of-transmission sequencer delay - } - m_tx_when_ready = false; + if (s.ptt () && !m_rigState.ptt ()) { // safe to start audio + // (caveat - DX Lab Suite Commander) + if (m_tx_when_ready && g_iptt) { // waiting to Tx and still needed + int ms_delay=1000*m_config.txDelay(); + if(m_mode=="FT4") ms_delay=20; + ptt1Timer.start(ms_delay); //Start-of-transmission sequencer delay } + m_tx_when_ready = false; + } m_rigState = s; auto old_freqNominal = m_freqNominal; if (!old_freqNominal) diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h index 79285522c..174642d8e 100644 --- a/widgets/mainwindow.h +++ b/widgets/mainwindow.h @@ -46,7 +46,7 @@ #define NUM_MSK144_SYMBOLS 144 //s8 + d48 + s8 + d80 #define NUM_QRA64_SYMBOLS 84 //63 data + 21 sync #define NUM_FT8_SYMBOLS 79 -#define NUM_FT4_SYMBOLS 103 +#define NUM_FT4_SYMBOLS 105 #define NUM_CW_SYMBOLS 250 #define TX_SAMPLE_RATE 48000 #define N_WIDGETS 33