GNU Radio 3.5.3.2 C++ API
audio_jack_sink.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2005-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_JACK_SINK_H
00023 #define INCLUDED_AUDIO_JACK_SINK_H
00024 
00025 #include <gr_audio_sink.h>
00026 #include <string>
00027 #include <jack/jack.h>
00028 #include <jack/ringbuffer.h>
00029 #include <stdexcept>
00030 
00031 int jack_sink_process (jack_nframes_t nframes, void *arg);
00032 
00033 /*!
00034  * \brief audio sink using JACK
00035  * \ingroup audio_blk
00036  *
00037  * The sink has one input stream of floats.
00038  *
00039  * Input samples must be in the range [-1,1].
00040  */
00041 class audio_jack_sink : public audio_sink {
00042 
00043   friend int jack_sink_process (jack_nframes_t nframes, void *arg);
00044 
00045   // typedef for pointer to class work method
00046   typedef int (audio_jack_sink::*work_t)(int noutput_items,
00047                                          gr_vector_const_void_star &input_items,
00048                                          gr_vector_void_star &output_items);
00049 
00050   unsigned int          d_sampling_rate;
00051   std::string           d_device_name;
00052   bool                  d_ok_to_block;
00053 
00054   jack_client_t         *d_jack_client;
00055   jack_port_t           *d_jack_output_port;
00056   jack_ringbuffer_t     *d_ringbuffer;
00057   jack_nframes_t        d_jack_buffer_size;
00058   pthread_cond_t        d_ringbuffer_ready;
00059   pthread_mutex_t       d_jack_process_lock;
00060 
00061   // random stats
00062   int                   d_nunderuns;            // count of underruns
00063 
00064   void output_error_msg (const char *msg, int err);
00065   void bail (const char *msg, int err) throw (std::runtime_error);
00066 
00067 
00068 public:
00069   audio_jack_sink (int sampling_rate, const std::string device_name, bool ok_to_block);
00070 
00071   ~audio_jack_sink ();
00072   
00073   bool check_topology (int ninputs, int noutputs);
00074 
00075   int work (int noutput_items,
00076             gr_vector_const_void_star &input_items,
00077             gr_vector_void_star &output_items);
00078 };
00079 
00080 #endif /* INCLUDED_AUDIO_JACK_SINK_H */