2015-03-12 23:05:53 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __libbackend_portaudio_pcmio_h__
|
|
|
|
#define __libbackend_portaudio_pcmio_h__
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <portaudio.h>
|
|
|
|
|
|
|
|
namespace ARDOUR {
|
|
|
|
|
|
|
|
class PortAudioIO {
|
|
|
|
public:
|
|
|
|
PortAudioIO (void);
|
|
|
|
~PortAudioIO (void);
|
|
|
|
|
2015-08-23 19:06:26 -04:00
|
|
|
enum ErrorCode {
|
|
|
|
NoError = 0,
|
|
|
|
InitializationError,
|
|
|
|
DeInitializationError,
|
|
|
|
DeviceConfigNotSupportedError,
|
|
|
|
StreamOpenError,
|
|
|
|
StreamStartError,
|
|
|
|
StreamStopError,
|
|
|
|
StreamCloseError,
|
|
|
|
IOError,
|
|
|
|
BufferUnderrunError,
|
|
|
|
BufferOverrunError
|
|
|
|
};
|
|
|
|
|
2015-08-20 08:31:06 -04:00
|
|
|
enum StandardDevices {
|
|
|
|
DeviceNone = -2,
|
|
|
|
DeviceDefault = -1
|
|
|
|
};
|
|
|
|
|
2015-07-28 23:28:17 -04:00
|
|
|
void host_api_list (std::vector<std::string>&);
|
|
|
|
bool set_host_api (const std::string& host_api_name);
|
|
|
|
std::string get_host_api () const { return _host_api_name; }
|
2015-08-22 07:16:17 -04:00
|
|
|
PaHostApiTypeId get_current_host_api_type () const;
|
2015-04-01 02:55:34 -04:00
|
|
|
PaHostApiIndex get_host_api_index_from_name (const std::string& name);
|
|
|
|
|
2015-08-23 18:59:58 -04:00
|
|
|
PaDeviceIndex get_default_input_device () const;
|
|
|
|
PaDeviceIndex get_default_output_device () const;
|
2015-04-01 08:56:45 -04:00
|
|
|
|
2015-08-25 03:23:07 -04:00
|
|
|
bool update_devices();
|
2015-05-08 21:42:46 -04:00
|
|
|
void input_device_list (std::map<int, std::string> &devices) const;
|
|
|
|
void output_device_list (std::map<int, std::string> &devices) const;
|
2015-03-12 23:05:53 -04:00
|
|
|
|
2015-08-03 22:02:06 -04:00
|
|
|
int available_sample_rates (int device_id, std::vector<float>& sample_rates);
|
|
|
|
int available_buffer_sizes (int device_id, std::vector<uint32_t>& buffer_sizes);
|
|
|
|
|
|
|
|
#ifdef WITH_ASIO
|
2015-08-03 22:25:46 -04:00
|
|
|
bool get_asio_buffer_properties (int device_id,
|
|
|
|
long& min_size_frames,
|
|
|
|
long& max_size_frames,
|
|
|
|
long& preferred_size_frames,
|
|
|
|
long& granularity);
|
|
|
|
|
2015-08-03 22:02:06 -04:00
|
|
|
bool get_asio_buffer_sizes (int device_id, std::vector<uint32_t>& buffer_size);
|
|
|
|
#endif
|
2015-03-12 23:05:53 -04:00
|
|
|
|
2015-07-20 07:44:46 -04:00
|
|
|
std::string control_app_name (int device_id) const;
|
|
|
|
void launch_control_app (int device_id);
|
2015-03-12 23:05:53 -04:00
|
|
|
|
2015-08-24 06:31:47 -04:00
|
|
|
ErrorCode open_blocking_stream(int device_input,
|
|
|
|
int device_output,
|
|
|
|
double sample_rate,
|
|
|
|
uint32_t samples_per_period);
|
|
|
|
ErrorCode start_stream(void);
|
2015-03-12 23:05:53 -04:00
|
|
|
|
2015-08-24 06:31:47 -04:00
|
|
|
ErrorCode close_stream(void);
|
2015-03-12 23:05:53 -04:00
|
|
|
|
|
|
|
uint32_t n_playback_channels (void) const { return _playback_channels; }
|
|
|
|
uint32_t n_capture_channels (void) const { return _capture_channels; }
|
|
|
|
|
2015-08-04 01:29:03 -04:00
|
|
|
std::string get_input_channel_name (int device_id, uint32_t channel) const;
|
|
|
|
std::string get_output_channel_name (int device_id, uint32_t channel) const;
|
|
|
|
|
2015-03-12 23:05:53 -04:00
|
|
|
double sample_rate (void) const { return _cur_sample_rate; }
|
|
|
|
uint32_t capture_latency (void) const { return _cur_input_latency; }
|
|
|
|
uint32_t playback_latency (void) const { return _cur_output_latency; }
|
|
|
|
double stream_time(void) const { if (_stream) return Pa_GetStreamTime (_stream); return 0; }
|
|
|
|
|
|
|
|
int next_cycle(uint32_t n_samples);
|
|
|
|
int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples);
|
|
|
|
int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples);
|
|
|
|
|
2015-05-03 23:28:41 -04:00
|
|
|
private: // Methods
|
|
|
|
|
2015-08-23 22:57:34 -04:00
|
|
|
static bool pa_initialize();
|
|
|
|
static bool pa_deinitialize();
|
|
|
|
static bool& pa_initialized();
|
|
|
|
|
2015-05-08 21:42:46 -04:00
|
|
|
void clear_device_lists ();
|
2015-08-22 07:04:53 -04:00
|
|
|
void add_none_devices ();
|
2015-05-08 21:42:46 -04:00
|
|
|
void add_default_devices ();
|
2015-05-03 23:28:41 -04:00
|
|
|
void add_devices ();
|
2015-08-06 08:22:18 -04:00
|
|
|
std::string get_host_api_name_from_index (PaHostApiIndex index);
|
2015-05-03 23:28:41 -04:00
|
|
|
|
2015-08-23 04:38:01 -04:00
|
|
|
bool get_output_stream_params(int device_output,
|
|
|
|
PaStreamParameters& outputParam) const;
|
|
|
|
bool get_input_stream_params(int device_input,
|
|
|
|
PaStreamParameters& inputParam) const;
|
|
|
|
|
|
|
|
bool set_sample_rate_and_latency_from_stream();
|
2015-08-23 03:08:50 -04:00
|
|
|
bool allocate_buffers_for_blocking_api (uint32_t samples_per_period);
|
|
|
|
|
2015-08-24 04:35:43 -04:00
|
|
|
ErrorCode pre_stream_open(int device_input,
|
|
|
|
PaStreamParameters& inputParam,
|
|
|
|
int device_output,
|
|
|
|
PaStreamParameters& outputParam);
|
|
|
|
|
2015-08-23 06:36:23 -04:00
|
|
|
void reset_stream_dependents ();
|
|
|
|
|
2015-08-22 23:12:26 -04:00
|
|
|
static void get_default_sample_rates(std::vector<float>&);
|
|
|
|
static void get_default_buffer_sizes(std::vector<uint32_t>&);
|
|
|
|
|
2015-05-03 23:28:41 -04:00
|
|
|
private: // Data
|
2015-03-12 23:05:53 -04:00
|
|
|
uint32_t _capture_channels;
|
|
|
|
uint32_t _playback_channels;
|
|
|
|
|
|
|
|
PaStream *_stream;
|
|
|
|
|
|
|
|
float *_input_buffer;
|
|
|
|
float *_output_buffer;
|
|
|
|
|
|
|
|
double _cur_sample_rate;
|
|
|
|
uint32_t _cur_input_latency;
|
|
|
|
uint32_t _cur_output_latency;
|
|
|
|
|
|
|
|
struct paDevice {
|
|
|
|
std::string name;
|
|
|
|
uint32_t n_inputs;
|
|
|
|
uint32_t n_outputs;
|
|
|
|
|
|
|
|
paDevice (std::string n, uint32_t i, uint32_t o)
|
|
|
|
: name (n)
|
|
|
|
, n_inputs (i)
|
|
|
|
, n_outputs (o)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2015-05-08 21:42:46 -04:00
|
|
|
std::map<int, paDevice *> _input_devices;
|
|
|
|
std::map<int, paDevice *> _output_devices;
|
2015-04-01 02:55:34 -04:00
|
|
|
|
2015-04-01 08:56:45 -04:00
|
|
|
PaHostApiIndex _host_api_index;
|
2015-07-28 23:28:17 -04:00
|
|
|
std::string _host_api_name;
|
2015-04-01 08:56:45 -04:00
|
|
|
|
2015-03-12 23:05:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif /* __libbackend_portaudio_pcmio_h__ */
|