Audaspace  1.9.0
A high level audio library.
JackDevice.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2009-2016 Jörg Müller
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 #pragma once
18 
19 #ifdef JACK_PLUGIN
20 #define AUD_BUILD_PLUGIN
21 #endif
22 
29 #include <atomic>
30 #include <condition_variable>
31 #include <string>
32 #include <thread>
33 
34 #include <jack/jack.h>
35 
37 #include "util/Buffer.h"
38 
40 
45 {
46 private:
50  jack_port_t** m_ports;
51 
55  jack_client_t* m_client;
56 
60  Buffer m_deinterleavebuf;
61 
66  AUD_LOCAL static void jack_shutdown(void* data);
67 
74  AUD_LOCAL static int jack_mix(jack_nframes_t length, void* data);
75 
76  AUD_LOCAL static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
77 
81  jack_transport_state_t m_lastState;
82 
86  jack_transport_state_t m_lastMixState;
87 
91  std::atomic<float> m_syncTime;
92 
96  std::atomic<int> m_syncCallRevision;
97 
101  std::atomic<int> m_lastSyncCallRevision;
102 
106  int m_rollingSyncRevision;
107 
113  int m_lastRollingSyncRevision;
114 
118  syncFunction m_syncFunc;
119 
123  void* m_syncFuncData;
124 
125  AUD_LOCAL void preMixingWork(bool playing) override;
126 
127  // delete copy constructor and operator=
128  JackDevice(const JackDevice&) = delete;
129  JackDevice& operator=(const JackDevice&) = delete;
130 
131 protected:
132  virtual void playing(bool playing);
133 
134 public:
143  JackDevice(const std::string &name, DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
144 
148  virtual ~JackDevice();
149 
153  void playSynchronizer();
154 
158  void stopSynchronizer();
159 
164  void seekSynchronizer(double time);
165 
171  void setSyncCallback(syncFunction sync, void* data);
172 
177  double getSynchronizerPosition();
178 
183  int isSynchronizerPlaying();
184 
188  static void registerPlugin();
189 };
190 
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
virtual void playing(bool playing)
This function tells the device, to start or pause playback.
#define AUD_DEFAULT_BUFFER_SIZE
The default playback buffer size of a device.
Definition: Audaspace.h:103
This device plays back through JACK.
Definition: JackDevice.h:44
The MixingThreadDevice class.
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality...
Definition: Buffer.h:33
Specification of a sound device.
Definition: Specification.h:128
This device extends the SoftwareDevice with code for running mixing in a separate thread...
Definition: MixingThreadDevice.h:36
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
#define AUD_PLUGIN_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:94
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition: Audaspace.h:80
The Buffer class.
virtual void preMixingWork(bool playing)
Called every iteration in the mixing thread before mixing.