Transceiver52M: Add dual channel diversity receiver option

This patch add support for dual channel diversity on the receive
path. This allows two antennas two shared antennas to be used for
each ARFCN handling channel in the receiver. This configuration
may improvde performance in multi-path fading environments,
however, noise andpotential interference levels are increased due
to the higher bandwidth used.

The receive path is oversampled by a factor of four for a rate
of 1.083333 Msps. If the receive paths are tuned within a
maximum channel spacing (currently set at 600 kHz), then both
ARFCN frequencies are processed by each channel of the receiver.
Otherwise, the frequency shifted diversity path is disabled and
standard non-diversity operation takes place.

Diversity processing is handled by selecting the path with the
higheset energy level and discarding the burst on the second
path. Selection occurs on a burst-by-burst basis.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h
index 124cdc3..95ef2b2 100644
--- a/Transceiver52M/radioInterface.h
+++ b/Transceiver52M/radioInterface.h
@@ -20,6 +20,7 @@
 #include "radioDevice.h"
 #include "radioVector.h"
 #include "radioClock.h"
+#include "Resampler.h"
 
 static const unsigned gSlotLen = 148;      ///< number of symbols per slot, not counting guard periods
 
@@ -37,6 +38,8 @@
   size_t mSPSTx;
   size_t mSPSRx;
   size_t mChans;
+  size_t mMIMO;
+
   std::vector<signalVector *> sendBuffer;
   std::vector<signalVector *> recvBuffer;
   unsigned sendCursor;
@@ -89,9 +92,8 @@
 
   /** constructor */
   RadioInterface(RadioDevice* wRadio = NULL,
-		 int receiveOffset = 3,
-		 size_t sps = 4, size_t chans = 1,
-		 GSM::Time wStartTime = GSM::Time(0));
+                 size_t sps = 4, size_t chans = 1, size_t diversity = 1,
+                 int receiveOffset = 3, GSM::Time wStartTime = GSM::Time(0));
 
   /** destructor */
   virtual ~RadioInterface();
@@ -109,7 +111,7 @@
   bool tuneTx(double freq, size_t chan = 0);
 
   /** set receive frequency */
-  bool tuneRx(double freq, size_t chan = 0);
+  virtual bool tuneRx(double freq, size_t chan = 0);
 
   /** set receive gain */
   double setRxGain(double dB, size_t chan = 0);
@@ -166,13 +168,33 @@
 
 public:
 
-  RadioInterfaceResamp(RadioDevice* wRadio = NULL,
-		       int receiveOffset = 3,
-		       size_t wSPS = 4, size_t chans = 1,
-		       GSM::Time wStartTime = GSM::Time(0));
+  RadioInterfaceResamp(RadioDevice* wRadio, size_t wSPS = 4, size_t chans = 1);
 
   ~RadioInterfaceResamp();
 
   bool init(int type);
   void close();
 };
+
+class RadioInterfaceDiversity : public RadioInterface {
+public:
+  RadioInterfaceDiversity(RadioDevice* wRadio,
+                          size_t sps = 4, size_t chans = 2);
+
+  ~RadioInterfaceDiversity();
+
+  bool init(int type);
+  void close();
+  bool tuneRx(double freq, size_t chan);
+
+private:
+  std::vector<Resampler *> dnsamplers;
+  std::vector<float> phases;
+  signalVector *outerRecvBuffer;
+
+  bool mDiversity;
+  double mFreqSpacing;
+
+  bool setupDiversityChannels();
+  void pullBuffer();
+};