summaryrefslogtreecommitdiff
path: root/gsm-receiver/src/lib/decoder/openbtsstuff/GSML1FEC.h
blob: ce9b5d4dc5a79aba64f8cc48ae2c9ed345d6c25e (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU 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 General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*/



#ifndef GSML1FEC_H
#define GSML1FEC_H

//#include "Threads.h"
#include "Assert.h"
#include "BitVector.h"

#include "GSMCommon.h"
//#include "GSMTransfer.h"
#include "GSMTDMA.h"
#include "VocoderFrame.h"
#include "RxBurst.h"
//#include "GSM610Tables.h"
#include <stdio.h>



namespace GSM
{


//class SAPMux;
  class L1FEC;
  class L1Decoder;



  /*
   Naming convention for bit vectors follows GSM 05.03 Section 2.2.
   d[k]  data
   u[k]  data bits after first encoding step
   c[k]  data bits after second encoding step
   i[B][k]  interleaved data bits
   e[B][k]  bits in a burst
  */


  enum TCHMode {
    MODE_SPEECH_FR,
    MODE_SPEECH_EFR,
  };


  /** L1 decoder used for full rate TCH and FACCH -- mostly from GSM 05.03 3.1 and 4.2 */
//: public XCCHL1Decoder
  class TCHFACCHL1Decoder
  {

    protected:
      SoftVector mI[8]; ///< deinterleaving history, 8 blocks instead of 4
      SoftVector mC;    ///< c[], as per GSM 05.03 2.2
      BitVector mTCHU;     ///< u[] (uncoded) in the spec
      BitVector mTCHD;     ///< d[] (data) in the spec
      SoftVector mClass1_c;    ///< the class 1 part of c[]
      BitVector mClass1A_d;    ///< the class 1A part of d[]
      SoftVector mClass2_c;    ///< the class 2 part of c[]
      ViterbiR2O4 mVCoder;

      VocoderFrame mVFrame;    ///< buffer for FR vocoder frame
      VocoderAMRFrame mVFrameAMR; ///< buffer for EFR vocoder frame packed in AMR container
      unsigned char mPrevGoodFrame[33]; ///< previous good frame.
      unsigned int  mPrevGoodFrameLength;

      Parity mTCHParity;
      const TDMAMapping& mMapping; ///< multiplexing description

// InterthreadQueue<unsigned char> mSpeechQ;     ///< output queue for speech frames

      static const unsigned mMaxQSize = 3;

      enum TCHMode mMode;

    public:

      TCHFACCHL1Decoder( const TDMAMapping& wMapping );

      ChannelType channelType() const {
        return FACCHType;
      }

      enum TCHMode mode() const {
        return mMode;
      }

      void setMode(enum TCHMode mode) {
        mMode = mode;
      }
 

      /** TCH/FACCH has a special-case writeLowSide. */
      void writeLowSide(const RxBurst& inBurst);

      /**
       Unlike other DCCHs, TCH/FACCH process burst calls
       deinterleave, decode, handleGoodFrame.
      */
      bool processBurst( const RxBurst& );

      /** Deinterleave i[] to c[].  */
      void deinterleave(int blockOffset );

      void replaceFACCH( int blockOffset );

      /**
       Decode a traffic frame from TCHI[] and enqueue it.
       Return true if there's a good frame.
      */
      bool decodeTCH(bool stolen);

      unsigned char * get_voice_frame(){
        return mPrevGoodFrame;
      }
      unsigned int get_voice_frame_length(){
        return mPrevGoodFrameLength;
      }
      /**
       Receive a traffic frame.
       Non-blocking.  Returns NULL if queue is dry.
       Caller is responsible for deleting the returned array.
      */
// unsigned char *recvTCH() { return mSpeechQ.read(0); }

      /** Return count of internally-queued traffic frames. */
// unsigned queueSize() const { return mSpeechQ.size(); }

  };






};  // namespace GSM





#endif

// vim: ts=4 sw=4
personal git repositories of Harald Welte. Your mileage may vary