From 990fd75c5fb41588128199587b8a05be1b65a1ab Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 4 Dec 2015 10:15:55 +0100 Subject: implement ALSA period/cycle setting --- libs/backends/alsa/alsa_audiobackend.cc | 32 +++++++++++++++++++++++++++++++- libs/backends/alsa/alsa_audiobackend.h | 9 +++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'libs/backends') diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index b0997a6202..d0236327f3 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -330,6 +330,15 @@ AlsaAudioBackend::available_output_channel_count (const std::string& device) con return 128; } +std::vector +AlsaAudioBackend::available_period_sizes (const std::string& driver) const +{ + std::vector ps; + ps.push_back (2); + ps.push_back (3); + return ps; +} + bool AlsaAudioBackend::can_change_sample_rate_when_running () const { @@ -422,6 +431,19 @@ AlsaAudioBackend::set_sample_rate (float sr) return 0; } +int +AlsaAudioBackend::set_peridod_size (uint32_t n) +{ + if (n == 0 || n > 3) { + return -1; + } + if (_run) { + return -1; + } + _periods_per_cycle = n; + return 0; +} + int AlsaAudioBackend::set_buffer_size (uint32_t bs) { @@ -526,6 +548,12 @@ AlsaAudioBackend::buffer_size () const return _samples_per_period; } +uint32_t +AlsaAudioBackend::period_size () const +{ + return _periods_per_cycle; +} + bool AlsaAudioBackend::interleaved () const { @@ -1208,6 +1236,8 @@ AlsaAudioBackend::register_system_audio_ports() const int a_ins = _n_inputs; const int a_out = _n_outputs; + // TODO set latency depending on _periods_per_cycle and _samples_per_period + /* audio ports */ lr.min = lr.max = (_measure_latency ? 0 : _systemic_audio_input_latency); for (int i = 1; i <= a_ins; ++i) { @@ -1282,7 +1312,7 @@ AlsaAudioBackend::register_system_midi_ports() LatencyRange lr; lr.min = lr.max = (_measure_latency ? 0 : nfo->systemic_output_latency); set_latency_range (p, false, lr); - static_cast(p)->set_n_periods(2); + static_cast(p)->set_n_periods(_periods_per_cycle); // TODO check MIDI alignment _system_midi_out.push_back(static_cast(p)); _rmidi_out.push_back (mout); } diff --git a/libs/backends/alsa/alsa_audiobackend.h b/libs/backends/alsa/alsa_audiobackend.h index c95593c349..1dca7ec149 100644 --- a/libs/backends/alsa/alsa_audiobackend.h +++ b/libs/backends/alsa/alsa_audiobackend.h @@ -148,10 +148,10 @@ class AlsaMidiPort : public AlsaPort { const AlsaMidiBuffer * const_buffer () const { return & _buffer[_bufperiod]; } void next_period() { if (_n_periods > 1) { get_buffer(0); _bufperiod = (_bufperiod + 1) % _n_periods; } } - void set_n_periods(int n) { if (n > 0 && n < 3) { _n_periods = n; } } + void set_n_periods(int n) { if (n > 0 && n < 4) { _n_periods = n; } } private: - AlsaMidiBuffer _buffer[2]; + AlsaMidiBuffer _buffer[3]; int _n_periods; int _bufperiod; }; // class AlsaMidiPort @@ -168,6 +168,8 @@ class AlsaAudioBackend : public AudioBackend { bool is_realtime () const; bool use_separate_input_and_output_devices () const { return true; } + bool can_set_period_size () const { return true; } + std::vector enumerate_devices () const; std::vector enumerate_input_devices () const; std::vector enumerate_output_devices () const; @@ -175,6 +177,7 @@ class AlsaAudioBackend : public AudioBackend { std::vector available_sample_rates2 (const std::string&, const std::string&) const; std::vector available_buffer_sizes (const std::string& device) const; std::vector available_buffer_sizes2 (const std::string&, const std::string&) const; + std::vector available_period_sizes (const std::string& driver) const; uint32_t available_input_channel_count (const std::string& device) const; uint32_t available_output_channel_count (const std::string& device) const; @@ -186,6 +189,7 @@ class AlsaAudioBackend : public AudioBackend { int set_output_device_name (const std::string&); int set_sample_rate (float); int set_buffer_size (uint32_t); + int set_peridod_size (uint32_t); int set_interleaved (bool yn); int set_input_channels (uint32_t); int set_output_channels (uint32_t); @@ -202,6 +206,7 @@ class AlsaAudioBackend : public AudioBackend { std::string output_device_name () const; float sample_rate () const; uint32_t buffer_size () const; + uint32_t period_size () const; bool interleaved () const; uint32_t input_channels () const; uint32_t output_channels () const; -- cgit v1.2.3