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

A very simple crude sinewave generator using a BASH script inside a Linux Terminal.

The file required is generated inside the code and requires /dev/audio to work.

Ensure you have this device, if not the download oss-compat from your OS's repository...

It lasts for about 8 seconds before exiting and saves a 65536 byte file to your working directory/drawer/folder as sinewave.raw.

Use an oscilloscope to check the waveform generated...

It is entirely Public Domain and you may do with it as you please...

Enjoy finding simple solutions to often very difficult problems... ;o)

Bazza, G0LCU...

Bash, 27 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
25
26
27
#!/bin/bash
#
# 1KHz.sh
#
# A very simple DEMO crude sinewave generator using the device /dev/audio in Linux.
# It is an eight second burst and generates an approximation of a pure sinewave using linear interpolation.
# The "sinewave.raw" file length is 65536 bytes in size and saved to your default working directory...
#
# $VER: 1KHz.sh_Version_0.00.10_Public_Domain_2013_B.Walker_G0LCU.

# Zero the raw file...
> sinewave.raw

# This is the binary byte data list for the crude sinewave.
data="\\x0f\\x2d\\x3f\\x2d\\x0f\\x03\\x00\\x03"

# Generate the file as an approximately eight second burst...
for waveform in {0..8191}
do
        printf "$data" >> sinewave.raw
done

# Now play back a single run of the raw data for about eight seconds.
cat sinewave.raw > /dev/audio

# End of 1KHz.sh DEMO...
# Enjoy finding simple solutions to often very simple problems... ;o)

A basic crude sinewave generator.

Bazza, G0LCU...