11 #ifndef __TwoBit1or2_h
12 #define __TwoBit1or2_h
16 #include "dsp/TwoBitLookup.h"
21 class TwoBit1or2 :
public TwoBitLookup
32 void nlow_build (TwoBitTable* table);
35 void get_lookup_block (
float* lookup, TwoBitTable* table);
38 unsigned get_lookup_block_size ();
44 std::vector<unsigned char> temp_values;
60 template<
class Iterator,
class Mask>
61 inline void operator() (Iterator& from,
Mask& mask,
62 unsigned char* to,
unsigned n)
64 for (
unsigned i=0; i<n; i++)
77 template<
class Iterator,
class Mask>
78 inline void operator() (Iterator& from, Mask& mask,
79 unsigned char* to,
unsigned n)
81 const unsigned n2 = n >> 1;
82 for (
unsigned i=0; i<n2; i++)
84 to[i*2] = mask (*from, 0);
85 to[i*2+1] = mask (*from, 1);
96 template<
unsigned N,
class Mask>
97 class TwoBit :
public TwoBit1or2
100 TwoBitToChar<N> unpacker;
106 static const unsigned samples_per_byte;
107 static const unsigned lookup_block_size;
111 template<
class Iterator>
112 inline void prepare (Iterator& input,
unsigned ndat)
114 temp_values.resize (ndat);
117 std::cerr <<
"TwoBit<" << N <<
">::prepare ndat=" << ndat << std::endl;
120 unpacker (input, mask, &(temp_values[0]), ndat);
126 for (
unsigned idat=0; idat < ndat; idat++)
128 nlow += nlow_lookup[ temp_values[idat] ];
129 total += temp_values[idat];
135 template<
class Iterator>
136 inline void unpack (
const Iterator& input,
unsigned ndat,
137 float* output,
unsigned output_incr,
unsigned& _nlow)
144 std::cerr <<
"TwoBit<" << N <<
">::unpack ndat=" << ndat
145 <<
" nlow=" << nlow <<
" nlow_min=" << nlow_min << std::endl;
148 if (nlow < nlow_min || nlow > nlow_max)
151 float* fourval = lookup_base + (nlow-nlow_min) * lookup_block_size;
153 for (
unsigned idat=0; idat < ndat; idat++)
154 output[idat*output_incr] = fourval[ temp_values[idat] ];
159 template<
unsigned N,
class Mask>
162 template<
unsigned N,
class Mask>