backport click correction to BT

This commit is contained in:
philippe44
2019-08-24 01:15:46 -07:00
parent 35ccb92a60
commit 93568723fd
3 changed files with 8 additions and 8 deletions

View File

@@ -43,7 +43,8 @@ extern u8_t config_spdif_gpio;
static log_level loglevel; static log_level loglevel;
static bool running = false; 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, 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); 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 #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 #else
{ {
frames_t count = out_frames; frames_t count = out_frames;
s32_t *_iptr = (s32_t*) outputbuf->readp; 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--) { while (count--) {
*_optr++ = *_iptr++ >> 16; *_optr++ = *_iptr++ >> 16;
*_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 { } else {
u8_t *buf = silencebuf; 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; return (int)out_frames;
@@ -131,6 +132,7 @@ int32_t output_bt_data(uint8_t *data, int32_t len) {
} }
btout = data; btout = data;
oframes = 0;
// This is how the BTC layer calculates the number of bytes to // 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 // for us to send. (BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16) - availPcmBytes

View File

@@ -457,6 +457,7 @@ static void *output_thread_i2s() {
synced = false; synced = false;
} }
oframes = 0;
output.updated = gettime_ms(); output.updated = gettime_ms();
output.frames_played_dmp = output.frames_played; 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 ...) // 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) { } else if (discard) {
discard -= oframes; discard -= oframes;
iframes = discard ? min(FRAME_BLOCK, discard) : FRAME_BLOCK; iframes = discard ? min(FRAME_BLOCK, discard) : FRAME_BLOCK;
oframes = 0;
UNLOCK; UNLOCK;
continue; 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); 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); SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time);
} }