<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#</title><link>http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx</link><description>digg_url = "http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx";digg_title = "Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#";digg_bgcolor = "#FFFFFF";digg_skin</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#</title><link>http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx#9809377</link><pubDate>Tue, 30 Jun 2009 10:52:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9809377</guid><dc:creator>Joshua Smyth</dc:creator><description>&lt;p&gt;Very interesting arrticle - can you write the wav to somekind of memory stream and play it back in real time so you can create some kind of synth keyboard thing?&lt;/p&gt;</description></item><item><title>re: Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#</title><link>http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx#9823297</link><pubDate>Wed, 08 Jul 2009 03:55:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9823297</guid><dc:creator>Nish</dc:creator><description>&lt;p&gt;Small correction: In the Square wave example, shouldn't the two channel loop be: data.shortArray[i + channel]? &lt;/p&gt;</description></item><item><title>re: Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#</title><link>http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx#9904079</link><pubDate>Wed, 07 Oct 2009 05:37:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9904079</guid><dc:creator>Patrick</dc:creator><description>&lt;p&gt;Great post. Did some wave stuff before but lost everything with a HDD crash, these projects are a great place to start again. &lt;/p&gt;
&lt;p&gt;Will part 5 be up anytime soon?&lt;/p&gt;
&lt;p&gt;Thanks for the efforts so far!&lt;/p&gt;</description></item><item><title>re: Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#</title><link>http://blogs.msdn.com/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx#9936152</link><pubDate>Sat, 12 Dec 2009 22:25:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9936152</guid><dc:creator>HarryLime</dc:creator><description>&lt;p&gt;Hi Dan, there is coding error in the sawtooth generation which is audible when volume is not 100%.&lt;/p&gt;
&lt;p&gt;I had a close look with a wave editor. For example with volume at 42% the generated wave is one octave lower, full swing and not a sawtooth any more. &lt;/p&gt;
&lt;p&gt;Fix of the inner loop:&lt;/p&gt;
&lt;p&gt;Move line &amp;nbsp;21: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tempSample += ampStep;&lt;/p&gt;
&lt;p&gt;above line 19: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int channel = 0; .....&lt;/p&gt;
&lt;p&gt;Having fixed that i starting digging deeper into the code because the triangle algorithm works correctly. Although it has the same increment statement within the inner loop. &lt;/p&gt;
&lt;p&gt;Because of the check of amplitude boundaries the wave is correct. The only minor issue is that left and right samples have not the same value.&lt;/p&gt;
&lt;p&gt;Then i was going back to the start of your article to the sine wave generation. Your intention is to generate a stereo wave with the exact same values for left and right. That is what the inner loop does but the array content is partly overwritten by the outer loop because of i++ instead of &amp;nbsp;i+=format.wChannels.&lt;/p&gt;
&lt;p&gt;Here is my suggestion for the sine wave:&lt;/p&gt;
&lt;p&gt;for (int i = 0; i &amp;lt; numSamples; i += format.wChannels)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;tempSample = Convert.ToInt16(amplitude * Math.Sin(t * i));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;for (int channel = 0; channel &amp;lt; format.wChannels; channel++)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data.shortArray[i + channel] = tempSample;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;} &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;} &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;Hope this helps. &lt;/p&gt;
&lt;p&gt;Anyway, you wrote an very interesting intro about wave generation. Looking forward to the WPF Wave Synth.&lt;/p&gt;
&lt;p&gt;best regards,&lt;/p&gt;
&lt;p&gt;Harry&lt;/p&gt;
</description></item></channel></rss>