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
f8206833
Commit
f8206833
authored
Sep 01, 2011
by
Rafaël Carré
Browse files
* #6629 : remove unused Algorithm interface
Update audio filters accordingly
parent
dbd91c44
Changes
18
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/Makefile.am
View file @
f8206833
...
...
@@ -31,7 +31,6 @@ noinst_HEADERS = \
audiorecorder.h
\
audiolayer.h
\
recordable.h
\
algorithm.h
\
delaydetection.h
\
echocancel.h
\
echosuppress.h
\
...
...
daemon/src/audio/algorithm.h
deleted
100644 → 0
View file @
dbd91c44
/*
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include "global.h"
/**
* \class Algorithm
*
* Abstract interface used to implement audio processing algorithm
*/
class
Algorithm
{
public:
virtual
void
reset
(
void
)
=
0
;
/**
* Put data to be processed
*/
virtual
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
=
0
;
/**
*
*/
virtual
int
getData
(
SFLDataFormat
*
outputData
)
=
0
;
/**
* Class implementing this interface must define this function
* for audio processing that require synchronization between spkrdata and
*/
virtual
void
process
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
=
0
;
/**
* Class implementing this interface must define this function
* for audio processing that require synchronization between spkrdata and
*/
virtual
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
)
=
0
;
/*
* Ensure that implementors of this interface will be deleted properly
* if we delete them via a pointer to their base class.
*/
virtual
~
Algorithm
()
{};
};
#endif
daemon/src/audio/alsa/alsalayer.cpp
View file @
f8206833
...
...
@@ -542,14 +542,12 @@ void AlsaLayer::capture(void)
int
outBytes
=
outSamples
*
sizeof
(
SFLDataFormat
);
SFLDataFormat
*
rsmpl_out
=
(
SFLDataFormat
*
)
malloc
(
outBytes
);
converter_
->
resample
(
(
SFLDataFormat
*
)
in
,
rsmpl_out
,
mainBufferSampleRate
,
audioSampleRate_
,
toGetSamples
);
dcblocker_
.
process
(
rsmpl_out
,
outByt
es
);
dcblocker_
.
process
(
rsmpl_out
,
rsmpl_out
,
outSampl
es
);
getMainBuffer
()
->
putData
(
rsmpl_out
,
outBytes
);
free
(
rsmpl_out
);
}
else
{
SFLDataFormat
*
filter_out
=
(
SFLDataFormat
*
)
malloc
(
toGetBytes
);
dcblocker_
.
process
(
in
,
filter_out
,
toGetBytes
);
getMainBuffer
()
->
putData
(
filter_out
,
toGetBytes
);
free
(
filter_out
);
dcblocker_
.
process
(
in
,
in
,
toGetSamples
);
getMainBuffer
()
->
putData
(
in
,
toGetBytes
);
}
end:
...
...
daemon/src/audio/audioloop.cpp
View file @
f8206833
...
...
@@ -43,13 +43,11 @@ AudioLoop::AudioLoop() :_buffer (0), _size (0), _pos (0), _sampleRate (0)
AudioLoop
::~
AudioLoop
()
{
delete
[]
_buffer
;
_buffer
=
0
;
}
void
AudioLoop
::
getNext
(
SFLDataFormat
*
output
,
int
samples
,
short
volume
)
AudioLoop
::
getNext
(
SFLDataFormat
*
output
,
int
total_
samples
,
short
volume
)
{
int
block
;
int
pos
=
_pos
;
if
(
_size
==
0
)
{
...
...
@@ -57,28 +55,28 @@ AudioLoop::getNext (SFLDataFormat* output, int samples, short volume)
return
;
}
while
(
samples
)
{
block
=
samples
;
while
(
total_
samples
)
{
int
samples
=
total_
samples
;
if
(
block
>
(
_size
-
pos
))
{
block
=
_size
-
pos
;
if
(
samples
>
(
_size
-
pos
))
{
samples
=
_size
-
pos
;
}
memcpy
(
output
,
_buffer
+
pos
,
block
*
sizeof
(
SFLDataFormat
));
// short>char conversion
memcpy
(
output
,
_buffer
+
pos
,
samples
*
sizeof
(
SFLDataFormat
));
// short>char conversion
if
(
volume
!=
100
)
{
for
(
int
i
=
0
;
i
<
block
;
i
++
)
{
for
(
int
i
=
0
;
i
<
samples
;
i
++
)
{
*
output
=
(
*
output
*
volume
)
/
100
;
output
++
;
}
}
else
{
output
+=
block
;
// this is the destination...
output
+=
samples
;
// this is the destination...
}
// should adjust sound here, in output???
pos
=
(
pos
+
block
)
%
_size
;
pos
=
(
pos
+
samples
)
%
_size
;
samples
-=
block
;
total_
samples
-=
samples
;
}
_pos
=
pos
;
...
...
daemon/src/audio/dcblocker.cpp
View file @
f8206833
...
...
@@ -42,34 +42,15 @@ void DcBlocker::reset()
_ym1
=
0
;
}
void
DcBlocker
::
putData
(
SFLDataFormat
*
inputData
UNUSED
,
int
nbBytes
UNUSED
)
{}
int
DcBlocker
::
getData
(
SFLDataFormat
*
outputData
UNUSED
)
{
return
0
;
}
void
DcBlocker
::
process
(
SFLDataFormat
*
data
,
int
nbBytes
)
{
abort
();
// use the 3 args prototype with input == output
}
int
DcBlocker
::
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
)
void
DcBlocker
::
process
(
SFLDataFormat
*
out
,
SFLDataFormat
*
in
,
int
samples
)
{
for
(
int
i
=
0
;
i
<
samples
;
i
++
)
{
_x
=
in
[
i
];
int
nbSamples
=
nbBytes
/
sizeof
(
SFLDataFormat
);
for
(
int
i
=
0
;
i
<
nbSamples
;
i
++
)
{
_x
=
inputData
[
i
];
_y
=
(
SFLDataFormat
)
(
(
float
)
_x
-
(
float
)
_xm1
+
0.9999
*
(
float
)
_ym1
);
_y
=
(
SFLDataFormat
)
(
(
float
)
_x
-
(
float
)
_xm1
+
0.9999
*
(
float
)
_y
);
_xm1
=
_x
;
_ym1
=
_y
;
out
putData
[
i
]
=
_y
;
out
[
i
]
=
_y
;
}
return
0
;
}
daemon/src/audio/dcblocker.h
View file @
f8206833
...
...
@@ -31,12 +31,9 @@
#ifndef DCBLOCKER_H
#define DCBLOCKER_H
#include "algorithm.h"
#include "global.h"
#include <vector>
class
DcBlocker
:
public
Algorithm
class
DcBlocker
{
public:
...
...
@@ -45,20 +42,9 @@ class DcBlocker : public Algorithm
~
DcBlocker
();
virtual
void
reset
(
void
);
/**
* Unused
*/
virtual
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
/**
* Unused
*/
virtual
int
getData
(
SFLDataFormat
*
outputData
);
void
reset
(
void
);
virtual
void
process
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
virtual
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
);
void
process
(
SFLDataFormat
*
out
,
SFLDataFormat
*
in
,
int
samples
);
private:
...
...
daemon/src/audio/delaydetection.cpp
View file @
f8206833
...
...
@@ -113,8 +113,6 @@ DelayDetection::DelayDetection() : _internalState (WaitForSpeaker), _decimationF
}
DelayDetection
::~
DelayDetection
()
{}
void
DelayDetection
::
reset
()
{
_nbMicSampleStored
=
0
;
...
...
@@ -168,11 +166,6 @@ void DelayDetection::putData (SFLDataFormat *inputData, int nbBytes)
}
int
DelayDetection
::
getData
(
SFLDataFormat
*
outputData
UNUSED
)
{
return
0
;
}
void
DelayDetection
::
process
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
{
...
...
@@ -212,11 +205,6 @@ void DelayDetection::process (SFLDataFormat *inputData, int nbBytes)
_debug
(
"MaxIndex: %d"
,
maxIndex
);
}
int
DelayDetection
::
process
(
SFLDataFormat
*
intputData
UNUSED
,
SFLDataFormat
*
outputData
UNUSED
,
int
nbBytes
UNUSED
)
{
return
0
;
}
void
DelayDetection
::
crossCorrelate
(
float
*
ref
,
float
*
seg
,
float
*
res
,
int
refSize
,
int
segSize
)
{
...
...
@@ -317,10 +305,8 @@ void DelayDetection::downsampleData (float *input, float *output, int nbSamples,
void
DelayDetection
::
bandpassFilter
(
float
*
input
,
int
nbSamples
)
{
for
(
int
i
=
0
;
i
<
nbSamples
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nbSamples
;
i
++
)
input
[
i
]
=
_bandpassFilter
.
getOutputSample
(
input
[
i
]);
}
}
...
...
@@ -330,12 +316,11 @@ int DelayDetection::getMaxIndex (float *data, int size)
float
max
=
0.0
;
int
k
=
0
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
if
(
data
[
i
]
>=
max
)
{
max
=
data
[
i
];
k
=
i
;
}
}
return
k
;
}
daemon/src/audio/delaydetection.h
View file @
f8206833
...
...
@@ -32,7 +32,8 @@
#ifndef DELAYDETECTION_H
#define DELAYDETECTION_H
#include "algorithm.h"
#include "global.h"
#include <vector>
// Template size in samples for correlation
#define WINDOW_SIZE 256
...
...
@@ -95,7 +96,7 @@ class FirFilter
};
class
DelayDetection
:
public
Algorithm
class
DelayDetection
{
public:
...
...
@@ -104,15 +105,11 @@ class DelayDetection : public Algorithm
~
DelayDetection
();
virtual
void
reset
(
void
);
virtual
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
virtual
int
getData
(
SFLDataFormat
*
getData
);
void
reset
(
void
);
v
irtual
void
process
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
v
oid
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
v
irtual
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
);
v
oid
process
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
private:
...
...
daemon/src/audio/echocancel.cpp
View file @
f8206833
...
...
@@ -241,9 +241,6 @@ int EchoCancel::getData (SFLDataFormat *outputData)
return
copied
;
}
void
EchoCancel
::
process
(
SFLDataFormat
*
data
UNUSED
,
int
nbBytes
UNUSED
)
{}
int
EchoCancel
::
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
)
{
...
...
daemon/src/audio/echocancel.h
View file @
f8206833
...
...
@@ -68,7 +68,7 @@
#define MIC_ADAPT_SIZE 100 // 1 sec
#define SPKR_ADAPT_SIZE 20 // 200 ms
class
EchoCancel
:
public
Algorithm
class
EchoCancel
{
public:
...
...
@@ -80,30 +80,25 @@ class EchoCancel : public Algorithm
/**
* Reset echocanceller internal state at runtime. Usefull when making a new call
*/
virtual
void
reset
(
void
);
void
reset
(
void
);
/**
* Add speaker data into internal buffer
* \param inputData containing far-end voice data to be sent to speakers
*/
virtual
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
/**
* Get data ready to be played by speakers
*/
virtual
int
getData
(
SFLDataFormat
*
outputData
);
/**
* Unused
*/
virtual
void
process
(
SFLDataFormat
*
data
,
int
nbBytes
);
int
getData
(
SFLDataFormat
*
outputData
);
/**
* Perform echo cancellation using internal buffers
* \param inputData containing mixed echo and voice data
* \param outputData containing
*/
virtual
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
);
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
);
/**
* Set echo canceller internal sampling rate, reset if sampling rate changed
...
...
daemon/src/audio/echosuppress.cpp
View file @
f8206833
...
...
@@ -6,71 +6,41 @@
*/
#include "echosuppress.h"
#include "pj/pool.h"
#include "pj/os.h"
#include <stdexcept>
#define ECHO_CANCEL_MEM_SIZE 1000
EchoSuppress
::
EchoSuppress
(
pj_pool_t
*
/*
pool
*/
)
EchoSuppress
::
EchoSuppress
(
pj_pool_t
*
pool
)
{
/*
pj_status_t status;
pj_thread_desc
aPJThreadDesc
;
pj_thread_t
*
pjThread
;
status = pj_thread_register("EchoCanceller", aPJThreadDesc, &pjThread);
if (
status
!= PJ_SUCCESS)
{
if
(
pj_thread_register
(
"EchoCanceller"
,
aPJThreadDesc
,
&
pjThread
)
!=
PJ_SUCCESS
)
_error
(
"EchoCancel: Error: Could not register new thread"
);
}
if (!pj_thread_is_registered()) {
_warn("EchoCancel: Thread not registered...");
}
echoCancelPool = pool;
if
(
!
pj_thread_is_registered
())
_warn
(
"EchoCancel: Thread not registered..."
);
status = pjmedia_echo_create(echoCancelPool, 8000, 160, 250, 0, PJMEDIA_ECHO_SIMPLE, &echoState);
if(status != PJ_SUCCESS) {
_error("EchoCancel: Error: Could not create echo canceller");
}
*/
if
(
pjmedia_echo_create
(
pool
,
8000
,
160
,
250
,
0
,
PJMEDIA_ECHO_SIMPLE
,
&
echoState
)
!=
PJ_SUCCESS
)
throw
std
::
runtime_error
(
"EchoCancel: Error: Could not create echo canceller"
);
}
EchoSuppress
::~
EchoSuppress
()
{
}
void
EchoSuppress
::
reset
()
{
}
void
EchoSuppress
::
putData
(
SFLDataFormat
*
/*inputData*/
,
int
/*nbBytes*/
)
void
EchoSuppress
::
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
)
{
/*
pj_status_t status;
status = pjmedia_echo_playback(echoState, reinterpret_cast<pj_int16_t *>(inputData));
if(status != PJ_SUCCESS) {
if
(
pjmedia_echo_playback
(
echoState
,
reinterpret_cast
<
pj_int16_t
*>
(
inputData
))
!=
PJ_SUCCESS
)
_warn
(
"EchoCancel: Warning: Problem while putting input data"
);
}
*/
}
int
EchoSuppress
::
getData
(
SFLDataFormat
*
/*
outputData
*/
)
int
EchoSuppress
::
getData
(
SFLDataFormat
*
outputData
)
{
/*
pj_status_t status;
status = pjmedia_echo_capture(echoState, reinterpret_cast<pj_int16_t *>(outputData), 0);
if(status != PJ_SUCCESS) {
if
(
pjmedia_echo_capture
(
echoState
,
reinterpret_cast
<
pj_int16_t
*>
(
outputData
),
0
)
!=
PJ_SUCCESS
)
_warn
(
"EchoCancel: Warning: Problem while getting output data"
);
}
*/
return
0
;
}
void
EchoSuppress
::
process
(
SFLDataFormat
*
data
UNUSED
,
int
nbBytes
UNUSED
)
{}
int
EchoSuppress
::
process
(
SFLDataFormat
*
/*inputData*/
,
SFLDataFormat
*
/*outputData*/
,
int
/*nbBytes*/
)
{
return
0
;
}
daemon/src/audio/echosuppress.h
View file @
f8206833
...
...
@@ -9,44 +9,24 @@
#define ECHOSUPPRESS_H_
#include "pjmedia/echo.h"
#include "
pj/poo
l.h"
#include "
globa
l.h"
#include "audio/algorithm.h"
class
EchoSuppress
:
public
Algorithm
{
class
EchoSuppress
{
public:
EchoSuppress
(
pj_pool_t
*
pool
);
virtual
~
EchoSuppress
();
virtual
void
reset
(
void
);
~
EchoSuppress
();
/**
* Add speaker data into internal buffer
* \param inputData containing far-end voice data to be sent to speakers
*/
virtual
void
putData
(
SFLDataFormat
*
,
int
);
virtual
int
getData
(
SFLDataFormat
*
);
void
putData
(
SFLDataFormat
*
,
int
);
/**
* Unused
*/
virtual
void
process
(
SFLDataFormat
*
,
int
);
int
getData
(
SFLDataFormat
*
);
/**
* Perform echo cancellation using internal buffers
* \param inputData containing mixed echo and voice data
* \param outputData containing
*/
virtual
int
process
(
SFLDataFormat
*
,
SFLDataFormat
*
,
int
);
private:
/**
* Memory pool for echo cancellation
*/
pj_pool_t
*
echoCancelPool
;
/**
* The internal state of the echo canceller
*/
...
...
daemon/src/audio/noisesuppress.cpp
View file @
f8206833
...
...
@@ -28,6 +28,7 @@
* as that of the covered work.
*/
#include <cassert>
#include "noisesuppress.h"
NoiseSuppress
::
NoiseSuppress
(
int
smplPerFrame
,
int
samplingRate
)
:
_noiseState
(
NULL
)
...
...
@@ -45,29 +46,14 @@ NoiseSuppress::~NoiseSuppress()
void
NoiseSuppress
::
reset
(
void
)
{
speex_preprocess_state_destroy
(
_noiseState
);
initNewNoiseSuppressor
(
_smplPerFrame
,
_samplingRate
);
}
void
NoiseSuppress
::
putData
(
SFLDataFormat
*
/*inputData*/
,
int
/*nbBytes*/
)
{}
int
NoiseSuppress
::
getData
(
SFLDataFormat
*
/*outputData*/
)
{
return
0
;
}
void
NoiseSuppress
::
process
(
SFLDataFormat
*
data
,
int
/*nbBytes*/
)
{
if
(
_noiseState
)
speex_preprocess_run
(
_noiseState
,
data
);
}
int
NoiseSuppress
::
process
(
SFLDataFormat
*
/*inputData*/
,
SFLDataFormat
*
/*outputData*/
,
int
/*nbBytes*/
)
void
NoiseSuppress
::
process
(
SFLDataFormat
*
data
,
int
nBytes
)
{
return
0
;
assert
(
_smplPerFrame
==
nBytes
/
sizeof
(
SFLDataFormat
));
speex_preprocess_run
(
_noiseState
,
data
);
}
void
NoiseSuppress
::
initNewNoiseSuppressor
(
int
smplPerFrame
,
int
samplingRate
)
...
...
daemon/src/audio/noisesuppress.h
View file @
f8206833
...
...
@@ -32,10 +32,9 @@
#define NOISESUPPRESS_H
#include <speex/speex_preprocess.h>
#include "
algorithm
.h"
#include "
global
.h"
class
NoiseSuppress
:
public
Algorithm
class
NoiseSuppress
{
public:
...
...
@@ -45,37 +44,19 @@ class NoiseSuppress : public Algorithm
~
NoiseSuppress
(
void
);
/**
* Reset noise suppressor internal state at runtime. Usefull when making a new call
*/
virtual
void
reset
(
void
);
/**
* Unused
*/
virtual
void
putData
(
SFLDataFormat
*
inputData
,
int
nbBytes
);
/**
* Unused
* Reset noise suppressor internal state at runtime. Usefull when making a new call
*/
v
irtual
int
getData
(
SFLDataFormat
*
outputData
);
v
oid
reset
(
void
);
/**
* Unused
*/
virtual
void
process
(
SFLDataFormat
*
data
,
int
nbBytes
);
/**
* Unused
*/
virtual
int
process
(
SFLDataFormat
*
inputData
,
SFLDataFormat
*
outputData
,
int
nbBytes
);
void
process
(
SFLDataFormat
*
data
,
int
nbBytes
);
private:
void
initNewNoiseSuppressor
(
int
_smplPerFrame
,
int
samplingRate
);
/**
* Noise reduction processing state
*/
* Noise reduction processing state
*/
SpeexPreprocessState
*
_noiseState
;
int
_smplPerFrame
;
...
...
daemon/src/audio/pulseaudio/pulselayer.cpp