Quellcode durchsuchen

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
philippe44 vor 5 Jahren
Ursprung
Commit
70ef69971f

BIN
components/codecs/lib/libalac.a


BIN
components/codecs/lib/libfaad.a


BIN
components/codecs/lib/libmad.a


BIN
components/codecs/lib/libogg.a


BIN
components/codecs/lib/libvorbisidec.a


+ 1 - 1
main/component.mk

@@ -2,7 +2,7 @@
 # "main" pseudo-component makefile.
 #
 # (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/mad 	\
 	-I$(COMPONENT_PATH)/../components/codecs/inc/faad2	\

+ 2 - 2
main/decode.c

@@ -59,7 +59,7 @@ static void *decode_thread() {
 		size_t bytes, space, min_space;
 		bool toend;
 		bool ran = false;
-
+		
 		LOCK_S;
 		bytes = _buf_used(streambuf);
 		toend = (stream.state <= DISCONNECT);
@@ -69,7 +69,7 @@ static void *decode_thread() {
 		UNLOCK_O;
 
 		LOCK_D;
-
+		
 		if (decode.state == DECODE_RUNNING && codec) {
 		
 			LOG_SDEBUG("streambuf bytes: %u outputbuf space: %u", bytes, space);

+ 1 - 2
main/esp_app_main.c

@@ -133,11 +133,10 @@ void app_main()
 		"-d",
 		"output=" CONFIG_LOGGING_OUTPUT,
 		"-b",
-		"256:2000"
+		"500:2000"
 
 	};
 
-
 	// can't do strtok on FLASH strings
 	argv = malloc(sizeof(_argv));
 	for (i = 0; i < sizeof(_argv)/sizeof(char*); i++) {

+ 14 - 2
main/output_bt.c

@@ -496,6 +496,8 @@ static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
 {
 	frames_t frames;
 	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) {
         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.updated = gettime_ms();
    	output.frames_played_dmp = output.frames_played;
-	if (!output.threshold) output.threshold = 20;
+	if (output.threshold < 20) output.threshold = 20;
 
 	optr = data;
   	frames = _output_frames(frames);
 	
 	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)) {
-		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;

+ 1 - 1
main/slimproto.c

@@ -274,7 +274,7 @@ static void process_strm(u8_t *pkt, int len) {
 	struct strm_packet *strm = (struct strm_packet *)pkt;
 
 	LOG_DEBUG("strm command %c", strm->command);
-
+	
 	switch(strm->command) {
 	case 't':
 		sendSTAT("STMt", strm->replay_gain); // STMt replay_gain is no longer used to track latency, but support it

+ 1 - 1
main/stream.c

@@ -159,7 +159,7 @@ static void *stream_thread() {
 
 		if (fd < 0 || !space || stream.state <= STREAMING_WAIT) {
 			UNLOCK;
-			usleep(100000);
+			usleep(space ? 100000 : 25000);
 			continue;
 		}
 

+ 21 - 34
main/vorbis.c

@@ -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) {
 	size_t bytes;
 
+	LOCK_S;
+	
 	bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
 	bytes = min(bytes, size * nmemb);
 
 	memcpy(ptr, streambuf->readp, bytes);
 	_buf_inc_readp(streambuf, bytes);
-
+	
+	UNLOCK_S;
+	
 	return bytes / size;
 }
 
@@ -115,28 +119,19 @@ static long _tell_cb(void *datasource) { return 0; }
 
 static decode_state vorbis_decode(void) {
 	static int channels;
-	bool end;
 	frames_t frames;
 	int bytes, s, n;
 	u8_t *write_buf;
 
 	LOCK_S;
-	LOCK_O_direct;
-	end = (stream.state <= DISCONNECT);
-
-	IF_DIRECT(
-		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;
+	
+	if (stream.state <= DISCONNECT && !_buf_used(streambuf)) {
 		UNLOCK_S;
 		return DECODE_COMPLETE;
 	}
-
+	
+	UNLOCK_S;
+	
 	if (decode.new_stream) {
 		ov_callbacks cbs;
 		int err;
@@ -152,45 +147,41 @@ static decode_state vorbis_decode(void) {
 
 		if ((err = OV(v, open_callbacks, streambuf, v->vf, NULL, 0, cbs)) < 0) {
 			LOG_WARN("open_callbacks error: %d", err);
-			UNLOCK_O_direct;
-			UNLOCK_S;
 			return DECODE_COMPLETE;
 		}
+		
 		v->opened = true;
-
 		info = OV(v, info, v->vf, -1);
 				
 		LOG_INFO("setting track_start");
-		LOCK_O_not_direct;
+		LOCK_O;
 		output.next_sample_rate = decode_newstream(info->rate, output.supported_rates); 
 		IF_DSD(	output.next_fmt = PCM; )
 		output.track_start = outputbuf->writep;
 		if (output.fade_mode) _checkfade(true);
 		decode.new_stream = false;
-		UNLOCK_O_not_direct;
-
-		IF_PROCESS(
-			frames = process.max_in_frames;
-		);
+		UNLOCK_O;
 
 		channels = info->channels;
 
 		if (channels > 2) {
 			LOG_WARN("too many channels: %d", channels);
-			UNLOCK_O_direct;
-			UNLOCK_S;
 			return DECODE_ERROR;
 		}
 	}
-
-	bytes = frames * 2 * channels; // samples returned are 16 bits
-
+	
+	LOCK_O_direct;
+	
 	IF_DIRECT(
+		frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
 		write_buf = outputbuf->writep;
 	);
 	IF_PROCESS(
+		frames = process.max_in_frames;
 		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
 #ifdef TREMOR_ONLY	
@@ -208,9 +199,8 @@ static decode_state vorbis_decode(void) {
 #endif
 	}
 #endif	
-	
+		
 	if (n > 0) {
-
 		frames_t count;
 		s16_t *iptr;
 		ISAMPLE_T *optr;
@@ -249,7 +239,6 @@ static decode_state vorbis_decode(void) {
 
 		LOG_INFO("end of stream");
 		UNLOCK_O_direct;
-		UNLOCK_S;
 		return DECODE_COMPLETE;
 
 	} else if (n == OV_HOLE) {
@@ -261,12 +250,10 @@ static decode_state vorbis_decode(void) {
 
 		LOG_INFO("ov_read error: %d", n);
 		UNLOCK_O_direct;
-		UNLOCK_S;
 		return DECODE_COMPLETE;
 	}
 
 	UNLOCK_O_direct;
-	UNLOCK_S;
 
 	return DECODE_RUNNING;
 }

+ 7 - 2
sdkconfig.defaults

@@ -1,4 +1,10 @@
 # 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
 CONFIG_BT_ENABLED=y
 CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=
@@ -11,7 +17,6 @@ CONFIG_BT_SPP_ENABLED=n
 CONFIG_GATTS_ENABLE=n
 CONFIG_GATTC_ENABLE=n
 CONFIG_BLE_SMP_ENABLE=n
-SW_COEXIST_PREFERENCE_BALANCE=y
 #enable SPIRAM
 CONFIG_SPIRAM_SUPPORT=y
 CONFIG_SPIRAM_BOOT_INIT=y
@@ -33,7 +38,7 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
 CONFIG_PARTITION_TABLE_OFFSET=0x8000
 CONFIG_PARTITION_TABLE_MD5=y
 # 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_0=
 CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1=y