GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005,2006 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_JACK_SINK_H 00023 #define INCLUDED_AUDIO_JACK_SINK_H 00024 00025 #include <gr_sync_block.h> 00026 #include <string> 00027 #include <jack/jack.h> 00028 #include <jack/ringbuffer.h> 00029 #include <stdexcept> 00030 00031 class audio_jack_sink; 00032 typedef boost::shared_ptr<audio_jack_sink> audio_jack_sink_sptr; 00033 00034 /*! 00035 * \brief make an JACK audio sink. 00036 * 00037 * \param sampling_rate sampling rate in Hz 00038 * \param device_name JACK device name, e.g., "gr_sink" 00039 * \param ok_to_block 00040 */ 00041 audio_jack_sink_sptr 00042 audio_jack_make_sink (int sampling_rate, 00043 const std::string device_name = "", 00044 bool ok_to_block = true); 00045 00046 int jack_sink_process (jack_nframes_t nframes, void *arg); 00047 00048 /*! 00049 * \brief audio sink using JACK 00050 * 00051 * The sink has one input stream of floats. 00052 * 00053 * Input samples must be in the range [-1,1]. 00054 */ 00055 class audio_jack_sink : public gr_sync_block { 00056 friend audio_jack_sink_sptr 00057 audio_jack_make_sink (int sampling_rate, const std::string device_name, bool ok_to_block); 00058 00059 friend int jack_sink_process (jack_nframes_t nframes, void *arg); 00060 00061 // typedef for pointer to class work method 00062 typedef int (audio_jack_sink::*work_t)(int noutput_items, 00063 gr_vector_const_void_star &input_items, 00064 gr_vector_void_star &output_items); 00065 00066 unsigned int d_sampling_rate; 00067 std::string d_device_name; 00068 bool d_ok_to_block; 00069 00070 jack_client_t *d_jack_client; 00071 jack_port_t *d_jack_output_port; 00072 jack_ringbuffer_t *d_ringbuffer; 00073 jack_nframes_t d_jack_buffer_size; 00074 pthread_cond_t d_ringbuffer_ready; 00075 pthread_mutex_t d_jack_process_lock; 00076 00077 // random stats 00078 int d_nunderuns; // count of underruns 00079 00080 void output_error_msg (const char *msg, int err); 00081 void bail (const char *msg, int err) throw (std::runtime_error); 00082 00083 00084 protected: 00085 audio_jack_sink (int sampling_rate, const std::string device_name, bool ok_to_block); 00086 00087 public: 00088 ~audio_jack_sink (); 00089 00090 bool check_topology (int ninputs, int noutputs); 00091 00092 int work (int noutput_items, 00093 gr_vector_const_void_star &input_items, 00094 gr_vector_void_star &output_items); 00095 }; 00096 00097 #endif /* INCLUDED_AUDIO_JACK_SINK_H */