GNU Radio 3.4.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006-2011 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef INCLUDED_AUDIO_PORTAUDIO_SOURCE_H 00023 #define INCLUDED_AUDIO_PORTAUDIO_SOURCE_H 00024 00025 #include <gr_audio_source.h> 00026 #include <gr_buffer.h> 00027 #include <gruel/thread.h> 00028 #include <string> 00029 #include <portaudio.h> 00030 #include <stdexcept> 00031 00032 PaStreamCallback portaudio_source_callback; 00033 00034 00035 /*! 00036 * \ Audio source using PORTAUDIO 00037 * 00038 * Input samples must be in the range [-1,1]. 00039 */ 00040 class audio_portaudio_source : public audio_source { 00041 00042 friend PaStreamCallback portaudio_source_callback; 00043 00044 00045 unsigned int d_sampling_rate; 00046 std::string d_device_name; 00047 bool d_ok_to_block; 00048 bool d_verbose; 00049 00050 unsigned int d_portaudio_buffer_size_frames; // number of frames in a portaudio buffer 00051 00052 PaStream *d_stream; 00053 PaStreamParameters d_input_parameters; 00054 00055 gr_buffer_sptr d_writer; // buffer used between work and callback 00056 gr_buffer_reader_sptr d_reader; 00057 00058 gruel::mutex d_ringbuffer_mutex; 00059 gruel::condition_variable d_ringbuffer_cond; 00060 bool d_ringbuffer_ready; 00061 00062 // random stats 00063 int d_noverruns; // count of overruns 00064 00065 void output_error_msg (const char *msg, int err); 00066 void bail (const char *msg, int err) throw (std::runtime_error); 00067 void create_ringbuffer(); 00068 00069 00070 public: 00071 audio_portaudio_source (int sampling_rate, const std::string device_name, 00072 bool ok_to_block); 00073 00074 ~audio_portaudio_source (); 00075 00076 bool check_topology (int ninputs, int noutputs); 00077 00078 int work (int ninput_items, 00079 gr_vector_const_void_star &input_items, 00080 gr_vector_void_star &output_items); 00081 }; 00082 00083 #endif /* INCLUDED_AUDIO_PORTAUDIO_SOURCE_H */