GNU Radio 3.4.0 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  *
00036  * The sink has one input stream of floats.
00037  *
00038  * Input samples must be in the range [-1,1].
00039  */
00040 class audio_jack_sink : public audio_sink {
00041 
00042   friend int jack_sink_process (jack_nframes_t nframes, void *arg);
00043 
00044   // typedef for pointer to class work method
00045   typedef int (audio_jack_sink::*work_t)(int noutput_items,
00046                                          gr_vector_const_void_star &input_items,
00047                                          gr_vector_void_star &output_items);
00048 
00049   unsigned int          d_sampling_rate;
00050   std::string           d_device_name;
00051   bool                  d_ok_to_block;
00052 
00053   jack_client_t         *d_jack_client;
00054   jack_port_t           *d_jack_output_port;
00055   jack_ringbuffer_t     *d_ringbuffer;
00056   jack_nframes_t        d_jack_buffer_size;
00057   pthread_cond_t        d_ringbuffer_ready;
00058   pthread_mutex_t       d_jack_process_lock;
00059 
00060   // random stats
00061   int                   d_nunderuns;            // count of underruns
00062 
00063   void output_error_msg (const char *msg, int err);
00064   void bail (const char *msg, int err) throw (std::runtime_error);
00065 
00066 
00067 public:
00068   audio_jack_sink (int sampling_rate, const std::string device_name, bool ok_to_block);
00069 
00070   ~audio_jack_sink ();
00071   
00072   bool check_topology (int ninputs, int noutputs);
00073 
00074   int work (int noutput_items,
00075             gr_vector_const_void_star &input_items,
00076             gr_vector_void_star &output_items);
00077 };
00078 
00079 #endif /* INCLUDED_AUDIO_JACK_SINK_H */