|
1 | 1 | /*
|
2 | 2 | * jack output driver. This file is part of Shairport Sync.
|
3 |
| - * Copyright (c) 2019 -- 2022 Mike Brady <[email protected]>, |
| 3 | + * Copyright (c) 2019 -- 2024 Mike Brady <[email protected]>, |
4 | 4 | * Jörn Nettingsmeier <[email protected]>
|
5 | 5 | *
|
6 | 6 | * All rights reserved.
|
@@ -50,8 +50,11 @@ pthread_mutex_t client_mutex = PTHREAD_MUTEX_INITIALIZER;
|
50 | 50 | jack_port_t *port[NPORTS];
|
51 | 51 | const char *port_name[NPORTS] = {"out_L", "out_R"};
|
52 | 52 |
|
| 53 | + |
| 54 | +int sps_sample_rate; |
| 55 | + |
53 | 56 | jack_client_t *client;
|
54 |
| -jack_nframes_t sample_rate; |
| 57 | +jack_nframes_t jack_sample_rate; |
55 | 58 | jack_nframes_t jack_latency;
|
56 | 59 |
|
57 | 60 | jack_ringbuffer_t *jackbuf;
|
@@ -235,17 +238,17 @@ static int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) c
|
235 | 238 | if (!client) {
|
236 | 239 | die("Could not start JACK server. JackStatus is %x", status);
|
237 | 240 | }
|
238 |
| - sample_rate = jack_get_sample_rate(client); |
| 241 | + jack_sample_rate = jack_get_sample_rate(client); |
239 | 242 | #ifdef CONFIG_SOXR
|
240 | 243 | if (config.jack_soxr_resample_quality >= SOXR_QQ) {
|
241 | 244 | quality_spec = soxr_quality_spec(config.jack_soxr_resample_quality, 0);
|
242 | 245 | io_spec = soxr_io_spec(SOXR_INT16_I, SOXR_FLOAT32_I);
|
243 | 246 | } else
|
244 | 247 | #endif
|
245 |
| - if (sample_rate != 44100) { |
| 248 | + if (jack_sample_rate != 44100) { |
246 | 249 | die("The JACK server is running at the wrong sample rate (%d) for Shairport Sync."
|
247 | 250 | " Must be 44100 Hz.",
|
248 |
| - sample_rate); |
| 251 | + jack_sample_rate); |
249 | 252 | }
|
250 | 253 | jack_set_process_callback(client, &process, NULL);
|
251 | 254 | jack_set_graph_order_callback(client, &graph, NULL);
|
@@ -329,14 +332,15 @@ static void jack_start(int i_sample_rate, __attribute__((unused)) int i_sample_f
|
329 | 332 | // Nothing to do, JACK client has already been set up at jack_init().
|
330 | 333 | // Also, we have no say over the sample rate or sample format of JACK,
|
331 | 334 | // We convert the 16bit samples to float, and die if the sample rate is != 44k1 without soxr.
|
| 335 | + sps_sample_rate = i_sample_rate; |
332 | 336 | #ifdef CONFIG_SOXR
|
333 | 337 | if (config.jack_soxr_resample_quality >= SOXR_QQ) {
|
334 | 338 | // we might improve a bit with soxr_clear if the sample_rate doesn't change
|
335 | 339 | if (soxr) {
|
336 | 340 | soxr_delete(soxr);
|
337 | 341 | }
|
338 | 342 | soxr_error_t e = NULL;
|
339 |
| - soxr = soxr_create(i_sample_rate, sample_rate, NPORTS, &e, &io_spec, &quality_spec, NULL); |
| 343 | + soxr = soxr_create(sps_sample_rate, jack_sample_rate, NPORTS, &e, &io_spec, &quality_spec, NULL); |
340 | 344 | if (!soxr) {
|
341 | 345 | die("Unable to create soxr resampler for JACK: %s", e);
|
342 | 346 | }
|
@@ -366,13 +370,15 @@ static int jack_delay(long *the_delay) {
|
366 | 370 | debug(2, "audio_occupancy_now is %d.", audio_occupancy_now);
|
367 | 371 | pthread_mutex_unlock(&buffer_mutex);
|
368 | 372 |
|
369 |
| - int64_t frames_processed_since_latest_latency_check = (delta * sample_rate) / 1000000000; |
| 373 | + int64_t frames_processed_since_latest_latency_check = (delta * jack_sample_rate) / 1000000000; |
370 | 374 | // debug(1,"delta: %" PRId64 " frames.",frames_processed_since_latest_latency_check);
|
371 | 375 | // jack_latency is set by the graph() callback, it's the average of the maximum
|
372 | 376 | // latencies of all our output ports. Adjust this constant baseline delay according
|
373 | 377 | // to the buffer fill level:
|
374 |
| - *the_delay = jack_latency + audio_occupancy_now - frames_processed_since_latest_latency_check; |
375 |
| - // debug(1,"reporting a delay of %d frames",*the_delay); |
| 378 | + int64_t the_delay_in_jack_frames = jack_latency + audio_occupancy_now - frames_processed_since_latest_latency_check; |
| 379 | + int64_t the_delay_in_sps_frames = (the_delay_in_jack_frames * sps_sample_rate) / jack_sample_rate; |
| 380 | + *the_delay = the_delay_in_sps_frames; |
| 381 | + // debug(2, "reporting a delay of %ld frames at Shairport Sync's rate of %d FPS.",*the_delay, sps_sample_rate); |
376 | 382 | return 0;
|
377 | 383 | }
|
378 | 384 |
|
|
0 commit comments