aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tsou <tom@tsou.cc>2015-03-25 15:10:07 -0700
committerTom Tsou <tom@tsou.cc>2015-03-26 16:56:45 -0700
commit4adf4724c366a9eb76bcd810d29ee8753413cec5 (patch)
tree58b9bd41ade9e89f2b99c3b89db02e71691b308d
parentc5b568d49c61bfa70e1837278b65d758668a6dff (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.cc>
-rw-r--r--Transceiver52M/Makefile.am2
-rw-r--r--Transceiver52M/Resampler.cpp19
-rw-r--r--Transceiver52M/Resampler.h3
-rw-r--r--Transceiver52M/radioBuffer.cpp228
-rw-r--r--Transceiver52M/radioBuffer.h45
-rw-r--r--Transceiver52M/radioInterface.cpp198
-rw-r--r--Transceiver52M/radioInterface.h24
-rw-r--r--Transceiver52M/radioInterfaceDiversity.cpp10
-rw-r--r--Transceiver52M/radioInterfaceResamp.cpp81
-rw-r--r--Transceiver52M/signalVector.cpp9
-rw-r--r--Transceiver52M/signalVector.h1
11 files changed, 414 insertions, 206 deletions
diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am
index d0a20f4..bfde2a6 100644
--- a/Transceiver52M/Makefile.am
+++ b/Transceiver52M/Makefile.am
@@ -54,6 +54,7 @@ COMMON_SOURCES = \
radioInterface.cpp \
radioVector.cpp \
radioClock.cpp \
+ radioBuffer.cpp \
sigProcLib.cpp \
signalVector.cpp \
Transceiver.cpp
@@ -72,6 +73,7 @@ noinst_HEADERS = \
radioVector.h \
radioClock.h \
radioDevice.h \
+ radioBuffer.h \
sigProcLib.h \
signalVector.h \
Transceiver.h \
diff --git a/Transceiver52M/Resampler.cpp b/Transceiver52M/Resampler.cpp
index 624b666..7001658 100644
--- a/Transceiver52M/Resampler.cpp
+++ b/Transceiver52M/Resampler.cpp
@@ -167,17 +167,13 @@ void Resampler::computePath()
}
}
-int Resampler::rotate(float *in, size_t in_len, float *out, size_t out_len)
+int Resampler::rotate(const float *in, size_t in_len, float *out, size_t out_len)
{
int n, path;
- int hist_len = filt_len - 1;
if (!check_vec_len(in_len, out_len, p, q))
return -1;
- /* Insert history */
- memcpy(&in[-2 * hist_len], history, hist_len * 2 * sizeof(float));
-
/* Generate output from precomputed input/output paths */
for (size_t i = 0; i < out_len; i++) {
n = in_index[i];
@@ -189,25 +185,15 @@ int Resampler::rotate(float *in, size_t in_len, float *out, size_t out_len)
n, 1, 1, 0);
}
- /* Save history */
- memcpy(history, &in[2 * (in_len - hist_len)],
- hist_len * 2 * sizeof(float));
-
return out_len;
}
bool Resampler::init(float bw)
{
- size_t hist_len = filt_len - 1;
-
/* Filterbank filter internals */
if (initFilters(bw) < 0)
return false;
- /* History buffer */
- history = new float[2 * hist_len];
- memset(history, 0, 2 * hist_len * sizeof(float));
-
/* Precompute filterbank paths */
in_index = new size_t[MAX_OUTPUT_LEN];
out_path = new size_t[MAX_OUTPUT_LEN];
@@ -222,7 +208,7 @@ size_t Resampler::len()
}
Resampler::Resampler(size_t p, size_t q, size_t filt_len)
- : in_index(NULL), out_path(NULL), partitions(NULL), history(NULL)
+ : in_index(NULL), out_path(NULL), partitions(NULL)
{
this->p = p;
this->q = q;
@@ -233,7 +219,6 @@ Resampler::~Resampler()
{
releaseFilters();
- delete history;
delete in_index;
delete out_path;
}
diff --git a/Transceiver52M/Resampler.h b/Transceiver52M/Resampler.h
index cf2defd..c9f9787 100644
--- a/Transceiver52M/Resampler.h
+++ b/Transceiver52M/Resampler.h
@@ -52,7 +52,7 @@ public:
* Input and output vector lengths must of be equal multiples of the
* rational conversion rate denominator and numerator respectively.
*/
- int rotate(float *in, size_t in_len, float *out, size_t out_len);
+ int rotate(const float *in, size_t in_len, float *out, size_t out_len);
/* Get filter length
* @return number of taps in each filter partition
@@ -67,7 +67,6 @@ private:
size_t *out_path;
float **partitions;
- float *history;
bool initFilters(float bw);
void releaseFilters();
diff --git a/Transceiver52M/radioBuffer.cpp b/Transceiver52M/radioBuffer.cpp
new file mode 100644
index 0000000..9e6f079
--- /dev/null
+++ b/Transceiver52M/radioBuffer.cpp
@@ -0,0 +1,228 @@
+/*
+ * Segmented Ring Buffer
+ *
+ * Copyright (C) 2015 Ettus Research LLC
+ *
+ * Author: Tom Tsou <tom@tsou.cc>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
+
+#include <string.h>
+#include <iostream>
+#include "radioBuffer.h"
+
+RadioBuffer::RadioBuffer(size_t numSegments, size_t segmentLen,
+ size_t hLen, bool outDirection)
+ : writeIndex(0), readIndex(0), availSamples(0)
+{
+ if (!outDirection)
+ hLen = 0;
+
+ buffer = new float[2 * (hLen + numSegments * segmentLen)];
+ bufferLen = numSegments * segmentLen;
+
+ segments.resize(numSegments);
+
+ for (size_t i = 0; i < numSegments; i++)
+ segments[i] = &buffer[2 * (hLen + i * segmentLen)];
+
+ this->outDirection = outDirection;
+ this->numSegments = numSegments;
+ this->segmentLen = segmentLen;
+ this->hLen = hLen;
+}
+
+RadioBuffer::~RadioBuffer()
+{
+ delete buffer;
+}
+
+void RadioBuffer::reset()
+{
+ writeIndex = 0;
+ readIndex = 0;
+ availSamples = 0;
+}
+
+/*
+ * Output direction
+ *
+ * Return a pointer to the oldest segment or NULL if a complete segment is not
+ * available.
+ */
+const float *RadioBuffer::getReadSegment()
+{
+ if (!outDirection) {
+ std::cout << "Invalid direction" << std::endl;
+ return NULL;
+ }
+ if (availSamples < segmentLen) {
+ std::cout << "Not enough samples " << std::endl;
+ std::cout << availSamples << " available per segment "
+ << segmentLen << std::endl;
+ return NULL;
+ }
+
+ size_t num = readIndex / segmentLen;
+
+ if (num >= numSegments) {
+ std::cout << "Invalid segment" << std::endl;
+ return NULL;
+ } else if (!num) {
+ memcpy(buffer,
+ &buffer[2 * bufferLen],
+ hLen * 2 * sizeof(float));
+ }
+
+ availSamples -= segmentLen;
+ readIndex = (readIndex + segmentLen) % bufferLen;
+
+ return segments[num];
+}
+
+/*
+ * Output direction
+ *
+ * Write a non-segment length of samples to the buffer.
+ */
+bool RadioBuffer::write(const float *wr, size_t len)
+{
+ if (!outDirection) {
+ std::cout << "Invalid direction" << std::endl;
+ return false;
+ }
+ if (availSamples + len > bufferLen) {
+ std::cout << "Insufficient space" << std::endl;
+ std::cout << bufferLen - availSamples << " available per write "
+ << len << std::endl;
+ return false;
+ }
+
+ if (writeIndex + len <= bufferLen) {
+ memcpy(&buffer[2 * (writeIndex + hLen)],
+ wr, len * 2 * sizeof(float));
+ } else {
+ size_t len0 = bufferLen - writeIndex;
+ size_t len1 = len - len0;
+ memcpy(&buffer[2 * (writeIndex + hLen)], wr, len0 * 2 * sizeof(float));
+ memcpy(&buffer[2 * hLen], &wr[2 * len0], len1 * 2 * sizeof(float));
+ }
+
+ availSamples += len;
+ writeIndex = (writeIndex + len) % bufferLen;
+
+ return true;
+}
+
+bool RadioBuffer::zero(size_t len)
+{
+ if (!outDirection) {
+ std::cout << "Invalid direction" << std::endl;
+ return false;
+ }
+ if (availSamples + len > bufferLen) {
+ std::cout << "Insufficient space" << std::endl;
+ std::cout << bufferLen - availSamples << " available per zero "
+ << len << std::endl;
+ return false;
+ }
+
+ if (writeIndex + len <= bufferLen) {
+ memset(&buffer[2 * (writeIndex + hLen)],
+ 0, len * 2 * sizeof(float));
+ } else {
+ size_t len0 = bufferLen - writeIndex;
+ size_t len1 = len - len0;
+ memset(&buffer[2 * (writeIndex + hLen)], 0, len0 * 2 * sizeof(float));
+ memset(&buffer[2 * hLen], 0, len1 * 2 * sizeof(float));
+ }
+
+ availSamples += len;
+ writeIndex = (writeIndex + len) % bufferLen;
+
+ return true;
+}
+
+/*
+ * Input direction
+ */
+float *RadioBuffer::getWriteSegment()
+{
+ if (outDirection) {
+ std::cout << "Invalid direction" << std::endl;
+ return NULL;
+ }
+ if (bufferLen - availSamples < segmentLen) {
+ std::cout << "Insufficient samples" << std::endl;
+ std::cout << bufferLen - availSamples
+ << " available for segment " << segmentLen
+ << std::endl;
+ return NULL;
+ }
+ if (writeIndex % segmentLen) {
+ std::cout << "Internal segment error" << std::endl;
+ return NULL;
+ }
+
+ size_t num = writeIndex / segmentLen;
+
+ if (num >= numSegments)
+ return NULL;
+
+ availSamples += segmentLen;
+ writeIndex = (writeIndex + segmentLen) % bufferLen;
+
+ return segments[num];
+}
+
+bool RadioBuffer::zeroWriteSegment()
+{
+ float *segment = getWriteSegment();
+ if (!segment)
+ return false;
+
+ memset(segment, 0, segmentLen * 2 * sizeof(float));
+
+ return true;
+}
+
+bool RadioBuffer::read(float *rd, size_t len)
+{
+ if (outDirection) {
+ std::cout << "Invalid direction" << std::endl;
+ return false;
+ }
+ if (availSamples < len) {
+ std::cout << "Insufficient samples" << std::endl;
+ std::cout << availSamples << " available for "
+ << len << std::endl;
+ return false;
+ }
+
+ if (readIndex + len <= bufferLen) {
+ memcpy(rd, &buffer[2 * readIndex], len * 2 * sizeof(float));
+ } else {
+ size_t len0 = bufferLen - readIndex;
+ size_t len1 = len - len0;
+ memcpy(rd, &buffer[2 * readIndex], len0 * 2 * sizeof(float));
+ memcpy(&rd[2 * len0], buffer, len1 * 2 * sizeof(float));
+ }
+
+ availSamples -= len;
+ readIndex = (readIndex + len) % bufferLen;
+
+ return true;
+}
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;
+};
diff --git a/Transceiver52M/radioInterface.cpp b/Transceiver52M/radioInterface.cpp
index 369f2ac..47ca029 100644
--- a/Transceiver52M/radioInterface.cpp
+++ b/Transceiver52M/radioInterface.cpp
@@ -1,26 +1,23 @@
/*
-* Copyright 2008, 2009 Free Software Foundation, Inc.
-*
-* This software is distributed under the terms of the GNU Affero Public License.
-* See the COPYING file in the main directory for details.
-*
-* This use of this software may be subject to additional restrictions.
-* See the LEGAL file in the main directory for details.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
+ * Radio device interface
+ *
+ * Copyright (C) 2008-2014 Free Software Foundation, Inc.
+ * Copyright (C) 2015 Ettus Research LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
#include "radioInterface.h"
#include "Resampler.h"
@@ -37,7 +34,7 @@ RadioInterface::RadioInterface(RadioDevice *wRadio,
size_t sps, size_t chans, size_t diversity,
int wReceiveOffset, GSM::Time wStartTime)
: mRadio(wRadio), mSPSTx(sps), mSPSRx(1), mChans(chans), mMIMO(diversity),
- sendCursor(0), recvCursor(0), underrun(false), overrun(false),
+ underrun(false), overrun(false),
receiveOffset(wReceiveOffset), mOn(false)
{
mClock.set(wStartTime);
@@ -65,33 +62,18 @@ bool RadioInterface::init(int type)
powerScaling.resize(mChans);
for (size_t i = 0; i < mChans; i++) {
- sendBuffer[i] = new signalVector(CHUNK * mSPSTx);
- recvBuffer[i] = new signalVector(NUMCHUNKS * CHUNK * mSPSRx);
+ sendBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSTx, 0, true);
+ recvBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSRx, 0, false);
- convertSendBuffer[i] = new short[sendBuffer[i]->size() * 2];
- convertRecvBuffer[i] = new short[recvBuffer[i]->size() * 2];
+ convertSendBuffer[i] = new short[CHUNK * mSPSTx * 2];
+ convertRecvBuffer[i] = new short[CHUNK * mSPSRx * 2];
}
- sendCursor = 0;
- recvCursor = 0;
-
return true;
}
void RadioInterface::close()
{
- for (size_t i = 0; i < sendBuffer.size(); i++)
- delete sendBuffer[i];
-
- for (size_t i = 0; i < recvBuffer.size(); i++)
- delete recvBuffer[i];
-
- for (size_t i = 0; i < convertSendBuffer.size(); i++)
- delete convertSendBuffer[i];
-
- for (size_t i = 0; i < convertRecvBuffer.size(); i++)
- delete convertRecvBuffer[i];
-
sendBuffer.resize(0);
recvBuffer.resize(0);
convertSendBuffer.resize(0);
@@ -130,35 +112,26 @@ int RadioInterface::setPowerAttenuation(int atten, size_t chan)
}
int RadioInterface::radioifyVector(signalVector &wVector,
- float *retVector,
- bool zero)
+ size_t chan, bool zero)
{
- if (zero) {
- memset(retVector, 0, wVector.size() * 2 * sizeof(float));
- return wVector.size();
- }
-
- memcpy(retVector, wVector.begin(), wVector.size() * 2 * sizeof(float));
+ if (zero)
+ sendBuffer[chan]->zero(wVector.size());
+ else
+ sendBuffer[chan]->write((float *) wVector.begin(), wVector.size());
return wVector.size();
}
-int RadioInterface::unRadioifyVector(float *floatVector,
- signalVector& newVector)
+int RadioInterface::unRadioifyVector(signalVector *newVector, size_t chan)
{
- signalVector::iterator itr = newVector.begin();
-
- if (newVector.size() > recvCursor) {
+ if (newVector->size() > recvBuffer[chan]->getAvailSamples()) {
LOG(ALERT) << "Insufficient number of samples in receive buffer";
return -1;
}
- for (size_t i = 0; i < newVector.size(); i++) {
- *itr++ = Complex<float>(floatVector[2 * i + 0],
- floatVector[2 * i + 1]);
- }
+ recvBuffer[chan]->read((float *) newVector->begin(), newVector->size());
- return newVector.size();
+ return newVector->size();
}
bool RadioInterface::tuneTx(double freq, size_t chan)
@@ -185,6 +158,11 @@ bool RadioInterface::start()
if (!mRadio->start())
return false;
+ for (size_t i = 0; i < mChans; i++) {
+ sendBuffer[i]->reset();
+ recvBuffer[i]->reset();
+ }
+
writeTimestamp = mRadio->initialWriteTimestamp();
readTimestamp = mRadio->initialReadTimestamp();
@@ -234,14 +212,10 @@ void RadioInterface::driveTransmitRadio(std::vector<signalVector *> &bursts,
if (!mOn)
return;
- for (size_t i = 0; i < mChans; i++) {
- radioifyVector(*bursts[i],
- (float *) (sendBuffer[i]->begin() + sendCursor), zeros[i]);
- }
-
- sendCursor += bursts[0]->size();
+ for (size_t i = 0; i < mChans; i++)
+ radioifyVector(*bursts[i], i, zeros[i]);
- pushBuffer();
+ while (pushBuffer());
}
bool RadioInterface::driveReceiveRadio()
@@ -256,8 +230,7 @@ bool RadioInterface::driveReceiveRadio()
GSM::Time rcvClock = mClock.get();
rcvClock.decTN(receiveOffset);
unsigned tN = rcvClock.TN();
- int recvSz = recvCursor;
- int readSz = 0;
+ int recvSz = recvBuffer[0]->getAvailSamples();
const int symbolsPerSlot = gSlotLen + 8;
int burstSize = (symbolsPerSlot + (tN % 4 == 0)) * mSPSRx;
@@ -274,13 +247,15 @@ bool RadioInterface::driveReceiveRadio()
while (recvSz > burstSize) {
for (size_t i = 0; i < mChans; i++) {
burst = new radioVector(rcvClock, burstSize, head, mMIMO);
-
+#if 0
for (size_t n = 0; n < mMIMO; n++) {
unRadioifyVector((float *)
(recvBuffer[mMIMO * i + n]->begin() + readSz),
*burst->getVector(n));
}
-
+#else
+ unRadioifyVector(burst->getVector(0), i);
+#endif
if (mReceiveFIFO[i].size() < 32)
mReceiveFIFO[i].write(burst);
else
@@ -289,7 +264,6 @@ bool RadioInterface::driveReceiveRadio()
mClock.incTN();
rcvClock.incTN();
- readSz += burstSize;
recvSz -= burstSize;
tN = rcvClock.TN();
@@ -297,16 +271,6 @@ bool RadioInterface::driveReceiveRadio()
burstSize = (symbolsPerSlot + (tN % 4 == 0)) * mSPSRx;
}
- if (readSz > 0) {
- for (size_t i = 0; i < recvBuffer.size(); i++) {
- memmove(recvBuffer[i]->begin(),
- recvBuffer[i]->begin() + readSz,
- (recvCursor - readSz) * 2 * sizeof(float));
- }
-
- recvCursor -= readSz;
- }
-
return true;
}
@@ -328,74 +292,66 @@ VectorFIFO* RadioInterface::receiveFIFO(size_t chan)
double RadioInterface::setRxGain(double dB, size_t chan)
{
- if (mRadio)
- return mRadio->setRxGain(dB, chan);
- else
- return -1;
+ return mRadio->setRxGain(dB, chan);
}
double RadioInterface::getRxGain(size_t chan)
{
- if (mRadio)
- return mRadio->getRxGain(chan);
- else
- return -1;
+ return mRadio->getRxGain(chan);
}
/* Receive a timestamped chunk from the device */
void RadioInterface::pullBuffer()
{
bool local_underrun;
- int num_recv;
- float *output;
+ size_t numRecv, segmentLen = recvBuffer[0]->getSegmentLen();
- if (recvCursor > recvBuffer[0]->size() - CHUNK)
+ if (recvBuffer[0]->getFreeSegments() <= 0)
return;
/* Outer buffer access size is fixed */
- num_recv = mRadio->readSamples(convertRecvBuffer,
- CHUNK,
- &overrun,
- readTimestamp,
- &local_underrun);
- if (num_recv != CHUNK) {
- LOG(ALERT) << "Receive error " << num_recv;
+ numRecv = mRadio->readSamples(convertRecvBuffer,
+ segmentLen,
+ &overrun,
+ readTimestamp,
+ &local_underrun);
+
+ if (numRecv != segmentLen) {
+ LOG(ALERT) << "Receive error " << numRecv;
return;
}
for (size_t i = 0; i < mChans; i++) {
- output = (float *) (recvBuffer[i]->begin() + recvCursor);
- convert_short_float(output, convertRecvBuffer[i], 2 * num_recv);
+ convert_short_float(recvBuffer[i]->getWriteSegment(),
+ convertRecvBuffer[i],
+ segmentLen * 2);
}
underrun |= local_underrun;
-
- readTimestamp += num_recv;
- recvCursor += num_recv;
+ readTimestamp += numRecv;
}
/* Send timestamped chunk to the device with arbitrary size */
-void RadioInterface::pushBuffer()
+bool RadioInterface::pushBuffer()
{
- int num_sent;
+ size_t numSent, segmentLen = sendBuffer[0]->getSegmentLen();
- if (sendCursor < CHUNK)
- return;
-
- if (sendCursor > sendBuffer[0]->size())
- LOG(ALERT) << "Send buffer overflow";
+ if (sendBuffer[0]->getAvailSegments() < 1)
+ return false;
for (size_t i = 0; i < mChans; i++) {
convert_float_short(convertSendBuffer[i],
- (float *) sendBuffer[i]->begin(),
- powerScaling[i], 2 * sendCursor);
+ (float *) sendBuffer[0]->getReadSegment(),
+ powerScaling[i],
+ segmentLen * 2);
}
- /* Send the all samples in the send buffer */
- num_sent = mRadio->writeSamples(convertSendBuffer,
- sendCursor,
- &underrun,
- writeTimestamp);
- writeTimestamp += num_sent;
- sendCursor = 0;
+ /* Send the all samples in the send buffer */
+ numSent = mRadio->writeSamples(convertSendBuffer,
+ segmentLen,
+ &underrun,
+ writeTimestamp);
+ writeTimestamp += numSent;
+
+ return true;
}
diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h
index b359cbd..d5d65aa 100644
--- a/Transceiver52M/radioInterface.h
+++ b/Transceiver52M/radioInterface.h
@@ -20,6 +20,7 @@
#include "radioDevice.h"
#include "radioVector.h"
#include "radioClock.h"
+#include "radioBuffer.h"
#include "Resampler.h"
static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
@@ -40,10 +41,8 @@ protected:
size_t mChans;
size_t mMIMO;
- std::vector<signalVector *> sendBuffer;
- std::vector<signalVector *> recvBuffer;
- unsigned sendCursor;
- unsigned recvCursor;
+ std::vector<RadioBuffer *> sendBuffer;
+ std::vector<RadioBuffer *> recvBuffer;
std::vector<short *> convertRecvBuffer;
std::vector<short *> convertSendBuffer;
@@ -61,16 +60,14 @@ protected:
private:
- /** format samples to USRP */
- int radioifyVector(signalVector &wVector,
- float *floatVector,
- bool zero);
+ /** format samples to USRP */
+ int radioifyVector(signalVector &wVector, size_t chan, bool zero);
/** format samples from USRP */
- int unRadioifyVector(float *floatVector, signalVector &wVector);
+ int unRadioifyVector(signalVector *wVector, size_t chan);
/** push GSM bursts into the transmit buffer */
- virtual void pushBuffer(void);
+ virtual bool pushBuffer(void);
/** pull GSM bursts from the receive buffer */
virtual void pullBuffer(void);
@@ -151,20 +148,15 @@ void *AlignRadioServiceLoopAdapter(RadioInterface*);
#endif
class RadioInterfaceResamp : public RadioInterface {
-
private:
- signalVector *innerSendBuffer;
signalVector *outerSendBuffer;
- signalVector *innerRecvBuffer;
signalVector *outerRecvBuffer;
- void pushBuffer();
+ bool pushBuffer();
void pullBuffer();
public:
-
RadioInterfaceResamp(RadioDevice* wRadio, size_t wSPS = 4, size_t chans = 1);
-
~RadioInterfaceResamp();
bool init(int type);
diff --git a/Transceiver52M/radioInterfaceDiversity.cpp b/Transceiver52M/radioInterfaceDiversity.cpp
index 8e921b1..c208288 100644
--- a/Transceiver52M/radioInterfaceDiversity.cpp
+++ b/Transceiver52M/radioInterfaceDiversity.cpp
@@ -45,10 +45,12 @@ extern "C" {
*/
#define RESAMP_TX4_FILTER 0.45
+#if 0
static size_t resamp_inrate = 0;
static size_t resamp_inchunk = 0;
static size_t resamp_outrate = 0;
static size_t resamp_outchunk = 0;
+#endif
RadioInterfaceDiversity::RadioInterfaceDiversity(RadioDevice *wRadio,
size_t sps, size_t chans)
@@ -81,6 +83,7 @@ void RadioInterfaceDiversity::close()
bool RadioInterfaceDiversity::setupDiversityChannels()
{
+#if 0
size_t inner_rx_len;
/* Inner and outer rates */
@@ -108,13 +111,14 @@ bool RadioInterfaceDiversity::setupDiversityChannels()
recvBuffer[i] = new signalVector(inner_rx_len);
}
-
+#endif
return true;
}
/* Initialize I/O specific objects */
bool RadioInterfaceDiversity::init(int type)
{
+#if 0
int tx_len, outer_rx_len;
if ((mMIMO != 2) || (mChans != 2)) {
@@ -147,7 +151,7 @@ bool RadioInterfaceDiversity::init(int type)
}
outerRecvBuffer = new signalVector(outer_rx_len, dnsamplers[0]->len());
-
+#endif
return true;
}
@@ -177,6 +181,7 @@ bool RadioInterfaceDiversity::tuneRx(double freq, size_t chan)
/* Receive a timestamped chunk from the device */
void RadioInterfaceDiversity::pullBuffer()
{
+#if 0
bool local_underrun;
int rc, num, path0, path1;
signalVector *shift, *base;
@@ -245,4 +250,5 @@ void RadioInterfaceDiversity::pullBuffer()
underrun |= local_underrun;
readTimestamp += (TIMESTAMP) resamp_outchunk;
recvCursor += resamp_inchunk;
+#endif
}
diff --git a/Transceiver52M/radioInterfaceResamp.cpp b/Transceiver52M/radioInterfaceResamp.cpp
index f898d65..26dd40b 100644
--- a/Transceiver52M/radioInterfaceResamp.cpp
+++ b/Transceiver52M/radioInterfaceResamp.cpp
@@ -1,8 +1,10 @@
/*
* Radio device interface with sample rate conversion
- * Written by Thomas Tsou <tom@tsou.cc>
*
- * Copyright 2011, 2012, 2013 Free Software Foundation, Inc.
+ * Copyright (C) 2011-2014 Free Software Foundation, Inc.
+ * Copyright (C) 2015 Ettus Research LLC
+ *
+ * Author: Tom Tsou <tom@tsou.cc>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -58,8 +60,8 @@ static size_t resamp_outchunk = 0;
RadioInterfaceResamp::RadioInterfaceResamp(RadioDevice *wRadio,
size_t sps, size_t chans)
: RadioInterface(wRadio, sps, chans),
- innerSendBuffer(NULL), outerSendBuffer(NULL),
- innerRecvBuffer(NULL), outerRecvBuffer(NULL)
+ outerSendBuffer(NULL),
+ outerRecvBuffer(NULL)
{
}
@@ -70,17 +72,13 @@ RadioInterfaceResamp::~RadioInterfaceResamp()
void RadioInterfaceResamp::close()
{
- delete innerSendBuffer;
delete outerSendBuffer;
- delete innerRecvBuffer;
delete outerRecvBuffer;
delete upsampler;
delete dnsampler;
- innerSendBuffer = NULL;
outerSendBuffer = NULL;
- innerRecvBuffer = NULL;
outerRecvBuffer = NULL;
upsampler = NULL;
@@ -157,21 +155,18 @@ bool RadioInterfaceResamp::init(int type)
* and requires headroom equivalent to the filter length. Low
* rate buffers are allocated in the main radio interface code.
*/
- innerSendBuffer =
- new signalVector(NUMCHUNKS * resamp_inchunk, upsampler->len());
+ sendBuffer[0] = new RadioBuffer(NUMCHUNKS, resamp_inchunk,
+ upsampler->len(), true);
+ recvBuffer[0] = new RadioBuffer(NUMCHUNKS * 20, resamp_inchunk, 0, false);
+
outerSendBuffer =
new signalVector(NUMCHUNKS * resamp_outchunk);
outerRecvBuffer =
new signalVector(resamp_outchunk, dnsampler->len());
- innerRecvBuffer =
- new signalVector(NUMCHUNKS * resamp_inchunk / mSPSTx);
convertSendBuffer[0] = new short[outerSendBuffer->size() * 2];
convertRecvBuffer[0] = new short[outerRecvBuffer->size() * 2];
- sendBuffer[0] = innerSendBuffer;
- recvBuffer[0] = innerRecvBuffer;
-
return true;
}
@@ -181,7 +176,7 @@ void RadioInterfaceResamp::pullBuffer()
bool local_underrun;
int rc, num_recv;
- if (recvCursor > innerRecvBuffer->size() - resamp_inchunk)
+ if (recvBuffer[0]->getFreeSegments() <= 0)
return;
/* Outer buffer access size is fixed */
@@ -204,57 +199,47 @@ void RadioInterfaceResamp::pullBuffer()
/* Write to the end of the inner receive buffer */
rc = dnsampler->rotate((float *) outerRecvBuffer->begin(),
resamp_outchunk,
- (float *) (innerRecvBuffer->begin() + recvCursor),
+ recvBuffer[0]->getWriteSegment(),
resamp_inchunk);
if (rc < 0) {
LOG(ALERT) << "Sample rate upsampling error";
}
- recvCursor += resamp_inchunk;
+ /* Set history for the next chunk */
+ outerRecvBuffer->updateHistory();
}
/* Send a timestamped chunk to the device */
-void RadioInterfaceResamp::pushBuffer()
+bool RadioInterfaceResamp::pushBuffer()
{
- int rc, chunks, num_sent;
- int inner_len, outer_len;
-
- if (sendCursor < resamp_inchunk)
- return;
-
- if (sendCursor > innerSendBuffer->size())
- LOG(ALERT) << "Send buffer overflow";
+ int rc;
+ size_t numSent;
- chunks = sendCursor / resamp_inchunk;
-
- inner_len = chunks * resamp_inchunk;
- outer_len = chunks * resamp_outchunk;
+ if (sendBuffer[0]->getAvailSegments() <= 0)
+ return false;
/* Always send from the beginning of the buffer */
- rc = upsampler->rotate((float *) innerSendBuffer->begin(), inner_len,
- (float *) outerSendBuffer->begin(), outer_len);
+ rc = upsampler->rotate(sendBuffer[0]->getReadSegment(),
+ resamp_inchunk,
+ (float *) outerSendBuffer->begin(),
+ resamp_outchunk);
if (rc < 0) {
LOG(ALERT) << "Sample rate downsampling error";
}
convert_float_short(convertSendBuffer[0],
(float *) outerSendBuffer->begin(),
- powerScaling[0], 2 * outer_len);
-
- num_sent = mRadio->writeSamples(convertSendBuffer,
- outer_len,
- &underrun,
- writeTimestamp);
- if (num_sent != outer_len) {
- LOG(ALERT) << "Transmit error " << num_sent;
+ powerScaling[0], 2 * resamp_outchunk);
+
+ numSent = mRadio->writeSamples(convertSendBuffer,
+ resamp_outchunk,
+ &underrun,
+ writeTimestamp);
+ if (numSent != resamp_outchunk) {
+ LOG(ALERT) << "Transmit error " << numSent;
}
- /* Shift remaining samples to beginning of buffer */
- memmove(innerSendBuffer->begin(),
- innerSendBuffer->begin() + inner_len,
- (sendCursor - inner_len) * 2 * sizeof(float));
+ writeTimestamp += resamp_outchunk;
- writeTimestamp += outer_len;
- sendCursor -= inner_len;
- assert(sendCursor >= 0);
+ return true;
}
diff --git a/Transceiver52M/signalVector.cpp b/Transceiver52M/signalVector.cpp
index 4b4099e..798a3c7 100644
--- a/Transceiver52M/signalVector.cpp
+++ b/Transceiver52M/signalVector.cpp
@@ -50,6 +50,15 @@ size_t signalVector::getStart() const
return mStart - mData;
}
+size_t signalVector::updateHistory()
+{
+ size_t num = getStart();
+
+ memmove(mData, mStart + this->size() - num, num * sizeof(complex));
+
+ return num;
+}
+
Symmetry signalVector::getSymmetry() const
{
return symmetry;
diff --git a/Transceiver52M/signalVector.h b/Transceiver52M/signalVector.h
index c9cb105..38541fe 100644
--- a/Transceiver52M/signalVector.h
+++ b/Transceiver52M/signalVector.h
@@ -32,6 +32,7 @@ public:
/** Return head room */
size_t getStart() const;
+ size_t updateHistory();
Symmetry getSymmetry() const;
void setSymmetry(Symmetry symmetry);