mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-07-25 19:44:12 -04:00
LimeSDR output: regulate Tx output
This commit is contained in:
@@ -24,6 +24,7 @@ LimeSDROutputThread::LimeSDROutputThread(lms_stream_t* stream, SampleSourceFifo*
|
||||
m_running(false),
|
||||
m_stream(stream),
|
||||
m_sampleFifo(sampleFifo),
|
||||
m_sampleRate(5000000),
|
||||
m_log2Interp(0),
|
||||
m_fcPos(LimeSDROutputSettings::FC_POS_CENTER)
|
||||
{
|
||||
@@ -66,7 +67,8 @@ void LimeSDROutputThread::setFcPos(int fcPos)
|
||||
|
||||
void LimeSDROutputThread::run()
|
||||
{
|
||||
int res;
|
||||
int res, count, msleep, mdelta;
|
||||
lms_stream_status_t streamStatus;
|
||||
|
||||
lms_stream_meta_t metadata; //Use metadata for additional control over sample receive function behaviour
|
||||
metadata.flushPartialPacket = false; //Do not discard data remainder when read size differs from packet size
|
||||
@@ -81,15 +83,46 @@ void LimeSDROutputThread::run()
|
||||
qDebug("LimeSDROutputThread::run: stream started");
|
||||
}
|
||||
|
||||
count = 0;
|
||||
msleep = LIMESDROUTPUT_BLOCKSIZE/(m_sampleRate/1e6f);
|
||||
mdelta = msleep/100;
|
||||
msleep = (3*msleep)/4; // to start faster
|
||||
|
||||
while (m_running)
|
||||
{
|
||||
callback(m_buf, LIMESDROUTPUT_BLOCKSIZE);
|
||||
|
||||
if ((res = LMS_SendStream(m_stream, (void *) m_buf, LIMESDROUTPUT_BLOCKSIZE, &metadata, 1000)) < 0)
|
||||
res = LMS_SendStream(m_stream, (void *) m_buf, LIMESDROUTPUT_BLOCKSIZE, &metadata, 1000);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
qCritical("LimeSDROutputThread::run write error: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
else if (res != LIMESDROUTPUT_BLOCKSIZE)
|
||||
{
|
||||
qDebug("LimeSDROutputThread::run written %d/%d samples", res, LIMESDROUTPUT_BLOCKSIZE);
|
||||
}
|
||||
|
||||
usleep(msleep);
|
||||
|
||||
if (count < 10)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LMS_GetStreamStatus(m_stream, &streamStatus) == 0)
|
||||
{
|
||||
if (streamStatus.fifoFilledCount < (4*streamStatus.fifoSize)/5) { // FIFO at 80%
|
||||
msleep -= mdelta;
|
||||
} else {
|
||||
msleep += mdelta;
|
||||
}
|
||||
}
|
||||
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (LMS_StopStream(m_stream) < 0) {
|
||||
|
||||
Reference in New Issue
Block a user