mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-23 12:18:37 -05:00
AudioThread: re-apply consistent formating
This commit is contained in:
parent
fc1c1c3b4d
commit
033bbd07df
@ -97,7 +97,7 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
||||
::memset(out, 0, nBufferFrames * 2 * sizeof(float));
|
||||
|
||||
//src in the controller thread:
|
||||
AudioThread *src = (AudioThread *) userData;
|
||||
AudioThread *src = (AudioThread *)userData;
|
||||
|
||||
//by construction, src is a controller thread, from deviceController:
|
||||
std::lock_guard<std::recursive_mutex> lock(src->getMutex());
|
||||
@ -201,7 +201,8 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
||||
}
|
||||
srcmix->audioQueuePtr++;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (int i = 0, iMax = srcmix->currentInput->channels * nBufferFrames; i < iMax; i++) {
|
||||
|
||||
if (srcmix->audioQueuePtr >= srcmix->currentInput->data.size()) {
|
||||
@ -359,7 +360,7 @@ void AudioThread::setSampleRate(int sampleRate) {
|
||||
}
|
||||
}
|
||||
|
||||
dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *) this, &opts);
|
||||
dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *)this, &opts);
|
||||
dac.startStream();
|
||||
}
|
||||
|
||||
@ -400,11 +401,12 @@ void AudioThread::setupDevice(int deviceId) {
|
||||
|
||||
if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) {
|
||||
sampleRate = deviceSampleRate[parameters.deviceId];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
std::cout << "Error, device sample rate wasn't initialized?" << std::endl;
|
||||
return;
|
||||
// sampleRate = AudioThread::getDefaultAudioSampleRate();
|
||||
// deviceSampleRate[parameters.deviceId] = sampleRate;
|
||||
// sampleRate = AudioThread::getDefaultAudioSampleRate();
|
||||
// deviceSampleRate[parameters.deviceId] = sampleRate;
|
||||
}
|
||||
|
||||
//Create a new controller:
|
||||
@ -417,12 +419,14 @@ void AudioThread::setupDevice(int deviceId) {
|
||||
deviceController[parameters.deviceId]->bindThread(this);
|
||||
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
|
||||
dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &nBufferFrames, &audioCallback, (void *)this, &opts);
|
||||
dac.startStream();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//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
|
||||
//threads at that moment:
|
||||
@ -432,7 +436,8 @@ void AudioThread::setupDevice(int deviceId) {
|
||||
}
|
||||
active = true;
|
||||
|
||||
} catch (RtAudioError& e) {
|
||||
}
|
||||
catch (RtAudioError& e) {
|
||||
e.printMessage();
|
||||
return;
|
||||
}
|
||||
@ -461,7 +466,8 @@ void AudioThread::setInitOutputDevice(int deviceId, int sampleRate) {
|
||||
if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) {
|
||||
sampleRate = deviceSampleRate[deviceId];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
deviceSampleRate[deviceId] = sampleRate;
|
||||
}
|
||||
this->sampleRate = sampleRate;
|
||||
@ -470,12 +476,12 @@ void AudioThread::setInitOutputDevice(int deviceId, int sampleRate) {
|
||||
void AudioThread::run() {
|
||||
#ifdef __APPLE__
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_max( SCHED_RR) - 1;
|
||||
sched_param prio = {priority}; // scheduling priority of thread
|
||||
int priority = sched_get_priority_max(SCHED_RR) - 1;
|
||||
sched_param prio = { priority }; // scheduling priority of thread
|
||||
pthread_setschedparam(tID, SCHED_RR, &prio);
|
||||
#endif
|
||||
|
||||
// std::cout << "Audio thread initializing.." << std::endl;
|
||||
// std::cout << "Audio thread initializing.." << std::endl;
|
||||
|
||||
if (dac.getDeviceCount() < 1) {
|
||||
std::cout << "No audio devices found!" << std::endl;
|
||||
@ -484,7 +490,7 @@ void AudioThread::run() {
|
||||
|
||||
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"));
|
||||
|
||||
@ -522,7 +528,8 @@ void AudioThread::run() {
|
||||
std::lock_guard<std::recursive_mutex> lock(deviceController[parameters.deviceId]->getMutex());
|
||||
|
||||
deviceController[parameters.deviceId]->removeThread(this);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// 'this' is a controller thread:
|
||||
try {
|
||||
if (dac.isStreamOpen()) {
|
||||
@ -531,12 +538,13 @@ void AudioThread::run() {
|
||||
}
|
||||
dac.closeStream();
|
||||
}
|
||||
} catch (RtAudioError& e) {
|
||||
}
|
||||
catch (RtAudioError& e) {
|
||||
e.printMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// std::cout << "Audio thread done." << std::endl;
|
||||
// std::cout << "Audio thread done." << std::endl;
|
||||
}
|
||||
|
||||
void AudioThread::terminate() {
|
||||
@ -571,12 +579,13 @@ void AudioThread::setActive(bool state) {
|
||||
|
||||
if (state && !active && inputQueue) {
|
||||
matchingControllerThread->bindThread(this);
|
||||
} else if (!state && active) {
|
||||
}
|
||||
else if (!state && active) {
|
||||
matchingControllerThread->removeThread(this);
|
||||
}
|
||||
|
||||
// Activity state changing, clear any inputs
|
||||
if(inputQueue) {
|
||||
if (inputQueue) {
|
||||
inputQueue->flush();
|
||||
}
|
||||
active = state;
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
|
||||
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 getSampleRate();
|
||||
|
Loading…
Reference in New Issue
Block a user