From 7df5b10ddcd64309a5c299f662a4cd62a7d175ab Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 14 Mar 2011 15:20:19 -0700 Subject: gnuradio-examples: add C++ audio examples using new gr-audio * gnuradio-examples/C++/audio/dial_tone --- config/grc_gnuradio_examples.m4 | 4 +- gnuradio-examples/c++/Makefile.am | 4 +- gnuradio-examples/c++/audio/.gitignore | 3 ++ gnuradio-examples/c++/audio/Makefile.am | 38 ++++++++++++++ gnuradio-examples/c++/audio/dial_tone.cc | 78 ++++++++++++++++++++++++++++ gnuradio-examples/c++/dial_tone/.gitignore | 5 -- gnuradio-examples/c++/dial_tone/Makefile.am | 45 ---------------- gnuradio-examples/c++/dial_tone/README | 16 ------ gnuradio-examples/c++/dial_tone/dial_tone.cc | 43 --------------- gnuradio-examples/c++/dial_tone/dial_tone.h | 33 ------------ gnuradio-examples/c++/dial_tone/main.cc | 35 ------------- 11 files changed, 124 insertions(+), 180 deletions(-) create mode 100644 gnuradio-examples/c++/audio/.gitignore create mode 100644 gnuradio-examples/c++/audio/Makefile.am create mode 100644 gnuradio-examples/c++/audio/dial_tone.cc delete mode 100644 gnuradio-examples/c++/dial_tone/.gitignore delete mode 100644 gnuradio-examples/c++/dial_tone/Makefile.am delete mode 100644 gnuradio-examples/c++/dial_tone/README delete mode 100644 gnuradio-examples/c++/dial_tone/dial_tone.cc delete mode 100644 gnuradio-examples/c++/dial_tone/dial_tone.h delete mode 100644 gnuradio-examples/c++/dial_tone/main.cc diff --git a/config/grc_gnuradio_examples.m4 b/config/grc_gnuradio_examples.m4 index 0aad0c0da..203f39d0d 100644 --- a/config/grc_gnuradio_examples.m4 +++ b/config/grc_gnuradio_examples.m4 @@ -20,12 +20,14 @@ dnl Boston, MA 02110-1301, USA. AC_DEFUN([GRC_GNURADIO_EXAMPLES],[ GRC_ENABLE(gnuradio-examples) - dnl Do not do gnuradio-examples if gnuradio-core skipped + dnl Do not do gnuradio-examples if gnuradio-core or gr-audio skipped GRC_CHECK_DEPENDENCY(gnuradio-examples, gnuradio-core) + GRC_CHECK_DEPENDENCY(gnuradio-examples, gr-audio) 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 \ diff --git a/gnuradio-examples/c++/Makefile.am b/gnuradio-examples/c++/Makefile.am index 43c63847a..5a49e0e89 100644 --- a/gnuradio-examples/c++/Makefile.am +++ b/gnuradio-examples/c++/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2006,2008 Free Software Foundation, Inc. +# Copyright 2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -20,4 +20,4 @@ # include $(top_srcdir)/Makefile.common -#SUBDIRS = dial_tone +SUBDIRS = audio diff --git a/gnuradio-examples/c++/audio/.gitignore b/gnuradio-examples/c++/audio/.gitignore new file mode 100644 index 000000000..bb08aaf91 --- /dev/null +++ b/gnuradio-examples/c++/audio/.gitignore @@ -0,0 +1,3 @@ +/Makefile +/Makefile.in +/dial_tone diff --git a/gnuradio-examples/c++/audio/Makefile.am b/gnuradio-examples/c++/audio/Makefile.am new file mode 100644 index 000000000..88bd7c1fd --- /dev/null +++ b/gnuradio-examples/c++/audio/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/gnuradio-examples/c++/audio/dial_tone.cc b/gnuradio-examples/c++/audio/dial_tone.cc new file mode 100644 index 000000000..e4e3d8ceb --- /dev/null +++ b/gnuradio-examples/c++/audio/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/gnuradio-examples/c++/dial_tone/.gitignore b/gnuradio-examples/c++/dial_tone/.gitignore deleted file mode 100644 index c5e345858..000000000 --- a/gnuradio-examples/c++/dial_tone/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/.deps -/.libs -/Makefile -/Makefile.in -/dial_tone diff --git a/gnuradio-examples/c++/dial_tone/Makefile.am b/gnuradio-examples/c++/dial_tone/Makefile.am deleted file mode 100644 index 188275fca..000000000 --- a/gnuradio-examples/c++/dial_tone/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright 2006,2008,2009,2010 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -# For compiling within the GNU Radio build tree -AM_CPPFLAGS = \ - -I$(top_srcdir)/gr-audio-alsa/src \ - $(STD_DEFINES_AND_INCLUDES) \ - $(WITH_INCLUDES) - -GR_AUDIO_ALSA_LA=$(top_builddir)/gr-audio-alsa/src/libgnuradio-audio-alsa.la - -# For compiling outside the tree, these will get fished out by pkgconfig - -noinst_PROGRAMS = dial_tone - -noinst_HEADERS = \ - dial_tone.h - -dial_tone_SOURCES = \ - dial_tone.cc \ - main.cc - -dial_tone_LDADD = \ - $(GNURADIO_CORE_LA) \ - $(GR_AUDIO_ALSA_LA) diff --git a/gnuradio-examples/c++/dial_tone/README b/gnuradio-examples/c++/dial_tone/README deleted file mode 100644 index 6d5ed5059..000000000 --- a/gnuradio-examples/c++/dial_tone/README +++ /dev/null @@ -1,16 +0,0 @@ -This example requires that gr-audio-alsa be built in the main tree in order -to compile successfully. It is not built automatically. - -To build this example, you must make two modifications to the build system: - -1) Add the following line inside config/grc_gnuradio_examples.m4: - - gnuradio-examples/c++/dial_tone/Makefile - - ...to the list of Makefiles already in there. - -2) In gnuradio-examples/c++/Makefile.am, uncomment the SUBDIRS line - -# SUBDIRS = dial_tone - -Then, from the top-level directory, re-run ./bootstrap and ./configure. \ No newline at end of file diff --git a/gnuradio-examples/c++/dial_tone/dial_tone.cc b/gnuradio-examples/c++/dial_tone/dial_tone.cc deleted file mode 100644 index 9a2772a18..000000000 --- a/gnuradio-examples/c++/dial_tone/dial_tone.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2006,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. - */ - -#include -#include -#include -#include - -// Shared pointer constructor -dial_tone_sptr make_dial_tone() -{ - return gnuradio::get_initial_sptr(new dial_tone()); -} - -// Hierarchical block constructor, with no inputs or outputs -dial_tone::dial_tone() : - gr_top_block("dial_tone") -{ - gr_sig_source_f_sptr src0 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 350, 0.1); - gr_sig_source_f_sptr src1 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 440, 0.1); - audio_alsa_sink_sptr sink = audio_alsa_make_sink(48000); - - connect(src0, 0, sink, 0); - connect(src1, 0, sink, 1); -} diff --git a/gnuradio-examples/c++/dial_tone/dial_tone.h b/gnuradio-examples/c++/dial_tone/dial_tone.h deleted file mode 100644 index c645439bb..000000000 --- a/gnuradio-examples/c++/dial_tone/dial_tone.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2006 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 - -class dial_tone; -typedef boost::shared_ptr dial_tone_sptr; -dial_tone_sptr make_dial_tone(); - -class dial_tone : public gr_top_block -{ -private: - dial_tone(); - friend dial_tone_sptr make_dial_tone(); -}; diff --git a/gnuradio-examples/c++/dial_tone/main.cc b/gnuradio-examples/c++/dial_tone/main.cc deleted file mode 100644 index a09bd8288..000000000 --- a/gnuradio-examples/c++/dial_tone/main.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2006 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++ application -// -// Instantiate a top block -// Instantiate a runtime, passing it the top block -// Tell the runtime to go... - -#include - -int main() -{ - dial_tone_sptr top_block = make_dial_tone(); - top_block->run(); - return 0; -} -- cgit