merged developer branch trondeau/cvsd -r4801:4904 to add CVSD vocoder and example...
[debian/gnuradio] / gr-cvsd-vocoder / src / lib / cvsd_encode_sb.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef INCLUDED_CVSD_ENCODER_SB_H
23 #define INCLUDED_CVSD_ENCODER_SB_H
24
25 #include <gr_sync_decimator.h>
26
27 class cvsd_encode_sb;
28
29 typedef boost::shared_ptr<cvsd_encode_sb> cvsd_encode_sb_sptr;
30
31 cvsd_encode_sb_sptr cvsd_make_encode_sb (short min_step=10,
32                                          short max_step=1280,
33                                          double step_decay=0.9990234375,
34                                          double accum_decay= 0.96875,
35                                          int K=32,
36                                          int J=4,
37                                          short pos_accum_max=32767,
38                                          short neg_accum_max=-32767);
39
40 class cvsd_encode_sb : public gr_sync_decimator
41 {
42 private:
43   friend cvsd_encode_sb_sptr cvsd_make_encode_sb (short min_step,
44                                                   short max_step,
45                                                   double step_decay,
46                                                   double accum_decay,
47                                                   int K,
48                                                   int J,
49                                                   short pos_accum_max,
50                                                   short neg_accum_max);
51
52   cvsd_encode_sb (short min_step, short max_step, double step_decay,
53                   double accum_decay, int K, int J,
54                   short pos_accum_max, short neg_accum_max);
55   
56   int cvsd_round(double input);
57   unsigned int cvsd_pow (short radix, short power);
58   unsigned char cvsd_bitwise_sum (unsigned int input);
59
60   short d_min_step;
61   short d_max_step;
62   double d_step_decay;
63   double d_accum_decay;
64
65   //! \brief Size of shift register; the number of output bits remembered in shift register
66   int d_K;
67
68   //! \brief Number of bits in the shift register that are equal; size of run of 1s, 0s
69   int d_J;
70
71   short d_pos_accum_max;
72   short d_neg_accum_max;
73
74   int d_accum;
75   int d_loop_counter;
76   unsigned int d_runner;
77   short d_stepsize;
78
79  public:
80   ~cvsd_encode_sb ();   // public destructor
81
82   short min_step() { return d_min_step; }
83   short max_step() { return d_max_step; }
84   double step_decay() { return d_step_decay; }
85   double accum_decay() { return d_accum_decay; }
86   int K() { return d_K; }
87   int J() { return d_J; }
88   short pos_accum_max() { return d_pos_accum_max; }
89   short neg_accum_max() { return d_neg_accum_max; }
90
91   int work (int noutput_items,
92             gr_vector_const_void_star &input_items,
93             gr_vector_void_star &output_items);
94 };
95
96 #endif /* INCLUDED_CVSD_ENCODE_SB_H */