diff options
Diffstat (limited to 'gr-cvsd-vocoder/src/lib')
-rw-r--r-- | gr-cvsd-vocoder/src/lib/.gitignore | 9 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/Makefile.am | 58 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/Makefile.swig.gen | 145 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc | 193 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h | 170 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc | 191 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h | 173 | ||||
-rw-r--r-- | gr-cvsd-vocoder/src/lib/cvsd_vocoder.i | 91 |
8 files changed, 0 insertions, 1030 deletions
diff --git a/gr-cvsd-vocoder/src/lib/.gitignore b/gr-cvsd-vocoder/src/lib/.gitignore deleted file mode 100644 index ea0a01678..000000000 --- a/gr-cvsd-vocoder/src/lib/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -/Makefile -/Makefile.in -/.libs -/.deps -/cvsd_vocoder.cc -/cvsd_vocoder.py* -/gnuradio -/guile -/python diff --git a/gr-cvsd-vocoder/src/lib/Makefile.am b/gr-cvsd-vocoder/src/lib/Makefile.am deleted file mode 100644 index 9c8c96b96..000000000 --- a/gr-cvsd-vocoder/src/lib/Makefile.am +++ /dev/null @@ -1,58 +0,0 @@ -# -# Copyright 2004,2005,2008,2009,2010 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common -include $(top_srcdir)/Makefile.swig - -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) $(WITH_INCLUDES) - -# These headers get installed in ${prefix}/include/gnuradio -grinclude_HEADERS = \ - cvsd_decode_bs.h \ - cvsd_encode_sb.h - -lib_LTLIBRARIES = libgnuradio-cvsd-vocoder.la - -libgnuradio_cvsd_vocoder_la_SOURCES = \ - cvsd_decode_bs.cc \ - cvsd_encode_sb.cc - -libgnuradio_cvsd_vocoder_la_LIBADD = \ - $(GNURADIO_CORE_LA) - -libgnuradio_cvsd_vocoder_la_LDFLAGS = $(NO_UNDEFINED) $(LTVERSIONFLAGS) - -################################### -# SWIG interface and library - -TOP_SWIG_IFILES = \ - cvsd_vocoder.i - -# Install so that they end up available as: -# import gnuradio.vocoder.cvsd_vocoder -# This ends up at: -# ${prefix}/lib/python${python_version}/site-packages/gnuradio/vocoder -cvsd_vocoder_pythondir_category = \ - gnuradio/vocoder - -# additional libraries for linking with the SWIG-generated library -cvsd_vocoder_la_swig_libadd = \ - libgnuradio-cvsd-vocoder.la diff --git a/gr-cvsd-vocoder/src/lib/Makefile.swig.gen b/gr-cvsd-vocoder/src/lib/Makefile.swig.gen deleted file mode 100644 index e23427a0f..000000000 --- a/gr-cvsd-vocoder/src/lib/Makefile.swig.gen +++ /dev/null @@ -1,145 +0,0 @@ -# -*- Makefile -*- -# -# Copyright 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -# Makefile.swig.gen for cvsd_vocoder.i - -## Default install locations for these files: -## -## Default location for the Python directory is: -## ${prefix}/lib/python${python_version}/site-packages/[category]/cvsd_vocoder -## Default location for the Python exec directory is: -## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/cvsd_vocoder -## -## The following can be overloaded to change the install location, but -## this has to be done in the including Makefile.am -before- -## Makefile.swig is included. - -cvsd_vocoder_pythondir_category ?= gnuradio/cvsd_vocoder -cvsd_vocoder_pylibdir_category ?= $(cvsd_vocoder_pythondir_category) -cvsd_vocoder_pythondir = $(pythondir)/$(cvsd_vocoder_pythondir_category) -cvsd_vocoder_pylibdir = $(pyexecdir)/$(cvsd_vocoder_pylibdir_category) - -# The .so libraries for the guile modules get installed whereever guile -# is installed, usually /usr/lib/guile/gnuradio/ -# FIXME: determince whether these should be installed with gnuradio. -cvsd_vocoder_scmlibdir = $(libdir) - -# The scm files for the guile modules get installed where ever guile -# is installed, usually /usr/share/guile/site/cvsd_vocoder -# FIXME: determince whether these should be installed with gnuradio. -cvsd_vocoder_scmdir = $(guiledir) - -## SWIG headers are always installed into the same directory. - -cvsd_vocoder_swigincludedir = $(swigincludedir) - -## This is a template file for a "generated" Makefile addition (in -## this case, "Makefile.swig.gen"). By including the top-level -## Makefile.swig, this file will be used to generate the SWIG -## dependencies. Assign the variable TOP_SWIG_FILES to be the list of -## SWIG .i files to generated wrappings for; there can be more than 1 -## so long as the names are unique (no sorting is done on the -## TOP_SWIG_FILES list). This file explicitly assumes that a SWIG .i -## file will generate .cc, .py, and possibly .h files -- meaning that -## all of these files will have the same base name (that provided for -## the SWIG .i file). -## -## This code is setup to ensure parallel MAKE ("-j" or "-jN") does the -## right thing. For more info, see < -## http://sources.redhat.com/automake/automake.html#Multiple-Outputs > - -## Other cleaned files: dependency files generated by SWIG or this Makefile - -MOSTLYCLEANFILES += $(DEPDIR)/*.S* - -## Various SWIG variables. These can be overloaded in the including -## Makefile.am by setting the variable value there, then including -## Makefile.swig . - -cvsd_vocoder_swiginclude_HEADERS = \ - cvsd_vocoder.i \ - $(cvsd_vocoder_swiginclude_headers) - -if PYTHON -cvsd_vocoder_pylib_LTLIBRARIES = \ - _cvsd_vocoder.la - -_cvsd_vocoder_la_SOURCES = \ - python/cvsd_vocoder.cc \ - $(cvsd_vocoder_la_swig_sources) - -cvsd_vocoder_python_PYTHON = \ - cvsd_vocoder.py \ - $(cvsd_vocoder_python) - -_cvsd_vocoder_la_LIBADD = \ - $(STD_SWIG_LA_LIB_ADD) \ - $(cvsd_vocoder_la_swig_libadd) - -_cvsd_vocoder_la_LDFLAGS = \ - $(STD_SWIG_LA_LD_FLAGS) \ - $(cvsd_vocoder_la_swig_ldflags) - -_cvsd_vocoder_la_CXXFLAGS = \ - $(STD_SWIG_CXX_FLAGS) \ - -I$(top_builddir) \ - $(cvsd_vocoder_la_swig_cxxflags) - -python/cvsd_vocoder.cc: cvsd_vocoder.py -cvsd_vocoder.py: cvsd_vocoder.i - -# Include the python dependencies for this file --include python/cvsd_vocoder.d - -endif # end of if python - -if GUILE - -cvsd_vocoder_scmlib_LTLIBRARIES = \ - libguile-gnuradio-cvsd_vocoder.la -libguile_gnuradio_cvsd_vocoder_la_SOURCES = \ - guile/cvsd_vocoder.cc \ - $(cvsd_vocoder_la_swig_sources) -nobase_cvsd_vocoder_scm_DATA = \ - gnuradio/cvsd_vocoder.scm \ - gnuradio/cvsd_vocoder-primitive.scm -libguile_gnuradio_cvsd_vocoder_la_LIBADD = \ - $(STD_SWIG_LA_LIB_ADD) \ - $(cvsd_vocoder_la_swig_libadd) -libguile_gnuradio_cvsd_vocoder_la_LDFLAGS = \ - $(STD_SWIG_LA_LD_FLAGS) \ - $(cvsd_vocoder_la_swig_ldflags) -libguile_gnuradio_cvsd_vocoder_la_CXXFLAGS = \ - $(STD_SWIG_CXX_FLAGS) \ - -I$(top_builddir) \ - $(cvsd_vocoder_la_swig_cxxflags) - -guile/cvsd_vocoder.cc: gnuradio/cvsd_vocoder.scm -gnuradio/cvsd_vocoder.scm: cvsd_vocoder.i -gnuradio/cvsd_vocoder-primitive.scm: gnuradio/cvsd_vocoder.scm - -# Include the guile dependencies for this file --include guile/cvsd_vocoder.d - -endif # end of GUILE - - diff --git a/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc b/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc deleted file mode 100644 index 26dcb29da..000000000 --- a/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * config.h is generated by configure. It contains the results - * of probing for features, options etc. It should be the first - * file included in your .cc file. - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cvsd_decode_bs.h> -#include <gr_io_signature.h> -#include <limits.h> - -/* - * Create a new instance of cvsd_decode_bs and return - * a boost shared_ptr. This is effectively the public constructor. - */ -cvsd_decode_bs_sptr -cvsd_make_decode_bs (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) -{ - return gnuradio::get_initial_sptr(new cvsd_decode_bs (min_step, max_step, - step_decay, accum_decay, K, J, - pos_accum_max, neg_accum_max)); -} - -cvsd_decode_bs::cvsd_decode_bs (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - : gr_sync_interpolator ("cvsd_decode_bs", - gr_make_io_signature (1, 1, sizeof (unsigned char)), - gr_make_io_signature (1, 1, sizeof (short)), - 8), - d_min_step (min_step), d_max_step(max_step), d_step_decay(step_decay), - d_accum_decay(accum_decay), d_K(K), d_J(J), - d_pos_accum_max(pos_accum_max), d_neg_accum_max(neg_accum_max), - d_accum(0), - d_loop_counter(1), - d_runner(0), - d_runner_mask(0), - d_stepsize(min_step) - -{ - assert(d_K <= 32); - assert(d_J <= d_K); -} - - -cvsd_decode_bs::~cvsd_decode_bs () -{ - // nothing else required in this example -} - -unsigned char cvsd_decode_bs::cvsd_bitwise_sum (unsigned int input) -{ - unsigned int temp=input; - unsigned char bits=0; - - while(temp) { - temp=temp&(temp-1); - bits++; - } - return bits; -} - -int cvsd_decode_bs::cvsd_round (double input) -{ - double temp; - temp=input+0.5; - temp=floor(temp); - - return (int)temp; -} - -unsigned int cvsd_decode_bs::cvsd_pow (short radix, short power) -{ - double d_radix = (double) radix; - int i_power = (int) power; - double output; - - output=pow(d_radix,i_power); - return ( (unsigned int) cvsd_round(output)); -} - - -int -cvsd_decode_bs::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - - - const unsigned char *in = (const unsigned char *) input_items[0]; - short *out = (short *) output_items[0]; - - int i=0; - short output_short=0; // 2 bytes 0 .. 65,535 - unsigned char bit_count=0; // 1 byte, 0 .. 255 - unsigned int mask=0; // 4 bytes, 0 .. 4,294,967,295 - unsigned char input_byte=0; // 1 bytes - unsigned char input_bit=0; // 1 byte, 0 .. 255 - - // Loop through each input data point - for(i = 0; i < noutput_items/8.0; i++) { - - input_byte = in[i]; - // Initiliaze bit counter - bit_count=0; - - while(bit_count<8) { - // Compute the Appropriate Mask - mask=cvsd_pow(2,7-bit_count); - - // Pull off the corresponding bit - input_bit = input_byte & mask; - - // Update the bit counter - bit_count++; - - // Update runner with the next input bit - // Runner is a shift-register; shift left, add on newest output bit - d_runner = (d_runner<<1) | ((unsigned int) input_bit); - - // Run this only if you have >= J bits in your shift register - if (d_loop_counter>=d_J) { - // Update Step Size - d_runner_mask=(cvsd_pow(2,d_J)-1); - if ((cvsd_bitwise_sum(d_runner & d_runner_mask)>=d_J)||(cvsd_bitwise_sum((~d_runner) & d_runner_mask)>=d_J)) { - // Runs of 1s and 0s - d_stepsize = std::min( (short) (d_stepsize + d_min_step), d_max_step); - } - else { - // No runs of 1s and 0s - d_stepsize = std::max( (short) cvsd_round(d_stepsize*d_step_decay), d_min_step); - } - } - - // Update Accum (i.e. the reference value) - if (input_bit) { - d_accum=d_accum+d_stepsize; - } - else { - d_accum=d_accum-d_stepsize; - } - - // Multiply by Accum_Decay - d_accum=(cvsd_round(d_accum*d_accum_decay)); - - // Check for overflow - if (d_accum >=((int) d_pos_accum_max)) { - d_accum=(int)d_pos_accum_max; - } - else if (d_accum <=((int) d_neg_accum_max)) { - d_accum=(int)d_neg_accum_max; - } - - // Find the output short to write to the file - output_short=((short) d_accum); - - if (d_loop_counter <= d_K) { - d_loop_counter++; - } - - *(out++) = output_short; - } // while () - - } // for() - - return noutput_items; -} diff --git a/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h b/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h deleted file mode 100644 index f7b50909f..000000000 --- a/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h +++ /dev/null @@ -1,170 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_CVSD_DECODE_BS_H -#define INCLUDED_CVSD_DECODE_BS_H - -#include <gr_sync_interpolator.h> - -class cvsd_decode_bs; - -typedef boost::shared_ptr<cvsd_decode_bs> cvsd_decode_bs_sptr; - - /*! - * \brief Constructor parameters to initialize the CVSD decoder. The default - * values are modeled after the Bluetooth standard and should not be changed, - * except by an advanced user - * - * \param min_step Minimum step size used to update the internal reference. Default: "10" - * \param max_step Maximum step size used to update the internal reference. Default: "1280" - * \param step_decay Decay factor applied to step size when there is not a run of J output 1s or 0s. Default: "0.9990234375" (i.e. 1-1/1024) - * \param accum_decay Decay factor applied to the internal reference during every interation of the codec. Default: "0.96875" (i.e. 1-1/32) - * \param K; Size of shift register; the number of output bits remembered by codec (must be less or equal to 32). Default: "32" - * \param J; Number of bits in the shift register that are equal; i.e. the size of a run of 1s, 0s. Default: "4" - * \param pos_accum_max Maximum integer value allowed for the internal reference. Default: "32767" (2^15 - 1 or MAXSHORT) - * \param neg_accum_max Minimum integer value allowed for the internal reference. Default: "-32767" (-2^15 + 1 or MINSHORT+1) - * - */ -cvsd_decode_bs_sptr cvsd_make_decode_bs (short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - -/*! - * \brief This block performs CVSD audio decoding. Its design and implementation - * is modeled after the CVSD encoder/decoder specifications defined in the - * Bluetooth standard. - * - * \ingroup vocoder_blk - * - * CVSD is a method for encoding speech that seeks to reduce the - * bandwidth required for digital voice transmission. CVSD takes - * advantage of strong correlation between samples, quantizing the - * difference in amplitude between two consecutive samples. This - * difference requires fewer quantization levels as compared to other - * methods that quantize the actual amplitude level, reducing the - * bandwidth. CVSD employs a two level quantizer (one bit) and an - * adaptive algorithm that allows for continuous step size adjustment. - * - * The coder can represent low amplitude signals with accuracy without - * sacrificing performance on large amplitude signals, a trade off that - * occurs in some non-adaptive modulations. - * - * The CVSD decoder effectively provides 1-to-8 decompression. More - * specifically, for each incoming input bit, the decoder outputs one - * audio sample. If the input is a "1" bit, the internal reference is - * increased appropriately and then outputted as the next estimated audio - * sample. If the input is a "0" bit, the internal reference is - * decreased appropriately and then likewise outputted as the next estimated - * audio sample. Grouping 8 input bits together, the encoder essentially - * produces 8 output audio samples for everyone one input byte. - * - * This decoder requires that output audio samples are 2-byte short signed - * integers. The result bandwidth conversion, therefore, is 1 byte of - * encoded audio data to 16 output bytes of raw audio data. - * - * The CVSD decoder module must be post-fixed by a down-converter to - * under-sample the audio data after decoding. The Bluetooth standard - * specifically calls for a 8-to-1 decimating down-converter. This is - * required so that so that output sampling rate equals the original input - * sampling rate present before the encoder. In all cases, the output - * down-converter rate must be the inverse of the input up-converter rate - * before the CVSD encoder. - * - * References: - * 1. Continuously Variable Slope Delta Modulation (CVSD) A Tutorial, - * Available: http://www.eetkorea.com/ARTICLES/2003AUG/A/2003AUG29_NTEK_RFD_AN02.PDF. - * 2. Specification of The Bluetooth System - * Available: http://grouper.ieee.org/groups/802/15/Bluetooth/core_10_b.pdf. - * 3. McGarrity, S., Bluetooth Full Duplex Voice and Data Transmission. 2002. - * Bluetooth Voice Simulink® Model, Available: - * http://www.mathworks.com/company/newsletters/digest/nov01/bluetooth.html - * - */ - -class cvsd_decode_bs : public gr_sync_interpolator -{ -private: - friend cvsd_decode_bs_sptr cvsd_make_decode_bs (short min_step, - short max_step, - double step_decay, - double accum_decay, - int K, - int J, - short pos_accum_max, - short neg_accum_max); - - cvsd_decode_bs (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max); - - //! Member functions required by the encoder/decoder - //! \brief Rounding function specific to CVSD - //! \return the input value rounded to the nearest integer - int cvsd_round(double input); - - //! \brief A power function specific to CVSD data formats - //! \return (radix)^power, where radix and power are short integers - unsigned int cvsd_pow (short radix, short power); - - //! \brief Sums number of 1's in the input - //! \return the number of 1s in the four bytes of an input unsigned integer - unsigned char cvsd_bitwise_sum (unsigned int input); - - short d_min_step; - short d_max_step; - double d_step_decay; - double d_accum_decay; - - int d_K; //!< \brief Size of shift register; the number of output bits remembered in shift register - int d_J; //!< \brief Number of bits in the shift register that are equal; size of run of 1s, 0s - - short d_pos_accum_max; - short d_neg_accum_max; - - int d_accum; //!< \brief Current value of internal reference - int d_loop_counter; //!< \brief Current value of the loop counter - unsigned int d_runner; //!< \brief Current value of the shift register - unsigned int d_runner_mask; //!< \brief Value of the mask to access the last J bits of the shift register - short d_stepsize; //!< \brief Current value of the step sizer - - public: - ~cvsd_decode_bs (); // public destructor - - short min_step() { return d_min_step; } - short max_step() { return d_max_step; } - double step_decay() { return d_step_decay; } - double accum_decay() { return d_accum_decay; } - int K() { return d_K; } - int J() { return d_J; } - short pos_accum_max() { return d_pos_accum_max; } - short neg_accum_max() { return d_neg_accum_max; } - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif /* INCLUDED_CVSD_DECODE_BS_H */ diff --git a/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc b/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc deleted file mode 100644 index df867f3ba..000000000 --- a/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * config.h is generated by configure. It contains the results - * of probing for features, options etc. It should be the first - * file included in your .cc file. - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cvsd_encode_sb.h> -#include <gr_io_signature.h> -#include <limits.h> - -/* - * Create a new instance of cvsd_encode_sb and return - * a boost shared_ptr. This is effectively the public constructor. - */ -cvsd_encode_sb_sptr -cvsd_make_encode_sb (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) -{ - return gnuradio::get_initial_sptr(new cvsd_encode_sb (min_step, max_step, - step_decay, accum_decay, K, J, - pos_accum_max, neg_accum_max)); -} - -cvsd_encode_sb::cvsd_encode_sb (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - : gr_sync_decimator ("cvsd_encode_sb", - gr_make_io_signature (1, 1, sizeof (short)), - gr_make_io_signature (1, 1, sizeof (unsigned char)), - 8), - d_min_step (min_step), d_max_step(max_step), d_step_decay(step_decay), - d_accum_decay(accum_decay), d_K(K), d_J(J), - d_pos_accum_max(pos_accum_max), d_neg_accum_max(neg_accum_max), - d_accum(0), - d_loop_counter(1), - d_runner(0), - d_stepsize(min_step) - -{ - assert(d_K <= 32); - assert(d_J <= d_K); -} - - -cvsd_encode_sb::~cvsd_encode_sb () -{ - // nothing else required in this example -} - -unsigned char cvsd_encode_sb::cvsd_bitwise_sum (unsigned int input) -{ - unsigned int temp=input; - unsigned char bits=0; - - while(temp) { - temp=temp&(temp-1); - bits++; - } - return bits; -} - -int cvsd_encode_sb::cvsd_round (double input) -{ - double temp; - temp=input+0.5; - temp=floor(temp); - - return (int)temp; -} - -unsigned int cvsd_encode_sb::cvsd_pow (short radix, short power) -{ - double d_radix = (double) radix; - int i_power = (int) power; - double output; - - output=pow(d_radix,i_power); - return ( (unsigned int) cvsd_round(output)); -} - - - -int -cvsd_encode_sb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const short *in = (const short *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - - unsigned short i=0; // 2 bytes, 0 .. 65,535 - unsigned char output_bit=0; // 1 byte, 0 .. 255 - unsigned char output_byte=0; // 1 bytes 0.255 - unsigned char bit_count=0; // 1 byte, 0 .. 255 - unsigned int mask=0; // 4 bytes, 0 .. 4,294,967,295 - - // Loop through each input data point - for(i = 0; i < noutput_items*8; i++) { - if((int)in[i] >= d_accum) { // Note: sign((data(n)-accum)) - output_bit=1; - } - else { - output_bit=0; - } - - // Update Accum (i.e. the reference value) - if (output_bit) { - d_accum=d_accum+d_stepsize; - //printf("Addding %d to the accum; the result is: %d.\n", d_stepsize, d_accum); - } - else { - d_accum=d_accum-d_stepsize; - //printf("Subtracting %d to the accum; the result is: %d.\n", d_stepsize, d_accum); - } - - // Multiply by Accum_Decay - d_accum=(cvsd_round(d_accum*d_accum_decay)); - - // Check for overflow - if (d_accum >= ((int)d_pos_accum_max)) { - d_accum = (int)d_pos_accum_max; - } - else if(d_accum <= ((int) d_neg_accum_max)) { - d_accum = (int) d_neg_accum_max; - } - - // Update runner with the last output bit - // Update Step Size - if (d_loop_counter >= d_J) { // Run this only if you have >= J bits in your shift register - mask=(cvsd_pow(2, d_J) - 1); - if ((cvsd_bitwise_sum(d_runner & mask) >= d_J) || (cvsd_bitwise_sum((~d_runner) & mask) >= d_J)) { - // Runs of 1s and 0s - d_stepsize = std::min( (short)(d_stepsize + d_min_step), d_max_step); - } - else { - // No runs of 1s and 0s - d_stepsize = std::max( (short)cvsd_round(d_stepsize*d_step_decay), d_min_step); - } - } - - // Runner is a shift-register; shift left, add on newest output bit - d_runner = (d_runner<<1) | ((unsigned int) output_bit); - - // Update the ouput type; shift left, add on newest output bit - // If you have put in 8 bits, output it as a byte - output_byte = (output_byte<<1) | output_bit; - bit_count++; - - if (d_loop_counter <= d_K) { - d_loop_counter++; - } - - // If you have put 8 bits, output and clear. - if (bit_count==8) { - // Read in short from the file - *(out++) = output_byte; - - // Reset the bit_count - bit_count=0; - output_byte=0; - } - } // While - - return noutput_items; -} diff --git a/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h b/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h deleted file mode 100644 index a7994d4ed..000000000 --- a/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h +++ /dev/null @@ -1,173 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_CVSD_ENCODER_SB_H -#define INCLUDED_CVSD_ENCODER_SB_H - -#include <gr_sync_decimator.h> - -class cvsd_encode_sb; - -typedef boost::shared_ptr<cvsd_encode_sb> cvsd_encode_sb_sptr; - - /*! - * \brief Constructor parameters to initialize the CVSD encoder. The default - * values are modeled after the Bluetooth standard and should not be changed - * except by an advanced user - * - * \param min_step Minimum step size used to update the internal reference. Default: "10" - * \param max_step Maximum step size used to update the internal reference. Default: "1280" - * \param step_decay Decay factor applied to step size when there is not a run of J output 1s or 0s. Default: "0.9990234375" (i.e. 1-1/1024) - * \param accum_decay Decay factor applied to the internal reference during every interation of the codec. Default: "0.96875" (i.e. 1-1/32) - * \param K; Size of shift register; the number of output bits remembered by codec (must be less or equal to 32). Default: "32" - * \param J; Number of bits in the shift register that are equal; i.e. the size of a run of 1s, 0s. Default: "4" - * \param pos_accum_max Maximum integer value allowed for the internal reference. Default: "32767" (2^15 - 1 or MAXSHORT) - * \param neg_accum_max Minimum integer value allowed for the internal reference. Default: "-32767" (-2^15 + 1 or MINSHORT+1) - * - */ - -cvsd_encode_sb_sptr cvsd_make_encode_sb (short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - -/*! - * \brief This block performs CVSD audio encoding. Its design and implementation - * is modeled after the CVSD encoder/decoder specifications defined in the - * Bluetooth standard. - * - * \ingroup vocoder_blk - * - * CVSD is a method for encoding speech that seeks to reduce the - * bandwidth required for digital voice transmission. CVSD takes - * advantage of strong correlation between samples, quantizing the - * difference in amplitude between two consecutive samples. This - * difference requires fewer quantization levels as compared to other - * methods that quantize the actual amplitude level, reducing the - * bandwidth. CVSD employs a two level quantizer (one bit) and an - * adaptive algorithm that allows for continuous step size adjustment. - * - * The coder can represent low amplitude signals with accuracy without - * sacrificing performance on large amplitude signals, a trade off that - * occurs in some non-adaptive modulations. - * - * The CVSD encoder effectively provides 8-to-1 compression. More - * specifically, each incoming audio sample is compared to an internal - * reference value. If the input is greater or equal to the reference, - * the encoder outputs a "1" bit. If the input is less than the reference, - * the encoder outputs a "0" bit. The reference value is then updated - * accordingly based on the frequency of outputted "1" or "0" bits. By - * grouping 8 outputs bits together, the encoder essentially produce one - * output byte for every 8 input audio samples. - * - * This encoder requires that input audio samples are 2-byte short signed - * integers. The result bandwidth conversion, therefore, is 16 input bytes - * of raw audio data to 1 output byte of encoded audio data. - * - * The CVSD encoder module must be prefixed by an up-converter to over-sample - * the audio data prior to encoding. The Bluetooth standard specifically - * calls for a 1-to-8 interpolating up-converter. While this reduces the - * overall compression of the codec, this is required so that the encoder - * can accurately compute the slope between adjacent audio samples and - * correctly update its internal reference value. - * - * References: - * - * 1. Continuously Variable Slope Delta Modulation (CVSD) A Tutorial, - * Available: http://www.eetkorea.com/ARTICLES/2003AUG/A/2003AUG29_NTEK_RFD_AN02.PDF. - * - * 2. Specification of The Bluetooth System - * Available: http://grouper.ieee.org/groups/802/15/Bluetooth/core_10_b.pdf. - * - * 3. McGarrity, S., Bluetooth Full Duplex Voice and Data Transmission. 2002. - * Bluetooth Voice Simulink® Model, Available: - * http://www.mathworks.com/company/newsletters/digest/nov01/bluetooth.html - * - */ - -class cvsd_encode_sb : public gr_sync_decimator -{ -private: - friend cvsd_encode_sb_sptr cvsd_make_encode_sb (short min_step, - short max_step, - double step_decay, - double accum_decay, - int K, - int J, - short pos_accum_max, - short neg_accum_max); - - cvsd_encode_sb (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max); - - //! Member functions required by the encoder/decoder - //! \brief Rounding function specific to CVSD - //! \return the input value rounded to the nearest integer - int cvsd_round(double input); - - //! \brief A power function specific to CVSD data formats - //! \return (radix)^power, where radix and power are short integers - unsigned int cvsd_pow (short radix, short power); - - //! \brief Sums number of 1's in the input - //! \return the number of 1s in the four bytes of an input unsigned integer - unsigned char cvsd_bitwise_sum (unsigned int input); - - // Members variables related to the CVSD encoder use to update interal reference value - short d_min_step; - short d_max_step; - double d_step_decay; - double d_accum_decay; - - int d_K; //!< \brief Size of shift register; the number of output bits remembered in shift register - int d_J; //!< \brief Number of bits in the shift register that are equal; size of run of 1s, 0s - - short d_pos_accum_max; - short d_neg_accum_max; - - int d_accum; //!< \brief Current value of internal reference - int d_loop_counter; //!< \brief Current value of the loop counter - unsigned int d_runner; //!< \brief Current value of the shift register - short d_stepsize; //!< \brief Current value of the step sizer - - public: - ~cvsd_encode_sb (); // public destructor - - short min_step() { return d_min_step; } - short max_step() { return d_max_step; } - double step_decay() { return d_step_decay; } - double accum_decay() { return d_accum_decay; } - int K() { return d_K; } - int J() { return d_J; } - short pos_accum_max() { return d_pos_accum_max; } - short neg_accum_max() { return d_neg_accum_max; } - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif /* INCLUDED_CVSD_ENCODE_SB_H */ diff --git a/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i b/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i deleted file mode 100644 index 82662e84e..000000000 --- a/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -%include "gnuradio.i" - -%{ -#include "cvsd_encode_sb.h" -#include "cvsd_decode_bs.h" -%} - -GR_SWIG_BLOCK_MAGIC(cvsd,encode_sb); - -cvsd_encode_sb_sptr cvsd_make_encode_sb (short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - -class cvsd_encode_sb : public gr_sync_decimator -{ -private: - cvsd_encode_sb (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max); - - - public: - short min_step() { return d_min_step; } - short max_step() { return d_max_step; } - double step_decay() { return d_step_decay; } - double accum_decay() { return d_accum_decay; } - int K() { return d_K; } - int J() { return d_J; } - short pos_accum_max() { return d_pos_accum_max; } - short neg_accum_max() { return d_neg_accum_max; } -}; - -// ---------------------------------------------------------------- - -GR_SWIG_BLOCK_MAGIC(cvsd,decode_bs); - -cvsd_decode_bs_sptr cvsd_make_decode_bs (short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - -class cvsd_decode_bs : public gr_sync_interpolator -{ -private: - cvsd_decode_bs (short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max); - - public: -}; - -#if SWIGGUILE -%scheme %{ -(load-extension-global "libguile-gnuradio-cvsd_vocoder" "scm_init_gnuradio_cvsd_vocoder_module") -%} - -%goops %{ -(use-modules (gnuradio gnuradio_core_runtime)) -%} -#endif |