mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-08-01 16:37:21 -04:00
Basic mixer for OSX -- multi demod streams working
RtAudio can’t open multiple streams, so now opening a new device will start a static audio thread and all other threads will attach/detach their input queues there.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
DemodulatorInstance::DemodulatorInstance() :
|
||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false), preDemodTerminated(false) {
|
||||
false), preDemodTerminated(false), active(false) {
|
||||
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
@@ -42,14 +42,12 @@ void DemodulatorInstance::run() {
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||
pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2048000);
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
||||
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
@@ -59,6 +57,7 @@ void DemodulatorInstance::run() {
|
||||
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
|
||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||
#endif
|
||||
active = true;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::updateLabel(int freq) {
|
||||
@@ -137,3 +136,11 @@ bool DemodulatorInstance::isTerminated() {
|
||||
return terminated;
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setActive(bool state) {
|
||||
active = state;
|
||||
audioThread->setActive(state);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,15 @@ public:
|
||||
bool isTerminated();
|
||||
void updateLabel(int freq);
|
||||
|
||||
bool isActive();
|
||||
void setActive(bool state);
|
||||
|
||||
private:
|
||||
std::atomic<std::string *> label;bool terminated;bool demodTerminated;bool audioTerminated;bool preDemodTerminated;
|
||||
std::atomic<std::string *> label;
|
||||
bool terminated;
|
||||
bool demodTerminated;
|
||||
bool audioTerminated;
|
||||
bool preDemodTerminated;
|
||||
std::atomic<bool> active;
|
||||
};
|
||||
|
||||
|
||||
@@ -88,10 +88,10 @@ void *DemodulatorPreThread::threadMain() {
|
||||
void DemodulatorPreThread::threadMain() {
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = {priority}; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_max( SCHED_FIFO )-1;
|
||||
sched_param prio = { priority }; // scheduling priority of thread
|
||||
pthread_setschedparam(tID, SCHED_FIFO, &prio);
|
||||
#endif
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
@@ -22,10 +22,10 @@ void *DemodulatorThread::threadMain() {
|
||||
void DemodulatorThread::threadMain() {
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_min( SCHED_RR );
|
||||
sched_param prio = {priority}; // scheduling priority of thread
|
||||
pthread_setschedparam( tID, SCHED_RR, &prio );
|
||||
pthread_t tID = pthread_self(); // ID of this thread
|
||||
int priority = sched_get_priority_max( SCHED_FIFO )-1;
|
||||
sched_param prio = { priority }; // scheduling priority of thread
|
||||
pthread_setschedparam(tID, SCHED_FIFO, &prio);
|
||||
#endif
|
||||
|
||||
msresamp_crcf audio_resampler = NULL;
|
||||
@@ -93,8 +93,11 @@ void DemodulatorThread::threadMain() {
|
||||
audioInputQueue->push(ati);
|
||||
}
|
||||
|
||||
if (visOutQueue != NULL) {
|
||||
visOutQueue->push(ati);
|
||||
if (visOutQueue != NULL && visOutQueue->empty()) {
|
||||
AudioThreadInput ati_vis;
|
||||
ati_vis.data.assign(demod_output,demod_output+num_written);
|
||||
visOutQueue->push(ati_vis);
|
||||
// visOutQueue->push(ati);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user