diff --git a/sdrbase/dsp/dvserialengine.cpp b/sdrbase/dsp/dvserialengine.cpp index 624ebf298..48a6ce30e 100644 --- a/sdrbase/dsp/dvserialengine.cpp +++ b/sdrbase/dsp/dvserialengine.cpp @@ -250,17 +250,18 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde std::vector::iterator it = m_controllers.begin(); std::vector::iterator itAvail = m_controllers.end(); bool done = false; + unsigned int fifoSlot; QMutexLocker locker(&m_mutex); while (it != m_controllers.end()) { - if (it->worker->hasFifo(audioFifo)) + if (it->worker->hasFifo(audioFifo, fifoSlot)) { - it->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo); + it->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo, fifoSlot); done = true; break; } - else if (it->worker->isAvailable()) + else if (it->worker->isAvailable(fifoSlot)) { itAvail = it; break; @@ -276,7 +277,7 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde int wNum = itAvail - m_controllers.begin(); qDebug("DVSerialEngine::pushMbeFrame: push %p on empty queue %d", audioFifo, wNum); - itAvail->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo); + itAvail->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo, fifoSlot); } else { diff --git a/sdrbase/dsp/dvserialworker.cpp b/sdrbase/dsp/dvserialworker.cpp index a15008ff1..610efe547 100644 --- a/sdrbase/dsp/dvserialworker.cpp +++ b/sdrbase/dsp/dvserialworker.cpp @@ -72,7 +72,12 @@ void DVSerialWorker::handleInputMessages() { Message* message; m_audioBufferFill = 0; - AudioFifo *audioFifo = 0; + AudioFifo *audioFifo[m_nbFifoSlots]; + + for (int i = 0; i < m_nbFifoSlots; i++) + { + audioFifo[i] = 0; + } while ((message = m_inputMessageQueue.pop()) != 0) { @@ -84,7 +89,7 @@ void DVSerialWorker::handleInputMessages() if (m_dvController.decode(m_dvAudioSamples, decodeMsg->getMbeFrame(), decodeMsg->getMbeRate(), dBVolume)) { upsample6(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels(), decodeMsg->getAudioFifo()); - audioFifo = decodeMsg->getAudioFifo(); + audioFifo[decodeMsg->getFifoSlot()] = decodeMsg->getAudioFifo(); } else { @@ -95,40 +100,60 @@ void DVSerialWorker::handleInputMessages() delete message; } - if (audioFifo) + for (int i = 0; i < m_nbFifoSlots; i++) { - uint res = audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10); - - if (res != m_audioBufferFill) + if (audioFifo[i]) { - qDebug("DVSerialWorker::handleInputMessages: %u/%u audio samples written", res, m_audioBufferFill); + uint res = audioFifo[i]->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10); + + if (res != m_audioBufferFill) + { + qDebug("DVSerialWorker::handleInputMessages: %u/%u audio samples written", res, m_audioBufferFill); + } + + m_fifoSlots[i].m_timestamp = QDateTime::currentDateTime(); } } - - m_fifoSlots[0].m_timestamp = QDateTime::currentDateTime(); } void DVSerialWorker::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, - unsigned char channels, AudioFifo *audioFifo) + unsigned char channels, AudioFifo *audioFifo, + unsigned int fifoSlot) { m_fifoSlots[0].m_audioFifo = audioFifo; - m_inputMessageQueue.push(MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo)); + m_inputMessageQueue.push(MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo, fifoSlot)); } -bool DVSerialWorker::isAvailable() +bool DVSerialWorker::isAvailable(unsigned int& fifoSlot) { - if (m_fifoSlots[0].m_audioFifo == 0) { - return true; - } + for (fifoSlot = 0; fifoSlot < m_nbFifoSlots; fifoSlot++) + { + if (m_fifoSlots[fifoSlot].m_audioFifo == 0) + { + return true; + } + else if (m_fifoSlots[fifoSlot].m_timestamp.time().msecsTo(QDateTime::currentDateTime().time()) > 1000) + { + return true; + } + } - return m_fifoSlots[0].m_timestamp.time().msecsTo(QDateTime::currentDateTime().time()) > 1000; // 1 second inactivity timeout + return false; } -bool DVSerialWorker::hasFifo(AudioFifo *audioFifo) +bool DVSerialWorker::hasFifo(AudioFifo *audioFifo, unsigned int& fifoSlot) { - return m_fifoSlots[0].m_audioFifo == audioFifo; + for (fifoSlot = 0; fifoSlot < m_nbFifoSlots; fifoSlot++) + { + if (m_fifoSlots[fifoSlot].m_audioFifo == audioFifo) + { + return true; + } + } + + return false; } void DVSerialWorker::upsample6(short *in, int nbSamplesIn, unsigned char channels, AudioFifo *audioFifo) diff --git a/sdrbase/dsp/dvserialworker.h b/sdrbase/dsp/dvserialworker.h index 9192b8b7c..ec74d1583 100644 --- a/sdrbase/dsp/dvserialworker.h +++ b/sdrbase/dsp/dvserialworker.h @@ -54,10 +54,17 @@ public: int getVolumeIndex() const { return m_volumeIndex; } unsigned char getChannels() const { return m_channels % 4; } AudioFifo *getAudioFifo() { return m_audioFifo; } + unsigned int getFifoSlot() const { return m_fifoSlot; } - static MsgMbeDecode* create(const unsigned char *mbeFrame, int mbeRateIndex, int volumeIndex, unsigned char channels, AudioFifo *audioFifo) + static MsgMbeDecode* create( + const unsigned char *mbeFrame, + int mbeRateIndex, + int volumeIndex, + unsigned char channels, + AudioFifo *audioFifo, + unsigned int fifoSlot) { - return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, channels, audioFifo); + return new MsgMbeDecode(mbeFrame, (SerialDV::DVRate) mbeRateIndex, volumeIndex, channels, audioFifo, fifoSlot); } private: @@ -66,17 +73,20 @@ public: int m_volumeIndex; unsigned char m_channels; AudioFifo *m_audioFifo; + unsigned int m_fifoSlot; MsgMbeDecode(const unsigned char *mbeFrame, SerialDV::DVRate mbeRate, int volumeIndex, unsigned char channels, - AudioFifo *audioFifo) : + AudioFifo *audioFifo, + unsigned int fifoSlot) : Message(), m_mbeRate(mbeRate), m_volumeIndex(volumeIndex), m_channels(channels), - m_audioFifo(audioFifo) + m_audioFifo(audioFifo), + m_fifoSlot(fifoSlot) { memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::DVController::getNbMbeBytes(m_mbeRate)); } @@ -89,14 +99,15 @@ public: int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, - AudioFifo *audioFifo); + AudioFifo *audioFifo, + unsigned int fifoSlot); bool open(const std::string& serialDevice); void close(); void process(); void stop(); - bool isAvailable(); - bool hasFifo(AudioFifo *audioFifo); + bool isAvailable(unsigned int& fifoSlot); + bool hasFifo(AudioFifo *audioFifo, unsigned int& fifoSlot); void postTest() { @@ -138,7 +149,8 @@ private: //short m_audioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE * 6 * 2]; // upsample to 48k and duplicate channel AudioVector m_audioBuffer; uint m_audioBufferFill; - FifoSlot m_fifoSlots[2]; + static const unsigned int m_nbFifoSlots = 1; + FifoSlot m_fifoSlots[m_nbFifoSlots]; short m_upsamplerLastValue; float m_phase; MBEAudioInterpolatorFilter m_upsampleFilter;