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
88832a4d
Commit
88832a4d
authored
12 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #9979: Alaw: cleanup
parent
f621f843
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
daemon/src/audio/codecs/alaw.cpp
+22
-26
22 additions, 26 deletions
daemon/src/audio/codecs/alaw.cpp
with
22 additions
and
26 deletions
daemon/src/audio/codecs/alaw.cpp
+
22
−
26
View file @
88832a4d
...
@@ -37,8 +37,7 @@ class Alaw : public sfl::AudioCodec {
...
@@ -37,8 +37,7 @@ class Alaw : public sfl::AudioCodec {
public:
public:
// 8 PCMA A 8000 1 [RFC3551]
// 8 PCMA A 8000 1 [RFC3551]
Alaw
(
int
payload
=
8
)
Alaw
(
int
payload
=
8
)
:
sfl
::
AudioCodec
(
payload
,
"PCMA"
)
{
:
sfl
::
AudioCodec
(
payload
,
"PCMA"
)
{
clockRate_
=
8000
;
clockRate_
=
8000
;
frameSize_
=
160
;
// samples, 20 ms at 8kHz
frameSize_
=
160
;
// samples, 20 ms at 8kHz
channel_
=
1
;
channel_
=
1
;
...
@@ -46,34 +45,30 @@ class Alaw : public sfl::AudioCodec {
...
@@ -46,34 +45,30 @@ class Alaw : public sfl::AudioCodec {
hasDynamicPayload_
=
false
;
hasDynamicPayload_
=
false
;
}
}
virtual
~
Alaw
()
{}
private
:
virtual
int
decode
(
SFLDataFormat
*
dst
,
unsigned
char
*
src
,
size_t
buf_size
)
virtual
int
decode
(
short
*
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
=
ALawDecode
(
*
src
);
while
(
src
<
end
)
*
dst
++
=
ALawDecode
(
*
src
++
);
return
frameSize_
;
return
frameSize_
;
}
}
virtual
int
encode
(
unsigned
char
*
dst
,
short
*
src
,
size_t
buf_size
)
{
virtual
int
encode
(
unsigned
char
*
dst
,
SFLDataFormat
*
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
(
unsigned
char
*
end
=
dst
+
frameSize_
;
dst
<
end
;
++
src
,
++
dst
)
*
dst
=
ALawEncode
(
*
src
);
while
(
dst
<
end
)
*
dst
++
=
ALawEncode
(
*
src
++
);
return
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
);
return
frameSize_
/
2
/* compression factor = 2:1 */
*
sizeof
(
SFLDataFormat
);
}
}
int
ALawDecode
(
uint8
alaw
)
{
int
ALawDecode
(
uint8
alaw
)
{
alaw
^=
0x55
;
// A-law has alternate bits inverted for transmission
alaw
^=
0x55
;
// A-law has alternate bits inverted for transmission
uint
sign
=
alaw
&
0x80
;
uint
sign
=
alaw
&
0x80
;
int
linear
=
alaw
&
0x1f
;
int
linear
=
alaw
&
0x1f
;
linear
<<=
4
;
linear
<<=
4
;
linear
+=
8
;
// Add a 'half' bit (0x08) to place PCM value in middle of range
linear
+=
8
;
// Add a 'half' bit (0x08) to place PCM value in middle of range
...
@@ -91,8 +86,8 @@ class Alaw : public sfl::AudioCodec {
...
@@ -91,8 +86,8 @@ class Alaw : public sfl::AudioCodec {
return
linear
;
return
linear
;
}
}
uint8
ALawEncode
(
SFLDataFormat
pcm16
)
uint8
ALawEncode
(
int16
pcm16
)
{
{
int
p
=
pcm16
;
int
p
=
pcm16
;
uint
a
;
// u-law value we are forming
uint
a
;
// u-law value we are forming
...
@@ -107,18 +102,18 @@ class Alaw : public sfl::AudioCodec {
...
@@ -107,18 +102,18 @@ class Alaw : public sfl::AudioCodec {
//calculate segment and interval numbers
//calculate segment and interval numbers
p
>>=
4
;
p
>>=
4
;
if
(
p
>=
0x20
)
{
if
(
p
>=
0x20
)
{
if
(
p
>=
0x100
)
{
if
(
p
>=
0x100
)
{
p
>>=
4
;
p
>>=
4
;
a
+=
0x40
;
a
+=
0x40
;
}
}
if
(
p
>=
0x40
)
{
if
(
p
>=
0x40
)
{
p
>>=
2
;
p
>>=
2
;
a
+=
0x20
;
a
+=
0x20
;
}
}
if
(
p
>=
0x20
)
{
if
(
p
>=
0x20
)
{
p
>>=
1
;
p
>>=
1
;
a
+=
0x10
;
a
+=
0x10
;
}
}
...
@@ -127,7 +122,8 @@ class Alaw : public sfl::AudioCodec {
...
@@ -127,7 +122,8 @@ class Alaw : public sfl::AudioCodec {
// a&0x70 now holds segment value and 'p' the interval number
// a&0x70 now holds segment value and 'p' the interval number
a
+=
p
;
// a now equal to encoded A-law value
a
+=
p
;
// a now equal to encoded A-law value
return
a
^
0x55
;
// A-law has alternate bits inverted for transmission
// A-law has alternate bits inverted for transmission
return
a
^
0x55
;
}
}
};
};
...
...
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