summaryrefslogtreecommitdiff
path: root/pjmedia/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-11-30 01:35:00 +0000
committerBenny Prijono <bennylp@teluu.com>2006-11-30 01:35:00 +0000
commit634423cd1e3f12d6cc70c8e6564d40e986eb0312 (patch)
tree02911836861d548916367a6e1b572bc005383d32 /pjmedia/include
parenta35cd16ec8ea8289b0c8a975ee858d39461a9cd9 (diff)
Implement task #26: integrate table based Alaw/Ulaw/linear conversion into pjmedia (thanks Toni Rutar for the original contribution)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@838 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/include')
-rw-r--r--pjmedia/include/pjmedia.h1
-rw-r--r--pjmedia/include/pjmedia/alaw_ulaw.h142
-rw-r--r--pjmedia/include/pjmedia/config.h11
3 files changed, 154 insertions, 0 deletions
diff --git a/pjmedia/include/pjmedia.h b/pjmedia/include/pjmedia.h
index 7a4375bf..1402327c 100644
--- a/pjmedia/include/pjmedia.h
+++ b/pjmedia/include/pjmedia.h
@@ -25,6 +25,7 @@
*/
#include <pjmedia/types.h>
+#include <pjmedia/alaw_ulaw.h>
#include <pjmedia/bidirectional.h>
#include <pjmedia/clock.h>
#include <pjmedia/codec.h>
diff --git a/pjmedia/include/pjmedia/alaw_ulaw.h b/pjmedia/include/pjmedia/alaw_ulaw.h
new file mode 100644
index 00000000..7d75bbf4
--- /dev/null
+++ b/pjmedia/include/pjmedia/alaw_ulaw.h
@@ -0,0 +1,142 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJMEDIA_ALAW_ULAW_H__
+#define __PJMEDIA_ALAW_ULAW_H__
+
+#include <pjmedia/types.h>
+
+#if defined(PJMEDIA_HAS_ALAW_ULAW_TABLE) && PJMEDIA_HAS_ALAW_ULAW_TABLE!=0
+
+extern const pj_uint8_t pjmedia_linear2ulaw_tab[16384];
+extern const pj_uint8_t pjmedia_linear2alaw_tab[16384];
+extern const pj_int16_t pjmedia_ulaw2linear_tab[256];
+extern const pj_int16_t pjmedia_alaw2linear_tab[256];
+
+
+/**
+ * Convert 16-bit linear PCM value to 8-bit A-Law.
+ *
+ * @param pcm_val 16-bit linear PCM value.
+ * @return 8-bit A-Law value.
+ */
+#define pjmedia_linear2alaw(pcm_val) \
+ pjmedia_linear2alaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
+
+/**
+ * Convert 8-bit A-Law value to 16-bit linear PCM value.
+ *
+ * @param chara_val 8-bit A-Law value.
+ * @return 16-bit linear PCM value.
+ */
+#define pjmedia_alaw2linear(chara_val) \
+ pjmedia_alaw2linear_tab[chara_val]
+
+/**
+ * Convert 16-bit linear PCM value to 8-bit U-Law.
+ *
+ * @param pcm_val 16-bit linear PCM value.
+ * @return U-bit A-Law value.
+ */
+#define pjmedia_linear2ulaw(pcm_val) \
+ pjmedia_linear2ulaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
+
+/**
+ * Convert 8-bit U-Law value to 16-bit linear PCM value.
+ *
+ * @param u_val 8-bit U-Law value.
+ * @return 16-bit linear PCM value.
+ */
+#define pjmedia_ulaw2linear(u_val) \
+ pjmedia_ulaw2linear_tab[u_val]
+
+/**
+ * Convert 8-bit A-Law value to 8-bit U-Law value.
+ *
+ * @param aval 8-bit A-Law value.
+ * @return 8-bit U-Law value.
+ */
+#define pjmedia_alaw2ulaw(aval) \
+ pjmedia_linear2ulaw(pjmedia_alaw2linear(aval))
+
+/**
+ * Convert 8-bit U-Law value to 8-bit A-Law value.
+ *
+ * @param uval 8-bit U-Law value.
+ * @return 8-bit A-Law value.
+ */
+#define pjmedia_ulaw2alaw(uval) \
+ pjmedia_linear2alaw(pjmedia_ulaw2linear(uval))
+
+
+#else
+
+/**
+ * Convert 16-bit linear PCM value to 8-bit A-Law.
+ *
+ * @param pcm_val 16-bit linear PCM value.
+ * @return 8-bit A-Law value.
+ */
+PJ_DECL(pj_uint8_t) pjmedia_linear2alaw(int pcm_val);
+
+/**
+ * Convert 8-bit A-Law value to 16-bit linear PCM value.
+ *
+ * @param chara_val 8-bit A-Law value.
+ * @return 16-bit linear PCM value.
+ */
+PJ_DECL(int) pjmedia_alaw2linear(unsigned chara_val);
+
+/**
+ * Convert 16-bit linear PCM value to 8-bit U-Law.
+ *
+ * @param pcm_val 16-bit linear PCM value.
+ * @return U-bit A-Law value.
+ */
+PJ_DECL(unsigned char) pjmedia_linear2ulaw(int pcm_val);
+
+/**
+ * Convert 8-bit U-Law value to 16-bit linear PCM value.
+ *
+ * @param u_val 8-bit U-Law value.
+ * @return 16-bit linear PCM value.
+ */
+PJ_DECL(int) pjmedia_ulaw2linear(unsigned char u_val);
+
+/**
+ * Convert 8-bit A-Law value to 8-bit U-Law value.
+ *
+ * @param aval 8-bit A-Law value.
+ * @return 8-bit U-Law value.
+ */
+PJ_DECL(unsigned char) pjmedia_alaw2ulaw(unsigned char aval);
+
+/**
+ * Convert 8-bit U-Law value to 8-bit A-Law value.
+ *
+ * @param uval 8-bit U-Law value.
+ * @return 8-bit A-Law value.
+ */
+PJ_DECL(unsigned char) pjmedia_ulaw2alaw(unsigned char uval);
+
+
+#endif
+
+
+#endif /* __PJMEDIA_ALAW_ULAW_H__ */
+
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h
index aa095f5d..b705e6f4 100644
--- a/pjmedia/include/pjmedia/config.h
+++ b/pjmedia/include/pjmedia/config.h
@@ -66,6 +66,17 @@
/**
+ * Specify which A-law/U-law conversion algorithm to use.
+ * By default the conversion algorithm uses A-law/U-law table which gives
+ * the best performance, at the expense of 33 KBytes of static data.
+ * If this option is disabled, a smaller but slower algorithm will be used.
+ */
+#ifndef PJMEDIA_HAS_ALAW_ULAW_TABLE
+# define PJMEDIA_HAS_ALAW_ULAW_TABLE 1
+#endif
+
+
+/**
* 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).