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
884a4865
Commit
884a4865
authored
Feb 11, 2008
by
Emmanuel Milou
Browse files
Speex codec tested - good audio
But size of the frames to work on
parent
4cab06ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/audio/CodecSpeex.h
deleted
100644 → 0
View file @
4cab06ab
/*
* Copyright (C) 2005 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@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.
*/
#ifndef __CODEC_SPEEX_H_
#define __CODEC_SPEEX_H_
#include
"audiocodec.h"
#include
<speex/speex.h>
class
CodecSpeex
:
public
AudioCodec
{
public:
CodecSpeex
(
int
payload
);
~
CodecSpeex
();
int
codecDecode
(
short
*
,
unsigned
char
*
,
unsigned
int
);
int
codecEncode
(
unsigned
char
*
,
short
*
,
unsigned
int
);
// only for speex
int
getFrameSize
()
{
return
_speex_frame_size
;
}
private:
unsigned
int
_clockRate
;
unsigned
int
_channel
;
void
initSpeex
();
void
terminateSpeex
();
const
SpeexMode
*
_speexModePtr
;
SpeexBits
_speex_dec_bits
;
SpeexBits
_speex_enc_bits
;
void
*
_speex_dec_state
;
void
*
_speex_enc_state
;
int
_speex_frame_size
;
};
#endif // __CODEC_SPEEX_H_
src/audio/Makefile.am
View file @
884a4865
...
...
@@ -15,12 +15,12 @@ libcodec_gsm_so_SOURCES = gsmcodec.cpp
libcodec_gsm_so_CFLAGS
=
-fPIC
-g
-Wall
libcodec_gsm_so_LDFLAGS
=
-shared
-lc
-lgsm
libcodec_speex_so_SOURCES
=
CodecSpeex
.cpp
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
=
CodecSpeex
.cpp
SPEEX_SOURCES_CPP
=
speexcodec
.cpp
SPEEX_FLAG
=
-DHAVE_SPEEX
SPEEX_LIB
=
-lspeex
else
...
...
@@ -43,8 +43,7 @@ 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
\
dtmfgenerator.h tonegenerator.h
\
codecDescriptor.h dtmf.h tone.h
\
CodecSpeex.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
...
...
src/audio/audiortp.cpp
View file @
884a4865
...
...
@@ -390,7 +390,6 @@ try {
//_fstream.write((char*) data, size);
// Decode data with relevant codec
_codecSampleRate
=
_audiocodec
->
getClockRate
();
int
max
=
(
int
)(
_codecSampleRate
*
_layerFrameSize
/
1000
);
if
(
size
>
max
)
{
...
...
@@ -404,6 +403,7 @@ try {
if
(
_audiocodec
!=
NULL
)
{
int
expandedSize
=
_audiocodec
->
codecDecode
(
_receiveDataDecoded
,
data
,
size
);
// printf("%i\n", expandedSize);
//_fstream.write((char*) _receiveDataDecoded, );
//buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes
int
nbInt16
=
expandedSize
/
sizeof
(
int16
);
...
...
@@ -518,12 +518,12 @@ AudioRtpRTX::run () {
//mic, we receive from soundcard in stereo, and we send encoded
//encoding before sending
AudioLayer
*
audiolayer
=
Manager
::
instance
().
getAudioDriver
();
loadCodec
(
_ca
->
getAudioCodec
());
_layerFrameSize
=
audiolayer
->
getFrameSize
();
// en ms
_layerSampleRate
=
audiolayer
->
getSampleRate
();
initBuffers
();
int
step
;
loadCodec
(
_ca
->
getAudioCodec
());
try
{
// Init the session
...
...
src/audio/gsmcodec.h
deleted
100644 → 0
View file @
4cab06ab
/*
* Copyright (C) 2004-2005-2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@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.
*/
#ifndef __GSM_H__
#define __GSM_H__
#include
<gsm.h>
#include
"audiocodec.h"
/*extern "C" {
#include "gsm/gsm.h"
}*/
/**
* GSM audio codec C++ class (over gsm/gsm.h)
*/
class
Gsm
:
public
AudioCodec
{
public:
// _payload should be 3
Gsm
(
int
payload
=
3
);
~
Gsm
(
void
);
int
codecDecode
(
short
*
,
unsigned
char
*
,
unsigned
int
);
int
codecEncode
(
unsigned
char
*
,
short
*
,
unsigned
int
);
void
test
();
private:
gsm
_decode_gsmhandle
;
gsm
_encode_gsmhandle
;
};
#endif // __ULAW_H__
src/audio/
CodecSpeex
.cpp
→
src/audio/
speexcodec
.cpp
View file @
884a4865
...
...
@@ -19,131 +19,94 @@
*/
#include
"audiocodec.h"
#include
<cstdio>
#include
<speex/speex.h>
class
CodecSpeex
:
public
AudioCodec
{
class
Speex
:
public
AudioCodec
{
public:
Codec
Speex
(
int
payload
=
0
)
Speex
(
int
payload
=
0
)
:
AudioCodec
(
payload
,
"speex"
)
{
_clockRate
=
8000
;
_channel
=
1
;
initSpeex
();
_clockRate
=
8000
;
_channel
=
1
;
initSpeex
();
}
int
getFrameSize
(){
return
_speex_frame_size
;
}
void
initSpeex
()
{
if
(
_clockRate
<
16000
)
{
/*
if (_clockRate < 16000 ) {
_speexModePtr = &speex_nb_mode;
}
else
if
(
_clockRate
<
32000
)
{
} else if (_clockRate < 32000) {
_speexModePtr = &speex_wb_mode;
}
else
{
} else {
_speexModePtr = &speex_uwb_mode;
}
}
*/
// 8000 HZ --> Narrow-band mode
// TODO Manage the other modes
_speexModePtr
=
&
speex_nb_mode
;
speex_bits_init
(
&
_speex_dec_bits
);
_speex_dec_state
=
speex_decoder_init
(
_speexModePtr
);
// Init the decoder struct
speex_bits_init
(
&
_speex_dec_bits
);
_speex_dec_state
=
speex_decoder_init
(
_speexModePtr
);
speex_bits_init
(
&
_speex_enc_bits
);
_speex_enc_state
=
speex_encoder_init
(
_speexModePtr
);
// Init the encoder struct
speex_bits_init
(
&
_speex_enc_bits
);
_speex_enc_state
=
speex_encoder_init
(
_speexModePtr
);
speex_decoder_ctl
(
_speex_dec_state
,
SPEEX_GET_FRAME_SIZE
,
&
_speex_frame_size
);
speex_decoder_ctl
(
_speex_dec_state
,
SPEEX_GET_FRAME_SIZE
,
&
_speex_frame_size
);
}
~
Codec
Speex
()
~
Speex
()
{
terminateSpeex
();
terminateSpeex
();
}
void
terminateSpeex
()
{
speex_bits_destroy
(
&
_speex_dec_bits
);
speex_decoder_destroy
(
_speex_dec_state
);
_speex_dec_state
=
0
;
speex_bits_destroy
(
&
_speex_enc_bits
);
speex_encoder_destroy
(
_speex_enc_state
);
_speex_enc_state
=
0
;
// 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
)
{
// void *enh; speex_decoder_ctl(dec_state, SPEEX_SET_ENH, &enh);
// decoding
speex_bits_read_from
(
&
_speex_dec_bits
,
(
char
*
)
src
,
size
);
//int return_status = speex_decode_int(_speex_dec_state, &_speex_dec_bits, dst);
// 0 = no error
// -1 = end of stream
// -2 = other
speex_decode_int
(
_speex_dec_state
,
&
_speex_dec_bits
,
dst
);
return
_speex_frame_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
_speex_frame_size
*
ratio
;
}
virtual
int
codecEncode
(
unsigned
char
*
dst
,
short
*
src
,
unsigned
int
size
)
{
speex_bits_reset
(
&
_speex_enc_bits
);
speex_encoder_ctl
(
_speex_enc_state
,
SPEEX_SET_SAMPLING_RATE
,
&
_clockRate
);
speex_bits_reset
(
&
_speex_enc_bits
);
speex_encoder_ctl
(
_speex_enc_state
,
SPEEX_SET_SAMPLING_RATE
,
&
_clockRate
);
speex_encode_int
(
_speex_enc_state
,
src
,
&
_speex_enc_bits
);
int
nbBytes
=
speex_bits_write
(
&
_speex_enc_bits
,
(
char
*
)
dst
,
size
);
return
nbBytes
;
speex_encode_int
(
_speex_enc_state
,
src
,
&
_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
;
SpeexBits
_speex_dec_bits
;
SpeexBits
_speex_enc_bits
;
void
*
_speex_dec_state
;
void
*
_speex_enc_state
;
int
_speex_frame_size
;
};
//the class factories
extern
"C"
AudioCodec
*
create
(){
return
new
Codec
Speex
(
110
);
//
the class factories
extern
"C"
AudioCodec
*
create
()
{
return
new
Speex
(
110
);
}
extern
"C"
void
destroy
(
AudioCodec
*
a
){
delete
a
;
extern
"C"
void
destroy
(
AudioCodec
*
a
)
{
delete
a
;
}
/*
* Speex example
* Test INT16 encoding to speex
* Copyrigth (C) 2005 Yan Morin <yan.morin@savoirfairelinux.com>
* Start: 2005-11-24
*/
/*
Test (without AudioCodec):
g++ -o CodecSpeex CodecSpeex.cpp -lspeex -lstdc++
#include <cstdio>
int main(void) {
CodecSpeex c(110);
int size = c.getFrameSize();
short* in = new short[size];
unsigned char* out = new unsigned char[size];
for (int i=0; i<size; i++) {in[i] = 0;}
for (int i=0; i<100; i++) { in[i] = 5000; }
int compSize = c.codecEncode(out, in, size);
for (int i=0; i<compSize; i++) { printf("%5d ", out[i]); }
printf("\nSize: %d\n", compSize);
for (int i=162; i<size; i++) { in[i] = 1000; }
compSize = c.codecDecode(in, out, compSize);
for (int i=0; i<size; i++) { printf("%5d ", in[i]); }
delete [] in;
delete [] out;
return 0;
}
*/
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