13
0

add dummy-backend speed-selection

This commit is contained in:
Robin Gareus 2015-09-06 00:33:24 +02:00
parent 7f00c70f9f
commit 4ef62a0d6d
2 changed files with 62 additions and 1 deletions

View File

@ -41,6 +41,8 @@ size_t DummyAudioBackend::_max_buffer_size = 8192;
std::vector<std::string> DummyAudioBackend::_midi_options;
std::vector<AudioBackend::DeviceStatus> DummyAudioBackend::_device_status;
std::vector<DummyAudioBackend::DriverSpeed> DummyAudioBackend::_driver_speed;
#ifdef PLATFORM_WINDOWS
static double _win_pc_rate = 0; // usec per tick
#endif
@ -64,6 +66,7 @@ DummyAudioBackend::DummyAudioBackend (AudioEngine& e, AudioBackendInfo& info)
, _running (false)
, _freewheel (false)
, _freewheeling (false)
, _speedup (1.0)
, _device ("")
, _samplerate (48000)
, _samples_per_period (1024)
@ -182,6 +185,49 @@ DummyAudioBackend::can_change_buffer_size_when_running () const
return true;
}
std::vector<std::string>
DummyAudioBackend::enumerate_drivers () const
{
if (_driver_speed.empty()) {
_driver_speed.push_back (DriverSpeed (_("Half Speed"), 2.0f));
_driver_speed.push_back (DriverSpeed (_("Normal Speed"), 1.0f));
_driver_speed.push_back (DriverSpeed (_("Double Speed"), 0.5f));
_driver_speed.push_back (DriverSpeed (_("5x Speed"), 0.2f));
_driver_speed.push_back (DriverSpeed (_("10x Speed"), 0.1f));
_driver_speed.push_back (DriverSpeed (_("20x Speed"), 0.05f));
}
std::vector<std::string> speed_drivers;
for (std::vector<DriverSpeed>::const_iterator it = _driver_speed.begin () ; it != _driver_speed.end (); ++it) {
speed_drivers.push_back (it->name);
}
return speed_drivers;
}
std::string
DummyAudioBackend::driver_name () const
{
for (std::vector<DriverSpeed>::const_iterator it = _driver_speed.begin () ; it != _driver_speed.end (); ++it) {
if (_speedup == it->speedup) {
return it->name;
}
}
assert (0);
return _("Normal Speed");
}
int
DummyAudioBackend::set_driver (const std::string& d)
{
for (std::vector<DriverSpeed>::const_iterator it = _driver_speed.begin () ; it != _driver_speed.end (); ++it) {
if (d == it->name) {
_speedup = it->speedup;
return 0;
}
}
return -1;
}
int
DummyAudioBackend::set_device_name (const std::string& d)
{
@ -1254,7 +1300,8 @@ DummyAudioBackend::main_process_thread ()
}
if (elapsed_time < nominal_time) {
Glib::usleep (nominal_time - elapsed_time);
const int64_t sleepy = _speedup * (nominal_time - elapsed_time);
Glib::usleep (std::max ((int64_t) 100, sleepy));
} else {
Glib::usleep (100); // don't hog cpu
}

View File

@ -45,6 +45,7 @@ namespace DummyMidiData {
} MIDISequence;
};
class DummyMidiEvent {
public:
DummyMidiEvent (const pframes_t timestamp, const uint8_t* data, size_t size);
@ -226,6 +227,11 @@ class DummyAudioBackend : public AudioBackend {
std::string name () const;
bool is_realtime () const;
bool requires_driver_selection() const { return true; }
std::string driver_name () const;
std::vector<std::string> enumerate_drivers () const;
int set_driver (const std::string&);
std::vector<DeviceStatus> enumerate_devices () const;
std::vector<float> available_sample_rates (const std::string& device) const;
std::vector<uint32_t> available_buffer_sizes (const std::string& device) const;
@ -374,13 +380,21 @@ class DummyAudioBackend : public AudioBackend {
MidiToAudio,
};
struct DriverSpeed {
std::string name;
float speedup;
DriverSpeed (const std::string& n, float s) : name (n), speedup (s) {}
};
std::string _instance_name;
static std::vector<std::string> _midi_options;
static std::vector<AudioBackend::DeviceStatus> _device_status;
static std::vector<DummyAudioBackend::DriverSpeed> _driver_speed;
bool _running;
bool _freewheel;
bool _freewheeling;
float _speedup;
std::string _device;