summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-03-21 11:59:15 +0000
committerBenny Prijono <bennylp@teluu.com>2006-03-21 11:59:15 +0000
commit1ac65f3b18e59cd2206dfb8c237ca1007e1d873e (patch)
treec1c34eca18160c62a9effc79e09ffdd449bc8ae7
parent61ff349aa29d8d3457120275a7213b72b57b785f (diff)
Added macro to exclude filters in resample and added options to select resample algorithm in conference
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@347 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/conference.h3
-rw-r--r--pjmedia/include/pjmedia/config.h22
-rw-r--r--pjmedia/src/pjmedia/conference.c19
-rw-r--r--pjmedia/src/pjmedia/largefilter.h4
-rw-r--r--pjmedia/src/pjmedia/resample.c50
-rw-r--r--pjmedia/src/pjmedia/smallfilter.h4
-rw-r--r--pjsip-apps/build/samples.dsp8
7 files changed, 96 insertions, 14 deletions
diff --git a/pjmedia/include/pjmedia/conference.h b/pjmedia/include/pjmedia/conference.h
index f93e0e58..bde63f77 100644
--- a/pjmedia/include/pjmedia/conference.h
+++ b/pjmedia/include/pjmedia/conference.h
@@ -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. */
};
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h
index 66f42d5e..c81693a5 100644
--- a/pjmedia/include/pjmedia/config.h
+++ b/pjmedia/include/pjmedia/config.h
@@ -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__ */
+
diff --git a/pjmedia/src/pjmedia/conference.c b/pjmedia/src/pjmedia/conference.c
index 456dcc4f..c6cb1278 100644
--- a/pjmedia/src/pjmedia/conference.c
+++ b/pjmedia/src/pjmedia/conference.c
@@ -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,
diff --git a/pjmedia/src/pjmedia/largefilter.h b/pjmedia/src/pjmedia/largefilter.h
index 16c0c3fc..d237b5cb 100644
--- a/pjmedia/src/pjmedia/largefilter.h
+++ b/pjmedia/src/pjmedia/largefilter.h
@@ -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,
diff --git a/pjmedia/src/pjmedia/resample.c b/pjmedia/src/pjmedia/resample.c
index 246f4cc6..9045a02c 100644
--- a/pjmedia/src/pjmedia/resample.c
+++ b/pjmedia/src/pjmedia/resample.c
@@ -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;
diff --git a/pjmedia/src/pjmedia/smallfilter.h b/pjmedia/src/pjmedia/smallfilter.h
index 6f6f0f84..367999d4 100644
--- a/pjmedia/src/pjmedia/smallfilter.h
+++ b/pjmedia/src/pjmedia/smallfilter.h
@@ -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,
diff --git a/pjsip-apps/build/samples.dsp b/pjsip-apps/build/samples.dsp
index 9cc5cb48..acc4663f 100644
--- a/pjsip-apps/build/samples.dsp
+++ b/pjsip-apps/build/samples.dsp
@@ -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"