2 * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __libbackend_portaudio_pcmio_h__
20 #define __libbackend_portaudio_pcmio_h__
25 #include <boost/shared_ptr.hpp>
29 #include <portaudio.h>
38 int state (void) const { return _state; }
40 bool initialize_pa ();
42 void host_api_list (std::vector<std::string>&);
43 bool set_host_api (const std::string& host_api_name);
44 std::string get_host_api () const { return _host_api_name; }
45 PaHostApiIndex get_host_api_index_from_name (const std::string& name);
47 PaDeviceIndex get_default_input_device ();
48 PaDeviceIndex get_default_output_device ();
51 void input_device_list (std::map<int, std::string> &devices) const;
52 void output_device_list (std::map<int, std::string> &devices) const;
54 int available_sample_rates (int device_id, std::vector<float>& sample_rates);
55 int available_buffer_sizes (int device_id, std::vector<uint32_t>& buffer_sizes);
57 bool get_default_buffer_sizes (int device_id, std::vector<uint32_t>& buffer_sizes);
59 bool get_asio_buffer_properties (int device_id,
60 long& min_size_frames,
61 long& max_size_frames,
62 long& preferred_size_frames,
65 bool get_asio_buffer_sizes (int device_id, std::vector<uint32_t>& buffer_size);
68 std::string control_app_name (int device_id) const;
69 void launch_control_app (int device_id);
78 uint32_t samples_per_period
81 uint32_t n_playback_channels (void) const { return _playback_channels; }
82 uint32_t n_capture_channels (void) const { return _capture_channels; }
84 std::string get_input_channel_name (int device_id, uint32_t channel) const;
85 std::string get_output_channel_name (int device_id, uint32_t channel) const;
87 double sample_rate (void) const { return _cur_sample_rate; }
88 uint32_t capture_latency (void) const { return _cur_input_latency; }
89 uint32_t playback_latency (void) const { return _cur_output_latency; }
90 double stream_time(void) const { if (_stream) return Pa_GetStreamTime (_stream); return 0; }
92 int next_cycle(uint32_t n_samples);
93 int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples);
94 int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples);
98 void clear_device_lists ();
99 void add_default_devices ();
106 uint32_t _capture_channels;
107 uint32_t _playback_channels;
111 float *_input_buffer;
112 float *_output_buffer;
114 double _cur_sample_rate;
115 uint32_t _cur_input_latency;
116 uint32_t _cur_output_latency;
123 paDevice (std::string n, uint32_t i, uint32_t o)
130 std::map<int, paDevice *> _input_devices;
131 std::map<int, paDevice *> _output_devices;
133 PaHostApiIndex _host_api_index;
134 std::string _host_api_name;
140 #endif /* __libbackend_portaudio_pcmio_h__ */