<!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][14699] </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=14699">14699</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-08-31 12:06:51 -0500 (Mon, 31 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>celliax: audio sync, alsa init when needed, volume of samples</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliaxh">freeswitch/branches/gmaruzz/mod_celliax/celliax.h</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc">freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxmod_celliaxc">freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14698 => 14699)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-31 14:33:41 UTC (rev 14698)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-31 17:06:51 UTC (rev 14699)
</span><span class="lines">@@ -552,3 +552,7 @@
</span><span class="cx"> int alsa_read(private_t * tech_pvt, short *data, int datalen);
</span><span class="cx"> 
</span><span class="cx"> #endif /* CELLIAX_ALSA */
</span><ins>+
+
+void celliax_store_boost(char *s, double *boost);
+int celliax_sound_boost(void * data, int samples_num, double boost);
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14698 => 14699)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-31 14:33:41 UTC (rev 14698)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-31 17:06:51 UTC (rev 14699)
</span><span class="lines">@@ -3707,6 +3707,7 @@
</span><span class="cx">                         ERRORA(&quot;device [%s], snd_pcm_close failed with error '%s'\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;alsapname, snd_strerror(err));
</span><span class="cx">                         return -1;
</span><span class="cx">                 }
</span><ins>+tech_pvt-&gt;alsap = NULL;
</ins><span class="cx">         }
</span><span class="cx">         if (tech_pvt-&gt;alsac) {
</span><span class="cx">                 err = snd_pcm_drop(tech_pvt-&gt;alsac);
</span><span class="lines">@@ -3719,6 +3720,7 @@
</span><span class="cx">                         ERRORA(&quot;device [%s], snd_pcm_close failed with error '%s'\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;alsacname, snd_strerror(err));
</span><span class="cx">                         return -1;
</span><span class="cx">                 }
</span><ins>+tech_pvt-&gt;alsac = NULL;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return 0;
</span><span class="lines">@@ -5067,4 +5069,58 @@
</span><span class="cx">     return RESULT_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/************************************************/
</ins><span class="cx"> 
</span><ins>+/* LUIGI RIZZO's magic */
+/* boost support. BOOST_SCALE * 10 ^(BOOST_MAX/20) must
+ * be representable in 16 bits to avoid overflows.
+ */
+#define BOOST_SCALE     (1&lt;&lt;9)
+#define BOOST_MAX       40          /* slightly less than 7 bits */
+
+/*
+ * store the boost factor
+ */
+void celliax_store_boost(char *s, double *boost)
+{
+  private_t * tech_pvt  = NULL;
+
+  if (sscanf(s, &quot;%lf&quot;, boost) != 1) {
+    ERRORA(&quot;invalid boost &lt;%s&gt;\n&quot;, SKYPIAX_P_LOG, s);
+    return;
+  }
+  if (*boost &lt; -BOOST_MAX) {
+    WARNINGA(&quot;boost %s too small, using %d\n&quot;, SKYPIAX_P_LOG, s, -BOOST_MAX);
+    *boost = -BOOST_MAX;
+  } else if (*boost &gt; BOOST_MAX) {
+    WARNINGA(&quot;boost %s too large, using %d\n&quot;, SKYPIAX_P_LOG, s, BOOST_MAX);
+    *boost = BOOST_MAX;
+  }
+  *boost = exp(log(10) * *boost / 20) * BOOST_SCALE;
+  if (option_debug &gt; 1)
+    DEBUGA_SKYPE(&quot;setting boost %s to %f\n&quot;, SKYPIAX_P_LOG, s, *boost);
+}
+
+
+int celliax_sound_boost(void * data, int samples_num, double boost)
+{
+/* LUIGI RIZZO's magic */
+  if (boost != 0) {             /* scale and clip values */
+    int i, x;
+
+    int16_t *ptr = (int16_t *) data;
+
+    for (i = 0; i &lt; samples_num; i++) {
+      x = (ptr[i] * boost) / BOOST_SCALE;
+      if (x &gt; 32767) {
+        x = 32767;
+      } else if (x &lt; -32768) {
+        x = -32768;
+      }
+      ptr[i] = x;
+    }
+  }
+  return 0;
+}
+
+
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_celliaxmod_celliaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14698 => 14699)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c        2009-08-31 14:33:41 UTC (rev 14698)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c        2009-08-31 17:06:51 UTC (rev 14699)
</span><span class="lines">@@ -258,6 +258,11 @@
</span><span class="cx">         //teletone_dtmf_detect_init(&amp;tech_pvt-&gt;dtmf_detect, tech_pvt-&gt;read_codec.implementation-&gt;actual_samples_per_second);
</span><span class="cx">         teletone_dtmf_detect_init(&amp;tech_pvt-&gt;dtmf_detect, 8000);
</span><span class="cx"> 
</span><ins>+        if(alsa_init(tech_pvt)){
+                ERRORA(&quot;alsa_init failed\n&quot;, SKYPIAX_P_LOG);
+                return SWITCH_STATUS_FALSE;
+
+        }
</ins><span class="cx">         if (switch_core_timer_init(&amp;tech_pvt-&gt;timer_read, &quot;soft&quot;, 20, tech_pvt-&gt;read_codec.implementation-&gt;samples_per_packet, celliax_module_pool) !=
</span><span class="cx">                 SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                 ERRORA(&quot;setup timer failed\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -483,6 +488,7 @@
</span><span class="cx">                 switch_core_timer_destroy(&amp;tech_pvt-&gt;timer_read);
</span><span class="cx">                 switch_core_timer_destroy(&amp;tech_pvt-&gt;timer_write);
</span><span class="cx"> 
</span><ins>+                alsa_shutdown(tech_pvt);
</ins><span class="cx"> 
</span><span class="cx">                 *tech_pvt-&gt;session_uuid_str = '\0';
</span><span class="cx">                 tech_pvt-&gt;interface_state = SKYPIAX_STATE_IDLE;
</span><span class="lines">@@ -682,11 +688,18 @@
</span><span class="cx"> 
</span><span class="cx">         //if ((samples = snd_pcm_readi(tech_pvt-&gt;alsac, tech_pvt-&gt;read_frame.data, tech_pvt-&gt;read_codec.implementation-&gt;samples_per_packet)) &gt; 0) 
</span><span class="cx">         if ((samples = alsa_read(tech_pvt, tech_pvt-&gt;read_frame.data, tech_pvt-&gt;read_codec.implementation-&gt;samples_per_packet)) &gt; 0) {
</span><ins>+
</ins><span class="cx">                 tech_pvt-&gt;read_frame.datalen = samples * 2;
</span><span class="cx">                 tech_pvt-&gt;read_frame.samples = samples;
</span><span class="cx"> 
</span><span class="cx">                 //switch_core_timer_check(&amp;tech_pvt-&gt;timer, SWITCH_TRUE);
</span><span class="cx">                 tech_pvt-&gt;read_frame.timestamp = tech_pvt-&gt;timer_read.samplecount;
</span><ins>+
+celliax_sound_boost(tech_pvt-&gt;read_frame.data, tech_pvt-&gt;read_frame.samples, tech_pvt-&gt;capture_boost);
+
+
+
+
</ins><span class="cx">                 *frame = &amp;tech_pvt-&gt;read_frame;
</span><span class="cx"> 
</span><span class="cx">                 //status = SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -813,11 +826,12 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">                 switch_core_timer_next(&amp;tech_pvt-&gt;timer_write);
</span><del>-        sent = frame-&gt;datalen;
</del><ins>+        //sent = frame-&gt;datalen;
</ins><span class="cx"> 
</span><span class="cx">         //ERRORA(&quot;PLAY \n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         //snd_pcm_writei(tech_pvt-&gt;alsap, (short *) frame-&gt;data, (int) (frame-&gt;datalen / 2));
</span><span class="cx"> 
</span><ins>+celliax_sound_boost(frame-&gt;data, frame-&gt;samples, tech_pvt-&gt;playback_boost);
</ins><span class="cx">         sent = alsa_write(tech_pvt, frame-&gt;data, (int) (frame-&gt;datalen));
</span><span class="cx"> //DEBUGA_SKYPE(&quot;sent=%d \n&quot;, SKYPIAX_P_LOG, sent);
</span><span class="cx"> 
</span><span class="lines">@@ -855,6 +869,8 @@
</span><span class="cx"> {
</span><span class="cx">         switch_channel_t *channel;
</span><span class="cx">         private_t *tech_pvt;
</span><ins>+int samples;
+short tmp_buffer[1280];
</ins><span class="cx"> 
</span><span class="cx">         channel = switch_core_session_get_channel(session);
</span><span class="cx">         switch_assert(channel != NULL);
</span><span class="lines">@@ -869,6 +885,18 @@
</span><span class="cx">                         channel_answer_channel(session);
</span><span class="cx">                 }
</span><span class="cx">                 break;
</span><ins>+case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
+
+                WARNINGA(&quot;%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
+        while ((samples = alsa_read(tech_pvt, tmp_buffer, tech_pvt-&gt;read_codec.implementation-&gt;samples_per_packet * 4)) &gt; 160) {
+                WARNINGA(&quot;read %d samples\n&quot;, SKYPIAX_P_LOG, samples);
+}
+                switch_core_timer_sync(&amp;tech_pvt-&gt;timer_read);
+                switch_core_timer_sync(&amp;tech_pvt-&gt;timer_write);
+
+break;
+
+
</ins><span class="cx">         default:
</span><span class="cx">                 {
</span><span class="cx">                         DEBUGA_SKYPE(&quot;MSG_ID=%d\n&quot;, SKYPIAX_P_LOG, msg-&gt;message_id);
</span><span class="lines">@@ -1455,7 +1483,11 @@
</span><span class="cx">                                 globals.SKYPIAX_INTERFACES[interface_id].alsa_capture_is_mono = 1;
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+                                globals.SKYPIAX_INTERFACES[interface_id].capture_boost = 0;
+                                globals.SKYPIAX_INTERFACES[interface_id].playback_boost = 0;
</ins><span class="cx"> 
</span><ins>+celliax_store_boost(&quot;5&quot;, &amp;globals.SKYPIAX_INTERFACES[interface_id].capture_boost);
+celliax_store_boost(&quot;5&quot;, &amp;globals.SKYPIAX_INTERFACES[interface_id].playback_boost);
</ins><span class="cx"> /*********************/
</span><span class="cx">                                 DEBUGA_SKYPE
</span><span class="cx">                                         (&quot;interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n&quot;,
</span><span class="lines">@@ -1522,6 +1554,7 @@
</span><span class="cx"> 
</span><span class="cx">                                 switch_sleep(100000);
</span><span class="cx"> 
</span><ins>+#ifdef NOTDEF
</ins><span class="cx">                                 res = alsa_init(&amp;globals.SKYPIAX_INTERFACES[interface_id]);
</span><span class="cx">                                 if (res == -1) {
</span><span class="cx">                                         ERRORA(&quot;Failed initializing sound device\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -1531,7 +1564,6 @@
</span><span class="cx">                                         //return NULL;
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-#ifdef NOTDEF
</del><span class="cx">                                 switch_threadattr_create(&amp;celliax_signaling_thread_attr, celliax_module_pool);
</span><span class="cx">                                 switch_threadattr_stacksize_set(celliax_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
</span><span class="cx">                                 switch_thread_create(&amp;globals.SKYPIAX_INTERFACES[interface_id].celliax_signaling_thread, celliax_signaling_thread_attr,
</span><span class="lines">@@ -1666,7 +1698,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                alsa_shutdown(&amp;globals.SKYPIAX_INTERFACES[interface_id]);
</del><ins>+                //alsa_shutdown(&amp;globals.SKYPIAX_INTERFACES[interface_id]);
</ins><span class="cx">                         if (globals.SKYPIAX_INTERFACES[interface_id].celliax_signaling_thread) {
</span><span class="cx"> #ifdef WIN32
</span><span class="cx">                                 switch_file_write(tech_pvt-&gt;SkypiaxHandles.fdesc[1], &quot;sciutati&quot;, &amp;howmany);        // let's the controldev_thread die
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>