GNU Radio 3.5.3.2 C++ API
audio_portaudio_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 #ifndef INCLUDED_AUDIO_PORTAUDIO_SINK_H
23 #define INCLUDED_AUDIO_PORTAUDIO_SINK_H
24 
25 #include <gr_audio_sink.h>
26 #include <gr_buffer.h>
27 #include <gruel/thread.h>
28 #include <string>
29 #include <portaudio.h>
30 #include <stdexcept>
31 //#include <gri_logger.h>
32 
33 PaStreamCallback portaudio_sink_callback;
34 
35 
36 /*!
37  * \brief Audio sink using PORTAUDIO
38  * \ingroup audio_blk
39  *
40  * Input samples must be in the range [-1,1].
41  */
43 
44  friend PaStreamCallback portaudio_sink_callback;
45 
46 
47  unsigned int d_sampling_rate;
48  std::string d_device_name;
49  bool d_ok_to_block;
50  bool d_verbose;
51 
52  unsigned int d_portaudio_buffer_size_frames; // number of frames in a portaudio buffer
53 
54  PaStream *d_stream;
55  PaStreamParameters d_output_parameters;
56 
57  gr_buffer_sptr d_writer; // buffer used between work and callback
58  gr_buffer_reader_sptr d_reader;
59 
60  gruel::mutex d_ringbuffer_mutex;
61  gruel::condition_variable d_ringbuffer_cond;
62  bool d_ringbuffer_ready;
63 
64  // random stats
65  int d_nunderuns; // count of underruns
66  //gri_logger_sptr d_log; // handle to non-blocking logging instance
67 
68  void output_error_msg (const char *msg, int err);
69  void bail (const char *msg, int err) throw (std::runtime_error);
70  void create_ringbuffer();
71 
72 
73 public:
74  audio_portaudio_sink (int sampling_rate, const std::string device_name,
75  bool ok_to_block);
76 
78 
79  bool check_topology (int ninputs, int noutputs);
80 
81  int work (int noutput_items,
82  gr_vector_const_void_star &input_items,
83  gr_vector_void_star &output_items);
84 };
85 
86 #endif /* INCLUDED_AUDIO_PORTAUDIO_SINK_H */