92 lines
2.7 KiB
Diff
92 lines
2.7 KiB
Diff
--- a/lib/sdrplay/sdrplay_source_c.cc 2017-06-24 23:13:25.747061807 +0200
|
|
+++ b/lib/sdrplay/sdrplay_source_c.cc 2015-09-20 09:27:29.000000000 +0200
|
|
@@ -142,8 +142,11 @@
|
|
*/
|
|
sdrplay_source_c::~sdrplay_source_c ()
|
|
{
|
|
- free(_dev);
|
|
- _dev = NULL;
|
|
+ if (_dev != NULL)
|
|
+ {
|
|
+ free(_dev);
|
|
+ _dev = NULL;
|
|
+ }
|
|
_buf_mutex.lock();
|
|
if (_running)
|
|
{
|
|
@@ -214,10 +217,10 @@
|
|
gr_complex *out = (gr_complex *)output_items[0];
|
|
int cnt = noutput_items;
|
|
unsigned int sampNum;
|
|
+ unsigned int sampNumStart;
|
|
int grChanged;
|
|
int rfChanged;
|
|
int fsChanged;
|
|
-
|
|
if (_uninit)
|
|
{
|
|
return WORK_DONE;
|
|
@@ -230,27 +233,35 @@
|
|
}
|
|
|
|
_buf_mutex.lock();
|
|
-
|
|
- if (_buf_offset)
|
|
+ sampNumStart = sampNum;
|
|
+ int first_offset = _buf_offset;
|
|
+ if (_buf_offset > 0)
|
|
{
|
|
- for (int i = _buf_offset; i < _dev->samplesPerPacket; i++)
|
|
+ for (int i = _buf_offset; i < _dev->samplesPerPacket; i++)
|
|
{
|
|
*out++ = gr_complex( float(_bufi[i]) * (1.0f/2048.0f), float(_bufq[i]) * (1.0f/2048.0f) );
|
|
}
|
|
- cnt -= (_dev->samplesPerPacket - _buf_offset);
|
|
+ if (cnt > ( _dev ->samplesPerPacket - _buf_offset ))
|
|
+ {
|
|
+ cnt = cnt - (_dev->samplesPerPacket - _buf_offset);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ _buf_offset = _buf_offset + cnt;
|
|
+ cnt = 0;
|
|
+ }
|
|
}
|
|
|
|
- while ((cnt - _dev->samplesPerPacket) >= 0)
|
|
+ while ((cnt - _dev->samplesPerPacket) > 0)
|
|
{
|
|
mir_sdr_ReadPacket(_bufi.data(), _bufq.data(), &sampNum, &grChanged, &rfChanged, &fsChanged);
|
|
for (int i = 0; i < _dev->samplesPerPacket; i++)
|
|
{
|
|
*out++ = gr_complex( float(_bufi[i]) * (1.0f/2048.0f), float(_bufq[i]) * (1.0f/2048.0f) );
|
|
}
|
|
- cnt -= _dev->samplesPerPacket;
|
|
+ cnt = cnt - _dev->samplesPerPacket;
|
|
}
|
|
-
|
|
- _buf_offset = 0;
|
|
+
|
|
if (cnt)
|
|
{
|
|
mir_sdr_ReadPacket(_bufi.data(), _bufq.data(), &sampNum, &grChanged, &rfChanged, &fsChanged);
|
|
@@ -258,10 +269,15 @@
|
|
{
|
|
*out++ = gr_complex( float(_bufi[i]) * (1.0f/2048.0f), float(_bufq[i]) * (1.0f/2048.0f) );
|
|
}
|
|
- _buf_offset = cnt;
|
|
- }
|
|
- _buf_mutex.unlock();
|
|
+ _buf_offset = cnt;
|
|
|
|
+ }
|
|
+ int items = sampNum - sampNumStart;
|
|
+ if ( (items + _dev->samplesPerPacket - first_offset - noutput_items) != (_dev->samplesPerPacket - cnt))
|
|
+ {
|
|
+ std::cerr << "Sampling Error! " << "cnt before return = " << cnt << " noutput_items = " << noutput_items << " first_offset = " << first_offset << " buffer_offset = " << _buf_offset << " Items = " << items << " SpP - _buf_offset = " << _dev->samplesPerPacket - _buf_offset << std::endl;
|
|
+ }
|
|
+ _buf_mutex.unlock();
|
|
return noutput_items;
|
|
}
|
|
|