[hamradio-commits] [soapyairspy] 01/07: New upstream version 0.1.1
Andreas E. Bombe
aeb at moszumanska.debian.org
Sun Aug 6 22:58:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
aeb pushed a commit to branch master
in repository soapyairspy.
commit ef03ee3365e6174734e6e9717d6a9919bb5ac964
Author: Andreas Bombe <aeb at debian.org>
Date: Thu Jun 29 21:48:19 2017 +0200
New upstream version 0.1.1
---
Changelog.txt | 7 ++
SoapyAirspy.hpp | 16 ++---
Streaming.cpp | 77 ++++++++++------------
debian/changelog | 6 ++
debian/control | 4 +-
...y.install => soapysdr0.6-module-airspy.install} | 0
6 files changed, 57 insertions(+), 53 deletions(-)
diff --git a/Changelog.txt b/Changelog.txt
index 94a1e46..44ff07f 100644
--- a/Changelog.txt
+++ b/Changelog.txt
@@ -1,3 +1,10 @@
+Release 0.1.1 (2017-04-29)
+==========================
+
+- Support native AIRSPY_SAMPLE_INT16_IQ format
+- Use atomics for ring buffer implementation
+- Use Format string constants for stream types
+
Release 0.1.0 (2016-09-01)
==========================
diff --git a/SoapyAirspy.hpp b/SoapyAirspy.hpp
index 96e6289..8730248 100644
--- a/SoapyAirspy.hpp
+++ b/SoapyAirspy.hpp
@@ -34,11 +34,12 @@
#include <string>
#include <cstring>
#include <algorithm>
+#include <atomic>
#include <libairspy/airspy.h>
-#define DEFAULT_BUFFER_LENGTH 2048
-#define DEFAULT_NUM_BUFFERS 6
+#define DEFAULT_BUFFER_BYTES 262144
+#define DEFAULT_NUM_BUFFERS 8
#define MAX_DEVICES 32
class SoapyAirspy: public SoapySDR::Device
@@ -214,8 +215,7 @@ private:
size_t numBuffers;
bool agcMode, streamActive, rfBias;
std::atomic_bool sampleRateChanged;
- int elementsPerSample;
- airspy_sample_type asFormat;
+ int bytesPerSample;
uint8_t lnaGain, mixerGain, vgaGain;
public:
@@ -225,12 +225,12 @@ public:
std::mutex _buf_mutex;
std::condition_variable _buf_cond;
- std::vector<std::vector<float> > _buffs;
+ std::vector<std::vector<char> > _buffs;
size_t _buf_head;
size_t _buf_tail;
- size_t _buf_count;
- float *_currentBuff;
- bool _overflowEvent;
+ std::atomic<size_t> _buf_count;
+ char *_currentBuff;
+ std::atomic<bool> _overflowEvent;
size_t bufferedElems;
size_t _currentHandle;
bool resetBuffer;
diff --git a/Streaming.cpp b/Streaming.cpp
index 207df77..3ba23d9 100644
--- a/Streaming.cpp
+++ b/Streaming.cpp
@@ -24,6 +24,7 @@
#include "SoapyAirspy.hpp"
#include <SoapySDR/Logger.hpp>
+#include <SoapySDR/Formats.hpp>
#include <algorithm> //min
#include <climits> //SHRT_MAX
#include <cstring> // memcpy
@@ -33,15 +34,15 @@ std::vector<std::string> SoapyAirspy::getStreamFormats(const int direction, cons
std::vector<std::string> formats;
// formats.push_back("CS8");
- formats.push_back("CS16");
- formats.push_back("CF32");
+ formats.push_back(SOAPY_SDR_CS16);
+ formats.push_back(SOAPY_SDR_CF32);
return formats;
}
std::string SoapyAirspy::getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const {
fullScale = 65536;
- return "CS16";
+ return SOAPY_SDR_CS16;
}
SoapySDR::ArgInfoList SoapyAirspy::getStreamArgsInfo(const int direction, const size_t channel) const {
@@ -83,8 +84,6 @@ static int _rx_callback(airspy_transfer *t)
int SoapyAirspy::rx_callback(airspy_transfer *t)
{
- std::unique_lock<std::mutex> lock(_buf_mutex);
-
if (sampleRateChanged.load()) {
return 1;
}
@@ -99,12 +98,18 @@ int SoapyAirspy::rx_callback(airspy_transfer *t)
//copy into the buffer queue
auto &buff = _buffs[_buf_tail];
- buff.resize(t->sample_count * elementsPerSample);
- std::memcpy(buff.data(), t->samples, t->sample_count * elementsPerSample * sizeof(float));
+ buff.resize(t->sample_count * bytesPerSample);
+ std::memcpy(buff.data(), t->samples, t->sample_count * bytesPerSample);
//increment the tail pointer
_buf_tail = (_buf_tail + 1) % numBuffers;
- _buf_count++;
+
+ //increment buffers available under lock
+ //to avoid race in acquireReadBuffer wait
+ {
+ std::lock_guard<std::mutex> lock(_buf_mutex);
+ _buf_count++;
+ }
//notify readStream()
_buf_cond.notify_one();
@@ -127,13 +132,13 @@ SoapySDR::Stream *SoapyAirspy::setupStream(
throw std::runtime_error("setupStream invalid channel selection");
}
- asFormat = AIRSPY_SAMPLE_INT16_IQ;
+ airspy_sample_type asFormat = AIRSPY_SAMPLE_INT16_IQ;
//check the format
- if (format == "CF32") {
+ if (format == SOAPY_SDR_CF32) {
SoapySDR_log(SOAPY_SDR_INFO, "Using format CF32.");
asFormat = AIRSPY_SAMPLE_FLOAT32_IQ;
- } else if (format == "CS16") {
+ } else if (format == SOAPY_SDR_CS16) {
SoapySDR_log(SOAPY_SDR_INFO, "Using format CS16.");
asFormat = AIRSPY_SAMPLE_INT16_IQ;
} else {
@@ -142,12 +147,15 @@ SoapySDR::Stream *SoapyAirspy::setupStream(
+ "' -- Only CS16 and CF32 are supported by SoapyAirspy module.");
}
- // TODO: use airspy_set_sample_type(dev, asFormat); when INT16 imlemented
- airspy_set_sample_type(dev, AIRSPY_SAMPLE_FLOAT32_IQ);
+ airspy_set_sample_type(dev, asFormat);
sampleRateChanged.store(true);
- bufferLength = DEFAULT_BUFFER_LENGTH*2;
- elementsPerSample = 2;
+ bytesPerSample = SoapySDR::formatToSize(format);
+
+ //We get this many complex samples over the bus.
+ //Its the same for both complex float and int16.
+ //TODO adjust when packing is enabled
+ bufferLength = DEFAULT_BUFFER_BYTES/4;
//clear async fifo counts
_buf_tail = 0;
@@ -156,8 +164,8 @@ SoapySDR::Stream *SoapyAirspy::setupStream(
//allocate buffers
_buffs.resize(numBuffers);
- for (auto &buff : _buffs) buff.reserve(bufferLength);
- for (auto &buff : _buffs) buff.resize(bufferLength);
+ for (auto &buff : _buffs) buff.reserve(bufferLength*bytesPerSample);
+ for (auto &buff : _buffs) buff.resize(bufferLength*bytesPerSample);
return (SoapySDR::Stream *) this;
}
@@ -169,7 +177,7 @@ void SoapyAirspy::closeStream(SoapySDR::Stream *stream)
size_t SoapyAirspy::getStreamMTU(SoapySDR::Stream *stream) const
{
- return bufferLength / elementsPerSample;
+ return bufferLength;
}
int SoapyAirspy::activateStream(
@@ -238,24 +246,11 @@ int SoapyAirspy::readStream(
size_t returnedElems = std::min(bufferedElems, numElems);
//convert into user's buff0
- if (asFormat == AIRSPY_SAMPLE_FLOAT32_IQ)
- {
- std::memcpy(buff0, _currentBuff, returnedElems * 2 * sizeof(float) );
- }
- else if (asFormat == AIRSPY_SAMPLE_INT16_IQ) // TODO: use actual airspy int samples
- {
- int16_t *itarget = (int16_t *) buff0;
- std::complex<int16_t> tmp;
- for (size_t i = 0; i < returnedElems; i++)
- {
- itarget[i * 2] = int16_t(_currentBuff[i * 2] * 32767.0);
- itarget[i * 2 + 1] = int16_t(_currentBuff[i * 2 + 1] * 32767.0);
- }
- }
+ std::memcpy(buff0, _currentBuff, returnedElems * bytesPerSample);
//bump variables for next call into readStream
bufferedElems -= returnedElems;
- _currentBuff += returnedElems * elementsPerSample;
+ _currentBuff += returnedElems * bytesPerSample;
//return number of elements written to buff0
if (bufferedElems != 0) flags |= SOAPY_SDR_MORE_FRAGMENTS;
@@ -286,15 +281,12 @@ int SoapyAirspy::acquireReadBuffer(
long long &timeNs,
const long timeoutUs)
{
- std::unique_lock <std::mutex> lock(_buf_mutex);
-
//reset is issued by various settings
//to drain old data out of the queue
if (resetBuffer)
{
//drain all buffers from the fifo
- _buf_head = (_buf_head + _buf_count) % numBuffers;
- _buf_count = 0;
+ _buf_head = (_buf_head + _buf_count.exchange(0)) % numBuffers;
resetBuffer = false;
_overflowEvent = false;
}
@@ -303,17 +295,17 @@ int SoapyAirspy::acquireReadBuffer(
if (_overflowEvent)
{
//drain the old buffers from the fifo
- _buf_head = (_buf_head + _buf_count) % numBuffers;
- _buf_count = 0;
+ _buf_head = (_buf_head + _buf_count.exchange(0)) % numBuffers;
_overflowEvent = false;
SoapySDR::log(SOAPY_SDR_SSI, "O");
return SOAPY_SDR_OVERFLOW;
}
//wait for a buffer to become available
- while (_buf_count == 0)
+ if (_buf_count == 0)
{
- _buf_cond.wait_for(lock, std::chrono::microseconds(timeoutUs));
+ std::unique_lock <std::mutex> lock(_buf_mutex);
+ _buf_cond.wait_for(lock, std::chrono::microseconds(timeoutUs), [this]{return _buf_count != 0;});
if (_buf_count == 0) return SOAPY_SDR_TIMEOUT;
}
@@ -324,7 +316,7 @@ int SoapyAirspy::acquireReadBuffer(
flags = 0;
//return number available
- return _buffs[handle].size() / elementsPerSample;
+ return _buffs[handle].size() / bytesPerSample;
}
void SoapyAirspy::releaseReadBuffer(
@@ -332,6 +324,5 @@ void SoapyAirspy::releaseReadBuffer(
const size_t handle)
{
//TODO this wont handle out of order releases
- std::unique_lock <std::mutex> lock(_buf_mutex);
_buf_count--;
}
diff --git a/debian/changelog b/debian/changelog
index f498940..9c039f1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+soapyairspy (0.1.1-1) unstable; urgency=low
+
+ * Release 0.1.1 (2017-04-29)
+
+ -- Josh Blum <josh at pothosware.com> Sat, 29 Apr 2017 15:02:58 -0000
+
soapyairspy (0.1.0) unstable; urgency=low
* Release 0.1.1 (2016-09-01)
diff --git a/debian/control b/debian/control
index 9757abd..221153b 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Homepage: https://github.com/pothosware/SoapyAirspy/wiki
Vcs-Git: https://github.com/pothosware/SoapyAirspy.git
Vcs-Browser: https://github.com/pothosware/SoapyAirspy
-Package: soapysdr0.5-2-module-airspy
+Package: soapysdr0.6-module-airspy
Architecture: any
Multi-Arch: same
Depends: ${shlibs:Depends}, ${misc:Depends}
@@ -22,7 +22,7 @@ Description: Airspy device support for SoapySDR
Package: soapysdr-module-airspy
Architecture: all
-Depends: soapysdr0.5-2-module-airspy, ${misc:Depends}
+Depends: soapysdr0.6-module-airspy, ${misc:Depends}
Description: Airspy device support for SoapySDR (default version)
The Soapy Airspy project provides a SoapySDR hardware support module.
.
diff --git a/debian/soapysdr0.5-2-module-airspy.install b/debian/soapysdr0.6-module-airspy.install
similarity index 100%
rename from debian/soapysdr0.5-2-module-airspy.install
rename to debian/soapysdr0.6-module-airspy.install
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/soapyairspy.git
More information about the pkg-hamradio-commits
mailing list