mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
Stabilization
move vorbis allocation to SPIRAM tweak defconfigs improve data reception wav,flac,mp3 work fine but BT seems to lose connection from time to time
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@
|
|||||||
# "main" pseudo-component makefile.
|
# "main" pseudo-component makefile.
|
||||||
#
|
#
|
||||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||||
CFLAGS += -DPOSIX -DLINKALL -DLOOPBACK -DDACAUDIO -DTREMOR_ONLY -DBYTES_PER_FRAME=4 \
|
CFLAGS += -O3 -DPOSIX -DLINKALL -DLOOPBACK -DDACAUDIO -DTREMOR_ONLY -DBYTES_PER_FRAME=4 \
|
||||||
-I$(COMPONENT_PATH)/../components/codecs/inc \
|
-I$(COMPONENT_PATH)/../components/codecs/inc \
|
||||||
-I$(COMPONENT_PATH)/../components/codecs/inc/mad \
|
-I$(COMPONENT_PATH)/../components/codecs/inc/mad \
|
||||||
-I$(COMPONENT_PATH)/../components/codecs/inc/faad2 \
|
-I$(COMPONENT_PATH)/../components/codecs/inc/faad2 \
|
||||||
|
|||||||
@@ -133,11 +133,10 @@ void app_main()
|
|||||||
"-d",
|
"-d",
|
||||||
"output=" CONFIG_LOGGING_OUTPUT,
|
"output=" CONFIG_LOGGING_OUTPUT,
|
||||||
"-b",
|
"-b",
|
||||||
"256:2000"
|
"500:2000"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// can't do strtok on FLASH strings
|
// can't do strtok on FLASH strings
|
||||||
argv = malloc(sizeof(_argv));
|
argv = malloc(sizeof(_argv));
|
||||||
for (i = 0; i < sizeof(_argv)/sizeof(char*); i++) {
|
for (i = 0; i < sizeof(_argv)/sizeof(char*); i++) {
|
||||||
|
|||||||
@@ -496,6 +496,8 @@ static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
|
|||||||
{
|
{
|
||||||
frames_t frames;
|
frames_t frames;
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
|
static unsigned min_o = -1, max_o = 0, min_s = -1, max_s = 0;
|
||||||
|
unsigned o, s;
|
||||||
|
|
||||||
if (len < 0 || data == NULL) {
|
if (len < 0 || data == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -517,15 +519,25 @@ static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
|
|||||||
output.device_frames = 0;
|
output.device_frames = 0;
|
||||||
output.updated = gettime_ms();
|
output.updated = gettime_ms();
|
||||||
output.frames_played_dmp = output.frames_played;
|
output.frames_played_dmp = output.frames_played;
|
||||||
if (!output.threshold) output.threshold = 20;
|
if (output.threshold < 20) output.threshold = 20;
|
||||||
|
|
||||||
optr = data;
|
optr = data;
|
||||||
frames = _output_frames(frames);
|
frames = _output_frames(frames);
|
||||||
|
|
||||||
UNLOCK;
|
UNLOCK;
|
||||||
|
|
||||||
|
o = _buf_used(outputbuf);
|
||||||
|
if (o < min_o) min_o = o;
|
||||||
|
if (o > max_o) max_o = o;
|
||||||
|
|
||||||
|
s = _buf_used(streambuf);
|
||||||
|
if (s < min_s) min_s = s;
|
||||||
|
if (s > max_s) max_s = s;
|
||||||
|
|
||||||
if (!(count++ & 0x1ff)) {
|
if (!(count++ & 0x1ff)) {
|
||||||
LOG_INFO("frames %d (count:%d) (out:%d, stream:%d)", frames, count, _buf_used(outputbuf), _buf_used(streambuf));
|
LOG_INFO("frames %d (count:%d) (out:%d/%d/%d, stream:%d/%d/%d)", frames, count, max_o, min_o, o, max_s, min_s, s);
|
||||||
|
min_o = min_s = -1;
|
||||||
|
max_o = max_s = -0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames * 4;
|
return frames * 4;
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ static void *stream_thread() {
|
|||||||
|
|
||||||
if (fd < 0 || !space || stream.state <= STREAMING_WAIT) {
|
if (fd < 0 || !space || stream.state <= STREAMING_WAIT) {
|
||||||
UNLOCK;
|
UNLOCK;
|
||||||
usleep(100000);
|
usleep(space ? 100000 : 25000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,12 +99,16 @@ extern int ov_read_tremor(); // needed to enable compilation, not linked
|
|||||||
static size_t _read_cb(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
static size_t _read_cb(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
|
|
||||||
|
LOCK_S;
|
||||||
|
|
||||||
bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
|
||||||
bytes = min(bytes, size * nmemb);
|
bytes = min(bytes, size * nmemb);
|
||||||
|
|
||||||
memcpy(ptr, streambuf->readp, bytes);
|
memcpy(ptr, streambuf->readp, bytes);
|
||||||
_buf_inc_readp(streambuf, bytes);
|
_buf_inc_readp(streambuf, bytes);
|
||||||
|
|
||||||
|
UNLOCK_S;
|
||||||
|
|
||||||
return bytes / size;
|
return bytes / size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,28 +119,19 @@ static long _tell_cb(void *datasource) { return 0; }
|
|||||||
|
|
||||||
static decode_state vorbis_decode(void) {
|
static decode_state vorbis_decode(void) {
|
||||||
static int channels;
|
static int channels;
|
||||||
bool end;
|
|
||||||
frames_t frames;
|
frames_t frames;
|
||||||
int bytes, s, n;
|
int bytes, s, n;
|
||||||
u8_t *write_buf;
|
u8_t *write_buf;
|
||||||
|
|
||||||
LOCK_S;
|
LOCK_S;
|
||||||
LOCK_O_direct;
|
|
||||||
end = (stream.state <= DISCONNECT);
|
|
||||||
|
|
||||||
IF_DIRECT(
|
if (stream.state <= DISCONNECT && !_buf_used(streambuf)) {
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
|
||||||
);
|
|
||||||
IF_PROCESS(
|
|
||||||
frames = process.max_in_frames;
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!frames && end) {
|
|
||||||
UNLOCK_O_direct;
|
|
||||||
UNLOCK_S;
|
UNLOCK_S;
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNLOCK_S;
|
||||||
|
|
||||||
if (decode.new_stream) {
|
if (decode.new_stream) {
|
||||||
ov_callbacks cbs;
|
ov_callbacks cbs;
|
||||||
int err;
|
int err;
|
||||||
@@ -152,46 +147,42 @@ static decode_state vorbis_decode(void) {
|
|||||||
|
|
||||||
if ((err = OV(v, open_callbacks, streambuf, v->vf, NULL, 0, cbs)) < 0) {
|
if ((err = OV(v, open_callbacks, streambuf, v->vf, NULL, 0, cbs)) < 0) {
|
||||||
LOG_WARN("open_callbacks error: %d", err);
|
LOG_WARN("open_callbacks error: %d", err);
|
||||||
UNLOCK_O_direct;
|
|
||||||
UNLOCK_S;
|
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
}
|
}
|
||||||
v->opened = true;
|
|
||||||
|
|
||||||
|
v->opened = true;
|
||||||
info = OV(v, info, v->vf, -1);
|
info = OV(v, info, v->vf, -1);
|
||||||
|
|
||||||
LOG_INFO("setting track_start");
|
LOG_INFO("setting track_start");
|
||||||
LOCK_O_not_direct;
|
LOCK_O;
|
||||||
output.next_sample_rate = decode_newstream(info->rate, output.supported_rates);
|
output.next_sample_rate = decode_newstream(info->rate, output.supported_rates);
|
||||||
IF_DSD( output.next_fmt = PCM; )
|
IF_DSD( output.next_fmt = PCM; )
|
||||||
output.track_start = outputbuf->writep;
|
output.track_start = outputbuf->writep;
|
||||||
if (output.fade_mode) _checkfade(true);
|
if (output.fade_mode) _checkfade(true);
|
||||||
decode.new_stream = false;
|
decode.new_stream = false;
|
||||||
UNLOCK_O_not_direct;
|
UNLOCK_O;
|
||||||
|
|
||||||
IF_PROCESS(
|
|
||||||
frames = process.max_in_frames;
|
|
||||||
);
|
|
||||||
|
|
||||||
channels = info->channels;
|
channels = info->channels;
|
||||||
|
|
||||||
if (channels > 2) {
|
if (channels > 2) {
|
||||||
LOG_WARN("too many channels: %d", channels);
|
LOG_WARN("too many channels: %d", channels);
|
||||||
UNLOCK_O_direct;
|
|
||||||
UNLOCK_S;
|
|
||||||
return DECODE_ERROR;
|
return DECODE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = frames * 2 * channels; // samples returned are 16 bits
|
LOCK_O_direct;
|
||||||
|
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
write_buf = outputbuf->writep;
|
write_buf = outputbuf->writep;
|
||||||
);
|
);
|
||||||
IF_PROCESS(
|
IF_PROCESS(
|
||||||
|
frames = process.max_in_frames;
|
||||||
write_buf = process.inbuf;
|
write_buf = process.inbuf;
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bytes = frames * 2 * channels; // samples returned are 16 bits
|
||||||
|
|
||||||
// write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them
|
// write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them
|
||||||
#ifdef TREMOR_ONLY
|
#ifdef TREMOR_ONLY
|
||||||
n = OV(v, read, v->vf, (char *)write_buf, bytes, &s);
|
n = OV(v, read, v->vf, (char *)write_buf, bytes, &s);
|
||||||
@@ -210,7 +201,6 @@ static decode_state vorbis_decode(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
|
|
||||||
frames_t count;
|
frames_t count;
|
||||||
s16_t *iptr;
|
s16_t *iptr;
|
||||||
ISAMPLE_T *optr;
|
ISAMPLE_T *optr;
|
||||||
@@ -249,7 +239,6 @@ static decode_state vorbis_decode(void) {
|
|||||||
|
|
||||||
LOG_INFO("end of stream");
|
LOG_INFO("end of stream");
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
UNLOCK_S;
|
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
|
|
||||||
} else if (n == OV_HOLE) {
|
} else if (n == OV_HOLE) {
|
||||||
@@ -261,12 +250,10 @@ static decode_state vorbis_decode(void) {
|
|||||||
|
|
||||||
LOG_INFO("ov_read error: %d", n);
|
LOG_INFO("ov_read error: %d", n);
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
UNLOCK_S;
|
|
||||||
return DECODE_COMPLETE;
|
return DECODE_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNLOCK_O_direct;
|
UNLOCK_O_direct;
|
||||||
UNLOCK_S;
|
|
||||||
|
|
||||||
return DECODE_RUNNING;
|
return DECODE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
# Override some defaults so BT stack is enabled and
|
# Override some defaults so BT stack is enabled and
|
||||||
|
# BT and WiFi balance
|
||||||
|
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=n
|
||||||
|
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=n
|
||||||
|
CONFIG_SW_COEXIST_ENABLE=y
|
||||||
|
CONFIG_SW_COEXIST_PREFERENCE_BALANCE=y
|
||||||
|
CONFIG_SW_COEXIST_PREFERENCE_VALUE=2
|
||||||
# Classic BT is enabled
|
# Classic BT is enabled
|
||||||
CONFIG_BT_ENABLED=y
|
CONFIG_BT_ENABLED=y
|
||||||
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=
|
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=
|
||||||
@@ -11,7 +17,6 @@ CONFIG_BT_SPP_ENABLED=n
|
|||||||
CONFIG_GATTS_ENABLE=n
|
CONFIG_GATTS_ENABLE=n
|
||||||
CONFIG_GATTC_ENABLE=n
|
CONFIG_GATTC_ENABLE=n
|
||||||
CONFIG_BLE_SMP_ENABLE=n
|
CONFIG_BLE_SMP_ENABLE=n
|
||||||
SW_COEXIST_PREFERENCE_BALANCE=y
|
|
||||||
#enable SPIRAM
|
#enable SPIRAM
|
||||||
CONFIG_SPIRAM_SUPPORT=y
|
CONFIG_SPIRAM_SUPPORT=y
|
||||||
CONFIG_SPIRAM_BOOT_INIT=y
|
CONFIG_SPIRAM_BOOT_INIT=y
|
||||||
@@ -33,7 +38,7 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
|||||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||||
CONFIG_PARTITION_TABLE_MD5=y
|
CONFIG_PARTITION_TABLE_MD5=y
|
||||||
# CPU & threads options
|
# CPU & threads options
|
||||||
ESP32_DEFAULT_CPU_FREQ_240=y
|
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||||
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=
|
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=
|
||||||
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0=
|
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0=
|
||||||
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1=y
|
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1=y
|
||||||
|
|||||||
Reference in New Issue
Block a user