audio_portaudio_source.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 <omnithread.h>
00028 #include <string>
00029 #include <portaudio.h>
00030 #include <stdexcept>
00031 #include <gri_logger.h>
00032
00033 class audio_portaudio_source;
00034 typedef boost::shared_ptr<audio_portaudio_source> audio_portaudio_source_sptr;
00035
00042 audio_portaudio_source_sptr
00043 audio_portaudio_make_source (int sampling_rate,
00044 const std::string dev = "",
00045 bool ok_to_block = true);
00046
00047 PaStreamCallback portaudio_source_callback;
00048
00049
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;
00070
00071 PaStream *d_stream;
00072 PaStreamParameters d_input_parameters;
00073
00074 gr_buffer_sptr d_writer;
00075 gr_buffer_reader_sptr d_reader;
00076 omni_semaphore d_ringbuffer_ready;
00077
00078
00079 int d_noverruns;
00080 gri_logger_sptr d_log;
00081
00082 void output_error_msg (const char *msg, int err);
00083 void bail (const char *msg, int err) throw (std::runtime_error);
00084 void create_ringbuffer();
00085
00086
00087 protected:
00088 audio_portaudio_source (int sampling_rate, const std::string device_name,
00089 bool ok_to_block);
00090
00091 public:
00092 ~audio_portaudio_source ();
00093
00094 bool check_topology (int ninputs, int noutputs);
00095
00096 int work (int ninput_items,
00097 gr_vector_const_void_star &input_items,
00098 gr_vector_void_star &output_items);
00099 };
00100
00101 #endif