summaryrefslogtreecommitdiff
path: root/pjsip-apps
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-09-02 23:45:18 +0000
committerBenny Prijono <bennylp@teluu.com>2006-09-02 23:45:18 +0000
commit0b10957f8616c1e3c9ed66442f0f880fe5ead450 (patch)
tree2ad6e04e067263e8c874be0b4ae4e68ca62f09b3 /pjsip-apps
parent39b4b3d3bb933da80b4f80fb4561f031456fe8d1 (diff)
Added multi-purpose tone generator in PJMEDIA (tonegen.[hc])
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@693 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps')
-rw-r--r--pjsip-apps/build/Samples-vc.mak3
-rw-r--r--pjsip-apps/build/Samples.mak3
-rw-r--r--pjsip-apps/build/samples.dsp4
-rw-r--r--pjsip-apps/src/samples/debug.c3
-rw-r--r--pjsip-apps/src/samples/tonegen.c137
5 files changed, 146 insertions, 4 deletions
diff --git a/pjsip-apps/build/Samples-vc.mak b/pjsip-apps/build/Samples-vc.mak
index 9bb198de..c20c4407 100644
--- a/pjsip-apps/build/Samples-vc.mak
+++ b/pjsip-apps/build/Samples-vc.mak
@@ -48,7 +48,8 @@ SAMPLES = $(BINDIR)\confsample.exe \
$(BINDIR)\sipstateless.exe \
$(BINDIR)\sndinfo.exe \
$(BINDIR)\sndtest.exe \
- $(BINDIR)\streamutil.exe
+ $(BINDIR)\streamutil.exe \
+ $(BINDIR)\tonegen.exe
all: $(OBJDIR) $(SAMPLES)
diff --git a/pjsip-apps/build/Samples.mak b/pjsip-apps/build/Samples.mak
index e4d92eb8..997df26d 100644
--- a/pjsip-apps/build/Samples.mak
+++ b/pjsip-apps/build/Samples.mak
@@ -51,7 +51,8 @@ SAMPLES := confsample \
sipstateless \
sndinfo \
sndtest \
- streamutil
+ streamutil \
+ tonegen
EXES := $(foreach file, $(SAMPLES), $(BINDIR)/$(file)-$(TARGET_NAME)$(HOST_EXE))
diff --git a/pjsip-apps/build/samples.dsp b/pjsip-apps/build/samples.dsp
index 1b53137b..4005ac21 100644
--- a/pjsip-apps/build/samples.dsp
+++ b/pjsip-apps/build/samples.dsp
@@ -152,6 +152,10 @@ SOURCE=..\src\samples\sndtest.c
SOURCE=..\src\samples\streamutil.c
# End Source File
+# Begin Source File
+
+SOURCE=..\src\samples\tonegen.c
+# End Source File
# End Group
# Begin Group "Header Files"
diff --git a/pjsip-apps/src/samples/debug.c b/pjsip-apps/src/samples/debug.c
index ea31c9a7..13dafc0e 100644
--- a/pjsip-apps/src/samples/debug.c
+++ b/pjsip-apps/src/samples/debug.c
@@ -27,5 +27,4 @@
* E.g.:
* #include "playfile.c"
*/
-#include "aectest.c"
-
+#include "tonegen.c"
diff --git a/pjsip-apps/src/samples/tonegen.c b/pjsip-apps/src/samples/tonegen.c
new file mode 100644
index 00000000..de8925b1
--- /dev/null
+++ b/pjsip-apps/src/samples/tonegen.c
@@ -0,0 +1,137 @@
+/* $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
+ */
+#include <pjmedia.h>
+#include <pjlib.h>
+
+#define SAMPLES_PER_FRAME 64
+#define ON_DURATION 100
+#define OFF_DURATION 100
+
+
+/*
+ * main()
+ */
+int main()
+{
+ pj_caching_pool cp;
+ pjmedia_endpt *med_endpt;
+ pj_pool_t *pool;
+ pjmedia_port *port;
+ unsigned i;
+ pj_status_t status;
+
+
+ /* Must init PJLIB first: */
+ status = pj_init();
+ PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+ /* Must create a pool factory before we can allocate any memory. */
+ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
+
+ /*
+ * Initialize media endpoint.
+ * This will implicitly initialize PJMEDIA too.
+ */
+ status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
+ PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+ /* Create memory pool for our file player */
+ pool = pj_pool_create( &cp.factory, /* pool factory */
+ "app", /* pool name. */
+ 4000, /* init size */
+ 4000, /* increment size */
+ NULL /* callback on error */
+ );
+
+ status = pjmedia_tonegen_create(pool, 8000, 1, SAMPLES_PER_FRAME, 16, 0, &port);
+ if (status != PJ_SUCCESS)
+ return 1;
+
+ {
+ pjmedia_tone_desc tones[3];
+
+ tones[0].freq1 = 200;
+ tones[0].freq2 = 0;
+ tones[0].on_msec = ON_DURATION;
+ tones[0].off_msec = OFF_DURATION;
+
+ tones[1].freq1 = 400;
+ tones[1].freq2 = 0;
+ tones[1].on_msec = ON_DURATION;
+ tones[1].off_msec = OFF_DURATION;
+
+ tones[2].freq1 = 800;
+ tones[2].freq2 = 0;
+ tones[2].on_msec = ON_DURATION;
+ tones[2].off_msec = OFF_DURATION;
+
+ status = pjmedia_tonegen_play(port, 3, tones, 0);
+ PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);
+ }
+
+ {
+ pjmedia_tone_digit digits[2];
+
+ digits[0].digit = '0';
+ digits[0].on_msec = ON_DURATION;
+ digits[0].off_msec = OFF_DURATION;
+
+ digits[1].digit = '0';
+ digits[1].on_msec = ON_DURATION;
+ digits[1].off_msec = OFF_DURATION;
+
+ status = pjmedia_tonegen_play_digits(port, 2, digits, 0);
+ PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);
+ }
+
+ {
+ pjmedia_frame frm;
+ FILE *f;
+ void *buf;
+
+ buf = pj_pool_alloc(pool, 2*8000);
+ frm.buf = buf;
+
+ f = fopen("tonegen.pcm", "wb");
+
+ for (i=0; i<8000/SAMPLES_PER_FRAME; ++i) {
+ pjmedia_port_get_frame(port, &frm);
+ fwrite(buf, SAMPLES_PER_FRAME, 2, f);
+ }
+
+ pj_assert(pjmedia_tonegen_is_busy(port) == 0);
+ fclose(f);
+ }
+
+ /* Delete port */
+ pjmedia_port_destroy(port);
+
+ /* Release application pool */
+ pj_pool_release( pool );
+
+ /* Destroy media endpoint. */
+ pjmedia_endpt_destroy( med_endpt );
+
+ /* Destroy pool factory */
+ pj_caching_pool_destroy( &cp );
+
+
+ /* Done. */
+ return 0;
+}