3 * Copyright 2005,2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
22 #ifndef INCLUDED_AUDIO_JACK_SOURCE_H
23 #define INCLUDED_AUDIO_JACK_SOURCE_H
25 #include <gr_sync_block.h>
27 #include <jack/jack.h>
28 #include <jack/ringbuffer.h>
31 class audio_jack_source;
32 typedef boost::shared_ptr<audio_jack_source> audio_jack_source_sptr;
35 * \brief make a JACK audio source.
37 * \param sampling_rate sampling rate in Hz
38 * \param device_name JACK device name, e.g., "gr_source"
41 audio_jack_source_sptr
42 audio_jack_make_source (int sampling_rate,
43 const std::string device_name = "",
44 bool ok_to_block = true);
46 int jack_source_process (jack_nframes_t nframes, void *arg);
49 * \brief audio source using JACK
51 * The source has one input stream of floats.
53 * Output samples will be in the range [-1,1].
55 class audio_jack_source : public gr_sync_block {
56 friend audio_jack_source_sptr
57 audio_jack_make_source (int sampling_rate, const std::string device_name, bool ok_to_block);
59 friend int jack_source_process (jack_nframes_t nframes, void *arg);
61 // typedef for pointer to class work method
62 typedef int (audio_jack_source::*work_t)(int noutput_items,
63 gr_vector_const_void_star &input_items,
64 gr_vector_void_star &output_items);
66 unsigned int d_sampling_rate;
67 std::string d_device_name;
70 jack_client_t *d_jack_client;
71 jack_port_t *d_jack_input_port;
72 jack_ringbuffer_t *d_ringbuffer;
73 jack_nframes_t d_jack_buffer_size;
74 pthread_cond_t d_ringbuffer_ready;
75 pthread_mutex_t d_jack_process_lock;
78 int d_noverruns; // count of overruns
80 void output_error_msg (const char *msg, int err);
81 void bail (const char *msg, int err) throw (std::runtime_error);
85 audio_jack_source (int sampling_rate, const std::string device_name, bool ok_to_block);
88 ~audio_jack_source ();
90 bool check_topology (int ninputs, int noutputs);
92 int work (int noutput_items,
93 gr_vector_const_void_star &input_items,
94 gr_vector_void_star &output_items);
97 #endif /* INCLUDED_AUDIO_JACK_SOURCE_H */