AudioThread: re-apply consistent formating

This commit is contained in:
vsonnier 2018-01-22 07:10:45 +01:00
parent fc1c1c3b4d
commit 033bbd07df
2 changed files with 166 additions and 157 deletions

View File

@ -97,7 +97,7 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
::memset(out, 0, nBufferFrames * 2 * sizeof(float)); ::memset(out, 0, nBufferFrames * 2 * sizeof(float));
//src in the controller thread: //src in the controller thread:
AudioThread *src = (AudioThread *) userData; AudioThread *src = (AudioThread *)userData;
//by construction, src is a controller thread, from deviceController: //by construction, src is a controller thread, from deviceController:
std::lock_guard<std::recursive_mutex> lock(src->getMutex()); std::lock_guard<std::recursive_mutex> lock(src->getMutex());
@ -201,7 +201,8 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
} }
srcmix->audioQueuePtr++; srcmix->audioQueuePtr++;
} }
} else { }
else {
for (int i = 0, iMax = srcmix->currentInput->channels * nBufferFrames; i < iMax; i++) { for (int i = 0, iMax = srcmix->currentInput->channels * nBufferFrames; i < iMax; i++) {
if (srcmix->audioQueuePtr >= srcmix->currentInput->data.size()) { if (srcmix->audioQueuePtr >= srcmix->currentInput->data.size()) {
@ -359,7 +360,7 @@ void AudioThread::setSampleRate(int sampleRate) {
} }
} }
dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *) this, &opts); dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *)this, &opts);
dac.startStream(); dac.startStream();
} }
@ -400,11 +401,12 @@ void AudioThread::setupDevice(int deviceId) {
if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) { if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) {
sampleRate = deviceSampleRate[parameters.deviceId]; sampleRate = deviceSampleRate[parameters.deviceId];
} else { }
else {
std::cout << "Error, device sample rate wasn't initialized?" << std::endl; std::cout << "Error, device sample rate wasn't initialized?" << std::endl;
return; return;
// sampleRate = AudioThread::getDefaultAudioSampleRate(); // sampleRate = AudioThread::getDefaultAudioSampleRate();
// deviceSampleRate[parameters.deviceId] = sampleRate; // deviceSampleRate[parameters.deviceId] = sampleRate;
} }
//Create a new controller: //Create a new controller:
@ -417,12 +419,14 @@ void AudioThread::setupDevice(int deviceId) {
deviceController[parameters.deviceId]->bindThread(this); deviceController[parameters.deviceId]->bindThread(this);
deviceController[parameters.deviceId]->attachControllerThread(new std::thread(&AudioThread::threadMain, deviceController[parameters.deviceId])); deviceController[parameters.deviceId]->attachControllerThread(new std::thread(&AudioThread::threadMain, deviceController[parameters.deviceId]));
} else if (deviceController[parameters.deviceId] == this) { }
else if (deviceController[parameters.deviceId] == this) {
//Attach callback //Attach callback
dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *)this, &opts); dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *)this, &opts);
dac.startStream(); dac.startStream();
} else { }
else {
//we are a bound thread, add ourselves to the controller deviceController[parameters.deviceId]. //we are a bound thread, add ourselves to the controller deviceController[parameters.deviceId].
//beware, we must take the controller mutex, because the audio callback may use the list of bounded //beware, we must take the controller mutex, because the audio callback may use the list of bounded
//threads at that moment: //threads at that moment:
@ -432,7 +436,8 @@ void AudioThread::setupDevice(int deviceId) {
} }
active = true; active = true;
} catch (RtAudioError& e) { }
catch (RtAudioError& e) {
e.printMessage(); e.printMessage();
return; return;
} }
@ -461,7 +466,8 @@ void AudioThread::setInitOutputDevice(int deviceId, int sampleRate) {
if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) { if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) {
sampleRate = deviceSampleRate[deviceId]; sampleRate = deviceSampleRate[deviceId];
} }
} else { }
else {
deviceSampleRate[deviceId] = sampleRate; deviceSampleRate[deviceId] = sampleRate;
} }
this->sampleRate = sampleRate; this->sampleRate = sampleRate;
@ -470,12 +476,12 @@ void AudioThread::setInitOutputDevice(int deviceId, int sampleRate) {
void AudioThread::run() { void AudioThread::run() {
#ifdef __APPLE__ #ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread pthread_t tID = pthread_self(); // ID of this thread
int priority = sched_get_priority_max( SCHED_RR) - 1; int priority = sched_get_priority_max(SCHED_RR) - 1;
sched_param prio = {priority}; // scheduling priority of thread sched_param prio = { priority }; // scheduling priority of thread
pthread_setschedparam(tID, SCHED_RR, &prio); pthread_setschedparam(tID, SCHED_RR, &prio);
#endif #endif
// std::cout << "Audio thread initializing.." << std::endl; // std::cout << "Audio thread initializing.." << std::endl;
if (dac.getDeviceCount() < 1) { if (dac.getDeviceCount() < 1) {
std::cout << "No audio devices found!" << std::endl; std::cout << "No audio devices found!" << std::endl;
@ -484,7 +490,7 @@ void AudioThread::run() {
setupDevice((outputDevice.load() == -1) ? (dac.getDefaultOutputDevice()) : outputDevice.load()); setupDevice((outputDevice.load() == -1) ? (dac.getDefaultOutputDevice()) : outputDevice.load());
// std::cout << "Audio thread started." << std::endl; // std::cout << "Audio thread started." << std::endl;
inputQueue = std::static_pointer_cast<AudioThreadInputQueue>(getInputQueue("AudioDataInput")); inputQueue = std::static_pointer_cast<AudioThreadInputQueue>(getInputQueue("AudioDataInput"));
@ -522,7 +528,8 @@ void AudioThread::run() {
std::lock_guard<std::recursive_mutex> lock(deviceController[parameters.deviceId]->getMutex()); std::lock_guard<std::recursive_mutex> lock(deviceController[parameters.deviceId]->getMutex());
deviceController[parameters.deviceId]->removeThread(this); deviceController[parameters.deviceId]->removeThread(this);
} else { }
else {
// 'this' is a controller thread: // 'this' is a controller thread:
try { try {
if (dac.isStreamOpen()) { if (dac.isStreamOpen()) {
@ -531,12 +538,13 @@ void AudioThread::run() {
} }
dac.closeStream(); dac.closeStream();
} }
} catch (RtAudioError& e) { }
catch (RtAudioError& e) {
e.printMessage(); e.printMessage();
} }
} }
// std::cout << "Audio thread done." << std::endl; // std::cout << "Audio thread done." << std::endl;
} }
void AudioThread::terminate() { void AudioThread::terminate() {
@ -571,12 +579,13 @@ void AudioThread::setActive(bool state) {
if (state && !active && inputQueue) { if (state && !active && inputQueue) {
matchingControllerThread->bindThread(this); matchingControllerThread->bindThread(this);
} else if (!state && active) { }
else if (!state && active) {
matchingControllerThread->removeThread(this); matchingControllerThread->removeThread(this);
} }
// Activity state changing, clear any inputs // Activity state changing, clear any inputs
if(inputQueue) { if (inputQueue) {
inputQueue->flush(); inputQueue->flush();
} }
active = state; active = state;

View File

@ -87,7 +87,7 @@ public:
static void enumerateDevices(std::vector<RtAudio::DeviceInfo> &devs); static void enumerateDevices(std::vector<RtAudio::DeviceInfo> &devs);
void setInitOutputDevice(int deviceId, int sampleRate=-1); void setInitOutputDevice(int deviceId, int sampleRate = -1);
int getOutputDevice(); int getOutputDevice();
int getSampleRate(); int getSampleRate();