Portaudio options - add ability to force playnice mode on osx, fix parsing of device id 0
Adrian Smith
10 years ago
33 | 33 | " -a <b>:<p>:<f>:<m>\tSpecify ALSA params to open output device, b = buffer time in ms or size in bytes, p = period count or size in bytes, f sample format (16|24|24_3|32), m = use mmap (0|1)\n" |
34 | 34 | #endif |
35 | 35 | #if PORTAUDIO |
36 | " -a <latency>\t\tSpecify output target latency in ms\n" | |
36 | #if MAC | |
37 | " -a <l>:<r>\t\tSpecify Portaudio params to open output device, l = target latency in ms, r = allow OSX to resample (0|1)\n" | |
38 | #else | |
39 | " -a <l>\t\tSpecify Portaudio params to open output device, l = target latency in ms\n" | |
40 | #endif | |
37 | 41 | #endif |
38 | 42 | " -b <stream>:<output>\tSpecify internal Stream and Output buffer sizes in Kbytes\n" |
39 | 43 | " -c <codec1>,<codec2>\tRestrict codecs to those specified, otherwise load all available codecs; known codecs: flac,pcm,mp3,ogg,aac (mad,mpg for specific mp3 codec)\n" |
108 | 112 | #endif |
109 | 113 | #if PORTAUDIO |
110 | 114 | unsigned pa_latency = 0; |
115 | int pa_osx_playnice = -1; | |
111 | 116 | #endif |
112 | 117 | |
113 | 118 | log_level log_output = lWARN; |
154 | 159 | if (m) alsa_mmap = atoi(m); |
155 | 160 | #endif |
156 | 161 | #if PORTAUDIO |
157 | pa_latency = (unsigned)atoi(optarg); | |
162 | char *l = next_param(optarg, ':'); | |
163 | char *p = next_param(NULL, ':'); | |
164 | if (l) pa_latency = (unsigned)atoi(l); | |
165 | if (p) pa_osx_playnice = atoi(p); | |
158 | 166 | #endif |
159 | 167 | } |
160 | 168 | break; |
288 | 296 | max_rate, rt_priority); |
289 | 297 | #endif |
290 | 298 | #if PORTAUDIO |
291 | output_init(log_output, output_device, output_buf_size, pa_latency, max_rate); | |
299 | output_init(log_output, output_device, output_buf_size, pa_latency, pa_osx_playnice, max_rate); | |
292 | 300 | #endif |
293 | 301 | |
294 | 302 | decode_init(log_decode, codecs); |
393 | 393 | if (!strncmp(device, "default", 7)) { |
394 | 394 | return Pa_GetDefaultOutputDevice(); |
395 | 395 | } |
396 | if (len >= 1 && len <= 2 && device[0] > '0' && device[0] <= '9') { | |
396 | if (len >= 1 && len <= 2 && device[0] >= '0' && device[0] <= '9') { | |
397 | 397 | return atoi(device); |
398 | 398 | } |
399 | 399 | |
511 | 511 | outputParameters.hostApiSpecificStreamInfo = NULL; |
512 | 512 | |
513 | 513 | #if OSX |
514 | // enable pro mode which aims to avoid resampling if possible for non built in devices | |
515 | // see http://code.google.com/p/squeezelite/issues/detail?id=11 for reason for not doing with built in device | |
514 | // enable pro mode which aims to avoid resampling if possible | |
515 | // see http://code.google.com/p/squeezelite/issues/detail?id=11 & http://code.google.com/p/squeezelite/issues/detail?id=37 | |
516 | // command line controls osx_playnice which is -1 if not specified, 0 or 1 | |
516 | 517 | PaMacCoreStreamInfo macInfo; |
517 | 518 | unsigned long streamInfoFlags; |
518 | if (!strcmp(Pa_GetDeviceInfo(outputParameters.device)->name, "Built-in Output")) { | |
519 | if (output.osx_playnice == 1 || | |
520 | (output.osx_playnice == -1 && !strcmp(Pa_GetDeviceInfo(outputParameters.device)->name, "Built-in Output"))) { | |
519 | 521 | LOG_INFO("opening device in PlayNice mode"); |
520 | 522 | streamInfoFlags = paMacCorePlayNice; |
521 | 523 | } else { |
1328 | 1330 | const char *alsa_sample_fmt, bool mmap, unsigned max_rate, unsigned rt_priority) { |
1329 | 1331 | #endif |
1330 | 1332 | #if PORTAUDIO |
1331 | void output_init(log_level level, const char *device, unsigned output_buf_size, unsigned latency, unsigned max_rate) { | |
1333 | void output_init(log_level level, const char *device, unsigned output_buf_size, unsigned latency, int osx_playnice, unsigned max_rate) { | |
1332 | 1334 | PaError err; |
1333 | 1335 | #endif |
1334 | 1336 | loglevel = level; |
1375 | 1377 | |
1376 | 1378 | #if PORTAUDIO |
1377 | 1379 | output.latency = latency; |
1380 | output.osx_playnice = osx_playnice; | |
1378 | 1381 | pa.stream = NULL; |
1379 | 1382 | |
1380 | 1383 | LOG_INFO("requested latency: %u", output.latency); |
433 | 433 | #if PORTAUDIO |
434 | 434 | bool pa_reopen; |
435 | 435 | unsigned latency; |
436 | int osx_playnice; | |
436 | 437 | #endif |
437 | 438 | unsigned frames_played; |
438 | 439 | unsigned current_sample_rate; |
464 | 465 | void output_init(log_level level, const char *device, unsigned output_buf_size, unsigned alsa_buffer, unsigned alsa_period, const char *alsa_sample_fmt, bool mmap, unsigned max_rate, unsigned rt_priority); |
465 | 466 | #endif |
466 | 467 | #if PORTAUDIO |
467 | void output_init(log_level level, const char *device, unsigned output_buf_size, unsigned latency, unsigned max_rate); | |
468 | void output_init(log_level level, const char *device, unsigned output_buf_size, unsigned latency, int osx_playnice, unsigned max_rate); | |
468 | 469 | #endif |
469 | 470 | void output_flush(void); |
470 | 471 | void output_close(void); |