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
bd819fc1
Unverified
Commit
bd819fc1
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
5f4c5dd4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
40 deletions
+35
-40
src/opus_decoder/celt.cpp
src/opus_decoder/celt.cpp
+19
-28
src/opus_decoder/celt.h
src/opus_decoder/celt.h
+0
-6
src/opus_decoder/opus_decoder.cpp
src/opus_decoder/opus_decoder.cpp
+8
-4
src/opus_decoder/opus_decoder.h
src/opus_decoder/opus_decoder.h
+8
-2
No files found.
src/opus_decoder/celt.cpp
View file @
bd819fc1
...
...
@@ -33,6 +33,7 @@
#include <Arduino.h>
#include "celt.h"
#include "opus_decoder.h"
CELTDecoder
*
cdec
;
band_ctx_t
s_band_ctx
;
...
...
@@ -768,7 +769,7 @@ uint32_t alg_unquant(int16_t *X, int32_t N, int32_t K, int32_t spread, int32_t B
if
(
K
<=
0
)
log_e
(
"alg_unquant() needs at least one pulse"
);
if
(
N
<=
1
)
log_e
(
"alg_unquant() needs at least two dimensions"
);
int32_t
*
iy
=
s_iyBuff
;
assert
(
N
<=
9
6
);
int32_t
*
iy
=
s_iyBuff
;
assert
(
N
<=
17
6
);
Ryy
=
decode_pulses
(
iy
,
N
,
K
);
normalise_residual
(
iy
,
X
,
N
,
Ryy
,
gain
);
exp_rotation
(
X
,
N
,
-
1
,
B
,
K
,
spread
);
...
...
@@ -1971,15 +1972,12 @@ int32_t celt_decoder_get_size(int32_t channels){
//----------------------------------------------------------------------------------------------------------------------
int32_t
celt_decoder_init
(
int32_t
channels
){
log_e
(
"hier"
);
// allocate buffers first
if
(
channels
<
0
||
channels
>
2
){
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;
return
ERR_OPUS_CHANNELS_OUT_OF_RANGE
;
}
if
(
cdec
==
NULL
){
log_e
(
"cdec is NULL"
);
return
OPUS_ALLOC_FAIL
;
return
ERR_OPUS_CELT_ALLOC_FAIL
;
}
int
n
=
celt_decoder_get_size
(
channels
);
...
...
@@ -2007,11 +2005,9 @@ int32_t celt_decoder_init(int32_t channels){
cdec
->
_decode_mem
[
0
]
=
0
;
cdec
->
end
=
cdec
->
mode
->
effEBands
;
// 21
log_e
(
"hier1"
);
int
ret
=
celt_decoder_ctl
(
OPUS_RESET_STATE
);
log_i
(
"ret %i"
,
ret
);
log_e
(
"ok"
);
return
OPUS_OK
;
if
(
ret
<
0
)
return
ret
;
return
ERR_OPUS_NONE
;
}
//----------------------------------------------------------------------------------------------------------------------
...
...
@@ -2026,7 +2022,7 @@ bool CELTDecoder_AllocateBuffers(void) {
size_t
omd
=
celt_decoder_get_size
(
2
);
if
(
!
cdec
)
{
cdec
=
(
CELTDecoder
*
)
__heap_caps_malloc
(
omd
);}
if
(
!
s_freqBuff
)
{
s_freqBuff
=
(
int32_t
*
)
__heap_caps_malloc
(
960
*
sizeof
(
int32_t
));}
if
(
!
s_iyBuff
)
{
s_iyBuff
=
(
int32_t
*
)
__heap_caps_malloc
(
96
*
sizeof
(
int32_t
));}
if
(
!
s_iyBuff
)
{
s_iyBuff
=
(
int32_t
*
)
__heap_caps_malloc
(
176
*
sizeof
(
int32_t
));}
if
(
!
s_normBuff
)
{
s_normBuff
=
(
int16_t
*
)
__heap_caps_malloc
(
1248
*
sizeof
(
int16_t
));}
if
(
!
s_XBuff
)
{
s_XBuff
=
(
int16_t
*
)
__heap_caps_malloc
(
1920
*
sizeof
(
int16_t
));}
if
(
!
s_bits1Buff
)
{
s_bits1Buff
=
(
int32_t
*
)
__heap_caps_malloc
(
21
*
sizeof
(
int32_t
));}
...
...
@@ -2280,12 +2276,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
if
(
m_CELTMode
.
shortMdctSize
<<
LM
==
frame_size
)
break
;
// frame_size == 960
if
(
LM
>
m_CELTMode
.
maxLM
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS
_BAD_ARG
;}
if
(
LM
>
m_CELTMode
.
maxLM
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
ERR_OPUS_CELT
_BAD_ARG
;}
}
M
=
1
<<
LM
;
// LM=3 -> M = 8
if
(
len
<
0
||
len
>
1275
||
outbuf
==
NULL
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS
_BAD_ARG
;}
if
(
len
<
0
||
len
>
1275
||
outbuf
==
NULL
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
ERR_OPUS_CELT
_BAD_ARG
;}
N
=
M
*
m_CELTMode
.
shortMdctSize
;
// const m_CELTMode.shortMdctSize == 120, M == 8 -> N = 960
...
...
@@ -2295,7 +2291,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
;
}
while
(
++
c
<
CC
);
if
(
len
<=
1
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS
_BAD_ARG
;}
if
(
len
<=
1
)
{
log_e
(
"OPUS_BAD_ARG"
);
return
ERR_OPUS_CELT
_BAD_ARG
;}
if
(
C
==
1
)
{
for
(
i
=
0
;
i
<
nbEBands
;
i
++
)
oldBandE
[
i
]
=
max
(
oldBandE
[
i
],
oldBandE
[
nbEBands
+
i
]);
...
...
@@ -2477,7 +2473,7 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
deemphasis
(
out_syn
,
outbuf
,
N
);
if
(
ec_tell
()
>
8
*
len
)
return
OPUS_INTERNAL_ERROR
;
if
(
ec_tell
()
>
8
*
len
)
return
ERR_CELT_
OPUS_INTERNAL_ERROR
;
if
(
s_ec
.
error
)
cdec
->
error
=
1
;
return
frame_size
;
...
...
@@ -2491,17 +2487,17 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
switch
(
request
)
{
case
CELT_SET_END_BAND_REQUEST
:
{
int32_t
value
=
va_arg
(
ap
,
int32_t
);
if
(
value
<
1
||
value
>
cdec
->
mode
->
nbEBands
)
goto
bad_arg
;
if
(
value
<
1
||
value
>
cdec
->
mode
->
nbEBands
)
{
va_end
(
ap
);
return
ERR_OPUS_CELT_END_BAND
;}
cdec
->
end
=
value
;
}
break
;
case
CELT_SET_CHANNELS_REQUEST
:
{
int32_t
value
=
va_arg
(
ap
,
int32_t
);
if
(
value
<
1
||
value
>
2
)
goto
bad_arg
;
if
(
value
<
1
||
value
>
2
)
{
va_end
(
ap
);
return
ERR_OPUS_CELT_SET_CHANNELS
;}
cdec
->
stream_channels
=
value
;
}
break
;
case
CELT_GET_AND_CLEAR_ERROR_REQUEST
:
{
int32_t
*
value
=
va_arg
(
ap
,
int32_t
*
);
if
(
value
==
NULL
)
goto
bad_arg
;
if
(
value
==
NULL
)
{
va_end
(
ap
);
return
ERR_OPUS_CELT_CLEAR_REQUEST
;}
*
value
=
cdec
->
error
;
cdec
->
error
=
0
;
}
break
;
...
...
@@ -2522,7 +2518,7 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
}
break
;
case
CELT_GET_MODE_REQUEST
:
{
const
CELTMode
**
value
=
va_arg
(
ap
,
const
CELTMode
**
);
if
(
value
==
0
)
goto
bad_arg
;
if
(
value
==
0
)
{
va_end
(
ap
);
return
ERR_OPUS_CELT_GET_MODE_REQUEST
;}
*
value
=
cdec
->
mode
;
}
break
;
case
CELT_SET_SIGNALLING_REQUEST
:
{
...
...
@@ -2530,17 +2526,12 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
cdec
->
signalling
=
value
;
}
break
;
default:
goto
bad_request
;
va_end
(
ap
);
return
ERR_OPUS_CELT_UNKNOWN_REQUEST
;
break
;
}
va_end
(
ap
);
return
OPUS_OK
;
bad_arg:
va_end
(
ap
);
log_e
(
"OPUS_BAD_ARG"
);
return
OPUS_BAD_ARG
;
bad_request:
va_end
(
ap
);
return
OPUS_UNIMPLEMENTED
;
return
ERR_OPUS_NONE
;
}
//----------------------------------------------------------------------------------------------------------------------
...
...
src/opus_decoder/celt.h
View file @
bd819fc1
...
...
@@ -37,12 +37,6 @@
#include "Arduino.h"
#define OPUS_OK 0
#define OPUS_BAD_ARG -18
#define OPUS_INTERNAL_ERROR -19
#define OPUS_UNIMPLEMENTED -20
#define OPUS_ALLOC_FAIL -21
#define OPUS_RESET_STATE 4028
#define OPUS_GET_SAMPLE_RATE_REQUEST 4029
...
...
src/opus_decoder/opus_decoder.cpp
View file @
bd819fc1
...
...
@@ -27,6 +27,7 @@ uint16_t *m_segmentTable;
uint8_t
m_segmentTableSize
=
0
;
int16_t
s_segmentTableRdPtr
=
-
1
;
int8_t
error
=
0
;
float
m_CompressionRatio
=
0
;
bool
OPUSDecoder_AllocateBuffers
(){
const
uint32_t
CELT_SET_END_BAND_REQUEST
=
10012
;
...
...
@@ -64,6 +65,7 @@ void OPUSsetDefaults(){
m_segmentTableSize
=
0
;
s_oldmode
=
0xFF
;
s_segmentTableRdPtr
=
-
1
;
error
=
0
;
}
...
...
@@ -77,8 +79,6 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
else
return
ret
;
// error
}
if
(
f_m_opusFramePacket
){
if
(
m_segmentTableSize
>
0
){
s_segmentTableRdPtr
++
;
...
...
@@ -135,7 +135,10 @@ uint8_t OPUSGetBitsPerSample(){
return
16
;
}
uint32_t
OPUSGetBitRate
(){
return
1
;
if
(
m_CompressionRatio
!=
0
){
return
(
16
*
2
*
48000
)
/
m_CompressionRatio
;
//bitsPerSample * channel* SampleRate/CompressionRatio
}
else
return
0
;
}
uint16_t
OPUSGetOutputSamps
(){
return
s_validSamples
;
// 1024
...
...
@@ -258,7 +261,7 @@ int parseOpusHead(uint8_t *inbuf, int nBytes){ // reference https://wiki.xiph.o
outputGain
+=
*
(
inbuf
+
16
);
uint8_t
channelMap
=
*
(
inbuf
+
18
);
if
(
channelCount
==
0
or
channelCount
>
2
)
return
ERR_OPUS_
NR_OF_CHANNELS_UNSUPPORTED
;
if
(
channelCount
==
0
or
channelCount
>
2
)
return
ERR_OPUS_
CHANNELS_OUT_OF_RANGE
;
m_channels
=
channelCount
;
if
(
sampleRate
!=
48000
)
return
ERR_OPUS_INVALID_SAMPLERATE
;
m_samplerate
=
sampleRate
;
...
...
@@ -319,6 +322,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
m_segmentLength
+=
n
;
}
m_segmentTableSize
=
segmentTableWrPtr
+
1
;
m_CompressionRatio
=
(
float
)(
960
*
2
*
pageSegments
)
/
m_segmentLength
;
// const 960 validBytes out
bool
continuedPage
=
headerType
&
0x01
;
// set: page contains data of a packet continued from the previous page
bool
firstPage
=
headerType
&
0x02
;
// set: this is the first page of a logical bitstream (bos)
...
...
src/opus_decoder/opus_decoder.h
View file @
bd819fc1
...
...
@@ -7,7 +7,7 @@
enum
:
int8_t
{
OPUS_PARSE_OGG_DONE
=
100
,
ERR_OPUS_NONE
=
0
,
ERR_OPUS_
NR_OF_CHANNELS_UNSUPPORTED
=
-
1
,
ERR_OPUS_
CHANNELS_OUT_OF_RANGE
=
-
1
,
ERR_OPUS_INVALID_SAMPLERATE
=
-
2
,
ERR_OPUS_EXTRA_CHANNELS_UNSUPPORTED
=
-
3
,
ERR_OPUS_DECODER_ASYNC
=
-
4
,
...
...
@@ -17,7 +17,13 @@ enum : int8_t {OPUS_PARSE_OGG_DONE = 100,
ERR_OPUS_CELT_BAD_ARG
=
-
18
,
ERR_OPUS_CELT_INTERNAL_ERROR
=
-
19
,
ERR_OPUS_CELT_UNIMPLEMENTED
=
-
20
,
ERR_OPUS_CELT_ALLOC_FAIL
=
-
21
};
ERR_OPUS_CELT_ALLOC_FAIL
=
-
21
,
ERR_OPUS_CELT_UNKNOWN_REQUEST
=
-
22
,
ERR_OPUS_CELT_GET_MODE_REQUEST
=
-
23
,
ERR_OPUS_CELT_CLEAR_REQUEST
=
-
24
,
ERR_OPUS_CELT_SET_CHANNELS
=
-
25
,
ERR_OPUS_CELT_END_BAND
=
-
26
,
ERR_CELT_OPUS_INTERNAL_ERROR
=
-
27
};
bool
OPUSDecoder_AllocateBuffers
();
void
OPUSDecoder_FreeBuffers
();
...
...
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