Commit d1efed8b authored by Alexandre Savard's avatar Alexandre Savard

[#958] Make libspeexdsp a required dependency

parent 158543bc
......@@ -341,17 +341,19 @@ AC_ARG_WITH([speex],
AS_IF([test "x$with_speex" != xno],
[AC_CHECK_HEADER([speex/speex.h], , AC_MSG_FAILURE([Unable to find the libspeex headers (you may need to install the dev package). You may use --without-speex to compile without speex codec support.]))]
[AC_CHECK_HEADER([speex/speex_preprocess.h], , AC_MSG_FAILURE([Unable to find the libspeexdsp headers (you may need to install the libspeexdsp-dev package). You may use --without-speex to compile without speex codec support.]))]
[AC_CHECK_LIB([speex], [speex_decode_int],
[],
[AC_MSG_FAILURE(
[libspeex link test failed. You may use --without-speex to compile without speex codec support.])]
)
]
dnl More advanced check in case the libspeexdsp is not installed
AC_SEARCH_LIBS(speex_preprocess_run, speexdsp, HAVE_SPEEXDSP="yes", HAVE_SPEEXDSP="no", [])
# dnl More advanced check in case the libspeexdsp is not installed
# AC_SEARCH_LIBS(speex_preprocess_run, speexdsp, HAVE_SPEEXDSP="yes", HAVE_SPEEXDSP="no", [])
)
dnl check in case the libspeexdsp is not installed
AC_CHECK_HEADER([speex/speex_preprocess.h], , AC_MSG_FAILURE([Unable to find the libspeexdsp headers (you may need to install the libspeexdsp-dev package) used for Noise Suppression and Automatic Gain Control.]))
AC_CHECK_LIB(speexdsp, speex_preprocess_run, [], [], [])
AC_DEFINE([HAVE_SPEEX], test "x$with_speex" = "xyes", [Define if you have libspeex])
AM_CONDITIONAL(BUILD_SPEEX, test "x$with_speex" = "xyes" )
AM_CONDITIONAL(ENABLE_SPEEXDSP, test $HAVE_SPEEXDSP = yes)
......
......@@ -4,6 +4,10 @@ noinst_LTLIBRARIES = libaudio.la
SUBDIRS = codecs audiortp sound alsa pulseaudio
# if ENABLE_SPEEXDSP
# SPEEXDSP=-DHAVE_SPEEXDSP_LIB
# endif
libaudio_la_SOURCES = \
audioloop.cpp \
ringbuffer.cpp \
......
......@@ -13,10 +13,6 @@ libcodec_gsm_so_LDFLAGS = --shared -lc -lgsm
INSTALL_GSM_RULE = install-libcodec_gsm_so
endif
if ENABLE_SPEEXDSP
SPEEXDSP=-DHAVE_SPEEXDSP_LIB
endif
if BUILD_SPEEX
SPEEX_NB_LIB = libcodec_speex_nb.so
libcodec_speex_nb_so_SOURCES = speexcodec_nb.cpp
......
......@@ -45,8 +45,7 @@ class Speex : public AudioCodec
_speex_enc_bits(),
_speex_dec_state(),
_speex_enc_state(),
_speex_frame_size(),
_preprocess_state() {
_speex_frame_size() {
_clockRate = 8000;
_frameSize = 160; // samples, 20 ms at 8kHz
_channel = 1;
......@@ -77,32 +76,6 @@ class Speex : public AudioCodec
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
int quality = 10;
int complex = 10;
int attenuation = -10;
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_VAD, &enable);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_DTX, &enable);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_VBR_QUALITY, &quality);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_COMPLEXITY, &complex);
// Init the decoder struct
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
// Init the preprocess struct
_preprocess_state = speex_preprocess_state_init (_speex_frame_size,_clockRate);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_DENOISE, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &attenuation);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
~Speex() {
......@@ -119,9 +92,6 @@ class Speex : public AudioCodec
speex_bits_destroy (&_speex_enc_bits);
speex_encoder_destroy (_speex_enc_state);
_speex_enc_state = 0;
speex_preprocess_state_destroy( _preprocess_state);
_preprocess_state = NULL;
}
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) {
......@@ -137,13 +107,6 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
int nbBytes = speex_bits_write (&_speex_enc_bits, (char*) dst, size);
......@@ -157,7 +120,6 @@ class Speex : public AudioCodec
void *_speex_dec_state;
void *_speex_enc_state;
int _speex_frame_size;
SpeexPreprocessState *_preprocess_state;
};
// the class factories
......
......@@ -32,7 +32,6 @@
#include "audiocodec.h"
#include <cstdio>
#include <speex/speex.h>
#include <speex/speex_preprocess.h>
class Speex : public AudioCodec
{
......@@ -45,8 +44,7 @@ class Speex : public AudioCodec
_speex_enc_bits(),
_speex_dec_state(),
_speex_enc_state(),
_speex_frame_size(),
_preprocess_state() {
_speex_frame_size() {
_clockRate = 32000;
_frameSize = 640; // 20 ms at 32 kHz
_channel = 1;
......@@ -78,30 +76,6 @@ class Speex : public AudioCodec
speex_encoder_ctl (_speex_enc_state,SPEEX_SET_SAMPLING_RATE,&_clockRate);
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
int complex = 10;
int attenuation = -10;
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_VAD, &enable);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_DTX, &enable);
// speex_encoder_ctl(_speex_enc_state, SPEEX_SET_VBR_QUALITY, &quality);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_COMPLEXITY, &complex);
// Init the decoder struct
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_frameSize);
// Init the preprocess struct
_preprocess_state = speex_preprocess_state_init (_frameSize,_clockRate);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_DENOISE, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &attenuation);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
~Speex() {
......@@ -119,8 +93,6 @@ class Speex : public AudioCodec
speex_encoder_destroy (_speex_enc_state);
_speex_enc_state = 0;
speex_preprocess_state_destroy( _preprocess_state);
_preprocess_state = NULL;
}
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) {
......@@ -136,13 +108,6 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
speex_bits_nbytes (&_speex_enc_bits);
int nbBytes = speex_bits_write (&_speex_enc_bits, (char*) dst, size);
......@@ -157,7 +122,6 @@ class Speex : public AudioCodec
void *_speex_dec_state;
void *_speex_enc_state;
int _speex_frame_size;
SpeexPreprocessState *_preprocess_state;
};
// the class factories
......
......@@ -32,7 +32,6 @@
#include "audiocodec.h"
#include <cstdio>
#include <speex/speex.h>
#include <speex/speex_preprocess.h>
class Speex : public AudioCodec
{
......@@ -45,8 +44,7 @@ class Speex : public AudioCodec
_speex_enc_bits(),
_speex_dec_state(),
_speex_enc_state(),
_speex_frame_size(),
_preprocess_state() {
_speex_frame_size() {
_clockRate = 16000;
_frameSize = 320; // 20 ms at 16 kHz
_channel = 1;
......@@ -77,31 +75,6 @@ class Speex : public AudioCodec
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
int quality = 10;
int complex = 10;
int attenuation = -10;
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_VAD, &enable);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_DTX, &enable);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_VBR_QUALITY, &quality);
speex_encoder_ctl (_speex_enc_state, SPEEX_SET_COMPLEXITY, &complex);
// Init the decoder struct
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
// Init the preprocess struct
_preprocess_state = speex_preprocess_state_init (_speex_frame_size,_clockRate);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_DENOISE, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &attenuation);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
~Speex() {
......@@ -119,8 +92,6 @@ class Speex : public AudioCodec
speex_encoder_destroy (_speex_enc_state);
_speex_enc_state = 0;
speex_preprocess_state_destroy( _preprocess_state);
_preprocess_state = NULL;
}
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) {
......@@ -137,13 +108,6 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
//printf ("Codec::codecEncode() size %i\n", size);
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
int nbBytes = speex_bits_write (&_speex_enc_bits, (char*) dst, size);
......@@ -158,7 +122,6 @@ class Speex : public AudioCodec
void *_speex_dec_state;
void *_speex_enc_state;
int _speex_frame_size;
SpeexPreprocessState *_preprocess_state;
};
// the class factories
......
......@@ -90,7 +90,6 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_spkrHistoryLength = SPKR_LENGTH / SEGMENT_LENGTH;
_nbSegmentPerFrame = _frameLength / SEGMENT_LENGTH;
// #ifdef HAVE_SPEEXDSP_LIB
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
int i=1;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DENOISE, &i);
......@@ -110,7 +109,7 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
i = 0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_VAD, &i);
// #endif
memset(_avgSpkrLevelHist, 0, BUFF_SIZE*sizeof(int));
memset(_avgMicLevelHist, 0, BUFF_SIZE*sizeof(int));
......@@ -135,9 +134,7 @@ EchoCancel::~EchoCancel()
delete _spkrData;
_spkrData = NULL;
// #ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
// #endif
// micFile->close();
// spkrFile->close();
......@@ -189,7 +186,6 @@ void EchoCancel::reset()
_spkrData->flushAll();
_spkrDataOut->flushAll();
// #ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
......@@ -210,8 +206,6 @@ void EchoCancel::reset()
f=0.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
// #endif
_spkrStoped = true;
_processedByte = 0;
......@@ -290,12 +284,14 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
// micFile->write((const char *)_tmpMic, byteSize);
// spkrFile->write((const char *)_tmpSpkr, byteSize);
// #ifdef HAVE_SPEEXDSP_LIB
#ifdef HAVE_LIBSPEEX_DSP
_debug("OK");
// Remove noise
if(_noiseActive)
speex_preprocess_run(_noiseState, _tmpMic);
// #endif
#endif
// Processed echo cancellation
performEchoCancel(_tmpMic, _tmpSpkr, _tmpOut);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment