From b7d8980a6e9e070609b4270ad51d8a91ebfb60b2 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 4 Jul 2011 21:00:18 -0700 Subject: gnuradio-examples, gr-audio: moved audio Python and C++ examples into gr-audio This begins a transition of examples from a separate gnuradio-examples component into an examples directory with the component they go with. In this commit: gnuradio-examples/c++/audio/ => gr-audio/examples/c++ gnuradio-examples/python/audio => gr-audio/examples/python The system installation directory remains $PREFIX/share/gnuradio/examples/audio --- config/grc_gnuradio_examples.m4 | 5 +- config/grc_gr_audio.m4 | 3 + gnuradio-examples/Makefile.am | 3 +- gnuradio-examples/c++/.gitignore | 5 - gnuradio-examples/c++/Makefile.am | 23 ---- gnuradio-examples/c++/audio/.gitignore | 3 - gnuradio-examples/c++/audio/Makefile.am | 38 ------ gnuradio-examples/c++/audio/dial_tone.cc | 78 ------------ gnuradio-examples/python/Makefile.am | 3 +- gnuradio-examples/python/audio/.gitignore | 10 -- gnuradio-examples/python/audio/Makefile.am | 38 ------ gnuradio-examples/python/audio/audio_copy.py | 64 ---------- gnuradio-examples/python/audio/audio_fft.py | 138 --------------------- gnuradio-examples/python/audio/audio_play.py | 57 --------- gnuradio-examples/python/audio/audio_to_file.py | 63 ---------- gnuradio-examples/python/audio/dial_tone.py | 57 --------- gnuradio-examples/python/audio/dial_tone_daemon.py | 57 --------- gnuradio-examples/python/audio/dial_tone_wav.py | 61 --------- gnuradio-examples/python/audio/mono_tone.py | 66 ---------- gnuradio-examples/python/audio/multi_tone.py | 90 -------------- gnuradio-examples/python/audio/noise.py | 55 -------- .../python/audio/spectrum_inversion.py | 68 ---------- gnuradio-examples/python/audio/test_resampler.py | 66 ---------- gr-audio/Makefile.am | 2 +- gr-audio/examples/.gitignore | 2 + gr-audio/examples/Makefile.am | 28 +++++ gr-audio/examples/c++/.gitignore | 3 + gr-audio/examples/c++/Makefile.am | 38 ++++++ gr-audio/examples/c++/dial_tone.cc | 78 ++++++++++++ gr-audio/examples/python/.gitignore | 4 + gr-audio/examples/python/Makefile.am | 38 ++++++ gr-audio/examples/python/audio_copy.py | 64 ++++++++++ gr-audio/examples/python/audio_fft.py | 138 +++++++++++++++++++++ gr-audio/examples/python/audio_play.py | 57 +++++++++ gr-audio/examples/python/audio_to_file.py | 63 ++++++++++ gr-audio/examples/python/dial_tone.py | 57 +++++++++ gr-audio/examples/python/dial_tone_daemon.py | 57 +++++++++ gr-audio/examples/python/dial_tone_wav.py | 61 +++++++++ gr-audio/examples/python/mono_tone.py | 66 ++++++++++ gr-audio/examples/python/multi_tone.py | 90 ++++++++++++++ gr-audio/examples/python/noise.py | 55 ++++++++ gr-audio/examples/python/spectrum_inversion.py | 68 ++++++++++ gr-audio/examples/python/test_resampler.py | 66 ++++++++++ 43 files changed, 1041 insertions(+), 1045 deletions(-) delete mode 100644 gnuradio-examples/c++/.gitignore delete mode 100644 gnuradio-examples/c++/Makefile.am delete mode 100644 gnuradio-examples/c++/audio/.gitignore delete mode 100644 gnuradio-examples/c++/audio/Makefile.am delete mode 100644 gnuradio-examples/c++/audio/dial_tone.cc delete mode 100644 gnuradio-examples/python/audio/.gitignore delete mode 100644 gnuradio-examples/python/audio/Makefile.am delete mode 100755 gnuradio-examples/python/audio/audio_copy.py delete mode 100755 gnuradio-examples/python/audio/audio_fft.py delete mode 100755 gnuradio-examples/python/audio/audio_play.py delete mode 100755 gnuradio-examples/python/audio/audio_to_file.py delete mode 100755 gnuradio-examples/python/audio/dial_tone.py delete mode 100755 gnuradio-examples/python/audio/dial_tone_daemon.py delete mode 100755 gnuradio-examples/python/audio/dial_tone_wav.py delete mode 100755 gnuradio-examples/python/audio/mono_tone.py delete mode 100755 gnuradio-examples/python/audio/multi_tone.py delete mode 100755 gnuradio-examples/python/audio/noise.py delete mode 100755 gnuradio-examples/python/audio/spectrum_inversion.py delete mode 100755 gnuradio-examples/python/audio/test_resampler.py create mode 100644 gr-audio/examples/.gitignore create mode 100644 gr-audio/examples/Makefile.am create mode 100644 gr-audio/examples/c++/.gitignore create mode 100644 gr-audio/examples/c++/Makefile.am create mode 100644 gr-audio/examples/c++/dial_tone.cc create mode 100644 gr-audio/examples/python/.gitignore create mode 100644 gr-audio/examples/python/Makefile.am create mode 100755 gr-audio/examples/python/audio_copy.py create mode 100755 gr-audio/examples/python/audio_fft.py create mode 100755 gr-audio/examples/python/audio_play.py create mode 100755 gr-audio/examples/python/audio_to_file.py create mode 100755 gr-audio/examples/python/dial_tone.py create mode 100755 gr-audio/examples/python/dial_tone_daemon.py create mode 100755 gr-audio/examples/python/dial_tone_wav.py create mode 100755 gr-audio/examples/python/mono_tone.py create mode 100755 gr-audio/examples/python/multi_tone.py create mode 100755 gr-audio/examples/python/noise.py create mode 100755 gr-audio/examples/python/spectrum_inversion.py create mode 100755 gr-audio/examples/python/test_resampler.py diff --git a/config/grc_gnuradio_examples.m4 b/config/grc_gnuradio_examples.m4 index 203f39d0d..6dff01943 100644 --- a/config/grc_gnuradio_examples.m4 +++ b/config/grc_gnuradio_examples.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2008,2009 Free Software Foundation, Inc. +dnl Copyright 2001,2002,2003,2004,2005,2006,2008,2009,2011 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -26,14 +26,11 @@ AC_DEFUN([GRC_GNURADIO_EXAMPLES],[ AC_CONFIG_FILES([ \ gnuradio-examples/Makefile \ - gnuradio-examples/c++/Makefile \ - gnuradio-examples/c++/audio/Makefile \ gnuradio-examples/python/Makefile \ gnuradio-examples/grc/Makefile \ gnuradio-examples/python/apps/hf_explorer/Makefile \ gnuradio-examples/python/apps/hf_radio/Makefile \ gnuradio-examples/python/apps/Makefile \ - gnuradio-examples/python/audio/Makefile \ gnuradio-examples/python/digital/Makefile \ gnuradio-examples/python/digital_voice/Makefile \ gnuradio-examples/python/digital-bert/Makefile \ diff --git a/config/grc_gr_audio.m4 b/config/grc_gr_audio.m4 index bcb19be35..92a0440d0 100644 --- a/config/grc_gr_audio.m4 +++ b/config/grc_gr_audio.m4 @@ -101,6 +101,9 @@ AC_DEFUN([GRC_GR_AUDIO],[ AC_CONFIG_FILES([ \ gr-audio/Makefile \ + gr-audio/examples/Makefile \ + gr-audio/examples/c++/Makefile \ + gr-audio/examples/python/Makefile \ gr-audio/grc/Makefile \ gr-audio/include/Makefile \ gr-audio/lib/Makefile \ diff --git a/gnuradio-examples/Makefile.am b/gnuradio-examples/Makefile.am index e0c1b1d15..ded4e743d 100644 --- a/gnuradio-examples/Makefile.am +++ b/gnuradio-examples/Makefile.am @@ -21,7 +21,8 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = c++ +SUBDIRS = + if PYTHON SUBDIRS += python grc endif diff --git a/gnuradio-examples/c++/.gitignore b/gnuradio-examples/c++/.gitignore deleted file mode 100644 index 19dd0e0a5..000000000 --- a/gnuradio-examples/c++/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/.deps -/.libs -/Makefile -/Makefile.in -/dialtone diff --git a/gnuradio-examples/c++/Makefile.am b/gnuradio-examples/c++/Makefile.am deleted file mode 100644 index 5a49e0e89..000000000 --- a/gnuradio-examples/c++/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright 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 $(top_srcdir)/Makefile.common -SUBDIRS = audio diff --git a/gnuradio-examples/c++/audio/.gitignore b/gnuradio-examples/c++/audio/.gitignore deleted file mode 100644 index bb08aaf91..000000000 --- a/gnuradio-examples/c++/audio/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Makefile -/Makefile.in -/dial_tone diff --git a/gnuradio-examples/c++/audio/Makefile.am b/gnuradio-examples/c++/audio/Makefile.am deleted file mode 100644 index 88bd7c1fd..000000000 --- a/gnuradio-examples/c++/audio/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright 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 $(top_srcdir)/Makefile.common - -# For compiling with the GNU Radio build tree, use include dir below. -# For compiling outside the tree, use 'pkg-config --cflags gnuradio-audio' -AM_CPPFLAGS = \ - -I$(top_srcdir)/gr-audio/include \ - $(STD_DEFINES_AND_INCLUDES) \ - $(WITH_INCLUDES) - -# For compiling within the GNU Radio build tree, link against GR_AUDIO_LA -# For compiling outside the tree, use 'pkg-config --libs gnuradio-audio' -GR_AUDIO_LA=$(top_builddir)/gr-audio/lib/libgnuradio-audio.la - -noinst_PROGRAMS = dial_tone - -dial_tone_SOURCES = dial_tone.cc -dial_tone_LDADD = $(GNURADIO_CORE_LA) $(GR_AUDIO_LA) diff --git a/gnuradio-examples/c++/audio/dial_tone.cc b/gnuradio-examples/c++/audio/dial_tone.cc deleted file mode 100644 index e4e3d8ceb..000000000 --- a/gnuradio-examples/c++/audio/dial_tone.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 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. - */ - - -/* - * GNU Radio C++ example creating dial tone - * ("the simplest thing that could possibly work") - * - * Send a tone each to the left and right channels of stereo audio - * output and let the user's brain sum them. - * - * GNU Radio makes extensive use of Boost shared pointers. Signal processing - * blocks are typically created by calling a "make" factory function, which - * returns an instance of the block as a typedef'd shared pointer that can - * be used in any way a regular pointer can. Shared pointers created this way - * keep track of their memory and free it at the right time, so the user - * doesn't need to worry about it (really). - * - */ - -// Include header files for each block used in flowgraph -#include -#include -#include - -int main(int argc, char **argv) -{ - int rate = 48000; // Audio card sample rate - float ampl = 0.1; // Don't exceed 0.5 or clipping will occur - - // Construct a top block that will contain flowgraph blocks. Alternatively, - // one may create a derived class from gr_top_block and hold instantiated blocks - // as member data for later manipulation. - gr_top_block_sptr tb = gr_make_top_block("dial_tone"); - - // Construct a real-valued signal source for each tone, at given sample rate - gr_sig_source_f_sptr src0 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 350, ampl); - gr_sig_source_f_sptr src1 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 440, ampl); - - // Construct an audio sink to accept audio tones - audio_sink::sptr sink = audio_make_sink(rate); - - // Connect output #0 of src0 to input #0 of sink (left channel) - tb->connect(src0, 0, sink, 0); - - // Connect output #0 of src1 to input #1 of sink (right channel) - tb->connect(src1, 0, sink, 1); - - // Tell GNU Radio runtime to start flowgraph threads; the foreground thread - // will block until either flowgraph exits (this example doesn't) or the - // application receives SIGINT (e.g., user hits CTRL-C). - // - // Real applications may use tb->start() which returns, allowing the foreground - // thread to proceed, then later use tb->stop(), followed by tb->wait(), to cleanup - // GNU Radio before exiting. - tb->run(); - - // Exit normally. - return 0; -} diff --git a/gnuradio-examples/python/Makefile.am b/gnuradio-examples/python/Makefile.am index ea03b438f..30effdf9a 100644 --- a/gnuradio-examples/python/Makefile.am +++ b/gnuradio-examples/python/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2004,2007,2009 Free Software Foundation, Inc. +# Copyright 2004,2007,2009,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,7 +23,6 @@ include $(top_srcdir)/Makefile.common SUBDIRS = \ apps \ - audio \ digital \ digital-bert \ digital_voice \ diff --git a/gnuradio-examples/python/audio/.gitignore b/gnuradio-examples/python/audio/.gitignore deleted file mode 100644 index c400497f5..000000000 --- a/gnuradio-examples/python/audio/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/*.pyc -/*.pyo diff --git a/gnuradio-examples/python/audio/Makefile.am b/gnuradio-examples/python/audio/Makefile.am deleted file mode 100644 index 356b51559..000000000 --- a/gnuradio-examples/python/audio/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright 2004,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 $(top_srcdir)/Makefile.common - -ourdatadir = $(exampledir)/audio - -dist_ourdata_SCRIPTS = \ - audio_copy.py \ - audio_fft.py \ - audio_play.py \ - audio_to_file.py \ - dial_tone.py \ - dial_tone_daemon.py \ - dial_tone_wav.py \ - mono_tone.py \ - multi_tone.py \ - noise.py \ - spectrum_inversion.py \ - test_resampler.py diff --git a/gnuradio-examples/python/audio/audio_copy.py b/gnuradio-examples/python/audio/audio_copy.py deleted file mode 100755 index 3094c9f7a..000000000 --- a/gnuradio-examples/python/audio/audio_copy.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-I", "--audio-input", type="string", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - src = audio.source (sample_rate, options.audio_input) - dst = audio.sink (sample_rate, options.audio_output) - - # Determine the maximum number of outputs on the source and - # maximum number of inputs on the sink, then connect together - # the most channels we can without overlap - nchan = min (src.output_signature().max_streams(), - dst.input_signature().max_streams()) - - for i in range (nchan): - self.connect ((src, i), (dst, i)) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass - diff --git a/gnuradio-examples/python/audio/audio_fft.py b/gnuradio-examples/python/audio/audio_fft.py deleted file mode 100755 index 960e0f94d..000000000 --- a/gnuradio-examples/python/audio/audio_fft.py +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr, gru, audio -from gnuradio import eng_notation -from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider -from optparse import OptionParser -import wx -import sys - -class app_top_block(stdgui2.std_top_block): - def __init__(self, frame, panel, vbox, argv): - stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) - - self.frame = frame - self.panel = panel - - parser = OptionParser(option_class=eng_option) - parser.add_option("-W", "--waterfall", action="store_true", default=False, - help="Enable waterfall display") - parser.add_option("-S", "--oscilloscope", action="store_true", default=False, - help="Enable oscilloscope display") - parser.add_option("-I", "--audio-input", type="string", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - - (options, args) = parser.parse_args() - sample_rate = int(options.sample_rate) - - if len(args) != 0: - parser.print_help() - sys.exit(1) - - self.show_debug_info = True - - # build the graph - if options.waterfall: - self.scope = \ - waterfallsink2.waterfall_sink_f (panel, fft_size=1024, sample_rate=sample_rate) - elif options.oscilloscope: - self.scope = scopesink2.scope_sink_f(panel, sample_rate=sample_rate) - else: - self.scope = fftsink2.fft_sink_f (panel, fft_size=1024, sample_rate=sample_rate, fft_rate=30, - ref_scale=1.0, ref_level=0, y_divs=12) - - self.src = audio.source (sample_rate, options.audio_input) - - self.connect(self.src, self.scope) - - self._build_gui(vbox) - - # set initial values - - def _set_status_msg(self, msg): - self.frame.GetStatusBar().SetStatusText(msg, 0) - - def _build_gui(self, vbox): - - def _form_set_freq(kv): - return self.set_freq(kv['freq']) - - vbox.Add(self.scope.win, 10, wx.EXPAND) - - #self._build_subpanel(vbox) - - def _build_subpanel(self, vbox_arg): - # build a secondary information panel (sometimes hidden) - - # FIXME figure out how to have this be a subpanel that is always - # created, but has its visibility controlled by foo.Show(True/False) - - def _form_set_decim(kv): - return self.set_decim(kv['decim']) - - if not(self.show_debug_info): - return - - panel = self.panel - vbox = vbox_arg - myform = self.myform - - #panel = wx.Panel(self.panel, -1) - #vbox = wx.BoxSizer(wx.VERTICAL) - - hbox = wx.BoxSizer(wx.HORIZONTAL) - hbox.Add((5,0), 0) - - myform['decim'] = form.int_field( - parent=panel, sizer=hbox, label="Decim", - callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg)) - - hbox.Add((5,0), 1) - myform['fs@usb'] = form.static_float_field( - parent=panel, sizer=hbox, label="Fs@USB") - - hbox.Add((5,0), 1) - myform['dbname'] = form.static_text_field( - parent=panel, sizer=hbox) - - hbox.Add((5,0), 1) - myform['baseband'] = form.static_float_field( - parent=panel, sizer=hbox, label="Analog BB") - - hbox.Add((5,0), 1) - myform['ddc'] = form.static_float_field( - parent=panel, sizer=hbox, label="DDC") - - hbox.Add((5,0), 0) - vbox.Add(hbox, 0, wx.EXPAND) - - -def main (): - app = stdgui2.stdapp(app_top_block, "Audio FFT", nstatus=1) - app.MainLoop() - -if __name__ == '__main__': - main () diff --git a/gnuradio-examples/python/audio/audio_play.py b/gnuradio-examples/python/audio/audio_play.py deleted file mode 100755 index f9520c7cf..000000000 --- a/gnuradio-examples/python/audio/audio_play.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-F", "--filename", type="string", default="audio.dat", - help="read input from FILE") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - parser.add_option("-R", "--repeat", action="store_true", default=False) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - (options, args) = parser.parse_args() - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - src = gr.file_source (gr.sizeof_float, options.filename, options.repeat) - dst = audio.sink (sample_rate, options.audio_output) - self.connect(src, dst) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/audio_to_file.py b/gnuradio-examples/python/audio/audio_to_file.py deleted file mode 100755 index 0d54f7bd2..000000000 --- a/gnuradio-examples/python/audio/audio_to_file.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - usage="%prog: [options] output_filename" - parser = OptionParser(option_class=eng_option, usage=usage) - parser.add_option("-I", "--audio-input", type="string", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - parser.add_option("-N", "--nsamples", type="eng_float", default=None, - help="number of samples to collect [default=+inf]") - - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - sample_rate = int(options.sample_rate) - src = audio.source (sample_rate, options.audio_input) - dst = gr.file_sink (gr.sizeof_float, filename) - - if options.nsamples is None: - self.connect((src, 0), dst) - else: - head = gr.head(gr.sizeof_float, int(options.nsamples)) - self.connect((src, 0), head, dst) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/dial_tone.py b/gnuradio-examples/python/audio/dial_tone.py deleted file mode 100755 index 65c5e50b2..000000000 --- a/gnuradio-examples/python/audio/dial_tone.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - ampl = 0.1 - - src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) - src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) - dst = audio.sink (sample_rate, options.audio_output) - self.connect (src0, (dst, 0)) - self.connect (src1, (dst, 1)) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/dial_tone_daemon.py b/gnuradio-examples/python/audio/dial_tone_daemon.py deleted file mode 100755 index d30d0e117..000000000 --- a/gnuradio-examples/python/audio/dial_tone_daemon.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,2007,2008 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, gru -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser -import os - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - ampl = 0.1 - - src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) - src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) - dst = audio.sink (sample_rate, options.audio_output) - self.connect (src0, (dst, 0)) - self.connect (src1, (dst, 1)) - - -if __name__ == '__main__': - pid = gru.daemonize() - print "To stop this program, enter 'kill %d'" % pid - my_top_block().run() diff --git a/gnuradio-examples/python/audio/dial_tone_wav.py b/gnuradio-examples/python/audio/dial_tone_wav.py deleted file mode 100755 index 6e87b2a48..000000000 --- a/gnuradio-examples/python/audio/dial_tone_wav.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,2007,2008 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. -# - -# GNU Radio example program to record a dial tone to a WAV file - -from gnuradio import gr -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - usage = "%prog: [options] filename" - parser = OptionParser(option_class=eng_option, usage=usage) - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - parser.add_option("-N", "--samples", type="eng_float", default=None, - help="number of samples to record") - (options, args) = parser.parse_args () - if len(args) != 1 or options.samples is None: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - ampl = 0.1 - - src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) - src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) - head0 = gr.head(gr.sizeof_float, int(options.samples)) - head1 = gr.head(gr.sizeof_float, int(options.samples)) - dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16) - - self.connect(src0, head0, (dst, 0)) - self.connect(src1, head1, (dst, 1)) - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/mono_tone.py b/gnuradio-examples/python/audio/mono_tone.py deleted file mode 100755 index 869c2e5ff..000000000 --- a/gnuradio-examples/python/audio/mono_tone.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -#import os -#print os.getpid() -#raw_input('Attach gdb and press Enter: ') - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - parser.add_option("-D", "--dont-block", action="store_false", default=True, - dest="ok_to_block") - - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - ampl = 0.1 - - src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 650, ampl) - - dst = audio.sink (sample_rate, - options.audio_output, - options.ok_to_block) - - self.connect (src0, (dst, 0)) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/multi_tone.py b/gnuradio-examples/python/audio/multi_tone.py deleted file mode 100755 index 7d47dd5d5..000000000 --- a/gnuradio-examples/python/audio/multi_tone.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2006,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. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -#import os -#print os.getpid() -#raw_input('Attach gdb and press Enter: ') - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - parser.add_option ("-m", "--max-channels", type="int", default="16", - help="set maximum channels to use") - parser.add_option("-D", "--dont-block", action="store_false", default=True, - dest="ok_to_block") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - limit_channels = options.max_channels - - ampl = 0.1 - - # With a tip of the hat to Harry Partch, may he R.I.P. - # See "Genesis of a Music". He was into some very wild tunings... - base = 392 - ratios = { 1 : 1.0, - 3 : 3.0/2, - 5 : 5.0/4, - 7 : 7.0/4, - 9 : 9.0/8, - 11 : 11.0/8 } - - # progression = (1, 5, 3, 7) - # progression = (1, 9, 3, 7) - # progression = (3, 7, 9, 11) - # progression = (7, 11, 1, 5) - progression = (7, 11, 1, 5, 9) - - dst = audio.sink (sample_rate, - options.audio_output, - options.ok_to_block) - - max_chan = dst.input_signature().max_streams() - if (max_chan == -1) or (max_chan > limit_channels): - max_chan = limit_channels - - for i in range (max_chan): - quo, rem = divmod (i, len (progression)) - freq = base * ratios[progression[rem]] * (quo + 1) - src = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, freq, ampl) - self.connect (src, (dst, i)) - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/noise.py b/gnuradio-examples/python/audio/noise.py deleted file mode 100755 index 75f741082..000000000 --- a/gnuradio-examples/python/audio/noise.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/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 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 -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, - help="set sample rate to RATE (48000)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - ampl = 0.1 - - src = gr.glfsr_source_b(32) # Pseudorandom noise source - b2f = gr.chunks_to_symbols_bf([ampl, -ampl], 1) - dst = audio.sink(sample_rate, options.audio_output) - self.connect(src, b2f, dst) - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/spectrum_inversion.py b/gnuradio-examples/python/audio/spectrum_inversion.py deleted file mode 100755 index 021e23f2d..000000000 --- a/gnuradio-examples/python/audio/spectrum_inversion.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. - -# -# Gang - Here's a simple script that demonstrates spectrum inversion -# using the multiply by [1,-1] method (mixing with Nyquist frequency). -# Requires nothing but a sound card, and sounds just like listening -# to a SSB signal on the wrong sideband. -# - -from gnuradio import gr -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-I", "--audio-input", type="string", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-r", "--sample-rate", type="eng_float", default=8000, - help="set sample rate to RATE (8000)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - sample_rate = int(options.sample_rate) - src = audio.source (sample_rate, options.audio_input) - dst = audio.sink (sample_rate, options.audio_output) - - vec1 = [1, -1] - vsource = gr.vector_source_f(vec1, True) - multiply = gr.multiply_ff() - - self.connect(src, (multiply, 0)) - self.connect(vsource, (multiply, 1)) - self.connect(multiply, dst) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gnuradio-examples/python/audio/test_resampler.py b/gnuradio-examples/python/audio/test_resampler.py deleted file mode 100755 index 4644c5e2f..000000000 --- a/gnuradio-examples/python/audio/test_resampler.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,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. -# - -from gnuradio import gr, gru, blks2 -from gnuradio import audio -from gnuradio.eng_option import eng_option -from optparse import OptionParser - - -class my_top_block(gr.top_block): - - def __init__(self): - gr.top_block.__init__(self) - - parser = OptionParser(option_class=eng_option) - parser.add_option("-O", "--audio-output", type="string", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") - parser.add_option("-i", "--input-rate", type="eng_float", default=8000, - help="set input sample rate to RATE (%default)") - parser.add_option("-o", "--output-rate", type="eng_float", default=48000, - help="set output sample rate to RATE (%default)") - (options, args) = parser.parse_args () - if len(args) != 0: - parser.print_help() - raise SystemExit, 1 - - input_rate = int(options.input_rate) - output_rate = int(options.output_rate) - - interp = gru.lcm(input_rate, output_rate) / input_rate - decim = gru.lcm(input_rate, output_rate) / output_rate - - print "interp =", interp - print "decim =", decim - - ampl = 0.1 - src0 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 650, ampl) - rr = blks2.rational_resampler_fff(interp, decim) - dst = audio.sink (output_rate, options.audio_output) - self.connect (src0, rr, (dst, 0)) - - -if __name__ == '__main__': - try: - my_top_block().run() - except KeyboardInterrupt: - pass diff --git a/gr-audio/Makefile.am b/gr-audio/Makefile.am index bb0d05d07..cde1702f2 100644 --- a/gr-audio/Makefile.am +++ b/gr-audio/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = include lib +SUBDIRS = include lib examples if PYTHON SUBDIRS += grc swig diff --git a/gr-audio/examples/.gitignore b/gr-audio/examples/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-audio/examples/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-audio/examples/Makefile.am b/gr-audio/examples/Makefile.am new file mode 100644 index 000000000..a2365d403 --- /dev/null +++ b/gr-audio/examples/Makefile.am @@ -0,0 +1,28 @@ +# +# Copyright 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 $(top_srcdir)/Makefile.common + +SUBDIRS = c++ + +if PYTHON +SUBDIRS += python +endif diff --git a/gr-audio/examples/c++/.gitignore b/gr-audio/examples/c++/.gitignore new file mode 100644 index 000000000..bb08aaf91 --- /dev/null +++ b/gr-audio/examples/c++/.gitignore @@ -0,0 +1,3 @@ +/Makefile +/Makefile.in +/dial_tone diff --git a/gr-audio/examples/c++/Makefile.am b/gr-audio/examples/c++/Makefile.am new file mode 100644 index 000000000..88bd7c1fd --- /dev/null +++ b/gr-audio/examples/c++/Makefile.am @@ -0,0 +1,38 @@ +# +# Copyright 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 $(top_srcdir)/Makefile.common + +# For compiling with the GNU Radio build tree, use include dir below. +# For compiling outside the tree, use 'pkg-config --cflags gnuradio-audio' +AM_CPPFLAGS = \ + -I$(top_srcdir)/gr-audio/include \ + $(STD_DEFINES_AND_INCLUDES) \ + $(WITH_INCLUDES) + +# For compiling within the GNU Radio build tree, link against GR_AUDIO_LA +# For compiling outside the tree, use 'pkg-config --libs gnuradio-audio' +GR_AUDIO_LA=$(top_builddir)/gr-audio/lib/libgnuradio-audio.la + +noinst_PROGRAMS = dial_tone + +dial_tone_SOURCES = dial_tone.cc +dial_tone_LDADD = $(GNURADIO_CORE_LA) $(GR_AUDIO_LA) diff --git a/gr-audio/examples/c++/dial_tone.cc b/gr-audio/examples/c++/dial_tone.cc new file mode 100644 index 000000000..e4e3d8ceb --- /dev/null +++ b/gr-audio/examples/c++/dial_tone.cc @@ -0,0 +1,78 @@ +/* + * Copyright 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. + */ + + +/* + * GNU Radio C++ example creating dial tone + * ("the simplest thing that could possibly work") + * + * Send a tone each to the left and right channels of stereo audio + * output and let the user's brain sum them. + * + * GNU Radio makes extensive use of Boost shared pointers. Signal processing + * blocks are typically created by calling a "make" factory function, which + * returns an instance of the block as a typedef'd shared pointer that can + * be used in any way a regular pointer can. Shared pointers created this way + * keep track of their memory and free it at the right time, so the user + * doesn't need to worry about it (really). + * + */ + +// Include header files for each block used in flowgraph +#include +#include +#include + +int main(int argc, char **argv) +{ + int rate = 48000; // Audio card sample rate + float ampl = 0.1; // Don't exceed 0.5 or clipping will occur + + // Construct a top block that will contain flowgraph blocks. Alternatively, + // one may create a derived class from gr_top_block and hold instantiated blocks + // as member data for later manipulation. + gr_top_block_sptr tb = gr_make_top_block("dial_tone"); + + // Construct a real-valued signal source for each tone, at given sample rate + gr_sig_source_f_sptr src0 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 350, ampl); + gr_sig_source_f_sptr src1 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 440, ampl); + + // Construct an audio sink to accept audio tones + audio_sink::sptr sink = audio_make_sink(rate); + + // Connect output #0 of src0 to input #0 of sink (left channel) + tb->connect(src0, 0, sink, 0); + + // Connect output #0 of src1 to input #1 of sink (right channel) + tb->connect(src1, 0, sink, 1); + + // Tell GNU Radio runtime to start flowgraph threads; the foreground thread + // will block until either flowgraph exits (this example doesn't) or the + // application receives SIGINT (e.g., user hits CTRL-C). + // + // Real applications may use tb->start() which returns, allowing the foreground + // thread to proceed, then later use tb->stop(), followed by tb->wait(), to cleanup + // GNU Radio before exiting. + tb->run(); + + // Exit normally. + return 0; +} diff --git a/gr-audio/examples/python/.gitignore b/gr-audio/examples/python/.gitignore new file mode 100644 index 000000000..b4813f3c8 --- /dev/null +++ b/gr-audio/examples/python/.gitignore @@ -0,0 +1,4 @@ +/Makefile +/Makefile.in +/*.pyc +/*.pyo diff --git a/gr-audio/examples/python/Makefile.am b/gr-audio/examples/python/Makefile.am new file mode 100644 index 000000000..356b51559 --- /dev/null +++ b/gr-audio/examples/python/Makefile.am @@ -0,0 +1,38 @@ +# +# Copyright 2004,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 $(top_srcdir)/Makefile.common + +ourdatadir = $(exampledir)/audio + +dist_ourdata_SCRIPTS = \ + audio_copy.py \ + audio_fft.py \ + audio_play.py \ + audio_to_file.py \ + dial_tone.py \ + dial_tone_daemon.py \ + dial_tone_wav.py \ + mono_tone.py \ + multi_tone.py \ + noise.py \ + spectrum_inversion.py \ + test_resampler.py diff --git a/gr-audio/examples/python/audio_copy.py b/gr-audio/examples/python/audio_copy.py new file mode 100755 index 000000000..3094c9f7a --- /dev/null +++ b/gr-audio/examples/python/audio_copy.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-I", "--audio-input", type="string", default="", + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + src = audio.source (sample_rate, options.audio_input) + dst = audio.sink (sample_rate, options.audio_output) + + # Determine the maximum number of outputs on the source and + # maximum number of inputs on the sink, then connect together + # the most channels we can without overlap + nchan = min (src.output_signature().max_streams(), + dst.input_signature().max_streams()) + + for i in range (nchan): + self.connect ((src, i), (dst, i)) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass + diff --git a/gr-audio/examples/python/audio_fft.py b/gr-audio/examples/python/audio_fft.py new file mode 100755 index 000000000..960e0f94d --- /dev/null +++ b/gr-audio/examples/python/audio_fft.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr, gru, audio +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider +from optparse import OptionParser +import wx +import sys + +class app_top_block(stdgui2.std_top_block): + def __init__(self, frame, panel, vbox, argv): + stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) + + self.frame = frame + self.panel = panel + + parser = OptionParser(option_class=eng_option) + parser.add_option("-W", "--waterfall", action="store_true", default=False, + help="Enable waterfall display") + parser.add_option("-S", "--oscilloscope", action="store_true", default=False, + help="Enable oscilloscope display") + parser.add_option("-I", "--audio-input", type="string", default="", + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + + (options, args) = parser.parse_args() + sample_rate = int(options.sample_rate) + + if len(args) != 0: + parser.print_help() + sys.exit(1) + + self.show_debug_info = True + + # build the graph + if options.waterfall: + self.scope = \ + waterfallsink2.waterfall_sink_f (panel, fft_size=1024, sample_rate=sample_rate) + elif options.oscilloscope: + self.scope = scopesink2.scope_sink_f(panel, sample_rate=sample_rate) + else: + self.scope = fftsink2.fft_sink_f (panel, fft_size=1024, sample_rate=sample_rate, fft_rate=30, + ref_scale=1.0, ref_level=0, y_divs=12) + + self.src = audio.source (sample_rate, options.audio_input) + + self.connect(self.src, self.scope) + + self._build_gui(vbox) + + # set initial values + + def _set_status_msg(self, msg): + self.frame.GetStatusBar().SetStatusText(msg, 0) + + def _build_gui(self, vbox): + + def _form_set_freq(kv): + return self.set_freq(kv['freq']) + + vbox.Add(self.scope.win, 10, wx.EXPAND) + + #self._build_subpanel(vbox) + + def _build_subpanel(self, vbox_arg): + # build a secondary information panel (sometimes hidden) + + # FIXME figure out how to have this be a subpanel that is always + # created, but has its visibility controlled by foo.Show(True/False) + + def _form_set_decim(kv): + return self.set_decim(kv['decim']) + + if not(self.show_debug_info): + return + + panel = self.panel + vbox = vbox_arg + myform = self.myform + + #panel = wx.Panel(self.panel, -1) + #vbox = wx.BoxSizer(wx.VERTICAL) + + hbox = wx.BoxSizer(wx.HORIZONTAL) + hbox.Add((5,0), 0) + + myform['decim'] = form.int_field( + parent=panel, sizer=hbox, label="Decim", + callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg)) + + hbox.Add((5,0), 1) + myform['fs@usb'] = form.static_float_field( + parent=panel, sizer=hbox, label="Fs@USB") + + hbox.Add((5,0), 1) + myform['dbname'] = form.static_text_field( + parent=panel, sizer=hbox) + + hbox.Add((5,0), 1) + myform['baseband'] = form.static_float_field( + parent=panel, sizer=hbox, label="Analog BB") + + hbox.Add((5,0), 1) + myform['ddc'] = form.static_float_field( + parent=panel, sizer=hbox, label="DDC") + + hbox.Add((5,0), 0) + vbox.Add(hbox, 0, wx.EXPAND) + + +def main (): + app = stdgui2.stdapp(app_top_block, "Audio FFT", nstatus=1) + app.MainLoop() + +if __name__ == '__main__': + main () diff --git a/gr-audio/examples/python/audio_play.py b/gr-audio/examples/python/audio_play.py new file mode 100755 index 000000000..f9520c7cf --- /dev/null +++ b/gr-audio/examples/python/audio_play.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-F", "--filename", type="string", default="audio.dat", + help="read input from FILE") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + parser.add_option("-R", "--repeat", action="store_true", default=False) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + (options, args) = parser.parse_args() + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + src = gr.file_source (gr.sizeof_float, options.filename, options.repeat) + dst = audio.sink (sample_rate, options.audio_output) + self.connect(src, dst) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/audio_to_file.py b/gr-audio/examples/python/audio_to_file.py new file mode 100755 index 000000000..0d54f7bd2 --- /dev/null +++ b/gr-audio/examples/python/audio_to_file.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# +# Copyright 2004,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + usage="%prog: [options] output_filename" + parser = OptionParser(option_class=eng_option, usage=usage) + parser.add_option("-I", "--audio-input", type="string", default="", + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + parser.add_option("-N", "--nsamples", type="eng_float", default=None, + help="number of samples to collect [default=+inf]") + + (options, args) = parser.parse_args () + if len(args) != 1: + parser.print_help() + raise SystemExit, 1 + filename = args[0] + + sample_rate = int(options.sample_rate) + src = audio.source (sample_rate, options.audio_input) + dst = gr.file_sink (gr.sizeof_float, filename) + + if options.nsamples is None: + self.connect((src, 0), dst) + else: + head = gr.head(gr.sizeof_float, int(options.nsamples)) + self.connect((src, 0), head, dst) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/dial_tone.py b/gr-audio/examples/python/dial_tone.py new file mode 100755 index 000000000..65c5e50b2 --- /dev/null +++ b/gr-audio/examples/python/dial_tone.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + ampl = 0.1 + + src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) + src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) + dst = audio.sink (sample_rate, options.audio_output) + self.connect (src0, (dst, 0)) + self.connect (src1, (dst, 1)) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/dial_tone_daemon.py b/gr-audio/examples/python/dial_tone_daemon.py new file mode 100755 index 000000000..d30d0e117 --- /dev/null +++ b/gr-audio/examples/python/dial_tone_daemon.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,2007,2008 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, gru +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + ampl = 0.1 + + src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) + src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) + dst = audio.sink (sample_rate, options.audio_output) + self.connect (src0, (dst, 0)) + self.connect (src1, (dst, 1)) + + +if __name__ == '__main__': + pid = gru.daemonize() + print "To stop this program, enter 'kill %d'" % pid + my_top_block().run() diff --git a/gr-audio/examples/python/dial_tone_wav.py b/gr-audio/examples/python/dial_tone_wav.py new file mode 100755 index 000000000..6e87b2a48 --- /dev/null +++ b/gr-audio/examples/python/dial_tone_wav.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,2007,2008 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. +# + +# GNU Radio example program to record a dial tone to a WAV file + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + usage = "%prog: [options] filename" + parser = OptionParser(option_class=eng_option, usage=usage) + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + parser.add_option("-N", "--samples", type="eng_float", default=None, + help="number of samples to record") + (options, args) = parser.parse_args () + if len(args) != 1 or options.samples is None: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + ampl = 0.1 + + src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl) + src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl) + head0 = gr.head(gr.sizeof_float, int(options.samples)) + head1 = gr.head(gr.sizeof_float, int(options.samples)) + dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16) + + self.connect(src0, head0, (dst, 0)) + self.connect(src1, head1, (dst, 1)) + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/mono_tone.py b/gr-audio/examples/python/mono_tone.py new file mode 100755 index 000000000..869c2e5ff --- /dev/null +++ b/gr-audio/examples/python/mono_tone.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +#import os +#print os.getpid() +#raw_input('Attach gdb and press Enter: ') + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + parser.add_option("-D", "--dont-block", action="store_false", default=True, + dest="ok_to_block") + + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + ampl = 0.1 + + src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 650, ampl) + + dst = audio.sink (sample_rate, + options.audio_output, + options.ok_to_block) + + self.connect (src0, (dst, 0)) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/multi_tone.py b/gr-audio/examples/python/multi_tone.py new file mode 100755 index 000000000..7d47dd5d5 --- /dev/null +++ b/gr-audio/examples/python/multi_tone.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 2004,2006,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. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +#import os +#print os.getpid() +#raw_input('Attach gdb and press Enter: ') + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + parser.add_option ("-m", "--max-channels", type="int", default="16", + help="set maximum channels to use") + parser.add_option("-D", "--dont-block", action="store_false", default=True, + dest="ok_to_block") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + limit_channels = options.max_channels + + ampl = 0.1 + + # With a tip of the hat to Harry Partch, may he R.I.P. + # See "Genesis of a Music". He was into some very wild tunings... + base = 392 + ratios = { 1 : 1.0, + 3 : 3.0/2, + 5 : 5.0/4, + 7 : 7.0/4, + 9 : 9.0/8, + 11 : 11.0/8 } + + # progression = (1, 5, 3, 7) + # progression = (1, 9, 3, 7) + # progression = (3, 7, 9, 11) + # progression = (7, 11, 1, 5) + progression = (7, 11, 1, 5, 9) + + dst = audio.sink (sample_rate, + options.audio_output, + options.ok_to_block) + + max_chan = dst.input_signature().max_streams() + if (max_chan == -1) or (max_chan > limit_channels): + max_chan = limit_channels + + for i in range (max_chan): + quo, rem = divmod (i, len (progression)) + freq = base * ratios[progression[rem]] * (quo + 1) + src = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, freq, ampl) + self.connect (src, (dst, i)) + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/noise.py b/gr-audio/examples/python/noise.py new file mode 100755 index 000000000..75f741082 --- /dev/null +++ b/gr-audio/examples/python/noise.py @@ -0,0 +1,55 @@ +#!/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 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 +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, + help="set sample rate to RATE (48000)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + ampl = 0.1 + + src = gr.glfsr_source_b(32) # Pseudorandom noise source + b2f = gr.chunks_to_symbols_bf([ampl, -ampl], 1) + dst = audio.sink(sample_rate, options.audio_output) + self.connect(src, b2f, dst) + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/spectrum_inversion.py b/gr-audio/examples/python/spectrum_inversion.py new file mode 100755 index 000000000..021e23f2d --- /dev/null +++ b/gr-audio/examples/python/spectrum_inversion.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. + +# +# Gang - Here's a simple script that demonstrates spectrum inversion +# using the multiply by [1,-1] method (mixing with Nyquist frequency). +# Requires nothing but a sound card, and sounds just like listening +# to a SSB signal on the wrong sideband. +# + +from gnuradio import gr +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-I", "--audio-input", type="string", default="", + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-r", "--sample-rate", type="eng_float", default=8000, + help="set sample rate to RATE (8000)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + sample_rate = int(options.sample_rate) + src = audio.source (sample_rate, options.audio_input) + dst = audio.sink (sample_rate, options.audio_output) + + vec1 = [1, -1] + vsource = gr.vector_source_f(vec1, True) + multiply = gr.multiply_ff() + + self.connect(src, (multiply, 0)) + self.connect(vsource, (multiply, 1)) + self.connect(multiply, dst) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/gr-audio/examples/python/test_resampler.py b/gr-audio/examples/python/test_resampler.py new file mode 100755 index 000000000..4644c5e2f --- /dev/null +++ b/gr-audio/examples/python/test_resampler.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,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. +# + +from gnuradio import gr, gru, blks2 +from gnuradio import audio +from gnuradio.eng_option import eng_option +from optparse import OptionParser + + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + parser = OptionParser(option_class=eng_option) + parser.add_option("-O", "--audio-output", type="string", default="", + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + parser.add_option("-i", "--input-rate", type="eng_float", default=8000, + help="set input sample rate to RATE (%default)") + parser.add_option("-o", "--output-rate", type="eng_float", default=48000, + help="set output sample rate to RATE (%default)") + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + input_rate = int(options.input_rate) + output_rate = int(options.output_rate) + + interp = gru.lcm(input_rate, output_rate) / input_rate + decim = gru.lcm(input_rate, output_rate) / output_rate + + print "interp =", interp + print "decim =", decim + + ampl = 0.1 + src0 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 650, ampl) + rr = blks2.rational_resampler_fff(interp, decim) + dst = audio.sink (output_rate, options.audio_output) + self.connect (src0, rr, (dst, 0)) + + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass -- cgit