Audaspace  1.9.0
A high level audio library.
MixingThreadDevice.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 
25 #include <condition_variable>
26 #include <thread>
27 
28 #include "devices/SoftwareDevice.h"
29 #include "util/RingBuffer.h"
30 
32 
37 {
38 private:
42  volatile bool m_playback{false};
43 
47  Buffer m_mixingBuffer;
48 
52  RingBuffer m_ringBuffer;
53 
57  bool m_valid{false};
58 
62  std::thread m_mixingThread;
63 
67  std::mutex m_mixingLock;
68 
72  std::condition_variable m_mixingCondition;
73 
77  AUD_LOCAL void updateRingBuffer();
78 
79  // delete copy constructor and operator=
80  MixingThreadDevice(const MixingThreadDevice&) = delete;
81  MixingThreadDevice& operator=(const MixingThreadDevice&) = delete;
82 
83 protected:
88  void startMixingThread(size_t buffersize);
89 
93  void notifyMixingThread();
94 
99  {
100  return m_ringBuffer;
101  }
102 
106  inline bool isMixingThreadRunning()
107  {
108  return m_valid;
109  }
110 
111  virtual void playing(bool playing);
112 
116  virtual void preMixingWork(bool playing);
117 
123 
128  void stopMixingThread();
129 };
130 
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
The RingBuffer class.
RingBuffer & getRingBuffer()
Get ring buffer for reading.
Definition: MixingThreadDevice.h:98
virtual void playing(bool playing)=0
This function tells the device, to start or pause playback.
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality...
Definition: Buffer.h:33
bool isMixingThreadRunning()
Returns whether the thread is running or not.
Definition: MixingThreadDevice.h:106
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
The software device is a generic device with software mixing.
Definition: SoftwareDevice.h:50
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition: Audaspace.h:80
This class is a simple ring buffer in RAM which is 32 Byte aligned and provides functionality for con...
Definition: RingBuffer.h:36
The SoftwareDevice class.