<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Tue May 21, 2013 4:06 pm by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Tue May 21, 2013 4:06 pm</pubDate>
  <lastBuildDate>Tue May 21, 2013 4:06 pm</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Another Python freebie...</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=93474#93474</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=58561'&gt;Bazza&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Oct 01, 2010 6:02 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hi all...&lt;br /&gt;
&lt;br /&gt;
Another piece of test gear for the electronics enthusiast.&lt;br /&gt;
&lt;br /&gt;
Well to add to the Audio Function Generator Python code&lt;br /&gt;
I gave to LXF some time ago here is another Python freebie&lt;br /&gt;
for LXF.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;`White` Noise Generator&amp;quot; written in STANDARD Python 2.5.2&lt;br /&gt;
for PCLinuxOS 2009. It Works in Knoopix 5.1.1 and Python too.&lt;br /&gt;
&lt;br /&gt;
Now experimenting with &amp;quot;Pink Noise&amp;quot;, &amp;quot;Brown Noise&amp;quot; and&lt;br /&gt;
&amp;quot;Bandpass Noise&amp;quot; filtering using Python.&lt;br /&gt;
&lt;br /&gt;
Enjoy finding simple solutions to often very difficult problems.&lt;br /&gt;
&lt;br /&gt;
Watch for wordwrapping etc...&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
# A stereo &amp;quot;White Noise&amp;quot; generator using STANDARD Python 2.5.2 or higher.&lt;br /&gt;
# This is for &amp;#40;PC&amp;#41;Linux&amp;#40;OS&amp;#41;, &amp;#40;ONLY?&amp;#41;, and was done purely for fun.&lt;br /&gt;
#&lt;br /&gt;
# Original idea copyright, &amp;#40;C&amp;#41;2010, B.Walker, G0LCU.&lt;br /&gt;
#&lt;br /&gt;
# DONATED TO LXF AS PUBLIC DOMAIN...&lt;br /&gt;
#&lt;br /&gt;
# Ensure the sound is enabled and the volume is turned up.&lt;br /&gt;
#&lt;br /&gt;
# Copy the file to the Lib folder/drawer/directory where Python resides&lt;br /&gt;
# as &amp;quot;noise.py&amp;quot; without the quotes.&lt;br /&gt;
#&lt;br /&gt;
# Start the Python interpreter from a console/terminal window.&lt;br /&gt;
#&lt;br /&gt;
# For a quick way to run the noise generator just use at the &amp;quot;&amp;gt;&amp;gt;&amp;gt;&amp;quot; prompt&amp;#58;-&lt;br /&gt;
#&lt;br /&gt;
# &amp;gt;&amp;gt;&amp;gt; import noise&amp;#91;RETURN/ENTER&amp;#93;&lt;br /&gt;
#&lt;br /&gt;
# And away we go...&lt;br /&gt;
#&lt;br /&gt;
# This code is Public Domain and you may do with it as you please...&lt;br /&gt;
#&lt;br /&gt;
# Coded on a&amp;#40;n&amp;#41; HP dual core notebook running PCLinuxOS 2009 and&lt;br /&gt;
# Python 2.5.2 for Linux...&lt;br /&gt;
#&lt;br /&gt;
# Connect an oscilloscope to the earphone socket&amp;#40;s&amp;#41; to see the noise&lt;br /&gt;
# waveform being generated.&lt;br /&gt;
#&lt;br /&gt;
# It's not perfect, but hey, a noise generator for free can't be bad eh!.&lt;br /&gt;
&lt;br /&gt;
# Import any modules, ~sys~ is not rquired but added nevertheless.&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
# Clear a terminal window ready to run this program.&lt;br /&gt;
print os.system&amp;#40;&amp;quot;clear&amp;quot;&amp;#41;,chr&amp;#40;13&amp;#41;,&amp;quot;&amp;nbsp; &amp;quot;,chr&amp;#40;13&amp;#41;,&lt;br /&gt;
&lt;br /&gt;
# The program proper...&lt;br /&gt;
def main&amp;#40;&amp;#41;&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Make all variables global, a quirk of mine... &amp;#58;&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; global noise&lt;br /&gt;
&amp;nbsp; &amp;nbsp; global value&lt;br /&gt;
&amp;nbsp; &amp;nbsp; global select&lt;br /&gt;
&amp;nbsp; &amp;nbsp; global count&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # The INITIAL default values.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; select=&amp;quot;G0LCU.&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; value=0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; noise=chr&amp;#40;value&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; count=0&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # A continuous loop to re-generate noise as required...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while 1&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Set up a basic user window.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print os.system&amp;#40;&amp;quot;clear&amp;quot;&amp;#41;,chr&amp;#40;13&amp;#41;,&amp;quot;&amp;nbsp; &amp;quot;,chr&amp;#40;13&amp;#41;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &amp;quot;Simple Noise Generator using STANDARD Python 2.5.2&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &amp;quot;for PCLinuxOS 2009, issued as Public Domain to LXF.&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &amp;quot;Original idea copyright, &amp;#40;C&amp;#41;2010, B.Walker, G0LCU.&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Select RETURN/ENTER for &amp;quot;White Noise&amp;quot;, OR, any other key then RETURN/ENTER to Quit.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select=raw_input&amp;#40;&amp;quot;Press RETURN/ENTER for noise or any other key then RETURN/ENTER to Quit&amp;#58;- &amp;quot;&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if select==&amp;quot;&amp;quot;&amp;#58; select=&amp;quot;1&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Don`t allow an error and crash out with one.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if len&amp;#40;select&amp;#41;!=1&amp;#58; break&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if select&amp;lt;=chr&amp;#40;48&amp;#41;&amp;#58; break&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if select&amp;gt;=chr&amp;#40;50&amp;#41;&amp;#58; break&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print os.system&amp;#40;&amp;quot;clear&amp;quot;&amp;#41;,chr&amp;#40;13&amp;#41;,&amp;quot;&amp;nbsp; &amp;quot;,chr&amp;#40;13&amp;#41;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print &amp;quot;White noise audio generation...&amp;quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Set the random seed value per run.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random.seed&amp;#40;None&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Open up the audio channel&amp;#40;s&amp;#41; to write directly to.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; audio=file&amp;#40;'/dev/audio', 'wb'&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # A count of 70000 is about 10 seconds of noise burst...&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count=0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while count&amp;lt;70000&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Generate a random byte value 0 to 63.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value=random.random&amp;#40;&amp;#41;*64&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value=int&amp;#40;value&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; noise=chr&amp;#40;value&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Write the character, &amp;#40;byte&amp;#41;, &amp;quot;value&amp;quot; to the audio device.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; audio.write&amp;#40;noise&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count=count+1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Close the audio device when finished.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; audio.close&amp;#40;&amp;#41;&lt;br /&gt;
main&amp;#40;&amp;#41;&lt;br /&gt;
# End of demo...&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
hmmm, I wonder how easy it is to create a real time audio&lt;br /&gt;
scope using STANDARD Python for Linux...</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=93474#93474</comments>
                                        <author>Bazza</author>
                                        <pubDate>Fri Oct 01, 2010 6:02 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=93474#93474</guid>
                                      </item></channel></rss>