From f64d07837544f2261ed352383d496873e054f786 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 7 Sep 2016 00:47:51 +0200 Subject: [PATCH] DSD demod plugin: DMR refactoring: allow stereo split of TDMA channels. Works with DVSerial too now. --- plugins/channel/demoddsd/dsddemod.cpp | 20 ++++++++++++++++---- sdrbase/dsp/dspengine.h | 4 ++-- sdrbase/dsp/dvserialengine.cpp | 4 ++-- sdrbase/dsp/dvserialengine.h | 2 +- sdrbase/dsp/dvserialworker.cpp | 8 ++++---- sdrbase/dsp/dvserialworker.h | 10 +++++++--- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/plugins/channel/demoddsd/dsddemod.cpp b/plugins/channel/demoddsd/dsddemod.cpp index 7ab32d8ef..d2da8606d 100644 --- a/plugins/channel/demoddsd/dsddemod.cpp +++ b/plugins/channel/demoddsd/dsddemod.cpp @@ -201,8 +201,14 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto { if ((m_running.m_slot1On) && m_dsdDecoder.mbeDVReady1()) { - if (!m_running.m_audioMute) { - DSPEngine::instance()->pushMbeFrame(m_dsdDecoder.getMbeDVFrame1(), m_dsdDecoder.getMbeRateIndex(), m_running.m_volume, &m_audioFifo1); + if (!m_running.m_audioMute) + { + DSPEngine::instance()->pushMbeFrame( + m_dsdDecoder.getMbeDVFrame1(), + m_dsdDecoder.getMbeRateIndex(), + m_running.m_volume, + m_running.m_tdmaStereo ? 1 : 3, // left or both channels + &m_audioFifo1); } m_dsdDecoder.resetMbeDV1(); @@ -210,8 +216,14 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto if ((m_running.m_slot2On) && m_dsdDecoder.mbeDVReady2()) { - if (!m_running.m_audioMute) { - DSPEngine::instance()->pushMbeFrame(m_dsdDecoder.getMbeDVFrame2(), m_dsdDecoder.getMbeRateIndex(), m_running.m_volume, &m_audioFifo2); + if (!m_running.m_audioMute) + { + DSPEngine::instance()->pushMbeFrame( + m_dsdDecoder.getMbeDVFrame2(), + m_dsdDecoder.getMbeRateIndex(), + m_running.m_volume, + m_running.m_tdmaStereo ? 2 : 3, // right or both channels + &m_audioFifo2); } m_dsdDecoder.resetMbeDV2(); diff --git a/sdrbase/dsp/dspengine.h b/sdrbase/dsp/dspengine.h index 07b13cf1e..bf3228ff6 100644 --- a/sdrbase/dsp/dspengine.h +++ b/sdrbase/dsp/dspengine.h @@ -76,10 +76,10 @@ public: #endif } - void pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, AudioFifo *audioFifo) + void pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, AudioFifo *audioFifo) { #ifdef DSD_USE_SERIALDV - m_dvSerialEngine.pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, audioFifo); + m_dvSerialEngine.pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo); #endif } diff --git a/sdrbase/dsp/dvserialengine.cpp b/sdrbase/dsp/dvserialengine.cpp index 1cd895771..012b03549 100644 --- a/sdrbase/dsp/dvserialengine.cpp +++ b/sdrbase/dsp/dvserialengine.cpp @@ -244,7 +244,7 @@ void DVSerialEngine::getDevicesNames(std::vector& deviceNames) } } -void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, AudioFifo *audioFifo) +void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, AudioFifo *audioFifo) { std::vector::iterator it = m_controllers.begin(); @@ -252,7 +252,7 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde { if (it->worker->m_inputMessageQueue.size() < 2) { - it->worker->m_inputMessageQueue.push(DVSerialWorker::MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, audioFifo)); + it->worker->m_inputMessageQueue.push(DVSerialWorker::MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo)); break; } diff --git a/sdrbase/dsp/dvserialengine.h b/sdrbase/dsp/dvserialengine.h index 97e68ec97..48c7bc7dd 100644 --- a/sdrbase/dsp/dvserialengine.h +++ b/sdrbase/dsp/dvserialengine.h @@ -40,7 +40,7 @@ public: int getNbDevices() const { return m_controllers.size(); } void getDevicesNames(std::vector& devicesNames); - void pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, AudioFifo *audioFifo); + void pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, AudioFifo *audioFifo); private: struct DVSerialController diff --git a/sdrbase/dsp/dvserialworker.cpp b/sdrbase/dsp/dvserialworker.cpp index c90403c69..102c94be2 100644 --- a/sdrbase/dsp/dvserialworker.cpp +++ b/sdrbase/dsp/dvserialworker.cpp @@ -80,7 +80,7 @@ void DVSerialWorker::handleInputMessages() if (m_dvController.decode(m_dvAudioSamples, decodeMsg->getMbeFrame(), decodeMsg->getMbeRate(), dBVolume)) { - upsample6(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getAudioFifo()); + upsample6(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels(), decodeMsg->getAudioFifo()); // upsample6(m_dvAudioSamples, m_audioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE); // decodeMsg->getAudioFifo()->write((const quint8 *) m_audioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE * 6, 10); } @@ -94,7 +94,7 @@ void DVSerialWorker::handleInputMessages() } } -void DVSerialWorker::upsample6(short *in, int nbSamplesIn, AudioFifo *audioFifo) +void DVSerialWorker::upsample6(short *in, int nbSamplesIn, unsigned char channels, AudioFifo *audioFifo) { for (int i = 0; i < nbSamplesIn; i++) { @@ -105,8 +105,8 @@ void DVSerialWorker::upsample6(short *in, int nbSamplesIn, AudioFifo *audioFifo) for (int j = 1; j < 7; j++) { upsample = (qint16) ((cur*j + prev*(6-j)) / 6); - m_audioBuffer[m_audioBufferFill].l = upsample; - m_audioBuffer[m_audioBufferFill].r = upsample; + m_audioBuffer[m_audioBufferFill].l = channels & 1 ? upsample : 0; + m_audioBuffer[m_audioBufferFill].r = (channels>>1) & 1 ? upsample : 0; ++m_audioBufferFill; if (m_audioBufferFill >= m_audioBuffer.size()) diff --git a/sdrbase/dsp/dvserialworker.h b/sdrbase/dsp/dvserialworker.h index e3f0419f8..40693179f 100644 --- a/sdrbase/dsp/dvserialworker.h +++ b/sdrbase/dsp/dvserialworker.h @@ -49,26 +49,30 @@ 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; } - static MsgMbeDecode* create(const unsigned char *mbeFrame, int mbeRateIndex, int volumeIndex, AudioFifo *audioFifo) + static MsgMbeDecode* create(const unsigned char *mbeFrame, int mbeRateIndex, int volumeIndex, unsigned char channels, AudioFifo *audioFifo) { - return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, audioFifo); + return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, channels, audioFifo); } private: unsigned char m_mbeFrame[SerialDV::MBE_FRAME_LENGTH_BYTES]; SerialDV::DVRate m_mbeRate; int m_volumeIndex; + unsigned char m_channels; AudioFifo *m_audioFifo; MsgMbeDecode(const unsigned char *mbeFrame, SerialDV::DVRate mbeRate, int volumeIndex, + unsigned char channels, AudioFifo *audioFifo) : Message(), m_mbeRate(mbeRate), m_volumeIndex(volumeIndex), + m_channels(channels), m_audioFifo(audioFifo) { memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::MBE_FRAME_LENGTH_BYTES); @@ -107,7 +111,7 @@ private: typedef std::vector AudioVector; void upsample6(short *in, short *out, int nbSamplesIn); - void upsample6(short *in, int nbSamplesIn, AudioFifo *audioFifo); + void upsample6(short *in, int nbSamplesIn, unsigned char channels, AudioFifo *audioFifo); SerialDV::DVController m_dvController; bool m_running;