diff options
author | Johnathan Corgan | 2011-07-18 11:21:59 -0700 |
---|---|---|
committer | Johnathan Corgan | 2011-07-18 11:43:40 -0700 |
commit | 53cb984afd6f4dcb65f413dc9c4d8277eb8cc7d5 (patch) | |
tree | 57702ef04bc7006947c62cdb316a405fa85bdccc | |
parent | 71d382debf95d37a0d388fa37476fbf60f0e9714 (diff) | |
download | gnuradio-53cb984afd6f4dcb65f413dc9c4d8277eb8cc7d5.tar.gz gnuradio-53cb984afd6f4dcb65f413dc9c4d8277eb8cc7d5.tar.bz2 gnuradio-53cb984afd6f4dcb65f413dc9c4d8277eb8cc7d5.zip |
gr-vocoder: re-implemented gr-cvsd-vocoder in gr-vocoder
-rw-r--r-- | gr-vocoder/examples/Makefile.am | 3 | ||||
-rwxr-xr-x | gr-vocoder/examples/cvsd_audio_loopback.py | 68 | ||||
-rwxr-xr-x | gr-vocoder/examples/gsm_audio_loopback.py | 1 | ||||
-rw-r--r-- | gr-vocoder/include/Makefile.am | 2 | ||||
-rw-r--r-- | gr-vocoder/include/vocoder_cvsd_decode_bs.h | 171 | ||||
-rw-r--r-- | gr-vocoder/include/vocoder_cvsd_encode_sb.h | 173 | ||||
-rw-r--r-- | gr-vocoder/lib/Makefile.am | 2 | ||||
-rw-r--r-- | gr-vocoder/lib/vocoder_cvsd_decode_bs.cc | 193 | ||||
-rw-r--r-- | gr-vocoder/lib/vocoder_cvsd_encode_sb.cc | 189 | ||||
-rw-r--r-- | gr-vocoder/python/Makefile.am | 6 | ||||
-rw-r--r-- | gr-vocoder/python/__init__.py | 1 | ||||
-rw-r--r-- | gr-vocoder/python/cvsd.py | 86 | ||||
-rwxr-xr-x | gr-vocoder/python/qa_cvsd_vocoder.py | 123 | ||||
-rwxr-xr-x | gr-vocoder/python/qa_gsm_full_rate.py | 6 | ||||
-rw-r--r-- | gr-vocoder/python/run_tests.in | 4 | ||||
-rw-r--r-- | gr-vocoder/swig/Makefile.am | 2 | ||||
-rw-r--r-- | gr-vocoder/swig/vocoder_cvsd_decode_bs.i | 44 | ||||
-rw-r--r-- | gr-vocoder/swig/vocoder_cvsd_encode_sb.i | 44 | ||||
-rw-r--r-- | gr-vocoder/swig/vocoder_swig.i | 2 |
19 files changed, 1113 insertions, 7 deletions
diff --git a/gr-vocoder/examples/Makefile.am b/gr-vocoder/examples/Makefile.am index 7e069865d..d325ae095 100644 --- a/gr-vocoder/examples/Makefile.am +++ b/gr-vocoder/examples/Makefile.am @@ -24,6 +24,5 @@ include $(top_srcdir)/Makefile.common ourdatadir = $(exampledir)/vocoder dist_ourdata_SCRIPTS = \ + cvsd_audio_loopback.py \ gsm_audio_loopback.py - - diff --git a/gr-vocoder/examples/cvsd_audio_loopback.py b/gr-vocoder/examples/cvsd_audio_loopback.py new file mode 100755 index 000000000..7f2a00dbf --- /dev/null +++ b/gr-vocoder/examples/cvsd_audio_loopback.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright 2007,2011 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. +# + +from gnuradio import gr, blks2 +from gnuradio import audio +from gnuradio import vocoder + +def build_graph(): + sample_rate = 8000 + scale_factor = 32000 + + tb = gr.top_block() + src = audio.source(sample_rate, "plughw:0,0") + src_scale = gr.multiply_const_ff(scale_factor) + + interp = blks2.rational_resampler_fff(8, 1) + f2s = gr.float_to_short () + + enc = vocoder.cvsd_encode_sb() + dec = vocoder.cvsd_decode_bs() + + s2f = gr.short_to_float () + decim = blks2.rational_resampler_fff(1, 8) + + sink_scale = gr.multiply_const_ff(1.0/scale_factor) + sink = audio.sink(sample_rate, "plughw:0,0") + + tb.connect(src, src_scale, interp, f2s, enc) + tb.connect(enc, dec, s2f, decim, sink_scale, sink) + + if 0: # debug + tb.conect(src, gr.file_sink(gr.sizeof_float, "source.dat")) + tb.conect(src_scale, gr.file_sink(gr.sizeof_float, "src_scale.dat")) + tb.conect(interp, gr.file_sink(gr.sizeof_float, "interp.dat")) + tb.conect(f2s, gr.file_sink(gr.sizeof_short, "f2s.dat")) + tb.conect(enc, gr.file_sink(gr.sizeof_char, "enc.dat")) + tb.conect(dec, gr.file_sink(gr.sizeof_short, "dec.dat")) + tb.conect(s2f, gr.file_sink(gr.sizeof_float, "s2f.dat")) + tb.conect(decim, gr.file_sink(gr.sizeof_float, "decim.dat")) + tb.conect(sink_scale, gr.file_sink(gr.sizeof_float, "sink_scale.dat")) + + return tb + +if __name__ == '__main__': + tb = build_graph() + tb.start() + raw_input ('Press Enter to exit: ') + tb.stop() + tb.wait() diff --git a/gr-vocoder/examples/gsm_audio_loopback.py b/gr-vocoder/examples/gsm_audio_loopback.py index 9904944ce..f4e96f471 100755 --- a/gr-vocoder/examples/gsm_audio_loopback.py +++ b/gr-vocoder/examples/gsm_audio_loopback.py @@ -42,3 +42,4 @@ if __name__ == '__main__': tb.start() raw_input ('Press Enter to exit: ') tb.stop() + tb.wait() diff --git a/gr-vocoder/include/Makefile.am b/gr-vocoder/include/Makefile.am index 71c56d47f..7ec9f6382 100644 --- a/gr-vocoder/include/Makefile.am +++ b/gr-vocoder/include/Makefile.am @@ -23,5 +23,7 @@ include $(top_srcdir)/Makefile.common # C/C++ headers get installed in ${prefix}/include/gnuradio grinclude_HEADERS = \ + vocoder_cvsd_decode_bs.h \ + vocoder_cvsd_encode_sb.h \ vocoder_gsm_fr_decode_ps.h \ vocoder_gsm_fr_encode_sp.h diff --git a/gr-vocoder/include/vocoder_cvsd_decode_bs.h b/gr-vocoder/include/vocoder_cvsd_decode_bs.h new file mode 100644 index 000000000..dd588c661 --- /dev/null +++ b/gr-vocoder/include/vocoder_cvsd_decode_bs.h @@ -0,0 +1,171 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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_VOCODER_CVSD_DECODE_BS_H +#define INCLUDED_VOCODER_CVSD_DECODE_BS_H + +#include <gr_sync_interpolator.h> + +class vocoder_cvsd_decode_bs; + +typedef boost::shared_ptr<vocoder_cvsd_decode_bs> vocoder_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) + * + */ +vocoder_cvsd_decode_bs_sptr vocoder_make_cvsd_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 vocoder_cvsd_decode_bs : public gr_sync_interpolator +{ +private: + friend vocoder_cvsd_decode_bs_sptr vocoder_make_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); + + vocoder_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: + ~vocoder_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_VOCODER_CVSD_DECODE_BS_H */ diff --git a/gr-vocoder/include/vocoder_cvsd_encode_sb.h b/gr-vocoder/include/vocoder_cvsd_encode_sb.h new file mode 100644 index 000000000..da09b3927 --- /dev/null +++ b/gr-vocoder/include/vocoder_cvsd_encode_sb.h @@ -0,0 +1,173 @@ +/* -*- 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_VOCODER_CVSD_ENCODER_SB_H +#define INCLUDED_VOCODER_CVSD_ENCODER_SB_H + +#include <gr_sync_decimator.h> + +class vocoder_cvsd_encode_sb; + +typedef boost::shared_ptr<vocoder_cvsd_encode_sb> vocoder_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) + * + */ + +vocoder_cvsd_encode_sb_sptr vocoder_make_cvsd_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 vocoder_cvsd_encode_sb : public gr_sync_decimator +{ +private: + friend vocoder_cvsd_encode_sb_sptr vocoder_make_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); + + vocoder_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: + ~vocoder_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_VOCODER_CVSD_ENCODE_SB_H */ diff --git a/gr-vocoder/lib/Makefile.am b/gr-vocoder/lib/Makefile.am index 3b3f2c5c1..ec97d96b6 100644 --- a/gr-vocoder/lib/Makefile.am +++ b/gr-vocoder/lib/Makefile.am @@ -29,6 +29,8 @@ AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) $(WITH_INCLUDES) \ lib_LTLIBRARIES = libgnuradio-vocoder.la libgnuradio_vocoder_la_SOURCES = \ + vocoder_cvsd_encode_sb.cc \ + vocoder_cvsd_decode_bs.cc \ vocoder_gsm_fr_decode_ps.cc \ vocoder_gsm_fr_encode_sp.cc diff --git a/gr-vocoder/lib/vocoder_cvsd_decode_bs.cc b/gr-vocoder/lib/vocoder_cvsd_decode_bs.cc new file mode 100644 index 000000000..baf99f041 --- /dev/null +++ b/gr-vocoder/lib/vocoder_cvsd_decode_bs.cc @@ -0,0 +1,193 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2011 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 <vocoder_cvsd_decode_bs.h> +#include <gr_io_signature.h> +#include <limits.h> + +/* + * Create a new instance of vocoder_cvsd_decode_bs and return + * a boost shared_ptr. This is effectively the public constructor. + */ +vocoder_cvsd_decode_bs_sptr +vocoder_make_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) +{ + return gnuradio::get_initial_sptr(new vocoder_cvsd_decode_bs (min_step, max_step, + step_decay, accum_decay, K, J, + pos_accum_max, neg_accum_max)); +} + +vocoder_cvsd_decode_bs::vocoder_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 ("vocoder_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); +} + + +vocoder_cvsd_decode_bs::~vocoder_cvsd_decode_bs () +{ + // nothing else required in this example +} + +unsigned char vocoder_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 vocoder_cvsd_decode_bs::cvsd_round (double input) +{ + double temp; + temp=input+0.5; + temp=floor(temp); + + return (int)temp; +} + +unsigned int vocoder_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 +vocoder_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-vocoder/lib/vocoder_cvsd_encode_sb.cc b/gr-vocoder/lib/vocoder_cvsd_encode_sb.cc new file mode 100644 index 000000000..71cf6df8c --- /dev/null +++ b/gr-vocoder/lib/vocoder_cvsd_encode_sb.cc @@ -0,0 +1,189 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2011 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 <vocoder_cvsd_encode_sb.h> +#include <gr_io_signature.h> +#include <limits.h> + +/* + * Create a new instance of vocoder_cvsd_encode_sb and return + * a boost shared_ptr. This is effectively the public constructor. + */ +vocoder_cvsd_encode_sb_sptr +vocoder_make_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) +{ + return gnuradio::get_initial_sptr(new vocoder_cvsd_encode_sb (min_step, max_step, + step_decay, accum_decay, K, J, + pos_accum_max, neg_accum_max)); +} + +vocoder_cvsd_encode_sb::vocoder_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 ("vocoder_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); +} + + +vocoder_cvsd_encode_sb::~vocoder_cvsd_encode_sb () +{ + // nothing else required in this example +} + +unsigned char vocoder_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 vocoder_cvsd_encode_sb::cvsd_round (double input) +{ + double temp; + temp=input+0.5; + temp=floor(temp); + + return (int)temp; +} + +unsigned int vocoder_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 +vocoder_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-vocoder/python/Makefile.am b/gr-vocoder/python/Makefile.am index b71a47618..e4dc1ac61 100644 --- a/gr-vocoder/python/Makefile.am +++ b/gr-vocoder/python/Makefile.am @@ -26,9 +26,11 @@ vocoderdir = $(grpythondir)/vocoder TESTS = run_tests noinst_PYTHON = \ - qa_gsm_full_rate.py + qa_gsm_full_rate.py \ + qa_cvsd_vocoder.py vocoder_PYTHON = \ - __init__.py + __init__.py \ + cvsd.py EXTRA_DIST += run_tests.in diff --git a/gr-vocoder/python/__init__.py b/gr-vocoder/python/__init__.py index 65185eb34..eb5fa6fc1 100644 --- a/gr-vocoder/python/__init__.py +++ b/gr-vocoder/python/__init__.py @@ -20,3 +20,4 @@ # from vocoder_swig import * +from cvsd import * diff --git a/gr-vocoder/python/cvsd.py b/gr-vocoder/python/cvsd.py new file mode 100644 index 000000000..27b06ddeb --- /dev/null +++ b/gr-vocoder/python/cvsd.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# Copyright 2007,2011 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. +# + +from gnuradio import gr +import vocoder_swig + +class cvsd_encode_fb(gr.hier_block2): + ''' + This is a wrapper for the CVSD encoder that performs interpolation and filtering + necessary to work with the vocoding. It converts an incoming float (+-1) to a short, scales + it (to 32000; slightly below the maximum value), interpolates it, and then vocodes it. + + The incoming sampling rate can be anything, though, of course, the higher the sampling rate and the + higher the interpolation rate are, the better the sound quality. + ''' + + def __init__(self, resample=8, bw=0.5): + ''' + When using the CVSD vocoder, appropriate sampling rates are from 8k to 64k with resampling rates + from 1 to 8. A rate of 8k with a resampling rate of 8 provides a good quality signal. + ''' + + gr.hier_block2.__init__(self, "cvsd_encode", + gr.io_signature(1, 1, gr.sizeof_float), # Input signature + gr.io_signature(1, 1, gr.sizeof_char)) # Output signature + + scale_factor = 32000.0 + self.interp = resample + + src_scale = gr.multiply_const_ff(scale_factor) + taps = gr.firdes.low_pass(self.interp, self.interp, bw, 2*bw) + interp = gr.interp_fir_filter_fff(self.interp, taps) + f2s = gr.float_to_short() + enc = vocoder_swig.cvsd_encode_sb() + + self.connect(self, src_scale, interp, f2s, enc, self) + + +class cvsd_decode_bf(gr.hier_block2): + ''' + This is a wrapper for the CVSD decoder that performs decimation and filtering + necessary to work with the vocoding. It converts an incoming CVSD-encoded short to a float, decodes it + to a float, decimates it, and scales it (by 32000; slightly below the maximum value to avoid clipping). + + The sampling rate can be anything, though, of course, the higher the sampling rate and the + higher the interpolation rate are, the better the sound quality. + ''' + + def __init__(self, resample=8, bw=0.5): + ''' + When using the CVSD vocoder, appropriate sampling rates are from 8k to 64k with resampling rates + from 1 to 8. A rate of 8k with a resampling rate of 8 provides a good quality signal. + ''' + gr.hier_block2.__init__(self, "cvsd_decode", + gr.io_signature(1, 1, gr.sizeof_char), # Input signature + gr.io_signature(1, 1, gr.sizeof_float)) # Output signature + + scale_factor = 32000.0 + self.decim = resample + + dec = vocoder_swig.cvsd_decode_bs() + s2f = gr.short_to_float() + taps = gr.firdes.low_pass(1, 1, bw, 2*bw) + decim = gr.fir_filter_fff(self.decim, taps) + sink_scale = gr.multiply_const_ff(1.0/scale_factor) + + self.connect(self, dec, s2f, decim, sink_scale, self) diff --git a/gr-vocoder/python/qa_cvsd_vocoder.py b/gr-vocoder/python/qa_cvsd_vocoder.py new file mode 100755 index 000000000..53045e4a9 --- /dev/null +++ b/gr-vocoder/python/qa_cvsd_vocoder.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2011 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. +# + +from gnuradio import gr, gr_unittest +from vocoder_swig import * +from cvsd import * + +class test_cvsd_vocoder (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block() + + def tearDown (self): + self.tb = None + + def test001_module_load (self): + raw_enc = cvsd_encode_sb(); + raw_dec = cvsd_decode_bs(); + hb_enc = cvsd_encode_fb(); + hb_dec = cvsd_decode_bf(); + + + """ Disable for now + def test01(self): + sample_rate = 8000 + scale_factor = 32000 + + expected_data = (6.9670547250243192e-21, -2.4088578356895596e-05, + -5.1261918997624889e-05, 7.2410854045301676e-05, + 8.444241393590346e-05, -1.2537107068055775e-05, + 0.00024186755763366818, -0.00060463894624263048, + 0.00064864184241741896, 0.010409165173768997, + 0.0087582804262638092, 0.017965050414204597, + 0.010722399689257145, 0.006602009292691946, + 0.02213001623749733, 0.0079685859382152557, + 0.033707316964864731, 0.027021972462534904, + 0.0086071854457259178, 0.0081678871065378189, + 0.039343506097793579, 0.030671956017613411, + 0.029626710340380669, 0.020126519724726677, + 0.023636780679225922, 0.0064640454947948456, + -0.0038861562497913837, 0.0021134600974619389, + -0.0088051930069923401, -0.00023228264763019979, + -0.033737499266862869, -0.033141419291496277, + -0.037145044654607773, -0.0080892946571111679, + -0.077117636799812317, -0.078382067382335663, + -0.055503919720649719, -0.019355267286300659, + -0.022441385313868523, -0.073706060647964478, + -0.054677654057741165, -0.047119375318288803, + -0.044418536126613617, -0.036084383726119995, + -0.0206278245896101, -0.031200021505355835, + -0.0004070434661116451, 0.0006594572332687676, + -0.016584658995270729, 0.07387717068195343, + -0.0063191778026521206, 0.051200628280639648, + -0.029480356723070145, 0.05176771804690361, + 0.038578659296035767, 0.026550088077783585, + 0.067103870213031769, 0.001888439292088151, + 0.28141644597053528, 0.49543789029121399, + 0.6626054048538208, 0.79180729389190674, + 0.89210402965545654, 0.96999943256378174, + 1.0261462926864624, 1.0267977714538574, + 1.0251555442810059, 1.0265737771987915, + 1.0278496742248535, 1.0208886861801147, + 1.0325057506561279, 0.91415292024612427, + 0.83941859006881714, 0.67373806238174438, + 0.51683622598648071, 0.38949671387672424, + 0.16016888618469238, 0.049505095928907394, + -0.16699212789535522, -0.26886492967605591, + -0.49256673455238342, -0.59178370237350464, + -0.73317724466323853, -0.78922677040100098, + -0.88782668113708496, -0.96708977222442627, + -0.96490746736526489, -0.94962418079376221, + -0.94716215133666992, -0.93755108118057251, + -0.84852480888366699, -0.80485564470291138, + -0.69762390851974487, -0.58398681879043579, + -0.45891636610031128, -0.29681697487831116, + -0.16035343706607819, 0.014823081903159618, + 0.16282452642917633, 0.33802291750907898) + + src = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 200, 1, 0) + head = gr.head(gr.sizeof_float, 100) + src_scale = gr.multiply_const_ff(scale_factor) + + interp = blks2.rational_resampler_fff(8, 1) + f2s = gr.float_to_short () + + enc = cvsd_vocoder.encode_sb() + dec = cvsd_vocoder.decode_bs() + + s2f = gr.short_to_float () + decim = blks2.rational_resampler_fff(1, 8) + + sink_scale = gr.multiply_const_ff(1.0/scale_factor) + sink = gr.vector_sink_f() + + self.tb.connect(src, src_scale, interp, f2s, enc) + self.tb.connect(enc, dec, s2f, decim, sink_scale, head, sink) + self.tb.run() + print sink.data() + + self.assertFloatTuplesAlmostEqual (expected_data, sink.data(), 5) + """ + +if __name__ == '__main__': + gr_unittest.run(test_cvsd_vocoder, "test_cvsd_vocoder.xml") diff --git a/gr-vocoder/python/qa_gsm_full_rate.py b/gr-vocoder/python/qa_gsm_full_rate.py index 4164a1965..f9125905c 100755 --- a/gr-vocoder/python/qa_gsm_full_rate.py +++ b/gr-vocoder/python/qa_gsm_full_rate.py @@ -21,7 +21,7 @@ # from gnuradio import gr, gr_unittest -import gsm_full_rate +import vocoder_swig class test_gsm_vocoder (gr_unittest.TestCase): @@ -31,5 +31,9 @@ class test_gsm_vocoder (gr_unittest.TestCase): def tearDown (self): self.tb = None + def test001_module_load (self): + enc = vocoder_swig.gsm_fr_encode_sp(); + dec = vocoder_swig.gsm_fr_decode_ps(); + if __name__ == '__main__': gr_unittest.run(test_gsm_vocoder, "test_gsm_vocoder.xml") diff --git a/gr-vocoder/python/run_tests.in b/gr-vocoder/python/run_tests.in index 96eefc559..e0c61a6b4 100644 --- a/gr-vocoder/python/run_tests.in +++ b/gr-vocoder/python/run_tests.in @@ -5,6 +5,6 @@ # 3rd parameter is path to Python QA directory @top_builddir@/run_tests.sh \ - @abs_top_srcdir@/gr-gsm-fr-vocoder \ - @abs_top_builddir@/gr-gsm-fr-vocoder \ + @abs_top_srcdir@/gr-vocoder \ + @abs_top_builddir@/gr-vocoder \ @srcdir@ diff --git a/gr-vocoder/swig/Makefile.am b/gr-vocoder/swig/Makefile.am index 54c1e004d..202032c19 100644 --- a/gr-vocoder/swig/Makefile.am +++ b/gr-vocoder/swig/Makefile.am @@ -57,6 +57,8 @@ vocoder_swig_la_swig_libadd = \ # additional SWIG files to be installed vocoder_swig_swiginclude_headers = \ + vocoder_cvsd_decode_bs.i \ + vocoder_cvsd_encode_sb.i \ vocoder_gsm_fr_encode_sp.i \ vocoder_gsm_fr_decode_ps.i diff --git a/gr-vocoder/swig/vocoder_cvsd_decode_bs.i b/gr-vocoder/swig/vocoder_cvsd_decode_bs.i new file mode 100644 index 000000000..e990f5440 --- /dev/null +++ b/gr-vocoder/swig/vocoder_cvsd_decode_bs.i @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2009,2011 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 "vocoder_cvsd_decode_bs.h" +%} + +GR_SWIG_BLOCK_MAGIC(vocoder,cvsd_decode_bs); + +vocoder_cvsd_decode_bs_sptr vocoder_make_cvsd_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 vocoder_cvsd_decode_bs : public gr_sync_interpolator +{ +private: + vocoder_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); +}; diff --git a/gr-vocoder/swig/vocoder_cvsd_encode_sb.i b/gr-vocoder/swig/vocoder_cvsd_encode_sb.i new file mode 100644 index 000000000..5db7b3a48 --- /dev/null +++ b/gr-vocoder/swig/vocoder_cvsd_encode_sb.i @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2009,2011 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 "vocoder_cvsd_encode_sb.h" +%} + +GR_SWIG_BLOCK_MAGIC(vocoder,cvsd_encode_sb); + +vocoder_cvsd_encode_sb_sptr vocoder_make_cvsd_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 vocoder_cvsd_encode_sb : public gr_sync_decimator +{ +private: + vocoder_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); +}; diff --git a/gr-vocoder/swig/vocoder_swig.i b/gr-vocoder/swig/vocoder_swig.i index 7876366f7..19798ec79 100644 --- a/gr-vocoder/swig/vocoder_swig.i +++ b/gr-vocoder/swig/vocoder_swig.i @@ -22,6 +22,8 @@ %include "gnuradio.i" +%include "vocoder_cvsd_decode_bs.i" +%include "vocoder_cvsd_encode_sb.i" %include "vocoder_gsm_fr_encode_sp.i" %include "vocoder_gsm_fr_decode_ps.i" |