Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mark Harris
Opus
Commits
541df0a9
Commit
541df0a9
authored
May 26, 2011
by
Jean-Marc Valin
Browse files
Fixes an issue when triggering PLC before receiving any packet
also s/BANDWIDTH/OPUS_BANDWIDTH/
parent
479e18bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/opus.h
View file @
541df0a9
...
...
@@ -72,12 +72,12 @@ extern "C" {
#define MODE_HYBRID 1001
#define MODE_CELT_ONLY 1002
#define BANDWIDTH_AUTO 1100
#define BANDWIDTH_NARROWBAND 1101
#define BANDWIDTH_MEDIUMBAND 1102
#define BANDWIDTH_WIDEBAND 1103
#define BANDWIDTH_SUPERWIDEBAND 1104
#define BANDWIDTH_FULLBAND 1105
#define
OPUS_
BANDWIDTH_AUTO 1100
#define
OPUS_
BANDWIDTH_NARROWBAND 1101
#define
OPUS_
BANDWIDTH_MEDIUMBAND 1102
#define
OPUS_
BANDWIDTH_WIDEBAND 1103
#define
OPUS_
BANDWIDTH_SUPERWIDEBAND 1104
#define
OPUS_
BANDWIDTH_FULLBAND 1105
...
...
src/opus_decoder.c
View file @
541df0a9
...
...
@@ -179,7 +179,15 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
mode
=
st
->
mode
;
ec_dec_init
(
&
dec
,(
unsigned
char
*
)
data
,
len
);
}
else
{
mode
=
st
->
prev_mode
;
if
(
st
->
prev_mode
==
0
)
{
/* If we haven't got any packet yet, all we can do is return zeros */
for
(
i
=
0
;
i
<
frame_size
;
i
++
)
pcm
[
i
]
=
0
;
return
audiosize
;
}
else
{
mode
=
st
->
prev_mode
;
}
}
if
(
data
!=
NULL
&&
!
st
->
prev_redundancy
&&
mode
!=
st
->
prev_mode
&&
st
->
prev_mode
>
0
...
...
@@ -212,11 +220,11 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
DecControl
.
nChannelsInternal
=
st
->
stream_channels
;
DecControl
.
payloadSize_ms
=
1000
*
audiosize
/
st
->
Fs
;
if
(
mode
==
MODE_SILK_ONLY
)
{
if
(
st
->
bandwidth
==
BANDWIDTH_NARROWBAND
)
{
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_NARROWBAND
)
{
DecControl
.
internalSampleRate
=
8000
;
}
else
if
(
st
->
bandwidth
==
BANDWIDTH_MEDIUMBAND
)
{
}
else
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_MEDIUMBAND
)
{
DecControl
.
internalSampleRate
=
12000
;
}
else
if
(
st
->
bandwidth
==
BANDWIDTH_WIDEBAND
)
{
}
else
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_WIDEBAND
)
{
DecControl
.
internalSampleRate
=
16000
;
}
else
{
DecControl
.
internalSampleRate
=
16000
;
...
...
@@ -274,16 +282,16 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
switch
(
st
->
bandwidth
)
{
case
BANDWIDTH_NARROWBAND
:
case
OPUS_
BANDWIDTH_NARROWBAND
:
endband
=
13
;
break
;
case
BANDWIDTH_WIDEBAND
:
case
OPUS_
BANDWIDTH_WIDEBAND
:
endband
=
17
;
break
;
case
BANDWIDTH_SUPERWIDEBAND
:
case
OPUS_
BANDWIDTH_SUPERWIDEBAND
:
endband
=
19
;
break
;
case
BANDWIDTH_FULLBAND
:
case
OPUS_
BANDWIDTH_FULLBAND
:
endband
=
21
;
break
;
}
...
...
@@ -551,15 +559,15 @@ int opus_packet_get_bandwidth(const unsigned char *data)
int
bandwidth
;
if
(
data
[
0
]
&
0x80
)
{
bandwidth
=
BANDWIDTH_MEDIUMBAND
+
((
data
[
0
]
>>
5
)
&
0x3
);
if
(
bandwidth
==
BANDWIDTH_MEDIUMBAND
)
bandwidth
=
BANDWIDTH_NARROWBAND
;
bandwidth
=
OPUS_
BANDWIDTH_MEDIUMBAND
+
((
data
[
0
]
>>
5
)
&
0x3
);
if
(
bandwidth
==
OPUS_
BANDWIDTH_MEDIUMBAND
)
bandwidth
=
OPUS_
BANDWIDTH_NARROWBAND
;
}
else
if
((
data
[
0
]
&
0x60
)
==
0x60
)
{
bandwidth
=
(
data
[
0
]
&
0x10
)
?
BANDWIDTH_FULLBAND
:
BANDWIDTH_SUPERWIDEBAND
;
bandwidth
=
(
data
[
0
]
&
0x10
)
?
OPUS_
BANDWIDTH_FULLBAND
:
OPUS_
BANDWIDTH_SUPERWIDEBAND
;
}
else
{
bandwidth
=
BANDWIDTH_NARROWBAND
+
((
data
[
0
]
>>
5
)
&
0x3
);
bandwidth
=
OPUS_
BANDWIDTH_NARROWBAND
+
((
data
[
0
]
>>
5
)
&
0x3
);
}
return
bandwidth
;
}
...
...
src/opus_encoder.c
View file @
541df0a9
...
...
@@ -127,12 +127,12 @@ OpusEncoder *opus_encoder_init(OpusEncoder* st, int Fs, int channels, int mode)
celt_encoder_ctl
(
celt_enc
,
CELT_SET_SIGNALLING
(
0
));
st
->
mode
=
MODE_HYBRID
;
st
->
bandwidth
=
BANDWIDTH_FULLBAND
;
st
->
bandwidth
=
OPUS_
BANDWIDTH_FULLBAND
;
st
->
use_vbr
=
0
;
st
->
user_bitrate_bps
=
OPUS_BITRATE_AUTO
;
st
->
bitrate_bps
=
3000
+
Fs
*
channels
;
st
->
user_mode
=
mode
;
st
->
user_bandwidth
=
BANDWIDTH_AUTO
;
st
->
user_bandwidth
=
OPUS_
BANDWIDTH_AUTO
;
st
->
voice_ratio
=
90
;
st
->
first
=
1
;
...
...
@@ -226,13 +226,13 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
if
(
st
->
mode
==
MODE_CELT_ONLY
||
st
->
first
||
st
->
silk_mode
.
allowBandwidthSwitch
)
{
const
int
*
bandwidth_thresholds
;
int
bandwidth
=
BANDWIDTH_FULLBAND
;
int
bandwidth
=
OPUS_
BANDWIDTH_FULLBAND
;
bandwidth_thresholds
=
st
->
mode
==
MODE_CELT_ONLY
?
audio_bandwidth_thresholds
:
voice_bandwidth_thresholds
;
do
{
int
threshold
,
hysteresis
;
threshold
=
bandwidth_thresholds
[
2
*
(
bandwidth
-
BANDWIDTH_MEDIUMBAND
)];
hysteresis
=
bandwidth_thresholds
[
2
*
(
bandwidth
-
BANDWIDTH_MEDIUMBAND
)
+
1
];
threshold
=
bandwidth_thresholds
[
2
*
(
bandwidth
-
OPUS_
BANDWIDTH_MEDIUMBAND
)];
hysteresis
=
bandwidth_thresholds
[
2
*
(
bandwidth
-
OPUS_
BANDWIDTH_MEDIUMBAND
)
+
1
];
if
(
!
st
->
first
)
{
if
(
st
->
bandwidth
>=
bandwidth
)
...
...
@@ -242,26 +242,26 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
}
if
(
mono_rate
>=
threshold
)
break
;
}
while
(
--
bandwidth
>
BANDWIDTH_NARROWBAND
);
}
while
(
--
bandwidth
>
OPUS_
BANDWIDTH_NARROWBAND
);
st
->
bandwidth
=
bandwidth
;
/* Prevents any transition to SWB/FB until the SILK layer has fully
switched to WB mode and turned the variable LP filter off */
if
(
st
->
mode
!=
MODE_CELT_ONLY
&&
!
st
->
silk_mode
.
inWBmodeWithoutVariableLP
&&
st
->
bandwidth
>
BANDWIDTH_WIDEBAND
)
st
->
bandwidth
=
BANDWIDTH_WIDEBAND
;
if
(
st
->
mode
!=
MODE_CELT_ONLY
&&
!
st
->
silk_mode
.
inWBmodeWithoutVariableLP
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_WIDEBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_WIDEBAND
;
}
/* Prevents Opus from wasting bits on frequencies that are above
the Nyquist rate of the input signal */
if
(
st
->
Fs
<=
24000
&&
st
->
bandwidth
>
BANDWIDTH_SUPERWIDEBAND
)
st
->
bandwidth
=
BANDWIDTH_SUPERWIDEBAND
;
if
(
st
->
Fs
<=
16000
&&
st
->
bandwidth
>
BANDWIDTH_WIDEBAND
)
st
->
bandwidth
=
BANDWIDTH_WIDEBAND
;
if
(
st
->
Fs
<=
12000
&&
st
->
bandwidth
>
BANDWIDTH_MEDIUMBAND
)
st
->
bandwidth
=
BANDWIDTH_MEDIUMBAND
;
if
(
st
->
Fs
<=
8000
&&
st
->
bandwidth
>
BANDWIDTH_NARROWBAND
)
st
->
bandwidth
=
BANDWIDTH_NARROWBAND
;
if
(
st
->
user_bandwidth
!=
BANDWIDTH_AUTO
)
if
(
st
->
Fs
<=
24000
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_SUPERWIDEBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_SUPERWIDEBAND
;
if
(
st
->
Fs
<=
16000
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_WIDEBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_WIDEBAND
;
if
(
st
->
Fs
<=
12000
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_MEDIUMBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_MEDIUMBAND
;
if
(
st
->
Fs
<=
8000
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_NARROWBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_NARROWBAND
;
if
(
st
->
user_bandwidth
!=
OPUS_
BANDWIDTH_AUTO
)
st
->
bandwidth
=
st
->
user_bandwidth
;
/* Prevents nonsensical configurations, i.e. modes that don't exist */
...
...
@@ -269,11 +269,11 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
st
->
mode
=
MODE_CELT_ONLY
;
if
(
frame_size
>
st
->
Fs
/
50
&&
st
->
mode
!=
MODE_SILK_ONLY
)
st
->
mode
=
MODE_SILK_ONLY
;
if
(
st
->
mode
==
MODE_CELT_ONLY
&&
st
->
bandwidth
==
BANDWIDTH_MEDIUMBAND
)
st
->
bandwidth
=
BANDWIDTH_WIDEBAND
;
if
(
st
->
mode
==
MODE_SILK_ONLY
&&
st
->
bandwidth
>
BANDWIDTH_WIDEBAND
)
if
(
st
->
mode
==
MODE_CELT_ONLY
&&
st
->
bandwidth
==
OPUS_
BANDWIDTH_MEDIUMBAND
)
st
->
bandwidth
=
OPUS_
BANDWIDTH_WIDEBAND
;
if
(
st
->
mode
==
MODE_SILK_ONLY
&&
st
->
bandwidth
>
OPUS_
BANDWIDTH_WIDEBAND
)
st
->
mode
=
MODE_HYBRID
;
if
(
st
->
mode
==
MODE_HYBRID
&&
st
->
bandwidth
<=
BANDWIDTH_WIDEBAND
)
if
(
st
->
mode
==
MODE_HYBRID
&&
st
->
bandwidth
<=
OPUS_
BANDWIDTH_WIDEBAND
)
st
->
mode
=
MODE_SILK_ONLY
;
bytes_target
=
st
->
bitrate_bps
*
frame_size
/
(
st
->
Fs
*
8
)
-
1
;
...
...
@@ -312,7 +312,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
st
->
silk_mode
.
bitRate
=
st
->
bitrate_bps
-
8
*
st
->
Fs
/
frame_size
;
if
(
st
->
mode
==
MODE_HYBRID
)
{
st
->
silk_mode
.
bitRate
/=
st
->
stream_channels
;
if
(
st
->
bandwidth
==
BANDWIDTH_SUPERWIDEBAND
)
{
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_SUPERWIDEBAND
)
{
if
(
st
->
Fs
==
100
*
frame_size
)
{
/* 24 kHz, 10 ms */
st
->
silk_mode
.
bitRate
=
(
(
st
->
silk_mode
.
bitRate
+
2000
+
st
->
use_vbr
*
1000
)
*
2
)
/
3
;
...
...
@@ -339,12 +339,12 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
st
->
silk_mode
.
payloadSize_ms
=
1000
*
frame_size
/
st
->
Fs
;
st
->
silk_mode
.
nChannelsAPI
=
st
->
channels
;
st
->
silk_mode
.
nChannelsInternal
=
st
->
stream_channels
;
if
(
st
->
bandwidth
==
BANDWIDTH_NARROWBAND
)
{
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_NARROWBAND
)
{
st
->
silk_mode
.
desiredInternalSampleRate
=
8000
;
}
else
if
(
st
->
bandwidth
==
BANDWIDTH_MEDIUMBAND
)
{
}
else
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_MEDIUMBAND
)
{
st
->
silk_mode
.
desiredInternalSampleRate
=
12000
;
}
else
{
SKP_assert
(
st
->
mode
==
MODE_HYBRID
||
st
->
bandwidth
==
BANDWIDTH_WIDEBAND
);
SKP_assert
(
st
->
mode
==
MODE_HYBRID
||
st
->
bandwidth
==
OPUS_
BANDWIDTH_WIDEBAND
);
st
->
silk_mode
.
desiredInternalSampleRate
=
16000
;
}
if
(
st
->
mode
==
MODE_HYBRID
)
{
...
...
@@ -373,11 +373,11 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
/* Extract SILK internal bandwidth for signaling in first byte */
if
(
st
->
mode
==
MODE_SILK_ONLY
)
{
if
(
st
->
silk_mode
.
internalSampleRate
==
8000
)
{
silk_internal_bandwidth
=
BANDWIDTH_NARROWBAND
;
silk_internal_bandwidth
=
OPUS_
BANDWIDTH_NARROWBAND
;
}
else
if
(
st
->
silk_mode
.
internalSampleRate
==
12000
)
{
silk_internal_bandwidth
=
BANDWIDTH_MEDIUMBAND
;
silk_internal_bandwidth
=
OPUS_
BANDWIDTH_MEDIUMBAND
;
}
else
if
(
st
->
silk_mode
.
internalSampleRate
==
16000
)
{
silk_internal_bandwidth
=
BANDWIDTH_WIDEBAND
;
silk_internal_bandwidth
=
OPUS_
BANDWIDTH_WIDEBAND
;
}
}
else
{
SKP_assert
(
st
->
silk_mode
.
internalSampleRate
==
16000
);
...
...
@@ -390,16 +390,16 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
switch
(
st
->
bandwidth
)
{
case
BANDWIDTH_NARROWBAND
:
case
OPUS_
BANDWIDTH_NARROWBAND
:
endband
=
13
;
break
;
case
BANDWIDTH_WIDEBAND
:
case
OPUS_
BANDWIDTH_WIDEBAND
:
endband
=
17
;
break
;
case
BANDWIDTH_SUPERWIDEBAND
:
case
OPUS_
BANDWIDTH_SUPERWIDEBAND
:
endband
=
19
;
break
;
case
BANDWIDTH_FULLBAND
:
case
OPUS_
BANDWIDTH_FULLBAND
:
endband
=
21
;
break
;
}
...
...
@@ -557,11 +557,11 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
}
if
(
st
->
mode
==
MODE_SILK_ONLY
)
{
data
[
0
]
=
(
silk_internal_bandwidth
-
BANDWIDTH_NARROWBAND
)
<<
5
;
data
[
0
]
=
(
silk_internal_bandwidth
-
OPUS_
BANDWIDTH_NARROWBAND
)
<<
5
;
data
[
0
]
|=
(
period
-
2
)
<<
3
;
}
else
if
(
st
->
mode
==
MODE_CELT_ONLY
)
{
int
tmp
=
st
->
bandwidth
-
BANDWIDTH_MEDIUMBAND
;
int
tmp
=
st
->
bandwidth
-
OPUS_
BANDWIDTH_MEDIUMBAND
;
if
(
tmp
<
0
)
tmp
=
0
;
data
[
0
]
=
0x80
;
...
...
@@ -570,7 +570,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
}
else
/* Hybrid */
{
data
[
0
]
=
0x60
;
data
[
0
]
|=
(
st
->
bandwidth
-
BANDWIDTH_SUPERWIDEBAND
)
<<
4
;
data
[
0
]
|=
(
st
->
bandwidth
-
OPUS_
BANDWIDTH_SUPERWIDEBAND
)
<<
4
;
data
[
0
]
|=
(
period
-
2
)
<<
3
;
}
data
[
0
]
|=
(
st
->
stream_channels
==
2
)
<<
2
;
...
...
@@ -644,12 +644,12 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
case
OPUS_SET_BANDWIDTH_REQUEST
:
{
int
value
=
va_arg
(
ap
,
int
);
if
(
value
<
BANDWIDTH_AUTO
||
value
>
BANDWIDTH_FULLBAND
)
if
(
value
<
OPUS_
BANDWIDTH_AUTO
||
value
>
OPUS_
BANDWIDTH_FULLBAND
)
return
OPUS_BAD_ARG
;
st
->
user_bandwidth
=
value
;
if
(
st
->
user_bandwidth
==
BANDWIDTH_NARROWBAND
)
{
if
(
st
->
user_bandwidth
==
OPUS_
BANDWIDTH_NARROWBAND
)
{
st
->
silk_mode
.
maxInternalSampleRate
=
8000
;
}
else
if
(
st
->
bandwidth
==
BANDWIDTH_MEDIUMBAND
)
{
}
else
if
(
st
->
bandwidth
==
OPUS_
BANDWIDTH_MEDIUMBAND
)
{
st
->
silk_mode
.
maxInternalSampleRate
=
12000
;
}
else
{
st
->
silk_mode
.
maxInternalSampleRate
=
16000
;
...
...
src/test_opus.c
View file @
541df0a9
...
...
@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
/* defaults: */
use_vbr
=
1
;
bandwidth
=
BANDWIDTH_AUTO
;
bandwidth
=
OPUS_
BANDWIDTH_AUTO
;
internal_sampling_rate_Hz
=
sampling_rate
;
max_payload_bytes
=
MAX_PACKET
;
complexity
=
10
;
...
...
@@ -140,15 +140,15 @@ int main(int argc, char *argv[])
args
++
;
}
else
if
(
STR_CASEINSENSITIVE_COMPARE
(
argv
[
args
],
"-bandwidth"
)
==
0
)
{
if
(
strcmp
(
argv
[
args
+
1
],
"NB"
)
==
0
)
bandwidth
=
BANDWIDTH_NARROWBAND
;
bandwidth
=
OPUS_
BANDWIDTH_NARROWBAND
;
else
if
(
strcmp
(
argv
[
args
+
1
],
"MB"
)
==
0
)
bandwidth
=
BANDWIDTH_MEDIUMBAND
;
bandwidth
=
OPUS_
BANDWIDTH_MEDIUMBAND
;
else
if
(
strcmp
(
argv
[
args
+
1
],
"WB"
)
==
0
)
bandwidth
=
BANDWIDTH_WIDEBAND
;
bandwidth
=
OPUS_
BANDWIDTH_WIDEBAND
;
else
if
(
strcmp
(
argv
[
args
+
1
],
"SWB"
)
==
0
)
bandwidth
=
BANDWIDTH_SUPERWIDEBAND
;
bandwidth
=
OPUS_
BANDWIDTH_SUPERWIDEBAND
;
else
if
(
strcmp
(
argv
[
args
+
1
],
"FB"
)
==
0
)
bandwidth
=
BANDWIDTH_FULLBAND
;
bandwidth
=
OPUS_
BANDWIDTH_FULLBAND
;
else
{
fprintf
(
stderr
,
"Unknown bandwidth %s. Supported are NB, MB, WB, SWB, FB.
\n
"
,
argv
[
args
+
1
]);
return
1
;
...
...
@@ -264,22 +264,22 @@ int main(int argc, char *argv[])
switch
(
bandwidth
)
{
case
BANDWIDTH_NARROWBAND
:
case
OPUS_
BANDWIDTH_NARROWBAND
:
bandwidth_string
=
"narrowband"
;
break
;
case
BANDWIDTH_MEDIUMBAND
:
case
OPUS_
BANDWIDTH_MEDIUMBAND
:
bandwidth_string
=
"mediumband"
;
break
;
case
BANDWIDTH_WIDEBAND
:
case
OPUS_
BANDWIDTH_WIDEBAND
:
bandwidth_string
=
"wideband"
;
break
;
case
BANDWIDTH_SUPERWIDEBAND
:
case
OPUS_
BANDWIDTH_SUPERWIDEBAND
:
bandwidth_string
=
"superwideband"
;
break
;
case
BANDWIDTH_FULLBAND
:
case
OPUS_
BANDWIDTH_FULLBAND
:
bandwidth_string
=
"fullband"
;
break
;
case
BANDWIDTH_AUTO
:
case
OPUS_
BANDWIDTH_AUTO
:
bandwidth_string
=
"auto"
;
break
;
default:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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