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
91deadbc
Commit
91deadbc
authored
Dec 29, 2023
by
schreibfaul1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
determine embedded block picture
parent
2f59cc23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
13 deletions
+32
-13
src/vorbis_decoder/vorbis_decoder.cpp
src/vorbis_decoder/vorbis_decoder.cpp
+32
-13
No files found.
src/vorbis_decoder/vorbis_decoder.cpp
View file @
91deadbc
...
...
@@ -15,7 +15,7 @@
* adapted for the ESP32 by schreibfaul1
*
* Created on: 13.02.2023
* Updated on:
13
.12.2023
* Updated on:
29
.12.2023
*/
//----------------------------------------------------------------------------------------------------------------------
// O G G I M P L.
...
...
@@ -54,6 +54,9 @@ char *s_vorbisChbuf = NULL;
int32_t
s_vorbisValidSamples
=
0
;
uint8_t
s_vorbisOldMode
=
0
;
uint32_t
s_blocksizes
[
2
];
uint32_t
s_blockPicPos
=
0
;
uint32_t
s_blockPicLen
=
0
;
uint32_t
s_commentLength
=
0
;
uint8_t
s_nrOfCodebooks
=
0
;
uint8_t
s_nrOfFloors
=
0
;
...
...
@@ -152,6 +155,8 @@ void VORBISsetDefaults(){
s_vorbisSegmentTableRdPtr
=
-
1
;
s_vorbisError
=
0
;
s_lastSegmentTableLen
=
0
;
s_blockPicPos
=
0
;
s_blockPicLen
=
0
;
VORBISDecoder_ClearBuffers
();
}
...
...
@@ -190,17 +195,19 @@ int VORBISDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
// log_i("first packet (identification len) %i", len);
s_identificatonHeaderLength
=
len
;
ret
=
parseVorbisFirstPacket
(
inbuf
,
len
);
s_blockPicPos
+=
28
;
}
}
else
if
(
s_pageNr
==
2
){
// comment header
int
idx
=
VORBIS_specialIndexOf
(
inbuf
,
"vorbis"
,
10
);
s_blockPicPos
+=
6
;
if
(
idx
==
1
){
// log_i("second packet (comment len) %i", len);
s_commentHeaderLength
=
len
;
ret
=
parseVorbisComment
(
inbuf
,
len
);
}
else
{
log_e
(
"no
\"
vorbis
\"
something went wrong %i"
,
len
);
;
// commentlength is greater than (one or more) OggS frame(s)
}
// log_w("s_vorbisSegmentTableSize %d", s_vorbisSegmentTableSize);
// Normally the segment table has two entries, the first for comments and the second for the codebooks
...
...
@@ -406,19 +413,21 @@ int parseVorbisFirstPacket(uint8_t *inbuf, int16_t nBytes){ // 4.2.2. Identifica
int
parseVorbisComment
(
uint8_t
*
inbuf
,
int16_t
nBytes
){
// reference https://xiph.org/vorbis/doc/v-comment.html
// first bytes are: '.vorbis'
uint
16
_t
pos
=
7
;
uint
32
_t
pos
=
7
;
uint32_t
vendorLength
=
*
(
inbuf
+
pos
+
3
)
<<
24
;
// lengt of vendor string, e.g. Xiph.Org libVorbis I 20070622
vendorLength
+=
*
(
inbuf
+
pos
+
2
)
<<
16
;
vendorLength
+=
*
(
inbuf
+
pos
+
1
)
<<
8
;
vendorLength
+=
*
(
inbuf
+
pos
);
if
(
vendorLength
>
254
){
// guard
log_e
(
"vorbis comment too long
"
);
log_e
(
"vorbis comment too long
, vendorLength %i"
,
vendorLength
);
return
0
;
}
memcpy
(
s_vorbisChbuf
,
inbuf
+
11
,
vendorLength
);
s_vorbisChbuf
[
vendorLength
]
=
'\0'
;
pos
+=
4
+
vendorLength
;
s_commentHeaderLength
-=
(
7
+
4
+
vendorLength
);
// log_i("vendorLength %x", vendorLength);
// log_i("vendorString %s", s_vorbisChbuf);
...
...
@@ -426,6 +435,7 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https:
uint8_t
nrOfComments
=
*
(
inbuf
+
pos
);
// log_i("nrOfComments %i", nrOfComments);
pos
+=
4
;
s_commentHeaderLength
-=
4
;
int
idx
=
0
;
char
*
artist
=
NULL
;
...
...
@@ -437,23 +447,30 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https:
commentLength
+=
*
(
inbuf
+
pos
+
2
)
<<
16
;
commentLength
+=
*
(
inbuf
+
pos
+
1
)
<<
8
;
commentLength
+=
*
(
inbuf
+
pos
);
s_commentLength
=
commentLength
;
if
(
commentLength
>
254
)
{
log_i
(
"vorbis comment too long"
);
return
0
;}
memcpy
(
s_vorbisChbuf
,
inbuf
+
pos
+
4
,
c
ommentLength
);
s_vorbisChbuf
[
c
ommentLength
]
=
'\0'
;
uint8_t
cl
=
min
((
uint32_t
)
254
,
commentLength
);
memcpy
(
s_vorbisChbuf
,
inbuf
+
pos
+
4
,
c
l
);
s_vorbisChbuf
[
c
l
]
=
'\0'
;
// log_i("commentLength %i comment %s", commentLength, s_vorbisChbuf);
pos
+=
commentLength
+
4
;
idx
=
VORBIS_specialIndexOf
((
uint8_t
*
)
s_vorbisChbuf
,
"artist="
,
10
);
if
(
idx
!=
0
)
VORBIS_specialIndexOf
((
uint8_t
*
)
s_vorbisChbuf
,
"ARTIST="
,
10
);
if
(
idx
==
0
){
artist
=
strndup
((
const
char
*
)(
s_vorbisChbuf
+
7
),
commentLength
-
7
);
}
if
(
idx
==
0
){
artist
=
strndup
((
const
char
*
)(
s_vorbisChbuf
+
7
),
commentLength
-
7
);
s_commentLength
=
0
;}
idx
=
VORBIS_specialIndexOf
((
uint8_t
*
)
s_vorbisChbuf
,
"title="
,
10
);
if
(
idx
!=
0
)
VORBIS_specialIndexOf
((
uint8_t
*
)
s_vorbisChbuf
,
"TITLE="
,
10
);
if
(
idx
==
0
){
title
=
strndup
((
const
char
*
)(
s_vorbisChbuf
+
6
),
commentLength
-
6
);
}
if
(
idx
==
0
){
title
=
strndup
((
const
char
*
)(
s_vorbisChbuf
+
6
),
commentLength
-
6
);
s_commentLength
=
0
;}
idx
=
VORBIS_specialIndexOf
((
uint8_t
*
)
s_vorbisChbuf
,
"metadata_block_picture="
,
25
);
if
(
idx
==
0
){
s_blockPicLen
=
commentLength
;
s_blockPicPos
+=
pos
+
23
;
uint16_t
blockPicLenUntilFrameEnd
=
s_commentHeaderLength
-
(
4
+
23
);
log_w
(
"metadata block picture found at pos %i, length %i, first blockLength %i"
,
s_blockPicPos
,
s_blockPicLen
,
blockPicLenUntilFrameEnd
);}
pos
+=
commentLength
+
4
;
s_commentHeaderLength
-=
(
4
+
commentLength
);
}
if
(
artist
&&
title
){
strcpy
(
s_vorbisChbuf
,
artist
);
...
...
@@ -587,6 +604,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){
if
(
s_f_oggContinuedPage
)
return
ERR_VORBIS_DECODER_ASYNC
;
inbuf
+=
idx
;
*
bytesLeft
-=
idx
;
s_blockPicPos
+=
idx
;
}
int16_t
segmentTableWrPtr
=
-
1
;
...
...
@@ -646,6 +664,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){
}
*
bytesLeft
-=
headerSize
;
s_blockPicPos
+=
headerSize
;
if
(
s_pageNr
<
4
&&
!
continuedPage
)
s_pageNr
++
;
s_f_oggFirstPage
=
firstPage
;
...
...
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