[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4802 - in gnuradio/branches/developers/trondeau/cvsd:
From: |
trondeau |
Subject: |
[Commit-gnuradio] r4802 - in gnuradio/branches/developers/trondeau/cvsd: . config gr-cvsd-vocoder gr-cvsd-vocoder/src gr-cvsd-vocoder/src/lib gr-cvsd-vocoder/src/python |
Date: |
Tue, 27 Mar 2007 17:24:06 -0600 (MDT) |
Author: trondeau
Date: 2007-03-27 17:24:05 -0600 (Tue, 27 Mar 2007)
New Revision: 4802
Added:
gnuradio/branches/developers/trondeau/cvsd/config/grc_gr_cvsd_vocoder.m4
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/Makefile.am
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/Makefile.am
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/Makefile.am
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/__init__.py
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/Makefile.am
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/encdec.py
Modified:
gnuradio/branches/developers/trondeau/cvsd/configure.ac
Log:
wip: first pass at CVSD vocoder; builds but needs debugging, optimization
Added: gnuradio/branches/developers/trondeau/cvsd/config/grc_gr_cvsd_vocoder.m4
===================================================================
--- gnuradio/branches/developers/trondeau/cvsd/config/grc_gr_cvsd_vocoder.m4
(rev 0)
+++ gnuradio/branches/developers/trondeau/cvsd/config/grc_gr_cvsd_vocoder.m4
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,36 @@
+dnl Copyright 2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+dnl
+dnl This file is part of GNU Radio
+dnl
+dnl GNU Radio is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2, or (at your option)
+dnl any later version.
+dnl
+dnl GNU Radio is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with GNU Radio; see the file COPYING. If not, write to
+dnl the Free Software Foundation, Inc., 51 Franklin Street,
+dnl Boston, MA 02110-1301, USA.
+
+AC_DEFUN([GRC_GR_CVSD_VOCODER],[
+ GRC_ENABLE([gr-cvsd-vocoder])
+
+ AC_CONFIG_FILES([\
+ gr-cvsd-vocoder/Makefile \
+ gr-cvsd-vocoder/src/Makefile \
+ gr-cvsd-vocoder/src/lib/Makefile \
+ gr-cvsd-vocoder/src/python/Makefile \
+ gr-cvsd-vocoder/src/python/run_tests \
+ ])
+
+ passed=yes
+ GRC_BUILD_CONDITIONAL([gr-cvsd-vocoder],[
+ dnl run_tests is created from run_tests.in. Make it executable.
+ AC_CONFIG_COMMANDS([run_tests_cvsd], [chmod +x
gr-cvsd-vocoder/src/python/run_tests])
+ ])
+])
Modified: gnuradio/branches/developers/trondeau/cvsd/configure.ac
===================================================================
--- gnuradio/branches/developers/trondeau/cvsd/configure.ac 2007-03-27
20:13:17 UTC (rev 4801)
+++ gnuradio/branches/developers/trondeau/cvsd/configure.ac 2007-03-27
23:24:05 UTC (rev 4802)
@@ -208,6 +208,7 @@
GRC_GR_AUDIO_WINDOWS
GRC_GR_ATSC
GRC_GR_COMEDI
+GRC_GR_CVSD_VOCODER
GRC_GR_GSM_FR_VOCODER
GRC_GR_PAGER
GRC_GR_RADIO_ASTRONOMY
Added: gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/Makefile.am
===================================================================
--- gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/Makefile.am
(rev 0)
+++ gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/Makefile.am
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,25 @@
+#
+# Copyright 2004 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 2, 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
+
+SUBDIRS = src
+DIST_SUBDIRS = src
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/Makefile.am
===================================================================
--- gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/Makefile.am
(rev 0)
+++ gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/Makefile.am
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,22 @@
+#
+# Copyright 2004 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 2, 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.
+#
+
+SUBDIRS = lib python
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/Makefile.am
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/Makefile.am
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/Makefile.am
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,97 @@
+#
+# Copyright 2004,2005 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 2, 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
+
+# Install this stuff so that it ends up as the gnuradio.vocoder module
+# This usually ends up at:
+# ${prefix}/lib/python${python_version}/site-packages/gnuradio/vocoder
+
+ourpythondir = $(grpythondir)/vocoder
+ourlibdir = $(grpyexecdir)/vocoder
+
+INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS)
+
+SWIGPYTHONARGS = $(SWIGPYTHONFLAGS) $(STD_DEFINES_AND_INCLUDES)
+
+
+ALL_IFILES = \
+ $(LOCAL_IFILES) \
+ $(NON_LOCAL_IFILES)
+
+NON_LOCAL_IFILES = \
+ $(GNURADIO_I)
+
+
+LOCAL_IFILES = \
+ $(top_srcdir)/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i
+
+# These files are built by SWIG. The first is the C++ glue.
+# The second is the python wrapper that loads the _howto shared library
+# and knows how to call our extensions.
+
+BUILT_SOURCES = \
+ cvsd_vocoder.cc \
+ cvsd_vocoder.py
+
+# This gets cvsd_vocoder.py installed in the right place
+ourpython_PYTHON = \
+ __init__.py \
+ cvsd_vocoder.py
+
+ourlib_LTLIBRARIES = _cvsd_vocoder.la
+
+# These are the source files that go into the shared library
+_cvsd_vocoder_la_SOURCES = \
+ cvsd_decode_bs.cc \
+ cvsd_encode_sb.cc \
+ cvsd_vocoder.cc
+
+
+# magic flags
+_cvsd_vocoder_la_LDFLAGS = $(NO_UNDEFINED) -module -avoid-version
+
+# link the library against the c++ standard library
+_cvsd_vocoder_la_LIBADD = \
+ $(PYTHON_LDFLAGS) \
+ $(GNURADIO_CORE_LA) \
+ -lstdc++
+
+cvsd_vocoder.cc cvsd_vocoder.py: cvsd_vocoder.i $(ALL_IFILES)
+ $(SWIG) $(SWIGPYTHONARGS) -module cvsd_vocoder -o cvsd_vocoder.cc
$(LOCAL_IFILES)
+
+# These headers get installed in ${prefix}/include/gnuradio
+grinclude_HEADERS = \
+ cvsd_decode_bs.h \
+ cvsd_encode_sb.h
+
+# These swig headers get installed in ${prefix}/include/gnuradio/swig
+swiginclude_HEADERS = \
+ $(LOCAL_IFILES)
+
+
+MOSTLYCLEANFILES = $(BUILT_SOURCES) *.pyc
+
+# Don't distribute output of swig
+dist-hook:
+ @for file in $(BUILT_SOURCES); do echo $(RM) $(distdir)/$$file; done
+ @for file in $(BUILT_SOURCES); do $(RM) $(distdir)/$$file; done
+
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/__init__.py
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/__init__.py
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/__init__.py
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,20 @@
+#
+# Copyright 2005 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 2, 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.
+#
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.cc
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,217 @@
+/* -*- 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 2, 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>
+
+/*
+ * 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 cvsd_decode_bs_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_pos_accum_max <= SHRT_MAX);
+ assert(d_neg_accum_max >= -SHRT_MAX);
+ assert(d_K <= 32);
+ assert(d_J <= d_K);
+
+ // nothing else required in this example
+}
+
+
+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;
+}
+
+short cvsd_decode_bs::cvsd_round (double input)
+{
+ double temp;
+ temp=input+0.5;
+ temp=floor(temp);
+
+ return (short)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];
+
+ unsigned short i=0; // 2 bytes, 0 .. 65,535
+ unsigned char 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
+
+
+ //printf("\nnoutput_item: %d\n", noutput_items);
+
+ // Loop through each input data point
+ for(i = 0; i < noutput_items/8.0; i++) {
+
+ input_byte = in[i];
+
+ // i think is unnecessary, but i'm not sure yet...
+ // Read in short from the file
+ //printf("Reading in two bytes from input file...\n");
+ //fread(ptr_input_byte, sizeof(unsigned char), 1, ptr_fin);
+
+ // 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
+ //printf("Adding bits to form a byte.\n");
+ 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
+ //printf("Updating the runner.\n");
+ 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
+ //printf("Updating stepsize by checking for runs of 1s and 0s.\n");
+ 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) & 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)
+ // printf("Updating stepsize.\n");
+ 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));
+ //printf("Multiplying accum by the accum_decay.\n");
+
+
+ // Check for overflow
+ //printf("Checking for accum saturation.\n");
+ if (d_accum >= d_pos_accum_max) {
+ d_accum=d_pos_accum_max;
+ }
+ else if (d_accum <= d_neg_accum_max) {
+ d_accum=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()
+
+ //printf("returning noutput_items: %d.\n\n", noutput_items);
+
+ return noutput_items;
+}
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_decode_bs.h
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,97 @@
+/* -*- 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 2, 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;
+
+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:
+ 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);
+
+ short cvsd_round(double input);
+ unsigned int cvsd_pow (short radix, short power);
+ unsigned char cvsd_bitwise_sum (unsigned int input);
+
+ short d_min_step;
+ short d_max_step;
+ double d_step_decay;
+ double d_accum_decay;
+
+ //! \brief Size of shift register; the number of output bits remembered in
shift register
+ int d_K;
+
+ //! \brief Number of bits in the shift register that are equal; size of run
of 1s, 0s
+ int d_J;
+
+ short d_pos_accum_max;
+ short d_neg_accum_max;
+
+ int d_accum;
+ int d_loop_counter;
+ unsigned int d_runner;
+ unsigned int d_runner_mask; // 4 bytes, 0 .. 4,294,967,295
+ short d_stepsize;
+
+ 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 */
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.cc
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,215 @@
+/* -*- 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 2, 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>
+
+/*
+ * 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 cvsd_encode_sb_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_pos_accum_max <= SHRT_MAX);
+ assert(d_neg_accum_max >= -SHRT_MAX);
+ assert(d_K <= 32);
+ assert(d_J <= d_K);
+
+ // nothing else required in this example
+}
+
+
+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;
+}
+
+short cvsd_encode_sb::cvsd_round (double input)
+{
+ double temp;
+ temp=input+0.5;
+ temp=floor(temp);
+
+ return (short)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
+
+ //printf("\nnoutput_item: %d\n", noutput_items);
+
+ // Loop through each input data point
+ for(i = 0; i < noutput_items*8; i++) {
+ //printf("Input value is: %d \n", in[i]);
+ //printf("Accum value is: %d \n", d_accum);
+
+ if((int)in[i] >= d_accum) { // Note: sign((data(n)-accum))
+ output_bit=1;
+ }
+ else {
+ output_bit=0;
+ }
+
+ //printf("Output bit is: %d \n", output_bit);
+
+ // Update Accum (i.e. the reference value)
+ // printf("Updating stepsize.\n");
+ 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));
+ //printf("Multiplying by the accum; the result %d.\n", d_accum);
+
+ // Check for overflow
+ if (d_accum >= d_pos_accum_max) {
+ //printf("The accum is at: %d, and the pos_accum_max is: %d.\n",
d_accum, d_pos_accum_max);
+ //printf("Warning! Accum is max saturated!\n");
+ d_accum = d_pos_accum_max;
+ }
+ else if(d_accum <= d_neg_accum_max) {
+ //printf("The accum is at: %d, and the neg_accum_max is: %d.\n",
d_accum, d_neg_accum_max);
+ //printf("Warning! Accum is min saturated!\n");
+ d_accum = d_neg_accum_max;
+ }
+
+ //printf("\n");
+
+ // 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
+ //printf("\nThe runner value is %d. The masked runner is %d. A run
was detected!!!!\n",
+ // d_runner, d_runner & mask);
+ d_stepsize = std::min( (short)(d_stepsize + d_min_step), d_max_step);
+ }
+ else {
+ // No runs of 1s and 0s
+ //printf("\nThe runner value is %d. The masked runner is %d. No runs
detected.\n",
+ // d_runner, d_runner & mask);
+ 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
+
+ //printf("returning noutput_items: %d.\n\n", noutput_items);
+
+ return noutput_items;
+}
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_encode_sb.h
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,96 @@
+/* -*- 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 2, 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;
+
+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:
+ 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);
+
+ short cvsd_round(double input);
+ unsigned int cvsd_pow (short radix, short power);
+ unsigned char cvsd_bitwise_sum (unsigned int input);
+
+ short d_min_step;
+ short d_max_step;
+ double d_step_decay;
+ double d_accum_decay;
+
+ //! \brief Size of shift register; the number of output bits remembered in
shift register
+ int d_K;
+
+ //! \brief Number of bits in the shift register that are equal; size of run
of 1s, 0s
+ int d_J;
+
+ short d_pos_accum_max;
+ short d_neg_accum_max;
+
+ int d_accum;
+ int d_loop_counter;
+ unsigned int d_runner;
+ short d_stepsize;
+
+ 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 */
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/lib/cvsd_vocoder.i
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,85 @@
+/* -*- 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 2, 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.
+ */
+
+%feature("autodoc","1");
+%include "exception.i"
+%import "gnuradio.i"
+
+%{
+#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
+#include "cvsd_encode_sb.h"
+#include "cvsd_decode_bs.h"
+#include <stdexcept>
+%}
+
+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:
+};
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/Makefile.am
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/Makefile.am
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/Makefile.am
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,33 @@
+#
+# Copyright 2004 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 2, 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
+
+EXTRA_DIST = run_tests.in
+
+
+TESTS = \
+ run_tests
+
+
+noinst_PYTHON = \
+ encdec.py \
+ qa_gsm_full_rate.py
Added:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/encdec.py
===================================================================
---
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/encdec.py
(rev 0)
+++
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/encdec.py
2007-03-27 23:24:05 UTC (rev 4802)
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+#
+# 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 2, 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, blks
+from gnuradio import audio
+from gnuradio.vocoder import cvsd_vocoder
+
+def build_graph():
+ fg = gr.flow_graph()
+ #src = audio.source(8000, "plughw:0,0")
+ src = gr.sig_source_f(8000, gr.GR_SIN_WAVE, 100, 1)
+ src_scale = gr.multiply_const_ff(32767)
+
+ interp = blks.rational_resampler_fff(fg, 8, 1)
+ f2s = gr.float_to_short ()
+
+ enc = cvsd_vocoder.encode_sb()
+ dec = cvsd_vocoder.decode_bs()
+
+ s2f = gr.short_to_float ()
+ decim = blks.rational_resampler_fff(fg, 1, 8)
+
+ sink_scale = gr.multiply_const_ff(10000) #1.0/32767.)
+ sink = audio.sink(8000, "plughw:0,0")
+
+ fg.connect(src, src_scale, interp, f2s, enc)
+ fg.connect(enc, dec, s2f, decim, sink_scale, sink)
+
+ fg.connect(src, gr.file_sink(gr.sizeof_float, "source.dat"))
+
+ return fg
+
+if __name__ == '__main__':
+ fg = build_graph()
+ fg.start()
+ raw_input ('Press Enter to exit: ')
+ fg.stop()
Property changes on:
gnuradio/branches/developers/trondeau/cvsd/gr-cvsd-vocoder/src/python/encdec.py
___________________________________________________________________
Name: svn:executable
+ *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4802 - in gnuradio/branches/developers/trondeau/cvsd: . config gr-cvsd-vocoder gr-cvsd-vocoder/src gr-cvsd-vocoder/src/lib gr-cvsd-vocoder/src/python,
trondeau <=