# HG changeset patch # User Chris Cannam # Date 1253537180 0 # Node ID 58b64dbb49c6177fdc2f8e15bb558371a4a4e2e3 # Parent b35c7af2e1d06630dcbefc7886335b29f93b879a * Set scheduling priority for PortAudio on POSIX systems if possible diff -r b35c7af2e1d0 -r 58b64dbb49c6 audioio/AudioPortAudioTarget.cpp --- a/audioio/AudioPortAudioTarget.cpp Fri Sep 11 15:42:32 2009 +0000 +++ b/audioio/AudioPortAudioTarget.cpp Mon Sep 21 12:46:20 2009 +0000 @@ -22,6 +22,10 @@ #include #include +#ifndef _WIN32 +#include +#endif + //#define DEBUG_AUDIO_PORT_AUDIO_TARGET 1 AudioPortAudioTarget::AudioPortAudioTarget(AudioCallbackPlaySource *source) : @@ -30,6 +34,7 @@ m_bufferSize(0), m_sampleRate(0), m_latency(0), + m_prioritySet(false), m_done(false) { PaError err; @@ -54,7 +59,7 @@ op.device = Pa_GetDefaultOutputDevice(); op.channelCount = 2; op.sampleFormat = paFloat32; - op.suggestedLatency = 0.2; + op.suggestedLatency = 1.0; op.hostApiSpecificStreamInfo = 0; err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, paFramesPerBufferUnspecified, @@ -194,6 +199,19 @@ return 0; } + if (!m_prioritySet) { +#ifndef _WIN32 + sched_param param; + param.sched_priority = 20; + if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) { + std::cerr << "AudioPortAudioTarget: NOTE: couldn't set RT scheduling class" << std::endl; + } else { + std::cerr << "AudioPortAudioTarget: NOTE: successfully set RT scheduling class" << std::endl; + } +#endif + m_prioritySet = true; + } + float *output = (float *)outputBuffer; assert(nframes <= m_bufferSize); diff -r b35c7af2e1d0 -r 58b64dbb49c6 audioio/AudioPortAudioTarget.h --- a/audioio/AudioPortAudioTarget.h Fri Sep 11 15:42:32 2009 +0000 +++ b/audioio/AudioPortAudioTarget.h Mon Sep 21 12:46:20 2009 +0000 @@ -59,6 +59,7 @@ int m_bufferSize; int m_sampleRate; int m_latency; + bool m_prioritySet; bool m_done; };