summaryrefslogtreecommitdiff
path: root/gsm-tvoid/src
diff options
context:
space:
mode:
Diffstat (limited to 'gsm-tvoid/src')
-rw-r--r--gsm-tvoid/src/lib/gsm_burst_ff_single.cc118
-rw-r--r--gsm-tvoid/src/lib/gsm_burst_ff_single.h31
-rw-r--r--gsm-tvoid/src/lib/gsm_burst_sink_c.cc141
-rw-r--r--gsm-tvoid/src/lib/gsm_burst_sink_c.h54
4 files changed, 344 insertions, 0 deletions
diff --git a/gsm-tvoid/src/lib/gsm_burst_ff_single.cc b/gsm-tvoid/src/lib/gsm_burst_ff_single.cc
new file mode 100644
index 0000000..ff6c354
--- /dev/null
+++ b/gsm-tvoid/src/lib/gsm_burst_ff_single.cc
@@ -0,0 +1,118 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gsm_burst_ff.h>
+#include <gr_io_signature.h>
+#include <gr_math.h>
+#include <stdio.h>
+#include <gri_mmse_fir_interpolator_cc.h>
+
+gsm_burst_ff_sptr gsm_make_burst_ff (gr_feval_ll *t)
+{
+ return gsm_burst_ff_sptr (new gsm_burst_ff(t));
+}
+
+static const int MIN_IN = 1; // minimum number of input streams
+static const int MAX_IN = 1; // maximum number of input streams
+static const int MIN_OUT = 0; // minimum number of output streams
+static const int MAX_OUT = 1; // maximum number of output streams
+
+gsm_burst_ff::gsm_burst_ff (gr_feval_ll *t) :
+ gsm_burst(t),
+ gr_block( "burst_ff",
+ gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)),
+// gr_make_io_signature (MIN_OUT, MAX_OUT, USEFUL_BITS * sizeof (float)))
+ gr_make_io_signature (0, 0, 0))
+// gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float)))
+{
+
+ set_history(1);
+
+}
+
+gsm_burst_ff::~gsm_burst_ff ()
+{
+}
+
+/*
+void gsm_burst_ff::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ unsigned ninputs = ninput_items_required.size ();
+ for (unsigned i = 0; i < ninputs; i++)
+ ninput_items_required[i] = noutput_items * BBUF_SIZE + history();
+}
+*/
+
+int gsm_burst_ff::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const float *in = (const float *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ int ii=0;
+ //int rval = 0; //default to no output
+ int rval = noutput_items; //default to no output
+
+ //int do_output = output_items.size() > 0 ? 1 : 0;
+ int do_output = 0;
+
+ int n_input = ninput_items[0];
+// fprintf(stderr,"out=%8.8x/#i=%d/#o=%d",(unsigned)out,n_input,noutput_items);
+// fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items);
+
+// while (( rval < noutput_items) && ( ii < n_input ) ) {
+ while ( ii < n_input ) {
+
+ assert(d_bbuf_pos <= BBUF_SIZE );
+
+ if (d_bbuf_pos >= 0) //could have been offset negative. TODO: perhaps better just to add some slack to the buffer
+ d_burst_buffer[d_bbuf_pos] = in[ii];
+
+ d_bbuf_pos++;
+
+ if ( d_bbuf_pos >= BBUF_SIZE ) {
+
+ if (get_burst()) {
+ //found a burst, send to output
+ if (do_output) {
+ //ensure that output data is in range
+ int b = d_burst_start;
+ if (b < 0)
+ b = 0;
+ else if (b >= 2 * MAX_CORR_DIST)
+ b = 2 * MAX_CORR_DIST - 1;
+
+ memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float));
+ }
+ //rval++;
+ //rval += USEFUL_BITS*sizeof(float);
+
+ switch ( d_clock_options & QB_MASK ) {
+ case QB_QUARTER: //Can't do this in the FF version
+ case QB_FULL04: //extra bit on timeslot 0 & 4
+ if (!(d_ts%4))
+ d_bbuf_pos--;
+ break;
+ case QB_NONE: //don't adjust for quarter bits at all
+ default:
+ break;
+ }
+
+ d_last_burst_s_count = d_sample_count;
+
+ }
+ }
+ d_sample_count++;
+ ii++;
+ }
+
+// fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval);
+
+ consume_each (ii);
+
+ return rval;
+}
diff --git a/gsm-tvoid/src/lib/gsm_burst_ff_single.h b/gsm-tvoid/src/lib/gsm_burst_ff_single.h
new file mode 100644
index 0000000..553fe65
--- /dev/null
+++ b/gsm-tvoid/src/lib/gsm_burst_ff_single.h
@@ -0,0 +1,31 @@
+#ifndef INCLUDED_GSM_BURST_FF_H
+#define INCLUDED_GSM_BURST_FF_H
+
+#include <gr_block.h>
+#include <gsm_burst.h>
+
+class gsm_burst_ff;
+
+typedef boost::shared_ptr<gsm_burst_ff> gsm_burst_ff_sptr;
+
+gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *);
+
+class gsm_burst_ff : public gr_block, public gsm_burst
+{
+private:
+
+ friend gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *);
+ gsm_burst_ff(gr_feval_ll *t);
+
+public:
+ ~gsm_burst_ff ();
+
+// void forecast (int noutput_items, gr_vector_int &ninput_items_required);
+
+ int general_work ( int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GSM_BURST_FF_H */
diff --git a/gsm-tvoid/src/lib/gsm_burst_sink_c.cc b/gsm-tvoid/src/lib/gsm_burst_sink_c.cc
new file mode 100644
index 0000000..58787bb
--- /dev/null
+++ b/gsm-tvoid/src/lib/gsm_burst_sink_c.cc
@@ -0,0 +1,141 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gsm_burst_sink_c.h"
+#include <gr_io_signature.h>
+#include <gr_math.h>
+#include <stdio.h>
+#include <gri_mmse_fir_interpolator_cc.h>
+
+gsm_burst_sink_c_sptr gsm_make_burst_sink_c (gr_feval_ll *t,float sample_rate)
+{
+ return gsm_burst_sink_c_sptr (new gsm_burst_sink_c(t,sample_rate));
+}
+
+static const int MIN_IN = 1; // minimum number of input streams
+static const int MAX_IN = 1; // maximum number of input streams
+
+gsm_burst_sink_c::gsm_burst_sink_c (gr_feval_ll *t, float sample_rate) :
+ gsm_burst(t),
+ gr_sync_block ( "burst_sink_c",
+ gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)),
+ gr_make_io_signature (0,0,0)
+ ),
+ d_clock_counter(0.0),
+ d_mu(0.5),
+ d_last_sample(0.0,0.0),
+ d_ii(0),
+ d_interp(new gri_mmse_fir_interpolator_cc())
+
+{
+
+ //clocking parameters
+ d_sample_interval = 1.0 / sample_rate;
+ d_relative_sample_rate = sample_rate / GSM_SYMBOL_RATE;
+
+ fprintf(stderr,"Sample interval : %e\n",d_sample_interval);
+ fprintf(stderr,"Relative sample rate : %g\n",d_relative_sample_rate);
+
+ //we need history for interpolator taps and some saftey relative to relative rate
+ int hist = d_interp->ntaps(); // + 16; // interpolator need -4/+3 samples NTAPS = 8 , 16 for safety margin
+ set_history(hist); //need history for interpolator
+
+}
+
+gsm_burst_sink_c::~gsm_burst_sink_c ()
+{
+ delete d_interp;
+}
+
+void gsm_burst_sink_c::shift_burst(int shift_bits)
+{
+ //fprintf(stderr,"sft:%d\n",shift_bits);
+
+ assert(shift_bits >= 0);
+ assert(shift_bits < BBUF_SIZE );
+
+ gr_complex *p_src = d_complex_burst + shift_bits;
+ gr_complex *p_dst = d_complex_burst;
+ int num = BBUF_SIZE - shift_bits;
+
+ memmove(p_dst,p_src,num * sizeof(gr_complex)); //need memmove because of overlap
+
+ //DON'T adjust the buffer positions, the superclass method will do that...
+ //d_bbuf_pos -= shift_bits;
+ //call the parent method to shift the float version
+ gsm_burst::shift_burst(shift_bits);
+}
+
+//TODO: put everything but GR stuff in a common complex type class (share w/ gsm_burst_cf)
+int gsm_burst_sink_c::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+
+{
+ const gr_complex *in = (const gr_complex *) input_items[0];
+
+// fprintf(stderr,"#o=%d",noutput_items);
+
+ assert( d_ii >= 0 );
+
+ while ( d_ii < noutput_items ) {
+ //clock symbols
+
+ gr_complex sample = d_interp->interpolate (&in[d_ii], d_mu);
+
+ gr_complex conjprod = sample * conj(d_last_sample);
+ float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod));
+
+ d_last_sample = sample;
+
+#if 1
+ assert(d_bbuf_pos <= BBUF_SIZE );
+
+ if (d_bbuf_pos >= 0) { //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer
+ d_burst_buffer[d_bbuf_pos] = diff_angle;
+ d_complex_burst[d_bbuf_pos] = sample;
+ }
+
+ d_bbuf_pos++;
+
+ if ( d_bbuf_pos >= BBUF_SIZE ) {
+ if (get_burst()) {
+ //adjust timing
+ //TODO: generate timing error from burst buffer (phase & freq)
+
+ switch ( d_clock_options & QB_MASK ) {
+ case QB_QUARTER: //extra 1/4 bit each burst
+ d_mu -= d_relative_sample_rate / 4.0;
+ break;
+ case QB_FULL04: //extra bit on timeslot 0 & 4
+ if (!(d_ts%4))
+ d_mu -= d_relative_sample_rate;
+ break;
+ case QB_NONE: //don't adjust for quarter bits at all
+ default:
+ break;
+ }
+
+ d_last_burst_s_count = d_sample_count;
+
+ //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos);
+ }
+ }
+#endif
+
+ d_mu += d_relative_sample_rate;
+ d_ii += (int)floor(d_mu);
+ //d_sample_count += (int)floor(d_mu); //TODO: outside loop?
+ d_mu -= floor(d_mu);
+ }
+
+ //reset d_ii, accounting for advance
+ d_ii -= noutput_items;
+
+// fprintf(stderr,"/mu=%f",d_mu);
+// fprintf(stderr,"/ii=%d\n",d_ii);
+
+ return noutput_items;
+}
diff --git a/gsm-tvoid/src/lib/gsm_burst_sink_c.h b/gsm-tvoid/src/lib/gsm_burst_sink_c.h
new file mode 100644
index 0000000..1197a2c
--- /dev/null
+++ b/gsm-tvoid/src/lib/gsm_burst_sink_c.h
@@ -0,0 +1,54 @@
+#ifndef INCLUDED_gsm_burst_sink_c_H
+#define INCLUDED_gsm_burst_sink_c_H
+
+#include <gr_sync_block.h>
+#include <gsm_burst.h>
+
+class gsm_burst_sink_c;
+
+typedef boost::shared_ptr<gsm_burst_sink_c> gsm_burst_sink_c_sptr;
+
+gsm_burst_sink_c_sptr gsm_make_burst_sink_c(gr_feval_ll *,float);
+
+class gri_mmse_fir_interpolator_cc;
+
+//class gsm_burst_sink_c : public gr_block, public gsm_burst
+class gsm_burst_sink_c : public gr_sync_block, public gsm_burst
+{
+private:
+
+ friend gsm_burst_sink_c_sptr gsm_make_burst_sink_c(gr_feval_ll *,float);
+ gsm_burst_sink_c(gr_feval_ll *,float);
+
+ //clocking parameters
+ double d_sample_interval;
+ double d_clock_counter;
+ gr_complex d_last_sample;
+
+ float d_relative_sample_rate; //omega
+ float d_mu;
+ int d_ii; //save index between work calls for interp advance
+
+ gri_mmse_fir_interpolator_cc *d_interp; //sub-sample interpolator from GR
+
+ gr_complex d_complex_burst[BBUF_SIZE];
+
+ void shift_burst(int shift_bits);
+
+public:
+ ~gsm_burst_sink_c ();
+
+// void forecast (int noutput_items, gr_vector_int &ninput_items_required);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+/* int general_work ( int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+*/
+};
+
+#endif /* INCLUDED_gsm_burst_sink_c_H */
personal git repositories of Harald Welte. Your mileage may vary