summaryrefslogtreecommitdiff
path: root/gsm-tvoid/src/lib/gsm_burst_ff.cc
blob: 2980829ca98b9c2596f811368cacc5217a46eba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

#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 ()
{
  return gsm_burst_ff_sptr (new gsm_burst_ff());
}

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 = 1;	// minimum number of output streams
static const int MAX_OUT = 1;	// maximum number of output streams

gsm_burst_ff::gsm_burst_ff () : 
	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)))
{
		
	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 n_input = ninput_items[0];
	//fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items);

	while (( rval < noutput_items) && ( 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

				//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++;

				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;
}
personal git repositories of Harald Welte. Your mileage may vary