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
7ebd56e7
Unverified
Commit
7ebd56e7
authored
Feb 04, 2023
by
Wolle
Committed by
GitHub
Feb 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
eb37fdf8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
19 deletions
+34
-19
src/opus_decoder/opus_decoder.cpp
src/opus_decoder/opus_decoder.cpp
+32
-18
src/opus_decoder/opus_decoder.h
src/opus_decoder/opus_decoder.h
+2
-1
No files found.
src/opus_decoder/opus_decoder.cpp
View file @
7ebd56e7
...
...
@@ -42,25 +42,45 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
}
if
(
f_m_opusFramePacket
){
//int ret = parseOpusFramePacket(inbuf, bytesLeft);
if
(
m_segmentTable
.
size
()
>
0
){
int
len
=
m_segmentTable
[
m_segmentTable
.
size
()
-
1
];
*
bytesLeft
-=
len
;
m_segmentTable
.
pop_back
();
// log_i("decode %i", len);
int
ret
=
parseOpusTOC
(
inbuf
[
0
]);
if
(
ret
<
0
)
return
ret
;
int
frame_size
=
opus_packet_get_samples_per_frame
(
inbuf
,
48000
);
inbuf
++
;
len
--
;
//int32_t validSamples = celt_decode_with_ec(inbuf, len, outbuf, frame_size);
log_i
(
"len %i, frame_size %i"
,
len
,
frame_size
);
if
(
m_segmentTable
.
size
()
==
0
){
f_m_opusFramePacket
=
false
;
f_m_parseOgg
=
true
;
}
}
}
return
0
;
}
//----------------------------------------------------------------------------------------------------------------------
int32_t
opus_packet_get_samples_per_frame
(
const
uint8_t
*
data
,
int32_t
Fs
)
{
int32_t
audiosize
;
if
(
data
[
0
]
&
0x80
)
{
audiosize
=
((
data
[
0
]
>>
3
)
&
0x3
);
audiosize
=
(
Fs
<<
audiosize
)
/
400
;
}
else
if
((
data
[
0
]
&
0x60
)
==
0x60
)
{
audiosize
=
(
data
[
0
]
&
0x08
)
?
Fs
/
50
:
Fs
/
100
;
}
else
{
audiosize
=
((
data
[
0
]
>>
3
)
&
0x3
);
if
(
audiosize
==
3
)
audiosize
=
Fs
*
60
/
1000
;
else
audiosize
=
(
Fs
<<
audiosize
)
/
100
;
}
return
audiosize
;
}
//----------------------------------------------------------------------------------------------------------------------
uint8_t
OPUSGetChannels
(){
return
m_channels
;
}
...
...
@@ -84,13 +104,11 @@ char* OPUSgetStreamTitle(){
return
NULL
;
}
//----------------------------------------------------------------------------------------------------------------------
int
parseOpus
FramePacket
(
){
// https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
int
parseOpus
TOC
(
uint8_t
TOC_Byte
){
// https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
uint8_t
configNr
=
0
;
uint8_t
s
=
0
;
uint8_t
c
=
0
;
//
uint8_t
TOC_Byte
=
m_segmentTable
[
0
];
uint8_t
c
=
0
;
(
void
)
c
;
configNr
=
(
TOC_Byte
&
0b11111000
)
>>
3
;
s
=
(
TOC_Byte
&
0b00000100
)
>>
2
;
...
...
@@ -105,7 +123,6 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16
(*) Although the sampling theorem allows a bandwidth as large as half the sampling rate, Opus never codes
audio above 20 kHz, as that is the generally accepted upper limit of human hearing.
s = 0: mono 1: stereo
c = 0: 1 frame in the packet
...
...
@@ -114,15 +131,12 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16
c = 3: an arbitrary number of frames in the packet
*/
log_i
(
"configNr %i"
,
configNr
);
log_i
(
"s %i"
,
s
);
log_i
(
"c %i"
,
c
);
// log_i("configNr %i, s %i, c %i", configNr, s, c);
if
(
configNr
<
12
)
return
ERR_OPUS_SILK_MODE_UNSUPPORTED
;
if
(
configNr
<
16
)
return
ERR_OPUS_HYBRID_MODE_UNSUPPORTED
;
f_m_opusFramePacket
=
false
;
return
0
;
return
s
;
}
//----------------------------------------------------------------------------------------------------------------------
int
parseOpusComment
(
uint8_t
*
inbuf
,
int
nBytes
){
// reference https://exiftool.org/TagNames/Vorbis.html#Comments
...
...
@@ -210,7 +224,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
f_m_parseOgg
=
false
;
int
ret
=
0
;
int
idx
=
OPUS_specialIndexOf
(
inbuf
,
"OggS"
,
6
);
log_i
(
"idx %i"
,
idx
);
//
log_i("idx %i", idx);
if
(
idx
!=
0
)
return
0
;
//ERR_OPUS_DECODER_ASYNC;
uint8_t
version
=
*
(
inbuf
+
4
);
(
void
)
version
;
...
...
@@ -270,7 +284,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
}
else
if
(
m_segmentTable
.
size
()
>
0
){
if
(
m_segmentLength
/
m_segmentTable
.
size
()
==
3
){
//parseOpus
FramePacket
();
//parseOpus
TOC
();
log_i
(
"special"
);
*
bytesLeft
-=
m_segmentLength
;
f_m_parseOgg
=
true
;
...
...
@@ -289,7 +303,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
// log_i("headerSize %i", headerSize);
// log_i("granulePosition %u", granulePosition);
// log_i("bitstreamSerialNr %u", bitstreamSerialNr);
log_i
(
"pageSequenceNr %u"
,
pageSequenceNr
);
//
log_i("pageSequenceNr %u", pageSequenceNr);
// log_i("pageSegments %i", pageSegments);
// log_i("m_segmentLength %i", m_segmentLength);
...
...
src/opus_decoder/opus_decoder.h
View file @
7ebd56e7
...
...
@@ -31,7 +31,8 @@ int OPUSFindSyncWord(unsigned char *buf, int nBytes);
int
OPUSparseOGG
(
uint8_t
*
inbuf
,
int
*
bytesLeft
);
int
parseOpusHead
(
uint8_t
*
inbuf
,
int
nBytes
);
int
parseOpusComment
(
uint8_t
*
inbuf
,
int
nBytes
);
int
parseOpusFramePacket
();
int
parseOpusTOC
(
uint8_t
TOC_Byte
);
int32_t
opus_packet_get_samples_per_frame
(
const
uint8_t
*
data
,
int32_t
Fs
);
// some helper functions
int
OPUS_specialIndexOf
(
uint8_t
*
base
,
const
char
*
str
,
int
baselen
,
bool
exact
=
false
);
\ No newline at end of file
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