Statistics
| Branch: | Tag: | Revision:

gnuradio / gr-audio / examples / c++ / dial_tone.cc @ b7d8980a

History | View | Annotate | Download (2.95 KB)

1
/*
2
 * Copyright 2011 Free Software Foundation, Inc.
3
 * 
4
 * This file is part of GNU Radio
5
 * 
6
 * GNU Radio is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3, or (at your option)
9
 * any later version.
10
 * 
11
 * GNU Radio is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with GNU Radio; see the file COPYING.  If not, write to
18
 * the Free Software Foundation, Inc., 51 Franklin Street,
19
 * Boston, MA 02110-1301, USA.
20
 */
21

22

23
/*
24
 * GNU Radio C++ example creating dial tone
25
 * ("the simplest thing that could possibly work")
26
 *
27
 * Send a tone each to the left and right channels of stereo audio
28
 * output and let the user's brain sum them.
29
 *
30
 * GNU Radio makes extensive use of Boost shared pointers.  Signal processing
31
 * blocks are typically created by calling a "make" factory function, which
32
 * returns an instance of the block as a typedef'd shared pointer that can
33
 * be used in any way a regular pointer can.  Shared pointers created this way
34
 * keep track of their memory and free it at the right time, so the user
35
 * doesn't need to worry about it (really).
36
 *
37
 */
38

39
// Include header files for each block used in flowgraph
40
#include <gr_top_block.h>
41
#include <gr_sig_source_f.h>
42
#include <gr_audio_sink.h>
43

44
int main(int argc, char **argv)
45
{
46
  int rate = 48000;                // Audio card sample rate
47
  float ampl = 0.1;                // Don't exceed 0.5 or clipping will occur
48

49
  // Construct a top block that will contain flowgraph blocks.  Alternatively,
50
  // one may create a derived class from gr_top_block and hold instantiated blocks
51
  // as member data for later manipulation.
52
  gr_top_block_sptr tb = gr_make_top_block("dial_tone");
53

54
  // Construct a real-valued signal source for each tone, at given sample rate
55
  gr_sig_source_f_sptr src0 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 350, ampl);
56
  gr_sig_source_f_sptr src1 = gr_make_sig_source_f(rate, GR_SIN_WAVE, 440, ampl);
57

58
  // Construct an audio sink to accept audio tones
59
  audio_sink::sptr sink = audio_make_sink(rate);
60

61
  // Connect output #0 of src0 to input #0 of sink (left channel)
62
  tb->connect(src0, 0, sink, 0);
63

64
  // Connect output #0 of src1 to input #1 of sink (right channel)
65
  tb->connect(src1, 0, sink, 1);
66

67
  // Tell GNU Radio runtime to start flowgraph threads; the foreground thread
68
  // will block until either flowgraph exits (this example doesn't) or the
69
  // application receives SIGINT (e.g., user hits CTRL-C).
70
  //
71
  // Real applications may use tb->start() which returns, allowing the foreground
72
  // thread to proceed, then later use tb->stop(), followed by tb->wait(), to cleanup
73
  // GNU Radio before exiting.
74
  tb->run();
75

76
  // Exit normally.
77
  return 0;
78
}