diff options
author | Robin Gareus <robin@gareus.org> | 2017-09-18 16:13:47 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-09-18 16:13:55 +0200 |
commit | 83379827667b0870fe743e5fe3c4bf2bbf95edc6 (patch) | |
tree | 52285840c828ff399035b0b3cc689b2cdda0dcff /libs/backends/alsa/alsa_slave.h | |
parent | 128a9853614e4c4a8e3b831de3ada60f0679d0b8 (diff) |
Prototype using additional ALSA devices (w/resampling).
Diffstat (limited to 'libs/backends/alsa/alsa_slave.h')
-rw-r--r-- | libs/backends/alsa/alsa_slave.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/libs/backends/alsa/alsa_slave.h b/libs/backends/alsa/alsa_slave.h new file mode 100644 index 0000000000..28cd20af06 --- /dev/null +++ b/libs/backends/alsa/alsa_slave.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2017 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_alsa_slave_h__ +#define __libbackend_alsa_slave_h__ + +#include <pthread.h> + +#include "pbd/ringbuffer.h" +#include "zita-resampler/vresampler.h" +#include "zita-alsa-pcmi.h" + +namespace ARDOUR { + +class AlsaAudioSlave +{ +public: + AlsaAudioSlave ( + const char *play_name, + const char *capt_name, + unsigned int master_rate, + unsigned int master_samples_per_period, + unsigned int slave_rate, + unsigned int slave_samples_per_period, + unsigned int periods_per_cycle); + + virtual ~AlsaAudioSlave (); + + bool start (); + void stop (); + + void cycle_start (double, double, bool); + void cycle_end (); + + uint32_t capt_chan (uint32_t chn, float* dst, uint32_t n_samples); + uint32_t play_chan (uint32_t chn, float* src, uint32_t n_samples); + + bool running () const { return _active; } + void freewheel (bool); + + int state (void) const { return _pcmi.state (); } + uint32_t nplay (void) const { return _pcmi.nplay (); } + uint32_t ncapt (void) const { return _pcmi.ncapt (); } + + PBD::Signal0<void> Halted; + +protected: + virtual void update_latencies (uint32_t, uint32_t) = 0; + +private: + Alsa_pcmi _pcmi; + + static void* _process_thread (void *); + void* process_thread (); + pthread_t _thread; + + bool _run; /* keep going or stop, ardour thread */ + bool _active; /* is running, process thread */ + + /* DLL, track slave process callback */ + double _t0, _t1; + uint64_t _samples_since_dll_reset; + + double _ratio; + uint32_t _capt_latency; + double _play_latency; + + volatile double _slave_speed; + volatile gint _draining; + + PBD::RingBuffer<float> _rb_capture; + PBD::RingBuffer<float> _rb_playback; + + size_t _samples_per_period; // master + + float* _capt_buff; + float* _play_buff; + float* _src_buff; + + ArdourZita::VResampler _src_capt; + ArdourZita::VResampler _src_play; + + static void reset_resampler (ArdourZita::VResampler&); + +}; // class AlsaAudioSlave + +} // namespace +#endif /* __libbackend_alsa_slave_h__ */ |