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
1a7a8081
Unverified
Commit
1a7a8081
authored
Nov 29, 2023
by
Wolle
Committed by
GitHub
Nov 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jump faster over ID3 blocks
parent
9d1759e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
26 deletions
+34
-26
src/Audio.cpp
src/Audio.cpp
+31
-24
src/Audio.h
src/Audio.h
+3
-2
No files found.
src/Audio.cpp
View file @
1a7a8081
...
...
@@ -3,8 +3,8 @@
*
* Created on: Oct 26.2018
*
* Version 3.0.7
b
* Updated on: Nov 2
7
.2023
* Version 3.0.7
c
* Updated on: Nov 2
9
.2023
* Author: Wolle (schreibfaul1)
*
*/
...
...
@@ -101,6 +101,12 @@ size_t AudioBuffer::bufferFilled() {
return
m_dataLength
;
}
size_t
AudioBuffer
::
getMaxAvailableBytes
()
{
if
(
m_writePtr
>=
m_readPtr
)
{
m_dataLength
=
(
m_writePtr
-
m_readPtr
);
}
else
{
m_dataLength
=
(
m_endPtr
-
m_readPtr
);}
return
m_dataLength
;
}
void
AudioBuffer
::
bytesWritten
(
size_t
bw
)
{
m_writePtr
+=
bw
;
if
(
m_writePtr
==
m_endPtr
)
{
...
...
@@ -1523,10 +1529,10 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
m_controlCounter
==
2
){
// skip extended header if exists
if
(
ehsz
>
256
)
{
ehsz
-=
256
;
remainingHeaderBytes
-=
256
;
return
256
;}
// Throw it away
if
(
ehsz
>
len
)
{
ehsz
-=
len
;
remainingHeaderBytes
-=
len
;
return
len
;}
// Throw it away
else
{
m_controlCounter
++
;
remainingHeaderBytes
-=
ehsz
;
...
...
@@ -1583,10 +1589,10 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
m_controlCounter
==
5
){
// If the frame is larger than 512 bytes, skip the rest
if
(
framesize
>
1024
){
framesize
-=
1024
;
remainingHeaderBytes
-=
1024
;
return
1024
;
if
(
framesize
>
len
){
framesize
-=
len
;
remainingHeaderBytes
-=
len
;
return
len
;
}
else
{
m_controlCounter
=
3
;
// check next frame
...
...
@@ -1672,13 +1678,13 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
frameid
[
3
]
=
0
;
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
tag
[
i
]
=
frameid
[
i
];
// tag = frameid
remainingHeaderBytes
-=
3
;
size_t
l
en
=
bigEndian
(
data
+
3
,
3
);
universal_tmp
=
l
en
;
size_t
dataL
en
=
bigEndian
(
data
+
3
,
3
);
universal_tmp
=
dataL
en
;
remainingHeaderBytes
-=
3
;
char
value
[
256
];
if
(
len
>
249
)
{
l
en
=
249
;
}
memcpy
(
value
,
(
data
+
7
),
l
en
);
value
[
l
en
+
1
]
=
0
;
if
(
dataLen
>
249
)
{
dataL
en
=
249
;
}
memcpy
(
value
,
(
data
+
7
),
dataL
en
);
value
[
dataL
en
+
1
]
=
0
;
m_chbuf
[
0
]
=
0
;
if
(
startsWith
(
tag
,
"PIC"
))
{
// image embedded in header
if
(
getDatamode
()
==
AUDIO_LOCALFILE
){
...
...
@@ -1700,20 +1706,20 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
showID3Tag
(
tag
,
value
);
}
remainingHeaderBytes
-=
universal_tmp
;
universal_tmp
-=
l
en
;
universal_tmp
-=
dataL
en
;
if
(
l
en
==
0
)
m_controlCounter
=
98
;
if
(
dataL
en
==
0
)
m_controlCounter
=
98
;
if
(
remainingHeaderBytes
==
0
)
m_controlCounter
=
98
;
return
3
+
3
+
l
en
;
return
3
+
3
+
dataL
en
;
}
// -- end section V2.2 -----------
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
m_controlCounter
==
98
){
// skip all ID3 metadata (mostly spaces)
if
(
remainingHeaderBytes
>
256
)
{
remainingHeaderBytes
-=
256
;
return
256
;
if
(
remainingHeaderBytes
>
len
)
{
remainingHeaderBytes
-=
len
;
return
len
;
}
// Throw it away
else
{
m_controlCounter
=
99
;
...
...
@@ -2704,11 +2710,12 @@ void Audio::processLocalFile() {
return
;
}
if
(
InBuff
.
bufferFilled
()
>
maxFrameSize
){
// read the file header first
InBuff
.
bytesWasRead
(
readAudioHeader
(
InBuff
.
bufferFilled
()));
InBuff
.
bytesWasRead
(
readAudioHeader
(
InBuff
.
getMaxAvailableBytes
()));
}
return
;
}
else
{
log_e
(
"%i"
,
millis
()
-
ctime
);
if
((
InBuff
.
freeSpace
()
>
maxFrameSize
)
&&
(
m_file_size
-
byteCounter
)
>
maxFrameSize
&&
availableBytes
){
// fill the buffer before playing
return
;
...
...
@@ -2935,7 +2942,7 @@ void Audio::processWebFile() {
// we have a webfile, read the file header first - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
m_controlCounter
!=
100
){
if
(
InBuff
.
bufferFilled
()
>
maxFrameSize
){
// read the file header first
int32_t
bytesRead
=
readAudioHeader
(
maxFrameSize
);
int32_t
bytesRead
=
readAudioHeader
(
InBuff
.
getMaxAvailableBytes
()
);
if
(
bytesRead
>
0
)
InBuff
.
bytesWasRead
(
bytesRead
);
}
return
;
...
...
@@ -5429,7 +5436,7 @@ uint32_t Audio::flac_correctResumeFilePos(uint32_t resumeFilePos){
p2
=
audiofile
.
read
();
pos
+=
2
;
while
(
!
found
||
pos
==
m_file_size
){
if
(
p1
==
0xFF
&&
p2
==
0xF8
){
found
=
true
;
log_i
(
"found"
);
break
;}
if
(
p1
==
0xFF
&&
p2
==
0xF8
){
found
=
true
;
break
;}
p1
=
p2
;
p2
=
audiofile
.
read
();
pos
++
;
...
...
src/Audio.h
View file @
1a7a8081
...
...
@@ -3,8 +3,8 @@
*
* Created on: Oct 28,2018
*
* Version 3.0.7
a
* Updated on: Nov
11
.2023
* Version 3.0.7
c
* Updated on: Nov
29
.2023
* Author: Wolle (schreibfaul1)
*/
...
...
@@ -86,6 +86,7 @@ public:
size_t
freeSpace
();
// number of free bytes to overwrite
size_t
writeSpace
();
// space fom writepointer to bufferend
size_t
bufferFilled
();
// returns the number of filled bytes
size_t
getMaxAvailableBytes
();
// max readable bytes in one block
void
bytesWritten
(
size_t
bw
);
// update writepointer
void
bytesWasRead
(
size_t
br
);
// update readpointer
uint8_t
*
getWritePtr
();
// returns the current writepointer
...
...
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