Commit 9c0fc2ed authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Move codecs stuff in audio/codecs directory - Must autoreconf all

parent 884a4865
......@@ -35,6 +35,8 @@ AC_CONFIG_FILES([libs/Makefile \
AC_CONFIG_FILES([src/Makefile \
src/sflphone \
src/audio/Makefile \
src/audio/codecs/Makefile
src/audio/codecs/ilbc/Makefile \
src/config/Makefile \
src/dbus/Makefile \
src/zeroconf/Makefile])
......
sflcodecdir = $(libdir)/sflphone/codecs/
sflcodecdir = $(libdir)/sflphone/codecs
noinst_LTLIBRARIES = libaudio.la
noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_gsm.so libcodec_speex.so
libcodec_ulaw_so_SOURCES = ulaw.cpp
libcodec_ulaw_so_CFLAGS = -fPIC -g -Wall
libcodec_ulaw_so_LDFLAGS = -shared -lc
SUBDIRS = codecs
libcodec_alaw_so_SOURCES = alaw.cpp
libcodec_alaw_so_CFLAGS = -fPIC -g -Wall
libcodec_alaw_so_LDFLAGS = -shared -lc
libcodec_gsm_so_SOURCES = gsmcodec.cpp
libcodec_gsm_so_CFLAGS = -fPIC -g -Wall
libcodec_gsm_so_LDFLAGS = -shared -lc -lgsm
libcodec_speex_so_SOURCES = speexcodec.cpp
libcodec_speex_so_CFLAGS = -fPIC -g -Wall
libcodec_speex_so_LDFLAGS = -shared -lc -lspeex
if USE_SPEEX
SPEEX_SOURCES_CPP=speexcodec.cpp
SPEEX_FLAG=-DHAVE_SPEEX
SPEEX_LIB=-lspeex
else
SPEEX_SOURCES_CPP=
SPEEX_FLAG=
SPEEX_LIB=
endif
#SUBDIRS = gsm
libaudio_la_SOURCES = audiofile.cpp tonelist.cpp \
audiortp.cpp dtmf.cpp tone.cpp audiolayer.cpp audiodevice.cpp dtmfgenerator.cpp \
tonegenerator.cpp codecDescriptor.cpp \
......@@ -41,29 +14,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $
libaudio_la_CPPFLAGS = $(SPEEX_FLAG)
noinst_HEADERS = audioloop.h common.h ringbuffer.h audiofile.h \
tonelist.h audiortp.h audiocodec.h audiolayer.h audiodevice.h \
tonelist.h audiortp.h audiolayer.h audiodevice.h \
dtmfgenerator.h tonegenerator.h \
codecDescriptor.h dtmf.h tone.h
install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so install-libcodec_gsm_so install-libcodec_speex_so
uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_so
install-libcodec_ulaw_so: libcodec_ulaw.so
mkdir -p $(sflcodecdir)
$(INSTALL_PROGRAM) libcodec_ulaw.so $(sflcodecdir)
install-libcodec_alaw_so: libcodec_alaw.so
$(INSTALL_PROGRAM) libcodec_alaw.so $(sflcodecdir)
install-libcodec_gsm_so: libcodec_gsm.so
$(INSTALL_PROGRAM) libcodec_gsm.so $(sflcodecdir)
install-libcodec_speex_so: libcodec_speex.so
$(INSTALL_PROGRAM) libcodec_speex.so $(sflcodecdir)
uninstall-libcodec_ulaw_so:
rm -f $(sflcodecdir)/libcodec_ulaw.so
uninstall-libcodec_alaw_so:
rm -f $(sflcodecdir)/libcodec_alaw.so
uninstall-libcodec_gsm_so:
rm -f $(sflcodecdir)/libcodec_gsm.so
uninstall-libcodec_speex_so:
rm -f $(sflcodecdir)/libcodec_speex.so
rm -rf $(sflcodecdir)
......@@ -24,7 +24,7 @@
#define __AUDIOFILE_H__
#include "audioloop.h"
#include "audiocodec.h"
#include "codecs/audiocodec.h"
/**
@author Yan Morin <yan.morin@savoirfairelinux.com>
......
......@@ -22,11 +22,7 @@
#include <iostream>
#include <cstdlib>
#include "audiocodec.h"
#include "codecDescriptor.h"
/*#ifdef HAVE_SPEEX
#include "CodecSpeex.h"
#endif*/
CodecDescriptor::CodecDescriptor()
{
......@@ -43,7 +39,7 @@ CodecDescriptor::init()
_codecMap[PAYLOAD_CODEC_ULAW] = "PCMU";
_codecMap[PAYLOAD_CODEC_GSM] = "GSM";
_codecMap[PAYLOAD_CODEC_ALAW] = "PCMA";
//_codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
_codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
_codecMap[PAYLOAD_CODEC_SPEEX_8000] = "speex";;
}
......@@ -112,7 +108,7 @@ CodecDescriptor::getBitRate(CodecType payload)
case PAYLOAD_CODEC_ILBC_20:
return 15.2;
case PAYLOAD_CODEC_ILBC_30:
return 15.2;
return 13.3;
}
return 0.0;
......
......@@ -50,7 +50,7 @@ typedef enum {
PAYLOAD_CODEC_SPEEX_32000 = 112
} CodecType;
#include "audiocodec.h"
#include "codecs/audiocodec.h"
/* A codec is identified by its payload. A payload is associated with a name. */
typedef std::map<CodecType, std::string> CodecMap;
......
sflcodecdir = $(libdir)/sflphone/codecs
noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_gsm.so libcodec_speex.so libcodec_ilbc.so
noinst_HEADERS = audiocodec.h
libcodec_ulaw_so_SOURCES = ulaw.cpp
libcodec_ulaw_so_CFLAGS = -fPIC -g -Wall
libcodec_ulaw_so_LDFLAGS = -shared -lc
libcodec_alaw_so_SOURCES = alaw.cpp
libcodec_alaw_so_CFLAGS = -fPIC -g -Wall
libcodec_alaw_so_LDFLAGS = -shared -lc
libcodec_gsm_so_SOURCES = gsmcodec.cpp
libcodec_gsm_so_CFLAGS = -fPIC -g -Wall
libcodec_gsm_so_LDFLAGS = -shared -lc -lgsm
libcodec_speex_so_SOURCES = speexcodec.cpp
libcodec_speex_so_CFLAGS = -fPIC -g -Wall
libcodec_speex_so_LDFLAGS = -shared -lc -lspeex
libcodec_ilbc_so_SOURCES = ilbc.cpp
libcodec_ilbc_so_CFLAGS = -fPIC -g -Wall
libcodec_ilbc_so_LDFLAGS = -shared ilbc/*.o -lc
SUBDIRS = ilbc
install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so install-libcodec_gsm_so install-libcodec_speex_so install-libcodec_ilbc_so
uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_gsm_so uninstall-libcodec_speex_so uninstall-libcodec_ilbc_so
install-libcodec_ulaw_so: libcodec_ulaw.so
mkdir -p $(sflcodecdir)
$(INSTALL_PROGRAM) libcodec_ulaw.so $(sflcodecdir)
install-libcodec_alaw_so: libcodec_alaw.so
$(INSTALL_PROGRAM) libcodec_alaw.so $(sflcodecdir)
install-libcodec_gsm_so: libcodec_gsm.so
$(INSTALL_PROGRAM) libcodec_gsm.so $(sflcodecdir)
install-libcodec_speex_so: libcodec_speex.so
$(INSTALL_PROGRAM) libcodec_speex.so $(sflcodecdir)
install-libcodec_ilbc_so: libcodec_ilbc.so
$(INSTALL_PROGRAM) libcodec_ilbc.so $(sflcodecdir)
uninstall-libcodec_ulaw_so:
rm -f $(sflcodecdir)/libcodec_ulaw.so
uninstall-libcodec_alaw_so:
rm -f $(sflcodecdir)/libcodec_alaw.so
uninstall-libcodec_gsm_so:
rm -f $(sflcodecdir)/libcodec_gsm.so
uninstall-libcodec_speex_so:
rm -f $(sflcodecdir)/libcodec_speex.so
uninstall-libcodec_ilbc_so:
rm -f $(sflcodecdir)/libcodec_ilbc.so
rm -rf $(sflcodecdir)
......@@ -18,7 +18,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "common.h"
#include "../common.h"
#include "audiocodec.h"
class Alaw : public AudioCodec {
......
#include "audiocodec.h"
extern "C" {
#include "ilbc/iLBC_encode.h"
#include "ilbc/iLBC_decode.h"
}
class Ilbc: public AudioCodec
{
public:
Ilbc(int payload)
: AudioCodec(payload, "iLBC"){
_clockRate = 8000;
_channel = 1;
initILBC();
}
void initILBC(){
initDecode(ilbc_dec, 20, 1);
initEncode(ilbc_enc, 20);
}
virtual int codecDecode(short *dst, unsigned char *src, unsigned int size){
iLBC_decode((float*) dst, src, ilbc_dec, 0);
return 160;
}
virtual int codecEncode(unsigned char *dst, short* src, unsigned int size){
iLBC_encode(dst, (float*) src, ilbc_enc);
return 160;
}
private:
iLBC_Dec_Inst_t* ilbc_dec;
iLBC_Enc_Inst_t* ilbc_enc;
};
// the class factories
extern "C" AudioCodec* create(){
return new Ilbc(97);
}
extern "C" void destroy(AudioCodec* a){
delete a;
}
/******************************************************************
iLBC Speech Coder ANSI-C Source Code
FrameClassify.c
Copyright (C) The Internet Society (2004).
All Rights Reserved.
******************************************************************/
#include "iLBC_define.h"
/*---------------------------------------------------------------*
* Classification of subframes to localize start state
*--------------------------------------------------------------*/
int FrameClassify( /* index to the max-energy sub-frame */
iLBC_Enc_Inst_t *iLBCenc_inst,
/* (i/o) the encoder state structure */
float *residual /* (i) lpc residual signal */
) {
float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
int n, l, max_ssqEn_n;
const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
(float)1.0,(float)0.9,(float)0.8};
const float sampEn_win[5]={(float)1.0/(float)6.0,
(float)2.0/(float)6.0, (float)3.0/(float)6.0,
(float)4.0/(float)6.0, (float)5.0/(float)6.0};
/* init the front and back energies to zero */
memset(fssqEn, 0, NSUB_MAX*sizeof(float));
memset(bssqEn, 0, NSUB_MAX*sizeof(float));
/* Calculate front of first seqence */
n=0;
pp=residual;
for (l=0; l<5; l++) {
fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
pp++;
}
for (l=5; l<SUBL; l++) {
fssqEn[n] += (*pp) * (*pp);
pp++;
}
/* Calculate front and back of all middle sequences */
for (n=1; n<iLBCenc_inst->nsub-1; n++) {
pp=residual+n*SUBL;
for (l=0; l<5; l++) {
fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
bssqEn[n] += (*pp) * (*pp);
pp++;
}
for (l=5; l<SUBL-5; l++) {
fssqEn[n] += (*pp) * (*pp);
bssqEn[n] += (*pp) * (*pp);
pp++;
}
for (l=SUBL-5; l<SUBL; l++) {
fssqEn[n] += (*pp) * (*pp);
bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
pp++;
}
}
/* Calculate back of last seqence */
n=iLBCenc_inst->nsub-1;
pp=residual+n*SUBL;
for (l=0; l<SUBL-5; l++) {
bssqEn[n] += (*pp) * (*pp);
pp++;
}
for (l=SUBL-5; l<SUBL; l++) {
bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
pp++;
}
/* find the index to the weighted 80 sample with
most energy */
if (iLBCenc_inst->mode==20) l=1;
else l=0;
max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
max_ssqEn_n=1;
for (n=2; n<iLBCenc_inst->nsub; n++) {
l++;
if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
ssqEn_win[l];
max_ssqEn_n=n;
}
}
return max_ssqEn_n;
}
/******************************************************************
iLBC Speech Coder ANSI-C Source Code
FrameClassify.h
Copyright (C) The Internet Society (2004).
All Rights Reserved.
******************************************************************/
#ifndef __iLBC_FRAMECLASSIFY_H
#define __iLBC_FRAMECLASSIFY_H
int FrameClassify( /* index to the max-energy sub-frame */
iLBC_Enc_Inst_t *iLBCenc_inst,
/* (i/o) the encoder state structure */
float *residual /* (i) lpc residual signal */
);
#endif
/******************************************************************
iLBC Speech Coder ANSI-C Source Code
LPC_decode.c
Copyright (C) The Internet Society (2004).
All Rights Reserved.
******************************************************************/
#include <math.h>
#include <string.h>
#include "helpfun.h"
#include "lsf.h"
#include "iLBC_define.h"
#include "constants.h"
/*---------------------------------------------------------------*
* interpolation of lsf coefficients for the decoder
*--------------------------------------------------------------*/
void LSFinterpolate2a_dec(
float *a, /* (o) lpc coefficients for a sub-frame */
float *lsf1, /* (i) first lsf coefficient vector */
float *lsf2, /* (i) second lsf coefficient vector */
float coef, /* (i) interpolation weight */
int length /* (i) length of lsf vectors */
){
float lsftmp[LPC_FILTERORDER];
interpolate(lsftmp, lsf1, lsf2, coef, length);
lsf2a(a, lsftmp);
}
/*---------------------------------------------------------------*
* obtain dequantized lsf coefficients from quantization index
*--------------------------------------------------------------*/
void SimplelsfDEQ(
float *lsfdeq, /* (o) dequantized lsf coefficients */
int *index, /* (i) quantization index */
int lpc_n /* (i) number of LPCs */
){
int i, j, pos, cb_pos;
/* decode first LSF */
pos = 0;
cb_pos = 0;
for (i = 0; i < LSF_NSPLIT; i++) {
for (j = 0; j < dim_lsfCbTbl[i]; j++) {
lsfdeq[pos + j] = lsfCbTbl[cb_pos +
(long)(index[i])*dim_lsfCbTbl[i] + j];
}
pos += dim_lsfCbTbl[i];
cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
}
if (lpc_n>1) {
/* decode last LSF */
pos = 0;
cb_pos = 0;
for (i = 0; i < LSF_NSPLIT; i++) {
for (j = 0; j < dim_lsfCbTbl[i]; j++) {
lsfdeq[LPC_FILTERORDER + pos + j] =
lsfCbTbl[cb_pos +
(long)(index[LSF_NSPLIT + i])*
dim_lsfCbTbl[i] + j];
}
pos += dim_lsfCbTbl[i];
cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
}
}
}
/*----------------------------------------------------------------*
* obtain synthesis and weighting filters form lsf coefficients
*---------------------------------------------------------------*/
void DecoderInterpolateLSF(
float *syntdenum, /* (o) synthesis filter coefficients */
float *weightdenum, /* (o) weighting denumerator
coefficients */
float *lsfdeq, /* (i) dequantized lsf coefficients */
int length, /* (i) length of lsf coefficient vector */
iLBC_Dec_Inst_t *iLBCdec_inst
/* (i) the decoder state structure */
){
int i, pos, lp_length;
float lp[LPC_FILTERORDER + 1], *lsfdeq2;
lsfdeq2 = lsfdeq + length;
lp_length = length + 1;
if (iLBCdec_inst->mode==30) {
/* sub-frame 1: Interpolation between old and first */
LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
lsf_weightTbl_30ms[0], length);
memcpy(syntdenum,lp,lp_length*sizeof(float));
bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
lp_length);
/* sub-frames 2 to 6: interpolation between first
and last LSF */
pos = lp_length;
for (i = 1; i < 6; i++) {
LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
lsf_weightTbl_30ms[i], length);
memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
bwexpand(weightdenum + pos, lp,
LPC_CHIRP_WEIGHTDENUM, lp_length);
pos += lp_length;
}
}
else {
pos = 0;
for (i = 0; i < iLBCdec_inst->nsub; i++) {
LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
lsfdeq, lsf_weightTbl_20ms[i], length);
memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
lp_length);
pos += lp_length;
}
}
/* update memory */
if (iLBCdec_inst->mode==30)
memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
length*sizeof(float));
else
memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
length*sizeof(float));
}
/******************************************************************
iLBC Speech Coder ANSI-C Source Code
LPC_decode.h
Copyright (C) The Internet Society (2004).
All Rights Reserved.
******************************************************************/
#ifndef __iLBC_LPC_DECODE_H
#define __iLBC_LPC_DECODE_H
void LSFinterpolate2a_dec(
float *a, /* (o) lpc coefficients for a sub-frame */
float *lsf1, /* (i) first lsf coefficient vector */
float *lsf2, /* (i) second lsf coefficient vector */
float coef, /* (i) interpolation weight */
int length /* (i) length of lsf vectors */
);
void SimplelsfDEQ(
float *lsfdeq, /* (o) dequantized lsf coefficients */
int *index, /* (i) quantization index */
int lpc_n /* (i) number of LPCs */
);
void DecoderInterpolateLSF(
float *syntdenum, /* (o) synthesis filter coefficients */
float *weightdenum, /* (o) weighting denumerator
coefficients */
float *lsfdeq, /* (i) dequantized lsf coefficients */
int length, /* (i) length of lsf coefficient vector */
iLBC_Dec_Inst_t *iLBCdec_inst
/* (i) the decoder state structure */
);
#endif
/******************************************************************
iLBC Speech Coder ANSI-C Source Code
LPCencode.c
Copyright (C) The Internet Society (2004).
All Rights Reserved.
******************************************************************/
#include <string.h>