1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/sdrbase/dsp/dvserialworker.h

166 lines
5.4 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_DSP_DVSERIALWORKER_H_
#define SDRBASE_DSP_DVSERIALWORKER_H_
#include <QObject>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <vector>
#include "dvcontroller.h"
#include "util/message.h"
#include "util/syncmessenger.h"
#include "util/messagequeue.h"
#include "dsp/filtermbe.h"
class AudioFifo;
class DVSerialWorker : public QObject {
Q_OBJECT
public:
class MsgTest : public Message
{
MESSAGE_CLASS_DECLARATION
public:
static MsgTest* create() { return new MsgTest(); }
private:
MsgTest() {}
};
class MsgMbeDecode : public Message
{
MESSAGE_CLASS_DECLARATION
public:
const unsigned char *getMbeFrame() const { return m_mbeFrame; }
SerialDV::DVRate getMbeRate() const { return m_mbeRate; }
int getVolumeIndex() const { return m_volumeIndex; }
unsigned char getChannels() const { return m_channels % 4; }
AudioFifo *getAudioFifo() { return m_audioFifo; }
2016-10-11 17:51:18 -04:00
unsigned int getFifoSlot() const { return m_fifoSlot; }
2016-10-11 17:51:18 -04:00
static MsgMbeDecode* create(
const unsigned char *mbeFrame,
int mbeRateIndex,
int volumeIndex,
unsigned char channels,
AudioFifo *audioFifo,
unsigned int fifoSlot)
{
2016-10-11 17:51:18 -04:00
return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, channels, audioFifo, fifoSlot);
}
private:
unsigned char m_mbeFrame[SerialDV::MBE_FRAME_MAX_LENGTH_BYTES];
SerialDV::DVRate m_mbeRate;
int m_volumeIndex;
unsigned char m_channels;
AudioFifo *m_audioFifo;
2016-10-11 17:51:18 -04:00
unsigned int m_fifoSlot;
MsgMbeDecode(const unsigned char *mbeFrame,
SerialDV::DVRate mbeRate,
int volumeIndex,
unsigned char channels,
2016-10-11 17:51:18 -04:00
AudioFifo *audioFifo,
unsigned int fifoSlot) :
Message(),
m_mbeRate(mbeRate),
m_volumeIndex(volumeIndex),
m_channels(channels),
2016-10-11 17:51:18 -04:00
m_audioFifo(audioFifo),
m_fifoSlot(fifoSlot)
{
memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::DVController::getNbMbeBytes(m_mbeRate));
}
};
DVSerialWorker();
~DVSerialWorker();
void pushMbeFrame(const unsigned char *mbeFrame,
int mbeRateIndex,
int mbeVolumeIndex,
unsigned char channels,
2016-10-11 17:51:18 -04:00
AudioFifo *audioFifo,
unsigned int fifoSlot);
bool open(const std::string& serialDevice);
void close();
void process();
void stop();
2016-10-11 17:51:18 -04:00
bool isAvailable(unsigned int& fifoSlot);
bool hasFifo(AudioFifo *audioFifo, unsigned int& fifoSlot);
void postTest()
{
//emit inputMessageReady();
m_inputMessageQueue.push(MsgTest::create());
}
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
signals:
void finished();
public slots:
void handleInputMessages();
private:
struct AudioSample {
qint16 l;
qint16 r;
};
typedef std::vector<AudioSample> AudioVector;
2016-10-11 16:52:45 -04:00
struct FifoSlot
{
2016-10-11 18:02:36 -04:00
FifoSlot() :
m_audioFifo(0),
m_timestamp(QDate(2000, 1, 1)),
m_audioBufferFill(0),
m_upsamplerLastValue(0)
{
m_audioBuffer.resize(48000);
}
2016-10-11 16:52:45 -04:00
AudioFifo *m_audioFifo;
QDateTime m_timestamp;
2016-10-11 18:02:36 -04:00
AudioVector m_audioBuffer;
uint m_audioBufferFill;
short m_upsamplerLastValue;
MBEAudioInterpolatorFilter m_upsampleFilter;
2016-10-11 18:19:44 -04:00
short m_dvAudioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE];
2016-10-11 16:52:45 -04:00
};
2016-10-11 18:02:36 -04:00
void upsample6(short *in, int nbSamplesIn, unsigned char channels, unsigned int fifoSlot);
2016-10-11 18:53:26 -04:00
static long long getUSecs();
2016-05-08 04:48:13 -04:00
SerialDV::DVController m_dvController;
bool m_running;
int m_currentGainIn;
int m_currentGainOut;
2016-10-11 17:51:18 -04:00
static const unsigned int m_nbFifoSlots = 1;
FifoSlot m_fifoSlots[m_nbFifoSlots];
};
#endif /* SDRBASE_DSP_DVSERIALWORKER_H_ */