Mercurial > hg > svapp
comparison audioio/AudioPortAudioTarget.cpp @ 114:ccdc5b30e54c
* Remove PAv18 support, change PORTAUDIO to PORTAUDIO_2_0 throughout as
this is what comes from PAv19's pkgconfig module name
author | Chris Cannam |
---|---|
date | Fri, 09 May 2008 15:39:42 +0000 |
parents | e177e6ee7c12 |
children | 4c9c04645685 |
comparison
equal
deleted
inserted
replaced
113:0c1ea5ff6518 | 114:ccdc5b30e54c |
---|---|
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #ifdef HAVE_PORTAUDIO | 16 #ifdef HAVE_PORTAUDIO_2_0 |
17 | 17 |
18 #include "AudioPortAudioTarget.h" | 18 #include "AudioPortAudioTarget.h" |
19 #include "AudioCallbackPlaySource.h" | 19 #include "AudioCallbackPlaySource.h" |
20 | 20 |
21 #include <iostream> | 21 #include <iostream> |
33 m_done(false) | 33 m_done(false) |
34 { | 34 { |
35 PaError err; | 35 PaError err; |
36 | 36 |
37 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | 37 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET |
38 #ifdef HAVE_PORTAUDIO_V18 | |
39 std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v18" << std::endl; | |
40 #else | |
41 std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v19" << std::endl; | 38 std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v19" << std::endl; |
42 #endif | |
43 #endif | 39 #endif |
44 | 40 |
45 err = Pa_Initialize(); | 41 err = Pa_Initialize(); |
46 if (err != paNoError) { | 42 if (err != paNoError) { |
47 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl; | 43 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl; |
52 m_sampleRate = 44100; | 48 m_sampleRate = 44100; |
53 if (m_source && (m_source->getSourceSampleRate() != 0)) { | 49 if (m_source && (m_source->getSourceSampleRate() != 0)) { |
54 m_sampleRate = m_source->getSourceSampleRate(); | 50 m_sampleRate = m_source->getSourceSampleRate(); |
55 } | 51 } |
56 | 52 |
57 #ifdef HAVE_PORTAUDIO_V18 | |
58 m_latency = Pa_GetMinNumBuffers(m_bufferSize, m_sampleRate) * m_bufferSize; | |
59 #endif | |
60 | |
61 #ifdef HAVE_PORTAUDIO_V18 | |
62 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, | |
63 m_sampleRate, m_bufferSize, 0, | |
64 processStatic, this); | |
65 #else | |
66 PaStreamParameters op; | 53 PaStreamParameters op; |
67 op.device = Pa_GetDefaultOutputDevice(); | 54 op.device = Pa_GetDefaultOutputDevice(); |
68 op.channelCount = 2; | 55 op.channelCount = 2; |
69 op.sampleFormat = paFloat32; | 56 op.sampleFormat = paFloat32; |
70 op.suggestedLatency = 0.2; | 57 op.suggestedLatency = 0.2; |
71 op.hostApiSpecificStreamInfo = 0; | 58 op.hostApiSpecificStreamInfo = 0; |
72 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, | 59 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, |
73 paFramesPerBufferUnspecified, | 60 paFramesPerBufferUnspecified, |
74 paNoFlag, processStatic, this); | 61 paNoFlag, processStatic, this); |
75 #endif | 62 |
76 | |
77 #ifndef HAVE_PORTAUDIO_V18 | |
78 if (err != paNoError) { | 63 if (err != paNoError) { |
79 | 64 |
80 std::cerr << "WARNING: AudioPortAudioTarget: Failed to open PortAudio stream with default frames per buffer, trying again with fixed frames per buffer..." << std::endl; | 65 std::cerr << "WARNING: AudioPortAudioTarget: Failed to open PortAudio stream with default frames per buffer, trying again with fixed frames per buffer..." << std::endl; |
81 | 66 |
82 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, | 67 err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, |
83 1024, | 68 1024, |
84 paNoFlag, processStatic, this); | 69 paNoFlag, processStatic, this); |
85 m_bufferSize = 1024; | 70 m_bufferSize = 1024; |
86 } | 71 } |
87 #endif | |
88 | 72 |
89 if (err != paNoError) { | 73 if (err != paNoError) { |
90 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl; | 74 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl; |
91 m_stream = 0; | 75 m_stream = 0; |
92 Pa_Terminate(); | 76 Pa_Terminate(); |
93 return; | 77 return; |
94 } | 78 } |
95 | 79 |
96 #ifndef HAVE_PORTAUDIO_V18 | |
97 const PaStreamInfo *info = Pa_GetStreamInfo(m_stream); | 80 const PaStreamInfo *info = Pa_GetStreamInfo(m_stream); |
98 m_latency = int(info->outputLatency * m_sampleRate + 0.001); | 81 m_latency = int(info->outputLatency * m_sampleRate + 0.001); |
99 if (m_bufferSize < m_latency) m_bufferSize = m_latency; | 82 if (m_bufferSize < m_latency) m_bufferSize = m_latency; |
100 #endif | |
101 | 83 |
102 std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl; | 84 std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl; |
103 | 85 |
104 err = Pa_StartStream(m_stream); | 86 err = Pa_StartStream(m_stream); |
105 | 87 |
173 { | 155 { |
174 if (!m_stream) return 0.0; | 156 if (!m_stream) return 0.0; |
175 else return Pa_GetStreamTime(m_stream); | 157 else return Pa_GetStreamTime(m_stream); |
176 } | 158 } |
177 | 159 |
178 #ifdef HAVE_PORTAUDIO_V18 | |
179 int | |
180 AudioPortAudioTarget::processStatic(void *input, void *output, | |
181 unsigned long nframes, | |
182 PaTimestamp outTime, void *data) | |
183 { | |
184 return ((AudioPortAudioTarget *)data)->process(input, output, | |
185 nframes, outTime); | |
186 } | |
187 #else | |
188 int | 160 int |
189 AudioPortAudioTarget::processStatic(const void *input, void *output, | 161 AudioPortAudioTarget::processStatic(const void *input, void *output, |
190 unsigned long nframes, | 162 unsigned long nframes, |
191 const PaStreamCallbackTimeInfo *timeInfo, | 163 const PaStreamCallbackTimeInfo *timeInfo, |
192 PaStreamCallbackFlags flags, void *data) | 164 PaStreamCallbackFlags flags, void *data) |
193 { | 165 { |
194 return ((AudioPortAudioTarget *)data)->process(input, output, | 166 return ((AudioPortAudioTarget *)data)->process(input, output, |
195 nframes, timeInfo, | 167 nframes, timeInfo, |
196 flags); | 168 flags); |
197 } | 169 } |
198 #endif | |
199 | 170 |
200 void | 171 void |
201 AudioPortAudioTarget::sourceModelReplaced() | 172 AudioPortAudioTarget::sourceModelReplaced() |
202 { | 173 { |
203 m_source->setTargetSampleRate(m_sampleRate); | 174 m_source->setTargetSampleRate(m_sampleRate); |
204 } | 175 } |
205 | 176 |
206 #ifdef HAVE_PORTAUDIO_V18 | |
207 int | |
208 AudioPortAudioTarget::process(void *inputBuffer, void *outputBuffer, | |
209 unsigned long nframes, | |
210 PaTimestamp) | |
211 #else | |
212 int | 177 int |
213 AudioPortAudioTarget::process(const void *, void *outputBuffer, | 178 AudioPortAudioTarget::process(const void *, void *outputBuffer, |
214 unsigned long nframes, | 179 unsigned long nframes, |
215 const PaStreamCallbackTimeInfo *, | 180 const PaStreamCallbackTimeInfo *, |
216 PaStreamCallbackFlags) | 181 PaStreamCallbackFlags) |
217 #endif | |
218 { | 182 { |
219 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | 183 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET |
220 std::cout << "AudioPortAudioTarget::process(" << nframes << ")" << std::endl; | 184 std::cout << "AudioPortAudioTarget::process(" << nframes << ")" << std::endl; |
221 #endif | 185 #endif |
222 | 186 |