diff --git a/components/squeezelite/output.c b/components/squeezelite/output.c index f41a032b..6f91da88 100644 --- a/components/squeezelite/output.c +++ b/components/squeezelite/output.c @@ -253,6 +253,9 @@ frames_t _output_frames(frames_t avail) { } out_frames = !silence ? min(size, cont_frames) : size; + + if (output.channels & 0x01) gainR = MONO_MUTED; + else if (output.channels & 0x02) gainL = MONO_MUTED; wrote = output.write_cb(out_frames, silence, gainL, gainR, cross_gain_in, cross_gain_out, &cross_ptr); diff --git a/components/squeezelite/output_bt.c b/components/squeezelite/output_bt.c index af629a4f..6bb223ac 100644 --- a/components/squeezelite/output_bt.c +++ b/components/squeezelite/output_bt.c @@ -90,9 +90,7 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g _apply_cross(outputbuf, out_frames, cross_gain_in, cross_gain_out, cross_ptr); } - if (gainL != FIXED_ONE || gainR!= FIXED_ONE) { - _apply_gain(outputbuf, out_frames, gainL, gainR); - } + _apply_gain(outputbuf, out_frames, gainL, gainR); #if BYTES_PER_FRAME == 4 memcpy(btout + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME); diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 1bb80bf8..a30ed983 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -410,10 +410,7 @@ static int _i2s_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32 } #if BYTES_PER_FRAME == 4 - if (gainL != FIXED_ONE || gainR!= FIXED_ONE) { - _apply_gain(outputbuf, out_frames, gainL, gainR); - } - + _apply_gain(outputbuf, out_frames, gainL, gainR); memcpy(obuf + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME); #else optr = (s32_t*) outputbuf->readp; diff --git a/components/squeezelite/output_pack.c b/components/squeezelite/output_pack.c index e2bfc798..b57b4856 100644 --- a/components/squeezelite/output_pack.c +++ b/components/squeezelite/output_pack.c @@ -356,17 +356,34 @@ void _apply_cross(struct buffer *outputbuf, frames_t out_frames, s32_t cross_gai } } + + #if !WIN inline #endif void _apply_gain(struct buffer *outputbuf, frames_t count, s32_t gainL, s32_t gainR) { - ISAMPLE_T *ptrL = (ISAMPLE_T *)(void *)outputbuf->readp; - ISAMPLE_T *ptrR = (ISAMPLE_T *)(void *)outputbuf->readp + 1; - while (count--) { - *ptrL = gain(gainL, *ptrL); - *ptrR = gain(gainR, *ptrR); - ptrL += 2; - ptrR += 2; - } + if (gainL == FIXED_ONE && gainR == FIXED_ONE) { + return; + } else if (gainL == MONO_MUTED) { + ISAMPLE_T *ptr = (ISAMPLE_T *)(void *)outputbuf->readp + 1; + while (count--) { + *(ptr - 1) = *ptr = gain(gainR, *ptr); + ptr += 2; + } + } else if (gainR == MONO_MUTED) { + ISAMPLE_T *ptr = (ISAMPLE_T *)(void *)outputbuf->readp; + while (count--) { + *(ptr + 1) = *ptr = gain(gainL, *ptr); + ptr += 2; + } + } else { + ISAMPLE_T *ptrL = (ISAMPLE_T *)(void *)outputbuf->readp; + ISAMPLE_T *ptrR = (ISAMPLE_T *)(void *)outputbuf->readp + 1; + while (count--) { + *ptrL = gain(gainL, *ptrL); + *ptrR = gain(gainR, *ptrR); + ptrL += 2; ptrR += 2; + } + } } diff --git a/components/squeezelite/slimproto.c b/components/squeezelite/slimproto.c index 59f79d53..902d71b2 100644 --- a/components/squeezelite/slimproto.c +++ b/components/squeezelite/slimproto.c @@ -397,8 +397,9 @@ static void process_strm(u8_t *pkt, int len) { output.next_replay_gain = unpackN(&strm->replay_gain); output.fade_mode = strm->transition_type - '0'; output.fade_secs = strm->transition_period; - output.invert = (strm->flags & 0x03) == 0x03; - LOG_DEBUG("set fade mode: %u", output.fade_mode); + output.invert = (strm->flags & 0x03) == 0x03; + output.channels = (strm->flags & 0x0c) >> 2; + LOG_DEBUG("set fade: %u, channels: %u, invert: %u", output.fade_mode, output.channels, output.invert); UNLOCK_O; } break; diff --git a/components/squeezelite/squeezelite.h b/components/squeezelite/squeezelite.h index 2831a80f..1abee452 100644 --- a/components/squeezelite/squeezelite.h +++ b/components/squeezelite/squeezelite.h @@ -471,7 +471,8 @@ void _wake_create(event_event*); #define MAX_SILENCE_FRAMES 2048 -#define FIXED_ONE 0x10000 +#define FIXED_ONE 0x10000 +#define MONO_MUTED (FIXED_ONE + 1) #ifndef BYTES_PER_FRAME #define BYTES_PER_FRAME 8 @@ -660,6 +661,7 @@ typedef enum { FADE_NONE = 0, FADE_CROSSFADE, FADE_IN, FADE_OUT, FADE_INOUT } fa struct outputstate { output_state state; output_format format; + u8_t channels; const char *device; int external; u32_t init_size; diff --git a/components/squeezelite/stream.c b/components/squeezelite/stream.c index 6573e895..51691142 100644 --- a/components/squeezelite/stream.c +++ b/components/squeezelite/stream.c @@ -521,19 +521,16 @@ void stream_sock(u32_t ip, u16_t port, const char *header, size_t header_len, un #if USE_SSL if (ntohs(port) == 443) { - char *server = strcasestr(header, "Host:"); + char server[256], *p; ssl = SSL_new(SSLctx); SSL_set_fd(ssl, sock); // add SNI + sscanf(header, "Host:%255s", server); if (server) { - char *p, *servername = malloc(1024); - - sscanf(server, "Host:%255[^:]s", servername); - for (p = servername; *p == ' '; p++); - SSL_set_tlsext_host_name(ssl, p); - free(servername); + if ((p = strchr(server, ':')) != NULL) *p = '\0'; + SSL_set_tlsext_host_name(ssl, server); } while (1) {