<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hawk Software &#187; Programming</title>
	<atom:link href="http://hawksoft.com/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://hawksoft.com</link>
	<description>Programming, web design, and more</description>
	<lastBuildDate>Wed, 25 Aug 2010 19:46:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ask Phil &#8211; Tweaking the TCP time-out</title>
		<link>http://hawksoft.com/2010/ask-phil-tweaking-the-tcp-time-out-491.shtml</link>
		<comments>http://hawksoft.com/2010/ask-phil-tweaking-the-tcp-time-out-491.shtml#comments</comments>
		<pubDate>Tue, 24 Aug 2010 02:12:50 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=491</guid>
		<description><![CDATA[Kama asked:
I have a question related to the tweaking of TCP timeouts and retries. Basically I have an application that connects to a remote server to perform various operations. If the server dies however, it will perform operations on a local database then sync up with the server later. In linux, if the remote server [...]]]></description>
			<content:encoded><![CDATA[<p>Kama asked:</p>
<p><em><strong>I have a question related to the tweaking of TCP timeouts and retries. Basically I have an application that connects to a remote server to perform various operations. If the server dies however, it will perform operations on a local database then sync up with the server later. In linux, if the remote server is offline, the application tries to reach the server for approximately 2 minutes before it gives up and uses the local database. This of course makes the application seem like it has hung.</strong></em></p>
<p><em><strong>I&#8217;ve done some research into tweaking tcp settings. I&#8217;ve found various settings that I can tweak in the proc systems using sysctl. I&#8217;m not sure which ones will work for this task. I&#8217;m currently playing with:</strong></em></p>
<p><em><strong>tcp_orphan_retries<br />
tcp_retries1<br />
tcp_retries2</strong></em></p>
<p><em><strong>Does anyone know if I&#8217;m on the right track? Also I know these flags alter the settings based on the retransmission timeout (RTO). Is there anyway of tweaking the RTO? Or will tweaking one of the above flags suffice?</strong></em></p>
<p>My reply:<span id="more-491"></span></p>
<p><em><strong>I think you are doing it the hard way&#8230;</strong></em></p>
<p><em><strong>The most common way to get around long connect times is to set the socket to non-blocking, call connect(), then call select() on the socket with a reasonable time-out, checking for errors and writability. If the select times out or shows a socket error then you know the connect() has not completed and you can close the socket. If select() returns that the socket is writable then the connect() was successful.</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/ask-phil-tweaking-the-tcp-time-out-491.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I use the GPL/LGPL, but don&#8217;t buy into the full GNU philosophy</title>
		<link>http://hawksoft.com/2010/why-i-use-the-gpllgpl-but-dont-buy-into-the-full-gnu-philosophy-471.shtml</link>
		<comments>http://hawksoft.com/2010/why-i-use-the-gpllgpl-but-dont-buy-into-the-full-gnu-philosophy-471.shtml#comments</comments>
		<pubDate>Thu, 19 Aug 2010 01:49:11 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=471</guid>
		<description><![CDATA[I use the GPL/LGPL (GPL for short) for current projects, and new projects will use the GPL Version 3.  But, I am no big fan of Richard Stallman, so why use the GPL at all, when there are so many other free and open source licenses?  Why do I use a free license at all?  [...]]]></description>
			<content:encoded><![CDATA[<p>I use the GPL/LGPL (GPL for short) for current projects, and new projects will use the GPL Version 3.  But, I am no big fan of Richard Stallman, so why use the GPL at all, when there are so many other free and open source licenses?  Why do I use a free license at all?  I will answer this second question first since it has a lot to do about how I came to be a programmer.<span id="more-471"></span></p>
<p>I first began programming back in 1978 using BASIC.  There were a few books available with sample programs, and I learned BASIC and assembler.  But I was also lucky  because a fellow calculator toting math geek (my TI-30 was kept in a  denim-look case which attached to my belt; very hip for 1978) had some sort of access to source code from a university.  The BIG software project that distracted us for months was a Star Trek game, which we modified weekly.  My friend told me about all the free software available at colleges and universities; some of it in cool languages like Pascal and C.</p>
<p>After taking some college courses, which included Pascal and Image (a database for HP minicomputers), I hardly programed at all for 10 years until I got an AT clone running DOS and Windows 3.1.  I briefly programmed with Turbo Pascal, but then decided I wanted to jump into C headfirst.  But how?  I did not have the time or funds to take formal courses, so I turned to free/open source code which was available on my local BBS (Bulletin Board System).  It was great!  With the free DJGPP C compiler for DOS I was able to learn by doing.  I also purchased a special introductory version of Visual C++ that just built Win16 programs, but I never used it much.</p>
<p>I was able to quickly learn about inlined assembly, VESA frame-buffer graphics, OpenGL, IPX and TCP/IP networking, and finally speech compression using free and open source code software.   So you might say I am making software available free as payback.  I like to think I am providing stepping stones for others to go further than I have, and just maybe someday they will provide stepping stones I can use to go even further myself.</p>
<p>Now to the first question: Why do I use the GPL?  The main reason is that it is extensively used, and it has been tested in court.  While I hope to never need to enforce a free software license in court, the fact that the GPL has been found to be enforceable adds a little peace of mind.</p>
<p>Another, somewhat selfish, reason is that the GPL is considered to be non-friendly to commercial software.  While this is based more on ignorance than on truth, the fact is that is the way it is seen.  But this allows me to periodically dual-license some of my code which pays to keep this site up and allows me to purchase software and hardware to support current and future projects.</p>
<p>In conclusion, while I promote and contribute to free and open source code projects, I still believe there is a place for commercial software.  And right now the GPL is the best license I can use to pay back to the free/open source code community, yet still make a little money.</p>
<p>Phil Frisbie, Jr.</p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/why-i-use-the-gpllgpl-but-dont-buy-into-the-full-gnu-philosophy-471.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ask Phil &#8211; Losing UDP packets</title>
		<link>http://hawksoft.com/2010/ask-phil-losing-udp-packets-485.shtml</link>
		<comments>http://hawksoft.com/2010/ask-phil-losing-udp-packets-485.shtml#comments</comments>
		<pubDate>Fri, 06 Aug 2010 01:14:07 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=485</guid>
		<description><![CDATA[Maxime once asked:
My C program needs to send UDP packets in burst. I have the following code:
send_data()
{
err = sendto(sock, &#38;msg1, len1, &#38;add, lenadd);
err = sendto(sock, &#38;msg2, len2, &#38;add, lenadd);
err = sendto(sock, &#38;msg3, len3, &#38;add, lenadd);
err = sendto(sock, &#38;msg4, len4, &#38;add, lenadd);
err = sendto(sock, &#38;msg5, len5, &#38;add, lenadd);
}
I do not get any error.
When I look on [...]]]></description>
			<content:encoded><![CDATA[<p>Maxime once asked:</p>
<p><em><strong>My C program needs to send UDP packets in burst. I have the following code:</strong></em></p>
<p><em><strong>send_data()</strong></em><br />
<em><strong>{<br />
err = sendto(sock, &amp;msg1, len1, &amp;add, lenadd);<br />
err = sendto(sock, &amp;msg2, len2, &amp;add, lenadd);<br />
err = sendto(sock, &amp;msg3, len3, &amp;add, lenadd);<br />
err = sendto(sock, &amp;msg4, len4, &amp;add, lenadd);<br />
err = sendto(sock, &amp;msg5, len5, &amp;add, lenadd);<br />
}</strong></em></p>
<p><em><strong>I do not get any error.</strong></em></p>
<p><em><strong>When I look on the network with a sniffer, sometimes, I [see] packets. but the missing packets are never put on the network.</strong></em></p>
<p><em><strong>How can I lose packets if I have a private network with only two nodes?</strong></em></p>
<p><em><strong>I use setsockopt(sock,SOL_SOCKET, SO_SNDBUF, &amp;maxsize, sizeof(int)); function to be sure I have enough buffer memory, but that not seams to help.</strong></em></p>
<p><em><strong>I have the same result with Windows or Linux.</strong></em></p>
<p><em><strong>Does someone have an idea?<span id="more-485"></span></strong></em></p>
<p>My obnoxious reply [I guess I used to be grumpier than I am now!]:</p>
<p><em><strong>Repeat after me: UDP is not reliable. UDP is not reliable&#8230;&#8230;</strong></em></p>
<p><em><strong>REALLY! The TCP/IP stack can drop UDP datagrams at ANY time, even if there is buffer space, even on a loopback address! The sooner you understand and acknowledge this the less frustration you will experience.</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/ask-phil-losing-udp-packets-485.shtml/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ask Phil &#8211; Can an LGPL library be used for commercial software?</title>
		<link>http://hawksoft.com/2010/ask-phil-can-an-lgpl-library-be-used-for-commercial-software-467.shtml</link>
		<comments>http://hawksoft.com/2010/ask-phil-can-an-lgpl-library-be-used-for-commercial-software-467.shtml#comments</comments>
		<pubDate>Thu, 08 Jul 2010 01:09:38 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=467</guid>
		<description><![CDATA[Many times I have been asked:
I would like to use your library HawkNL (or HawkVoiceDI) in a commercial application.  Does the LGPL allow me to do this? Or can I license your library for a commercial application?
My reply:
First, please read he full terms of the LGPL Version 2.  Basically, if you use the library as [...]]]></description>
			<content:encoded><![CDATA[<p>Many times I have been asked:</p>
<p><strong><em>I would like to use your library HawkNL (or HawkVoiceDI) in a commercial application.  Does the LGPL allow me to do this? Or can I license your library for a commercial application?</em></strong></p>
<p>My reply:</p>
<p><strong><em>First, please read he full terms of the<a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html"> LGPL Version 2</a>.  Basically, if you use the library as a Windows DLL or *nix loadable module or shared object, then you only need to provide source for the library and any modifications you added.  The end user MUST be able to modify the library source and recompile the library if they choose.  A good example of this was Sony&#8217;s use of HawkVoiceDI in the game <a href="http://planetside.station.sony.com/">Planetside</a>.  Sony used HawkVoiceDI as a DLL and <a href="http://planetside.station.sony.com/howto/manual_detail.vm?handle=6.14">provided a link to the source code</a> in the online manual.</em></strong></p>
<p><strong><em>And yes, these libraries, and some of my other code, is available under a commercial license.  Hawk Software is a part-time job for me, so licensing helps keep this website up!</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/ask-phil-can-an-lgpl-library-be-used-for-commercial-software-467.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real posts 64, spam 1860, and a fixed point conversion update</title>
		<link>http://hawksoft.com/2010/real-posts-64-spam-1860-and-a-fixed-point-conversion-update-460.shtml</link>
		<comments>http://hawksoft.com/2010/real-posts-64-spam-1860-and-a-fixed-point-conversion-update-460.shtml#comments</comments>
		<pubDate>Thu, 24 Jun 2010 02:45:44 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Speech/Voice Compression]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=460</guid>
		<description><![CDATA[Whew!  Just got done reviewing posts to weed out the real ones from the spam.  The amount of spam has greatly increased over the last week, and out of 70 posts since yesterday there was ONE real post.  Or, at least, it was not obviously spam!
I know some are waiting for the rest of the [...]]]></description>
			<content:encoded><![CDATA[<p>Whew!  Just got done reviewing posts to weed out the real ones from the spam.  The amount of spam has greatly increased over the last week, and out of 70 posts since yesterday there was ONE real post.  Or, at least, it was not obviously spam!</p>
<p>I know some are waiting for the rest of the floating point to fixed point series, and I am sorry that it is taking a lot more time than I anticipated.  <span id="more-460"></span>I had outlined the entire series and completed the first two parts before I began posting, and I thought that a week between parts would be sufficient to get through it, but I was wrong.  When dealing with code originally converted seven years ago my memory takes extra time to retrieve all the details.  And some intermediate code versions are missing, so I am recreating some intermediate code to properly show the steps.</p>
<p>Also, some steps are so detailed that I will just provide an overview in this series, and will post more detailed explanations in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/real-posts-64-spam-1860-and-a-fixed-point-conversion-update-460.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Floating point to fixed point code conversion – Part 3: Using macros to bridge the conversion process</title>
		<link>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-3-using-macros-to-bridge-the-conversion-process-419.shtml</link>
		<comments>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-3-using-macros-to-bridge-the-conversion-process-419.shtml#comments</comments>
		<pubDate>Sat, 05 Jun 2010 05:40:30 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Speech/Voice Compression]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=419</guid>
		<description><![CDATA[Be sure to read Part 1 for an introduction to fixed point math, and Part 2 for guidelines in preparing your floating point code for conversion to fixed point.
I begin the conversion process by adding these macros to the source files to emulate the fixed point math functions which will be used later:
#define fixed32  [...]]]></description>
			<content:encoded><![CDATA[<p>Be sure to read <a href="http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-1-introduction-366.shtml">Part 1</a> for an introduction to fixed point math, and <a href="http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-2-preparing-your-code-371.shtml">Part 2</a> for guidelines in preparing your floating point code for conversion to fixed point.</p>
<p>I begin the conversion process by adding these macros to the source files to emulate the fixed point math functions which will be used later:</p>
<pre><strong>#define fixed32         float
#define ftofix32(x)     ((float)(x))  /* float value to fixed */
#define itofix32(x)     ((float)(x))  /* integer value to fixed */<span id="more-419"></span>
#define fixtoi32(x)     ((int)((x) &lt; 0.0f ? (x) - 0.5f : (x) + 0.5f))  /* fixed value to integer with rounding */
#define fixtof32(x)     (x)  /* fixed value to float */
#define fixabs32(x)     fabs(x)  /* absolute value */
#define fixmul32(x, y)  ((float)(x) * (float)(y))  /* multiply x and y */
#define fixdiv32(x, y)  ((float)(x) / (float)(y))  /* divide x by y */
#define fixadd32(x, y)  ((float)(x) + (float)(y))  /* use only where you suspect large values will be accumulated */
#define fixsub32(x, y)  ((float)(x) - (float)(y))  /* same caution as add */

</strong></pre>
<p>First go through your code and replace every instance of &#8216;float&#8217; with &#8216;fixed32&#8242;:</p>
<pre><strong>void hp100(fixed32 *speech, long end, struct lpc10_encoder_state *st)
{
    fixed32 z11;
    fixed32 z21;
    fixed32 z12;
    fixed32 z22;
</strong></pre>
<p>Then go through and modify each use of a static float or integer (integers only if they are used in floating point math equations) to use the macros:</p>
<pre><strong>static fixed32 enscl[8] = { ftofix32(.0204f),ftofix32(.0167f),ftofix32(.0145f),ftofix32(.0147f),
ftofix32(.0143f),ftofix32(.0135f),ftofix32(.0125f),ftofix32(.0112f) };

static fixed32 vdcl[10] = { itofix32(600),itofix32(450),itofix32(300),itofix32(200),itofix32(0), itofix32(0),
itofix32(0),itofix32(0),itofix32(0),itofix32(0) };

</strong></pre>
<p>Convert casts to use the macros:</p>
<pre><strong>minamd = fixtoi32(amdf[*minptr]);</strong></pre>
<p>Then convert each fabs, multiply, and divide:</p>
<pre><strong>ivrc[1] = fixdiv32((r[2] - fixmul32(ivrc[0], r[1])), (r[0] - fixmul32(ivrc[0], r[1])));</strong></pre>
<pre><strong> </strong></pre>
<p>Now look carefully through your code and look for other floating point functions used.  Add macros as necessary and convert the code to use them:</p>
<pre><strong>#define fixsqrt32(x)    (float)sqrt(x)
#define fixexp32(x)     (float)exp(x)
#define fixlog32(x)     (float)log(x)
 </strong></pre>
<p>Regularly make sure your floating point code still works while converting it to use the macros.  Use the test framework or reference data you created in part 2.  At this point your code should still be bit-exact.</p>
<p><strong><em>NOTE: It is possible that using these macros will cause some floating calculations to no longer be bit-exact.  It is common for x86 compilers to use 80-bit registers for intermediate results for increased speed, and then round/truncate back to 32 bits just before storing the values.  These macros may reduce the use of the 80-bit registers by causing rounding/truncating more often.  The differences will be insignificant for most calculations, but they can be noticeable in a loop which performs a multiply and accumulate for thousands of values.  It is not really that these macros are reducing the precision of the calculations; it is that they are only allowing it to be at 32-bits and not higher.</em></strong></p>
<p>Now it is time to determine the fixed point precision and perform scaling as needed.  At this point my instructions will become a little fuzzy due to differences in compilers and platforms.  How easy your own conversion is from here on will be determined by how well you really understand the code you are converting and how well you command the <a href="http://en.wikipedia.org/wiki/Force_%28Star_Wars%29">Force</a> <img src='http://hawksoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Remember from Part 1 that our fixed point values are using a 32 bit integer partitioned into bits for the whole number (and sign) and the rest of the bits for the fraction.   I usually begin with 16.16 fixed point (16 bits for each), but it depends on how large your large values are compared with the precision needed for the smallest values.  It is a balancing act.  Sometimes you are lucky and your code is only dealing with large values or very small values, but often different parts of your code are using both.  To see how large your values are first add these two additional defines:</p>
<pre><strong>#define precision       16 /* bits for the fractional part */</strong></pre>
<pre><strong>#define floatlimit      (float)(((1 &lt;&lt; (32 - precision)) / 2) - 1 )</strong></pre>
<pre><strong> </strong></pre>
<p>Then replace your macros with these functions:</p>
<pre><strong>fixed32 fixmul32(fixed32 x, fixed32 y)
{
    fixed32 temp = x * y;

    if(temp &gt; floatlimit)
    {
        return floatlimit;
    }
    else if(temp &lt; -floatlimit)
    {
        return -floatlimit;
    }
    return temp;
}
fixed32 fixdiv32(fixed32 x, fixed32 y)
{
    fixed32 temp = x / y;
    if(temp &gt; floatlimit)
    {
        return floatlimit;
    }
    else if(temp &lt; -floatlimit)
    {
        return -floatlimit;
    }
    return temp;
}
fixed32 fixadd32(fixed32 x, fixed32 y)
{
    fixed32 temp = x + y;
    if(temp &gt; floatlimit)
    {
        return floatlimit;
    }
    else if(temp &lt; -floatlimit)
    {
        return -floatlimit;
    }
    return temp;
}
fixed32 fixsub32(fixed32 x, fixed32 y)
{
    fixed32 temp = x - y;
    if(temp &gt; floatlimit)
    {
        return floatlimit;
    }
    else if(temp &lt; -floatlimit)
    {
        return -floatlimit;
    }
    return temp;
}

</strong></pre>
<p>The code above works for me with Visual Studio; I simply set up breakpoints on all the appropriate return lines to detect overflow.  When the code hits a break I look back through the stack trace to see where the overflow occurred.  You can also change these functions to defines and use asserts or print out the locations of the overflows.</p>
<p>In the new defines we just added I began with 16-bits of precision for the fractional part of the fixed point values.  If you are getting overflows reduce the fractional precision, one bit at a time, and retest until you either eliminate the overflows or fail your test.  If you can back off the fractional precision to eliminate the overflows, and your code still passes your tests, then you are one lucky developer!  But more likely when you reduce the fractional precision enough to eliminate the overflows your code will be broken. <img src='http://hawksoft.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Part 4 will cover scaling and modifying algorithms in preparation for the actual fixed point conversion</p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-3-using-macros-to-bridge-the-conversion-process-419.shtml/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What I&#8217;m Reading</title>
		<link>http://hawksoft.com/2010/what-im-reading-411.shtml</link>
		<comments>http://hawksoft.com/2010/what-im-reading-411.shtml#comments</comments>
		<pubDate>Fri, 28 May 2010 01:55:28 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Speech/Voice Compression]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=411</guid>
		<description><![CDATA[OK, so I needed a filler while I finalize changes to the next installment to the floating-to-fixed point series    But hey, this is all good, if not varied, information.

Associate Mutexes with Data to Prevent Races
Numerical Recipes
The TCP-Friendly Website
Secure Programming.com
rt_lpc : real-time LPC analysis + synthesis + visualization

]]></description>
			<content:encoded><![CDATA[<p>OK, so I needed a filler while I finalize changes to the next installment to the floating-to-fixed point series <img src='http://hawksoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   But hey, this is all good, if not varied, information.</p>
<ul>
<li><a href="http://www.drdobbs.com/224701827;jsessionid=QLIECSEVHZJZHQE1GHPSKH4ATMY32JVN?cid=RSSfeed_DDJ_All">Associate Mutexes with Data to Prevent Races</a><span id="more-411"></span></li>
<li><a href="http://www.nr.com/oldverswitcher.html">Numerical Recipes</a></li>
<li><a href="http://www.icir.org/floyd/tcp_friendly.html">The TCP-Friendly Website</a></li>
<li><a href="http://www.secureprogramming.com/?action=browse&amp;feature=links&amp;filter=software">Secure Programming.com</a></li>
<li><a href="http://soundlab.cs.princeton.edu/software/rt_lpc/">rt_lpc : real-time LPC analysis + synthesis + visualization</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/what-im-reading-411.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ask Phil &#8211; Where are unicode Winsock functions?</title>
		<link>http://hawksoft.com/2010/ask-phil-where-are-unicode-winsock-functions-391.shtml</link>
		<comments>http://hawksoft.com/2010/ask-phil-where-are-unicode-winsock-functions-391.shtml#comments</comments>
		<pubDate>Tue, 11 May 2010 01:50:27 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=391</guid>
		<description><![CDATA[Many people have asked questions similar to this:
When I get into winsock in globalization, I found out winsock.h has a lot of different data structure if _UNICODE turned on. But, there is no function support those data types. such as gethostbyname(&#8230;) only take const char FAR * name. How could I call gethostbyname when _UNICODE [...]]]></description>
			<content:encoded><![CDATA[<p>Many people have asked questions similar to this:</p>
<p><strong><em>When I get into winsock in globalization, I found out winsock.h has a lot of different data structure if _UNICODE turned on. But, there is no function support those data types. such as gethostbyname(&#8230;) only take const char FAR * name. How could I call gethostbyname when _UNICODE turned on in Visual C++?</em></strong></p>
<p>My reply:<span id="more-391"></span></p>
<p><strong><em>You do it like everyone else! You must provide code to convert from unicode to ascii and back into unicode whenever you deal with Winsock functions.</em></strong></p>
<p><strong><em>For example, my free open source code network library HawkNL compiles with or without unicode, so in my function to resolve a host name to an address I do this:</em></strong></p>
<pre><strong>#ifdef _UNICODE
/* convert from wide char string to multibyte char string */
(void)wcstombs(temp, (const NLchar *)name, NL_MAX_STRING_LENGTH);
#else
strncpy(temp, name, NL_MAX_STRING_LENGTH);
#endif
</strong></pre>
<p><strong><em>So if unicode I convert the string, but if not I copy it before I process it further before I call gethostbyname().</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/ask-phil-where-are-unicode-winsock-functions-391.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Floating point to fixed point code conversion – Part 2: Preparing your code</title>
		<link>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-2-preparing-your-code-371.shtml</link>
		<comments>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-2-preparing-your-code-371.shtml#comments</comments>
		<pubDate>Fri, 07 May 2010 02:29:30 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Speech/Voice Compression]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=371</guid>
		<description><![CDATA[See Part 1 for an introduction to fixed point code, and the reasons you may need to use it.
Starting off with clean, fully debugged, fully functional, and stable floating point code is a must.  Fixed point code can be harder to interpret, so you do not want to be modifying the converted code every [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-1-introduction-366.shtml">See Part 1</a> for an introduction to fixed point code, and the reasons you may need to use it.</p>
<p>Starting off with clean, fully debugged, fully functional, and stable floating point code is a must.  Fixed point code can be harder to interpret, so you do not want to be modifying the converted code every time you correct or add a feature to the original code.  It is even better to start off with code that has not been heavily hand-optimized since it will be easier to understand and convert.  Of course, make sure your algorithms are efficient and you are not doing something stupid like scanning through arrays non-sequentially and getting a ton of cache misses <img src='http://hawksoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <span id="more-371"></span></p>
<p>In preparing to convert the LPC-10 codec I reduced the number of .c source code files in the original code from 33 (it used one source file for each major function) down to just 2: one for encoding and one for decoding. I did this so that I could convert the encoder and decoder separately and make testing easier.</p>
<p>Now that you have clean code, you can create reference data and/or a test framework to verify your code&#8217;s correct operation. It is too easy to break your code while making the conversion, so you must be able to test it. In the LPC-10 codec I added code to dump the encoder output values to stdout where they could be redirected to a text file.</p>
<pre><strong>static void encode(long *voice, long pitch, float rms, float *rc, long *ipitch,</strong>
<strong>long *irms, long *irc)</strong>
<strong>{</strong>
<strong>…</strong>
<strong>printf("%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\n",</strong>
<strong>irc[0],irc[1],irc[2],irc[3],irc[4],irc[5],irc[6],irc[7],irc[8],irc[9],</strong>
<strong>*ipitch, *irms);</strong>
<strong>} /* encode_ */
</strong><strong></strong></pre>
<p>To create my encoder reference values I encoded two known speech files using the unmodified floating point code and dumped the encoded values to files.  It was then easy to regularly diff the reference files with the files generated by the fixed point code to see how accurate the conversion was.  In the end, I stopped when the fixed point encoder achieved 95% accuracy compared to the floating point code, and the resulting decoded speech was indistinguishable from that generated by the floating point code.</p>
<p>For a lossy speech codec like LPC-10 I did not need to spend the time achieving 100% bit-exact results, but having the reference files helped assure me that my conversion was good, and helped to quickly notify me when I broke the code while trying to make it better.</p>
<p>Part 3 will cover the conversion process.</p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/floating-point-to-fixed-point-code-conversion-part-2-preparing-your-code-371.shtml/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ask Phil &#8211; UDP datagram loss</title>
		<link>http://hawksoft.com/2010/ask-phil-udp-datagram-loss-375.shtml</link>
		<comments>http://hawksoft.com/2010/ask-phil-udp-datagram-loss-375.shtml#comments</comments>
		<pubDate>Tue, 04 May 2010 01:48:26 +0000</pubDate>
		<dc:creator>Phil Frisbie, Jr.</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hawksoft.com/?p=375</guid>
		<description><![CDATA[Mike asked:
I have a question about the loss of UDP datagrams.  System setup like below:
 /-------------\    Crossover    /-------------\
 &#124; System A    &#124;  &#60;------------&#62; &#124; System B    &#124;
 &#124; 192.168.0.1 &#124;      Cable      &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Mike asked:</p>
<p><em><strong>I have a question about the loss of UDP datagrams.  System setup like below:</strong></em></p>
<pre><strong> /-------------\    Crossover    /-------------\
 | System A    |  &lt;------------&gt; | System B    |
 | 192.168.0.1 |      Cable      | 192.168.0.2 |
 \-------------/      100MB/s    \-------------/
</strong></pre>
<p><em><strong>If I have a test program to send UPD datagrams across this connection, assuming I am not overloading the link, should I expect any datagram loss?<span id="more-375"></span></strong></em></p>
<p>My reply:</p>
<p><em><strong>Yes, with UDP you MUST expect lost packets and provide code to deal with  them.</strong></em></p>
<p><em><strong>Not overloading the link has nothing to do with lost packets; timing is  everything. For example, if the sender sends a burst of packets faster  than the  link layer can handle and the send buffer fills up then packets will be  silently  dropped. Or if the receiving thread gets delayed due to a momentary  spike in CPU  activity and cannot receive the packets fast enough and the receive  buffer fills  up packets will be discarded.</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://hawksoft.com/2010/ask-phil-udp-datagram-loss-375.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
