From: Jörn Nettingsmeier Date: Sat, 16 Feb 2019 16:09:29 +0000 (+0000) Subject: Move away from hardcoded channels. Centralizes information, simplifies the code,... X-Git-Tag: 3.3RC0~52^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f39e0d83073513e4bbfd85648fda932d056c717;p=thirdparty%2Fshairport-sync.git Move away from hardcoded channels. Centralizes information, simplifies the code, and might be helpful for future surround support. --- diff --git a/audio_jack.c b/audio_jack.c index cd90c796..6f4e3416 100644 --- a/audio_jack.c +++ b/audio_jack.c @@ -58,8 +58,10 @@ audio_output audio_jack = {.name = "jack", .parameters = NULL, .mute = NULL}; -static jack_port_t *left_port; -static jack_port_t *right_port; +// This also affects deinterlacing, so make it exactly the number of incoming audio channels! +#define NPORTS 2 +static jack_port_t *port[NPORTS]; +static const char* port_name[NPORTS] = { "out_L", "out_R" }; static jack_client_t *client; static jack_nframes_t sample_rate; @@ -68,7 +70,7 @@ static jack_nframes_t jack_latency; static jack_ringbuffer_t *jackbuf; static int flush_please = 0; -static jack_latency_range_t latest_left_latency_range, latest_right_latency_range; +static jack_latency_range_t latest_latency_range[NPORTS]; static int64_t time_of_latest_transfer; @@ -77,24 +79,23 @@ static inline jack_default_audio_sample_t sample_conv(short sample) { } static void deinterleave_and_convert(const char *interleaved_frames, - jack_default_audio_sample_t * const jack_buffer_left, - jack_default_audio_sample_t * const jack_buffer_right, + jack_default_audio_sample_t* jack_buffer[], + jack_nframes_t offset, jack_nframes_t nframes) { - jack_nframes_t i; + jack_nframes_t f; short *ifp = (short *)interleaved_frames; // we're dealing with 16bit audio here - jack_default_audio_sample_t *fpl = jack_buffer_left; - jack_default_audio_sample_t *fpr = jack_buffer_right; - for (i=0; i 0) { - left_buffer[frames_written] = 0.0; - right_buffer[frames_written] = 0.0; + for (int i=0; i < NPORTS; i++) { + buffer[i][frames_written] = 0.0; + } frames_written++; nframes--; } @@ -132,14 +134,16 @@ static int process(jack_nframes_t nframes, __attribute__((unused)) void *arg) { } static int graph(__attribute__((unused)) void * arg) { - jack_port_get_latency_range(left_port, JackPlaybackLatency, &latest_left_latency_range); - jack_port_get_latency_range(right_port, JackPlaybackLatency, &latest_right_latency_range); - jack_latency = (latest_left_latency_range.max + latest_right_latency_range.max) / 2; - debug(1, "JACK graph reorder callback called. Current latencies to terminal downstream port:\n" - "\tLmin = %d, Lmax = %d, Rmin = %d, Rmax = %d; jack base latency = %d", - latest_left_latency_range.min, latest_left_latency_range.max, - latest_right_latency_range.min, latest_right_latency_range.max, - jack_latency); + int latency = 0; + debug(1, "JACK graph reorder callback called. Current latencies to terminal downstream port:"); + for (int i=0; i