3 * Copyright 2006.2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
22 #ifndef INCLUDED_AUDIO_PORTAUDIO_SOURCE_H
23 #define INCLUDED_AUDIO_PORTAUDIO_SOURCE_H
25 #include <gr_sync_block.h>
26 #include <gr_buffer.h>
27 #include <gruel/thread.h>
29 #include <portaudio.h>
32 class audio_portaudio_source;
33 typedef boost::shared_ptr<audio_portaudio_source> audio_portaudio_source_sptr;
36 * \brief PORTAUDIO audio source.
38 * \param sampling_rate sampling rate in Hz
39 * \param device_name PORTAUDIO device name, e.g., "pa:"
40 * \param ok_to_block true if it's ok for us to block
42 audio_portaudio_source_sptr
43 audio_portaudio_make_source (int sampling_rate,
44 const std::string device_name = "",
45 bool ok_to_block = true);
47 PaStreamCallback portaudio_source_callback;
51 * \ Audio source using PORTAUDIO
53 * Input samples must be in the range [-1,1].
55 class audio_portaudio_source : public gr_sync_block {
56 friend audio_portaudio_source_sptr
57 audio_portaudio_make_source (int sampling_rate,
58 const std::string device_name,
61 friend PaStreamCallback portaudio_source_callback;
64 unsigned int d_sampling_rate;
65 std::string d_device_name;
69 unsigned int d_portaudio_buffer_size_frames; // number of frames in a portaudio buffer
72 PaStreamParameters d_input_parameters;
74 gr_buffer_sptr d_writer; // buffer used between work and callback
75 gr_buffer_reader_sptr d_reader;
77 gruel::mutex d_ringbuffer_mutex;
78 gruel::condition_variable d_ringbuffer_cond;
79 bool d_ringbuffer_ready;
82 int d_noverruns; // count of overruns
84 void output_error_msg (const char *msg, int err);
85 void bail (const char *msg, int err) throw (std::runtime_error);
86 void create_ringbuffer();
90 audio_portaudio_source (int sampling_rate, const std::string device_name,
94 ~audio_portaudio_source ();
96 bool check_topology (int ninputs, int noutputs);
98 int work (int ninput_items,
99 gr_vector_const_void_star &input_items,
100 gr_vector_void_star &output_items);
103 #endif /* INCLUDED_AUDIO_PORTAUDIO_SOURCE_H */