Skip to content
Snippets Groups Projects
Commit d269924e authored by Alexandre Savard's avatar Alexandre Savard
Browse files

Merge branch 'speex32' into m_savard

parents b7188467 6b8f740e
No related branches found
No related tags found
No related merge requests found
...@@ -397,6 +397,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoint ...@@ -397,6 +397,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoint
codec = codec_list_get_by_payload(110); codec = codec_list_get_by_payload(110);
else if ((g_strcasecmp(name,"speex")==0) && (g_strcasecmp(srate,"16 kHz")==0)) else if ((g_strcasecmp(name,"speex")==0) && (g_strcasecmp(srate,"16 kHz")==0))
codec = codec_list_get_by_payload(111); codec = codec_list_get_by_payload(111);
else if ((g_strcasecmp(name,"speex")==0) && (g_strcasecmp(srate,"32 kHz")==0))
codec = codec_list_get_by_payload(112);
else else
codec = codec_list_get_by_name(name); codec = codec_list_get_by_name(name);
......
...@@ -31,6 +31,14 @@ libcodec_speex_wb_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP) ...@@ -31,6 +31,14 @@ libcodec_speex_wb_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP)
INSTALL_SPEEX_WB_RULE = install-libcodec_speex_wb_so INSTALL_SPEEX_WB_RULE = install-libcodec_speex_wb_so
endif endif
if BUILD_SPEEX
SPEEX_UB_LIB = libcodec_speex_ub.so
libcodec_speex_ub_so_SOURCES = speexcodec_ub.cpp
libcodec_speex_ub_so_CFLAGS = -fPIC -g -Wall
libcodec_speex_ub_so_CXXFLAGS = -fPIC -g -Wall $(SPEEXDSP)
libcodec_speex_ub_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP)
INSTALL_SPEEX_UB_RULE = install-libcodec_speex_ub_so
endif
if BUILD_CELT if BUILD_CELT
CELT_LIB = libcodec_celt.so CELT_LIB = libcodec_celt.so
...@@ -52,7 +60,7 @@ INSTALL_ILBC_RULE = install-libcodec_ilbc_so ...@@ -52,7 +60,7 @@ INSTALL_ILBC_RULE = install-libcodec_ilbc_so
SUBDIRS = ilbc SUBDIRS = ilbc
endif endif
noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_g722.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(CELT_LIB) $(ILBC_LIB) noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_g722.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(SPEEX_UB_LIB) $(CELT_LIB) $(ILBC_LIB)
noinst_HEADERS = audiocodec.h noinst_HEADERS = audiocodec.h
...@@ -72,8 +80,8 @@ libcodec_g722_so_CFLAGS = -fPIC -g -Wall ...@@ -72,8 +80,8 @@ libcodec_g722_so_CFLAGS = -fPIC -g -Wall
libcodec_g722_so_CXXFLAGS = -fPIC -g -Wall libcodec_g722_so_CXXFLAGS = -fPIC -g -Wall
libcodec_g722_so_LDFLAGS = --shared -lc libcodec_g722_so_LDFLAGS = --shared -lc
install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so install-libcodec_g722_so $(INSTALL_GSM_RULE) $(INSTALL_SPEEX_NB_RULE) $(INSTALL_SPEEX_WB_RULE) $(INSTALL_CELT_RULE) $(INSTALL_ILBC_RULE) install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so install-libcodec_g722_so $(INSTALL_GSM_RULE) $(INSTALL_SPEEX_NB_RULE) $(INSTALL_SPEEX_WB_RULE) $(INSTALL_SPEEX_UB_RULE) $(INSTALL_CELT_RULE) $(INSTALL_ILBC_RULE)
uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_g722_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_nb_so uninstall-libcodec_speex_wb_so uninstall-libcodec_celt_so uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_g722_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_nb_so uninstall-libcodec_speex_wb_so uninstall-libcodec_speex_ub_so uninstall-libcodec_celt_so
install-libcodec_ulaw_so: libcodec_ulaw.so install-libcodec_ulaw_so: libcodec_ulaw.so
...@@ -89,6 +97,8 @@ install-libcodec_speex_nb_so: libcodec_speex_nb.so ...@@ -89,6 +97,8 @@ install-libcodec_speex_nb_so: libcodec_speex_nb.so
$(INSTALL_PROGRAM) libcodec_speex_nb.so $(sflcodecdir) $(INSTALL_PROGRAM) libcodec_speex_nb.so $(sflcodecdir)
install-libcodec_speex_wb_so: libcodec_speex_wb.so install-libcodec_speex_wb_so: libcodec_speex_wb.so
$(INSTALL_PROGRAM) libcodec_speex_wb.so $(sflcodecdir) $(INSTALL_PROGRAM) libcodec_speex_wb.so $(sflcodecdir)
install-libcodec_speex_ub_so: libcodec_speex_ub.so
$(INSTALL_PROGRAM) libcodec_speex_ub.so $(sflcodecdir)
install-libcodec_celt_so: libcodec_celt.so install-libcodec_celt_so: libcodec_celt.so
$(INSTALL_PROGRAM) libcodec_celt.so $(sflcodecdir) $(INSTALL_PROGRAM) libcodec_celt.so $(sflcodecdir)
install-libcodec_ilbc_so: libcodec_ilbc.so install-libcodec_ilbc_so: libcodec_ilbc.so
...@@ -107,6 +117,8 @@ uninstall-libcodec_speex_nb_so: ...@@ -107,6 +117,8 @@ uninstall-libcodec_speex_nb_so:
rm -f $(sflcodecdir)/libcodec_speex_nb.so rm -f $(sflcodecdir)/libcodec_speex_nb.so
uninstall-libcodec_speex_wb_so: uninstall-libcodec_speex_wb_so:
rm -f $(sflcodecdir)/libcodec_speex_wb.so rm -f $(sflcodecdir)/libcodec_speex_wb.so
uninstall-libcodec_speex_ub_so:
rm -f $(sflcodecdir)/libcodec_speex_ub.so
rm -rf $(sflcodecdir) rm -rf $(sflcodecdir)
uninstall-libcodec_celt_so: libcodec_celt.so uninstall-libcodec_celt_so: libcodec_celt.so
$(INSTALL_PROGRAM) libcodec_celt.so $(sflcodecdir) $(INSTALL_PROGRAM) libcodec_celt.so $(sflcodecdir)
......
...@@ -128,8 +128,10 @@ class Speex : public AudioCodec{ ...@@ -128,8 +128,10 @@ class Speex : public AudioCodec{
speex_preprocess_run(_preprocess_state, src); speex_preprocess_run(_preprocess_state, src);
#endif #endif
speex_encode_int(_speex_enc_state, src, &_speex_enc_bits); speex_encode_int(_speex_enc_state, src, &_speex_enc_bits);
int nbBytes = speex_bits_write(&_speex_enc_bits, (char*)dst, size); int nbBytes = speex_bits_write(&_speex_enc_bits, (char*)dst, size);
return nbBytes; return nbBytes;
} }
......
/*
* Copyright (C) 2007-2009 Savoir-Faire Linux inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Emmanuel Milou <emmanuel.milou@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.
*/
#include "audiocodec.h"
#include <cstdio>
#include <speex/speex.h>
#include <speex/speex_preprocess.h>
class Speex : public AudioCodec{
public:
Speex(int payload=0)
: AudioCodec(payload, "speex"),
_speexModePtr(NULL),
_speex_dec_bits(),
_speex_enc_bits(),
_speex_dec_state(),
_speex_enc_state(),
_speex_frame_size(),
_preprocess_state()
{
_clockRate = 32000;
_frameSize = 320; // 10 ms at 32 kHz
_channel = 1;
_bitrate = 0;
_bandwidth = 0;
initSpeex();
}
Speex( const Speex& );
Speex& operator=(const Speex&);
void initSpeex() {
// int _samplingRate = 32000;
// 8000 HZ --> Narrow-band mode
// TODO Manage the other modes
_speexModePtr = &speex_wb_mode;
// _speexModePtr = &speex_wb_mode;
// Init the decoder struct
speex_bits_init(&_speex_dec_bits);
_speex_dec_state = speex_decoder_init(_speexModePtr);
// Init the encoder struct
speex_bits_init(&_speex_enc_bits);
_speex_enc_state = speex_encoder_init(_speexModePtr);
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 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()
{
terminateSpeex();
}
void terminateSpeex() {
// Destroy the decoder struct
speex_bits_destroy(&_speex_dec_bits);
speex_decoder_destroy(_speex_dec_state);
_speex_dec_state = 0;
// Destroy the encoder struct
speex_bits_destroy(&_speex_enc_bits);
speex_encoder_destroy(_speex_enc_state);
_speex_enc_state = 0;
}
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size)
{
// int ratio = 320 / _speex_frame_size;
speex_bits_read_from(&_speex_dec_bits, (char*)src, size);
speex_decode_int(_speex_dec_state, &_speex_dec_bits, dst);
// return the nuber of byte, not the number of sample
return _speex_frame_size * 2;
}
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);
return nbBytes;
}
private:
const SpeexMode* _speexModePtr;
SpeexBits _speex_dec_bits;
SpeexBits _speex_enc_bits;
void *_speex_dec_state;
void *_speex_enc_state;
int _speex_frame_size;
SpeexPreprocessState *_preprocess_state;
};
// the class factories
extern "C" AudioCodec* create() {
return new Speex(112);
}
extern "C" void destroy(AudioCodec* a) {
delete a;
}
...@@ -113,6 +113,7 @@ class Speex : public AudioCodec{ ...@@ -113,6 +113,7 @@ class Speex : public AudioCodec{
{ {
int ratio = 320 / _speex_frame_size; int ratio = 320 / _speex_frame_size;
speex_bits_read_from(&_speex_dec_bits, (char*)src, size); speex_bits_read_from(&_speex_dec_bits, (char*)src, size);
speex_decode_int(_speex_dec_state, &_speex_dec_bits, dst); speex_decode_int(_speex_dec_state, &_speex_dec_bits, dst);
...@@ -128,9 +129,10 @@ class Speex : public AudioCodec{ ...@@ -128,9 +129,10 @@ class Speex : public AudioCodec{
speex_preprocess_run(_preprocess_state, src); speex_preprocess_run(_preprocess_state, src);
#endif #endif
printf("Codec::codecEncode() size %i\n", size);
speex_encode_int(_speex_enc_state, src, &_speex_enc_bits); speex_encode_int(_speex_enc_state, src, &_speex_enc_bits);
int nbBytes = speex_bits_write(&_speex_enc_bits, (char*)dst, size); int nbBytes = speex_bits_write(&_speex_enc_bits, (char*)dst, size);
printf("Codec::codecEncode() nbBytes: %i \n",nbBytes); printf("Codec::codecEncode() nbBytes %i\n", nbBytes);
return nbBytes; return nbBytes;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment