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
22c277bc
Commit
22c277bc
authored
13 years ago
by
Alexandre Savard
Browse files
Options
Downloads
Patches
Plain Diff
#5916: Add gaincontrol files
parent
1ec1ffb5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sflphone-common/src/audio/gaincontrol.cpp
+72
-0
72 additions, 0 deletions
sflphone-common/src/audio/gaincontrol.cpp
sflphone-common/src/audio/gaincontrol.h
+84
-0
84 additions, 0 deletions
sflphone-common/src/audio/gaincontrol.h
with
156 additions
and
0 deletions
sflphone-common/src/audio/gaincontrol.cpp
0 → 100644
+
72
−
0
View file @
22c277bc
#include
<math.h>
#include
<limits.h>
#include
<fstream>
#include
<iostream>
#include
"global.h"
#include
"gaincontrol.h"
#define SFL_GAIN_ATTACK_RELEASE_TIME 10
#define SFL_GAIN_LIMITER_RATIO 0.1
#define SFL_GAIN_LIMITER_THRESHOLD 0.6
GainControl
::
GainControl
(
double
sr
)
:
averager
(
sr
,
SFL_GAIN_ATTACK_RELEASE_TIME
)
,
limiter
(
SFL_GAIN_LIMITER_RATIO
,
SFL_GAIN_LIMITER_THRESHOLD
)
{}
GainControl
::~
GainControl
()
{}
std
::
fstream
tmpRms
(
"testrms.raw"
,
std
::
fstream
::
out
);
void
GainControl
::
process
(
SFLDataFormat
*
inBuf
,
SFLDataFormat
*
outBuf
,
int
bufLength
)
{
double
rms
,
rmsAvg
,
in
,
out
;
for
(
int
i
=
0
;
i
<
bufLength
;
i
++
)
{
in
=
(
double
)
inBuf
[
i
]
/
(
double
)
SHRT_MAX
;
rms
=
detector
.
getRms
(
in
);
rmsAvg
=
sqrt
(
averager
.
getAverage
(
rms
));
tmpRms
.
write
(
reinterpret_cast
<
char
*>
(
&
rmsAvg
),
sizeof
(
double
));
out
=
limiter
.
limit
(
in
);
outBuf
[
i
]
=
(
short
)(
out
*
(
double
)
SHRT_MAX
);
}
}
GainControl
::
RmsDetection
::
RmsDetection
()
{}
double
GainControl
::
RmsDetection
::
getRms
(
double
in
)
{
return
in
*
in
;
}
GainControl
::
DetectionAverage
::
DetectionAverage
(
double
sr
,
double
t
)
:
g
(
0.0
),
teta
(
t
),
samplingRate
(
sr
),
previous_y
(
0.0
)
{
g
=
exp
(
-
1.0
/
(
samplingRate
*
(
teta
/
1000.0
)));
std
::
cout
<<
"GainControl: g: "
<<
g
<<
", teta: "
<<
teta
<<
std
::
endl
;
}
double
GainControl
::
DetectionAverage
::
getAverage
(
double
in
)
{
previous_y
=
((
1.0
-
g
)
*
in
)
+
(
g
*
previous_y
);
return
previous_y
;
}
GainControl
::
Limiter
::
Limiter
(
double
r
,
double
thresh
)
:
ratio
(
r
),
threshold
(
thresh
)
{
std
::
cout
<<
"GainControl: limiter threshold: "
<<
threshold
<<
std
::
endl
;
}
double
GainControl
::
Limiter
::
limit
(
double
in
)
{
double
out
;
out
=
(
in
>
threshold
?
(
ratio
*
(
in
-
threshold
))
+
threshold
:
in
<
-
threshold
?
(
ratio
*
(
in
+
threshold
))
-
threshold
:
in
);
return
out
;
}
This diff is collapsed.
Click to expand it.
sflphone-common/src/audio/gaincontrol.h
0 → 100644
+
84
−
0
View file @
22c277bc
#ifndef GAINCONTROL_H
#define GAINCONTROL_H
#include
"global.h"
#define SFL_GAIN_BUFFER_LENGTH 160
class
GainControl
{
public:
GainControl
(
double
);
~
GainControl
(
void
);
void
process
(
SFLDataFormat
*
,
SFLDataFormat
*
,
int
);
private:
class
RmsDetection
{
public:
/**
* Constructor for this class
*/
RmsDetection
(
void
);
/**
* Get rms value
*/
double
getRms
(
double
);
};
class
DetectionAverage
{
public:
/**
* Constructor for this class
*/
DetectionAverage
(
double
,
double
);
/**
* Process average
*/
double
getAverage
(
double
);
private:
/**
* Average factor
*/
double
g
;
/**
* Attack and release ramp time (in ms)
*/
double
teta
;
/**
* Samplig rate
*/
double
samplingRate
;
/**
* Previous gain (first order memory)
*/
double
previous_y
;
};
class
Limiter
{
public:
Limiter
(
double
,
double
);
double
limit
(
double
);
private:
double
ratio
;
double
threshold
;
};
RmsDetection
detector
;
DetectionAverage
averager
;
Limiter
limiter
;
};
#endif // GAINCONTROL_H
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