Added macro to exclude filters in resample and added options to select resample algorithm in conference

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@347 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2006-03-21 11:59:15 +00:00
parent e260915ed7
commit 86ee4b4583
7 changed files with 96 additions and 14 deletions

View File

@ -61,6 +61,9 @@ enum pjmedia_conf_option
PJMEDIA_CONF_NO_MIC = 1, /**< Disable audio streams from the
microphone device. */
PJMEDIA_CONF_NO_DEVICE = 2, /**< Do not create sound device. */
PJMEDIA_CONF_SMALL_FILTER=4,/**< Use small filter table when resampling */
PJMEDIA_CONF_USE_LINEAR=8, /**< Use linear resampling instead of filter
based. */
};

View File

@ -41,10 +41,32 @@
/**
* Unless specified otherwise, G711 codec is included by default.
* Note that there are parts of G711 codec (such as linear2ulaw) that are
* needed by other PJMEDIA components (e.g. silence detector, conference).
* Thus disabling G711 is generally not a good idea.
*/
#ifndef PJMEDIA_HAS_G711_CODEC
# define PJMEDIA_HAS_G711_CODEC 1
#endif
/**
* Include small filter table in resample.
* This adds about 9KB in rdata.
*/
#ifndef PJMEDIA_HAS_SMALL_FILTER
# define PJMEDIA_HAS_SMALL_FILTER 1
#endif
/**
* Include large filter table in resample.
* This adds about 32KB in rdata.
*/
#ifndef PJMEDIA_HAS_LARGE_FILTER
# define PJMEDIA_HAS_LARGE_FILTER 1
#endif
#endif /* __PJMEDIA_CONFIG_H__ */

View File

@ -237,18 +237,21 @@ static pj_status_t create_conf_port( pj_pool_t *pool,
*/
if (conf_port->clock_rate != conf->clock_rate) {
double factor;
pj_bool_t high_quality;
pj_bool_t large_filter;
factor = 1.0 * conf_port->clock_rate / conf->clock_rate;
high_quality = ((conf->options & PJMEDIA_CONF_USE_LINEAR)==0);
large_filter = ((conf->options & PJMEDIA_CONF_SMALL_FILTER)==0);
/* Create resample for rx buffer. */
status = pjmedia_resample_create( pool,
PJ_TRUE, /* High quality */
PJ_TRUE, /* Large filter */
high_quality,
large_filter,
conf_port->clock_rate,/* Rate in */
conf->clock_rate, /* Rate out */
(unsigned)(conf->samples_per_frame *
factor),
conf->samples_per_frame *
conf_port->clock_rate /
conf->clock_rate,
&conf_port->rx_resample);
if (status != PJ_SUCCESS)
return status;
@ -256,8 +259,8 @@ static pj_status_t create_conf_port( pj_pool_t *pool,
/* Create resample for tx buffer. */
status = pjmedia_resample_create(pool,
PJ_TRUE, /* High quality */
PJ_TRUE, /* Large filter */
high_quality,
large_filter,
conf->clock_rate, /* Rate in */
conf_port->clock_rate, /* Rate out */
conf->samples_per_frame,

View File

@ -2,7 +2,7 @@
#define LARGE_FILTER_NMULT ((HWORD)65)
#define LARGE_FILTER_SCALE 14746 /* Unity-gain scale factor */
#define LARGE_FILTER_NWING 8192 /* Filter table length */
static HWORD LARGE_FILTER_IMP[] /* Impulse response */ = {
static const HWORD LARGE_FILTER_IMP[] /* Impulse response */ = {
32767,
32766,
32764,
@ -8196,7 +8196,7 @@ static HWORD LARGE_FILTER_IMP[] /* Impulse response */ = {
0,
0};
static HWORD LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
static const HWORD LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
-1,
-2,
-3,

View File

@ -65,9 +65,12 @@
#include <pjmedia/resample.h>
#include <pjmedia/errno.h>
#include <pj/assert.h>
#include <pj/log.h>
#include <pj/pool.h>
#define THIS_FILE "resample.c"
/*
* Taken from stddefs.h
@ -191,8 +194,26 @@ typedef unsigned int UWORD;
# pragma warning(disable: 4761) // integral size mismatch in argument; conversion supplied
#endif
#include "smallfilter.h"
#include "largefilter.h"
#if defined(PJMEDIA_HAS_SMALL_FILTER) && PJMEDIA_HAS_SMALL_FILTER!=0
# include "smallfilter.h"
#else
# define SMALL_FILTER_NMULT 0
# define SMALL_FILTER_SCALE 0
# define SMALL_FILTER_NWING 0
# define SMALL_FILTER_IMP NULL
# define SMALL_FILTER_IMPD NULL
#endif
#if defined(PJMEDIA_HAS_LARGE_FILTER) && PJMEDIA_HAS_LARGE_FILTER!=0
# include "largefilter.h"
#else
# define LARGE_FILTER_NMULT 0
# define LARGE_FILTER_SCALE 0
# define LARGE_FILTER_NWING 0
# define LARGE_FILTER_IMP NULL
# define LARGE_FILTER_IMPD NULL
#endif
#undef INLINE
#define INLINE
@ -480,6 +501,31 @@ PJ_DEF(pj_status_t) pjmedia_resample_create( pj_pool_t *pool,
high_quality = 0;
}
#if !defined(PJMEDIA_HAS_LARGE_FILTER) || PJMEDIA_HAS_LARGE_FILTER==0
/*
* If large filter is excluded in the build, then prevent application
* from using it.
*/
if (high_quality && large_filter) {
large_filter = PJ_FALSE;
PJ_LOG(5,(THIS_FILE,
"Resample uses small filter because large filter is "
"disabled"));
}
#endif
#if !defined(PJMEDIA_HAS_SMALL_FILTER) || PJMEDIA_HAS_SMALL_FILTER==0
/*
* If small filter is excluded in the build and application wants to
* use it, then drop to linear conversion.
*/
if (high_quality && large_filter == 0) {
high_quality = PJ_FALSE;
PJ_LOG(4,(THIS_FILE,
"Resample uses linear because small filter is disabled"));
}
#endif
resample->factor = rate_out * 1.0 / rate_in;
resample->large_filter = large_filter;
resample->high_quality = high_quality;

View File

@ -2,7 +2,7 @@
#define SMALL_FILTER_NMULT ((HWORD)13)
#define SMALL_FILTER_SCALE 13128 /* Unity-gain scale factor */
#define SMALL_FILTER_NWING 1536 /* Filter table length */
static HWORD SMALL_FILTER_IMP[] /* Impulse response */ = {
static const HWORD SMALL_FILTER_IMP[] /* Impulse response */ = {
32767,
32766,
32764,
@ -1541,7 +1541,7 @@ static HWORD SMALL_FILTER_IMP[] /* Impulse response */ = {
-1
};
static HWORD SMALL_FILTER_IMPD[] = {
static const HWORD SMALL_FILTER_IMPD[] = {
-1,
-2,
-4,

View File

@ -90,6 +90,10 @@ SOURCE=..\src\samples\confsample.c
# End Source File
# Begin Source File
SOURCE=..\src\samples\level.c
# End Source File
# Begin Source File
SOURCE=..\src\samples\playfile.c
# End Source File
# Begin Source File
@ -100,6 +104,10 @@ SOURCE=..\src\samples\playsine.c
SOURCE=..\src\samples\simpleua.c
# End Source File
# Begin Source File
SOURCE=..\src\samples\sndinfo.c
# End Source File
# End Group
# Begin Group "Header Files"