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
287f182f
Unverified
Commit
287f182f
authored
Feb 06, 2023
by
Wolle
Committed by
GitHub
Feb 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
c6373e1d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
31 deletions
+66
-31
src/opus_decoder/celt.cpp
src/opus_decoder/celt.cpp
+33
-15
src/opus_decoder/celt.h
src/opus_decoder/celt.h
+0
-2
src/opus_decoder/opus_decoder.cpp
src/opus_decoder/opus_decoder.cpp
+32
-14
src/opus_decoder/opus_decoder.h
src/opus_decoder/opus_decoder.h
+1
-0
No files found.
src/opus_decoder/celt.cpp
View file @
287f182f
...
@@ -1971,29 +1971,46 @@ int32_t celt_decoder_get_size(int32_t channels){
...
@@ -1971,29 +1971,46 @@ int32_t celt_decoder_get_size(int32_t channels){
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
int32_t
celt_decoder_init
(
int32_t
channels
){
int32_t
celt_decoder_init
(
int32_t
channels
){
log_e
(
"hier"
);
// allocate buffers first
// allocate buffers first
if
(
channels
<
0
||
channels
>
2
)
if
(
channels
<
0
||
channels
>
2
){
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;
return
OPUS_BAD_ARG
;
}
if
(
cdec
==
NULL
)
if
(
cdec
==
NULL
){
log_e
(
"cdec is NULL"
);
return
OPUS_ALLOC_FAIL
;
return
OPUS_ALLOC_FAIL
;
}
int
n
=
celt_decoder_get_size
(
channels
);
int
n
=
celt_decoder_get_size
(
channels
);
memset
(
cdec
,
0
,
n
*
sizeof
(
char
));
memset
(
cdec
,
0
,
n
*
sizeof
(
char
));
cdec
->
channels
=
channels
;
if
(
channels
==
1
)
cdec
->
disable_inv
=
1
;
else
cdec
->
disable_inv
=
0
;
// 1 mono , 0 stereo
cdec
->
end
=
cdec
->
mode
->
effEBands
;
// 21
cdec
->
error
=
0
;
cdec
->
mode
=
&
m_CELTMode
;
cdec
->
mode
=
&
m_CELTMode
;
cdec
->
overlap
=
m_CELTMode
.
overlap
;
cdec
->
overlap
=
m_CELTMode
.
overlap
;
cdec
->
stream_channels
=
channels
;
cdec
->
channels
=
channels
;
cdec
->
postfilter_gain
=
0
;
cdec
->
postfilter_gain_old
=
0
;
cdec
->
postfilter_period
=
0
;
cdec
->
postfilter_tapset
=
0
;
cdec
->
postfilter_tapset_old
=
0
;
cdec
->
preemph_memD
[
0
]
=
0
;
cdec
->
preemph_memD
[
1
]
=
0
;
cdec
->
rng
=
0
;
cdec
->
signalling
=
1
;
cdec
->
start
=
0
;
cdec
->
start
=
0
;
cdec
->
stream_channels
=
channels
;
cdec
->
_decode_mem
[
0
]
=
0
;
cdec
->
end
=
cdec
->
mode
->
effEBands
;
// 21
cdec
->
end
=
cdec
->
mode
->
effEBands
;
// 21
cdec
->
signalling
=
1
;
if
(
channels
==
1
)
cdec
->
disable_inv
=
1
;
else
cdec
->
disable_inv
=
0
;
// 1 mono , 0 stereo
celt_decoder_ctl
(
OPUS_RESET_STATE
);
log_e
(
"hier1"
);
int
ret
=
celt_decoder_ctl
(
OPUS_RESET_STATE
);
log_i
(
"ret %i"
,
ret
);
log_e
(
"ok"
);
return
OPUS_OK
;
return
OPUS_OK
;
}
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
...
@@ -2263,12 +2280,12 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
...
@@ -2263,12 +2280,12 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
{
{
for
(
LM
=
0
;
LM
<=
m_CELTMode
.
maxLM
;
LM
++
)
// m_CELTMode.maxLM == 3
for
(
LM
=
0
;
LM
<=
m_CELTMode
.
maxLM
;
LM
++
)
// m_CELTMode.maxLM == 3
if
(
m_CELTMode
.
shortMdctSize
<<
LM
==
frame_size
)
break
;
// frame_size == 960
if
(
m_CELTMode
.
shortMdctSize
<<
LM
==
frame_size
)
break
;
// frame_size == 960
if
(
LM
>
m_CELTMode
.
maxLM
)
return
OPUS_BAD_ARG
;
if
(
LM
>
m_CELTMode
.
maxLM
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;}
}
}
M
=
1
<<
LM
;
// LM=3 -> M = 8
M
=
1
<<
LM
;
// LM=3 -> M = 8
if
(
len
<
0
||
len
>
1275
||
outbuf
==
NULL
)
return
OPUS_BAD_ARG
;
if
(
len
<
0
||
len
>
1275
||
outbuf
==
NULL
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;}
N
=
M
*
m_CELTMode
.
shortMdctSize
;
// const m_CELTMode.shortMdctSize == 120, M == 8 -> N = 960
N
=
M
*
m_CELTMode
.
shortMdctSize
;
// const m_CELTMode.shortMdctSize == 120, M == 8 -> N = 960
...
@@ -2278,7 +2295,7 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
...
@@ -2278,7 +2295,7 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
out_syn
[
c
]
=
decode_mem
[
c
]
+
DECODE_BUFFER_SIZE
-
N
;
out_syn
[
c
]
=
decode_mem
[
c
]
+
DECODE_BUFFER_SIZE
-
N
;
}
while
(
++
c
<
CC
);
}
while
(
++
c
<
CC
);
if
(
len
<=
1
)
{
return
OPUS_BAD_ARG
;
}
if
(
len
<=
1
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;
}
if
(
C
==
1
)
{
if
(
C
==
1
)
{
for
(
i
=
0
;
i
<
nbEBands
;
i
++
)
oldBandE
[
i
]
=
max
(
oldBandE
[
i
],
oldBandE
[
nbEBands
+
i
]);
for
(
i
=
0
;
i
<
nbEBands
;
i
++
)
oldBandE
[
i
]
=
max
(
oldBandE
[
i
],
oldBandE
[
nbEBands
+
i
]);
...
@@ -2519,7 +2536,8 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
...
@@ -2519,7 +2536,8 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
return
OPUS_OK
;
return
OPUS_OK
;
bad_arg:
bad_arg:
va_end
(
ap
);
va_end
(
ap
);
return
OPUS_BAD_ARG
;
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;
bad_request:
bad_request:
va_end
(
ap
);
va_end
(
ap
);
return
OPUS_UNIMPLEMENTED
;
return
OPUS_UNIMPLEMENTED
;
...
...
src/opus_decoder/celt.h
View file @
287f182f
...
@@ -124,8 +124,6 @@ struct CELTDecoder {
...
@@ -124,8 +124,6 @@ struct CELTDecoder {
uint32_t
rng
;
uint32_t
rng
;
int32_t
error
;
int32_t
error
;
int32_t
last_pitch_index
;
int32_t
loss_count
;
int32_t
postfilter_period
;
int32_t
postfilter_period
;
int32_t
postfilter_period_old
;
int32_t
postfilter_period_old
;
int16_t
postfilter_gain
;
int16_t
postfilter_gain
;
...
...
src/opus_decoder/opus_decoder.cpp
View file @
287f182f
...
@@ -21,33 +21,52 @@ uint16_t m_samplerate = 0;
...
@@ -21,33 +21,52 @@ uint16_t m_samplerate = 0;
uint32_t
m_segmentLength
=
0
;
uint32_t
m_segmentLength
=
0
;
char
*
m_chbuf
=
NULL
;
char
*
m_chbuf
=
NULL
;
int32_t
s_validSamples
=
0
;
int32_t
s_validSamples
=
0
;
uint8_t
s_oldmode
=
0
;
uint16_t
*
m_segmentTable
;
uint16_t
*
m_segmentTable
;
uint8_t
m_segmentTableSize
=
0
;
uint8_t
m_segmentTableSize
=
0
;
int16_t
s_segmentTableRdPtr
=
-
1
;
int8_t
error
=
0
;
int8_t
error
=
0
;
bool
OPUSDecoder_AllocateBuffers
(){
bool
OPUSDecoder_AllocateBuffers
(){
const
uint32_t
CELT_SET_END_BAND_REQUEST
=
10012
;
const
uint32_t
CELT_SET_END_BAND_REQUEST
=
10012
;
const
uint32_t
CELT_SET_SIGNALLING_REQUEST
=
10016
;
const
uint32_t
CELT_SET_SIGNALLING_REQUEST
=
10016
;
m_chbuf
=
(
char
*
)
malloc
(
512
);
m_chbuf
=
(
char
*
)
malloc
(
512
);
if
(
!
CELTDecoder_AllocateBuffers
())
return
false
;
if
(
!
CELTDecoder_AllocateBuffers
())
{
log_e
(
"CELT not init"
);
return
false
;}
m_segmentTable
=
(
uint16_t
*
)
malloc
(
256
*
sizeof
(
uint16_t
));
m_segmentTable
=
(
uint16_t
*
)
malloc
(
256
*
sizeof
(
uint16_t
));
if
(
!
m_segmentTable
)
return
false
;
if
(
!
m_segmentTable
)
{
log_e
(
"CELT not init"
);
return
false
;}
CELTDecoder_ClearBuffer
();
CELTDecoder_ClearBuffer
();
OPUSDecoder_ClearBuffers
();
OPUSDecoder_ClearBuffers
();
error
=
celt_decoder_init
(
2
);
if
(
error
<
0
)
return
false
;
error
=
celt_decoder_init
(
2
);
if
(
error
<
0
)
{
log_e
(
"CELT not init"
);
return
false
;}
error
=
celt_decoder_ctl
(
CELT_SET_SIGNALLING_REQUEST
,
0
);
if
(
error
<
0
)
return
false
;
error
=
celt_decoder_ctl
(
CELT_SET_SIGNALLING_REQUEST
,
0
);
if
(
error
<
0
)
{
log_e
(
"CELT not init"
);
return
false
;}
error
=
celt_decoder_ctl
(
CELT_SET_END_BAND_REQUEST
,
21
);
if
(
error
<
0
)
return
false
;
error
=
celt_decoder_ctl
(
CELT_SET_END_BAND_REQUEST
,
21
);
if
(
error
<
0
)
{
log_e
(
"CELT not init"
);
return
false
;}
OPUSsetDefaults
();
return
true
;
return
true
;
}
}
void
OPUSDecoder_FreeBuffers
(){
void
OPUSDecoder_FreeBuffers
(){
if
(
m_chbuf
)
{
free
(
m_chbuf
);
m_chbuf
=
NULL
;}
if
(
m_chbuf
)
{
free
(
m_chbuf
);
m_chbuf
=
NULL
;}
if
(
m_segmentTable
)
{
free
(
m_segmentTable
);
m_segmentTable
=
NULL
;}
if
(
m_segmentTable
)
{
free
(
m_segmentTable
);
m_segmentTable
=
NULL
;}
CELTDecoder_FreeBuffers
();
}
}
void
OPUSDecoder_ClearBuffers
(){
void
OPUSDecoder_ClearBuffers
(){
if
(
m_chbuf
)
memset
(
m_chbuf
,
0
,
512
);
if
(
m_chbuf
)
memset
(
m_chbuf
,
0
,
512
);
if
(
m_segmentTable
)
memset
(
m_segmentTable
,
0
,
256
);
if
(
m_segmentTable
)
memset
(
m_segmentTable
,
0
,
256
*
sizeof
(
int16_t
)
);
}
}
void
OPUSsetDefaults
(){
f_m_subsequentPage
=
false
;
f_m_parseOgg
=
false
;
f_m_newSt
=
false
;
// streamTitle
f_m_opusFramePacket
=
false
;
m_channels
=
0
;
m_samplerate
=
0
;
m_segmentLength
=
0
;
s_validSamples
=
0
;
m_segmentTableSize
=
0
;
s_oldmode
=
0xFF
;
s_segmentTableRdPtr
=
-
1
;
error
=
0
;
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
int
OPUSDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
){
int
OPUSDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
){
...
@@ -58,13 +77,13 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
...
@@ -58,13 +77,13 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
else
return
ret
;
// error
else
return
ret
;
// error
}
}
static
int16_t
segmentTableRdPtr
=
-
1
;
if
(
f_m_opusFramePacket
){
if
(
f_m_opusFramePacket
){
if
(
m_segmentTableSize
>
0
){
if
(
m_segmentTableSize
>
0
){
segmentTableRdPtr
++
;
s
_s
egmentTableRdPtr
++
;
m_segmentTableSize
--
;
m_segmentTableSize
--
;
int
len
=
m_segmentTable
[
segmentTableRdPtr
];
int
len
=
m_segmentTable
[
s
_s
egmentTableRdPtr
];
*
bytesLeft
-=
len
;
*
bytesLeft
-=
len
;
int32_t
ret
=
parseOpusTOC
(
inbuf
[
0
]);
int32_t
ret
=
parseOpusTOC
(
inbuf
[
0
]);
if
(
ret
<
0
)
return
ret
;
if
(
ret
<
0
)
return
ret
;
...
@@ -78,7 +97,7 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
...
@@ -78,7 +97,7 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
s_validSamples
=
ret
;
s_validSamples
=
ret
;
if
(
m_segmentTableSize
==
0
){
if
(
m_segmentTableSize
==
0
){
segmentTableRdPtr
=
-
1
;
// back to the parking position
s
_s
egmentTableRdPtr
=
-
1
;
// back to the parking position
f_m_opusFramePacket
=
false
;
f_m_opusFramePacket
=
false
;
f_m_parseOgg
=
true
;
f_m_parseOgg
=
true
;
}
}
...
@@ -132,7 +151,6 @@ char* OPUSgetStreamTitle(){
...
@@ -132,7 +151,6 @@ char* OPUSgetStreamTitle(){
int
parseOpusTOC
(
uint8_t
TOC_Byte
){
// https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
int
parseOpusTOC
(
uint8_t
TOC_Byte
){
// https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
uint8_t
mode
=
0
;
uint8_t
mode
=
0
;
static
uint8_t
oldmode
=
0
;
uint8_t
configNr
=
0
;
uint8_t
configNr
=
0
;
uint8_t
s
=
0
;
uint8_t
s
=
0
;
uint8_t
c
=
0
;
(
void
)
c
;
uint8_t
c
=
0
;
(
void
)
c
;
...
@@ -142,8 +160,8 @@ int parseOpusTOC(uint8_t TOC_Byte){ // https://www.rfc-editor.org/rfc/rfc6716
...
@@ -142,8 +160,8 @@ int parseOpusTOC(uint8_t TOC_Byte){ // https://www.rfc-editor.org/rfc/rfc6716
c
=
(
TOC_Byte
&
0b00000011
);
c
=
(
TOC_Byte
&
0b00000011
);
if
(
TOC_Byte
&
0x80
)
mode
=
2
;
else
mode
=
1
;
if
(
TOC_Byte
&
0x80
)
mode
=
2
;
else
mode
=
1
;
if
(
oldmode
!=
mode
)
{
if
(
s_
oldmode
!=
mode
)
{
oldmode
=
mode
;
s_
oldmode
=
mode
;
if
(
mode
==
2
)
log_i
(
"opus mode is MODE_CELT_ONLY"
);
if
(
mode
==
2
)
log_i
(
"opus mode is MODE_CELT_ONLY"
);
}
}
...
@@ -259,7 +277,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
...
@@ -259,7 +277,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
int
idx
=
OPUS_specialIndexOf
(
inbuf
,
"OggS"
,
6
);
int
idx
=
OPUS_specialIndexOf
(
inbuf
,
"OggS"
,
6
);
if
(
idx
!=
0
)
return
ERR_OPUS_DECODER_ASYNC
;
if
(
idx
!=
0
)
return
ERR_OPUS_DECODER_ASYNC
;
static
int16_t
segmentTableWrPtr
=
-
1
;
int16_t
segmentTableWrPtr
=
-
1
;
uint8_t
version
=
*
(
inbuf
+
4
);
(
void
)
version
;
uint8_t
version
=
*
(
inbuf
+
4
);
(
void
)
version
;
uint8_t
headerType
=
*
(
inbuf
+
5
);
(
void
)
headerType
;
uint8_t
headerType
=
*
(
inbuf
+
5
);
(
void
)
headerType
;
...
...
src/opus_decoder/opus_decoder.h
View file @
287f182f
...
@@ -22,6 +22,7 @@ enum : int8_t {OPUS_PARSE_OGG_DONE = 100,
...
@@ -22,6 +22,7 @@ enum : int8_t {OPUS_PARSE_OGG_DONE = 100,
bool
OPUSDecoder_AllocateBuffers
();
bool
OPUSDecoder_AllocateBuffers
();
void
OPUSDecoder_FreeBuffers
();
void
OPUSDecoder_FreeBuffers
();
void
OPUSDecoder_ClearBuffers
();
void
OPUSDecoder_ClearBuffers
();
void
OPUSsetDefaults
();
int
OPUSDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
);
int
OPUSDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
);
uint8_t
OPUSGetChannels
();
uint8_t
OPUSGetChannels
();
uint32_t
OPUSGetSampRate
();
uint32_t
OPUSGetSampRate
();
...
...
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