root / gnuradio-core / src / lib / general / gr_glfsr_source_f.cc @ 5155713e
History | View | Annotate | Download (2.2 kB)
| 1 | bae47cc4 | jcorgan | /* -*- c++ -*- */
|
|---|---|---|---|
| 2 | bae47cc4 | jcorgan | /*
|
| 3 | 0a9b999b | Eric Blossom | * Copyright 2007,2010 Free Software Foundation, Inc. |
| 4 | bae47cc4 | jcorgan | * |
| 5 | bae47cc4 | jcorgan | * This file is part of GNU Radio |
| 6 | bae47cc4 | jcorgan | * |
| 7 | bae47cc4 | jcorgan | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | bae47cc4 | jcorgan | * it under the terms of the GNU General Public License as published by |
| 9 | 937b719d | eb | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | bae47cc4 | jcorgan | * any later version. |
| 11 | bae47cc4 | jcorgan | * |
| 12 | bae47cc4 | jcorgan | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | bae47cc4 | jcorgan | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | bae47cc4 | jcorgan | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | bae47cc4 | jcorgan | * GNU General Public License for more details. |
| 16 | bae47cc4 | jcorgan | * |
| 17 | bae47cc4 | jcorgan | * You should have received a copy of the GNU General Public License |
| 18 | bae47cc4 | jcorgan | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | bae47cc4 | jcorgan | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | bae47cc4 | jcorgan | * Boston, MA 02110-1301, USA. |
| 21 | bae47cc4 | jcorgan | */ |
| 22 | bae47cc4 | jcorgan | |
| 23 | bae47cc4 | jcorgan | |
| 24 | bae47cc4 | jcorgan | #ifdef HAVE_CONFIG_H
|
| 25 | bae47cc4 | jcorgan | #include <config.h> |
| 26 | bae47cc4 | jcorgan | #endif
|
| 27 | bae47cc4 | jcorgan | |
| 28 | bae47cc4 | jcorgan | #include <gr_glfsr_source_f.h> |
| 29 | bae47cc4 | jcorgan | #include <gri_glfsr.h> |
| 30 | bae47cc4 | jcorgan | #include <gr_io_signature.h> |
| 31 | bae47cc4 | jcorgan | #include <stdexcept> |
| 32 | bae47cc4 | jcorgan | |
| 33 | bae47cc4 | jcorgan | gr_glfsr_source_f_sptr |
| 34 | bae47cc4 | jcorgan | gr_make_glfsr_source_f(int degree, bool repeat, int mask, int seed) |
| 35 | bae47cc4 | jcorgan | {
|
| 36 | 0a9b999b | Eric Blossom | return gnuradio::get_initial_sptr(new gr_glfsr_source_f(degree, repeat, mask, seed)); |
| 37 | bae47cc4 | jcorgan | } |
| 38 | bae47cc4 | jcorgan | |
| 39 | bae47cc4 | jcorgan | gr_glfsr_source_f::gr_glfsr_source_f(int degree, bool repeat, int mask, int seed) |
| 40 | bae47cc4 | jcorgan | : gr_sync_block ("glfsr_source_f",
|
| 41 | bae47cc4 | jcorgan | gr_make_io_signature (0, 0, 0), |
| 42 | bae47cc4 | jcorgan | gr_make_io_signature (1, 1, sizeof(float))), |
| 43 | bae47cc4 | jcorgan | d_repeat(repeat), |
| 44 | bae47cc4 | jcorgan | d_index(0)
|
| 45 | bae47cc4 | jcorgan | {
|
| 46 | bae47cc4 | jcorgan | if (degree < 1 || degree > 32) |
| 47 | bae47cc4 | jcorgan | throw std::runtime_error("gr_glfsr_source_f: degree must be between 1 and 32 inclusive"); |
| 48 | bae47cc4 | jcorgan | d_length = (unsigned int)((1ULL << degree)-1); |
| 49 | bae47cc4 | jcorgan | |
| 50 | bae47cc4 | jcorgan | if (mask == 0) |
| 51 | bae47cc4 | jcorgan | mask = gri_glfsr::glfsr_mask(degree); |
| 52 | bae47cc4 | jcorgan | d_glfsr = new gri_glfsr(mask, seed);
|
| 53 | bae47cc4 | jcorgan | } |
| 54 | bae47cc4 | jcorgan | |
| 55 | bae47cc4 | jcorgan | gr_glfsr_source_f::~gr_glfsr_source_f() |
| 56 | bae47cc4 | jcorgan | {
|
| 57 | bae47cc4 | jcorgan | delete d_glfsr;
|
| 58 | bae47cc4 | jcorgan | } |
| 59 | bae47cc4 | jcorgan | |
| 60 | bae47cc4 | jcorgan | int
|
| 61 | bae47cc4 | jcorgan | gr_glfsr_source_f::work(int noutput_items,
|
| 62 | bae47cc4 | jcorgan | gr_vector_const_void_star &input_items, |
| 63 | bae47cc4 | jcorgan | gr_vector_void_star &output_items) |
| 64 | bae47cc4 | jcorgan | {
|
| 65 | bae47cc4 | jcorgan | float *out = (float *) output_items[0]; |
| 66 | bae47cc4 | jcorgan | if ((d_index > d_length) && d_repeat == false) |
| 67 | bae47cc4 | jcorgan | return -1; /* once through the sequence */ |
| 68 | bae47cc4 | jcorgan | |
| 69 | bae47cc4 | jcorgan | int i;
|
| 70 | bae47cc4 | jcorgan | for (i = 0; i < noutput_items; i++) { |
| 71 | bae47cc4 | jcorgan | out[i] = (float)d_glfsr->next_bit()*2.0-1.0; |
| 72 | bae47cc4 | jcorgan | d_index++; |
| 73 | bae47cc4 | jcorgan | if (d_index > d_length && d_repeat == false) |
| 74 | bae47cc4 | jcorgan | break;
|
| 75 | bae47cc4 | jcorgan | } |
| 76 | bae47cc4 | jcorgan | |
| 77 | bae47cc4 | jcorgan | return i;
|
| 78 | bae47cc4 | jcorgan | } |
| 79 | bae47cc4 | jcorgan | |
| 80 | bae47cc4 | jcorgan | int
|
| 81 | bae47cc4 | jcorgan | gr_glfsr_source_f::mask() const
|
| 82 | bae47cc4 | jcorgan | {
|
| 83 | bae47cc4 | jcorgan | return d_glfsr->mask();
|
| 84 | bae47cc4 | jcorgan | } |