mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 12:50:49 +03:00
Merge remote-tracking branch 'origin/master' into master-cmake
Conflicts: README.md components/config/config.c components/driver_bt/bt_app_sink.c components/raop/raop.c components/services/audio_controls.c main/platform_esp32.h
This commit is contained in:
@@ -4,18 +4,8 @@
|
||||
* (c) Sebastien 2019
|
||||
* Philippe G. 2019, philippe_44@outlook.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -44,15 +34,15 @@ static bool enable_bt_sink;
|
||||
static bool enable_airplay;
|
||||
|
||||
#define RAOP_OUTPUT_SIZE (RAOP_SAMPLE_RATE * 2 * 2 * 2 * 1.2)
|
||||
#define SYNC_WIN_RUN 32
|
||||
#define SYNC_WIN_SLOW 32
|
||||
#define SYNC_WIN_CHECK 8
|
||||
#define SYNC_WIN_START 2
|
||||
#define SYNC_WIN_FAST 2
|
||||
|
||||
static raop_event_t raop_state;
|
||||
|
||||
static EXT_RAM_ATTR struct {
|
||||
bool enabled;
|
||||
int sum, count, win, errors[SYNC_WIN_RUN];
|
||||
int sum, count, win, errors[SYNC_WIN_SLOW];
|
||||
s32_t len;
|
||||
u32_t start_time, playtime;
|
||||
} raop_sync;
|
||||
@@ -200,48 +190,31 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
||||
// this is async, so player might have been deleted
|
||||
switch (event) {
|
||||
case RAOP_TIMING: {
|
||||
u32_t ms, now = gettime_ms();
|
||||
int error;
|
||||
|
||||
if (!raop_sync.enabled || output.state < OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
|
||||
|
||||
// first must make sure we started on time
|
||||
if (raop_sync.win == SYNC_WIN_START) {
|
||||
// how many ms have we really played
|
||||
ms = now - output.updated + ((output.frames_played_dmp - output.device_frames) * 10) / (RAOP_SAMPLE_RATE / 100);
|
||||
error = ms - (now - raop_sync.start_time);
|
||||
if (!raop_sync.enabled || output.state != OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
|
||||
|
||||
u32_t ms, now = gettime_ms();
|
||||
u32_t level = _buf_used(outputbuf);
|
||||
int error;
|
||||
|
||||
LOG_INFO("backend played %u, desired %u, (delta:%d)", ms, now - raop_sync.start_time, error);
|
||||
} else {
|
||||
u32_t level = _buf_used(outputbuf);
|
||||
// in how many ms will the most recent block play
|
||||
ms = (((s32_t)(level - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + output.frames_in_process) * 10) / (RAOP_SAMPLE_RATE / 100) - (s32_t) (now - output.updated);
|
||||
|
||||
// in how many ms will the most recent block play
|
||||
ms = (((s32_t)(level - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + output.frames_in_process) * 10) / (RAOP_SAMPLE_RATE / 100) - (s32_t) (now - output.updated);
|
||||
// when outputbuf is empty, it means we have a network black-out or something
|
||||
error = level ? (raop_sync.playtime - now) - ms : 0;
|
||||
|
||||
// when outputbuf is empty, it means we have a network black-out or something
|
||||
error = level ? (raop_sync.playtime - now) - ms : 0;
|
||||
|
||||
if (loglevel == lDEBUG || !level) {
|
||||
LOG_INFO("head local:%d, remote:%d (delta:%d)", ms, raop_sync.playtime - now, error);
|
||||
LOG_INFO("obuf:%u, sync_len:%u, devframes:%u, inproc:%u", _buf_used(outputbuf), raop_sync.len, output.device_frames, output.frames_in_process);
|
||||
}
|
||||
if (loglevel == lDEBUG || !level) {
|
||||
LOG_INFO("head local:%d, remote:%d (delta:%d)", ms, raop_sync.playtime - now, error);
|
||||
LOG_INFO("obuf:%u, sync_len:%u, devframes:%u, inproc:%u", _buf_used(outputbuf), raop_sync.len, output.device_frames, output.frames_in_process);
|
||||
}
|
||||
|
||||
// calculate sum, error and update sliding window
|
||||
raop_sync.errors[raop_sync.count++ % raop_sync.win] = error;
|
||||
raop_sync.sum += error;
|
||||
error = raop_sync.sum / min(raop_sync.count, raop_sync.win);
|
||||
|
||||
// move to normal mode if possible
|
||||
if (raop_sync.win == SYNC_WIN_START && raop_sync.count >= SYNC_WIN_START && abs(error) < 10) {
|
||||
raop_sync.win = SYNC_WIN_RUN;
|
||||
LOG_INFO("switching to slow sync mode %u", raop_sync.win);
|
||||
}
|
||||
|
||||
// wait till e have enough data or there is a strong deviation
|
||||
if ((raop_sync.count >= raop_sync.win && abs(error) > 10) || (raop_sync.count >= SYNC_WIN_CHECK && abs(error) > 100)) {
|
||||
|
||||
// correct if needed
|
||||
// wait till we have enough data or there is a strong deviation
|
||||
if ((raop_sync.count >= raop_sync.win && abs(error) > 10) || (raop_sync.count >= SYNC_WIN_CHECK && abs(error) > 100)) {
|
||||
if (error < 0) {
|
||||
output.skip_frames = -(error * RAOP_SAMPLE_RATE) / 1000;
|
||||
output.state = OUTPUT_SKIP_FRAMES;
|
||||
@@ -251,11 +224,18 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
||||
output.state = OUTPUT_PAUSE_FRAMES;
|
||||
LOG_INFO("pausing for %u frames (count: %d)", output.pause_frames, raop_sync.count);
|
||||
}
|
||||
|
||||
// reset sliding window
|
||||
|
||||
raop_sync.sum = raop_sync.count = 0;
|
||||
memset(raop_sync.errors, 0, sizeof(raop_sync.errors));
|
||||
|
||||
}
|
||||
|
||||
// move to normal mode if possible
|
||||
if (raop_sync.win == 1) {
|
||||
raop_sync.win = SYNC_WIN_FAST;
|
||||
LOG_INFO("backend played %u, desired %u, (delta:%d)", ms, raop_sync.playtime - now, error);
|
||||
} else if (raop_sync.win == SYNC_WIN_FAST && raop_sync.count >= SYNC_WIN_FAST && abs(error) < 10) {
|
||||
raop_sync.win = SYNC_WIN_SLOW;
|
||||
LOG_INFO("switching to slow sync mode %u", raop_sync.win);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -272,8 +252,8 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
||||
case RAOP_STREAM:
|
||||
LOG_INFO("Stream", NULL);
|
||||
raop_state = event;
|
||||
raop_sync.win = SYNC_WIN_START;
|
||||
raop_sync.sum = raop_sync.count = 0 ;
|
||||
raop_sync.win = 1;
|
||||
raop_sync.sum = raop_sync.count = 0;
|
||||
memset(raop_sync.errors, 0, sizeof(raop_sync.errors));
|
||||
raop_sync.enabled = !strcasestr(output.device, "BT");
|
||||
output.next_sample_rate = output.current_sample_rate = RAOP_SAMPLE_RATE;
|
||||
|
||||
Reference in New Issue
Block a user