GNU Radio 3.6.4 C++ API
audio_jack_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005-2011 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 #ifndef INCLUDED_AUDIO_JACK_SOURCE_H
23 #define INCLUDED_AUDIO_JACK_SOURCE_H
24 
25 #include <gr_audio_source.h>
26 #include <string>
27 #include <jack/jack.h>
28 #include <jack/ringbuffer.h>
29 #include <stdexcept>
30 
31 int jack_source_process (jack_nframes_t nframes, void *arg);
32 
33 /*!
34  * \brief audio source using JACK
35  * \ingroup audio_blk
36  *
37  * The source has one input stream of floats.
38  *
39  * Output samples will be in the range [-1,1].
40  */
42 
43  friend int jack_source_process (jack_nframes_t nframes, void *arg);
44 
45  // typedef for pointer to class work method
46  typedef int (audio_jack_source::*work_t)(int noutput_items,
47  gr_vector_const_void_star &input_items,
48  gr_vector_void_star &output_items);
49 
50  unsigned int d_sampling_rate;
51  std::string d_device_name;
52  bool d_ok_to_block;
53 
54  jack_client_t *d_jack_client;
55  jack_port_t *d_jack_input_port;
56  jack_ringbuffer_t *d_ringbuffer;
57  jack_nframes_t d_jack_buffer_size;
58  pthread_cond_t d_ringbuffer_ready;
59  pthread_mutex_t d_jack_process_lock;
60 
61  // random stats
62  int d_noverruns; // count of overruns
63 
64  void output_error_msg (const char *msg, int err);
65  void bail (const char *msg, int err) throw (std::runtime_error);
66 
67 
68 public:
69  audio_jack_source (int sampling_rate, const std::string device_name, bool ok_to_block);
70 
72 
73  bool check_topology (int ninputs, int noutputs);
74 
75  int work (int noutput_items,
76  gr_vector_const_void_star &input_items,
77  gr_vector_void_star &output_items);
78 };
79 
80 #endif /* INCLUDED_AUDIO_JACK_SOURCE_H */