AudioThread polishing

This commit is contained in:
vsonnier 2017-09-01 06:18:35 +02:00
parent 5460863608
commit 252b6bf9f8
2 changed files with 36 additions and 38 deletions

View File

@ -509,20 +509,11 @@ AudioThreadCommandQueue *AudioThread::getCommandQueue() {
void AudioThread::setGain(float gain_in) {
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (gain < 0.0) {
gain = 0.0;
if (gain_in < 0.0) {
gain_in = 0.0;
}
if (gain > 2.0) {
gain = 2.0;
if (gain_in > 2.0) {
gain_in = 2.0;
}
gain = gain_in;
}
float AudioThread::getGain() {
std::lock_guard<std::recursive_mutex> lock(m_mutex);
return gain;
}

View File

@ -60,26 +60,19 @@ typedef std::shared_ptr<AudioThreadInputQueue> AudioThreadInputQueuePtr;
typedef std::shared_ptr<AudioThreadCommandQueue> AudioThreadCommandQueuePtr;
class AudioThread : public IOThread {
public:
AudioThreadInputPtr currentInput;
AudioThreadInputQueuePtr inputQueue;
std::atomic_uint audioQueuePtr;
std::atomic_uint underflowCount;
std::atomic_bool initialized;
std::atomic_bool active;
std::atomic_int outputDevice;
float gain;
AudioThread();
~AudioThread();
virtual ~AudioThread();
static void enumerateDevices(std::vector<RtAudio::DeviceInfo> &devs);
void setupDevice(int deviceId);
void setInitOutputDevice(int deviceId, int sampleRate=-1);
int getOutputDevice();
void setSampleRate(int sampleRate);
int getSampleRate();
virtual void run();
virtual void terminate();
@ -87,11 +80,31 @@ public:
void setActive(bool state);
void setGain(float gain_in);
float getGain();
static std::map<int, int> deviceSampleRate;
AudioThreadCommandQueue *getCommandQueue();
//give access to the this AudioThread lock
std::recursive_mutex& getMutex();
static void deviceCleanup();
static void setDeviceSampleRate(int deviceId, int sampleRate);
//fields below, only to be used by other AudioThreads !
std::atomic_uint underflowCount;
//protected by m_mutex
std::vector<AudioThread *> boundThreads;
AudioThreadInputQueuePtr inputQueue;
AudioThreadInputPtr currentInput;
std::atomic_uint audioQueuePtr;
std::atomic<float> gain;
private:
std::atomic_bool active;
std::atomic_int outputDevice;
RtAudio dac;
unsigned int nBufferFrames;
RtAudio::StreamOptions opts;
@ -102,20 +115,14 @@ private:
//The own m_mutex protecting this AudioThread, in particular boundThreads
std::recursive_mutex m_mutex;
public:
//give access to the this AudioThread lock
std::recursive_mutex& getMutex();
void setupDevice(int deviceId);
void setSampleRate(int sampleRate);
void bindThread(AudioThread *other);
void removeThread(AudioThread *other);
static std::map<int, AudioThread *> deviceController;
static std::map<int,int> deviceSampleRate;
static std::map<int,std::thread *> deviceThread;
static void deviceCleanup();
static void setDeviceSampleRate(int deviceId, int sampleRate);
//protected by m_mutex
std::vector<AudioThread *> boundThreads;
static std::map<int, std::thread *> deviceThread;
};