Welcome, guest | Sign In | My Account | Store | Cart

This small bash script generates an 8044 byte 1KHz sinewave wave file and immediately plays it. The file created is a _pure_ sinewave and lasts for 1 second. It uses the default "afplay" command to run the generated file.

It was designed around an Apple Macbook Pro but using "aplay" it might even work on other *nix flavours from the command line. I have not bothered to try it as this was purely for my MB Pro.

The wave file can be found as "/tmp/sinewave.wav" during the working session(s) and can be saved anywhere of your choice.

Enjoy...

(Watch for word wrapping etc...)

Bazza.

Bash, 24 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash --posix
# beep
# *********************************************************
# Generate a 1 second beep shell command for OSX 10.7.5, default bash terminal.
# Original idea (C)2012, B.Walker, G0LCU.
# Now issued as Public Domain, CC0. You may do with it as you please.
# *********************************************************
> /tmp/sinewave.wav
printf "\x52\x49\x46\x46\x64\x1F\x00\x00\x57\x41\x56\x45\x66\x6D\x74\x20\x10\x00\x00\x00\x01\x00\x01\x00\x40\x1F\x00\x00\x40\x1F\x00\x00\x01\x00\x08\x00\x64\x61\x74\x61\x40\x1F\x00\x00" >> /tmp/sinewave.wav
for n in {0..999}
do
	printf "\x80\x26\x00\x26\x7F\xD9\xFF\xD9" >> /tmp/sinewave.wav
done
# *********************************************************
# The line below uses various Linux flavours, "aplay"...
# aplay /tmp/sinewave.wav
# *********************************************************
# Use the OSX default basic command line audio player, "/usr/bin/afplay".
afplay /tmp/sinewave.wav
# "afinfo" is OSX also...
# afinfo /tmp/sinewave.wav
# *********************************************************
exit 0
# Enjoy finding simple solutions to often very difficult problems...

I am lazy and like to do things the easy way and this was the result.

It is all yours guys and gals.

I would dearly love to know which other *NIX and Linux flavours this works on so as to include them in the tags section.

Enjoy...

1 comment

Barry Walker (author) 10 years ago  # | flag

Now tested on Linux using "aplay"...