2015-12-06 13:47:55 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2015 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
#ifndef INCLUDE_UDPSRC_H
|
|
|
|
#define INCLUDE_UDPSRC_H
|
2015-11-18 21:27:37 -05:00
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
#include <dsp/basebandsamplesink.h>
|
2015-11-18 21:27:37 -05:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/fftfilt.h"
|
|
|
|
#include "dsp/interpolator.h"
|
2016-04-03 21:44:06 -04:00
|
|
|
#include "dsp/phasediscri.h"
|
2016-04-03 05:29:11 -04:00
|
|
|
#include "util/udpsink.h"
|
2015-11-18 21:27:37 -05:00
|
|
|
#include "util/message.h"
|
2015-12-02 22:02:21 -05:00
|
|
|
#include "audio/audiofifo.h"
|
|
|
|
|
2015-11-18 21:27:37 -05:00
|
|
|
|
2015-12-01 20:28:31 -05:00
|
|
|
class QUdpSocket;
|
2015-11-18 21:27:37 -05:00
|
|
|
class UDPSrcGUI;
|
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
class UDPSrc : public BasebandSampleSink {
|
2015-11-18 21:27:37 -05:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum SampleFormat {
|
|
|
|
FormatS16LE,
|
2016-04-05 11:02:24 -04:00
|
|
|
FormatNFM,
|
|
|
|
FormatNFMMono,
|
|
|
|
FormatLSB,
|
|
|
|
FormatUSB,
|
|
|
|
FormatLSBMono,
|
|
|
|
FormatUSBMono,
|
|
|
|
FormatAMMono,
|
2015-11-18 21:27:37 -05:00
|
|
|
FormatNone
|
|
|
|
};
|
|
|
|
|
2015-12-02 22:02:21 -05:00
|
|
|
struct AudioSample {
|
|
|
|
qint16 l;
|
|
|
|
qint16 r;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<AudioSample> AudioVector;
|
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, BasebandSampleSink* spectrum);
|
2015-11-18 21:27:37 -05:00
|
|
|
virtual ~UDPSrc();
|
|
|
|
|
2015-12-03 21:46:51 -05:00
|
|
|
void configure(MessageQueue* messageQueue,
|
|
|
|
SampleFormat sampleFormat,
|
|
|
|
Real outputSampleRate,
|
|
|
|
Real rfBandwidth,
|
2016-04-03 21:44:06 -04:00
|
|
|
int fmDeviation,
|
2015-12-03 21:46:51 -05:00
|
|
|
QString& udpAddress,
|
|
|
|
int udpPort,
|
2015-12-05 06:03:26 -05:00
|
|
|
int audioPort);
|
2015-12-03 21:46:51 -05:00
|
|
|
void configureImmediate(MessageQueue* messageQueue,
|
2015-12-05 06:03:26 -05:00
|
|
|
bool audioActive,
|
2015-12-05 06:23:55 -05:00
|
|
|
bool audioStereo,
|
2015-12-03 21:46:51 -05:00
|
|
|
int boost,
|
|
|
|
int volume);
|
2015-11-18 21:27:37 -05:00
|
|
|
void setSpectrum(MessageQueue* messageQueue, bool enabled);
|
|
|
|
Real getMagSq() const { return m_magsq; }
|
|
|
|
|
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& cmd);
|
|
|
|
|
2016-04-03 05:29:11 -04:00
|
|
|
static const int udpBLockSampleSize = 512; // UDP block size in number of samples
|
|
|
|
|
2015-12-02 22:02:21 -05:00
|
|
|
public slots:
|
|
|
|
void audioReadyRead();
|
|
|
|
|
2015-11-18 21:27:37 -05:00
|
|
|
protected:
|
|
|
|
class MsgUDPSrcConfigure : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
SampleFormat getSampleFormat() const { return m_sampleFormat; }
|
|
|
|
Real getOutputSampleRate() const { return m_outputSampleRate; }
|
|
|
|
Real getRFBandwidth() const { return m_rfBandwidth; }
|
2016-04-03 21:44:06 -04:00
|
|
|
int getFMDeviation() const { return m_fmDeviation; }
|
2015-12-01 20:28:31 -05:00
|
|
|
const QString& getUDPAddress() const { return m_udpAddress; }
|
2015-11-19 02:55:58 -05:00
|
|
|
int getUDPPort() const { return m_udpPort; }
|
2015-12-04 07:47:43 -05:00
|
|
|
int getAudioPort() const { return m_audioPort; }
|
2015-12-03 21:46:51 -05:00
|
|
|
|
|
|
|
static MsgUDPSrcConfigure* create(SampleFormat
|
|
|
|
sampleFormat,
|
|
|
|
Real sampleRate,
|
|
|
|
Real rfBandwidth,
|
2016-04-03 21:44:06 -04:00
|
|
|
int fmDeviation,
|
2015-12-03 21:46:51 -05:00
|
|
|
QString& udpAddress,
|
|
|
|
int udpPort,
|
2015-12-05 06:03:26 -05:00
|
|
|
int audioPort)
|
2015-11-18 21:27:37 -05:00
|
|
|
{
|
2015-12-03 21:46:51 -05:00
|
|
|
return new MsgUDPSrcConfigure(sampleFormat,
|
|
|
|
sampleRate,
|
|
|
|
rfBandwidth,
|
2016-04-03 21:44:06 -04:00
|
|
|
fmDeviation,
|
2015-12-03 21:46:51 -05:00
|
|
|
udpAddress,
|
|
|
|
udpPort,
|
2015-12-05 06:03:26 -05:00
|
|
|
audioPort);
|
2015-11-18 21:27:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SampleFormat m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
2016-04-03 21:44:06 -04:00
|
|
|
int m_fmDeviation;
|
2015-12-01 20:28:31 -05:00
|
|
|
QString m_udpAddress;
|
2015-11-19 02:55:58 -05:00
|
|
|
int m_udpPort;
|
2015-12-04 07:47:43 -05:00
|
|
|
int m_audioPort;
|
2015-12-03 21:46:51 -05:00
|
|
|
|
|
|
|
MsgUDPSrcConfigure(SampleFormat sampleFormat,
|
|
|
|
Real outputSampleRate,
|
|
|
|
Real rfBandwidth,
|
2016-04-03 21:44:06 -04:00
|
|
|
int fmDeviation,
|
2015-12-03 21:46:51 -05:00
|
|
|
QString& udpAddress,
|
|
|
|
int udpPort,
|
2015-12-05 06:03:26 -05:00
|
|
|
int audioPort) :
|
2015-11-18 21:27:37 -05:00
|
|
|
Message(),
|
|
|
|
m_sampleFormat(sampleFormat),
|
|
|
|
m_outputSampleRate(outputSampleRate),
|
|
|
|
m_rfBandwidth(rfBandwidth),
|
2016-04-03 21:44:06 -04:00
|
|
|
m_fmDeviation(fmDeviation),
|
2015-12-01 20:28:31 -05:00
|
|
|
m_udpAddress(udpAddress),
|
2015-11-19 02:55:58 -05:00
|
|
|
m_udpPort(udpPort),
|
2015-12-05 06:03:26 -05:00
|
|
|
m_audioPort(audioPort)
|
2015-12-03 21:46:51 -05:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgUDPSrcConfigureImmediate : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getBoost() const { return m_boost; }
|
|
|
|
int getVolume() const { return m_volume; }
|
2015-12-05 06:03:26 -05:00
|
|
|
bool getAudioActive() const { return m_audioActive; }
|
2015-12-05 06:23:55 -05:00
|
|
|
bool getAudioStereo() const { return m_audioStereo; }
|
2015-12-03 21:46:51 -05:00
|
|
|
|
|
|
|
static MsgUDPSrcConfigureImmediate* create(
|
2015-12-05 06:03:26 -05:00
|
|
|
bool audioActive,
|
2015-12-05 06:23:55 -05:00
|
|
|
bool audioStereo,
|
2015-12-03 21:46:51 -05:00
|
|
|
int boost,
|
|
|
|
int volume)
|
|
|
|
{
|
|
|
|
return new MsgUDPSrcConfigureImmediate(
|
2015-12-05 06:03:26 -05:00
|
|
|
audioActive,
|
2015-12-05 06:23:55 -05:00
|
|
|
audioStereo,
|
2015-12-03 21:46:51 -05:00
|
|
|
boost,
|
|
|
|
volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_boost;
|
|
|
|
int m_volume;
|
2015-12-05 06:03:26 -05:00
|
|
|
bool m_audioActive;
|
2015-12-05 06:23:55 -05:00
|
|
|
bool m_audioStereo;
|
2015-12-03 21:46:51 -05:00
|
|
|
|
|
|
|
MsgUDPSrcConfigureImmediate(
|
2015-12-05 06:03:26 -05:00
|
|
|
bool audioActive,
|
2015-12-05 06:23:55 -05:00
|
|
|
bool audioStereo,
|
2015-12-03 21:46:51 -05:00
|
|
|
int boost,
|
|
|
|
int volume) :
|
|
|
|
Message(),
|
2015-12-05 06:03:26 -05:00
|
|
|
m_audioActive(audioActive),
|
2015-12-05 06:23:55 -05:00
|
|
|
m_audioStereo(audioStereo),
|
2015-12-03 21:46:51 -05:00
|
|
|
m_boost(boost),
|
|
|
|
m_volume(volume)
|
2015-11-18 21:27:37 -05:00
|
|
|
{ }
|
|
|
|
};
|
2015-12-03 21:46:51 -05:00
|
|
|
|
2015-11-18 21:27:37 -05:00
|
|
|
class MsgUDPSrcSpectrum : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getEnabled() const { return m_enabled; }
|
|
|
|
|
|
|
|
static MsgUDPSrcSpectrum* create(bool enabled)
|
|
|
|
{
|
|
|
|
return new MsgUDPSrcSpectrum(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_enabled;
|
|
|
|
|
|
|
|
MsgUDPSrcSpectrum(bool enabled) :
|
|
|
|
Message(),
|
|
|
|
m_enabled(enabled)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MessageQueue* m_uiMessageQueue;
|
2015-11-19 02:55:58 -05:00
|
|
|
UDPSrcGUI* m_udpSrcGUI;
|
2015-12-02 22:02:21 -05:00
|
|
|
QUdpSocket *m_audioSocket;
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
int m_inputSampleRate;
|
|
|
|
|
|
|
|
int m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
2016-04-03 05:29:11 -04:00
|
|
|
QString m_udpAddressStr;
|
2015-12-01 20:28:31 -05:00
|
|
|
quint16 m_udpPort;
|
2015-12-04 07:47:43 -05:00
|
|
|
quint16 m_audioPort;
|
2015-11-18 21:27:37 -05:00
|
|
|
int m_boost;
|
2015-12-03 21:46:51 -05:00
|
|
|
bool m_audioActive;
|
2015-12-05 05:49:24 -05:00
|
|
|
bool m_audioStereo;
|
2015-12-03 21:46:51 -05:00
|
|
|
int m_volume;
|
2016-04-03 21:44:06 -04:00
|
|
|
int m_fmDeviation;
|
2015-11-18 21:27:37 -05:00
|
|
|
Real m_magsq;
|
|
|
|
|
|
|
|
Real m_scale;
|
|
|
|
Complex m_last, m_this;
|
|
|
|
|
|
|
|
NCO m_nco;
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_sampleDistanceRemain;
|
2015-11-19 02:55:58 -05:00
|
|
|
fftfilt* UDPFilter;
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
SampleVector m_sampleBuffer;
|
2016-04-03 05:29:11 -04:00
|
|
|
UDPSink<Sample> *m_udpBuffer;
|
2016-04-05 11:02:24 -04:00
|
|
|
UDPSink<FixReal> *m_udpBufferMono;
|
2015-12-02 22:02:21 -05:00
|
|
|
|
|
|
|
AudioVector m_audioBuffer;
|
|
|
|
uint m_audioBufferFill;
|
|
|
|
AudioFifo m_audioFifo;
|
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
BasebandSampleSink* m_spectrum;
|
2015-11-18 21:27:37 -05:00
|
|
|
bool m_spectrumEnabled;
|
|
|
|
|
|
|
|
quint32 m_nextSSBId;
|
|
|
|
quint32 m_nextS16leId;
|
|
|
|
|
2016-04-06 03:33:29 -04:00
|
|
|
char *m_udpAudioBuf;
|
|
|
|
static const int m_udpAudioPayloadSize = 8192; //!< UDP audio samples buffer. No UDP block on Earth is larger than this
|
|
|
|
|
2016-04-03 21:44:06 -04:00
|
|
|
PhaseDiscriminators m_phaseDiscri;
|
|
|
|
|
2015-11-18 21:27:37 -05:00
|
|
|
QMutex m_settingsMutex;
|
|
|
|
};
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
#endif // INCLUDE_UDPSRC_H
|