Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Another Python freebie...

Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
LXF regular

Joined: Sat Mar 21, 2009 11:16 am
Posts: 1476
Location: Loughborough

PostPosted: Fri Oct 01, 2010 6:02 pm    Post subject: Another Python freebie... Reply with quote

Hi all...

Another piece of test gear for the electronics enthusiast.

Well to add to the Audio Function Generator Python code
I gave to LXF some time ago here is another Python freebie
for LXF.

A "`White` Noise Generator" written in STANDARD Python 2.5.2
for PCLinuxOS 2009. It Works in Knoopix 5.1.1 and Python too.

Now experimenting with "Pink Noise", "Brown Noise" and
"Bandpass Noise" filtering using Python.

Enjoy finding simple solutions to often very difficult problems.

Watch for wordwrapping etc...


# A stereo "White Noise" generator using STANDARD Python 2.5.2 or higher.
# This is for (PC)Linux(OS), (ONLY?), and was done purely for fun.
# Original idea copyright, (C)2010, B.Walker, G0LCU.
# Ensure the sound is enabled and the volume is turned up.
# Copy the file to the Lib folder/drawer/directory where Python resides
# as "" without the quotes.
# Start the Python interpreter from a console/terminal window.
# For a quick way to run the noise generator just use at the ">>>" prompt:-
# >>> import noise[RETURN/ENTER]
# And away we go...
# This code is Public Domain and you may do with it as you please...
# Coded on a(n) HP dual core notebook running PCLinuxOS 2009 and
# Python 2.5.2 for Linux...
# Connect an oscilloscope to the earphone socket(s) to see the noise
# waveform being generated.
# It's not perfect, but hey, a noise generator for free can't be bad eh!.

# Import any modules, ~sys~ is not rquired but added nevertheless.
import sys
import os
import random

# Clear a terminal window ready to run this program.
print os.system("clear"),chr(13),"  ",chr(13),

# The program proper...
def main():
    # Make all variables global, a quirk of mine... :)
    global noise
    global value
    global select
    global count
    # The INITIAL default values.

    # A continuous loop to re-generate noise as required...
    while 1:
        # Set up a basic user window.
        print os.system("clear"),chr(13),"  ",chr(13),
        print "Simple Noise Generator using STANDARD Python 2.5.2"
        print "for PCLinuxOS 2009, issued as Public Domain to LXF."
        print "Original idea copyright, (C)2010, B.Walker, G0LCU."
        # Select RETURN/ENTER for "White Noise", OR, any other key then RETURN/ENTER to Quit.
        select=raw_input("Press RETURN/ENTER for noise or any other key then RETURN/ENTER to Quit:- ")
        if select=="": select="1"
        # Don`t allow an error and crash out with one.
        if len(select)!=1: break
        if select<=chr(48): break
        if select>=chr(50): break
        print os.system("clear"),chr(13),"  ",chr(13),
        print "White noise audio generation..."
        # Set the random seed value per run.
        # Open up the audio channel(s) to write directly to.
        audio=file('/dev/audio', 'wb')
        # A count of 70000 is about 10 seconds of noise burst...
        while count<70000:
            # Generate a random byte value 0 to 63.
            # Write the character, (byte), "value" to the audio device.
        # Close the audio device when finished.
# End of demo...

hmmm, I wonder how easy it is to create a real time audio
scope using STANDARD Python for Linux...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 

Powered by phpBB © 2001, 2005 phpBB Group

Copyright 2011 Future Publishing, all rights reserved.

Web hosting by UKFast