A Crude 1KHz Audio Sinewave Generator Demo...

A very simple crude sinewave generator.

The file required is generated inside the code, is linear interpolated 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...

Bazza, G0LCU...

#!/bin/bash
#
# 1KHz.sh
#
# A very simple DEMO crude sinewave generator using the device /dev/audio.
# 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...

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

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

# Generate the file as an 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)

I wonder how short the MP3 file would be?

Hi DGPickett...

Certainly not 8 bytes for a single shot, that is for sure!

If it is possible to generate a "sinewave.mp3" _sinewave_ file, or any known waveshape for that matter, for 8 seconds inside 7 simple lines of code that anyone can understand without first recording said waveform then I would be mighty interested... ;o)

I think the implication was that a pure sine wave might compress really really well in mp3.

Hi Corona688...

Trust me to get it wrong...

Thanks for the heads-up...

I suppose you might want MPEG2.5 and CBR for the 8000 samples a second, which is 8 samples repeated for a 1000 Hz sine tone.
MP3 - Wikipedia, the free encyclopedia

Maybe 12 bytes, one header and 8 8 bit samples?