mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
Audio Input: added dataReady() signal to AudioFifo and use it to avoid CPU burn loop. Basic implementation
This commit is contained in:
parent
c4a25fee38
commit
4b397f0cc7
@ -46,6 +46,7 @@ AudioInputThread::~AudioInputThread()
|
||||
|
||||
void AudioInputThread::startWork()
|
||||
{
|
||||
connect(m_fifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
|
||||
m_startWaitMutex.lock();
|
||||
|
||||
start();
|
||||
@ -60,6 +61,7 @@ void AudioInputThread::startWork()
|
||||
|
||||
void AudioInputThread::stopWork()
|
||||
{
|
||||
disconnect(m_fifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
|
||||
m_running = false;
|
||||
wait();
|
||||
}
|
||||
@ -71,19 +73,15 @@ void AudioInputThread::run()
|
||||
|
||||
while (m_running)
|
||||
{
|
||||
workIQ(m_convBufSamples);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
qDebug("AudioInputThread::run: running loop stopped");
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void AudioInputThread::workIQ(unsigned int samples)
|
||||
void AudioInputThread::workIQ(unsigned int nbRead)
|
||||
{
|
||||
// Most of the time, this returns 0, because of the low sample rate.
|
||||
// Could be more efficient in this case to have blocking wait?
|
||||
uint32_t nbRead = m_fifo->read((unsigned char *) m_buf, samples);
|
||||
|
||||
// Map between left and right audio channels and IQ channels
|
||||
if (m_iqMapping == AudioInputSettings::IQMapping::L)
|
||||
{
|
||||
@ -139,3 +137,12 @@ void AudioInputThread::workIQ(unsigned int samples)
|
||||
|
||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
void AudioInputThread::handleAudio()
|
||||
{
|
||||
uint32_t nbRead;
|
||||
|
||||
while ((nbRead = m_fifo->read((unsigned char *) m_buf, m_convBufSamples)) != 0) {
|
||||
workIQ(nbRead);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,10 @@ private:
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 16, true> m_decimatorsIQ;
|
||||
|
||||
void run();
|
||||
void workIQ(unsigned int samples);
|
||||
void workIQ(unsigned int nbRead);
|
||||
|
||||
private slots:
|
||||
void handleAudio();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_AUDIOINPUTTHREAD_H
|
||||
|
@ -97,6 +97,7 @@ uint AudioFifo::write(const quint8* data, uint32_t numSamples)
|
||||
}
|
||||
|
||||
m_mutex.unlock();
|
||||
emit dataReady();
|
||||
return total;
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,9 @@ private:
|
||||
uint32_t m_tail;
|
||||
|
||||
bool create(uint32_t numSamples);
|
||||
|
||||
signals:
|
||||
void dataReady();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_AUDIOFIFO_H
|
||||
|
Loading…
Reference in New Issue
Block a user