Mercurial > hg > svapp
comparison audioio/AudioPortAudioTarget.cpp @ 100:22bf057ea151 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | a8acc7841d70 |
children |
comparison
equal
deleted
inserted
replaced
71:a8acc7841d70 | 100:22bf057ea151 |
---|---|
46 if (err != paNoError) { | 46 if (err != paNoError) { |
47 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl; | 47 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl; |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 m_bufferSize = 1024; | 51 m_bufferSize = 2048; |
52 m_sampleRate = 44100; | 52 m_sampleRate = 44100; |
53 if (m_source && (m_source->getSourceSampleRate() != 0)) { | 53 if (m_source && (m_source->getSourceSampleRate() != 0)) { |
54 m_sampleRate = m_source->getSourceSampleRate(); | 54 m_sampleRate = m_source->getSourceSampleRate(); |
55 } | 55 } |
56 | 56 |
61 #ifdef HAVE_PORTAUDIO_V18 | 61 #ifdef HAVE_PORTAUDIO_V18 |
62 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, | 62 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, |
63 m_sampleRate, m_bufferSize, 0, | 63 m_sampleRate, m_bufferSize, 0, |
64 processStatic, this); | 64 processStatic, this); |
65 #else | 65 #else |
66 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, | 66 PaStreamParameters op; |
67 m_sampleRate, m_bufferSize, | 67 op.device = Pa_GetDefaultOutputDevice(); |
68 processStatic, this); | 68 op.channelCount = 2; |
69 op.sampleFormat = paFloat32; | |
70 op.suggestedLatency = 0.2; | |
71 op.hostApiSpecificStreamInfo = 0; | |
72 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, | |
73 paFramesPerBufferUnspecified, | |
74 paNoFlag, processStatic, this); | |
69 #endif | 75 #endif |
76 | |
77 #ifndef HAVE_PORTAUDIO_V18 | |
78 if (err != paNoError) { | |
79 | |
80 std::cerr << "WARNING: AudioPortAudioTarget: Failed to open PortAudio stream with default frames per buffer, trying again with fixed frames per buffer..." << std::endl; | |
81 | |
82 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, | |
83 1024, | |
84 paNoFlag, processStatic, this); | |
85 m_bufferSize = 1024; | |
86 } | |
87 #endif | |
70 | 88 |
71 if (err != paNoError) { | 89 if (err != paNoError) { |
72 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl; | 90 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl; |
73 m_stream = 0; | 91 m_stream = 0; |
74 Pa_Terminate(); | 92 Pa_Terminate(); |
76 } | 94 } |
77 | 95 |
78 #ifndef HAVE_PORTAUDIO_V18 | 96 #ifndef HAVE_PORTAUDIO_V18 |
79 const PaStreamInfo *info = Pa_GetStreamInfo(m_stream); | 97 const PaStreamInfo *info = Pa_GetStreamInfo(m_stream); |
80 m_latency = int(info->outputLatency * m_sampleRate + 0.001); | 98 m_latency = int(info->outputLatency * m_sampleRate + 0.001); |
99 if (m_bufferSize < m_latency) m_bufferSize = m_latency; | |
81 #endif | 100 #endif |
82 | 101 |
83 std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl; | 102 std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl; |
84 | 103 |
85 err = Pa_StartStream(m_stream); | 104 err = Pa_StartStream(m_stream); |
92 return; | 111 return; |
93 } | 112 } |
94 | 113 |
95 if (m_source) { | 114 if (m_source) { |
96 std::cerr << "AudioPortAudioTarget: block size " << m_bufferSize << std::endl; | 115 std::cerr << "AudioPortAudioTarget: block size " << m_bufferSize << std::endl; |
97 m_source->setTargetBlockSize(m_bufferSize); | 116 m_source->setTarget(this, m_bufferSize); |
98 m_source->setTargetSampleRate(m_sampleRate); | 117 m_source->setTargetSampleRate(m_sampleRate); |
99 m_source->setTargetPlayLatency(m_latency); | 118 m_source->setTargetPlayLatency(m_latency); |
100 } | 119 } |
101 | 120 |
102 #ifdef DEBUG_PORT_AUDIO_TARGET | 121 #ifdef DEBUG_PORT_AUDIO_TARGET |
105 } | 124 } |
106 | 125 |
107 AudioPortAudioTarget::~AudioPortAudioTarget() | 126 AudioPortAudioTarget::~AudioPortAudioTarget() |
108 { | 127 { |
109 std::cerr << "AudioPortAudioTarget::~AudioPortAudioTarget()" << std::endl; | 128 std::cerr << "AudioPortAudioTarget::~AudioPortAudioTarget()" << std::endl; |
129 | |
130 if (m_source) { | |
131 m_source->setTarget(0, m_bufferSize); | |
132 } | |
110 | 133 |
111 shutdown(); | 134 shutdown(); |
112 | 135 |
113 if (m_stream) { | 136 if (m_stream) { |
114 | 137 |
141 | 164 |
142 bool | 165 bool |
143 AudioPortAudioTarget::isOK() const | 166 AudioPortAudioTarget::isOK() const |
144 { | 167 { |
145 return (m_stream != 0); | 168 return (m_stream != 0); |
169 } | |
170 | |
171 double | |
172 AudioPortAudioTarget::getCurrentTime() const | |
173 { | |
174 if (!m_stream) return 0.0; | |
175 else return Pa_GetStreamTime(m_stream); | |
146 } | 176 } |
147 | 177 |
148 #ifdef HAVE_PORTAUDIO_V18 | 178 #ifdef HAVE_PORTAUDIO_V18 |
149 int | 179 int |
150 AudioPortAudioTarget::processStatic(void *input, void *output, | 180 AudioPortAudioTarget::processStatic(void *input, void *output, |