GNU Radio 3.7.0 C++ API
cvsd_encode_sb.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef INCLUDED_VOCODER_CVSD_ENCODER_SB_H
00023 #define INCLUDED_VOCODER_CVSD_ENCODER_SB_H
00024 
00025 #include <gnuradio/vocoder/api.h>
00026 #include <gnuradio/sync_decimator.h>
00027 
00028 namespace gr {
00029   namespace vocoder {
00030 
00031     /*!
00032      * \brief This block performs CVSD audio encoding.  Its design and
00033      * implementation is modeled after the CVSD encoder/decoder
00034      * specifications defined in the Bluetooth standard.
00035      * \ingroup audio_blk
00036      *
00037      * \details
00038      * CVSD is a method for encoding speech that seeks to reduce the
00039      * bandwidth required for digital voice transmission. CVSD takes
00040      * advantage of strong correlation between samples, quantizing the
00041      * difference in amplitude between two consecutive samples. This
00042      * difference requires fewer quantization levels as compared to
00043      * other methods that quantize the actual amplitude level,
00044      * reducing the bandwidth. CVSD employs a two level quantizer
00045      * (one bit) and an adaptive algorithm that allows for continuous
00046      * step size adjustment.
00047      *
00048      * The coder can represent low amplitude signals with accuracy
00049      * without sacrificing performance on large amplitude signals, a
00050      * trade off that occurs in some non-adaptive modulations.
00051      *
00052      * The CVSD encoder effectively provides 8-to-1 compression. More
00053      * specifically, each incoming audio sample is compared to an
00054      * internal reference value. If the input is greater or equal to
00055      * the reference, the encoder outputs a "1" bit. If the input is
00056      * less than the reference, the encoder outputs a "0" bit.  The
00057      * reference value is then updated accordingly based on the
00058      * frequency of outputted "1" or "0" bits. By grouping 8 outputs
00059      * bits together, the encoder essentially produce one output byte
00060      * for every 8 input audio samples.
00061      *
00062      * This encoder requires that input audio samples are 2-byte short
00063      * signed integers. The result bandwidth conversion, therefore,
00064      * is 16 input bytes of raw audio data to 1 output byte of encoded
00065      * audio data.
00066      *
00067      * The CVSD encoder module must be prefixed by an up-converter to
00068      * over-sample the audio data prior to encoding. The Bluetooth
00069      * standard specifically calls for a 1-to-8 interpolating
00070      * up-converter.  While this reduces the overall compression of
00071      * the codec, this is required so that the encoder can accurately
00072      * compute the slope between adjacent audio samples and correctly
00073      * update its internal reference value.
00074      *
00075      * References:
00076      *
00077      * 1.  Continuously Variable Slope Delta Modulation (CVSD) A Tutorial,
00078      *     Available: http://www.eetkorea.com/ARTICLES/2003AUG/A/2003AUG29_NTEK_RFD_AN02.PDF.
00079      *
00080      * 2.  Specification of The Bluetooth System
00081      *     Available: http://grouper.ieee.org/groups/802/15/Bluetooth/core_10_b.pdf.
00082      *
00083      * 3.  McGarrity, S., Bluetooth Full Duplex Voice and Data Transmission. 2002.
00084      *     Bluetooth Voice Simulink® Model, Available:
00085      *     http://www.mathworks.com/company/newsletters/digest/nov01/bluetooth.html
00086      */
00087     class VOCODER_API cvsd_encode_sb : virtual public sync_decimator
00088     {
00089     public:
00090       // gr::vocoder::cvsd_encode_sb::sptr
00091       typedef boost::shared_ptr<cvsd_encode_sb> sptr;
00092       
00093       /*!
00094        * \brief Constructor parameters to initialize the CVSD encoder.
00095        * The default values are modeled after the Bluetooth standard and
00096        * should not be changed except by an advanced user
00097        *
00098        * \param min_step      Minimum step size used to update the internal reference.  Default: "10"
00099        * \param max_step      Maximum step size used to update the internal reference.  Default: "1280"
00100        * \param step_decay    Decay factor applied to step size when there is not a run of J output 1s or 0s.
00101        *                      Default: "0.9990234375"  (i.e. 1-1/1024)
00102        * \param accum_decay   Decay factor applied to the internal reference during every interation of the codec.
00103        *                      Default: "0.96875"  (i.e. 1-1/32)
00104        * \param K;            Size of shift register; the number of output bits remembered by codec (must be <= to 32).
00105        *                      Default: "32"
00106        * \param J;            Number of bits in the shift register that are equal; i.e. the size of a run of 1s, 0s.
00107        *                      Default: "4"
00108        * \param pos_accum_max Maximum integer value allowed for the internal reference.
00109        *                      Default: "32767" (2^15 - 1 or MAXSHORT)
00110        * \param neg_accum_max Minimum integer value allowed for the internal reference.
00111        *                      Default: "-32767" (-2^15 + 1 or MINSHORT+1)
00112        */
00113       static sptr make(short min_step=10, short max_step=1280,
00114                        double step_decay=0.9990234375, double accum_decay= 0.96875,
00115                        int K=32, int J=4,
00116                        short pos_accum_max=32767, short neg_accum_max=-32767);
00117 
00118       virtual short min_step() = 0;
00119       virtual short max_step() = 0; 
00120       virtual double step_decay() = 0;
00121       virtual double accum_decay() = 0;
00122       virtual int K() = 0;
00123       virtual int J() = 0;
00124       virtual short pos_accum_max() = 0;
00125       virtual short neg_accum_max() = 0;
00126     };
00127 
00128   } /* namespace vocoder */
00129 } /* namespace gr */
00130 
00131 #endif /* INCLUDED_VOCODER_CVSD_ENCODE_SB_H */