Ardour  8.12
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 
29 #include "zita-alsa-pcmi.h"
30 
31 namespace ARDOUR {
32 
34 {
35 public:
37  const char *play_name,
38  const char *capt_name,
39  unsigned int master_rate,
40  unsigned int master_samples_per_period,
41  unsigned int slave_rate,
42  unsigned int slave_samples_per_period,
43  unsigned int periods_per_cycle);
44 
45  virtual ~AlsaAudioSlave ();
46 
47  bool start ();
48  void stop ();
49 
50  void cycle_start (double, double, bool);
51  void cycle_end ();
52 
53  uint32_t capt_chan (uint32_t chn, float* dst, uint32_t n_samples);
54  uint32_t play_chan (uint32_t chn, float* src, uint32_t n_samples);
55 
56  bool running () const { return _active; }
57  void freewheel (bool);
58 
59  int state (void) const { return _pcmi.state (); }
60  uint32_t nplay (void) const { return _pcmi.nplay (); }
61  uint32_t ncapt (void) const { return _pcmi.ncapt (); }
62 
63  PBD::Signal0<void> Halted;
64 
65 protected:
66  virtual void update_latencies (uint32_t, uint32_t) = 0;
67 
68 private:
70 
71  static void* _process_thread (void *);
72  void* process_thread ();
73  pthread_t _thread;
74 
75  bool _run; /* keep going or stop, ardour thread */
76  bool _active; /* is running, process thread */
77 
78  /* DLL, track slave process callback */
79  double _t0, _t1;
81 
82  double _ratio;
83  uint32_t _capt_latency;
84  double _play_latency;
85 
86  volatile double _slave_speed;
87 
88  std::atomic<int> _draining;
89 
92 
93  size_t _samples_per_period; // master
94 
95  float* _capt_buff;
96  float* _play_buff;
97  float* _src_buff;
98 
101 
103 
104 }; // class AlsaAudioSlave
105 
106 } // namespace
107 #endif /* __libbackend_alsa_slave_h__ */
void cycle_start(double, double, bool)
std::atomic< int > _draining
Definition: alsa_slave.h:88
ArdourZita::VResampler _src_play
Definition: alsa_slave.h:100
PBD::RingBuffer< float > _rb_capture
Definition: alsa_slave.h:90
static void * _process_thread(void *)
uint32_t ncapt(void) const
Definition: alsa_slave.h:61
bool running() const
Definition: alsa_slave.h:56
int state(void) const
Definition: alsa_slave.h:59
PBD::Signal0< void > Halted
Definition: alsa_slave.h:63
uint64_t _samples_since_dll_reset
Definition: alsa_slave.h:80
PBD::RingBuffer< float > _rb_playback
Definition: alsa_slave.h:91
volatile double _slave_speed
Definition: alsa_slave.h:86
virtual void update_latencies(uint32_t, uint32_t)=0
uint32_t nplay(void) const
Definition: alsa_slave.h:60
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:99
static void reset_resampler(ArdourZita::VResampler &)
uint32_t nplay(void) const
uint32_t ncapt(void) const
int state(void) const