audio_portaudio_source.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006.2010 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_sync_block.h>
00026 #include <gr_buffer.h>
00027 #include <gruel/thread.h>
00028 #include <string>
00029 #include <portaudio.h>
00030 #include <stdexcept>
00031 
00032 class audio_portaudio_source;
00033 typedef boost::shared_ptr<audio_portaudio_source> audio_portaudio_source_sptr;
00034 
00035 /*!
00036  * \brief PORTAUDIO audio source.
00037  *
00038  * \param sampling_rate sampling rate in Hz
00039  * \param device_name PORTAUDIO device name, e.g., "pa:"
00040  * \param ok_to_block   true if it's ok for us to block
00041  */
00042 audio_portaudio_source_sptr
00043 audio_portaudio_make_source (int sampling_rate,
00044                            const std::string device_name = "",
00045                            bool ok_to_block = true);
00046 
00047 PaStreamCallback portaudio_source_callback;
00048 
00049 
00050 /*!
00051  * \ Audio source using PORTAUDIO
00052  *
00053  * Input samples must be in the range [-1,1].
00054  */
00055 class audio_portaudio_source : public gr_sync_block {
00056   friend audio_portaudio_source_sptr
00057   audio_portaudio_make_source (int sampling_rate,
00058                              const std::string device_name,
00059                              bool ok_to_block);
00060 
00061   friend PaStreamCallback portaudio_source_callback;
00062 
00063 
00064   unsigned int          d_sampling_rate;
00065   std::string           d_device_name;
00066   bool                  d_ok_to_block;
00067   bool                  d_verbose;
00068 
00069   unsigned int          d_portaudio_buffer_size_frames; // number of frames in a portaudio buffer
00070 
00071   PaStream              *d_stream;
00072   PaStreamParameters    d_input_parameters;
00073 
00074   gr_buffer_sptr        d_writer;               // buffer used between work and callback
00075   gr_buffer_reader_sptr d_reader;
00076 
00077   gruel::mutex          d_ringbuffer_mutex;
00078   gruel::condition_variable d_ringbuffer_cond;
00079   bool                  d_ringbuffer_ready;
00080 
00081   // random stats
00082   int                   d_noverruns;            // count of overruns
00083 
00084   void output_error_msg (const char *msg, int err);
00085   void bail (const char *msg, int err) throw (std::runtime_error);
00086   void create_ringbuffer();
00087 
00088 
00089  protected:
00090   audio_portaudio_source (int sampling_rate, const std::string device_name,
00091                           bool ok_to_block);
00092 
00093  public:
00094   ~audio_portaudio_source ();
00095   
00096   bool check_topology (int ninputs, int noutputs);
00097 
00098   int work (int ninput_items,
00099             gr_vector_const_void_star &input_items,
00100             gr_vector_void_star &output_items);
00101 };
00102 
00103 #endif /* INCLUDED_AUDIO_PORTAUDIO_SOURCE_H */
Generated on Sat Oct 23 17:36:05 2010 for GNU Radio 3.3.0 C++ API by  doxygen 1.6.3