summaryrefslogtreecommitdiff
path: root/Modulator.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2019-06-02 22:17:11 +0200
committerChristoph Berg <myon@debian.org>2019-06-02 22:17:11 +0200
commit851b658298afb9bafeda98ffbfa2ade612c656be (patch)
tree826d54e9dac4ce15fdd1b6af3360eeba7993a7d2 /Modulator.cpp
parentb7238399ea4f1ca51d8f7b8f9220af3da0913edf (diff)
New upstream version 2.1.0~rc6+repackupstream/2.1.0_rc6+repack
Diffstat (limited to 'Modulator.cpp')
-rw-r--r--Modulator.cpp52
1 files changed, 22 insertions, 30 deletions
diff --git a/Modulator.cpp b/Modulator.cpp
index 725de9e4..4d017177 100644
--- a/Modulator.cpp
+++ b/Modulator.cpp
@@ -25,15 +25,15 @@ double constexpr Modulator::m_twoPi;
// unsigned m_nspd=1.2*48000.0/wpm;
// m_nspd=3072; //18.75 WPM
-Modulator::Modulator (unsigned frameRate, unsigned periodLengthInSeconds,
+Modulator::Modulator (unsigned frameRate, double periodLengthInSeconds,
QObject * parent)
: AudioDevice {parent}
, m_quickClose {false}
, m_phi {0.0}
, m_toneSpacing {0.0}
, m_fSpread {0.0}
- , m_frameRate {frameRate}
, m_period {periodLengthInSeconds}
+ , m_frameRate {frameRate}
, m_state {Idle}
, m_tuning {false}
, m_cwLevel {false}
@@ -45,19 +45,15 @@ Modulator::Modulator (unsigned frameRate, unsigned periodLengthInSeconds,
void Modulator::start (unsigned symbolsLength, double framesPerSymbol,
double frequency, double toneSpacing,
SoundOutput * stream, Channel channel,
- bool synchronize, bool fastMode, double dBSNR, int TRperiod)
+ bool synchronize, bool fastMode, double dBSNR, double TRperiod)
{
Q_ASSERT (stream);
// Time according to this computer which becomes our base time
qint64 ms0 = QDateTime::currentMSecsSinceEpoch() % 86400000;
+ unsigned mstr = ms0 % int(1000.0*m_period); // ms into the nominal Tx start time
-// qDebug() << "ModStart" << symbolsLength << framesPerSymbol
-// << frequency << toneSpacing;
-
- if(m_state != Idle) stop ();
-
+ if(m_state != Idle) stop();
m_quickClose = false;
-
m_symbolsLength = symbolsLength;
m_isym0 = std::numeric_limits<unsigned>::max (); // big number
m_frequency0 = 0.;
@@ -69,37 +65,33 @@ void Modulator::start (unsigned symbolsLength, double framesPerSymbol,
m_toneSpacing = toneSpacing;
m_bFastMode=fastMode;
m_TRperiod=TRperiod;
- unsigned delay_ms = 1920 == m_nsps && 15 == m_period ? 500 : 1000;
+ unsigned delay_ms=1000;
+ if(m_nsps==1920) delay_ms=500; //FT8
+ if(m_nsps==576) delay_ms=300; //FT4
- // noise generator parameters
+// noise generator parameters
if (m_addNoise) {
m_snr = qPow (10.0, 0.05 * (dBSNR - 6.0));
m_fac = 3000.0;
if (m_snr > 1.0) m_fac = 3000.0 / m_snr;
}
- unsigned mstr = ms0 % (1000 * m_period); // ms in period
-
- // round up to an exact portion of a second that allows for startup
- // delays
+// round up to an exact portion of a second that allows for startup delays
m_ic = (mstr / delay_ms) * m_frameRate * delay_ms / 1000;
if(m_bFastMode) m_ic=0;
m_silentFrames = 0;
- // calculate number of silent frames to send, so that audio will start at
- // the nominal time "delay_ms" into the Tx sequence.
+// calculate number of silent frames to send, so that audio will start at
+// the nominal time "delay_ms" into the Tx sequence.
if (synchronize && !m_tuning && !m_bFastMode) {
m_silentFrames = m_ic + m_frameRate / (1000 / delay_ms) - (mstr * (m_frameRate / 1000));
}
- if(symbolsLength==105 and framesPerSymbol==512
- and (toneSpacing==12000.0/512.0 or toneSpacing==-2.0)) {
-//### FT4 parameters
- m_ic=0;
- m_silentFrames=0;
- }
-// qDebug() << "Mod AA" << symbolsLength << framesPerSymbol << toneSpacing;
-// qDebug() << "Mod AB" << delay_ms << mstr << m_ic << m_silentFrames;
+
+// qDebug() << "aa" << QDateTime::currentDateTimeUtc().toString("hh:mm:ss.zzz")
+// << m_ic << m_silentFrames << m_silentFrames/48000.0
+// << mstr << fmod(double(ms0),1000.0*m_period);
+
initialize (QIODevice::ReadOnly, channel);
Q_EMIT stateChanged ((m_state = (synchronize && m_silentFrames) ?
@@ -183,12 +175,12 @@ qint64 Modulator::readData (char * data, qint64 maxSize)
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;
+ if(m_TRperiod==3.0) slowCwId=false;
bool fastCwId=false;
static bool bCwId=false;
qint64 ms = QDateTime::currentMSecsSinceEpoch();
- float tsec=0.001*(ms % (1000*m_TRperiod));
- if(m_bFastMode and (icw[0]>0) and (tsec>(m_TRperiod-5.0))) fastCwId=true;
+ float tsec=0.001*(ms % int(1000*m_TRperiod));
+ 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;
@@ -259,7 +251,7 @@ qint64 Modulator::readData (char * data, qint64 maxSize)
i1= m_symbolsLength * 4.0 * m_nsps;
}
if(m_bFastMode and !m_tuning) {
- i1=m_TRperiod*48000 - 24000;
+ i1=m_TRperiod*48000.0 - 24000.0;
i0=i1-816;
}
@@ -267,7 +259,7 @@ qint64 Modulator::readData (char * data, qint64 maxSize)
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.0) 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) {