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
53ca2991
Unverified
Commit
53ca2991
authored
Aug 11, 2022
by
Wolle
Committed by
GitHub
Aug 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix wav files invalid codec
parent
36464fda
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
50 deletions
+54
-50
src/Audio.cpp
src/Audio.cpp
+52
-49
src/Audio.h
src/Audio.h
+2
-1
No files found.
src/Audio.cpp
View file @
53ca2991
...
...
@@ -3,8 +3,8 @@
*
* Created on: Oct 26.2018
*
* Version 2.0.5
g
* Updated on: Aug 1
0
.2022
* Version 2.0.5
h
* Updated on: Aug 1
1
.2022
* Author: Wolle (schreibfaul1)
*
*/
...
...
@@ -1111,6 +1111,49 @@ bool Audio::latinToUTF8(char* buff, size_t bufflen){
return
true
;
}
//---------------------------------------------------------------------------------------------------------------------
size_t
Audio
::
readAudioHeader
(
uint32_t
bytes
){
size_t
bytesReaded
=
0
;
if
(
m_codec
==
CODEC_WAV
){
int
res
=
read_WAV_Header
(
InBuff
.
getReadPtr
(),
bytes
);
if
(
res
>=
0
)
bytesReaded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_MP3
){
int
res
=
read_ID3_Header
(
InBuff
.
getReadPtr
(),
bytes
);
if
(
res
>=
0
)
bytesReaded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_M4A
){
int
res
=
read_M4A_Header
(
InBuff
.
getReadPtr
(),
bytes
);
if
(
res
>=
0
)
bytesReaded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_AAC
){
// stream only, no header
m_audioDataSize
=
getFileSize
();
m_controlCounter
=
100
;
}
if
(
m_codec
==
CODEC_FLAC
){
int
res
=
read_FLAC_Header
(
InBuff
.
getReadPtr
(),
bytes
);
if
(
res
>=
0
)
bytesReaded
=
res
;
else
{
// error, skip header
stopSong
();
m_controlCounter
=
100
;
}
}
if
(
!
isRunning
()){
log_e
(
"Processing stopped due to invalid audio header"
);
return
0
;
}
return
bytesReaded
;
}
//---------------------------------------------------------------------------------------------------------------------
int
Audio
::
read_WAV_Header
(
uint8_t
*
data
,
size_t
len
)
{
static
size_t
headerSize
;
static
uint32_t
cs
=
0
;
...
...
@@ -2805,7 +2848,6 @@ bool Audio::STfromEXTINF(char* str){
void
Audio
::
processLocalFile
()
{
if
(
!
(
audiofile
&&
m_f_running
&&
getDatamode
()
==
AUDIO_LOCALFILE
))
return
;
int
bytesDecoded
=
0
;
uint32_t
bytesCanBeWritten
=
0
;
uint32_t
bytesCanBeRead
=
0
;
...
...
@@ -2853,45 +2895,7 @@ void Audio::processLocalFile() {
if
(
bytesCanBeRead
==
InBuff
.
getMaxBlockSize
())
{
// mp3 or aac frame complete?
if
(
m_controlCounter
!=
100
){
if
(
m_codec
==
CODEC_WAV
){
int
res
=
read_WAV_Header
(
InBuff
.
getReadPtr
(),
bytesCanBeRead
);
if
(
res
>=
0
)
bytesDecoded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_MP3
){
int
res
=
read_ID3_Header
(
InBuff
.
getReadPtr
(),
bytesCanBeRead
);
if
(
res
>=
0
)
bytesDecoded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_M4A
){
int
res
=
read_M4A_Header
(
InBuff
.
getReadPtr
(),
bytesCanBeRead
);
if
(
res
>=
0
)
bytesDecoded
=
res
;
else
{
// error, skip header
m_controlCounter
=
100
;
}
}
if
(
m_codec
==
CODEC_AAC
){
// stream only, no header
m_audioDataSize
=
getFileSize
();
m_controlCounter
=
100
;
}
if
(
m_codec
==
CODEC_FLAC
){
int
res
=
read_FLAC_Header
(
InBuff
.
getReadPtr
(),
bytesCanBeRead
);
if
(
res
>=
0
)
bytesDecoded
=
res
;
else
{
// error, skip header
stopSong
();
m_controlCounter
=
100
;
}
}
if
(
!
isRunning
()){
log_e
(
"Processing stopped due to invalid audio header"
);
return
;
}
bytesDecoded
=
readAudioHeader
(
bytesCanBeRead
);
}
else
{
bytesDecoded
=
sendBytes
(
InBuff
.
getReadPtr
(),
bytesCanBeRead
);
...
...
@@ -3729,7 +3733,7 @@ bool Audio:: initializeDecoder(){
InBuff
.
changeMaxBlockSize
(
m_frameSizeWav
);
break
;
case
CODEC_OGG
:
m_codec
=
CODEC_OGG
;
m_codec
=
CODEC_OGG
;
log_e
(
"!"
);
AUDIO_INFO
(
"ogg not supported"
);
goto
exit
;
break
;
...
...
@@ -4063,13 +4067,12 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
bytesLeft
=
len
;
int
ret
=
0
;
int
bytesDecoded
=
0
;
if
(
m_codec
==
CODEC_WAV
){
//copy len data in outbuff and set validsamples and bytesdecoded=len
memmove
(
m_outBuff
,
data
,
len
);
if
(
getBitsPerSample
()
==
16
)
m_validSamples
=
len
/
(
2
*
getChannels
());
if
(
getBitsPerSample
()
==
8
)
m_validSamples
=
len
/
2
;
bytesLeft
=
0
;
}
switch
(
m_codec
){
case
CODEC_WAV
:
memmove
(
m_outBuff
,
data
,
len
);
//copy len data in outbuff and set validsamples and bytesdecoded=len
if
(
getBitsPerSample
()
==
16
)
m_validSamples
=
len
/
(
2
*
getChannels
());
if
(
getBitsPerSample
()
==
8
)
m_validSamples
=
len
/
2
;
bytesLeft
=
0
;
break
;
case
CODEC_MP3
:
ret
=
MP3Decode
(
data
,
&
bytesLeft
,
m_outBuff
,
0
);
break
;
case
CODEC_AAC
:
ret
=
AACDecode
(
data
,
&
bytesLeft
,
m_outBuff
);
break
;
case
CODEC_M4A
:
ret
=
AACDecode
(
data
,
&
bytesLeft
,
m_outBuff
);
break
;
...
...
src/Audio.h
View file @
53ca2991
...
...
@@ -2,7 +2,7 @@
* Audio.h
*
* Created on: Oct 28,2018
* Updated on: Aug 1
0
,2022
* Updated on: Aug 1
1
,2022
* Author: Wolle (schreibfaul1)
*/
...
...
@@ -235,6 +235,7 @@ private:
void
printDecodeError
(
int
r
);
void
showID3Tag
(
const
char
*
tag
,
const
char
*
val
);
void
unicode2utf8
(
char
*
buff
,
uint32_t
len
);
size_t
readAudioHeader
(
uint32_t
bytes
);
int
read_WAV_Header
(
uint8_t
*
data
,
size_t
len
);
int
read_FLAC_Header
(
uint8_t
*
data
,
size_t
len
);
int
read_ID3_Header
(
uint8_t
*
data
,
size_t
len
);
...
...
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