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
b2497fed
Commit
b2497fed
authored
14 years ago
by
Alexandre Savard
Browse files
Options
Downloads
Patches
Plain Diff
[#1966] Very good echo canceller settings
parent
5413ba6a
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/echocancel.cpp
+26
-72
26 additions, 72 deletions
sflphone-common/src/audio/echocancel.cpp
sflphone-common/src/audio/echocancel.h
+4
-4
4 additions, 4 deletions
sflphone-common/src/audio/echocancel.h
with
30 additions
and
76 deletions
sflphone-common/src/audio/echocancel.cpp
+
26
−
72
View file @
b2497fed
...
...
@@ -32,8 +32,6 @@
// #include <fstream>
#define MICDELAY 32000
EchoCancel
::
EchoCancel
(
int
smplRate
,
int
frameLength
)
:
_samplingRate
(
smplRate
),
_frameLength
(
frameLength
),
_smplPerFrame
(
0
),
...
...
@@ -61,14 +59,12 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
{
_debug
(
"EchoCancel: Instantiate echo canceller"
);
/*
micFile
=
new
ofstream
(
"micData"
,
ofstream
::
binary
);
echoFile
=
new
ofstream
(
"echoData"
,
ofstream
::
binary
);
spkrFile
=
new
ofstream
(
"spkrData"
,
ofstream
::
binary
);
micLevelData = new ofstream("micLevelData", ofstream:binary);
micLevelData
=
new
ofstream
(
"micLevelData"
,
ofstream
:
:
binary
);
spkrLevelData
=
new
ofstream
(
"spkrLevelData"
,
ofstream
::
binary
);
*/
_micData
=
new
RingBuffer
(
50000
);
_spkrData
=
new
RingBuffer
(
50000
);
...
...
@@ -87,7 +83,6 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_spkrHistoryLength
=
SPKR_LENGTH
/
SEGMENT_LENGTH
;
_nbSegmentPerFrame
=
_frameLength
/
SEGMENT_LENGTH
;
_noiseState
=
speex_preprocess_state_init
(
_smplPerFrame
,
_samplingRate
);
int
i
=
1
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DENOISE
,
&
i
);
...
...
@@ -97,9 +92,9 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_AGC_LEVEL
,
&
i
);
i
=
0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB
,
&
i
);
float
f
=
.0
;
float
f
=
0
.0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB_DECAY
,
&
f
);
f
=
.0
;
f
=
0
.0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB_LEVEL
,
&
f
);
memset
(
_avgSpkrLevelHist
,
0
,
BUFF_SIZE
*
sizeof
(
int
));
...
...
@@ -126,7 +121,6 @@ EchoCancel::~EchoCancel()
speex_preprocess_state_destroy
(
_noiseState
);
/*
micFile
->
close
();
spkrFile
->
close
();
echoFile
->
close
();
...
...
@@ -139,7 +133,7 @@ EchoCancel::~EchoCancel()
spkrLevelData
->
close
();
delete
micLevelData
;
delete
spkrLevelData
;
*/
}
...
...
@@ -168,7 +162,7 @@ void EchoCancel::reset()
memset
(
_delayLineAmplify
,
0
,
MAX_DELAY_LINE_AMPL
*
sizeof
(
float
));
_amplDelayIndexIn
=
0
;
_amplDelayIndexOut
=
100
;
_amplDelayIndexOut
=
ECHO_LENGTH
/
SEGMENT_LENGTH
;
_adaptDone
=
false
;
_adaptStarted
=
false
;
...
...
@@ -180,13 +174,6 @@ void EchoCancel::reset()
_spkrData
->
flushAll
();
_spkrDataOut
->
flushAll
();
/*
SFLDataFormat delay[MICDELAY];
memset(delay, 0, sizeof(SFLDataFormat));
_micData->Put(delay, MICDELAY*2);
*/
speex_preprocess_state_destroy
(
_noiseState
);
_noiseState
=
speex_preprocess_state_init
(
_smplPerFrame
,
_samplingRate
);
...
...
@@ -286,23 +273,16 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
_spkrData
->
Get
(
_tmpSpkr
,
byteSize
);
_micData
->
Get
(
_tmpMic
,
byteSize
);
//
micFile->write((const char *)_tmpMic, byteSize);
//
spkrFile->write((const char *)_tmpSpkr, byteSize);
micFile
->
write
((
const
char
*
)
_tmpMic
,
byteSize
);
spkrFile
->
write
((
const
char
*
)
_tmpSpkr
,
byteSize
);
/*
while((computeAmplitudeLevel(_tmpSpkr, _smplPerFrame) < MIN_SIG_LEVEL) && (spkrAvail >= byteSize)) {
_spkrData->Get(_tmpSpkr, byteSize);
spkrAvail = _spkrData->AvailForGet();
}
*/
// Remove noise
speex_preprocess_run
(
_noiseState
,
_tmpMic
);
// Processed echo cancellation
performEchoCancel
(
_tmpMic
,
_tmpSpkr
,
_tmpOut
);
// echoFile->write((const char *)_tmpOut, byteSize);
// Remove noise
speex_preprocess_run
(
_noiseState
,
_tmpOut
);
echoFile
->
write
((
const
char
*
)
_tmpOut
,
byteSize
);
bcopy
(
_tmpOut
,
outputData
+
(
nbFrame
*
_smplPerFrame
),
byteSize
);
...
...
@@ -339,8 +319,8 @@ void EchoCancel::setSamplingRate(int smplRate) {
void
EchoCancel
::
performEchoCancel
(
SFLDataFormat
*
micData
,
SFLDataFormat
*
spkrData
,
SFLDataFormat
*
outputData
)
{
//
int tempmiclevel[_nbSegmentPerFrame];
//
int tempspkrlevel[_nbSegmentPerFrame];
int
tempmiclevel
[
_nbSegmentPerFrame
];
int
tempspkrlevel
[
_nbSegmentPerFrame
];
for
(
int
k
=
0
;
k
<
_nbSegmentPerFrame
;
k
++
)
{
...
...
@@ -352,43 +332,20 @@ void EchoCancel::performEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDa
// _debug("_spkrLevel: (max): %d", _spkrLevel);
// _debug("_micLevel: (min): %d", _micLevel);
// tempspkrlevel[k] = _spkrLevel;
// tempmiclevel[k] = _micLevel;
/*
if(_micLevel >= MIN_SIG_LEVEL) {
if(_spkrLevel < MIN_SIG_LEVEL) {
increaseFactor(0.02);
}
else if(_micLevel > _spkrLevel) {
increaseFactor(0.05);
}
else {
// decreaseFactor();
_amplFactor = 0.0;
_debug("CANCELECHO AAAAAA");
}
}
else {
if(_spkrLevel < MIN_SIG_LEVEL) {
increaseFactor(0.02);
// _amplFactor = 0.0;
// _debug("CANCELECHO BBBBBBB");
}
else {
// decreaseFactor();
_amplFactor = 0.0;
_debug("CANCELECHO CCCCCCCC");
}
}
*/
tempspkrlevel
[
k
]
=
_spkrLevel
;
tempmiclevel
[
k
]
=
_micLevel
;
if
(
_spkrLevel
>=
MIN_SIG_LEVEL
)
{
_amplFactor
=
0.0
;
if
(
_micLevel
>
_spkrLevel
)
{
increaseFactor
(
0.2
);
// _amplFactor = 0.0;
}
else
{
_amplFactor
=
0.0
;
}
}
else
{
increaseFactor
(
0.0
2
);
increaseFactor
(
0.0
1
);
}
// lowpass filtering
...
...
@@ -401,24 +358,21 @@ void EchoCancel::performEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDa
}
//
micLevelData->write((const char *)tempmiclevel, sizeof(int)*_nbSegmentPerFrame);
//
spkrLevelData->write((const char *)tempspkrlevel, sizeof(int)*_nbSegmentPerFrame);
micLevelData
->
write
((
const
char
*
)
tempmiclevel
,
sizeof
(
int
)
*
_nbSegmentPerFrame
);
spkrLevelData
->
write
((
const
char
*
)
tempspkrlevel
,
sizeof
(
int
)
*
_nbSegmentPerFrame
);
}
void
EchoCancel
::
updateEchoCancel
(
SFLDataFormat
*
micData
,
SFLDataFormat
*
spkrData
)
{
int
micLvl
=
computeAmplitudeLevel
(
micData
,
_smplPerSeg
);
// TODO: we should find a way to normalize signal at this point
int
micLvl
=
computeAmplitudeLevel
(
micData
,
_smplPerSeg
)
/
10
;
int
spkrLvl
=
computeAmplitudeLevel
(
spkrData
,
_smplPerSeg
);
// Add 1 to make sure we are not dividing by 0
_avgMicLevelHist
[
_micHistCnt
++
]
=
micLvl
+
1
;
_avgSpkrLevelHist
[
_spkrHistCnt
++
]
=
spkrLvl
+
1
;
// spkrLevelData->write((const char *)_spkrAdaptArray, _spkrAdaptSize*sizeof(int));
// micLevelData->write((const char *)_micAdaptArray, _micAdaptSize*sizeof(int));
// _debug("micLevel: %d", micLvl);
// _debug("spkrLevel: %d", spkrLvl);
...
...
This diff is collapsed.
Click to expand it.
sflphone-common/src/audio/echocancel.h
+
4
−
4
View file @
b2497fed
...
...
@@ -44,15 +44,15 @@
#define SEGMENT_LENGTH 10
// Length of the echo tail in ms
#define ECHO_LENGTH
5
0
#define SPKR_LENGTH
5
0
#define MIC_LENGTH
5
0
#define ECHO_LENGTH
100
0
#define SPKR_LENGTH
8
0
#define MIC_LENGTH
8
0
// Voice level threashold
#define MIN_SIG_LEVEL 75
// Delay between mic and speaker
#define DELAY_AMPLIFY 60
//
#define DELAY_AMPLIFY 60
// maximum in segment size (segment are SEGMENT_LENGTH long)
#define MAX_DELAY_LINE_AMPL 100 // 1 sec
...
...
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