Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
e70dd869
Unverified
Commit
e70dd869
authored
Nov 29, 2022
by
Wolle
Committed by
GitHub
Nov 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new stream detection
parent
7aafbe24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
39 deletions
+41
-39
src/Audio.cpp
src/Audio.cpp
+39
-36
src/Audio.h
src/Audio.h
+2
-3
No files found.
src/Audio.cpp
View file @
e70dd869
...
...
@@ -3,8 +3,8 @@
*
* Created on: Oct 26.2018
*
* Version 2.0.7
a
* Updated on: Nov 2
4
.2022
* Version 2.0.7
b
* Updated on: Nov 2
8
.2022
* Author: Wolle (schreibfaul1)
*
*/
...
...
@@ -432,7 +432,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
if
(
startsWith
(
l_host
,
"https"
))
m_f_ssl
=
true
;
else
m_f_ssl
=
false
;
// optional basic authorization
// optional basic authorization
uint16_t
auth
=
strlen
(
user
)
+
strlen
(
pwd
);
char
authorization
[
base64_encode_expected_len
(
auth
+
1
)
+
1
];
authorization
[
0
]
=
'\0'
;
...
...
@@ -2775,12 +2775,11 @@ void Audio::processLocalFile() {
static
uint8_t
cnt
=
0
;
uint8_t
compression
;
if
(
m_codec
==
CODEC_WAV
)
compression
=
1
;
else
if
(
m_codec
==
CODEC_FLAC
)
compression
=
2
;
if
(
m_codec
==
CODEC_FLAC
)
compression
=
2
;
else
compression
=
3
;
cnt
++
;
if
(
cnt
==
compression
){
playAudioData
();
cnt
=
0
;}
}
return
;
}
//----------------------------------------------------------------------------------------------------------------------
void
Audio
::
processWebStream
()
{
...
...
@@ -2812,8 +2811,10 @@ void Audio::processWebStream() {
availableBytes
=
min
(
availableBytes
,
m_metacount
);
}
slowStreamDetection
(
InBuff
.
bufferFilled
(),
maxFrameSize
);
if
(
f_stream
)
lostStreamDetection
(
availableBytes
);
// if the buffer is often almost empty issue a warning - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
f_stream
){
if
(
streamDetection
(
availableBytes
))
return
;
}
// buffer fill routine - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
availableBytes
)
{
...
...
@@ -2836,8 +2837,12 @@ void Audio::processWebStream() {
// play audio data - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
f_stream
){
static
uint8_t
cnt
=
0
;
uint8_t
compression
;
if
(
m_codec
==
CODEC_WAV
)
compression
=
1
;
if
(
m_codec
==
CODEC_FLAC
)
compression
=
2
;
else
compression
=
3
;
cnt
++
;
if
(
cnt
==
3
){
playAudioData
();
cnt
=
0
;}
if
(
cnt
==
compression
){
playAudioData
();
cnt
=
0
;}
}
}
//---------------------------------------------------------------------------------------------------------------------
...
...
@@ -2872,9 +2877,9 @@ void Audio::processWebFile() {
if
(
m_f_tts
)
m_contentlength
=
chunkSize
;
}
// if the buffer is often almost empty issue a warning - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// if the buffer is often almost empty issue a warning
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
!
f_webFileDataComplete
&&
f_stream
){
slowStreamDetection
(
InBuff
.
bufferFilled
(),
maxFrameSize
)
;
if
(
streamDetection
(
availableBytes
))
return
;
}
availableBytes
=
min
(
InBuff
.
writeSpace
(),
availableBytes
);
...
...
@@ -2934,7 +2939,7 @@ void Audio::processWebFile() {
uint8_t
compression
;
if
(
m_codec
==
CODEC_WAV
)
compression
=
1
;
if
(
m_codec
==
CODEC_FLAC
)
compression
=
2
;
else
compression
=
6
;
else
compression
=
3
;
cnt
++
;
if
(
cnt
==
compression
){
playAudioData
();
cnt
=
0
;}
}
...
...
@@ -4879,36 +4884,34 @@ bool Audio::readID3V1Tag(){
// [2] https://en.wikipedia.org/wiki/ID3#ID3v1_and_ID3v1.1[5]
}
//----------------------------------------------------------------------------------------------------------------------
void
Audio
::
slowStreamDetection
(
uint32_t
inBuffFilled
,
uint32_t
maxFrameSize
){
static
uint32_t
tmr_
1s
=
millis
();
// timer 1 sec
static
bool
f_tmr_1s
=
false
;
boolean
Audio
::
streamDetection
(
uint32_t
bytesAvail
){
static
uint32_t
tmr_
slow
=
millis
();
static
uint32_t
tmr_lost
=
millis
()
;
static
uint8_t
cnt_slow
=
0
;
if
(
tmr_1s
+
1000
<
millis
())
{
f_tmr_1s
=
true
;
tmr_1s
=
millis
()
+
1000
;}
if
(
m_codec
==
CODEC_WAV
)
maxFrameSize
/=
4
;
if
(
m_codec
==
CODEC_FLAC
)
maxFrameSize
/=
2
;
if
(
inBuffFilled
<
maxFrameSize
){
cnt_slow
++
;
if
(
f_tmr_1s
)
{
if
(
cnt_slow
>
50
)
AUDIO_INFO
(
"slow stream, dropouts are possible"
);
f_tmr_1s
=
false
;
cnt_slow
=
0
;
}
}
else
cnt_slow
=
0
;
}
//----------------------------------------------------------------------------------------------------------------------
void
Audio
::
lostStreamDetection
(
uint32_t
bytesAvail
){
static
uint32_t
loopCnt
=
0
;
if
(
!
bytesAvail
){
loopCnt
++
;
if
(
loopCnt
>
200000
)
{
// wait several seconds
loopCnt
=
0
;
static
uint8_t
cnt_lost
=
0
;
// if within one second the content of the audio buffer falls below the size of an audio frame 50 times,
// issue a message
if
(
tmr_slow
+
1000
<
millis
()){
tmr_slow
=
millis
();
if
(
cnt_slow
>
50
)
AUDIO_INFO
(
"slow stream, dropouts are possible"
);
cnt_slow
=
0
;
}
if
(
InBuff
.
bufferFilled
()
<
InBuff
.
getMaxBlockSize
())
cnt_slow
++
;
// if no audio data is received within three seconds, a new connection attempt is started.
if
(
bytesAvail
)
{
tmr_lost
=
millis
()
+
1000
;
cnt_lost
=
0
;}
if
(
tmr_lost
<
millis
()){
// 3s no data?
cnt_lost
++
;
tmr_lost
=
millis
()
+
1000
;
if
(
cnt_lost
==
3
){
cnt_lost
=
0
;
AUDIO_INFO
(
"Stream lost -> try new connection"
);
connecttohost
(
m_lastHost
);
return
;
return
true
;
}
}
else
loopCnt
=
0
;
return
false
;
}
//----------------------------------------------------------------------------------------------------------------------
void
Audio
::
seek_m4a_stsz
(){
...
...
src/Audio.h
View file @
e70dd869
...
...
@@ -2,7 +2,7 @@
* Audio.h
*
* Created on: Oct 28,2018
* Updated on: Nov 2
4
,2022
* Updated on: Nov 2
8
,2022
* Author: Wolle (schreibfaul1)
*/
...
...
@@ -272,8 +272,7 @@ private:
uint16_t
readMetadata
(
uint16_t
b
,
bool
first
=
false
);
size_t
chunkedDataTransfer
(
uint8_t
*
bytes
);
bool
readID3V1Tag
();
void
slowStreamDetection
(
uint32_t
inBuffFilled
,
uint32_t
maxFrameSize
);
void
lostStreamDetection
(
uint32_t
bytesAvail
);
boolean
streamDetection
(
uint32_t
bytesAvail
);
void
seek_m4a_stsz
();
uint32_t
m4a_correctResumeFilePos
(
uint32_t
resumeFilePos
);
uint32_t
flac_correctResumeFilePos
(
uint32_t
resumeFilePos
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment