Mercurial > hg > sonic-visualiser
comparison audioio/AudioPortAudioTarget.cpp @ 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 | cd5d7ff8ef38 |
children | 5828afd1d229 |
comparison
equal
deleted
inserted
replaced
91:7005d8a9f0e0 | 92:52409ab73526 |
---|---|
31 m_sampleRate(0), | 31 m_sampleRate(0), |
32 m_latency(0) | 32 m_latency(0) |
33 { | 33 { |
34 PaError err; | 34 PaError err; |
35 | 35 |
36 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | |
37 #ifdef HAVE_PORTAUDIO_v18 | |
38 std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v18" << std::endl; | |
39 #else | |
40 std::cerr << "AudioPortAudioTarget: Initialising for PortAudio v19" << std::endl; | |
41 #endif | |
42 #endif | |
43 | |
36 err = Pa_Initialize(); | 44 err = Pa_Initialize(); |
37 if (err != paNoError) { | 45 if (err != paNoError) { |
38 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio" << std::endl; | 46 std::cerr << "ERROR: AudioPortAudioTarget: Failed to initialize PortAudio: " << Pa_GetErrorText(err) << std::endl; |
39 return; | 47 return; |
40 } | 48 } |
41 | 49 |
42 m_bufferSize = 1024; | 50 m_bufferSize = 1024; |
43 m_sampleRate = 44100; | 51 m_sampleRate = 44100; |
44 if (m_source && (m_source->getSourceSampleRate() != 0)) { | 52 if (m_source && (m_source->getSourceSampleRate() != 0)) { |
45 m_sampleRate = m_source->getSourceSampleRate(); | 53 m_sampleRate = m_source->getSourceSampleRate(); |
46 } | 54 } |
47 | 55 |
56 #ifdef HAVE_PORTAUDIO_v18 | |
48 m_latency = Pa_GetMinNumBuffers(m_bufferSize, m_sampleRate) * m_bufferSize; | 57 m_latency = Pa_GetMinNumBuffers(m_bufferSize, m_sampleRate) * m_bufferSize; |
49 | 58 #endif |
50 std::cerr << "\n\n\nLATENCY= " << m_latency << std::endl; | 59 |
51 | 60 #ifdef HAVE_PORTAUDIO_v18 |
52 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, | 61 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, |
53 m_sampleRate, m_bufferSize, 0, | 62 m_sampleRate, m_bufferSize, 0, |
54 processStatic, this); | 63 processStatic, this); |
64 #else | |
65 err = Pa_OpenDefaultStream(&m_stream, 0, 2, paFloat32, | |
66 m_sampleRate, m_bufferSize, | |
67 processStatic, this); | |
68 #endif | |
55 | 69 |
56 if (err != paNoError) { | 70 if (err != paNoError) { |
57 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream" << std::endl; | 71 std::cerr << "ERROR: AudioPortAudioTarget: Failed to open PortAudio stream: " << Pa_GetErrorText(err) << std::endl; |
58 m_stream = 0; | 72 m_stream = 0; |
59 Pa_Terminate(); | 73 Pa_Terminate(); |
60 return; | 74 return; |
61 } | 75 } |
62 | 76 |
77 #ifndef HAVE_PORTAUDIO_v18 | |
78 const PaStreamInfo *info = Pa_GetStreamInfo(m_stream); | |
79 m_latency = int(info->outputLatency * m_sampleRate + 0.001); | |
80 #endif | |
81 | |
82 std::cerr << "PortAudio latency = " << m_latency << " frames" << std::endl; | |
83 | |
63 err = Pa_StartStream(m_stream); | 84 err = Pa_StartStream(m_stream); |
64 | 85 |
65 if (err != paNoError) { | 86 if (err != paNoError) { |
66 std::cerr << "ERROR: AudioPortAudioTarget: Failed to start PortAudio stream" << std::endl; | 87 std::cerr << "ERROR: AudioPortAudioTarget: Failed to start PortAudio stream: " << Pa_GetErrorText(err) << std::endl; |
67 Pa_CloseStream(m_stream); | 88 Pa_CloseStream(m_stream); |
68 m_stream = 0; | 89 m_stream = 0; |
69 Pa_Terminate(); | 90 Pa_Terminate(); |
70 return; | 91 return; |
71 } | 92 } |
82 { | 103 { |
83 if (m_stream) { | 104 if (m_stream) { |
84 PaError err; | 105 PaError err; |
85 err = Pa_CloseStream(m_stream); | 106 err = Pa_CloseStream(m_stream); |
86 if (err != paNoError) { | 107 if (err != paNoError) { |
87 std::cerr << "ERROR: AudioPortAudioTarget: Failed to close PortAudio stream" << std::endl; | 108 std::cerr << "ERROR: AudioPortAudioTarget: Failed to close PortAudio stream: " << Pa_GetErrorText(err) << std::endl; |
88 } | 109 } |
89 Pa_Terminate(); | 110 err = Pa_Terminate(); |
111 if (err != paNoError) { | |
112 std::cerr << "ERROR: AudioPortAudioTarget: Failed to terminate PortAudio: " << Pa_GetErrorText(err) << std::endl; | |
113 } | |
90 } | 114 } |
91 } | 115 } |
92 | 116 |
93 bool | 117 bool |
94 AudioPortAudioTarget::isOK() const | 118 AudioPortAudioTarget::isOK() const |
95 { | 119 { |
96 return (m_stream != 0); | 120 return (m_stream != 0); |
97 } | 121 } |
98 | 122 |
123 #ifdef HAVE_PORTAUDIO_v18 | |
99 int | 124 int |
100 AudioPortAudioTarget::processStatic(void *input, void *output, | 125 AudioPortAudioTarget::processStatic(void *input, void *output, |
101 unsigned long nframes, | 126 unsigned long nframes, |
102 PaTimestamp outTime, void *data) | 127 PaTimestamp outTime, void *data) |
103 { | 128 { |
104 return ((AudioPortAudioTarget *)data)->process(input, output, | 129 return ((AudioPortAudioTarget *)data)->process(input, output, |
105 nframes, outTime); | 130 nframes, outTime); |
106 } | 131 } |
132 #else | |
133 int | |
134 AudioPortAudioTarget::processStatic(const void *input, void *output, | |
135 unsigned long nframes, | |
136 const PaStreamCallbackTimeInfo *timeInfo, | |
137 PaStreamCallbackFlags flags, void *data) | |
138 { | |
139 return ((AudioPortAudioTarget *)data)->process(input, output, | |
140 nframes, timeInfo, | |
141 flags); | |
142 } | |
143 #endif | |
107 | 144 |
108 void | 145 void |
109 AudioPortAudioTarget::sourceModelReplaced() | 146 AudioPortAudioTarget::sourceModelReplaced() |
110 { | 147 { |
111 m_source->setTargetSampleRate(m_sampleRate); | 148 m_source->setTargetSampleRate(m_sampleRate); |
112 } | 149 } |
113 | 150 |
151 #ifdef HAVE_PORTAUDIO_v18 | |
114 int | 152 int |
115 AudioPortAudioTarget::process(void *inputBuffer, void *outputBuffer, | 153 AudioPortAudioTarget::process(void *inputBuffer, void *outputBuffer, |
116 unsigned long nframes, | 154 unsigned long nframes, |
117 PaTimestamp) | 155 PaTimestamp) |
156 #else | |
157 int | |
158 AudioPortAudioTarget::process(const void *inputBuffer, void *outputBuffer, | |
159 unsigned long nframes, | |
160 const PaStreamCallbackTimeInfo *, | |
161 PaStreamCallbackFlags) | |
162 #endif | |
118 { | 163 { |
119 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET | 164 #ifdef DEBUG_AUDIO_PORT_AUDIO_TARGET |
120 std::cout << "AudioPortAudioTarget::process(" << nframes << ")" << std::endl; | 165 std::cout << "AudioPortAudioTarget::process(" << nframes << ")" << std::endl; |
121 #endif | 166 #endif |
122 | 167 |