comparison audioio/AudioJACKTarget.cpp @ 366:0876ea394902 warnfix_no_size_t

Remove size_t's, fix compiler warnings
author Chris Cannam
date Tue, 17 Jun 2014 16:23:06 +0100
parents 068235cf5bf7
children 49d5e885f58e
comparison
equal deleted inserted replaced
355:e7a3fa8f4eec 366:0876ea394902
169 if (!s) return 0; 169 if (!s) return 0;
170 func f = (func)s; 170 func f = (func)s;
171 return f(client, port); 171 return f(client, port);
172 } 172 }
173 173
174 static void dynamic_jack_port_get_latency_range(jack_port_t *port,
175 jack_latency_callback_mode_t mode,
176 jack_latency_range_t *range)
177 {
178 typedef void (*func)(jack_port_t *, jack_latency_callback_mode_t, jack_latency_range_t *);
179 void *s = symbol("jack_port_get_latency_range");
180 if (!s) {
181 range.min = range.max = 0;
182 return;
183 }
184 func f = (func)s;
185 f(port, mode, range);
186 }
187
174 #define dynamic1(rv, name, argtype, failval) \ 188 #define dynamic1(rv, name, argtype, failval) \
175 static rv dynamic_##name(argtype arg) { \ 189 static rv dynamic_##name(argtype arg) { \
176 typedef rv (*func) (argtype); \ 190 typedef rv (*func) (argtype); \
177 void *s = symbol(#name); \ 191 void *s = symbol(#name); \
178 if (!s) return failval; \ 192 if (!s) return failval; \
185 dynamic1(jack_nframes_t, jack_get_sample_rate, jack_client_t *, 0); 199 dynamic1(jack_nframes_t, jack_get_sample_rate, jack_client_t *, 0);
186 dynamic1(int, jack_activate, jack_client_t *, 1); 200 dynamic1(int, jack_activate, jack_client_t *, 1);
187 dynamic1(int, jack_deactivate, jack_client_t *, 1); 201 dynamic1(int, jack_deactivate, jack_client_t *, 1);
188 dynamic1(int, jack_client_close, jack_client_t *, 1); 202 dynamic1(int, jack_client_close, jack_client_t *, 1);
189 dynamic1(jack_nframes_t, jack_frame_time, jack_client_t *, 0); 203 dynamic1(jack_nframes_t, jack_frame_time, jack_client_t *, 0);
190 dynamic1(jack_nframes_t, jack_port_get_latency, jack_port_t *, 0);
191 dynamic1(const char *, jack_port_name, const jack_port_t *, 0); 204 dynamic1(const char *, jack_port_name, const jack_port_t *, 0);
192 205
193 #define jack_client_new dynamic_jack_client_new 206 #define jack_client_new dynamic_jack_client_new
194 #define jack_client_open dynamic_jack_client_open 207 #define jack_client_open dynamic_jack_client_open
195 #define jack_get_buffer_size dynamic_jack_get_buffer_size 208 #define jack_get_buffer_size dynamic_jack_get_buffer_size
201 #define jack_client_close dynamic_jack_client_close 214 #define jack_client_close dynamic_jack_client_close
202 #define jack_frame_time dynamic_jack_frame_time 215 #define jack_frame_time dynamic_jack_frame_time
203 #define jack_get_ports dynamic_jack_get_ports 216 #define jack_get_ports dynamic_jack_get_ports
204 #define jack_port_register dynamic_jack_port_register 217 #define jack_port_register dynamic_jack_port_register
205 #define jack_port_unregister dynamic_jack_port_unregister 218 #define jack_port_unregister dynamic_jack_port_unregister
206 #define jack_port_get_latency dynamic_jack_port_get_latency
207 #define jack_port_name dynamic_jack_port_name 219 #define jack_port_name dynamic_jack_port_name
208 #define jack_connect dynamic_jack_connect 220 #define jack_connect dynamic_jack_connect
209 #define jack_port_get_buffer dynamic_jack_port_get_buffer 221 #define jack_port_get_buffer dynamic_jack_port_get_buffer
210 222
211 #endif 223 #endif
332 m_mutex.lock(); 344 m_mutex.lock();
333 345
334 m_source->setTarget(this, m_bufferSize); 346 m_source->setTarget(this, m_bufferSize);
335 m_source->setTargetSampleRate(m_sampleRate); 347 m_source->setTargetSampleRate(m_sampleRate);
336 348
337 size_t channels = m_source->getSourceChannelCount(); 349 int channels = m_source->getSourceChannelCount();
338 350
339 // Because we offer pan, we always want at least 2 channels 351 // Because we offer pan, we always want at least 2 channels
340 if (channels < 2) channels = 2; 352 if (channels < 2) channels = 2;
341 353
342 if (channels == m_outputs.size() || !m_client) { 354 if (channels == (int)m_outputs.size() || !m_client) {
343 m_mutex.unlock(); 355 m_mutex.unlock();
344 return; 356 return;
345 } 357 }
346 358
347 const char **ports = 359 const char **ports =
348 jack_get_ports(m_client, NULL, NULL, 360 jack_get_ports(m_client, NULL, NULL,
349 JackPortIsPhysical | JackPortIsInput); 361 JackPortIsPhysical | JackPortIsInput);
350 size_t physicalPortCount = 0; 362 int physicalPortCount = 0;
351 while (ports[physicalPortCount]) ++physicalPortCount; 363 while (ports[physicalPortCount]) ++physicalPortCount;
352 364
353 #ifdef DEBUG_AUDIO_JACK_TARGET 365 #ifdef DEBUG_AUDIO_JACK_TARGET
354 SVDEBUG << "AudioJACKTarget::sourceModelReplaced: have " << channels << " channels and " << physicalPortCount << " physical ports" << endl; 366 SVDEBUG << "AudioJACKTarget::sourceModelReplaced: have " << channels << " channels and " << physicalPortCount << " physical ports" << endl;
355 #endif 367 #endif
356 368
357 while (m_outputs.size() < channels) { 369 while ((int)m_outputs.size() < channels) {
358 370
359 char name[20]; 371 char name[20];
360 jack_port_t *port; 372 jack_port_t *port;
361 373
362 sprintf(name, "out %d", int(m_outputs.size() + 1)); 374 sprintf(name, "out %d", int(m_outputs.size() + 1));
370 if (!port) { 382 if (!port) {
371 cerr 383 cerr
372 << "ERROR: AudioJACKTarget: Failed to create JACK output port " 384 << "ERROR: AudioJACKTarget: Failed to create JACK output port "
373 << m_outputs.size() << endl; 385 << m_outputs.size() << endl;
374 } else { 386 } else {
375 m_source->setTargetPlayLatency(jack_port_get_latency(port)); 387 jack_latency_range_t range;
388 jack_port_get_latency_range(port, JackPlaybackLatency, &range);
389 m_source->setTargetPlayLatency(range.max);
390 cerr << "AudioJACKTarget: output latency is " << range.max << endl;
376 } 391 }
377 392
378 if (m_outputs.size() < physicalPortCount) { 393 if ((int)m_outputs.size() < physicalPortCount) {
379 jack_connect(m_client, jack_port_name(port), ports[m_outputs.size()]); 394 jack_connect(m_client, jack_port_name(port), ports[m_outputs.size()]);
380 } 395 }
381 396
382 m_outputs.push_back(port); 397 m_outputs.push_back(port);
383 } 398 }
384 399
385 while (m_outputs.size() > channels) { 400 while ((int)m_outputs.size() > channels) {
386 std::vector<jack_port_t *>::iterator itr = m_outputs.end(); 401 std::vector<jack_port_t *>::iterator itr = m_outputs.end();
387 --itr; 402 --itr;
388 jack_port_t *port = *itr; 403 jack_port_t *port = *itr;
389 if (port) jack_port_unregister(m_client, port); 404 if (port) jack_port_unregister(m_client, port);
390 m_outputs.erase(itr); 405 m_outputs.erase(itr);
417 } 432 }
418 #endif 433 #endif
419 434
420 float **buffers = (float **)alloca(m_outputs.size() * sizeof(float *)); 435 float **buffers = (float **)alloca(m_outputs.size() * sizeof(float *));
421 436
422 for (size_t ch = 0; ch < m_outputs.size(); ++ch) { 437 for (int ch = 0; ch < (int)m_outputs.size(); ++ch) {
423 buffers[ch] = (float *)jack_port_get_buffer(m_outputs[ch], nframes); 438 buffers[ch] = (float *)jack_port_get_buffer(m_outputs[ch], nframes);
424 } 439 }
425 440
426 size_t received = 0; 441 int received = 0;
427 442
428 if (m_source) { 443 if (m_source) {
429 received = m_source->getSourceSamples(nframes, buffers); 444 received = m_source->getSourceSamples(nframes, buffers);
430 } 445 }
431 446
432 for (size_t ch = 0; ch < m_outputs.size(); ++ch) { 447 for (int ch = 0; ch < (int)m_outputs.size(); ++ch) {
433 for (size_t i = received; i < nframes; ++i) { 448 for (int i = received; i < (int)nframes; ++i) {
434 buffers[ch][i] = 0.0; 449 buffers[ch][i] = 0.0;
435 } 450 }
436 } 451 }
437 452
438 float peakLeft = 0.0, peakRight = 0.0; 453 float peakLeft = 0.0, peakRight = 0.0;
439 454
440 for (size_t ch = 0; ch < m_outputs.size(); ++ch) { 455 for (int ch = 0; ch < (int)m_outputs.size(); ++ch) {
441 456
442 float peak = 0.0; 457 float peak = 0.0;
443 458
444 for (size_t i = 0; i < nframes; ++i) { 459 for (int i = 0; i < (int)nframes; ++i) {
445 buffers[ch][i] *= m_outputGain; 460 buffers[ch][i] *= m_outputGain;
446 float sample = fabsf(buffers[ch][i]); 461 float sample = fabsf(buffers[ch][i]);
447 if (sample > peak) peak = sample; 462 if (sample > peak) peak = sample;
448 } 463 }
449 464