GNU Radio 3.5.3.2 C++ API
audio_osx_sink.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006-2011 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio.
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_AUDIO_OSX_SINK_H
24 #define INCLUDED_AUDIO_OSX_SINK_H
25 
26 #include <gr_audio_sink.h>
27 #include <string>
28 #include <list>
29 #include <AudioUnit/AudioUnit.h>
30 #include <circular_buffer.h>
31 
32 /*!
33  * \brief audio sink using OSX
34  * \ingroup audio_blk
35  *
36  * input signature is one or two streams of floats.
37  * Input samples must be in the range [-1,1].
38  */
39 
40 class audio_osx_sink : public audio_sink {
41 
42  Float64 d_sample_rate;
43  int d_channel_config;
44  UInt32 d_n_channels;
45  UInt32 d_queueSampleCount, d_max_sample_count;
46  bool d_do_block;
47  gruel::mutex* d_internal;
48  gruel::condition_variable* d_cond_data;
49  circular_buffer<float>** d_buffers;
50 
51 // AudioUnits and Such
52  AudioUnit d_OutputAU;
53 
54 public:
55  audio_osx_sink (int sample_rate = 44100,
56  const std::string device_name = "2",
57  bool do_block = true,
58  int channel_config = -1,
59  int max_sample_count = -1);
60 
61  ~audio_osx_sink ();
62 
63  bool IsRunning ();
64  bool start ();
65  bool stop ();
66 
67  int work (int noutput_items,
68  gr_vector_const_void_star &input_items,
69  gr_vector_void_star &output_items);
70 
71 private:
72  static OSStatus AUOutputCallback (void *inRefCon,
73  AudioUnitRenderActionFlags *ioActionFlags,
74  const AudioTimeStamp *inTimeStamp,
75  UInt32 inBusNumber,
76  UInt32 inNumberFrames,
77  AudioBufferList *ioData);
78 };
79 
80 #endif /* INCLUDED_AUDIO_OSX_SINK_H */