Ardour  9.0-pre0-582-g084a23a80d
alsa_slave.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __libbackend_alsa_slave_h__
20 #define __libbackend_alsa_slave_h__
21 
22 #include <atomic>
23 
24 #include <pthread.h>
25 
26 #include "pbd/ringbuffer.h"
27 #include "pbd/signals.h"
28 
30 #include "zita-alsa-pcmi.h"
31 
32 namespace ARDOUR {
33 
35 {
36 public:
38  const char *play_name,
39  const char *capt_name,
40  unsigned int master_rate,
41  unsigned int master_samples_per_period,
42  unsigned int slave_rate,
43  unsigned int slave_samples_per_period,
44  unsigned int periods_per_cycle);
45 
46  virtual ~AlsaAudioSlave ();
47 
48  bool start ();
49  void stop ();
50 
51  void cycle_start (double, double, bool);
52  void cycle_end ();
53 
54  uint32_t capt_chan (uint32_t chn, float* dst, uint32_t n_samples);
55  uint32_t play_chan (uint32_t chn, float* src, uint32_t n_samples);
56 
57  bool running () const { return _active; }
58  void freewheel (bool);
59 
60  int state (void) const { return _pcmi.state (); }
61  uint32_t nplay (void) const { return _pcmi.nplay (); }
62  uint32_t ncapt (void) const { return _pcmi.ncapt (); }
63 
65 
66 protected:
67  virtual void update_latencies (uint32_t, uint32_t) = 0;
68 
69 private:
71 
72  static void* _process_thread (void *);
73  void* process_thread ();
74  pthread_t _thread;
75 
76  bool _run; /* keep going or stop, ardour thread */
77  bool _active; /* is running, process thread */
78 
79  /* DLL, track slave process callback */
80  double _t0, _t1;
82 
83  double _ratio;
84  uint32_t _capt_latency;
85  double _play_latency;
86 
87  volatile double _slave_speed;
88 
89  std::atomic<int> _draining;
90 
93 
94  size_t _samples_per_period; // master
95 
96  float* _capt_buff;
97  float* _play_buff;
98  float* _src_buff;
99 
102 
104 
105 }; // class AlsaAudioSlave
106 
107 } // namespace
108 #endif /* __libbackend_alsa_slave_h__ */
void cycle_start(double, double, bool)
std::atomic< int > _draining
Definition: alsa_slave.h:89
ArdourZita::VResampler _src_play
Definition: alsa_slave.h:101
PBD::RingBuffer< float > _rb_capture
Definition: alsa_slave.h:91
PBD::Signal< void()> Halted
Definition: alsa_slave.h:64
static void * _process_thread(void *)
uint32_t ncapt(void) const
Definition: alsa_slave.h:62
bool running() const
Definition: alsa_slave.h:57
int state(void) const
Definition: alsa_slave.h:60
uint64_t _samples_since_dll_reset
Definition: alsa_slave.h:81
PBD::RingBuffer< float > _rb_playback
Definition: alsa_slave.h:92
volatile double _slave_speed
Definition: alsa_slave.h:87
virtual void update_latencies(uint32_t, uint32_t)=0
uint32_t nplay(void) const
Definition: alsa_slave.h:61
uint32_t play_chan(uint32_t chn, float *src, uint32_t n_samples)
uint32_t capt_chan(uint32_t chn, float *dst, uint32_t n_samples)
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)
ArdourZita::VResampler _src_capt
Definition: alsa_slave.h:100
static void reset_resampler(ArdourZita::VResampler &)
uint32_t nplay(void) const
uint32_t ncapt(void) const
int state(void) const