HulaLoop
Simple cross-platform audio loopback and recording.
OSAudio.h
1 #ifndef HL_OS_AUDIO_H
2 #define HL_OS_AUDIO_H
3 
4 // System
5 #include <atomic>
6 #include <cstdlib>
7 #include <thread>
8 #include <vector>
9 
10 #include "Device.h"
11 #include "HulaRingBuffer.h"
12 
13 namespace hula
14 {
19  class OSAudio {
20  private:
21  void joinAndKillThreads(std::vector<std::thread> &threads);
22 
23  protected:
24 
29  {
30  this->activeInputDevice = nullptr;
31  this->activeOutputDevice = nullptr;
32  };
33 
38 
43 
48  std::vector<HulaRingBuffer *> rbs;
49 
53  std::vector<std::thread> inThreads;
54 
58  std::vector<std::thread> outThreads;
59 
67  std::atomic<bool> endCapture;
68 
76 
77  public:
78  virtual ~OSAudio() = 0;
79 
80  void setBufferSize(uint32_t size);
81 
82  void addBuffer(HulaRingBuffer *rb);
83  void removeBuffer(HulaRingBuffer *rb);
84  void copyToBuffers(const void *data, uint32_t bytes);
85 
93  virtual std::vector<Device *> getDevices(DeviceType type) = 0;
94 
98  virtual void capture() = 0;
99  static void backgroundCapture(OSAudio *_this);
100 
104  virtual bool checkDeviceParams(Device *device) = 0;
105 
106  virtual bool setActiveInputDevice(Device *device);
107  virtual bool setActiveOutputDevice(Device *device);
108  };
109 }
110 
111 #endif // END HL_OS_AUDIO_H
Abstract class that defines the required components for OS specfic audio classes. ...
Definition: OSAudio.h:19
std::vector< HulaRingBuffer * > rbs
List of all added ring buffers.
Definition: OSAudio.h:48
std::vector< std::thread > inThreads
Thread for input device activities.
Definition: OSAudio.h:53
OSAudio()
Constructor is protected since this class is abstract.
Definition: OSAudio.h:28
virtual bool checkDeviceParams(Device *device)=0
Verify the bit rate of set rate with the hardware device compatibility.
void setBufferSize(uint32_t size)
Set the desired capture buffer size.
Definition: OSAudio.cpp:14
virtual void capture()=0
Execution loop for loopback capture.
std::vector< std::thread > outThreads
Thread for output device activities.
Definition: OSAudio.h:58
Device * activeOutputDevice
The selected output device.
Definition: OSAudio.h:42
uint32_t captureBufferSize
I don&#39;t really know what this is for right now but I&#39;m going to add this comment so that Doxygen will...
Definition: OSAudio.h:75
void copyToBuffers(const void *data, uint32_t bytes)
Write to each of the buffers contained in rbs.
Definition: OSAudio.cpp:74
HulaLoop wrapper class for PortAudio ring buffer.
Definition: HulaRingBuffer.h:86
virtual bool setActiveInputDevice(Device *device)
Set the selected input device and restart capture threads with new device.
Definition: OSAudio.cpp:132
virtual bool setActiveOutputDevice(Device *device)
Set the selected output device and restart capture threads with new device.
Definition: OSAudio.cpp:193
void addBuffer(HulaRingBuffer *rb)
Add an initialized buffer to the list of buffers that receive audio data.
Definition: OSAudio.cpp:25
Wrapper for OS specific device information.
Definition: Device.h:55
Wrapper around translation functions for Qt.
Definition: Controller.h:10
void removeBuffer(HulaRingBuffer *rb)
Remove a buffer from the list of buffers that receive audio data.
Definition: OSAudio.cpp:53
static void backgroundCapture(OSAudio *_this)
Static function to allow starting a thread with an instance&#39;s capture method.
Definition: OSAudio.cpp:97
std::atomic< bool > endCapture
Flag to syncronize the capture thread for an instance.
Definition: OSAudio.h:67
DeviceType
Denotes type of Device.
Definition: Device.h:18
virtual std::vector< Device * > getDevices(DeviceType type)=0
Receive the list of available record, playback and/or loopback audio devices connected to the OS and ...
virtual ~OSAudio()=0
Virtual implementation of Destructor.
Definition: OSAudio.cpp:224
Device * activeInputDevice
The selected input device.
Definition: OSAudio.h:32