mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-29 13:32:26 -04:00
DV Serial: prepare multi slot (1)
This commit is contained in:
parent
18a8e7c903
commit
2caf76b746
@ -250,17 +250,18 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde
|
|||||||
std::vector<DVSerialController>::iterator it = m_controllers.begin();
|
std::vector<DVSerialController>::iterator it = m_controllers.begin();
|
||||||
std::vector<DVSerialController>::iterator itAvail = m_controllers.end();
|
std::vector<DVSerialController>::iterator itAvail = m_controllers.end();
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
unsigned int fifoSlot;
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
|
|
||||||
while (it != m_controllers.end())
|
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;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (it->worker->isAvailable())
|
else if (it->worker->isAvailable(fifoSlot))
|
||||||
{
|
{
|
||||||
itAvail = it;
|
itAvail = it;
|
||||||
break;
|
break;
|
||||||
@ -276,7 +277,7 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde
|
|||||||
int wNum = itAvail - m_controllers.begin();
|
int wNum = itAvail - m_controllers.begin();
|
||||||
|
|
||||||
qDebug("DVSerialEngine::pushMbeFrame: push %p on empty queue %d", audioFifo, wNum);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,12 @@ void DVSerialWorker::handleInputMessages()
|
|||||||
{
|
{
|
||||||
Message* message;
|
Message* message;
|
||||||
m_audioBufferFill = 0;
|
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)
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
||||||
{
|
{
|
||||||
@ -84,7 +89,7 @@ void DVSerialWorker::handleInputMessages()
|
|||||||
if (m_dvController.decode(m_dvAudioSamples, decodeMsg->getMbeFrame(), decodeMsg->getMbeRate(), dBVolume))
|
if (m_dvController.decode(m_dvAudioSamples, decodeMsg->getMbeFrame(), decodeMsg->getMbeRate(), dBVolume))
|
||||||
{
|
{
|
||||||
upsample6(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels(), decodeMsg->getAudioFifo());
|
upsample6(m_dvAudioSamples, SerialDV::MBE_AUDIO_BLOCK_SIZE, decodeMsg->getChannels(), decodeMsg->getAudioFifo());
|
||||||
audioFifo = decodeMsg->getAudioFifo();
|
audioFifo[decodeMsg->getFifoSlot()] = decodeMsg->getAudioFifo();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -95,40 +100,60 @@ void DVSerialWorker::handleInputMessages()
|
|||||||
delete message;
|
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 (audioFifo[i])
|
||||||
|
|
||||||
if (res != m_audioBufferFill)
|
|
||||||
{
|
{
|
||||||
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,
|
void DVSerialWorker::pushMbeFrame(const unsigned char *mbeFrame,
|
||||||
int mbeRateIndex,
|
int mbeRateIndex,
|
||||||
int mbeVolumeIndex,
|
int mbeVolumeIndex,
|
||||||
unsigned char channels, AudioFifo *audioFifo)
|
unsigned char channels, AudioFifo *audioFifo,
|
||||||
|
unsigned int fifoSlot)
|
||||||
{
|
{
|
||||||
m_fifoSlots[0].m_audioFifo = audioFifo;
|
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) {
|
for (fifoSlot = 0; fifoSlot < m_nbFifoSlots; fifoSlot++)
|
||||||
return true;
|
{
|
||||||
}
|
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)
|
void DVSerialWorker::upsample6(short *in, int nbSamplesIn, unsigned char channels, AudioFifo *audioFifo)
|
||||||
|
@ -54,10 +54,17 @@ public:
|
|||||||
int getVolumeIndex() const { return m_volumeIndex; }
|
int getVolumeIndex() const { return m_volumeIndex; }
|
||||||
unsigned char getChannels() const { return m_channels % 4; }
|
unsigned char getChannels() const { return m_channels % 4; }
|
||||||
AudioFifo *getAudioFifo() { return m_audioFifo; }
|
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:
|
private:
|
||||||
@ -66,17 +73,20 @@ public:
|
|||||||
int m_volumeIndex;
|
int m_volumeIndex;
|
||||||
unsigned char m_channels;
|
unsigned char m_channels;
|
||||||
AudioFifo *m_audioFifo;
|
AudioFifo *m_audioFifo;
|
||||||
|
unsigned int m_fifoSlot;
|
||||||
|
|
||||||
MsgMbeDecode(const unsigned char *mbeFrame,
|
MsgMbeDecode(const unsigned char *mbeFrame,
|
||||||
SerialDV::DVRate mbeRate,
|
SerialDV::DVRate mbeRate,
|
||||||
int volumeIndex,
|
int volumeIndex,
|
||||||
unsigned char channels,
|
unsigned char channels,
|
||||||
AudioFifo *audioFifo) :
|
AudioFifo *audioFifo,
|
||||||
|
unsigned int fifoSlot) :
|
||||||
Message(),
|
Message(),
|
||||||
m_mbeRate(mbeRate),
|
m_mbeRate(mbeRate),
|
||||||
m_volumeIndex(volumeIndex),
|
m_volumeIndex(volumeIndex),
|
||||||
m_channels(channels),
|
m_channels(channels),
|
||||||
m_audioFifo(audioFifo)
|
m_audioFifo(audioFifo),
|
||||||
|
m_fifoSlot(fifoSlot)
|
||||||
{
|
{
|
||||||
memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::DVController::getNbMbeBytes(m_mbeRate));
|
memcpy((void *) m_mbeFrame, (const void *) mbeFrame, SerialDV::DVController::getNbMbeBytes(m_mbeRate));
|
||||||
}
|
}
|
||||||
@ -89,14 +99,15 @@ public:
|
|||||||
int mbeRateIndex,
|
int mbeRateIndex,
|
||||||
int mbeVolumeIndex,
|
int mbeVolumeIndex,
|
||||||
unsigned char channels,
|
unsigned char channels,
|
||||||
AudioFifo *audioFifo);
|
AudioFifo *audioFifo,
|
||||||
|
unsigned int fifoSlot);
|
||||||
|
|
||||||
bool open(const std::string& serialDevice);
|
bool open(const std::string& serialDevice);
|
||||||
void close();
|
void close();
|
||||||
void process();
|
void process();
|
||||||
void stop();
|
void stop();
|
||||||
bool isAvailable();
|
bool isAvailable(unsigned int& fifoSlot);
|
||||||
bool hasFifo(AudioFifo *audioFifo);
|
bool hasFifo(AudioFifo *audioFifo, unsigned int& fifoSlot);
|
||||||
|
|
||||||
void postTest()
|
void postTest()
|
||||||
{
|
{
|
||||||
@ -138,7 +149,8 @@ private:
|
|||||||
//short m_audioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE * 6 * 2]; // upsample to 48k and duplicate channel
|
//short m_audioSamples[SerialDV::MBE_AUDIO_BLOCK_SIZE * 6 * 2]; // upsample to 48k and duplicate channel
|
||||||
AudioVector m_audioBuffer;
|
AudioVector m_audioBuffer;
|
||||||
uint m_audioBufferFill;
|
uint m_audioBufferFill;
|
||||||
FifoSlot m_fifoSlots[2];
|
static const unsigned int m_nbFifoSlots = 1;
|
||||||
|
FifoSlot m_fifoSlots[m_nbFifoSlots];
|
||||||
short m_upsamplerLastValue;
|
short m_upsamplerLastValue;
|
||||||
float m_phase;
|
float m_phase;
|
||||||
MBEAudioInterpolatorFilter m_upsampleFilter;
|
MBEAudioInterpolatorFilter m_upsampleFilter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user