Mercurial > hg > svapp
comparison audioio/AudioPortAudioTarget.cpp @ 182:58b64dbb49c6
* Set scheduling priority for PortAudio on POSIX systems if possible
author | Chris Cannam |
---|---|
date | Mon, 21 Sep 2009 12:46:20 +0000 |
parents | 7dae51741cc9 |
children | d9c21e7bff21 |
comparison
equal
deleted
inserted
replaced
181:b35c7af2e1d0 | 182:58b64dbb49c6 |
---|---|
20 | 20 |
21 #include <iostream> | 21 #include <iostream> |
22 #include <cassert> | 22 #include <cassert> |
23 #include <cmath> | 23 #include <cmath> |
24 | 24 |
25 #ifndef _WIN32 | |
26 #include <pthread.h> | |
27 #endif | |
28 | |
25 //#define DEBUG_AUDIO_PORT_AUDIO_TARGET 1 | 29 //#define DEBUG_AUDIO_PORT_AUDIO_TARGET 1 |
26 | 30 |
27 AudioPortAudioTarget::AudioPortAudioTarget(AudioCallbackPlaySource *source) : | 31 AudioPortAudioTarget::AudioPortAudioTarget(AudioCallbackPlaySource *source) : |
28 AudioCallbackPlayTarget(source), | 32 AudioCallbackPlayTarget(source), |
29 m_stream(0), | 33 m_stream(0), |
30 m_bufferSize(0), | 34 m_bufferSize(0), |
31 m_sampleRate(0), | 35 m_sampleRate(0), |
32 m_latency(0), | 36 m_latency(0), |
37 m_prioritySet(false), | |
33 m_done(false) | 38 m_done(false) |
34 { | 39 { |
35 PaError err; | 40 PaError err; |
36 | 41 |
37 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | 42 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET |
52 | 57 |
53 PaStreamParameters op; | 58 PaStreamParameters op; |
54 op.device = Pa_GetDefaultOutputDevice(); | 59 op.device = Pa_GetDefaultOutputDevice(); |
55 op.channelCount = 2; | 60 op.channelCount = 2; |
56 op.sampleFormat = paFloat32; | 61 op.sampleFormat = paFloat32; |
57 op.suggestedLatency = 0.2; | 62 op.suggestedLatency = 1.0; |
58 op.hostApiSpecificStreamInfo = 0; | 63 op.hostApiSpecificStreamInfo = 0; |
59 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, | 64 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, |
60 paFramesPerBufferUnspecified, | 65 paFramesPerBufferUnspecified, |
61 paNoFlag, processStatic, this); | 66 paNoFlag, processStatic, this); |
62 | 67 |
190 if (!m_source || m_done) { | 195 if (!m_source || m_done) { |
191 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | 196 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET |
192 std::cerr << "AudioPortAudioTarget::process: Doing nothing, no source or application done" << std::endl; | 197 std::cerr << "AudioPortAudioTarget::process: Doing nothing, no source or application done" << std::endl; |
193 #endif | 198 #endif |
194 return 0; | 199 return 0; |
200 } | |
201 | |
202 if (!m_prioritySet) { | |
203 #ifndef _WIN32 | |
204 sched_param param; | |
205 param.sched_priority = 20; | |
206 if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) { | |
207 std::cerr << "AudioPortAudioTarget: NOTE: couldn't set RT scheduling class" << std::endl; | |
208 } else { | |
209 std::cerr << "AudioPortAudioTarget: NOTE: successfully set RT scheduling class" << std::endl; | |
210 } | |
211 #endif | |
212 m_prioritySet = true; | |
195 } | 213 } |
196 | 214 |
197 float *output = (float *)outputBuffer; | 215 float *output = (float *)outputBuffer; |
198 | 216 |
199 assert(nframes <= m_bufferSize); | 217 assert(nframes <= m_bufferSize); |