changeset 92:52409ab73526

* Add support for PortAudio v19 * Add ladspa.cat file to provide categories if unavailable through LRDF
author Chris Cannam
date Thu, 25 Jan 2007 12:02:44 +0000
parents 7005d8a9f0e0
children 14cc0a78f340
files audioio/AudioPortAudioTarget.cpp audioio/AudioPortAudioTarget.h
diffstat 2 files changed, 72 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/audioio/AudioPortAudioTarget.cpp	Fri Jan 19 14:38:57 2007 +0000
+++ b/audioio/AudioPortAudioTarget.cpp	Thu Jan 25 12:02:44 2007 +0000
@@ -33,9 +33,17 @@
 {
     PaError err;
 
+#ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET
+#ifdef HAVE_PORTAUDIO_v18
+    std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v18" << std::endl;
+#else
+    std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v19" << std::endl;
+#endif
+#endif
+
     err = Pa_Initialize();
     if (err != paNoError) {
-	std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio" << std::endl;
+	std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl;
 	return;
     }
 
@@ -45,25 +53,38 @@
 	m_sampleRate = m_source->getSourceSampleRate();
     }
 
+#ifdef HAVE_PORTAUDIO_v18
     m_latency = Pa_GetMinNumBuffers(m_bufferSize, m_sampleRate) * m_bufferSize;
+#endif
 
-    std::cerr << "\n\n\nLATENCY= " << m_latency << std::endl;
-
+#ifdef HAVE_PORTAUDIO_v18
     err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32,
 			       m_sampleRate, m_bufferSize, 0,
 			       processStatic, this);
+#else
+    err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32,
+			       m_sampleRate, m_bufferSize,
+			       processStatic, this);
+#endif    
 
     if (err != paNoError) {
-	std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream" << std::endl;
+	std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl;
 	m_stream = 0;
 	Pa_Terminate();
 	return;
     }
 
+#ifndef HAVE_PORTAUDIO_v18
+    const PaStreamInfo *info = Pa_GetStreamInfo(m_stream);
+    m_latency = int(info->outputLatency * m_sampleRate + 0.001);
+#endif
+
+    std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl;
+
     err = Pa_StartStream(m_stream);
 
     if (err != paNoError) {
-	std::cerr << "ERROR: AudioPortAudioTarget: Failed to start PortAudio stream" << std::endl;
+	std::cerr << "ERROR: AudioPortAudioTarget: Failed to start PortAudio stream: " << Pa_GetErrorText(err) << std::endl;
 	Pa_CloseStream(m_stream);
 	m_stream = 0;
 	Pa_Terminate();
@@ -84,9 +105,12 @@
 	PaError err;
 	err = Pa_CloseStream(m_stream);
 	if (err != paNoError) {
-	    std::cerr << "ERROR: AudioPortAudioTarget: Failed to close PortAudio stream" << std::endl;
+	    std::cerr << "ERROR: AudioPortAudioTarget: Failed to close PortAudio stream: " << Pa_GetErrorText(err) << std::endl;
 	}
-	Pa_Terminate();
+	err = Pa_Terminate();
+        if (err != paNoError) {
+            std::cerr << "ERROR: AudioPortAudioTarget: Failed to terminate PortAudio: " << Pa_GetErrorText(err) << std::endl;
+	}   
     }
 }
 
@@ -96,6 +120,7 @@
     return (m_stream != 0);
 }
 
+#ifdef HAVE_PORTAUDIO_v18
 int
 AudioPortAudioTarget::processStatic(void *input, void *output,
 				    unsigned long nframes,
@@ -104,6 +129,18 @@
     return ((AudioPortAudioTarget *)data)->process(input, output,
 						   nframes, outTime);
 }
+#else
+int
+AudioPortAudioTarget::processStatic(const void *input, void *output,
+                                    unsigned long nframes,
+                                    const PaStreamCallbackTimeInfo *timeInfo,
+                                    PaStreamCallbackFlags flags, void *data)
+{
+    return ((AudioPortAudioTarget *)data)->process(input, output,
+                                                   nframes, timeInfo,
+                                                   flags);
+}
+#endif
 
 void
 AudioPortAudioTarget::sourceModelReplaced()
@@ -111,10 +148,18 @@
     m_source->setTargetSampleRate(m_sampleRate);
 }
 
+#ifdef HAVE_PORTAUDIO_v18
 int
 AudioPortAudioTarget::process(void *inputBuffer, void *outputBuffer,
 			      unsigned long nframes,
 			      PaTimestamp)
+#else
+int
+AudioPortAudioTarget::process(const void *inputBuffer, void *outputBuffer,
+                              unsigned long nframes,
+                              const PaStreamCallbackTimeInfo *,
+                              PaStreamCallbackFlags)
+#endif
 {
 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET    
     std::cout << "AudioPortAudioTarget::process(" << nframes << ")" << std::endl;
--- a/audioio/AudioPortAudioTarget.h	Fri Jan 19 14:38:57 2007 +0000
+++ b/audioio/AudioPortAudioTarget.h	Thu Jan 25 12:02:44 2007 +0000
@@ -18,6 +18,10 @@
 
 #ifdef HAVE_PORTAUDIO
 
+// This code can be compiled for either PortAudio v18 or v19.
+// PortAudio v19 is the default.  If you want to use v18, define
+// the preprocessor symbol HAVE_PORTAUDIO_v18.
+
 #include <portaudio.h>
 #include <vector>
 
@@ -39,6 +43,8 @@
     virtual void sourceModelReplaced();
 
 protected:
+#ifdef HAVE_PORTAUDIO_V18
+
     int process(void *input, void *output, unsigned long frames,
 		PaTimestamp outTime);
 
@@ -47,6 +53,20 @@
 
     PortAudioStream *m_stream;
 
+#else
+
+    int process(const void *input, void *output, unsigned long frames,
+                const PaStreamCallbackTimeInfo *timeInfo,
+                PaStreamCallbackFlags statusFlags);
+
+    static int processStatic(const void *, void *, unsigned long,
+                             const PaStreamCallbackTimeInfo *,
+                             PaStreamCallbackFlags, void *);
+
+    PaStream *m_stream;
+
+#endif
+
     int m_bufferSize;
     int m_sampleRate;
     int m_latency;