2013-08-07 19:09:13 -04:00
|
|
|
#include "Modulator.hpp"
|
|
|
|
#include <limits>
|
|
|
|
#include <qmath.h>
|
|
|
|
#include <QDateTime>
|
2020-06-13 11:04:41 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
#include <QRandomGenerator>
|
|
|
|
#endif
|
2013-08-07 19:09:13 -04:00
|
|
|
#include <QDebug>
|
2018-11-07 12:49:45 -05:00
|
|
|
#include "widgets/mainwindow.h" // TODO: G4WJS - break this dependency
|
2019-07-02 13:45:05 -04:00
|
|
|
#include "Audio/soundout.h"
|
2017-11-21 15:06:58 -05:00
|
|
|
#include "commons.h"
|
2013-08-07 19:09:13 -04:00
|
|
|
|
Added support for use of "Standard" locations for writable files.
This allows writable files to be located in the "correct"
location for each platform rather than in the directory of
the executable which, in general, is not recommended or
allowed in some cases.
A preprocessor macro WSJT_STANDARD_FILE_LOCATIONS is used to
switch be tween old and new functionality, currently it is on
by default. It can be turned off by defining it to a false
value (0) or more simply with cmake-gui setting the option
with the same name. JTAlert can only work with the old
non-standard file locations until Laurie VK3AMA chooses to
support the new file locations.
Even if the above is not enabled; the QSettings file is
written to a user specific location so it will be shared by
all instances of the program (i.e. across upgrades). See
below for multiple concurrent instance support changes.
Added a command line parser module for Fortran.
Added 'lib/options.f90' to facilitate more complex argument
passing to jt9 to cover explicit file locations.
Changed the way multiple concurrent instances are handled.
This is to allow the program to be run multiple times from
the same installation directory.
A new wsjtx command line optional argument is available "-r"
or "--rig" which enables multiple concurrent instance
support. The parameter of the new option is a unique name
signifying a rig or equivalent. The name is used as the
shared memory segment key and in window titles. The name is
also used to access unique settings files and writable data
files like ALL.TXT and log files. No attempt has been made
to share these files between concurrent instances.
If "-r" or "--rig" is used without a parameter it still
enables multiple concurrent instance support for that
instance. All instances must use a unique parameter, one of
which may be empty.
The rig name is appended the
QCoreApplication::applicationName() for convenient usage like
window titles.
Set non Qt locale to "C".
This ensures that C library functions give consistent results
whatever the system locale is set to. QApplication follows
the system locale as before. Thus using QApplication and its
descendants like widgets and QString for all user visible
formating will give correct l10n and using C/C++ library will
give consistent formatting across locales.
Added top level C++ exception handling to main.cpp.
Because the new transceiver framework uses exceptions
internally, the main function now handles any exceptions that
aren't caught.
Retired devsetup, replaced with Configuration.
Configuration is a class that encapsulates most of the
configuration behavior. Because rig configuration is so
closely coupled with rig operation, Configuration serves as a
proxy for access to the rig control functions. See
Configuration.hpp for more details of the Configuration
interface.
Menu changes.
Various checkable menu actions moved from main menu to the
Configuration dialog. The whole settings menu has been
retired with the single "Settings..." action moved to the
file menu for consistency on Mac where it appears as
"Preferences" in line with Mac guidelines.
New data models for data used by the application.
ADIF amateur band parameters, free text message macros, spot
working frequencies and, station information (station
descriptions and transverter offsets per band) each implement
the QAbstractItemModel interface allowing them to be used
directly with Qt view widgets (Bands.hpp, FrequencyList.hpp
and, StationList.hpp). Configuration manages maintenance of
an instance of all but the former of the above models. The
ADIF band model is owned by Configuration but requires no
user maintenance as it is immutable.
Band combo box gets more functionality.
This widget is now an editable QComboBox with some extra
input capabilities.
The popup list is still the list of spot working frequencies,
now showing the actual frequency decorated with the band
name. This allows multiple spot frequencies on a band if
required.
The line edit allows direct frequency entry in mega-Hertz
with a completer built in to suggest the available spot
working frequencies. It also allows band name entry where
the first available spot working frequency is selected.
Recognized band names are those that are defined by the ADIF
specification and can be found in in the implementation of
the ADIF bands model (Bands.cpp).
If an out of band frequency is chosen, the line edit shows a
warning red background and the text "OOB". Out of band is
only defined by the ADIF band limits which in general are
wider than any entities regulations.
Qt 5.2 now supports default audio i/p and o/p devices.
These devices are placeholders for whatever the user defines
as the default device. Because of this they need special
treatment as the actual device used is chosen at open time
behind the scenes.
Close-down behavior is simplified.
The close-down semantics were broken such that some objects
were not being shut down cleanly, this required amendments to
facilitate correct close down of threads.
User font selection added to Configuration UI.
Buttons to set the application font and the font for the band
and Rx frequency activity widgets have been added to the
Configuration UI to replace the file based font size control.
Free text macros now selected directly.
The free text line edit widgets are now editable combo boxes
that have the current free text macro definitions as their
popup list. The old context menu to do this has been
retired.
Astronomical data window dynamically formatted and has font a chooser.
This window is now autonomous, has its own font chooser and,
dynamically resizes to cover the contents.
Double click to Tx enabled now has its own widget in the status bar.
QDir used for portable path and file name handling throughout.
The "Monitor", "Decode", "Enable Tx" and, "Tune" buttons are now
checkable.
Being checkable allows these buttons control their own state
and rendering.
Calls to PSK Reporter interface simplified.
In mainwindow.cpp the calls to this interface are
rationalized to just 3 locations.
Manipulation of ALL.TXT simplified.
Moved, where possible, to common functions.
Elevated frequency types to be Qt types.
Frequency and FrequencyDelta defined as Qt types in their
meta-type system (Radio.hpp). They are integral types for
maximum accuracy.
Re-factored rig control calls in mainwindow.cpp.
The new Configuration proxy access to rig control required
many changes (mostly simplifications) to the MainWindow rig
control code. Some common code has been gathered in member
functions like qsy(), monitor(), band_changed() and
auto_tx_mode().
Rig control enhancements.
The rig control for clients interface is declared as an
abstract interface (See Transceiver.hpp). Concrete
implementations of this interface are provided for the Hamlib
rig control library, DX Lab Suite Commander via a TCP/IP
command channel, Ham Radio Deluxe also via a TCP/IP command
channel and, OmniRig via its Windows COM server interface.
Concrete Transceiver implementations are expected to be moved
to a separate thread after construction since many operations
are blocking and not suitable for running in a GUI thread.
To facilitate this all instantiation of concrete Transceiver
instances are handled by Configuration using a factory class
(TransceiverFactory) for configuration parameter based
instantiation.
Various common functionality shared by different rig
interface implementations are factored out into helper base
classes that implement or delegate parts of the Transceiver
interface. They are TransceiverBase which caches state to
minimize expensive rig commands, it also maps the Transceiver
interface into a more convenient form for implementation
(template methods). PollingTransceiver that provides a state
polling mechanism that only reports actual changes.
EmulateSplitTransceiver that provides split operation by
QSYing on PTT state changes.
EmulateSplitTransceiver can be used with any implementation
as it follows the GoF Decorator pattern and can wrap any
Transceiver implementation.
OmniRigTransceiver is derived directly from TransceiverBase
since it doesn't require polling due to its asynchronous
nature. OmniRigTransceiver is only built on Windows as it is
a COM server client. To build it you must first install the
OmniRig client on the development machine
(http://www.dxatlas.com/omnirig/).
DXLabSuiteCommanderTransceiver derives from
PollingTransceiver since it is a synchronous communications
channel. No third party library is required for this
interface.
HRDTransceiver also derives from PollingTransceiver. The HRD
interface library has been reverse engineered to provide
functionality with all available versions of HRD. No third
party libraries are required.
HamlibTransceiver likewise derives from PollingTransceiver
since the Hamlib asynchronous interface is non-functional.
Although this class will interface with the release version
of Hamlib (1.2.15.3); for correct operation on most rigs it
needs to run with the latest master branch code of Hamlib.
During development many changes to Hamlib have been submitted
and accepted, hence this requirement. Hamlib source can be
obtained from git://git.code.sf.net/p/hamlib/code and at the
time of writing he master branch was at SHA 6e4432.
The Hamlib interface directly calls the "C" interface and the
modified rigclass.{h,cpp} files have been retired.
There is a rig type selection of "None" which may be used for
non-CAT rigs, this is actually a connection to the dummy
Hamlib device.
PollingTransvceiver derives from TransceiverBase and
TransceiverBase derives from the Transceiver interface.
Each interface implementation offers some possibility of PTT
control via a different serial port than the CAT port. We
also support PTT control directly via a second serial port.
This is done by delegating to a dummy Hamlib instance which
is only used for PTT control. This means that
DXLabSuiteCommanderTransceiver, HRDTransceiver and
OmniRigTransceiver always wrap a dummy HamlibTransceiver
instance. The factory class TransceiverFactory manages all
these constructional complexities.
Serial port selection combo boxes are now editable with a
manually entered value being saved to the settings file.
This allows a non-standard port device to be used without
having to edit the settings file manually.
For TCP/IP network CAT interfaces; the network address and
port may be specified allowing the target device to be
located on a different machine from the one running wsjtx if
required. The default used when the address field is left
blank is the correct one for normal usage on the local host.
Selecting a polling interval of zero is no longer possible,
this is because the rig control capability can no longer
support one way connection. This is in line with most other
CAT control software.
In the Configuration dialog there are options to select split
mode control by the software and mode control by the
software. For the former "None", "Rig" and "Fake it" are
available, for the latter "None", "USB" and, "Data" are
available. Because tone generation is implicitly linked to
split mode operation; it is no longer possible to have the
software in split mode and the rig not or vice versa. This
may mean some rigs cannot be used in split mode and therefore
not in dual JT65+JT9 until issues with CAT control with that
rig are resolved. Single mode with VOX keying and no CAT
control are still possible so even the most basic transceiver
setup is supported as before.
Configuration now supports a frequency offset suitable for
transverter operation. The station details model
(StationList.hpp) includes a column to store an offset for
each band if required.
CMake build script improvements.
The CMakeLists.txt from the 'lib' directory has been retired
with its contents merged into the top level CMakeLists.txt.
Install target support has been greatly improved with the
Release build configuration now building a fully standalone
installation on Mac and Windows. The Debug configuration
still builds an installation that has environment
dependencies for external libraries, which is desirable for
testing and debugging.
Package target support is largely complete for Mac, Windows
and, Linux, it should be possible to build release installers
directly from CMake/CPack.
Cmake FindXXXX.cmake modules have been added to improve the
location of fftw-3 and Hamlib packages.
Version numbers are now stored in Versions.cmake and work in
concert with automatic svn revision lookup during build. The
version string becomes 'rlocal'± if there are any uncommitted
changes in the build source tree.
Moved resource like files to Qt resources.
Because location of resource files (when they cannot go into
the installation directory because of packaging rules) is
hard to standardize. I have used the Qt resource system for
all ancillary data files. Some like kvasd.dat are dumped out
to the temp (working directory) because they are accessed by
an external program, others like the audio samples are copied
out so they appear in the data directory under the default
save directory.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3929 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2014-03-26 09:21:00 -04:00
|
|
|
#include "moc_Modulator.cpp"
|
|
|
|
|
|
|
|
extern float gran(); // Noise generator (for tests only)
|
|
|
|
|
2014-03-05 13:20:40 -05:00
|
|
|
#define RAMP_INCREMENT 64 // MUST be an integral factor of 2^16
|
2013-08-10 11:29:55 -04:00
|
|
|
|
|
|
|
#if defined (WSJT_SOFT_KEYING)
|
2014-04-06 17:58:11 -04:00
|
|
|
# define SOFT_KEYING WSJT_SOFT_KEYING
|
2013-08-10 11:29:55 -04:00
|
|
|
#else
|
2014-04-11 18:50:34 -04:00
|
|
|
# define SOFT_KEYING 1
|
2013-08-10 11:29:55 -04:00
|
|
|
#endif
|
|
|
|
|
2016-04-30 20:40:51 -04:00
|
|
|
double constexpr Modulator::m_twoPi;
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
// float wpm=20.0;
|
|
|
|
// unsigned m_nspd=1.2*48000.0/wpm;
|
|
|
|
// m_nspd=3072; //18.75 WPM
|
|
|
|
|
2019-05-22 12:44:28 -04:00
|
|
|
Modulator::Modulator (unsigned frameRate, double periodLengthInSeconds,
|
2015-05-27 09:08:28 -04:00
|
|
|
QObject * parent)
|
2014-04-03 15:29:13 -04:00
|
|
|
: AudioDevice {parent}
|
2014-04-06 17:58:11 -04:00
|
|
|
, m_quickClose {false}
|
2014-04-03 15:29:13 -04:00
|
|
|
, m_phi {0.0}
|
2014-04-08 07:56:29 -04:00
|
|
|
, m_toneSpacing {0.0}
|
|
|
|
, m_fSpread {0.0}
|
2014-04-03 15:29:13 -04:00
|
|
|
, m_period {periodLengthInSeconds}
|
2019-05-23 13:24:35 -04:00
|
|
|
, m_frameRate {frameRate}
|
2014-04-03 15:29:13 -04:00
|
|
|
, m_state {Idle}
|
|
|
|
, m_tuning {false}
|
2014-04-06 17:58:11 -04:00
|
|
|
, m_cwLevel {false}
|
2016-04-30 20:40:51 -04:00
|
|
|
, m_j0 {-1}
|
|
|
|
, m_toneFrequency0 {1500.0}
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-29 14:47:46 -04:00
|
|
|
void Modulator::start (QString mode, unsigned symbolsLength, double framesPerSymbol,
|
2015-05-29 15:23:54 -04:00
|
|
|
double frequency, double toneSpacing,
|
2015-05-27 09:08:28 -04:00
|
|
|
SoundOutput * stream, Channel channel,
|
2019-05-22 12:44:28 -04:00
|
|
|
bool synchronize, bool fastMode, double dBSNR, double TRperiod)
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
2014-04-06 17:58:11 -04:00
|
|
|
Q_ASSERT (stream);
|
2016-10-21 10:23:06 -04:00
|
|
|
// Time according to this computer which becomes our base time
|
2013-08-07 19:09:13 -04:00
|
|
|
qint64 ms0 = QDateTime::currentMSecsSinceEpoch() % 86400000;
|
2019-05-23 13:24:35 -04:00
|
|
|
unsigned mstr = ms0 % int(1000.0*m_period); // ms into the nominal Tx start time
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2019-05-23 13:24:35 -04:00
|
|
|
if(m_state != Idle) stop();
|
2014-04-06 17:58:11 -04:00
|
|
|
m_quickClose = false;
|
2013-08-07 19:09:13 -04:00
|
|
|
m_symbolsLength = symbolsLength;
|
2015-04-22 13:48:03 -04:00
|
|
|
m_isym0 = std::numeric_limits<unsigned>::max (); // big number
|
2014-09-24 13:25:19 -04:00
|
|
|
m_frequency0 = 0.;
|
2015-12-08 20:10:58 -05:00
|
|
|
m_phi = 0.;
|
2013-08-07 19:09:13 -04:00
|
|
|
m_addNoise = dBSNR < 0.;
|
|
|
|
m_nsps = framesPerSymbol;
|
|
|
|
m_frequency = frequency;
|
|
|
|
m_amp = std::numeric_limits<qint16>::max ();
|
2014-04-08 07:56:29 -04:00
|
|
|
m_toneSpacing = toneSpacing;
|
2015-11-17 20:28:12 -05:00
|
|
|
m_bFastMode=fastMode;
|
|
|
|
m_TRperiod=TRperiod;
|
2019-05-23 13:24:35 -04:00
|
|
|
unsigned delay_ms=1000;
|
2020-07-23 13:51:05 -04:00
|
|
|
if(mode=="FT8" or (mode=="FST4" and m_nsps==720)) delay_ms=500; //FT8, FST4-15
|
|
|
|
if(mode=="FT4") delay_ms=300; //FT4
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2019-05-23 13:24:35 -04:00
|
|
|
// noise generator parameters
|
2014-03-05 13:20:40 -05:00
|
|
|
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;
|
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2020-06-23 15:10:29 -04:00
|
|
|
m_ic=0;
|
2019-05-23 13:24:35 -04:00
|
|
|
// round up to an exact portion of a second that allows for startup delays
|
2020-06-23 15:10:29 -04:00
|
|
|
if(delay_ms > 0 and !m_bFastMode) {
|
|
|
|
m_ic = (mstr/delay_ms) * m_frameRate * delay_ms / 1000;
|
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
m_silentFrames = 0;
|
2019-05-23 13:24:35 -04:00
|
|
|
// calculate number of silent frames to send, so that audio will start at
|
|
|
|
// the nominal time "delay_ms" into the Tx sequence.
|
2015-11-17 20:28:12 -05:00
|
|
|
if (synchronize && !m_tuning && !m_bFastMode) {
|
2020-06-23 15:10:29 -04:00
|
|
|
if(delay_ms >= mstr) m_silentFrames = m_ic + 0.001*(delay_ms-mstr)*m_frameRate;
|
2017-06-28 14:23:56 -04:00
|
|
|
}
|
2019-05-23 13:24:35 -04:00
|
|
|
|
2020-06-27 16:24:11 -04:00
|
|
|
// qDebug() << "aa" << QDateTime::currentDateTimeUtc().toString("hh:mm:ss.zzz")
|
|
|
|
// << delay_ms << mstr << m_silentFrames << m_ic << m_symbolsLength;
|
2020-06-25 17:18:48 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
initialize (QIODevice::ReadOnly, channel);
|
2014-03-05 13:20:40 -05:00
|
|
|
Q_EMIT stateChanged ((m_state = (synchronize && m_silentFrames) ?
|
2014-04-03 15:29:13 -04:00
|
|
|
Synchronizing : Active));
|
|
|
|
m_stream = stream;
|
2015-04-22 13:48:03 -04:00
|
|
|
if (m_stream) m_stream->restart (this);
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
|
|
|
|
2014-04-06 17:58:11 -04:00
|
|
|
void Modulator::tune (bool newState)
|
2014-04-03 15:29:13 -04:00
|
|
|
{
|
2014-04-06 17:58:11 -04:00
|
|
|
m_tuning = newState;
|
2015-04-22 13:48:03 -04:00
|
|
|
if (!m_tuning) stop (true);
|
2014-04-06 17:58:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Modulator::stop (bool quick)
|
|
|
|
{
|
|
|
|
m_quickClose = quick;
|
2014-04-03 15:29:13 -04:00
|
|
|
close ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Modulator::close ()
|
|
|
|
{
|
|
|
|
if (m_stream)
|
|
|
|
{
|
2014-04-06 17:58:11 -04:00
|
|
|
if (m_quickClose)
|
|
|
|
{
|
|
|
|
m_stream->reset ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_stream->stop ();
|
|
|
|
}
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
|
|
|
if (m_state != Idle)
|
|
|
|
{
|
|
|
|
Q_EMIT stateChanged ((m_state = Idle));
|
|
|
|
}
|
|
|
|
AudioDevice::close ();
|
2013-08-07 19:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 Modulator::readData (char * data, qint64 maxSize)
|
|
|
|
{
|
2015-06-10 10:58:55 -04:00
|
|
|
double toneFrequency=1500.0;
|
2016-09-06 11:36:17 -04:00
|
|
|
if(m_nsps==6) {
|
|
|
|
toneFrequency=1000.0;
|
|
|
|
m_frequency=1000.0;
|
|
|
|
m_frequency0=1000.0;
|
|
|
|
}
|
2014-01-07 12:14:59 -05:00
|
|
|
if(maxSize==0) return 0;
|
2014-04-08 07:20:20 -04:00
|
|
|
Q_ASSERT (!(maxSize % qint64 (bytesPerFrame ()))); // no torn frames
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_ASSERT (isOpen ());
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
qint64 numFrames (maxSize / bytesPerFrame ());
|
|
|
|
qint16 * samples (reinterpret_cast<qint16 *> (data));
|
|
|
|
qint16 * end (samples + numFrames * (bytesPerFrame () / sizeof (qint16)));
|
2014-04-08 07:20:20 -04:00
|
|
|
qint64 framesGenerated (0);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2020-06-23 15:10:29 -04:00
|
|
|
// if(m_ic==0) qDebug() << "aa" << 0.001*(QDateTime::currentMSecsSinceEpoch() % qint64(1000*m_TRperiod))
|
|
|
|
// << m_state << m_TRperiod << m_silentFrames << m_ic << foxcom_.wave[m_ic];
|
2019-04-02 11:39:28 -04:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
switch (m_state)
|
2014-04-03 15:29:13 -04:00
|
|
|
{
|
|
|
|
case Synchronizing:
|
|
|
|
{
|
|
|
|
if (m_silentFrames) { // send silence up to first second
|
2014-04-08 07:20:20 -04:00
|
|
|
framesGenerated = qMin (m_silentFrames, numFrames);
|
2014-04-03 15:29:13 -04:00
|
|
|
for ( ; samples != end; samples = load (0, samples)) { // silence
|
|
|
|
}
|
2014-04-08 07:20:20 -04:00
|
|
|
m_silentFrames -= framesGenerated;
|
|
|
|
return framesGenerated * bytesPerFrame ();
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
Q_EMIT stateChanged ((m_state = Active));
|
2014-04-06 17:58:11 -04:00
|
|
|
m_cwLevel = false;
|
2014-04-03 15:29:13 -04:00
|
|
|
m_ramp = 0; // prepare for CW wave shaping
|
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
// fall through
|
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
case Active:
|
|
|
|
{
|
2015-11-17 20:28:12 -05:00
|
|
|
unsigned int isym=0;
|
2019-04-02 11:39:28 -04:00
|
|
|
|
2015-11-17 20:28:12 -05:00
|
|
|
if(!m_tuning) isym=m_ic/(4.0*m_nsps); // Actual fsample=48000
|
2016-10-13 12:19:24 -04:00
|
|
|
bool slowCwId=((isym >= m_symbolsLength) && (icw[0] > 0)) && (!m_bFastMode);
|
2019-05-22 12:44:28 -04:00
|
|
|
if(m_TRperiod==3.0) slowCwId=false;
|
2016-10-13 12:19:24 -04:00
|
|
|
bool fastCwId=false;
|
|
|
|
static bool bCwId=false;
|
|
|
|
qint64 ms = QDateTime::currentMSecsSinceEpoch();
|
2019-05-22 12:44:28 -04:00
|
|
|
float tsec=0.001*(ms % int(1000*m_TRperiod));
|
|
|
|
if(m_bFastMode and (icw[0]>0) and (tsec > (m_TRperiod-5.0))) fastCwId=true;
|
2016-10-13 12:19:24 -04:00
|
|
|
if(!m_bFastMode) m_nspd=2560; // 22.5 WPM
|
|
|
|
|
2019-04-02 11:39:28 -04:00
|
|
|
// qDebug() << "Mod A" << m_ic << isym << tsec;
|
|
|
|
|
2016-10-13 12:19:24 -04:00
|
|
|
if(slowCwId or fastCwId) { // Transmit CW ID?
|
|
|
|
m_dphi = m_twoPi*m_frequency/m_frameRate;
|
|
|
|
if(m_bFastMode and !bCwId) {
|
|
|
|
m_frequency=1500; // Set params for CW ID
|
2016-10-21 13:03:11 -04:00
|
|
|
m_dphi = m_twoPi*m_frequency/m_frameRate;
|
2016-10-13 12:19:24 -04:00
|
|
|
m_symbolsLength=126;
|
|
|
|
m_nsps=4096.0*12000.0/11025.0;
|
|
|
|
m_ic=2246949;
|
|
|
|
m_nspd=2560; // 22.5 WPM
|
2016-12-04 09:15:41 -05:00
|
|
|
if(icw[0]*m_nspd/48000.0 > 4.0) m_nspd=4.0*48000.0/icw[0]; //Faster CW for long calls
|
2016-10-13 12:19:24 -04:00
|
|
|
}
|
|
|
|
bCwId=true;
|
|
|
|
unsigned ic0 = m_symbolsLength * 4 * m_nsps;
|
|
|
|
unsigned j(0);
|
2014-04-03 15:29:13 -04:00
|
|
|
|
|
|
|
while (samples != end) {
|
2016-10-13 12:19:24 -04:00
|
|
|
j = (m_ic - ic0)/m_nspd + 1; // symbol of this sample
|
2014-04-08 07:20:20 -04:00
|
|
|
bool level {bool (icw[j])};
|
2014-04-03 15:29:13 -04:00
|
|
|
m_phi += m_dphi;
|
|
|
|
if (m_phi > m_twoPi) m_phi -= m_twoPi;
|
2015-06-03 15:55:21 -04:00
|
|
|
qint16 sample=0;
|
|
|
|
float amp=32767.0;
|
2016-10-30 16:19:18 -04:00
|
|
|
float x=0;
|
2015-06-03 15:55:21 -04:00
|
|
|
if(m_ramp!=0) {
|
2016-10-30 16:19:18 -04:00
|
|
|
x=qSin(float(m_phi));
|
2015-06-03 15:55:21 -04:00
|
|
|
if(SOFT_KEYING) {
|
|
|
|
amp=qAbs(qint32(m_ramp));
|
|
|
|
if(amp>32767.0) amp=32767.0;
|
|
|
|
}
|
|
|
|
sample=round(amp*x);
|
|
|
|
}
|
2016-10-30 16:19:18 -04:00
|
|
|
if(m_bFastMode) {
|
|
|
|
sample=0;
|
|
|
|
if(level) sample=32767.0*x;
|
|
|
|
}
|
2016-10-13 12:19:24 -04:00
|
|
|
if (int (j) <= icw[0] && j < NUM_CW_SYMBOLS) { // stop condition
|
|
|
|
samples = load (postProcessSample (sample), samples);
|
|
|
|
++framesGenerated;
|
|
|
|
++m_ic;
|
|
|
|
} else {
|
|
|
|
Q_EMIT stateChanged ((m_state = Idle));
|
|
|
|
return framesGenerated * bytesPerFrame ();
|
|
|
|
}
|
2014-04-03 15:29:13 -04:00
|
|
|
|
2014-04-06 17:58:11 -04:00
|
|
|
// adjust ramp
|
2016-10-13 12:19:24 -04:00
|
|
|
if ((m_ramp != 0 && m_ramp != std::numeric_limits<qint16>::min ()) || level != m_cwLevel) {
|
|
|
|
// either ramp has terminated at max/min or direction has changed
|
|
|
|
m_ramp += RAMP_INCREMENT; // ramp
|
|
|
|
}
|
2014-04-06 17:58:11 -04:00
|
|
|
m_cwLevel = level;
|
2014-03-05 13:20:40 -05:00
|
|
|
}
|
2014-04-03 15:29:13 -04:00
|
|
|
return framesGenerated * bytesPerFrame ();
|
2016-10-13 12:19:24 -04:00
|
|
|
} else {
|
|
|
|
bCwId=false;
|
|
|
|
} //End of code for CW ID
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
double const baud (12000.0 / m_nsps);
|
|
|
|
// fade out parameters (no fade out for tuning)
|
2015-11-17 20:28:12 -05:00
|
|
|
unsigned int i0,i1;
|
|
|
|
if(m_tuning) {
|
2016-06-05 16:34:11 -04:00
|
|
|
i1 = i0 = (m_bFastMode ? 999999 : 9999) * m_nsps;
|
2015-11-17 20:28:12 -05:00
|
|
|
} else {
|
|
|
|
i0=(m_symbolsLength - 0.017) * 4.0 * m_nsps;
|
|
|
|
i1= m_symbolsLength * 4.0 * m_nsps;
|
|
|
|
}
|
2015-11-21 15:24:46 -05:00
|
|
|
if(m_bFastMode and !m_tuning) {
|
2019-05-22 12:44:28 -04:00
|
|
|
i1=m_TRperiod*48000.0 - 24000.0;
|
2015-11-17 20:28:12 -05:00
|
|
|
i0=i1-816;
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:06:58 -05:00
|
|
|
qint16 sample;
|
2019-04-02 11:39:28 -04:00
|
|
|
|
2014-04-08 07:20:20 -04:00
|
|
|
for (unsigned i = 0; i < numFrames && m_ic <= i1; ++i) {
|
2015-11-17 20:28:12 -05:00
|
|
|
isym=0;
|
2019-05-22 12:44:28 -04:00
|
|
|
if(!m_tuning and m_TRperiod!=3.0) isym=m_ic/(4.0*m_nsps); //Actual fsample=48000
|
2015-11-17 20:28:12 -05:00
|
|
|
if(m_bFastMode) isym=isym%m_symbolsLength;
|
2014-09-24 13:25:19 -04:00
|
|
|
if (isym != m_isym0 || m_frequency != m_frequency0) {
|
2015-04-22 13:48:03 -04:00
|
|
|
if(itone[0]>=100) {
|
2016-04-30 20:40:51 -04:00
|
|
|
m_toneFrequency0=itone[0];
|
2014-04-03 15:29:13 -04:00
|
|
|
} else {
|
2015-04-22 13:48:03 -04:00
|
|
|
if(m_toneSpacing==0.0) {
|
2016-04-30 20:40:51 -04:00
|
|
|
m_toneFrequency0=m_frequency + itone[isym]*baud;
|
2015-04-22 13:48:03 -04:00
|
|
|
} else {
|
2016-04-30 20:40:51 -04:00
|
|
|
m_toneFrequency0=m_frequency + itone[isym]*m_toneSpacing;
|
2015-04-22 13:48:03 -04:00
|
|
|
}
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
2016-04-30 20:40:51 -04:00
|
|
|
m_dphi = m_twoPi * m_toneFrequency0 / m_frameRate;
|
2014-04-03 15:29:13 -04:00
|
|
|
m_isym0 = isym;
|
2015-06-05 20:02:02 -04:00
|
|
|
m_frequency0 = m_frequency; //???
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
int j=m_ic/480;
|
2016-04-30 20:40:51 -04:00
|
|
|
if(m_fSpread>0.0 and j!=m_j0) {
|
2020-06-13 11:04:41 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
float x1=QRandomGenerator::global ()->generateDouble ();
|
|
|
|
float x2=QRandomGenerator::global ()->generateDouble ();
|
|
|
|
#else
|
2015-07-12 06:28:28 -04:00
|
|
|
float x1=(float)qrand()/RAND_MAX;
|
|
|
|
float x2=(float)qrand()/RAND_MAX;
|
2020-06-13 11:04:41 -04:00
|
|
|
#endif
|
2016-04-30 20:40:51 -04:00
|
|
|
toneFrequency = m_toneFrequency0 + 0.5*m_fSpread*(x1+x2-1.0);
|
2014-04-03 15:29:13 -04:00
|
|
|
m_dphi = m_twoPi * toneFrequency / m_frameRate;
|
2016-04-30 20:40:51 -04:00
|
|
|
m_j0=j;
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
m_phi += m_dphi;
|
|
|
|
if (m_phi > m_twoPi) m_phi -= m_twoPi;
|
|
|
|
if (m_ic > i0) m_amp = 0.98 * m_amp;
|
|
|
|
if (m_ic > i1) m_amp = 0.0;
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2017-11-21 15:06:58 -05:00
|
|
|
sample=qRound(m_amp*qSin(m_phi));
|
2019-01-18 16:22:25 -05:00
|
|
|
|
|
|
|
//Here's where we transmit from a precomputed wave[] array:
|
2019-04-02 11:39:28 -04:00
|
|
|
if(!m_tuning and (m_toneSpacing < 0)) {
|
|
|
|
m_amp=32767.0;
|
|
|
|
sample=qRound(m_amp*foxcom_.wave[m_ic]);
|
|
|
|
}
|
2020-06-27 16:24:11 -04:00
|
|
|
/*
|
|
|
|
if((m_ic<1000 or (4*m_symbolsLength*m_nsps - m_ic) < 1000) and (m_ic%10)==0) {
|
|
|
|
qDebug() << "cc" << QDateTime::currentDateTimeUtc().toString("hh:mm:ss.zzz") << m_ic << sample;
|
|
|
|
}
|
|
|
|
*/
|
2017-11-21 15:06:58 -05:00
|
|
|
samples = load(postProcessSample(sample), samples);
|
2014-04-08 07:20:20 -04:00
|
|
|
++framesGenerated;
|
2014-04-03 15:29:13 -04:00
|
|
|
++m_ic;
|
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2020-06-25 17:18:48 -04:00
|
|
|
// qDebug() << "dd" << QDateTime::currentDateTimeUtc().toString("hh:mm:ss.zzz")
|
2020-06-27 16:24:11 -04:00
|
|
|
// << m_ic << i1 << foxcom_.wave[m_ic] << framesGenerated;
|
2020-06-25 17:18:48 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
if (m_amp == 0.0) { // TODO G4WJS: compare double with zero might not be wise
|
|
|
|
if (icw[0] == 0) {
|
|
|
|
// no CW ID to send
|
|
|
|
Q_EMIT stateChanged ((m_state = Idle));
|
2014-04-08 07:20:20 -04:00
|
|
|
return framesGenerated * bytesPerFrame ();
|
2014-04-03 15:29:13 -04:00
|
|
|
}
|
|
|
|
m_phi = 0.0;
|
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2015-06-05 20:02:02 -04:00
|
|
|
m_frequency0 = m_frequency;
|
2019-04-02 11:39:28 -04:00
|
|
|
// done for this chunk - continue on next call
|
|
|
|
|
|
|
|
// qDebug() << "Mod B" << m_ic << i1 << 0.001*(QDateTime::currentMSecsSinceEpoch() % (1000*m_TRperiod));
|
2019-01-26 19:50:25 -05:00
|
|
|
|
|
|
|
while (samples != end) // pad block with silence
|
|
|
|
{
|
|
|
|
samples = load (0, samples);
|
|
|
|
++framesGenerated;
|
|
|
|
}
|
2014-04-08 07:20:20 -04:00
|
|
|
return framesGenerated * bytesPerFrame ();
|
2014-03-05 13:20:40 -05:00
|
|
|
}
|
2014-04-03 15:29:13 -04:00
|
|
|
// fall through
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
case Idle:
|
|
|
|
break;
|
2014-03-05 13:20:40 -05:00
|
|
|
}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
Q_ASSERT (Idle == m_state);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
qint16 Modulator::postProcessSample (qint16 sample) const
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
2014-04-11 18:50:22 -04:00
|
|
|
if (m_addNoise) { // Test frame, we'll add noise
|
2014-03-05 13:20:40 -05:00
|
|
|
qint32 s = m_fac * (gran () + sample * m_snr / 32768.0);
|
|
|
|
if (s > std::numeric_limits<qint16>::max ()) {
|
|
|
|
s = std::numeric_limits<qint16>::max ();
|
2013-08-07 19:09:13 -04:00
|
|
|
}
|
2014-03-05 13:20:40 -05:00
|
|
|
if (s < std::numeric_limits<qint16>::min ()) {
|
|
|
|
s = std::numeric_limits<qint16>::min ();
|
2013-08-07 19:09:13 -04:00
|
|
|
}
|
2014-03-05 13:20:40 -05:00
|
|
|
sample = s;
|
|
|
|
}
|
2013-08-10 11:29:55 -04:00
|
|
|
return sample;
|
2013-08-07 19:09:13 -04:00
|
|
|
}
|