diff audioio/AudioPortAudioTarget.cpp @ 91:9fc4b256c283

* PortAudio driver: do not specify frames per buffer, let PA decide * Remove old non-RubberBand time stretcher -- it doesn't work with varying buffer sizes such as the PA driver may now be using * Rewrite getCurrentPlayingFrame for greater correctness when using long buffer sizes (interpolating according to audio stream timestamp) * Several changes to make the timestretch management RT safe(r)
author Chris Cannam
date Fri, 08 Feb 2008 17:51:15 +0000
parents 0948bf800422
children dd6d0bc05030
line wrap: on
line diff
--- a/audioio/AudioPortAudioTarget.cpp	Thu Feb 07 12:35:08 2008 +0000
+++ b/audioio/AudioPortAudioTarget.cpp	Fri Feb 08 17:51:15 2008 +0000
@@ -69,7 +69,8 @@
     op.sampleFormat = paFloat32;
     op.suggestedLatency = 0.2;
     op.hostApiSpecificStreamInfo = 0;
-    err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate, m_bufferSize,
+    err = Pa_OpenStream(&m_stream, 0, &op, m_sampleRate,
+                        paFramesPerBufferUnspecified,
                         paNoFlag, processStatic, this);
 #endif    
 
@@ -83,6 +84,7 @@
 #ifndef HAVE_PORTAUDIO_V18
     const PaStreamInfo *info = Pa_GetStreamInfo(m_stream);
     m_latency = int(info->outputLatency * m_sampleRate + 0.001);
+    m_bufferSize = m_latency;
 #endif
 
     std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl;
@@ -99,7 +101,7 @@
 
     if (m_source) {
 	std::cerr << "AudioPortAudioTarget: block size " << m_bufferSize << std::endl;
-	m_source->setTargetBlockSize(m_bufferSize);
+	m_source->setTarget(this, m_bufferSize);
 	m_source->setTargetSampleRate(m_sampleRate);
 	m_source->setTargetPlayLatency(m_latency);
     }
@@ -113,6 +115,10 @@
 {
     std::cerr << "AudioPortAudioTarget::~AudioPortAudioTarget()" << std::endl;
 
+    if (m_source) {
+        m_source->setTarget(0, m_bufferSize);
+    }
+
     shutdown();
 
     if (m_stream) {
@@ -150,6 +156,13 @@
     return (m_stream != 0);
 }
 
+double
+AudioPortAudioTarget::getCurrentTime() const
+{
+    if (!m_stream) return 0.0;
+    else return Pa_GetStreamTime(m_stream);
+}
+
 #ifdef HAVE_PORTAUDIO_V18
 int
 AudioPortAudioTarget::processStatic(void *input, void *output,