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
a686705f
Commit
a686705f
authored
Feb 16, 2024
by
schreibfaul1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some corrections
parent
fffe7f4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
8 deletions
+38
-8
src/flac_decoder/flac_decoder.cpp
src/flac_decoder/flac_decoder.cpp
+38
-8
No files found.
src/flac_decoder/flac_decoder.cpp
View file @
a686705f
...
...
@@ -31,7 +31,7 @@ const uint16_t s_flacOutBuffSize = 2048;
uint16_t
s_blockSize
=
0
;
uint16_t
s_blockSizeLeft
=
0
;
uint16_t
s_flacValidSamples
=
0
;
uint16_t
m
_rIndex
=
0
;
uint16_t
s
_rIndex
=
0
;
uint8_t
s_flacStatus
=
0
;
uint8_t
*
s_flacInptr
;
float
s_flacCompressionRatio
=
0
;
...
...
@@ -89,6 +89,7 @@ void FLACDecoder_FreeBuffers(){
}
//----------------------------------------------------------------------------------------------------------------------
void
FLACDecoder_setDefaults
(){
coefs
.
clear
();
coefs
.
shrink_to_fit
();
s_flacSegmTableVec
.
clear
();
s_flacSegmTableVec
.
shrink_to_fit
();
s_flacBlockPicItem
.
clear
();
s_flacBlockPicItem
.
shrink_to_fit
();
s_flac_bitBuffer
=
0
;
...
...
@@ -98,6 +99,15 @@ void FLACDecoder_setDefaults(){
s_flacBlockPicPos
=
0
;
s_flacBlockPicLen
=
0
;
s_flacRemainBlockPicLen
=
0
;
s_blockSize
=
0
;
s_blockSizeLeft
=
0
;
s_flacValidSamples
=
0
;
s_rIndex
=
0
;
s_flacStatus
=
0
;
s_flacCompressionRatio
=
0
;
s_flacBitBufferLen
=
0
;
s_flac_pageSegments
=
0
;
s_f_flacNewStreamtitle
=
false
;
s_f_flacFirstCall
=
true
;
s_f_oggWrapper
=
false
;
s_f_lastMetaDataBlock
=
false
;
...
...
@@ -116,8 +126,8 @@ const uint32_t mask[] = {0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x00000
uint32_t
readUint
(
uint8_t
nBits
,
int
*
bytesLeft
){
while
(
s_flacBitBufferLen
<
nBits
){
uint8_t
temp
=
*
(
s_flacInptr
+
m
_rIndex
);
m
_rIndex
++
;
uint8_t
temp
=
*
(
s_flacInptr
+
s
_rIndex
);
s
_rIndex
++
;
(
*
bytesLeft
)
--
;
if
(
*
bytesLeft
<
0
)
{
log_i
(
"error in bitreader"
);
vTaskDelay
(
100
);}
s_flac_bitBuffer
=
(
s_flac_bitBuffer
<<
8
)
|
temp
;
...
...
@@ -529,13 +539,15 @@ int parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
//----------------------------------------------------------------------------------------------------------------------
int8_t
FLACDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
){
// MAIN LOOP
int
ret
=
0
;
uint16_t
segmLen
=
0
;
static
int
nBytes
=
0
;
int
ret
=
0
;
uint16_t
segmLen
=
0
;
static
uint16_t
segmLenTmp
=
0
;
static
int
nBytes
=
0
;
if
(
s_f_flacFirstCall
){
// determine if ogg or flag
s_f_flacFirstCall
=
false
;
nBytes
=
0
;
segmLenTmp
=
0
;
if
(
FLAC_specialIndexOf
(
inbuf
,
"OggS"
,
5
)
==
0
){
s_f_oggWrapper
=
true
;
s_f_flacParseOgg
=
true
;
...
...
@@ -544,6 +556,20 @@ int8_t FLACDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){ // MAIN LOOP
if
(
s_f_oggWrapper
){
if
(
segmLenTmp
){
// can't skip more than 16K
if
(
segmLenTmp
>
16384
){
s_flacCurrentFilePos
+=
16384
;
*
bytesLeft
-=
16384
;
segmLenTmp
-=
16384
;
}
else
{
s_flacCurrentFilePos
+=
segmLenTmp
;
*
bytesLeft
-=
segmLenTmp
;
segmLenTmp
=
0
;
}
return
FLAC_PARSE_OGG_DONE
;
}
if
(
nBytes
>
0
){
int16_t
diff
=
nBytes
;
ret
=
FLACDecodeNative
(
inbuf
,
&
nBytes
,
outbuf
);
...
...
@@ -584,7 +610,7 @@ int8_t FLACDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){ // MAIN LOOP
case
0
:
ret
=
parseFlacFirstPacket
(
inbuf
,
segmLen
);
if
(
ret
==
segmLen
)
{
s_flacPageNr
++
;
s_flacPageNr
=
1
;
ret
=
FLAC_PARSE_OGG_DONE
;
break
;
}
...
...
@@ -616,6 +642,10 @@ int8_t FLACDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){ // MAIN LOOP
return
FLAC_PARSE_OGG_DONE
;
break
;
}
if
(
segmLen
>
16384
){
segmLenTmp
=
segmLen
;
return
FLAC_PARSE_OGG_DONE
;
}
*
bytesLeft
-=
segmLen
;
s_flacCurrentFilePos
+=
segmLen
;
return
ret
;
...
...
@@ -630,7 +660,7 @@ int8_t FLACDecodeNative(uint8_t *inbuf, int *bytesLeft, short *outbuf){
static
int
sbl
=
0
;
if
(
s_flacStatus
!=
OUT_SAMPLES
){
m
_rIndex
=
0
;
s
_rIndex
=
0
;
s_flacInptr
=
inbuf
;
}
...
...
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