Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
20658dad
Commit
20658dad
authored
Jun 14, 2010
by
Alexandre Savard
Browse files
[#3507] Add downsampling decimation filter
parent
d7a2b23d
Changes
2
Hide whitespace changes
Inline
Side-by-side
sflphone-common/src/audio/delaydetection.cpp
View file @
20658dad
...
@@ -40,13 +40,13 @@ FirFilter::FirFilter(std::vector<double> ir) : _impulseResponse(ir),
...
@@ -40,13 +40,13 @@ FirFilter::FirFilter(std::vector<double> ir) : _impulseResponse(ir),
FirFilter
::~
FirFilter
()
{}
FirFilter
::~
FirFilter
()
{}
in
t
FirFilter
::
getOutputSample
(
in
t
inputSample
)
floa
t
FirFilter
::
getOutputSample
(
floa
t
inputSample
)
{
{
_
delayLine
[
_count
]
=
(
double
)
inputSample
;
_
taps
[
_count
]
=
inputSample
;
double
result
=
0.0
;
double
result
=
0.0
;
int
index
=
_count
;
int
index
=
_count
;
for
(
int
i
=
0
;
i
<
_length
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_length
;
i
++
)
{
result
=
result
+
_impulseResponse
[
i
]
*
_
delayLine
[
index
--
];
result
=
result
+
_impulseResponse
[
i
]
*
_
taps
[
index
--
];
if
(
index
<
0
)
if
(
index
<
0
)
index
=
_length
-
1
;
index
=
_length
-
1
;
}
}
...
@@ -54,17 +54,28 @@ int FirFilter::getOutputSample(int inputSample)
...
@@ -54,17 +54,28 @@ int FirFilter::getOutputSample(int inputSample)
if
(
_count
>=
_length
)
if
(
_count
>=
_length
)
_count
=
0
;
_count
=
0
;
return
(
int
)
result
;
return
result
;
}
}
DelayDetection
::
DelayDetection
(
)
{}
DelayDetection
::
DelayDetection
(
std
::
vector
<
double
>
ir
)
:
_decimationFilter
(
ir
)
{}
DelayDetection
::~
DelayDetection
(){}
DelayDetection
::~
DelayDetection
(){}
void
DelayDetection
::
reset
()
{}
void
DelayDetection
::
reset
()
{}
void
DelayDetection
::
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
{}
void
DelayDetection
::
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
{
int
nbSamples
=
nbBytes
/
sizeof
(
SFLDataFormat
);
float
tmp
[
nbSamples
];
float
down
[
nbSamples
];
convertInt16ToFloat32
(
inputData
,
tmp
,
nbSamples
);
downsampleData
(
tmp
,
down
,
nbSamples
,
8
);
}
int
DelayDetection
::
getData
(
SFLDataFormat
*
outputData
)
{
return
0
;
}
int
DelayDetection
::
getData
(
SFLDataFormat
*
outputData
)
{
return
0
;
}
...
@@ -120,6 +131,7 @@ void DelayDetection::crossCorrelate(double *ref, double *seg, double *res, short
...
@@ -120,6 +131,7 @@ void DelayDetection::crossCorrelate(double *ref, double *seg, double *res, short
++
i
;
++
i
;
}
}
}
}
double
DelayDetection
::
correlate
(
double
*
sig1
,
double
*
sig2
,
short
size
)
{
double
DelayDetection
::
correlate
(
double
*
sig1
,
double
*
sig2
,
short
size
)
{
short
s
=
size
;
short
s
=
size
;
...
@@ -130,3 +142,33 @@ double DelayDetection::correlate(double *sig1, double *sig2, short size) {
...
@@ -130,3 +142,33 @@ double DelayDetection::correlate(double *sig1, double *sig2, short size) {
return
ac
;
return
ac
;
}
}
void
DelayDetection
::
convertInt16ToFloat32
(
SFLDataFormat
*
input
,
float
*
output
,
int
nbSamples
)
{
// factor is 1/(2^15), used to rescale the short int range to the
// [-1.0 - 1.0] float range.
#define S2F_FACTOR .000030517578125f;
int
len
=
nbSamples
;
while
(
len
)
{
len
--
;
output
[
len
]
=
(
float
)
input
[
len
]
*
S2F_FACTOR
;
}
}
void
DelayDetection
::
downsampleData
(
float
*
input
,
float
*
output
,
int
nbSamples
,
int
factor
)
{
float
tmp
[
nbSamples
];
for
(
int
i
=
0
;
i
<
nbSamples
;
i
++
)
{
tmp
[
i
]
=
_decimationFilter
.
getOutputSample
(
input
[
i
]);
}
for
(
int
i
=
0
;
i
<
nbSamples
;
i
+=
factor
)
{
output
[
i
]
=
tmp
[
i
];
}
}
sflphone-common/src/audio/delaydetection.h
View file @
20658dad
...
@@ -40,6 +40,9 @@
...
@@ -40,6 +40,9 @@
// Segment length in ms for correlation
// Segment length in ms for correlation
#define MAX_DELAY 150
#define MAX_DELAY 150
// Size of internal buffers in samples
#define DELAY_BUFF_SIZE 150*8000/1000
#define MAXFILTERSIZE 100
#define MAXFILTERSIZE 100
class
FirFilter
{
class
FirFilter
{
...
@@ -56,6 +59,11 @@ class FirFilter {
...
@@ -56,6 +59,11 @@ class FirFilter {
*/
*/
~
FirFilter
();
~
FirFilter
();
/**
* Perform filtering on one sample
*/
float
getOutputSample
(
float
inputSample
);
private:
private:
...
@@ -72,17 +80,12 @@ class FirFilter {
...
@@ -72,17 +80,12 @@ class FirFilter {
/**
/**
* Circular buffer
* Circular buffer
*/
*/
double
_
delayLine
[
MAXFILTERSIZE
];
double
_
taps
[
MAXFILTERSIZE
];
/**
/**
* Counter
* Counter
*/
*/
int
_count
;
int
_count
;
/**
* Perform filtering on one sample
*/
int
getOutputSample
(
int
inputSample
);
};
};
...
@@ -91,7 +94,7 @@ class DelayDetection : public Algorithm {
...
@@ -91,7 +94,7 @@ class DelayDetection : public Algorithm {
public:
public:
DelayDetection
();
DelayDetection
(
std
::
vector
<
double
>
ir
);
~
DelayDetection
();
~
DelayDetection
();
...
@@ -119,6 +122,10 @@ class DelayDetection : public Algorithm {
...
@@ -119,6 +122,10 @@ class DelayDetection : public Algorithm {
*/
*/
double
correlate
(
double
*
sig1
,
double
*
sig2
,
short
size
);
double
correlate
(
double
*
sig1
,
double
*
sig2
,
short
size
);
void
convertInt16ToFloat32
(
SFLDataFormat
*
input
,
float
*
ouput
,
int
nbSamples
);
void
downsampleData
(
float
*
input
,
float
*
output
,
int
nbSamples
,
int
factor
);
/**
/**
* Segment size in samples for correlation
* Segment size in samples for correlation
*/
*/
...
@@ -129,6 +136,22 @@ class DelayDetection : public Algorithm {
...
@@ -129,6 +136,22 @@ class DelayDetection : public Algorithm {
*/
*/
short
_correlationSize
;
short
_correlationSize
;
float
_spkrReference
[
DELAY_BUFF_SIZE
];
float
_capturedData
[
DELAY_BUFF_SIZE
];
float
_spkrReferenceDown
[
DELAY_BUFF_SIZE
];
float
_captureDataDown
[
DELAY_BUFF_SIZE
];
float
_spkrReferenceFilter
[
DELAY_BUFF_SIZE
];
float
_captureDataFilter
[
DELAY_BUFF_SIZE
];
// int myints[] = {16,2,77,29};
// vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
FirFilter
_decimationFilter
;
public:
public:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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