GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
lfsr_32k.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GRI_LFSR_32k_H
12 #define INCLUDED_GRI_LFSR_32k_H
13 
14 #include <gnuradio/blocks/api.h>
16 
17 namespace gr {
18 namespace blocks {
19 
20 /*!
21  * \brief generate pseudo-random sequence of length 32768 bits.
22  * \ingroup misc
23  *
24  * \details
25  * This is based on gri_lfsr_15_1_0 with an extra 0 added at the
26  * end of the sequence.
27  */
29 {
30 private:
31  lfsr_15_1_0 d_lfsr;
32  unsigned int d_count;
33 
34 public:
35  lfsr_32k() { reset(); }
36 
37  void reset()
38  {
39  d_lfsr.reset();
40  d_count = 0;
41  }
42 
43  int next_bit()
44  {
45  if (d_count == 32767) {
46  d_count = 0;
47  return 0;
48  }
49  d_count++;
50  return d_lfsr.next_bit();
51  }
52 
53  int next_byte()
54  {
55  int v = 0;
56  for (int i = 0; i < 8; i++) {
57  v >>= 1;
58  if (next_bit())
59  v |= 0x80;
60  }
61  return v;
62  }
63 
64  int next_short()
65  {
66  int v = 0;
67  for (int i = 0; i < 16; i++) {
68  v >>= 1;
69  if (next_bit())
70  v |= 0x8000;
71  }
72  return v;
73  }
74 };
75 
76 } /* namespace blocks */
77 } /* namespace gr */
78 
79 #endif /* INCLUDED_GRI_LFSR_32k_H */
Linear Feedback Shift Register using primitive polynomial x^15 + x + 1.
Definition: lfsr_15_1_0.h:28
int next_bit()
Definition: lfsr_15_1_0.h:37
void reset()
Definition: lfsr_15_1_0.h:35
generate pseudo-random sequence of length 32768 bits.
Definition: lfsr_32k.h:29
int next_short()
Definition: lfsr_32k.h:64
int next_byte()
Definition: lfsr_32k.h:53
void reset()
Definition: lfsr_32k.h:37
lfsr_32k()
Definition: lfsr_32k.h:35
int next_bit()
Definition: lfsr_32k.h:43
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
Definition: cc_common.h:35