Imported Upstream version 3.0.4
[debian/gnuradio] / gr-audio-osx / src / audio_osx_sink.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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_sync_block.h>
27 #include <string>
28 #include <list>
29 #include <AudioUnit/AudioUnit.h>
30 #include <circular_buffer.h>
31
32 class audio_osx_sink;
33 typedef boost::shared_ptr<audio_osx_sink> audio_osx_sink_sptr;
34
35 audio_osx_sink_sptr
36 audio_osx_make_sink (int sample_rate = 44100,
37                      const std::string device_name = "2",
38                      bool do_block = true,
39                      int channel_config = -1,
40                      int max_sample_count = -1);
41
42 /*!
43  * \brief audio sink using OSX
44  *
45  * input signature is one or two streams of floats.
46  * Input samples must be in the range [-1,1].
47  */
48
49 class audio_osx_sink : public gr_sync_block {
50   friend audio_osx_sink_sptr
51   audio_osx_make_sink (int sample_rate,
52                        const std::string device_name,
53                        bool do_block,
54                        int channel_config,
55                        int max_sample_count);
56
57   Float64             d_sample_rate;
58   int                 d_channel_config;
59   UInt32              d_n_channels;
60   UInt32              d_queueSampleCount, d_max_sample_count;
61   bool                d_do_block;
62   mld_mutex_ptr       d_internal;
63   mld_condition_ptr   d_cond_data;
64   circular_buffer<float>** d_buffers;
65
66 // AudioUnits and Such
67   AudioUnit           d_OutputAU;
68
69 protected:
70   audio_osx_sink (int sample_rate = 44100,
71                   const std::string device_name = "2",
72                   bool do_block = true,
73                   int channel_config = -1,
74                   int max_sample_count = -1);
75
76 public:
77   ~audio_osx_sink ();
78
79   bool IsRunning ();
80   bool start ();
81   bool stop ();
82
83   int work (int noutput_items,
84             gr_vector_const_void_star &input_items,
85             gr_vector_void_star &output_items);
86
87 private:
88   static OSStatus AUOutputCallback (void *inRefCon, 
89                                     AudioUnitRenderActionFlags *ioActionFlags, 
90                                     const AudioTimeStamp *inTimeStamp, 
91                                     UInt32 inBusNumber, 
92                                     UInt32 inNumberFrames, 
93                                     AudioBufferList *ioData);
94 };
95
96 #endif /* INCLUDED_AUDIO_OSX_SINK_H */