add mono channel option - release

This commit is contained in:
Philippe G
2021-02-06 18:02:33 -08:00
parent b9deead084
commit 369a9cb9bc
7 changed files with 40 additions and 25 deletions

View File

@@ -254,6 +254,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);
if (wrote <= 0) {

View File

@@ -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);
}
#if BYTES_PER_FRAME == 4
memcpy(btout + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME);

View File

@@ -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);
}
memcpy(obuf + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME);
#else
optr = (s32_t*) outputbuf->readp;

View File

@@ -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) {
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;
ptrL += 2; ptrR += 2;
}
}
}

View File

@@ -398,7 +398,8 @@ static void process_strm(u8_t *pkt, int len) {
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.channels = (strm->flags & 0x0c) >> 2;
LOG_DEBUG("set fade: %u, channels: %u, invert: %u", output.fade_mode, output.channels, output.invert);
UNLOCK_O;
}
break;

View File

@@ -472,6 +472,7 @@ void _wake_create(event_event*);
#define MAX_SILENCE_FRAMES 2048
#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;

View File

@@ -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) {