audio_alsa_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
00023 #ifndef INCLUDED_AUDIO_ALSA_SOURCE_H
00024 #define INCLUDED_AUDIO_ALSA_SOURCE_H
00025
00026
00027 #define ALSA_PCM_NEW_HW_PARAMS_API
00028 #define ALSA_PCM_NEW_SW_PARAMS_API
00029
00030 #include <gr_sync_block.h>
00031 #include <string>
00032 #include <alsa/asoundlib.h>
00033 #include <stdexcept>
00034
00035 class audio_alsa_source;
00036 typedef boost::shared_ptr<audio_alsa_source> audio_alsa_source_sptr;
00037
00045 audio_alsa_source_sptr
00046 audio_alsa_make_source (int sampling_rate,
00047 const std::string dev = "",
00048 bool ok_to_block = true);
00049
00058 class audio_alsa_source : public gr_sync_block {
00059 friend audio_alsa_source_sptr
00060 audio_alsa_make_source (int sampling_rate,
00061 const std::string device_name,
00062 bool ok_to_block);
00063
00064
00065 typedef int (audio_alsa_source::*work_t)(int noutput_items,
00066 gr_vector_const_void_star &input_items,
00067 gr_vector_void_star &output_items);
00068
00069 unsigned int d_sampling_rate;
00070 std::string d_device_name;
00071 snd_pcm_t *d_pcm_handle;
00072 snd_pcm_hw_params_t *d_hw_params;
00073 snd_pcm_sw_params_t *d_sw_params;
00074 snd_pcm_format_t d_format;
00075 unsigned int d_nperiods;
00076 unsigned int d_period_time_us;
00077 snd_pcm_uframes_t d_period_size;
00078 unsigned int d_buffer_size_bytes;
00079 char *d_buffer;
00080 work_t d_worker;
00081 unsigned int d_hw_nchan;
00082 bool d_special_case_stereo_to_mono;
00083
00084
00085 int d_noverruns;
00086 int d_nsuspends;
00087
00088 void output_error_msg (const char *msg, int err);
00089 void bail (const char *msg, int err) throw (std::runtime_error);
00090
00091 protected:
00092 audio_alsa_source (int sampling_rate, const std::string device_name,
00093 bool ok_to_block);
00094
00095 public:
00096 ~audio_alsa_source ();
00097
00098 bool check_topology (int ninputs, int noutputs);
00099
00100 int work (int noutput_items,
00101 gr_vector_const_void_star &input_items,
00102 gr_vector_void_star &output_items);
00103
00104 protected:
00105 bool read_buffer (void *buffer, unsigned nframes, unsigned sizeof_frame);
00106
00107 int work_s16 (int noutput_items,
00108 gr_vector_const_void_star &input_items,
00109 gr_vector_void_star &output_items);
00110
00111 int work_s16_2x1 (int noutput_items,
00112 gr_vector_const_void_star &input_items,
00113 gr_vector_void_star &output_items);
00114
00115 int work_s32 (int noutput_items,
00116 gr_vector_const_void_star &input_items,
00117 gr_vector_void_star &output_items);
00118
00119 int work_s32_2x1 (int noutput_items,
00120 gr_vector_const_void_star &input_items,
00121 gr_vector_void_star &output_items);
00122 };
00123
00124 #endif