Audaspace  1.3.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 "JackSynchronizer.h"
30 #include "devices/SoftwareDevice.h"
31 #include "util/Buffer.h"
32 
33 #include <string>
34 #include <condition_variable>
35 #include <thread>
36 #include <jack/jack.h>
37 #include <jack/ringbuffer.h>
38 
40 
45 {
46 private:
50  jack_port_t** m_ports;
51 
55  jack_client_t* m_client;
56 
60  Buffer m_buffer;
61 
65  Buffer m_deinterleavebuf;
66 
67  jack_ringbuffer_t** m_ringbuffers;
68 
72  bool m_valid;
73 
75  JackSynchronizer m_synchronizer;
76 
81  AUD_LOCAL static void jack_shutdown(void* data);
82 
89  AUD_LOCAL static int jack_mix(jack_nframes_t length, void* data);
90 
91  AUD_LOCAL static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
92 
96  jack_transport_state_t m_nextState;
97 
101  jack_transport_state_t m_state;
102 
106  int m_sync;
107 
111  ISynchronizer::syncFunction m_syncFunc;
112 
116  void* m_syncFuncData;
117 
121  std::thread m_mixingThread;
122 
126  std::mutex m_mixingLock;
127 
131  std::condition_variable m_mixingCondition;
132 
136  AUD_LOCAL void updateRingBuffers();
137 
138  // delete copy constructor and operator=
139  JackDevice(const JackDevice&) = delete;
140  JackDevice& operator=(const JackDevice&) = delete;
141 
142 protected:
143  virtual void playing(bool playing);
144 
145 public:
154  JackDevice(std::string name, DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
155 
159  virtual ~JackDevice();
160 
161  virtual ISynchronizer* getSynchronizer();
162 
166  void startPlayback();
167 
171  void stopPlayback();
172 
177  void seekPlayback(float time);
178 
184  void setSyncCallback(ISynchronizer::syncFunction sync, void* data);
185 
190  float getPlaybackPosition();
191 
196  bool doesPlayback();
197 
201  static void registerPlugin();
202 };
203 
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
This class enables global synchronization of several audio applications if supported.
Definition: ISynchronizer.h:38
virtual ISynchronizer * getSynchronizer()
Retrieves the synchronizer for this device, which enables accurate synchronization between audio play...
#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 JackSynchronizer class.
virtual void playing(bool playing)=0
This function tells the device, to start or pause playback.
void(* syncFunction)(void *, int, float)
The syncFunction is called when a synchronization event happens.
Definition: ISynchronizer.h:52
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality...
Definition: Buffer.h:33
This class is a Synchronizer implementation using JACK Transport.
Definition: JackSynchronizer.h:38
Specification of a sound device.
Definition: Specification.h:119
#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
The software device is a generic device with software mixing.
Definition: SoftwareDevice.h:51
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition: Audaspace.h:80
The Buffer class.
The SoftwareDevice class.