Mercurial > hg > svapp
comparison audioio/AudioPulseAudioTarget.cpp @ 436:72c662fe7ea3 cxx11
Further dedicated-types fixes
author | Chris Cannam |
---|---|
date | Tue, 10 Mar 2015 17:02:52 +0000 |
parents | 7709bb9a1130 |
children | ad998a2fe9e2 |
comparison
equal
deleted
inserted
replaced
435:618d5816b04d | 436:72c662fe7ea3 |
---|---|
55 //!!! handle signals how? | 55 //!!! handle signals how? |
56 | 56 |
57 m_bufferSize = 20480; | 57 m_bufferSize = 20480; |
58 m_sampleRate = 44100; | 58 m_sampleRate = 44100; |
59 if (m_source && (m_source->getSourceSampleRate() != 0)) { | 59 if (m_source && (m_source->getSourceSampleRate() != 0)) { |
60 m_sampleRate = m_source->getSourceSampleRate(); | 60 m_sampleRate = int(m_source->getSourceSampleRate()); |
61 } | 61 } |
62 m_spec.rate = m_sampleRate; | 62 m_spec.rate = m_sampleRate; |
63 m_spec.channels = 2; | 63 m_spec.channels = 2; |
64 m_spec.format = PA_SAMPLE_FLOAT32NE; | 64 m_spec.format = PA_SAMPLE_FLOAT32NE; |
65 | 65 |
139 { | 139 { |
140 if (!m_stream) return 0.0; | 140 if (!m_stream) return 0.0; |
141 | 141 |
142 pa_usec_t usec = 0; | 142 pa_usec_t usec = 0; |
143 pa_stream_get_time(m_stream, &usec); | 143 pa_stream_get_time(m_stream, &usec); |
144 return usec / 1000000.f; | 144 return double(usec) / 1000000.0; |
145 } | 145 } |
146 | 146 |
147 void | 147 void |
148 AudioPulseAudioTarget::sourceModelReplaced() | 148 AudioPulseAudioTarget::sourceModelReplaced() |
149 { | 149 { |
150 m_source->setTargetSampleRate(m_sampleRate); | 150 m_source->setTargetSampleRate(m_sampleRate); |
151 } | 151 } |
152 | 152 |
153 void | 153 void |
154 AudioPulseAudioTarget::streamWriteStatic(pa_stream *stream, | 154 AudioPulseAudioTarget::streamWriteStatic(pa_stream *, |
155 size_t length, | 155 size_t length, |
156 void *data) | 156 void *data) |
157 { | 157 { |
158 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; | 158 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; |
159 | 159 |
160 assert(stream == target->m_stream); | 160 // assert(stream == target->m_stream); |
161 | 161 |
162 target->streamWrite(length); | 162 target->streamWrite(length); |
163 } | 163 } |
164 | 164 |
165 void | 165 void |
166 AudioPulseAudioTarget::streamWrite(int requested) | 166 AudioPulseAudioTarget::streamWrite(sv_frame_t requested) |
167 { | 167 { |
168 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY | 168 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY |
169 cout << "AudioPulseAudioTarget::streamWrite(" << requested << ")" << endl; | 169 cout << "AudioPulseAudioTarget::streamWrite(" << requested << ")" << endl; |
170 #endif | 170 #endif |
171 if (m_done) return; | 171 if (m_done) return; |
173 QMutexLocker locker(&m_mutex); | 173 QMutexLocker locker(&m_mutex); |
174 | 174 |
175 pa_usec_t latency = 0; | 175 pa_usec_t latency = 0; |
176 int negative = 0; | 176 int negative = 0; |
177 if (!pa_stream_get_latency(m_stream, &latency, &negative)) { | 177 if (!pa_stream_get_latency(m_stream, &latency, &negative)) { |
178 int latframes = (latency / 1000000.f) * float(m_sampleRate); | 178 int latframes = int(double(latency) / 1000000.0 * double(m_sampleRate)); |
179 if (latframes > 0) m_source->setTargetPlayLatency(latframes); | 179 if (latframes > 0) m_source->setTargetPlayLatency(latframes); |
180 } | 180 } |
181 | 181 |
182 static float *output = 0; | 182 static float *output = 0; |
183 static float **tmpbuf = 0; | 183 static float **tmpbuf = 0; |
184 static int tmpbufch = 0; | 184 static int tmpbufch = 0; |
185 static int tmpbufsz = 0; | 185 static sv_frame_t tmpbufsz = 0; |
186 | 186 |
187 int sourceChannels = m_source->getSourceChannelCount(); | 187 int sourceChannels = m_source->getSourceChannelCount(); |
188 | 188 |
189 // Because we offer pan, we always want at least 2 channels | 189 // Because we offer pan, we always want at least 2 channels |
190 if (sourceChannels < 2) sourceChannels = 2; | 190 if (sourceChannels < 2) sourceChannels = 2; |
191 | 191 |
192 int nframes = requested / (sourceChannels * sizeof(float)); | 192 sv_frame_t nframes = requested / (sourceChannels * sizeof(float)); |
193 | 193 |
194 if (nframes > m_bufferSize) { | 194 if (nframes > m_bufferSize) { |
195 cerr << "WARNING: AudioPulseAudioTarget::streamWrite: nframes " << nframes << " > m_bufferSize " << m_bufferSize << endl; | 195 cerr << "WARNING: AudioPulseAudioTarget::streamWrite: nframes " << nframes << " > m_bufferSize " << m_bufferSize << endl; |
196 } | 196 } |
197 | 197 |
221 } | 221 } |
222 | 222 |
223 output = new float[tmpbufsz * tmpbufch]; | 223 output = new float[tmpbufsz * tmpbufch]; |
224 } | 224 } |
225 | 225 |
226 int received = m_source->getSourceSamples(nframes, tmpbuf); | 226 sv_frame_t received = m_source->getSourceSamples(nframes, tmpbuf); |
227 | 227 |
228 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY | 228 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY |
229 cerr << "requested " << nframes << ", received " << received << endl; | 229 cerr << "requested " << nframes << ", received " << received << endl; |
230 | 230 |
231 if (received < nframes) { | 231 if (received < nframes) { |
266 | 266 |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 void | 270 void |
271 AudioPulseAudioTarget::streamStateChangedStatic(pa_stream *stream, | 271 AudioPulseAudioTarget::streamStateChangedStatic(pa_stream *, |
272 void *data) | 272 void *data) |
273 { | 273 { |
274 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; | 274 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; |
275 | 275 |
276 assert(stream == target->m_stream); | 276 // assert(stream == target->m_stream); |
277 | 277 |
278 target->streamStateChanged(); | 278 target->streamStateChanged(); |
279 } | 279 } |
280 | 280 |
281 void | 281 void |
301 int negative = 0; | 301 int negative = 0; |
302 if (pa_stream_get_latency(m_stream, &latency, &negative)) { | 302 if (pa_stream_get_latency(m_stream, &latency, &negative)) { |
303 cerr << "AudioPulseAudioTarget::streamStateChanged: Failed to query latency" << endl; | 303 cerr << "AudioPulseAudioTarget::streamStateChanged: Failed to query latency" << endl; |
304 } | 304 } |
305 cerr << "Latency = " << latency << " usec" << endl; | 305 cerr << "Latency = " << latency << " usec" << endl; |
306 int latframes = (latency / 1000000.f) * float(m_sampleRate); | 306 int latframes = int(double(latency) / 1000000.0 * m_sampleRate); |
307 cerr << "that's " << latframes << " frames" << endl; | 307 cerr << "that's " << latframes << " frames" << endl; |
308 | 308 |
309 const pa_buffer_attr *attr; | 309 const pa_buffer_attr *attr; |
310 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { | 310 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { |
311 SVDEBUG << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << endl; | 311 SVDEBUG << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << endl; |
332 break; | 332 break; |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 void | 336 void |
337 AudioPulseAudioTarget::contextStateChangedStatic(pa_context *context, | 337 AudioPulseAudioTarget::contextStateChangedStatic(pa_context *, |
338 void *data) | 338 void *data) |
339 { | 339 { |
340 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; | 340 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; |
341 | 341 |
342 assert(context == target->m_context); | 342 // assert(context == target->m_context); |
343 | 343 |
344 target->contextStateChanged(); | 344 target->contextStateChanged(); |
345 } | 345 } |
346 | 346 |
347 void | 347 void |