2014-04-28 15:29:35 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2013 Paul Davis
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
#include <sys/time.h>
|
2014-04-28 17:00:40 -04:00
|
|
|
#include <regex.h>
|
2014-07-07 10:23:23 -04:00
|
|
|
#include <stdlib.h>
|
2014-04-28 17:00:40 -04:00
|
|
|
|
2014-05-13 01:10:32 -04:00
|
|
|
#include <glibmm.h>
|
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
#include "dummy_audiobackend.h"
|
2014-05-24 18:21:44 -04:00
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
#include "pbd/error.h"
|
2014-05-24 18:21:44 -04:00
|
|
|
#include "ardour/port_manager.h"
|
2014-04-28 15:29:35 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
static std::string s_instance_name;
|
2014-04-28 17:00:40 -04:00
|
|
|
size_t DummyAudioBackend::_max_buffer_size = 8192;
|
2014-06-23 05:56:58 -04:00
|
|
|
std::vector<std::string> DummyAudioBackend::_midi_options;
|
2014-06-23 06:16:35 -04:00
|
|
|
std::vector<AudioBackend::DeviceStatus> DummyAudioBackend::_device_status;
|
2014-04-28 17:00:40 -04:00
|
|
|
|
2014-05-01 09:14:25 -04:00
|
|
|
DummyAudioBackend::DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info)
|
|
|
|
: AudioBackend (e, info)
|
2014-04-28 16:59:19 -04:00
|
|
|
, _running (false)
|
|
|
|
, _freewheeling (false)
|
2014-07-07 10:23:23 -04:00
|
|
|
, _device ("")
|
2014-04-28 16:59:19 -04:00
|
|
|
, _samplerate (48000)
|
2014-04-28 21:13:40 -04:00
|
|
|
, _samples_per_period (1024)
|
2014-04-28 16:59:19 -04:00
|
|
|
, _dsp_load (0)
|
|
|
|
, _n_inputs (0)
|
|
|
|
, _n_outputs (0)
|
2014-05-14 19:18:00 -04:00
|
|
|
, _n_midi_inputs (0)
|
|
|
|
, _n_midi_outputs (0)
|
2014-04-28 16:59:19 -04:00
|
|
|
, _systemic_input_latency (0)
|
|
|
|
, _systemic_output_latency (0)
|
|
|
|
, _processed_samples (0)
|
2014-06-06 07:53:07 -04:00
|
|
|
, _port_change_flag (false)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
|
|
|
_instance_name = s_instance_name;
|
2014-05-24 18:21:44 -04:00
|
|
|
pthread_mutex_init (&_port_callback_mutex, 0);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DummyAudioBackend::~DummyAudioBackend ()
|
|
|
|
{
|
2014-05-24 18:21:44 -04:00
|
|
|
pthread_mutex_destroy (&_port_callback_mutex);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AUDIOBACKEND API */
|
|
|
|
|
|
|
|
std::string
|
|
|
|
DummyAudioBackend::name () const
|
|
|
|
{
|
|
|
|
return X_("Dummy");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::is_realtime () const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<AudioBackend::DeviceStatus>
|
|
|
|
DummyAudioBackend::enumerate_devices () const
|
|
|
|
{
|
2014-06-23 06:16:35 -04:00
|
|
|
if (_device_status.empty()) {
|
2014-07-07 10:23:23 -04:00
|
|
|
_device_status.push_back (DeviceStatus (_("Silence"), true));
|
|
|
|
_device_status.push_back (DeviceStatus (_("Sine Wave"), true));
|
|
|
|
_device_status.push_back (DeviceStatus (_("White Noise"), true));
|
|
|
|
_device_status.push_back (DeviceStatus (_("Pink Noise"), true));
|
|
|
|
_device_status.push_back (DeviceStatus (_("Pink Noise (low CPU)"), true));
|
2014-06-23 06:16:35 -04:00
|
|
|
}
|
|
|
|
return _device_status;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<float>
|
|
|
|
DummyAudioBackend::available_sample_rates (const std::string&) const
|
|
|
|
{
|
|
|
|
std::vector<float> sr;
|
2014-04-28 17:00:40 -04:00
|
|
|
sr.push_back (8000.0);
|
|
|
|
sr.push_back (22050.0);
|
|
|
|
sr.push_back (24000.0);
|
2014-04-28 15:29:35 -04:00
|
|
|
sr.push_back (44100.0);
|
|
|
|
sr.push_back (48000.0);
|
2014-04-28 17:00:40 -04:00
|
|
|
sr.push_back (88200.0);
|
|
|
|
sr.push_back (96000.0);
|
|
|
|
sr.push_back (176400.0);
|
|
|
|
sr.push_back (192000.0);
|
2014-04-28 15:29:35 -04:00
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<uint32_t>
|
|
|
|
DummyAudioBackend::available_buffer_sizes (const std::string&) const
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> bs;
|
2014-04-28 17:00:40 -04:00
|
|
|
bs.push_back (4);
|
|
|
|
bs.push_back (8);
|
|
|
|
bs.push_back (16);
|
|
|
|
bs.push_back (32);
|
2014-04-28 15:29:35 -04:00
|
|
|
bs.push_back (64);
|
2014-04-28 17:00:40 -04:00
|
|
|
bs.push_back (128);
|
|
|
|
bs.push_back (256);
|
|
|
|
bs.push_back (512);
|
2014-04-28 15:29:35 -04:00
|
|
|
bs.push_back (1024);
|
2014-04-28 17:00:40 -04:00
|
|
|
bs.push_back (2048);
|
|
|
|
bs.push_back (4096);
|
|
|
|
bs.push_back (8192);
|
2014-04-28 15:29:35 -04:00
|
|
|
return bs;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::available_input_channel_count (const std::string&) const
|
|
|
|
{
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::available_output_channel_count (const std::string&) const
|
|
|
|
{
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::can_change_sample_rate_when_running () const
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return true;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::can_change_buffer_size_when_running () const
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return true;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-07-07 10:23:23 -04:00
|
|
|
DummyAudioBackend::set_device_name (const std::string& d)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-07-07 10:23:23 -04:00
|
|
|
_device = d;
|
2014-04-28 16:59:19 -04:00
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 16:59:19 -04:00
|
|
|
DummyAudioBackend::set_sample_rate (float sr)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
if (sr <= 0) { return -1; }
|
|
|
|
_samplerate = sr;
|
|
|
|
engine.sample_rate_change (sr);
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 16:59:19 -04:00
|
|
|
DummyAudioBackend::set_buffer_size (uint32_t bs)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (bs <= 0 || bs >= _max_buffer_size) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-04-28 21:13:40 -04:00
|
|
|
_samples_per_period = bs;
|
2014-04-28 16:59:19 -04:00
|
|
|
engine.buffer_size_change (bs);
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::set_interleaved (bool yn)
|
|
|
|
{
|
|
|
|
if (!yn) { return 0; }
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_input_channels (uint32_t cc)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
_n_inputs = cc;
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_output_channels (uint32_t cc)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
_n_outputs = cc;
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_systemic_input_latency (uint32_t sl)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
_systemic_input_latency = sl;
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_systemic_output_latency (uint32_t sl)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
_systemic_output_latency = sl;
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieving parameters */
|
|
|
|
std::string
|
|
|
|
DummyAudioBackend::device_name () const
|
|
|
|
{
|
2014-07-07 10:23:23 -04:00
|
|
|
return _device;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
DummyAudioBackend::sample_rate () const
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return _samplerate;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::buffer_size () const
|
|
|
|
{
|
2014-04-28 21:13:40 -04:00
|
|
|
return _samples_per_period;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::interleaved () const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::input_channels () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
return _n_inputs;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::output_channels () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
return _n_outputs;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::systemic_input_latency () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
return _systemic_input_latency;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::systemic_output_latency () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
return _systemic_output_latency;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
2014-06-23 05:56:58 -04:00
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
/* MIDI */
|
|
|
|
std::vector<std::string>
|
|
|
|
DummyAudioBackend::enumerate_midi_options () const
|
|
|
|
{
|
2014-06-23 05:56:58 -04:00
|
|
|
if (_midi_options.empty()) {
|
|
|
|
_midi_options.push_back (_("1 in, 1 out"));
|
|
|
|
_midi_options.push_back (_("2 in, 2 out"));
|
|
|
|
_midi_options.push_back (_("8 in, 8 out"));
|
|
|
|
}
|
|
|
|
return _midi_options;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-05-15 18:41:35 -04:00
|
|
|
DummyAudioBackend::set_midi_option (const std::string& opt)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-05-15 18:41:35 -04:00
|
|
|
if (opt == _("1 in, 1 out")) {
|
|
|
|
_n_midi_inputs = _n_midi_outputs = 1;
|
|
|
|
}
|
|
|
|
else if (opt == _("2 in, 2 out")) {
|
|
|
|
_n_midi_inputs = _n_midi_outputs = 2;
|
|
|
|
}
|
|
|
|
else if (opt == _("8 in, 8 out")) {
|
|
|
|
_n_midi_inputs = _n_midi_outputs = 8;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_n_midi_inputs = _n_midi_outputs = 0;
|
|
|
|
}
|
2014-06-01 12:18:08 -04:00
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
DummyAudioBackend::midi_option () const
|
|
|
|
{
|
2014-06-01 12:18:08 -04:00
|
|
|
return ""; // TODO
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* State Control */
|
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
static void * pthread_process (void *arg)
|
|
|
|
{
|
|
|
|
DummyAudioBackend *d = static_cast<DummyAudioBackend *>(arg);
|
|
|
|
d->main_process_thread ();
|
|
|
|
pthread_exit (0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
int
|
|
|
|
DummyAudioBackend::_start (bool /*for_latency_measurement*/)
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
if (_running) {
|
|
|
|
PBD::error << _("DummyAudioBackend: already active.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-28 23:12:12 -04:00
|
|
|
if (_ports.size()) {
|
|
|
|
PBD::warning << _("DummyAudioBackend: recovering from unclean shutdown, port registry is not empty.") << endmsg;
|
2014-07-07 10:23:23 -04:00
|
|
|
_system_inputs.clear();
|
2014-04-28 23:12:12 -04:00
|
|
|
_ports.clear();
|
|
|
|
}
|
2014-04-28 16:59:19 -04:00
|
|
|
|
2014-04-28 23:12:12 -04:00
|
|
|
if (register_system_ports()) {
|
|
|
|
PBD::error << _("DummyAudioBackend: failed to register system ports.") << endmsg;
|
2014-04-28 16:59:19 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-05 21:43:39 -04:00
|
|
|
engine.sample_rate_change (_samplerate);
|
|
|
|
engine.buffer_size_change (_samples_per_period);
|
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
if (engine.reestablish_ports ()) {
|
|
|
|
PBD::error << _("DummyAudioBackend: Could not re-establish ports.") << endmsg;
|
|
|
|
stop ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.reconnect_ports ();
|
2014-06-06 07:53:07 -04:00
|
|
|
_port_change_flag = false;
|
2014-04-28 23:12:12 -04:00
|
|
|
|
|
|
|
if (pthread_create (&_main_thread, NULL, pthread_process, this)) {
|
|
|
|
PBD::error << _("DummyAudioBackend: cannot start.") << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int timeout = 5000;
|
2014-05-13 01:10:32 -04:00
|
|
|
while (!_running && --timeout > 0) { Glib::usleep (1000); }
|
2014-04-28 23:12:12 -04:00
|
|
|
|
|
|
|
if (timeout == 0 || !_running) {
|
|
|
|
PBD::error << _("DummyAudioBackend: failed to start process thread.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::stop ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
void *status;
|
|
|
|
if (!_running) {
|
2014-05-24 18:23:14 -04:00
|
|
|
return 0;
|
2014-04-28 16:59:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_running = false;
|
|
|
|
if (pthread_join (_main_thread, &status)) {
|
|
|
|
PBD::error << _("DummyAudioBackend: failed to terminate.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
2014-04-28 23:12:12 -04:00
|
|
|
unregister_system_ports();
|
2014-04-28 16:59:19 -04:00
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 16:59:19 -04:00
|
|
|
DummyAudioBackend::freewheel (bool onoff)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-29 06:57:03 -04:00
|
|
|
if (onoff == _freewheeling) {
|
2014-04-28 16:59:19 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
_freewheeling = onoff;
|
|
|
|
engine.freewheel_callback (onoff);
|
2014-04-28 15:29:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
DummyAudioBackend::dsp_load () const
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return 100.f * _dsp_load;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
DummyAudioBackend::raw_buffer_size (DataType t)
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
switch (t) {
|
|
|
|
case DataType::AUDIO:
|
2014-06-01 12:18:08 -04:00
|
|
|
return _samples_per_period * sizeof(Sample);
|
2014-04-28 17:00:40 -04:00
|
|
|
case DataType::MIDI:
|
|
|
|
return _max_buffer_size; // XXX not really limited
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process time */
|
|
|
|
pframes_t
|
|
|
|
DummyAudioBackend::sample_time ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return _processed_samples;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pframes_t
|
|
|
|
DummyAudioBackend::sample_time_at_cycle_start ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return _processed_samples;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pframes_t
|
|
|
|
DummyAudioBackend::samples_since_cycle_start ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
|
|
|
|
void *
|
|
|
|
DummyAudioBackend::dummy_process_thread (void *arg)
|
|
|
|
{
|
|
|
|
ThreadData* td = reinterpret_cast<ThreadData*> (arg);
|
|
|
|
boost::function<void ()> f = td->f;
|
|
|
|
delete td;
|
|
|
|
f ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
int
|
|
|
|
DummyAudioBackend::create_process_thread (boost::function<void()> func)
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
pthread_t thread_id;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
size_t stacksize = 100000;
|
|
|
|
|
|
|
|
pthread_attr_init (&attr);
|
|
|
|
pthread_attr_setstacksize (&attr, stacksize);
|
|
|
|
ThreadData* td = new ThreadData (this, func, stacksize);
|
|
|
|
|
|
|
|
if (pthread_create (&thread_id, &attr, dummy_process_thread, td)) {
|
|
|
|
PBD::error << _("AudioEngine: cannot create process thread.") << endmsg;
|
2014-06-01 12:18:08 -04:00
|
|
|
pthread_attr_destroy (&attr);
|
2014-04-28 16:59:19 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-01 12:18:08 -04:00
|
|
|
pthread_attr_destroy (&attr);
|
2014-04-28 16:59:19 -04:00
|
|
|
|
|
|
|
_threads.push_back (thread_id);
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::join_process_threads ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
for (std::vector<pthread_t>::const_iterator i = _threads.begin (); i != _threads.end (); ++i)
|
|
|
|
{
|
|
|
|
void *status;
|
|
|
|
if (pthread_join (*i, &status)) {
|
|
|
|
PBD::error << _("AudioEngine: cannot terminate process thread.") << endmsg;
|
|
|
|
rv -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_threads.clear ();
|
|
|
|
return rv;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::in_process_thread ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
for (std::vector<pthread_t>::const_iterator i = _threads.begin (); i != _threads.end (); ++i)
|
|
|
|
{
|
|
|
|
if (pthread_equal (*i, pthread_self ()) != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::process_thread_count ()
|
|
|
|
{
|
2014-04-28 16:59:19 -04:00
|
|
|
return _threads.size ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DummyAudioBackend::update_latencies ()
|
|
|
|
{
|
2014-06-11 16:01:21 -04:00
|
|
|
// trigger latency callback in RT thread (locked graph)
|
|
|
|
port_connect_add_remove_callback();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PORTENGINE API */
|
|
|
|
|
|
|
|
void*
|
|
|
|
DummyAudioBackend::private_handle () const
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string&
|
|
|
|
DummyAudioBackend::my_name () const
|
|
|
|
{
|
|
|
|
return _instance_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::available () const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::port_name_size () const
|
|
|
|
{
|
|
|
|
return 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::set_port_name: Invalid Port(s)") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->set_name (_instance_name + ":" + name);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_port_name (PortEngine::PortHandle port) const
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::get_port_name: Invalid Port(s)") << endmsg;
|
|
|
|
return std::string ();
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->name ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PortEngine::PortHandle
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_port_by_name (const std::string& name) const
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
PortHandle port = (PortHandle) find_port (name);
|
|
|
|
return port;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::get_ports (
|
|
|
|
const std::string& port_name_pattern,
|
|
|
|
DataType type, PortFlags flags,
|
2014-04-28 17:00:40 -04:00
|
|
|
std::vector<std::string>& port_names) const
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
int rv = 0;
|
|
|
|
regex_t port_regex;
|
|
|
|
bool use_regexp = false;
|
|
|
|
if (port_name_pattern.size () > 0) {
|
|
|
|
if (!regcomp (&port_regex, port_name_pattern.c_str (), REG_EXTENDED|REG_NOSUB)) {
|
|
|
|
use_regexp = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < _ports.size (); ++i) {
|
|
|
|
DummyPort* port = _ports[i];
|
|
|
|
if ((port->type () == type) && (port->flags () & flags)) {
|
|
|
|
if (!use_regexp || !regexec (&port_regex, port->name ().c_str (), 0, NULL, 0)) {
|
|
|
|
port_names.push_back (port->name ());
|
|
|
|
++rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (use_regexp) {
|
|
|
|
regfree (&port_regex);
|
|
|
|
}
|
|
|
|
return rv;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DataType
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::port_data_type (PortEngine::PortHandle port) const
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
return DataType::NIL;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->type ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PortEngine::PortHandle
|
|
|
|
DummyAudioBackend::register_port (
|
2014-04-28 17:00:40 -04:00
|
|
|
const std::string& name,
|
|
|
|
ARDOUR::DataType type,
|
|
|
|
ARDOUR::PortFlags flags)
|
|
|
|
{
|
|
|
|
if (name.size () == 0) { return 0; }
|
|
|
|
if (flags & IsPhysical) { return 0; }
|
2014-04-28 23:12:12 -04:00
|
|
|
return add_port (_instance_name + ":" + name, type, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
PortEngine::PortHandle
|
|
|
|
DummyAudioBackend::add_port (
|
|
|
|
const std::string& name,
|
|
|
|
ARDOUR::DataType type,
|
|
|
|
ARDOUR::PortFlags flags)
|
|
|
|
{
|
|
|
|
assert(name.size ());
|
|
|
|
if (find_port (name)) {
|
|
|
|
PBD::error << _("DummyBackend::register_port: Port already exists:")
|
|
|
|
<< " (" << name << ")" << endmsg;
|
2014-04-28 17:00:40 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DummyPort* port = NULL;
|
|
|
|
switch (type) {
|
|
|
|
case DataType::AUDIO:
|
2014-05-24 18:21:44 -04:00
|
|
|
port = new DummyAudioPort (*this, name, flags);
|
2014-04-28 17:00:40 -04:00
|
|
|
break;
|
|
|
|
case DataType::MIDI:
|
2014-05-24 18:21:44 -04:00
|
|
|
port = new DummyMidiPort (*this, name, flags);
|
2014-04-28 17:00:40 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PBD::error << _("DummyBackend::register_port: Invalid Data Type.") << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ports.push_back (port);
|
|
|
|
|
|
|
|
return port;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::unregister_port (PortEngine::PortHandle port_handle)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port_handle)) {
|
|
|
|
PBD::error << _("DummyBackend::unregister_port: Invalid Port.") << endmsg;
|
|
|
|
}
|
2014-04-28 23:12:12 -04:00
|
|
|
DummyPort* port = static_cast<DummyPort*>(port_handle);
|
|
|
|
std::vector<DummyPort*>::iterator i = std::find (_ports.begin (), _ports.end (), static_cast<DummyPort*>(port_handle));
|
2014-04-28 17:00:40 -04:00
|
|
|
if (i == _ports.end ()) {
|
|
|
|
PBD::error << _("DummyBackend::unregister_port: Failed to find port") << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
2014-04-28 23:12:12 -04:00
|
|
|
disconnect_all(port_handle);
|
2014-04-28 17:00:40 -04:00
|
|
|
_ports.erase (i);
|
|
|
|
delete port;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
2014-04-28 23:12:12 -04:00
|
|
|
int
|
|
|
|
DummyAudioBackend::register_system_ports()
|
|
|
|
{
|
|
|
|
LatencyRange lr;
|
2014-07-07 10:23:23 -04:00
|
|
|
enum DummyAudioPort::GeneratorType gt;
|
|
|
|
if (_device == _("White Noise")) {
|
|
|
|
gt = DummyAudioPort::WhiteNoise;
|
|
|
|
} else if (_device == _("Pink Noise")) {
|
|
|
|
gt = DummyAudioPort::PinkNoise;
|
|
|
|
} else if (_device == _("Pink Noise (low CPU)")) {
|
|
|
|
gt = DummyAudioPort::PonyNoise;
|
|
|
|
} else if (_device == _("Sine Wave")) {
|
|
|
|
gt = DummyAudioPort::SineWave;
|
|
|
|
} else {
|
|
|
|
gt = DummyAudioPort::Silence;
|
|
|
|
}
|
2014-04-28 23:12:12 -04:00
|
|
|
|
|
|
|
const int a_ins = _n_inputs > 0 ? _n_inputs : 8;
|
|
|
|
const int a_out = _n_outputs > 0 ? _n_outputs : 8;
|
2014-05-14 19:18:00 -04:00
|
|
|
const int m_ins = _n_midi_inputs > 0 ? _n_midi_inputs : 2;
|
|
|
|
const int m_out = _n_midi_outputs > 0 ? _n_midi_outputs : 2;
|
2014-04-28 23:12:12 -04:00
|
|
|
|
|
|
|
/* audio ports */
|
|
|
|
lr.min = lr.max = _samples_per_period + _systemic_input_latency;
|
|
|
|
for (int i = 1; i <= a_ins; ++i) {
|
|
|
|
char tmp[64];
|
|
|
|
snprintf(tmp, sizeof(tmp), "system:capture_%d", i);
|
|
|
|
PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsOutput | IsPhysical | IsTerminal));
|
|
|
|
if (!p) return -1;
|
|
|
|
set_latency_range (p, false, lr);
|
2014-07-07 10:23:23 -04:00
|
|
|
_system_inputs.push_back (static_cast<DummyAudioPort*>(p));
|
|
|
|
static_cast<DummyAudioPort*>(p)->setup_generator (gt, _samplerate);
|
2014-04-28 23:12:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
lr.min = lr.max = _samples_per_period + _systemic_output_latency;
|
|
|
|
for (int i = 1; i <= a_out; ++i) {
|
|
|
|
char tmp[64];
|
|
|
|
snprintf(tmp, sizeof(tmp), "system:playback_%d", i);
|
|
|
|
PortHandle p = add_port(std::string(tmp), DataType::AUDIO, static_cast<PortFlags>(IsInput | IsPhysical | IsTerminal));
|
|
|
|
if (!p) return -1;
|
2014-06-05 18:57:30 -04:00
|
|
|
set_latency_range (p, true, lr);
|
2014-04-28 23:12:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* midi ports */
|
|
|
|
lr.min = lr.max = _samples_per_period + _systemic_input_latency;
|
|
|
|
for (int i = 1; i <= m_ins; ++i) {
|
|
|
|
char tmp[64];
|
|
|
|
snprintf(tmp, sizeof(tmp), "system:midi_capture_%d", i);
|
|
|
|
PortHandle p = add_port(std::string(tmp), DataType::MIDI, static_cast<PortFlags>(IsOutput | IsPhysical | IsTerminal));
|
|
|
|
if (!p) return -1;
|
|
|
|
set_latency_range (p, false, lr);
|
|
|
|
}
|
|
|
|
|
|
|
|
lr.min = lr.max = _samples_per_period + _systemic_output_latency;
|
|
|
|
for (int i = 1; i <= m_out; ++i) {
|
|
|
|
char tmp[64];
|
|
|
|
snprintf(tmp, sizeof(tmp), "system:midi_playback_%d", i);
|
|
|
|
PortHandle p = add_port(std::string(tmp), DataType::MIDI, static_cast<PortFlags>(IsInput | IsPhysical | IsTerminal));
|
|
|
|
if (!p) return -1;
|
2014-06-05 18:57:30 -04:00
|
|
|
set_latency_range (p, true, lr);
|
2014-04-28 23:12:12 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DummyAudioBackend::unregister_system_ports()
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2014-07-07 10:23:23 -04:00
|
|
|
_system_inputs.clear();
|
2014-04-28 23:12:12 -04:00
|
|
|
while (i < _ports.size ()) {
|
|
|
|
DummyPort* port = _ports[i];
|
|
|
|
if (port->is_physical () && port->is_terminal ()) {
|
|
|
|
port->disconnect_all ();
|
|
|
|
_ports.erase (_ports.begin() + i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
int
|
|
|
|
DummyAudioBackend::connect (const std::string& src, const std::string& dst)
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyPort* src_port = find_port (src);
|
|
|
|
DummyPort* dst_port = find_port (dst);
|
|
|
|
|
|
|
|
if (!src_port) {
|
|
|
|
PBD::error << _("DummyBackend::connect: Invalid Source port:")
|
|
|
|
<< " (" << src <<")" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!dst_port) {
|
|
|
|
PBD::error << _("DummyBackend::connect: Invalid Destination port:")
|
|
|
|
<< " (" << dst <<")" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return src_port->connect (dst_port);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::disconnect (const std::string& src, const std::string& dst)
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyPort* src_port = find_port (src);
|
|
|
|
DummyPort* dst_port = find_port (dst);
|
|
|
|
|
|
|
|
if (!src_port || !dst_port) {
|
|
|
|
PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return src_port->disconnect (dst_port);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::connect (PortEngine::PortHandle src, const std::string& dst)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyPort* dst_port = find_port (dst);
|
|
|
|
if (!valid_port (src)) {
|
|
|
|
PBD::error << _("DummyBackend::connect: Invalid Source Port Handle") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!dst_port) {
|
|
|
|
PBD::error << _("DummyBackend::connect: Invalid Destination Port")
|
|
|
|
<< " (" << dst << ")" << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(src)->connect (dst_port);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::disconnect (PortEngine::PortHandle src, const std::string& dst)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyPort* dst_port = find_port (dst);
|
|
|
|
if (!valid_port (src) || !dst_port) {
|
|
|
|
PBD::error << _("DummyBackend::disconnect: Invalid Port(s)") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(src)->disconnect (dst_port);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::disconnect_all (PortEngine::PortHandle port)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
static_cast<DummyPort*>(port)->disconnect_all ();
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::connected (PortEngine::PortHandle port, bool /* process_callback_safe*/)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::disconnect_all: Invalid Port") << endmsg;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->is_connected ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::connected_to (PortEngine::PortHandle src, const std::string& dst, bool /*process_callback_safe*/)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyPort* dst_port = find_port (dst);
|
|
|
|
if (!valid_port (src) || !dst_port) {
|
|
|
|
PBD::error << _("DummyBackend::connected_to: Invalid Port") << endmsg;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(src)->is_connected (dst_port);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::physically_connected (PortEngine::PortHandle port, bool /*process_callback_safe*/)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::physically_connected: Invalid Port") << endmsg;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->is_physically_connected ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std::string>& names, bool /*process_callback_safe*/)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyBackend::get_connections: Invalid Port") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (0 == names.size ());
|
|
|
|
|
|
|
|
const std::vector<DummyPort*>& connected_ports = static_cast<DummyPort*>(port)->get_connections ();
|
|
|
|
|
|
|
|
for (std::vector<DummyPort*>::const_iterator i = connected_ports.begin (); i != connected_ports.end (); ++i) {
|
|
|
|
names.push_back ((*i)->name ());
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int)names.size ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* MIDI */
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::midi_event_get (
|
|
|
|
pframes_t& timestamp,
|
|
|
|
size_t& size, uint8_t** buf, void* port_buffer,
|
|
|
|
uint32_t event_index)
|
|
|
|
{
|
|
|
|
assert (buf && port_buffer);
|
2014-04-28 21:13:40 -04:00
|
|
|
DummyMidiBuffer& source = * static_cast<DummyMidiBuffer*>(port_buffer);
|
2014-04-28 17:00:40 -04:00
|
|
|
if (event_index >= source.size ()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
DummyMidiEvent * const event = source[event_index].get ();
|
|
|
|
|
|
|
|
timestamp = event->timestamp ();
|
|
|
|
size = event->size ();
|
|
|
|
*buf = event->data ();
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::midi_event_put (
|
|
|
|
void* port_buffer,
|
|
|
|
pframes_t timestamp,
|
|
|
|
const uint8_t* buffer, size_t size)
|
|
|
|
{
|
|
|
|
assert (buffer && port_buffer);
|
2014-04-28 21:13:40 -04:00
|
|
|
DummyMidiBuffer& dst = * static_cast<DummyMidiBuffer*>(port_buffer);
|
2014-04-28 17:00:40 -04:00
|
|
|
if (dst.size () && (pframes_t)dst.back ()->timestamp () > timestamp) {
|
|
|
|
fprintf (stderr, "DummyMidiBuffer: it's too late for this event.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dst.push_back (boost::shared_ptr<DummyMidiEvent>(new DummyMidiEvent (timestamp, buffer, size)));
|
|
|
|
return 0;
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DummyAudioBackend::get_midi_event_count (void* port_buffer)
|
|
|
|
{
|
2014-05-24 18:23:14 -04:00
|
|
|
assert (port_buffer);
|
2014-04-28 17:00:40 -04:00
|
|
|
return static_cast<DummyMidiBuffer*>(port_buffer)->size ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DummyAudioBackend::midi_clear (void* port_buffer)
|
|
|
|
{
|
2014-05-24 18:23:14 -04:00
|
|
|
assert (port_buffer);
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyMidiBuffer * buf = static_cast<DummyMidiBuffer*>(port_buffer);
|
|
|
|
assert (buf);
|
|
|
|
buf->clear ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Monitoring */
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::can_monitor_input () const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::request_input_monitoring (PortEngine::PortHandle, bool)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DummyAudioBackend::ensure_input_monitoring (PortEngine::PortHandle, bool)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyAudioBackend::monitoring_input (PortEngine::PortHandle)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Latency management */
|
|
|
|
|
|
|
|
void
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::set_latency_range (PortEngine::PortHandle port, bool for_playback, LatencyRange latency_range)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyPort::set_latency_range (): invalid port.") << endmsg;
|
|
|
|
}
|
|
|
|
static_cast<DummyPort*>(port)->set_latency_range (latency_range, for_playback);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LatencyRange
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_latency_range (PortEngine::PortHandle port, bool for_playback)
|
|
|
|
{
|
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyPort::get_latency_range (): invalid port.") << endmsg;
|
|
|
|
LatencyRange r;
|
|
|
|
r.min = 0;
|
|
|
|
r.max = 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->latency_range (for_playback);
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Discovering physical ports */
|
|
|
|
|
|
|
|
bool
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::port_is_physical (PortEngine::PortHandle port) const
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
if (!valid_port (port)) {
|
|
|
|
PBD::error << _("DummyPort::port_is_physical (): invalid port.") << endmsg;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<DummyPort*>(port)->is_physical ();
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_physical_outputs (DataType type, std::vector<std::string>& port_names)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
for (size_t i = 0; i < _ports.size (); ++i) {
|
|
|
|
DummyPort* port = _ports[i];
|
2014-06-01 12:16:15 -04:00
|
|
|
if ((port->type () == type) && port->is_input () && port->is_physical ()) {
|
2014-04-28 17:00:40 -04:00
|
|
|
port_names.push_back (port->name ());
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_physical_inputs (DataType type, std::vector<std::string>& port_names)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
for (size_t i = 0; i < _ports.size (); ++i) {
|
|
|
|
DummyPort* port = _ports[i];
|
2014-06-01 12:16:15 -04:00
|
|
|
if ((port->type () == type) && port->is_output () && port->is_physical ()) {
|
2014-04-28 17:00:40 -04:00
|
|
|
port_names.push_back (port->name ());
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ChanCount
|
|
|
|
DummyAudioBackend::n_physical_outputs () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
int n_midi = 0;
|
|
|
|
int n_audio = 0;
|
|
|
|
for (size_t i = 0; i < _ports.size (); ++i) {
|
|
|
|
DummyPort* port = _ports[i];
|
|
|
|
if (port->is_output () && port->is_physical ()) {
|
|
|
|
switch (port->type ()) {
|
|
|
|
case DataType::AUDIO: ++n_audio; break;
|
|
|
|
case DataType::MIDI: ++n_midi; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
ChanCount cc;
|
2014-04-28 17:00:40 -04:00
|
|
|
cc.set (DataType::AUDIO, n_audio);
|
|
|
|
cc.set (DataType::MIDI, n_midi);
|
2014-04-28 15:29:35 -04:00
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChanCount
|
|
|
|
DummyAudioBackend::n_physical_inputs () const
|
|
|
|
{
|
2014-04-28 17:00:40 -04:00
|
|
|
int n_midi = 0;
|
|
|
|
int n_audio = 0;
|
|
|
|
for (size_t i = 0; i < _ports.size (); ++i) {
|
|
|
|
DummyPort* port = _ports[i];
|
|
|
|
if (port->is_input () && port->is_physical ()) {
|
|
|
|
switch (port->type ()) {
|
|
|
|
case DataType::AUDIO: ++n_audio; break;
|
|
|
|
case DataType::MIDI: ++n_midi; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 15:29:35 -04:00
|
|
|
ChanCount cc;
|
2014-04-28 17:00:40 -04:00
|
|
|
cc.set (DataType::AUDIO, n_audio);
|
|
|
|
cc.set (DataType::MIDI, n_midi);
|
2014-04-28 15:29:35 -04:00
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Getting access to the data buffer for a port */
|
|
|
|
|
|
|
|
void*
|
2014-04-28 17:00:40 -04:00
|
|
|
DummyAudioBackend::get_buffer (PortEngine::PortHandle port, pframes_t nframes)
|
2014-04-28 15:29:35 -04:00
|
|
|
{
|
2014-05-24 18:23:14 -04:00
|
|
|
assert (port);
|
2014-04-28 17:00:40 -04:00
|
|
|
assert (valid_port (port));
|
|
|
|
return static_cast<DummyPort*>(port)->get_buffer (nframes);
|
2014-04-28 16:59:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Engine Process */
|
|
|
|
void *
|
|
|
|
DummyAudioBackend::main_process_thread ()
|
|
|
|
{
|
|
|
|
AudioEngine::thread_init_callback (this);
|
|
|
|
_running = true;
|
|
|
|
_processed_samples = 0;
|
|
|
|
|
2014-06-06 07:53:07 -04:00
|
|
|
manager.registration_callback();
|
2014-06-05 21:43:39 -04:00
|
|
|
manager.graph_order_callback();
|
|
|
|
|
2014-05-16 12:13:08 -04:00
|
|
|
uint64_t clock1, clock2;
|
|
|
|
clock1 = g_get_monotonic_time();
|
2014-04-28 16:59:19 -04:00
|
|
|
while (_running) {
|
2014-07-07 10:23:23 -04:00
|
|
|
|
|
|
|
// re-set input buffers, generate on demand.
|
|
|
|
for (std::vector<DummyAudioPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) {
|
|
|
|
(*it)->next_period();
|
|
|
|
}
|
|
|
|
|
2014-04-28 21:13:40 -04:00
|
|
|
if (engine.process_callback (_samples_per_period)) {
|
2014-04-28 16:59:19 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-28 21:13:40 -04:00
|
|
|
_processed_samples += _samples_per_period;
|
2014-04-28 16:59:19 -04:00
|
|
|
if (!_freewheeling) {
|
2014-05-16 12:13:08 -04:00
|
|
|
clock2 = g_get_monotonic_time();
|
|
|
|
const int64_t elapsed_time = clock2 - clock1;
|
|
|
|
const int64_t nomial_time = 1e6 * _samples_per_period / _samplerate;
|
2014-04-28 16:59:19 -04:00
|
|
|
_dsp_load = elapsed_time / (float) nomial_time;
|
|
|
|
if (elapsed_time < nomial_time) {
|
2014-05-13 01:10:32 -04:00
|
|
|
Glib::usleep (nomial_time - elapsed_time);
|
2014-04-28 16:59:19 -04:00
|
|
|
} else {
|
2014-05-13 01:10:32 -04:00
|
|
|
Glib::usleep (100); // don't hog cpu
|
2014-04-28 16:59:19 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_dsp_load = 1.0;
|
2014-05-13 01:10:32 -04:00
|
|
|
Glib::usleep (100); // don't hog cpu
|
2014-04-28 16:59:19 -04:00
|
|
|
}
|
2014-05-16 12:13:08 -04:00
|
|
|
clock1 = g_get_monotonic_time();
|
2014-05-24 18:21:44 -04:00
|
|
|
|
2014-06-06 07:53:07 -04:00
|
|
|
bool connections_changed = false;
|
|
|
|
bool ports_changed = false;
|
2014-05-24 18:21:44 -04:00
|
|
|
if (!pthread_mutex_trylock (&_port_callback_mutex)) {
|
2014-06-06 07:53:07 -04:00
|
|
|
if (_port_change_flag) {
|
|
|
|
ports_changed = true;
|
|
|
|
_port_change_flag = false;
|
|
|
|
}
|
|
|
|
if (!_port_connection_queue.empty ()) {
|
|
|
|
connections_changed = true;
|
|
|
|
}
|
2014-05-24 18:21:44 -04:00
|
|
|
while (!_port_connection_queue.empty ()) {
|
|
|
|
PortConnectData *c = _port_connection_queue.back ();
|
|
|
|
manager.connect_callback (c->a, c->b, c->c);
|
|
|
|
_port_connection_queue.pop_back ();
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock (&_port_callback_mutex);
|
|
|
|
}
|
2014-06-06 07:53:07 -04:00
|
|
|
if (ports_changed) {
|
|
|
|
manager.registration_callback();
|
|
|
|
}
|
|
|
|
if (connections_changed) {
|
|
|
|
manager.graph_order_callback();
|
|
|
|
}
|
2014-06-11 16:01:21 -04:00
|
|
|
if (connections_changed || ports_changed) {
|
|
|
|
engine.latency_callback(false);
|
|
|
|
engine.latency_callback(true);
|
|
|
|
}
|
2014-05-24 18:21:44 -04:00
|
|
|
|
2014-04-28 16:59:19 -04:00
|
|
|
}
|
|
|
|
_running = false;
|
2014-04-28 15:29:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:00:40 -04:00
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
static boost::shared_ptr<DummyAudioBackend> _instance;
|
|
|
|
|
2014-05-01 09:14:25 -04:00
|
|
|
static boost::shared_ptr<AudioBackend> backend_factory (AudioEngine& e);
|
|
|
|
static int instantiate (const std::string& arg1, const std::string& /* arg2 */);
|
|
|
|
static int deinstantiate ();
|
|
|
|
static bool already_configured ();
|
|
|
|
|
|
|
|
static ARDOUR::AudioBackendInfo _descriptor = {
|
|
|
|
"Dummy",
|
|
|
|
instantiate,
|
|
|
|
deinstantiate,
|
|
|
|
backend_factory,
|
|
|
|
already_configured,
|
|
|
|
};
|
|
|
|
|
2014-04-28 15:29:35 -04:00
|
|
|
static boost::shared_ptr<AudioBackend>
|
|
|
|
backend_factory (AudioEngine& e)
|
|
|
|
{
|
|
|
|
if (!_instance) {
|
2014-05-01 09:14:25 -04:00
|
|
|
_instance.reset (new DummyAudioBackend (e, _descriptor));
|
2014-04-28 15:29:35 -04:00
|
|
|
}
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
instantiate (const std::string& arg1, const std::string& /* arg2 */)
|
|
|
|
{
|
|
|
|
s_instance_name = arg1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
deinstantiate ()
|
|
|
|
{
|
|
|
|
_instance.reset ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
already_configured ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
|
|
|
|
{
|
|
|
|
return &_descriptor;
|
|
|
|
}
|
2014-04-28 17:00:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-05-24 18:21:44 -04:00
|
|
|
DummyPort::DummyPort (DummyAudioBackend &b, const std::string& name, PortFlags flags)
|
|
|
|
: _dummy_backend (b)
|
|
|
|
, _name (name)
|
2014-04-28 17:00:40 -04:00
|
|
|
, _flags (flags)
|
|
|
|
{
|
|
|
|
_capture_latency_range.min = 0;
|
|
|
|
_capture_latency_range.max = 0;
|
|
|
|
_playback_latency_range.min = 0;
|
|
|
|
_playback_latency_range.max = 0;
|
2014-06-06 07:53:07 -04:00
|
|
|
_dummy_backend.port_connect_add_remove_callback();
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DummyPort::~DummyPort () {
|
|
|
|
disconnect_all ();
|
2014-06-06 07:53:07 -04:00
|
|
|
_dummy_backend.port_connect_add_remove_callback();
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DummyPort::connect (DummyPort *port)
|
|
|
|
{
|
|
|
|
if (!port) {
|
|
|
|
PBD::error << _("DummyPort::connect (): invalid (null) port") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type () != port->type ()) {
|
|
|
|
PBD::error << _("DummyPort::connect (): wrong port-type") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_output () && port->is_output ()) {
|
|
|
|
PBD::error << _("DummyPort::connect (): cannot inter-connect output ports.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_input () && port->is_input ()) {
|
|
|
|
PBD::error << _("DummyPort::connect (): cannot inter-connect input ports.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this == port) {
|
|
|
|
PBD::error << _("DummyPort::connect (): cannot self-connect ports.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_connected (port)) {
|
2014-04-28 23:12:12 -04:00
|
|
|
#if 0 // don't bother to warn about this for now. just ignore it
|
2014-04-28 17:00:40 -04:00
|
|
|
PBD::error << _("DummyPort::connect (): ports are already connected:")
|
|
|
|
<< " (" << name () << ") -> (" << port->name () << ")"
|
|
|
|
<< endmsg;
|
2014-04-28 23:12:12 -04:00
|
|
|
#endif
|
2014-04-28 17:00:40 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_connect (port, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DummyPort::_connect (DummyPort *port, bool callback)
|
|
|
|
{
|
|
|
|
_connections.push_back (port);
|
|
|
|
if (callback) {
|
|
|
|
port->_connect (this, false);
|
2014-05-24 18:21:44 -04:00
|
|
|
_dummy_backend.port_connect_callback (name(), port->name(), true);
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DummyPort::disconnect (DummyPort *port)
|
|
|
|
{
|
|
|
|
if (!port) {
|
|
|
|
PBD::error << _("DummyPort::disconnect (): invalid (null) port") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_connected (port)) {
|
|
|
|
PBD::error << _("DummyPort::disconnect (): ports are not connected:")
|
|
|
|
<< " (" << name () << ") -> (" << port->name () << ")"
|
|
|
|
<< endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_disconnect (port, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DummyPort::_disconnect (DummyPort *port, bool callback)
|
|
|
|
{
|
|
|
|
std::vector<DummyPort*>::iterator it = std::find (_connections.begin (), _connections.end (), port);
|
|
|
|
|
|
|
|
assert (it != _connections.end ());
|
|
|
|
|
|
|
|
_connections.erase (it);
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
port->_disconnect (this, false);
|
2014-05-24 18:21:44 -04:00
|
|
|
_dummy_backend.port_connect_callback (name(), port->name(), false);
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DummyPort::disconnect_all ()
|
|
|
|
{
|
|
|
|
while (!_connections.empty ()) {
|
|
|
|
_connections.back ()->_disconnect (this, false);
|
2014-05-24 18:21:44 -04:00
|
|
|
_dummy_backend.port_connect_callback (name(), _connections.back ()->name(), false);
|
2014-04-28 17:00:40 -04:00
|
|
|
_connections.pop_back ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DummyPort::is_connected (const DummyPort *port) const
|
|
|
|
{
|
|
|
|
return std::find (_connections.begin (), _connections.end (), port) != _connections.end ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyPort::is_physically_connected () const
|
|
|
|
{
|
|
|
|
for (std::vector<DummyPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {
|
|
|
|
if ((*it)->is_physical ()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-05-24 18:21:44 -04:00
|
|
|
DummyAudioPort::DummyAudioPort (DummyAudioBackend &b, const std::string& name, PortFlags flags)
|
|
|
|
: DummyPort (b, name, flags)
|
2014-07-07 10:23:23 -04:00
|
|
|
, _gen_type (Silence)
|
|
|
|
, _gen_cycle (false)
|
|
|
|
, _pass (false)
|
2014-04-28 17:00:40 -04:00
|
|
|
{
|
|
|
|
memset (_buffer, 0, sizeof (_buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
DummyAudioPort::~DummyAudioPort () { }
|
|
|
|
|
2014-07-07 10:23:23 -04:00
|
|
|
void DummyAudioPort::setup_generator (GeneratorType const g, float const samplerate)
|
|
|
|
{
|
|
|
|
_gen_type = g;
|
|
|
|
_rseed = g_get_monotonic_time() % UINT_MAX;
|
|
|
|
_pass = false;
|
|
|
|
|
|
|
|
switch (_gen_type) {
|
|
|
|
case Silence:
|
|
|
|
break;
|
|
|
|
case SineWave:
|
|
|
|
_b1 = 0;
|
|
|
|
{
|
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
srand (_rseed);
|
|
|
|
const unsigned int k = rand () % 128;
|
|
|
|
#else
|
|
|
|
const unsigned int k = rand_r (&_rseed) % 128;
|
|
|
|
#endif
|
|
|
|
// midi note, chromatic scale
|
|
|
|
_b0 = (440.f / 32.f) * powf(2, (k - 9.0) / 12.0) / samplerate;
|
|
|
|
assert (_b0 < M_PI/2); // fine when samplerate >= 8K
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PinkNoise:
|
|
|
|
case PonyNoise:
|
|
|
|
_b0 = _b1 = _b2 = _b3 = _b4 = _b5 = _b6 = 0.f;
|
|
|
|
// fall trhu, no break
|
|
|
|
case WhiteNoise:
|
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
srand (_rseed);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float randf (unsigned int *seedp) {
|
|
|
|
static const float rmf = RAND_MAX / 2.0;
|
|
|
|
// TODO this should use a better uniform random generator
|
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
return ((float)rand () / rmf) - 1.f;
|
|
|
|
#else
|
|
|
|
return ((float)rand_r (seedp) / rmf) - 1.f;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
float DummyAudioPort::grandf ()
|
|
|
|
{
|
|
|
|
// Gaussian White Noise
|
|
|
|
// http://www.musicdsp.org/archive.php?classid=0#109
|
|
|
|
float x1, x2, r;
|
|
|
|
|
|
|
|
if (_pass) {
|
|
|
|
_pass = false;
|
|
|
|
return _rn1;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
x1 = randf (&_rseed);
|
|
|
|
x2 = randf (&_rseed);
|
|
|
|
r = x1 * x1 + x2 * x2;
|
|
|
|
} while ((r >= 1.0f) || (r < 1e-22f));
|
|
|
|
|
|
|
|
r = sqrtf (-2.f * logf (r) / r);
|
|
|
|
|
|
|
|
_pass = true;
|
|
|
|
_rn1 = r * x2;
|
|
|
|
return r * x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DummyAudioPort::generate (pframes_t n_samples)
|
|
|
|
{
|
|
|
|
switch (_gen_type) {
|
|
|
|
case Silence:
|
|
|
|
memset (_buffer, 0, n_samples * sizeof (Sample));
|
|
|
|
break;
|
|
|
|
case SineWave:
|
|
|
|
for (pframes_t i = 0 ; i < n_samples; ++i) {
|
|
|
|
_buffer[i] = .12589f * sinf(2.0 * M_PI * _b1);
|
|
|
|
_b1 += _b0;
|
|
|
|
if (_b1 > 1.0) _b1 -= 2.0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WhiteNoise:
|
|
|
|
for (pframes_t i = 0 ; i < n_samples; ++i) {
|
|
|
|
_buffer[i] = .089125f * grandf();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PinkNoise:
|
|
|
|
for (pframes_t i = 0 ; i < n_samples; ++i) {
|
|
|
|
// Paul Kellet's refined method
|
|
|
|
// http://www.musicdsp.org/files/pink.txt
|
|
|
|
// NB. If 'white' consists of uniform random numbers,
|
|
|
|
// the pink noise will have an almost gaussian distribution.
|
|
|
|
const float white = .0498f * randf(&_rseed);
|
|
|
|
_b0 = .99886f * _b0 + white * .0555179f;
|
|
|
|
_b1 = .99332f * _b1 + white * .0750759f;
|
|
|
|
_b2 = .96900f * _b2 + white * .1538520f;
|
|
|
|
_b3 = .86650f * _b3 + white * .3104856f;
|
|
|
|
_b4 = .55000f * _b4 + white * .5329522f;
|
|
|
|
_b5 = -.7616f * _b5 - white * .0168980f;
|
|
|
|
_buffer[i] = _b0 + _b1 + _b2 + _b3 + _b4 + _b5 + _b6 + white * 0.5362;
|
|
|
|
_b6 = white * 0.115926;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PonyNoise:
|
|
|
|
for (pframes_t i = 0 ; i < n_samples; ++i) {
|
|
|
|
const float white = 0.0498f * randf(&_rseed);
|
|
|
|
// Paul Kellet's economy method
|
|
|
|
// http://www.musicdsp.org/files/pink.txt
|
|
|
|
_b0 = 0.99765 * _b0 + white * 0.0990460;
|
|
|
|
_b1 = 0.96300 * _b1 + white * 0.2965164;
|
|
|
|
_b2 = 0.57000 * _b2 + white * 1.0526913;
|
|
|
|
_buffer[i] = _b0 + _b1 + _b2 + white * 0.1848;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 17:00:40 -04:00
|
|
|
void* DummyAudioPort::get_buffer (pframes_t n_samples)
|
|
|
|
{
|
|
|
|
if (is_input ()) {
|
|
|
|
std::vector<DummyPort*>::const_iterator it = get_connections ().begin ();
|
|
|
|
if (it == get_connections ().end ()) {
|
|
|
|
memset (_buffer, 0, n_samples * sizeof (Sample));
|
|
|
|
} else {
|
2014-07-07 10:23:23 -04:00
|
|
|
DummyAudioPort * source = static_cast<DummyAudioPort*>(*it);
|
2014-04-28 17:00:40 -04:00
|
|
|
assert (source && source->is_output ());
|
2014-07-07 10:23:23 -04:00
|
|
|
if (source->is_physical() && source->is_terminal()) {
|
|
|
|
source->get_buffer(n_samples); // generate signal.
|
|
|
|
}
|
2014-04-28 17:00:40 -04:00
|
|
|
memcpy (_buffer, source->const_buffer (), n_samples * sizeof (Sample));
|
|
|
|
while (++it != get_connections ().end ()) {
|
2014-07-07 10:23:23 -04:00
|
|
|
source = static_cast<DummyAudioPort*>(*it);
|
2014-04-28 17:00:40 -04:00
|
|
|
assert (source && source->is_output ());
|
|
|
|
Sample* dst = buffer ();
|
2014-07-07 10:23:23 -04:00
|
|
|
if (source->is_physical() && source->is_terminal()) {
|
|
|
|
source->get_buffer(n_samples); // generate signal.
|
|
|
|
}
|
2014-04-28 17:00:40 -04:00
|
|
|
const Sample* src = source->const_buffer ();
|
|
|
|
for (uint32_t s = 0; s < n_samples; ++s, ++dst, ++src) {
|
|
|
|
*dst += *src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 23:12:12 -04:00
|
|
|
} else if (is_output () && is_physical () && is_terminal()) {
|
2014-07-07 10:23:23 -04:00
|
|
|
if (!_gen_cycle) {
|
|
|
|
_gen_cycle = true;
|
|
|
|
generate(n_samples);
|
|
|
|
}
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
return _buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-24 18:21:44 -04:00
|
|
|
DummyMidiPort::DummyMidiPort (DummyAudioBackend &b, const std::string& name, PortFlags flags)
|
|
|
|
: DummyPort (b, name, flags)
|
2014-04-28 17:00:40 -04:00
|
|
|
{
|
|
|
|
_buffer.clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
DummyMidiPort::~DummyMidiPort () { }
|
|
|
|
|
2014-06-02 06:19:35 -04:00
|
|
|
struct MidiEventSorter {
|
|
|
|
bool operator() (const boost::shared_ptr<DummyMidiEvent>& a, const boost::shared_ptr<DummyMidiEvent>& b) {
|
|
|
|
return *a < *b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-28 17:00:40 -04:00
|
|
|
void* DummyMidiPort::get_buffer (pframes_t /* nframes */)
|
|
|
|
{
|
|
|
|
if (is_input ()) {
|
|
|
|
_buffer.clear ();
|
|
|
|
for (std::vector<DummyPort*>::const_iterator i = get_connections ().begin ();
|
|
|
|
i != get_connections ().end ();
|
|
|
|
++i) {
|
|
|
|
const DummyMidiBuffer src = static_cast<const DummyMidiPort*>(*i)->const_buffer ();
|
|
|
|
for (DummyMidiBuffer::const_iterator it = src.begin (); it != src.end (); ++it) {
|
|
|
|
_buffer.push_back (boost::shared_ptr<DummyMidiEvent>(new DummyMidiEvent (**it)));
|
|
|
|
}
|
|
|
|
}
|
2014-06-02 06:19:35 -04:00
|
|
|
std::sort (_buffer.begin (), _buffer.end (), MidiEventSorter());
|
2014-04-28 23:12:12 -04:00
|
|
|
} else if (is_output () && is_physical () && is_terminal()) {
|
|
|
|
_buffer.clear ();
|
2014-04-28 17:00:40 -04:00
|
|
|
}
|
|
|
|
return &_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
DummyMidiEvent::DummyMidiEvent (const pframes_t timestamp, const uint8_t* data, size_t size)
|
|
|
|
: _size (size)
|
|
|
|
, _timestamp (timestamp)
|
|
|
|
, _data (0)
|
|
|
|
{
|
|
|
|
if (size > 0) {
|
|
|
|
_data = (uint8_t*) malloc (size);
|
|
|
|
memcpy (_data, data, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DummyMidiEvent::DummyMidiEvent (const DummyMidiEvent& other)
|
|
|
|
: _size (other.size ())
|
|
|
|
, _timestamp (other.timestamp ())
|
|
|
|
, _data (0)
|
|
|
|
{
|
|
|
|
if (other.size () && other.const_data ()) {
|
|
|
|
_data = (uint8_t*) malloc (other.size ());
|
|
|
|
memcpy (_data, other.const_data (), other.size ());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DummyMidiEvent::~DummyMidiEvent () {
|
|
|
|
free (_data);
|
|
|
|
};
|