2
0
Эх сурвалжийг харах

add mono channel option - release

Philippe G 4 жил өмнө
parent
commit
369a9cb9bc

+ 3 - 0
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);
 

+ 1 - 3
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);

+ 1 - 4
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;	

+ 25 - 8
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;
+		}
+   }	
 }
 

+ 3 - 2
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;

+ 3 - 1
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;

+ 4 - 7
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) {