<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16259] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16259">16259</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2010-01-12 09:03:06 -0600 (Tue, 12 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>gsmopen: added portaudio_gsmlib_cplusplus_noalsa directory, to compile with portaudio and speex and gsmlib. This will hopefully ***run on windows and mac*** AND solve the sidetone echo generated by cellphones used as interfaces</pre>

<h3>Added Paths</h3>
<ul>
<li>freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/</li>
<li>freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/</li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenMakefile">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/Makefile</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopengsmopenh">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen.h</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopengsmopen_protocolcpp">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen_protocol.cpp</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenmod_gsmopencpp">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/mod_gsmopen.cpp</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpa_ringbufferc">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.c</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpa_ringbufferh">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.h</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpablioc">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.c</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpablioh">freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenMakefile"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/Makefile (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/Makefile                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/Makefile        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+MODNAME=mod_gsmopen
+SVNDEF := -D'GSMOPEN_SVN_VERSION=&quot;$(shell svnversion -n .)&quot;'
+LOCAL_CFLAGS += $(SVNDEF) -DNO_ALSA -DGSMOPEN_PORTAUDIO
+LOCAL_LDFLAGS=-lportaudio -lspeex -lspeexdsp -lgsmme
+LOCAL_OBJS=gsmopen_protocol.o pablio.o pa_ringbuffer.o
+include ../../../../../../build/modmake.rules
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopengsmopenh"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen.h (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen.h                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen.h        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+link ../../gsmopen.h
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen.h
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:special
</span><span class="cx">   + *
</span></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopengsmopen_protocolcpp"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen_protocol.cpp (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen_protocol.cpp                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen_protocol.cpp        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+link ../../gsmopen_protocol.cpp
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/gsmopen_protocol.cpp
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:special
</span><span class="cx">   + *
</span></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenmod_gsmopencpp"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/mod_gsmopen.cpp (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/mod_gsmopen.cpp                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/mod_gsmopen.cpp        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+link ../../mod_gsmopen.cpp
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/mod_gsmopen.cpp
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:special
</span><span class="cx">   + *
</span></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpa_ringbufferc"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.c (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.c                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.c        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1,275 @@
</span><ins>+/*
+ * $Id: pa_ringbuffer.c 1164 2006-12-21 15:34:50Z bjornroche $
+ * Portable Audio I/O Library
+ * Ring Buffer utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ * modified for SMP safety on Mac OS X by Bjorn Roche
+ * modified for SMP safety on Linux by Leland Lucius
+ * also, allowed for const where possible
+ * Note that this is safe only for a single-thread reader and a
+ * single-thread writer.
+ *
+ * This program uses the PortAudio Portable Audio Library.
+ * For more information see: http://www.portaudio.com
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the &quot;Software&quot;), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * The text above constitutes the entire PortAudio license; however, 
+ * the PortAudio community also makes the following non-binding requests:
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version. It is also 
+ * requested that these non-binding requests be included along with the 
+ * license above.
+ */
+
+/**
+ @file
+ @ingroup common_src
+*/
+
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;math.h&gt;
+#include &quot;pa_ringbuffer.h&quot;
+#include &lt;string.h&gt;
+
+/****************
+ * First, we'll define some memory barrier primitives based on the system.
+ * right now only OS X, FreeBSD, and Linux are supported. In addition to providing
+ * memory barriers, these functions should ensure that data cached in registers
+ * is written out to cache where it can be snooped by other CPUs. (ie, the volatile
+ * keyword should not be required)
+ *
+ * the primitives that must be defined are:
+ *
+ * PaUtil_FullMemoryBarrier()
+ * PaUtil_ReadMemoryBarrier()
+ * PaUtil_WriteMemoryBarrier()
+ *
+ ****************/
+#define __VIA_HACK__
+#if defined(__VIA_HACK__)
+#define NO_BARRIER
+#endif
+
+#if defined(NO_BARRIER)
+#   define PaUtil_FullMemoryBarrier()
+#   define PaUtil_ReadMemoryBarrier()
+#   define PaUtil_WriteMemoryBarrier()
+#else
+
+#if defined(__APPLE__)                        //|| defined(__FreeBSD__)
+#   include &lt;libkern/OSAtomic.h&gt;
+        /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
+           full memory barriers, so the three types of barriers are the same. */
+#   define PaUtil_FullMemoryBarrier()  OSMemoryBarrier()
+#   define PaUtil_ReadMemoryBarrier()  OSMemoryBarrier()
+#   define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
+#elif defined(__GNUC__)
+
+        /* GCC understands volatile asm and &quot;memory&quot; to mean it
+         * should not reorder memory read/writes */
+#   if defined( __PPC__ )
+#      define PaUtil_FullMemoryBarrier()  __asm__ volatile(&quot;sync&quot;:::&quot;memory&quot;)
+#      define PaUtil_ReadMemoryBarrier()  __asm__ volatile(&quot;sync&quot;:::&quot;memory&quot;)
+#      define PaUtil_WriteMemoryBarrier() __asm__ volatile(&quot;sync&quot;:::&quot;memory&quot;)
+#   elif defined( __i386__ ) || defined( __i486__ ) || defined( __i586__ ) || defined( __i686__ ) || defined(__x86_64__)
+#      define PaUtil_FullMemoryBarrier()  __asm__ volatile(&quot;mfence&quot;:::&quot;memory&quot;)
+#      define PaUtil_ReadMemoryBarrier()  __asm__ volatile(&quot;lfence&quot;:::&quot;memory&quot;)
+#      define PaUtil_WriteMemoryBarrier() __asm__ volatile(&quot;sfence&quot;:::&quot;memory&quot;)
+#   else
+#      define PaUtil_FullMemoryBarrier()
+#      define PaUtil_ReadMemoryBarrier()
+#      define PaUtil_WriteMemoryBarrier()
+#   endif
+#elif defined(_MSC_VER)
+#   include &lt;intrin.h&gt;
+#   pragma intrinsic(_ReadWriteBarrier)
+#   pragma intrinsic(_ReadBarrier)
+#   pragma intrinsic(_WriteBarrier)
+#   define PaUtil_FullMemoryBarrier()  _ReadWriteBarrier()
+#   define PaUtil_ReadMemoryBarrier()  _ReadBarrier()
+#   define PaUtil_WriteMemoryBarrier() _WriteBarrier()
+#else
+#   define PaUtil_FullMemoryBarrier()
+#   define PaUtil_ReadMemoryBarrier()
+#   define PaUtil_WriteMemoryBarrier()
+#endif
+#endif
+/***************************************************************************
+ * Initialize FIFO.
+ * numBytes must be power of 2, returns -1 if not.
+ */
+long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr)
+{
+        if (((numBytes - 1) &amp; numBytes) != 0)
+                return -1;                                /* Not Power of two. */
+        rbuf-&gt;bufferSize = numBytes;
+        rbuf-&gt;buffer = (char *) dataPtr;
+        PaUtil_FlushRingBuffer(rbuf);
+        rbuf-&gt;bigMask = (numBytes * 2) - 1;
+        rbuf-&gt;smallMask = (numBytes) - 1;
+        return 0;
+}
+
+/***************************************************************************
+** Return number of bytes available for reading. */
+long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf)
+{
+        PaUtil_ReadMemoryBarrier();
+        return ((rbuf-&gt;writeIndex - rbuf-&gt;readIndex) &amp; rbuf-&gt;bigMask);
+}
+
+/***************************************************************************
+** Return number of bytes available for writing. */
+long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf)
+{
+        /* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
+        return (rbuf-&gt;bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
+}
+
+/***************************************************************************
+** Clear buffer. Should only be called when buffer is NOT being read. */
+void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf)
+{
+        rbuf-&gt;writeIndex = rbuf-&gt;readIndex = 0;
+}
+
+/***************************************************************************
+** Get address of region(s) to which we can write data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be written or numBytes, whichever is smaller.
+*/
+long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
+{
+        long index;
+        long available = PaUtil_GetRingBufferWriteAvailable(rbuf);
+        if (numBytes &gt; available)
+                numBytes = available;
+        /* Check to see if write is not contiguous. */
+        index = rbuf-&gt;writeIndex &amp; rbuf-&gt;smallMask;
+        if ((index + numBytes) &gt; rbuf-&gt;bufferSize) {
+                /* Write data in two blocks that wrap the buffer. */
+                long firstHalf = rbuf-&gt;bufferSize - index;
+                *dataPtr1 = &amp;rbuf-&gt;buffer[index];
+                *sizePtr1 = firstHalf;
+                *dataPtr2 = &amp;rbuf-&gt;buffer[0];
+                *sizePtr2 = numBytes - firstHalf;
+        } else {
+                *dataPtr1 = &amp;rbuf-&gt;buffer[index];
+                *sizePtr1 = numBytes;
+                *dataPtr2 = NULL;
+                *sizePtr2 = 0;
+        }
+        return numBytes;
+}
+
+
+/***************************************************************************
+*/
+long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes)
+{
+        /* we need to ensure that previous writes are seen before we update the write index */
+        PaUtil_WriteMemoryBarrier();
+        return rbuf-&gt;writeIndex = (rbuf-&gt;writeIndex + numBytes) &amp; rbuf-&gt;bigMask;
+}
+
+/***************************************************************************
+** Get address of region(s) from which we can read data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be written or numBytes, whichever is smaller.
+*/
+long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
+{
+        long index;
+        long available = PaUtil_GetRingBufferReadAvailable(rbuf);
+        if (numBytes &gt; available)
+                numBytes = available;
+        /* Check to see if read is not contiguous. */
+        index = rbuf-&gt;readIndex &amp; rbuf-&gt;smallMask;
+        if ((index + numBytes) &gt; rbuf-&gt;bufferSize) {
+                /* Write data in two blocks that wrap the buffer. */
+                long firstHalf = rbuf-&gt;bufferSize - index;
+                *dataPtr1 = &amp;rbuf-&gt;buffer[index];
+                *sizePtr1 = firstHalf;
+                *dataPtr2 = &amp;rbuf-&gt;buffer[0];
+                *sizePtr2 = numBytes - firstHalf;
+        } else {
+                *dataPtr1 = &amp;rbuf-&gt;buffer[index];
+                *sizePtr1 = numBytes;
+                *dataPtr2 = NULL;
+                *sizePtr2 = 0;
+        }
+        return numBytes;
+}
+
+/***************************************************************************
+*/
+long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes)
+{
+        /* we need to ensure that previous writes are always seen before updating the index. */
+        PaUtil_WriteMemoryBarrier();
+        return rbuf-&gt;readIndex = (rbuf-&gt;readIndex + numBytes) &amp; rbuf-&gt;bigMask;
+}
+
+/***************************************************************************
+** Return bytes written. */
+long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes)
+{
+        long size1, size2, numWritten;
+        void *data1, *data2;
+        numWritten = PaUtil_GetRingBufferWriteRegions(rbuf, numBytes, &amp;data1, &amp;size1, &amp;data2, &amp;size2);
+        if (size2 &gt; 0) {
+
+                memcpy(data1, data, size1);
+                data = ((char *) data) + size1;
+                memcpy(data2, data, size2);
+        } else {
+                memcpy(data1, data, size1);
+        }
+        PaUtil_AdvanceRingBufferWriteIndex(rbuf, numWritten);
+        return numWritten;
+}
+
+/***************************************************************************
+** Return bytes read. */
+long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes)
+{
+        long size1, size2, numRead;
+        void *data1, *data2;
+        numRead = PaUtil_GetRingBufferReadRegions(rbuf, numBytes, &amp;data1, &amp;size1, &amp;data2, &amp;size2);
+        if (size2 &gt; 0) {
+                memcpy(data, data1, size1);
+                data = ((char *) data) + size1;
+                memcpy(data, data2, size2);
+        } else {
+                memcpy(data, data1, size1);
+        }
+        PaUtil_AdvanceRingBufferReadIndex(rbuf, numRead);
+        return numRead;
+}
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpa_ringbufferh"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.h (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.h                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pa_ringbuffer.h        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1,192 @@
</span><ins>+#ifndef PA_RINGBUFFER_H
+#define PA_RINGBUFFER_H
+/*
+ * $Id: pa_ringbuffer.h 1151 2006-11-29 02:11:16Z leland_lucius $
+ * Portable Audio I/O Library
+ * Ring Buffer utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ * modified for SMP safety on OS X by Bjorn Roche.
+ * also allowed for const where possible.
+ * Note that this is safe only for a single-thread reader
+ * and a single-thread writer.
+ *
+ * This program is distributed with the PortAudio Portable Audio Library.
+ * For more information see: http://www.portaudio.com
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the &quot;Software&quot;), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * The text above constitutes the entire PortAudio license; however, 
+ * the PortAudio community also makes the following non-binding requests:
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version. It is also 
+ * requested that these non-binding requests be included along with the 
+ * license above.
+ */
+
+/** @file
+ @ingroup common_src
+*/
+
+#ifdef __cplusplus
+extern &quot;C&quot; {
+#endif                                                        /* __cplusplus */
+
+        typedef struct PaUtilRingBuffer {
+                long bufferSize;                /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
+                long writeIndex;                /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
+                long readIndex;                        /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
+                long bigMask;                        /* Used for wrapping indices with extra bit to distinguish full/empty. */
+                long smallMask;                        /* Used for fitting indices to buffer. */
+                char *buffer;
+        } PaUtilRingBuffer;
+
+/** Initialize Ring Buffer.
+
+ @param rbuf The ring buffer.
+
+ @param numBytes The number of bytes in the buffer and must be power of 2.
+
+ @param dataPtr A pointer to a previously allocated area where the data
+ will be maintained.  It must be numBytes long.
+
+ @return -1 if numBytes is not a power of 2, otherwise 0.
+*/
+        long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr);
+
+/** Clear buffer. Should only be called when buffer is NOT being read.
+
+ @param rbuf The ring buffer.
+*/
+        void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf);
+
+/** Retrieve the number of bytes available in the ring buffer for writing.
+
+ @param rbuf The ring buffer.
+
+ @return The number of bytes available for writing.
+*/
+        long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf);
+
+/** Retrieve the number of bytes available in the ring buffer for reading.
+
+ @param rbuf The ring buffer.
+
+ @return The number of bytes available for reading.
+*/
+        long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf);
+
+/** Write data to the ring buffer.
+
+ @param rbuf The ring buffer.
+
+ @param data The address of new data to write to the buffer.
+
+ @param numBytes The number of bytes to be written.
+
+ @return The number of bytes written.
+*/
+        long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes);
+
+/** Read data from the ring buffer.
+
+ @param rbuf The ring buffer.
+
+ @param data The address where the data should be stored.
+
+ @param numBytes The number of bytes to be read.
+
+ @return The number of bytes read.
+*/
+        long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes);
+
+/** Get address of region(s) to which we can write data.
+
+ @param rbuf The ring buffer.
+
+ @param numBytes The number of bytes desired.
+
+ @param dataPtr1 The address where the first (or only) region pointer will be
+ stored.
+
+ @param sizePtr1 The address where the first (or only) region length will be
+ stored.
+
+ @param dataPtr2 The address where the second region pointer will be stored if
+ the first region is too small to satisfy numBytes.
+
+ @param sizePtr2 The address where the second region length will be stored if
+ the first region is too small to satisfy numBytes.
+
+ @return The room available to be written or numBytes, whichever is smaller.
+*/
+        long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
+
+/** Advance the write index to the next location to be written.
+
+ @param rbuf The ring buffer.
+
+ @param numBytes The number of bytes to advance.
+
+ @return The new position.
+*/
+        long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes);
+
+/** Get address of region(s) from which we can write data.
+
+ @param rbuf The ring buffer.
+
+ @param numBytes The number of bytes desired.
+
+ @param dataPtr1 The address where the first (or only) region pointer will be
+ stored.
+
+ @param sizePtr1 The address where the first (or only) region length will be
+ stored.
+
+ @param dataPtr2 The address where the second region pointer will be stored if
+ the first region is too small to satisfy numBytes.
+
+ @param sizePtr2 The address where the second region length will be stored if
+ the first region is too small to satisfy numBytes.
+
+ @return The number of bytes available for reading.
+*/
+        long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
+
+/** Advance the read index to the next location to be read.
+
+ @param rbuf The ring buffer.
+
+ @param numBytes The number of bytes to advance.
+
+ @return The new position.
+*/
+        long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes);
+
+#ifdef __cplusplus
+}
+#endif                                                        /* __cplusplus */
+#endif                                                        /* PA_RINGBUFFER_H */
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpablioc"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.c (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.c                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.c        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1,491 @@
</span><ins>+/*
+ * $Id: pablio.c 1151 2006-11-29 02:11:16Z leland_lucius $
+ * pablio.c
+ * Portable Audio Blocking Input/Output utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ *
+ * This program uses the PortAudio Portable Audio Library.
+ * For more information see: http://www.portaudio.com
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the &quot;Software&quot;), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * The text above constitutes the entire PortAudio license; however, 
+ * the PortAudio community also makes the following non-binding requests:
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version. It is also 
+ * requested that these non-binding requests be included along with the 
+ * license above.
+ */
+
+#undef GIOVA48
+
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;math.h&gt;
+#include &quot;portaudio.h&quot;
+#include &quot;pa_ringbuffer.h&quot;
+#include &quot;pablio.h&quot;
+#include &lt;string.h&gt;
+#include &lt;time.h&gt;
+
+/************************************************************************/
+/******** Prototypes ****************************************************/
+/************************************************************************/
+
+static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
+                              unsigned long framesPerBuffer,
+                              const PaStreamCallbackTimeInfo * timeInfo,
+                              PaStreamCallbackFlags statusFlags, void *userData);
+static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames,
+                               long bytesPerFrame);
+static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
+
+/************************************************************************/
+/******** Functions *****************************************************/
+/************************************************************************/
+
+/* Called from PortAudio.
+ * Read and write data 
+ */
+static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
+                              unsigned long framesPerBuffer,
+                              const PaStreamCallbackTimeInfo * timeInfo,
+                              PaStreamCallbackFlags statusFlags, void *userData)
+{
+  PABLIO_Stream *data = (PABLIO_Stream *) userData;
+  long numBytes = data-&gt;bytesPerFrame * framesPerBuffer;
+  char c = 'M';
+#ifdef WANT_SPEEX
+  spx_int16_t *in;
+  spx_int16_t *out;
+  unsigned int i = 0;
+#ifndef GIOVA48
+  spx_int16_t pcm2[160];
+#else //GIOVA48
+  spx_int16_t pcm2[960];
+#endif //GIOVA48
+#endif // WANT_SPEEX
+
+  /* This may get called with NULL inputBuffer during initial setup. */
+  if (inputBuffer == NULL) {
+    fprintf(stderr, &quot;INPUT NULL\n\n\n\n&quot;);
+    return 0;
+  }
+  if (outputBuffer == NULL) {
+    fprintf(stderr, &quot;OUTPUT NULL\n\n\n\n&quot;);
+    return 0;
+  }
+
+#ifdef WANT_SPEEX
+  in = ((spx_int16_t *) inputBuffer);
+  out = ((spx_int16_t *) outputBuffer);
+#endif // WANT_SPEEX
+
+/****************
+ * THIS IS SPK (RX data from network)
+ ****************/
+  if (outputBuffer != NULL) {
+    int i;
+    int numRead = PaUtil_ReadRingBuffer(&amp;data-&gt;outFIFO, outputBuffer, numBytes);
+    /* Zero out remainder of buffer if we run out of data. */
+    for (i = numRead; i &lt; numBytes; i++) {
+      ((char *) outputBuffer)[i] = 0;
+    }
+  }
+#ifdef WANT_SPEEX
+  if (*data-&gt;speexecho &amp;&amp; *(long *) data-&gt;owner) {
+    /* Put frame into playback buffer */
+    speex_echo_playback(data-&gt;echo_state, out);
+  }
+  if (*data-&gt;speexecho &amp;&amp; *(long *) data-&gt;owner) {
+    /* Perform echo cancellation */
+    speex_echo_capture(data-&gt;echo_state, in, pcm2);
+#ifndef GIOVA48
+    for (i = 0; i &lt; 160; i++)
+#else //GIOVA48
+    for (i = 0; i &lt; 960; i++)
+#endif //GIOVA48
+      in[i] = pcm2[i];
+  }
+  /* Apply noise/echo residual suppression */
+  if (*data-&gt;speexpreprocess &amp;&amp; *(long *) data-&gt;owner) {
+    speex_preprocess_run(data-&gt;preprocess, in);
+  }
+#endif // WANT_SPEEX
+
+/***************
+ * THIS IS MIC (TX data to network)
+ ***************/
+  /* This may get called with NULL inputBuffer during initial setup. */
+  if (inputBuffer != NULL) {
+    if (PaUtil_WriteRingBuffer(&amp;data-&gt;inFIFO, inputBuffer, numBytes) != numBytes) {
+      PaUtil_FlushRingBuffer(&amp;data-&gt;inFIFO);
+      PaUtil_WriteRingBuffer(&amp;data-&gt;inFIFO, inputBuffer, numBytes);
+    }
+  }
+  write(data-&gt;audioreadpipe, &amp;c, 1);
+  return 0;
+}
+
+/* Allocate buffer. */
+static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames,
+                               long bytesPerFrame)
+{
+  long numBytes = numFrames * bytesPerFrame;
+  char *buffer = (char *) malloc(numBytes);
+  if (buffer == NULL)
+    return paInsufficientMemory;
+  memset(buffer, 0, numBytes);
+  return (PaError) PaUtil_InitializeRingBuffer(rbuf, numBytes, buffer);
+}
+
+/* Free buffer. */
+static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf)
+{
+  if (rbuf-&gt;buffer)
+    free(rbuf-&gt;buffer);
+  rbuf-&gt;buffer = NULL;
+  return paNoError;
+}
+
+/************************************************************
+ * Write data to ring buffer.
+ * Will not return until all the data has been written.
+ */
+long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
+{
+  long bytesWritten;
+  char *p = (char *) data;
+  long numBytes = aStream-&gt;bytesPerFrame * numFrames;
+  int tried = 0;
+
+  //printf(&quot;numBytes=%d, aStream-&gt;bytesPerFrame=%d, numFrames=%d\n&quot;, numBytes, aStream-&gt;bytesPerFrame, numFrames);
+  
+  while (numBytes &gt; 0) {
+    bytesWritten = PaUtil_WriteRingBuffer(&amp;aStream-&gt;outFIFO, p, numBytes);
+    numBytes -= bytesWritten;
+    p += bytesWritten;
+    if (numBytes &gt; 0 &amp;&amp; tried == 10) {
+      PaUtil_FlushRingBuffer(&amp;aStream-&gt;outFIFO);
+      fprintf(stderr, &quot;=========================&gt;FLUSH tried: %d, numBytes: %ld, bytesWritten: %lu\n\n\n&quot;, tried, numBytes, bytesWritten);
+      tried = 0;
+#ifdef WANT_SPEEX
+      speex_echo_state_reset(aStream-&gt;echo_state);
+#endif// WANT_SPEEX
+    }
+    if (tried) {
+      fprintf(stderr, &quot;============&gt;FLUSHINO tried: %d, numBytes: %ld, bytesWritten: %lu\n\n\n&quot;, tried, numBytes, bytesWritten);
+      //usleep(1000 * 2 * tried);
+      //usleep( (1000*tried &gt; 4000) ? 4000 : 1000*tried);
+      usleep(2000);
+    }
+    tried++;
+  }
+  return numFrames;
+}
+
+/************************************************************
+ * Read data from ring buffer.
+ */
+long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
+{
+  long bytesRead;
+  char *p = (char *) data;
+  long numBytes = aStream-&gt;bytesPerFrame * numFrames;
+  int tried = 0;
+  long avail;
+
+  avail = PaUtil_GetRingBufferReadAvailable(&amp;aStream-&gt;inFIFO);
+
+  if (avail &lt; numBytes) {
+    //fprintf(stderr, &quot;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; avail: %ld, numBytes: %ld\n\n&quot;, avail, numBytes);
+    usleep(5000);
+    return 0;
+  }
+#if 1
+  if (avail &gt;= numBytes * 7) {
+    PaUtil_FlushRingBuffer(&amp;aStream-&gt;inFIFO);
+    fprintf(stderr, &quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; avail: %ld, numBytes*7: %ld\n\n&quot;, avail,
+            numBytes * 7);
+    return 0;
+  }
+#endif
+
+  while (numBytes &gt; 0) {
+    bytesRead = PaUtil_ReadRingBuffer(&amp;aStream-&gt;inFIFO, p, numBytes);
+    numBytes -= bytesRead;
+    if (numBytes &gt; 0 &amp;&amp; tried == 3) {
+      PaUtil_FlushRingBuffer(&amp;aStream-&gt;inFIFO);
+      fprintf(stderr, &quot;=========================&gt;FLUSH2\n\n\n&quot;);
+      usleep(2000);
+      tried = 0;
+      return 0;
+    }
+    if (tried) {
+      fprintf(stderr,
+              &quot;============&gt;FLUSHINO 2 tried: %d, numBytes: %ld, bytesRead: %lu\n\n\n&quot;,
+              tried, numBytes, bytesRead);
+      usleep(2000);
+    }
+    tried++;
+  }
+  return numFrames;
+}
+
+/************************************************************
+ * Return the number of frames that could be written to the stream without
+ * having to wait.
+ */
+long GetAudioStreamWriteable(PABLIO_Stream * aStream)
+{
+  int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&amp;aStream-&gt;outFIFO);
+  return bytesEmpty / aStream-&gt;bytesPerFrame;
+}
+
+/************************************************************
+ * Return the number of frames that are available to be read from the
+ * stream without having to wait.
+ */
+long GetAudioStreamReadable(PABLIO_Stream * aStream)
+{
+  int bytesFull = PaUtil_GetRingBufferReadAvailable(&amp;aStream-&gt;inFIFO);
+  return bytesFull / aStream-&gt;bytesPerFrame;
+}
+
+/***********************************************************/
+static unsigned long RoundUpToNextPowerOf2(unsigned long n)
+{
+  long numBits = 0;
+  if (((n - 1) &amp; n) == 0)
+    return n;
+  while (n &gt; 0) {
+    n = n &gt;&gt; 1;
+    numBits++;
+  }
+  return (1 &lt;&lt; numBits);
+}
+
+/************************************************************
+ * Opens a PortAudio stream with default characteristics.
+ * Allocates PABLIO_Stream structure.
+ *
+ */
+PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
+                        const PaStreamParameters * inputParameters,
+                        const PaStreamParameters * outputParameters, double sampleRate,
+                        PaStreamFlags streamFlags, long samples_per_frame,
+                        int audioreadpipe, int *speexecho,
+                        int *speexpreprocess, void *owner)
+{
+  long bytesPerSample = 2;
+  PaError err;
+  PABLIO_Stream *aStream;
+  long numFrames;
+  //long numBytes;
+  int channels = 1;
+  short tmp;
+  //float level;
+  int ciapa;
+
+  /* Allocate PABLIO_Stream structure for caller. */
+  aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
+  if (aStream == NULL)
+    return paInsufficientMemory;
+  memset(aStream, 0, sizeof(PABLIO_Stream));
+
+  /* Initialize PortAudio  */
+  err = Pa_Initialize();
+  if (err != paNoError)
+    goto error;
+
+  if (inputParameters) {
+    channels = inputParameters-&gt;channelCount;
+  } else if (outputParameters) {
+    channels = outputParameters-&gt;channelCount;
+  }
+
+  numFrames = RoundUpToNextPowerOf2(samples_per_frame * 5);
+  aStream-&gt;bytesPerFrame = bytesPerSample;
+
+  /* Initialize Ring Buffers */
+
+  if (inputParameters) {
+    err = PABLIO_InitFIFO(&amp;aStream-&gt;inFIFO, numFrames, aStream-&gt;bytesPerFrame);
+    if (err != paNoError)
+      goto error;
+  }
+
+  if (outputParameters) {
+    err = PABLIO_InitFIFO(&amp;aStream-&gt;outFIFO, numFrames, aStream-&gt;bytesPerFrame);
+    if (err != paNoError)
+      goto error;
+  }
+
+  /* Make Write FIFO appear full initially. */
+  //numBytes = PaUtil_GetRingBufferWriteAvailable(&amp;aStream-&gt;outFIFO);
+  //PaUtil_AdvanceRingBufferWriteIndex(&amp;aStream-&gt;outFIFO, numBytes);
+
+#ifdef WANT_SPEEX
+  /* Echo canceller with 200 ms tail length */
+#ifndef GIOVA48
+  aStream-&gt;echo_state = speex_echo_state_init(160, 1024);
+  ciapa = 8000;
+#else// GIOVA48
+  aStream-&gt;echo_state = speex_echo_state_init(960, 1024);
+  ciapa = 48000;
+#endif // GIOVA48
+  speex_echo_ctl(aStream-&gt;echo_state, SPEEX_ECHO_SET_SAMPLING_RATE, &amp;ciapa);
+
+  /* Setup preprocessor and associate with echo canceller for residual echo suppression */
+#ifndef GIOVA48
+  aStream-&gt;preprocess = speex_preprocess_state_init(160, 8000);
+#else// GIOVA48
+  aStream-&gt;preprocess = speex_preprocess_state_init(960, 48000);
+#endif // GIOVA48
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_ECHO_STATE,
+                       aStream-&gt;echo_state);
+
+  /* Setup preprocessor various other goodies */
+  tmp = 0;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_AGC, &amp;tmp);
+  //level=8000.1; 
+  //speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_AGC_LEVEL, &amp;level);
+
+  // Let's turn off all of the 'denoisers' (eg denoise and dereverb, and vad too) because they start automatic gain on mic input on cm108 usb, also if it (the agc on usb) disbled through mixer
+  tmp = 0;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_DENOISE, &amp;tmp);
+  tmp = 0;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_DEREVERB, &amp;tmp);
+  tmp = 0;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_SET_VAD, &amp;tmp);
+
+#if 0
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC, &amp;tmp);
+  fprintf(stderr, &quot;AGC is: %d\n&quot;, tmp);
+  level = 1.0;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC_LEVEL, &amp;level);
+  fprintf(stderr, &quot;AGC_LEVEL is: %f\n&quot;, level);
+  //tmp=1;
+  //speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC_TARGET, &amp;tmp);
+  //fprintf( stderr, &quot;AGC_TARGET is: %d\n&quot;, tmp );
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_DENOISE, &amp;tmp);
+  fprintf(stderr, &quot;DENOISE is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_DEREVERB, &amp;tmp);
+  fprintf(stderr, &quot;DEREVERB is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_VAD, &amp;tmp);
+  fprintf(stderr, &quot;VAD is: %d\n&quot;, tmp);
+
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_NOISE_SUPPRESS, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_NOISE_SUPPRESS is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_ECHO_SUPPRESS, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_ECHO_SUPPRESS is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE,
+                       &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC_MAX_GAIN, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_AGC_MAX_GAIN is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC_INCREMENT, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_AGC_INCREMENT is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_AGC_DECREMENT, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_AGC_DECREMENT is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_PROB_START, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_PROB_START is: %d\n&quot;, tmp);
+  tmp = 1;
+  speex_preprocess_ctl(aStream-&gt;preprocess, SPEEX_PREPROCESS_GET_PROB_CONTINUE, &amp;tmp);
+  fprintf(stderr, &quot;SPEEX_PREPROCESS_GET_PROB_CONTINUE is: %d\n&quot;, tmp);
+#endif //0
+
+  sleep(1);
+#endif // WANT_SPEEX
+
+  aStream-&gt;audioreadpipe = audioreadpipe;
+  aStream-&gt;speexecho = speexecho;
+  aStream-&gt;speexpreprocess = speexpreprocess;
+  aStream-&gt;owner = owner;
+
+  /* Open a PortAudio stream that we will use to communicate with the underlying
+   * audio drivers. */
+  err =
+    Pa_OpenStream(&amp;aStream-&gt;stream, inputParameters, outputParameters, sampleRate,
+                  samples_per_frame, streamFlags, blockingIOCallback, aStream);
+
+  if (err != paNoError)
+    goto error;
+
+  err = Pa_StartStream(aStream-&gt;stream);
+
+  if (err != paNoError)
+    goto error;
+  *rwblPtr = aStream;
+  return paNoError;
+
+error:
+  CloseAudioStream(aStream);
+  *rwblPtr = NULL;
+  return err;
+}
+
+/************************************************************/
+PaError CloseAudioStream(PABLIO_Stream * aStream)
+{
+  PaError err;
+  int bytesEmpty;
+  int byteSize = aStream-&gt;outFIFO.bufferSize;
+
+  /* If we are writing data, make sure we play everything written. */
+  if (byteSize &gt; 0) {
+    bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&amp;aStream-&gt;outFIFO);
+    while (bytesEmpty &lt; byteSize) {
+      Pa_Sleep(10);
+      bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&amp;aStream-&gt;outFIFO);
+    }
+  }
+
+  err = Pa_StopStream(aStream-&gt;stream);
+  if (err != paNoError)
+    goto error;
+  err = Pa_CloseStream(aStream-&gt;stream);
+  if (err != paNoError)
+    goto error;
+  Pa_Terminate();
+
+error:
+  PABLIO_TermFIFO(&amp;aStream-&gt;inFIFO);
+  PABLIO_TermFIFO(&amp;aStream-&gt;outFIFO);
+  free(aStream);
+  return err;
+}
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_gsmopenportaudio_gsmlib_cplusplus_noalsamod_gsmopenpablioh"></a>
<div class="addfile"><h4>Added: freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.h (0 => 16259)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.h                                (rev 0)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/portaudio_gsmlib_cplusplus_noalsa/mod_gsmopen/pablio.h        2010-01-12 15:03:06 UTC (rev 16259)
</span><span class="lines">@@ -0,0 +1,142 @@
</span><ins>+#define WANT_SPEEX
+#ifndef _PABLIO_H
+#define _PABLIO_H
+
+#ifdef __cplusplus
+extern &quot;C&quot; {
+#endif                          /* __cplusplus */
+
+/*
+ * $Id: pablio.h 1083 2006-08-23 07:30:49Z rossb $
+ * PABLIO.h
+ * Portable Audio Blocking read/write utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com/portaudio/
+ *
+ * Include file for PABLIO, the Portable Audio Blocking I/O Library.
+ * PABLIO is built on top of PortAudio, the Portable Audio Library.
+ * For more information see: http://www.portaudio.com
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the &quot;Software&quot;), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * The text above constitutes the entire PortAudio license; however, 
+ * the PortAudio community also makes the following non-binding requests:
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version. It is also 
+ * requested that these non-binding requests be included along with the 
+ * license above.
+ */
+
+#undef WANT_OSLEC
+
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;math.h&gt;
+#include &lt;unistd.h&gt;
+#include &lt;string.h&gt;
+#include &quot;pa_ringbuffer.h&quot;
+#include &quot;portaudio.h&quot;
+#ifdef WANT_SPEEX
+#include &quot;speex/speex_preprocess.h&quot;
+#include &quot;speex/speex_echo.h&quot;
+#endif                          /* WANT_SPEEX */
+#ifdef WANT_OSLEC
+#include &quot;spandsp/echo.h&quot;
+#endif                          /* WANT_OSLEC */
+
+#include &lt;string.h&gt;
+
+  typedef struct {
+    PaUtilRingBuffer inFIFO;
+    PaUtilRingBuffer outFIFO;
+    PaStream *stream;
+    int bytesPerFrame;
+#ifdef WANT_SPEEX
+    SpeexPreprocessState *preprocess;
+    SpeexEchoState *echo_state;
+#endif                          /* WANT_SPEEX */
+#ifdef WANT_OSLEC
+    echo_can_state_t *ec;
+#endif                          /* WANT_OSLEC */
+    int audioreadpipe;
+    int *speexecho;
+    int *speexpreprocess;
+    void *owner;
+  } PABLIO_Stream;
+
+/* Values for flags for OpenAudioStream(). */
+#define PABLIO_READ     (1&lt;&lt;0)
+#define PABLIO_WRITE    (1&lt;&lt;1)
+#define PABLIO_READ_WRITE    (PABLIO_READ|PABLIO_WRITE)
+#define PABLIO_MONO     (1&lt;&lt;2)
+#define PABLIO_STEREO   (1&lt;&lt;3)
+
+/************************************************************
+ * Write data to ring buffer.
+ * Will not return until all the data has been written.
+ */
+  //long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
+  long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
+
+/************************************************************
+ * Read data from ring buffer.
+ * Will not return until all the data has been read.
+ */
+  //long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
+  long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
+
+/************************************************************
+ * Return the number of frames that could be written to the stream without
+ * having to wait.
+ */
+  long GetAudioStreamWriteable(PABLIO_Stream * aStream);
+
+/************************************************************
+ * Return the number of frames that are available to be read from the
+ * stream without having to wait.
+ */
+  long GetAudioStreamReadable(PABLIO_Stream * aStream);
+
+/************************************************************
+ * Opens a PortAudio stream with default characteristics.
+ * Allocates PABLIO_Stream structure.
+ *
+ * flags parameter can be an ORed combination of:
+ *    PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
+ *    and either PABLIO_MONO or PABLIO_STEREO
+ */
+  PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
+                          const PaStreamParameters * inputParameters,
+                          const PaStreamParameters * outputParameters, double sampleRate,
+                          PaStreamCallbackFlags statusFlags, long samples_per_frame,
+                          int audioreadpipe, int *speexecho,
+                          int *speexpreprocess, void *owner);
+
+  PaError CloseAudioStream(PABLIO_Stream * aStream);
+
+#ifdef __cplusplus
+}
+#endif                          /* __cplusplus */
+#endif                          /* _PABLIO_H */
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>