Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
41d62ad1
Commit
41d62ad1
authored
12 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #9979: ulaw: normalize types
parent
ca4fb50b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
daemon/src/audio/codecs/ulaw.cpp
+20
-22
20 additions, 22 deletions
daemon/src/audio/codecs/ulaw.cpp
with
20 additions
and
22 deletions
daemon/src/audio/codecs/ulaw.cpp
+
20
−
22
View file @
41d62ad1
...
@@ -44,73 +44,71 @@ class Ulaw : public sfl::AudioCodec {
...
@@ -44,73 +44,71 @@ class Ulaw : public sfl::AudioCodec {
hasDynamicPayload_
=
false
;
hasDynamicPayload_
=
false
;
}
}
virtual
int
decode
(
shor
t
*
dst
,
unsigned
char
*
src
,
size_t
buf_size
)
{
virtual
int
decode
(
SFLDataForma
t
*
dst
,
unsigned
char
*
src
,
size_t
buf_size
)
{
assert
(
buf_size
==
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
));
assert
(
buf_size
==
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
));
unsigned
char
*
end
=
src
+
buf_size
;
for
(
unsigned
char
*
end
=
src
+
buf_size
;
src
<
end
;
++
src
,
++
dst
)
*
dst
=
ULawDecode
(
*
src
);
while
(
src
<
end
)
*
dst
++
=
ULawDecode
(
*
src
++
);
return
frameSize_
;
return
frameSize_
;
}
}
virtual
int
encode
(
unsigned
char
*
dst
,
shor
t
*
src
,
size_t
buf_size
)
{
virtual
int
encode
(
unsigned
char
*
dst
,
SFLDataForma
t
*
src
,
size_t
buf_size
)
{
assert
(
buf_size
>=
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
));
assert
(
buf_size
>=
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
));
uint8
*
end
=
dst
+
frameSize_
;
for
(
uint8
*
end
=
dst
+
frameSize_
;
dst
<
end
;
++
src
,
++
dst
)
*
dst
=
ULawEncode
(
*
src
);
while
(
dst
<
end
)
*
dst
++
=
ULawEncode
(
*
src
++
);
return
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
);;
return
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
);;
}
}
int
ULawDecode
(
uint8
ulaw
)
{
SFLDataFormat
ULawDecode
(
uint8
ulaw
)
{
ulaw
^=
0xff
;
// u-law has all bits inverted for transmission
ulaw
^=
0xff
;
// u-law has all bits inverted for transmission
int
linear
=
ulaw
&
0x0f
;
int
linear
=
ulaw
&
0x0f
;
linear
<<=
3
;
linear
<<=
3
;
linear
|=
0x84
;
// Set MSB (0x80) and a 'half' bit (0x04) to place PCM value in middle of range
linear
|=
0x84
;
// Set MSB (0x80) and a 'half' bit (0x04) to place PCM value in middle of range
uint
shift
=
ulaw
>>
4
;
uint
shift
=
ulaw
>>
4
;
shift
&=
7
;
shift
&=
7
;
linear
<<=
shift
;
linear
<<=
shift
;
linear
-=
0x84
;
// Subract uLaw bias
linear
-=
0x84
;
// Subract uLaw bias
if
(
ulaw
&
0x80
)
if
(
ulaw
&
0x80
)
return
-
linear
;
return
-
linear
;
else
else
return
linear
;
return
linear
;
}
}
uint8
ULawEncode
(
int16
pcm16
)
{
uint8
ULawEncode
(
SFLDataFormat
pcm16
)
{
int
p
=
pcm16
;
int
p
=
pcm16
;
uint
u
;
// u-law value we are forming
uint
u
;
// u-law value we are forming
if
(
p
<
0
)
{
if
(
p
<
0
)
{
p
=
~
p
;
p
=
~
p
;
u
=
0x80
^
0x10
^
0xff
;
// Sign bit = 1 (^0x10 because this will get inverted later) ^0xff ^0xff to invert final u-Law code
u
=
0x80
^
0x10
^
0xff
;
// Sign bit = 1 (^0x10 because this will get inverted later) ^0xff ^0xff to invert final u-Law code
}
else
{
}
else
{
u
=
0x00
^
0x10
^
0xff
;
// Sign bit = 0 (-0x10 because this amount extra will get added later) ^0xff to invert final u-Law code
u
=
0x00
^
0x10
^
0xff
;
// Sign bit = 0 (-0x10 because this amount extra will get added later) ^0xff to invert final u-Law code
}
}
p
+=
0x84
;
// Add uLaw bias
p
+=
0x84
;
// Add uLaw bias
if
(
p
>
0x7f00
)
if
(
p
>
0x7f00
)
p
=
0x7f00
;
// Clip to 15 bits
p
=
0x7f00
;
// Clip to 15 bits
// Calculate segment and interval numbers
// Calculate segment and interval numbers
p
>>=
3
;
// Shift down to 13bit
p
>>=
3
;
// Shift down to 13bit
if
(
p
>=
0x100
)
{
if
(
p
>=
0x100
)
{
p
>>=
4
;
p
>>=
4
;
u
^=
0x40
;
u
^=
0x40
;
}
}
if
(
p
>=
0x40
)
{
if
(
p
>=
0x40
)
{
p
>>=
2
;
p
>>=
2
;
u
^=
0x20
;
u
^=
0x20
;
}
}
if
(
p
>=
0x20
)
{
if
(
p
>=
0x20
)
{
p
>>=
1
;
p
>>=
1
;
u
^=
0x10
;
u
^=
0x10
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment