mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-23 18:52:28 -04:00
File Source plugin: auto adaptative throttling
This commit is contained in:
parent
1a9af41ac3
commit
1393a93070
@ -22,8 +22,6 @@
|
|||||||
|
|
||||||
#include "filesourcethread.h"
|
#include "filesourcethread.h"
|
||||||
|
|
||||||
const int FileSourceThread::m_rateDivider = 1000/FILESOURCE_THROTTLE_MS;
|
|
||||||
|
|
||||||
FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent) :
|
FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent) :
|
||||||
QThread(parent),
|
QThread(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
@ -33,7 +31,9 @@ FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sam
|
|||||||
m_chunksize(0),
|
m_chunksize(0),
|
||||||
m_sampleFifo(sampleFifo),
|
m_sampleFifo(sampleFifo),
|
||||||
m_samplesCount(0),
|
m_samplesCount(0),
|
||||||
m_samplerate(0)
|
m_samplerate(0),
|
||||||
|
m_throttlems(FILESOURCE_THROTTLE_MS),
|
||||||
|
m_throttleToggle(false)
|
||||||
{
|
{
|
||||||
assert(m_ifstream != 0);
|
assert(m_ifstream != 0);
|
||||||
}
|
}
|
||||||
@ -57,6 +57,7 @@ void FileSourceThread::startWork()
|
|||||||
{
|
{
|
||||||
qDebug() << "FileSourceThread::startWork: file stream open, starting...";
|
qDebug() << "FileSourceThread::startWork: file stream open, starting...";
|
||||||
m_startWaitMutex.lock();
|
m_startWaitMutex.lock();
|
||||||
|
m_elapsedTimer.start();
|
||||||
start();
|
start();
|
||||||
while(!m_running)
|
while(!m_running)
|
||||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||||
@ -88,24 +89,37 @@ void FileSourceThread::setSamplerate(int samplerate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_samplerate = samplerate;
|
m_samplerate = samplerate;
|
||||||
m_chunksize = (m_samplerate / m_rateDivider)*4; // TODO: implement FF and slow motion here. 4 corresponds to live. 2 is half speed, 8 is doulbe speed
|
// TODO: implement FF and slow motion here. 4 corresponds to live. 2 is half speed, 8 is doulbe speed
|
||||||
m_bufsize = m_chunksize;
|
m_chunksize = (m_samplerate * 4 * m_throttlems) / 1000;
|
||||||
|
|
||||||
if (m_buf == 0) {
|
setBuffer(m_chunksize);
|
||||||
qDebug() << " - Allocate buffer";
|
|
||||||
m_buf = (quint8*) malloc(m_bufsize);
|
|
||||||
} else {
|
|
||||||
qDebug() << " - Re-allocate buffer";
|
|
||||||
m_buf = (quint8*) realloc((void*) m_buf, m_bufsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << " - size: " << m_bufsize
|
|
||||||
<< " #samples: " << (m_bufsize/4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//m_samplerate = samplerate;
|
//m_samplerate = samplerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSourceThread::setBuffer(int chunksize)
|
||||||
|
{
|
||||||
|
if (chunksize > m_bufsize)
|
||||||
|
{
|
||||||
|
m_bufsize = chunksize;
|
||||||
|
|
||||||
|
if (m_buf == 0)
|
||||||
|
{
|
||||||
|
qDebug() << "FileSourceThread::setBuffer: Allocate buffer";
|
||||||
|
m_buf = (quint8*) malloc(m_bufsize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "FileSourceThread::setBuffer: Re-allocate buffer";
|
||||||
|
m_buf = (quint8*) realloc((void*) m_buf, m_bufsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "FileSourceThread::setBuffer: size: " << m_bufsize
|
||||||
|
<< " #samples: " << (m_bufsize/4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileSourceThread::run()
|
void FileSourceThread::run()
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
@ -131,6 +145,16 @@ void FileSourceThread::tick()
|
|||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running)
|
||||||
{
|
{
|
||||||
|
qint64 throttlems = m_elapsedTimer.restart();
|
||||||
|
|
||||||
|
if (throttlems != m_throttlems)
|
||||||
|
{
|
||||||
|
m_throttlems = throttlems;
|
||||||
|
m_chunksize = (m_samplerate * 4 * (m_throttlems+(m_throttleToggle ? 1 : 0))) / 1000;
|
||||||
|
m_throttleToggle = !m_throttleToggle;
|
||||||
|
setBuffer(m_chunksize);
|
||||||
|
}
|
||||||
|
|
||||||
// read samples directly feeding the SampleFifo (no callback)
|
// read samples directly feeding the SampleFifo (no callback)
|
||||||
m_ifstream->read(reinterpret_cast<char*>(m_buf), m_chunksize);
|
m_ifstream->read(reinterpret_cast<char*>(m_buf), m_chunksize);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QElapsedTimer>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -39,6 +40,7 @@ public:
|
|||||||
void startWork();
|
void startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
void setSamplerate(int samplerate);
|
void setSamplerate(int samplerate);
|
||||||
|
void setBuffer(int chunksize);
|
||||||
bool isRunning() const { return m_running; }
|
bool isRunning() const { return m_running; }
|
||||||
std::size_t getSamplesCount() const { return m_samplesCount; }
|
std::size_t getSamplesCount() const { return m_samplesCount; }
|
||||||
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
|
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
|
||||||
@ -58,7 +60,9 @@ private:
|
|||||||
std::size_t m_samplesCount;
|
std::size_t m_samplesCount;
|
||||||
|
|
||||||
int m_samplerate;
|
int m_samplerate;
|
||||||
static const int m_rateDivider;
|
int m_throttlems;
|
||||||
|
QElapsedTimer m_elapsedTimer;
|
||||||
|
bool m_throttleToggle;
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
//void decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len);
|
//void decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user