aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M/radioBuffer.h
diff options
context:
space:
mode:
authorTom Tsou <tom.tsou@ettus.com>2015-08-21 19:32:58 -0700
committerTom Tsou <tom.tsou@ettus.com>2016-07-01 03:03:11 -0700
commit28670fb5dad8e48ff74051a5bbe0c8309b04c817 (patch)
treef93d11d8a26701cdecceebdf40b9fac006c8af03 /Transceiver52M/radioBuffer.h
parent05c6feb71dd2f66b74c9e1671d91570485479836 (diff)
iface: Add inner ring-buffer implementation
Two buffers, inner and outer, are used in the transceiver implementation. The outer buffer interfaces with the device receive interface to guarantee timestamp aligned and contiguously allocated sample buffers. The inner buffer absorbs vector size differences between GSM bursts (156 or 157 samples) and the resampler interface (typically fixed multiples of 65). Reimplement the inner buffer with a ring buffer that allows fixed size segments on the outer (resampler) portion and variable lengths (GSM side) on the inner side. Compared to the previous stack-like version, this implementation removes unnecessary copying of buffer contents. Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
Diffstat (limited to 'Transceiver52M/radioBuffer.h')
-rw-r--r--Transceiver52M/radioBuffer.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/Transceiver52M/radioBuffer.h b/Transceiver52M/radioBuffer.h
new file mode 100644
index 0000000..afb6e63
--- /dev/null
+++ b/Transceiver52M/radioBuffer.h
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+#include <stddef.h>
+#include <vector>
+
+class RadioBuffer {
+public:
+ RadioBuffer(size_t numSegments, size_t segmentLen,
+ size_t hLen, bool outDirection);
+
+ ~RadioBuffer();
+
+ const size_t getSegmentLen() { return segmentLen; };
+ const size_t getNumSegments() { return numSegments; };
+ const size_t getAvailSamples() { return availSamples; };
+ const size_t getAvailSegments() { return availSamples / segmentLen; };
+
+ const size_t getFreeSamples()
+ {
+ return bufferLen - availSamples;
+ }
+
+ const size_t getFreeSegments()
+ {
+ return getFreeSamples() / segmentLen;
+ }
+
+ void reset();
+
+ /* Output direction */
+ const float *getReadSegment();
+ bool write(const float *wr, size_t len);
+ bool zero(size_t len);
+
+ /* Input direction */
+ float *getWriteSegment();
+ bool zeroWriteSegment();
+ bool read(float *rd, size_t len);
+
+private:
+ size_t writeIndex, readIndex, availSamples;
+ size_t bufferLen, numSegments, segmentLen, hLen;
+ float *buffer;
+ std::vector<float *> segments;
+ bool outDirection;
+};