From 93568723fdf80294a0c36b08c4570f39334cb6fd Mon Sep 17 00:00:00 2001 From: philippe44 Date: Sat, 24 Aug 2019 01:15:46 -0700 Subject: [PATCH] backport click correction to BT --- components/raop/rtp.c | 2 +- components/squeezelite/output_bt.c | 10 ++++++---- components/squeezelite/output_i2s.c | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/raop/rtp.c b/components/raop/rtp.c index b97c3b62..da97f59c 100644 --- a/components/raop/rtp.c +++ b/components/raop/rtp.c @@ -375,7 +375,7 @@ static void alac_decode(rtp_t *ctx, s16_t *dest, char *buf, int len, int *outsiz unsigned char iv[16]; int aeslen; assert(len<=MAX_PACKET); - + if (ctx->decrypt) { aeslen = len & ~0xf; memcpy(iv, ctx->aesiv, sizeof(iv)); diff --git a/components/squeezelite/output_bt.c b/components/squeezelite/output_bt.c index 90678e98..15101d76 100644 --- a/components/squeezelite/output_bt.c +++ b/components/squeezelite/output_bt.c @@ -43,7 +43,8 @@ extern u8_t config_spdif_gpio; static log_level loglevel; static bool running = false; -uint8_t * btout; +static uint8_t *btout; +static frames_t oframes; static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr); @@ -101,12 +102,12 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g } #if BYTES_PER_FRAME == 4 - memcpy(btout, outputbuf->readp, out_frames * BYTES_PER_FRAME); + memcpy(btout + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME); #else { frames_t count = out_frames; s32_t *_iptr = (s32_t*) outputbuf->readp; - s16_t *_optr = (s16_t*) bt_optr; + s16_t *_optr = (s16_t*) (btout + oframes * BYTES_PER_FRAME); while (count--) { *_optr++ = *_iptr++ >> 16; *_optr++ = *_iptr++ >> 16; @@ -117,7 +118,7 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g } else { u8_t *buf = silencebuf; - memcpy(btout, buf, out_frames * BYTES_PER_FRAME); + memcpy(btout + oframes * BYTES_PER_FRAME, buf, out_frames * BYTES_PER_FRAME); } return (int)out_frames; @@ -131,6 +132,7 @@ int32_t output_bt_data(uint8_t *data, int32_t len) { } btout = data; + oframes = 0; // This is how the BTC layer calculates the number of bytes to // for us to send. (BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16) - availPcmBytes diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index fbfd27c9..e4b8ed20 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -457,6 +457,7 @@ static void *output_thread_i2s() { synced = false; } + oframes = 0; output.updated = gettime_ms(); output.frames_played_dmp = output.frames_played; // try to estimate how much we have consumed from the DMA buffer (calculation is incorrect at the very beginning ...) @@ -479,7 +480,6 @@ static void *output_thread_i2s() { } else if (discard) { discard -= oframes; iframes = discard ? min(FRAME_BLOCK, discard) : FRAME_BLOCK; - oframes = 0; UNLOCK; continue; } @@ -527,8 +527,6 @@ static void *output_thread_i2s() { LOG_WARN("I2S DMA Overflow! available bytes: %d, I2S wrote %d bytes", oframes * bytes_per_frame, bytes); } - oframes = 0; - SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time); }