mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-17 05:41:56 -05:00
Tx ph.1: refactored source sample FIFO. StarUML model: added Tx classes
This commit is contained in:
parent
4709ba9e01
commit
52b618469c
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,14 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <assert.h>
|
||||
#include "samplesourcefifo.h"
|
||||
|
||||
SampleSourceFifo::SampleSourceFifo(uint32_t size, uint32_t samplesChunkSize) :
|
||||
m_size(size),
|
||||
m_samplesChunkSize(samplesChunkSize),
|
||||
m_i(0)
|
||||
m_ir(0),
|
||||
m_iw(size/2)
|
||||
{
|
||||
assert(samplesChunkSize < m_size/4);
|
||||
m_data.resize(2*m_size);
|
||||
@ -29,44 +31,56 @@ SampleSourceFifo::SampleSourceFifo(uint32_t size, uint32_t samplesChunkSize) :
|
||||
SampleSourceFifo::~SampleSourceFifo()
|
||||
{}
|
||||
|
||||
void SampleSourceFifo::read(SampleVector::iterator& begin, SampleVector::iterator& end)
|
||||
void SampleSourceFifo::read(SampleVector::iterator& beginRead, unsigned int nbSamples)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
end = m_data.begin() + m_size + m_i;
|
||||
begin = end - m_samplesChunkSize;
|
||||
emit dataRead();
|
||||
}
|
||||
|
||||
void SampleSourceFifo::getReadIterator(SampleVector::iterator& beginRead)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
beginRead = m_data.begin() + m_size + m_i - m_samplesChunkSize;
|
||||
emit dataRead();
|
||||
assert(nbSamples < m_samplesChunkSize/2);
|
||||
|
||||
beginRead = m_data.begin() + m_size + m_ir;
|
||||
m_ir = (m_ir + nbSamples) % m_size;
|
||||
|
||||
int i_delta = m_iw - m_ir;
|
||||
|
||||
if (i_delta > 0)
|
||||
{
|
||||
if (i_delta < m_samplesChunkSize)
|
||||
{
|
||||
emit dataWrite();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i_delta + m_size < m_samplesChunkSize)
|
||||
{
|
||||
emit dataWrite();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SampleSourceFifo::write(const Sample& sample)
|
||||
{
|
||||
m_data[m_i] = sample;
|
||||
m_data[m_i+m_size] = sample;
|
||||
m_data[m_iw] = sample;
|
||||
m_data[m_iw+m_size] = sample;
|
||||
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
m_i = (m_i+1) % m_size;
|
||||
m_iw = (m_iw+1) % m_size;
|
||||
}
|
||||
}
|
||||
|
||||
void SampleSourceFifo::getWriteIterator(SampleVector::iterator& writeAt)
|
||||
{
|
||||
writeAt = m_data.begin() + m_i;
|
||||
writeAt = m_data.begin() + m_iw;
|
||||
}
|
||||
|
||||
void SampleSourceFifo::bumpIndex()
|
||||
{
|
||||
m_data[m_i+m_size] = m_data[m_i];
|
||||
m_i = (m_i+1) % m_size;
|
||||
m_data[m_iw+m_size] = m_data[m_iw];
|
||||
m_iw = (m_iw+1) % m_size;
|
||||
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
m_i = (m_i+1) % m_size;
|
||||
m_iw = (m_iw+1) % m_size;
|
||||
}
|
||||
}
|
||||
|
@ -32,21 +32,25 @@ public:
|
||||
~SampleSourceFifo();
|
||||
|
||||
unsigned int getChunkSize() const { return m_samplesChunkSize; }
|
||||
void read(SampleVector::iterator& begin, SampleVector::iterator& end);
|
||||
void getReadIterator(SampleVector::iterator& beginRead); //!< begin read at this point for the chunksize length
|
||||
void write(const Sample& sample); //!< write directly
|
||||
|
||||
/** begin read at current read point for the given length */
|
||||
void read(SampleVector::iterator& beginRead, unsigned int nbSamples);
|
||||
|
||||
void getWriteIterator(SampleVector::iterator& writeAt); //!< get iterator to current item for update - write phase 1
|
||||
void bumpIndex(); //!< copy current item to second buffer and bump write index - write phase 2
|
||||
|
||||
void write(const Sample& sample); //!< write directly - phase 1 + phase 2
|
||||
|
||||
private:
|
||||
uint32_t m_size;
|
||||
uint32_t m_samplesChunkSize;
|
||||
SampleVector m_data;
|
||||
uint32_t m_i;
|
||||
uint32_t m_iw;
|
||||
uint32_t m_ir;
|
||||
QMutex m_mutex;
|
||||
|
||||
signals:
|
||||
void dataRead(); // signal data has been read past a read chunk of samples
|
||||
void dataWrite(); // signal data is read past a read chunk of samples and write is needed
|
||||
};
|
||||
|
||||
#endif /* SDRBASE_DSP_SAMPLESOURCEFIFO_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user