A Function To Create A 1 Second Sinewave WAVE Beep File In Python.
sinebeep.py
Creating an audio WAVE file called...
beep.wav
...that can be played using almost ANY audio player available.
This simple DEMO snippet of code generates a 1 second sinewave WAVE file. It IS saved inside the CURRENT drawer so that you can find it... ;o)
Note that the waveform itself is created in pure text mode, that is from decimal 32, (space), to decimal 126, (~)... This makes it possible to create a lot of arbitrary RAW
waveforms any length inside any suitable text editor to _at_least_ 6 bit depth AND IF the full range of decimal 0 to 127 is used, 7 bit depth.
This works on:-
Classic stock AMIGA A1200, using Python 1.4.0.
WinUAE and E-UAE, AmigaOS 3.0.x using Python 1.4.0 to 2.0.1.
Windows, to at least 7, using Python 2.0.1 to 3.3.2.
Various Linux flavours using Python 2.4.6 to 3.2.2.
Apple OSX 10.7.x and above using Python 2.5.6 to 3.4.1.
The file size is 8044 bytes and _IF_ you need to it can be palyed directly without a player on some Linux flavours that have the /dev/dsp device. It is an 8 bit, unsigned integer,
mono, 8000Hz sampling speed 8000 byte RAW file with the WAVE header added.
It will still work with PulseAudio and OSS using...
cat /full/path/to/beep.wav > /dev/dsp
...but with a momenatry click due to the 44 header bytes; but hey it is a beep alternative...
This took a while to work out how to make it Version AND Platform independent but this is the result...
Enjoy finding simple solutions to often very difficult problems.
The chr() function is common to ALL versions of Python for HEX character values from 0x00 to 0x7F, decimal 0 to 127 inclusive. It COULD be considered eqivalent to bytes
inside these two limits.
As these two limits are effectively 7 bits in size then creating almost any wave shape is possible withing limits of the HW in use and the 7 bit depth.
This is a hack, so......
......therefore it is easily possible to juggle the header to stay inside 7 bits per byte and create ALMOST any 7 bit waveform, any length, mono or stereo at any
standard sampling speed.
It is NOT practically possible to do 16 bit signed values that satisfies ALL Python versions, BUT, it IS if there are two versions, one to suit pre-version 3.0.0 and the other to suit
post-version 3.0.0...
Bazza...
This User Gave Thanks to wisecracker For This Post:
Hi all...
As you know I like making code backwards compatible for as many platforms as possible.
This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Hi everyone.
I'm trying to learn python as it relates to parsing xml, and I thought I would start by trying to create an easy (or I thought would be easy) function
to match on a certain attribute in an xml file and print out it's related attribute.
Here's an example to hopeful make sense of... (0 Replies)
All,
I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this
#!/usr/bin/python
def div4and6(s,e):
for i in range(s,e+1):
if... (5 Replies)
I would like to make a perl function , this function could send mail via SMTP and also could import a text file into mail content , that mean I have a text file , want to use this function to send mail via SMTP , the mail content is the text file , would advise how to write this script ? thanks (1 Reply)
Hi all...
I don't think this has been done before but I am open to being corrected...
This batch file generates a 65536 byte binary file to give 8 seconds of pure sinewave at the earphone/speaker output(s)...
It uses ONLY a default Windows 32 bit installation, to Windows 7, except for the... (0 Replies)
My Calling script is like below:
for file in `echo $LIST_OF_FILES` --listing filenames eg, xyz_meta_20110501_00000789.tar
do
file_name=`basename $file`
<call a function to create .txt file in below format>
done
Want to generate a .txt file that contains below data in ksh:
... (3 Replies)
IKHz_SW_OSX.py
A DEMO mono _pure_ sinewave generator using standard text mode Python 2.6.7 to at least 2.7.3.
This code is EASILY modifyable to Python version 3.x.x...
This DEMO kids level 1KHz generator is mainly for a MacBook Pro, (13 inch in my case), OSX 10.7.5 and above. See below...... (0 Replies)
HI,
I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc.
What I am intending to find out is catenate a file where let say
cat a.txt| awk ' {
t= h*($3+$2);
t=... (7 Replies)
Now I have two wave file(*.wav) at Tru64 Unix machine.
I want to make a new wave file including the two wave file.
how I should finish this programmer.
If you know, can you give me the format of the wave file(*.wav)
and Sun au file(*.au).
Thank you. (1 Reply)