Sponsored Content
Top Forums Shell Programming and Scripting A Crude 1KHz Audio Sinewave Generator Demo... Post 302758723 by wisecracker on Sunday 20th of January 2013 03:23:29 PM
Old 01-20-2013
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...

Code:
#!/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)

 

7 More Discussions You Might Find Interesting

1. Programming

Python, Platform Independent, Pure Audio Sinewave Generator...

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)
Discussion started by: wisecracker
0 Replies

2. Windows & DOS: Issues & Discussions

A SOX 1KHz Sinewave Generator Using A Batch File...

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)
Discussion started by: wisecracker
0 Replies

3. UNIX for Dummies Questions & Answers

A crude random byte generator...

There was an upload recently on generating a pseudo-random file when /dev/random does NOT exist. This does not need /dev/random, /dev/urandom or $RANDOM either... (I assume $RANDOM relies on the /dev/random device in some way.) This code uses hexdump just because I like hexdump for ease of... (2 Replies)
Discussion started by: wisecracker
2 Replies

4. OS X (Apple)

A Bash Audio Sweep Generator...

This is a small program as a tester for a basic sweep generator for bandwidth testing of AudioScope.sh. This DEMO is only capable of 4KHz down to about 85Hz and back due to the low bit rate, but it is proof of concept for a much wider variant using a much higher bit rate. The file generated... (4 Replies)
Discussion started by: wisecracker
4 Replies

5. OS X (Apple)

An Audio Function Generator...

Ok guys, gals and geeks... As from today I am starting to learn awk in earnest doing something totally different. I am going to create a pseudo-Audio_Function Generator centred around OSX 10.11.x minimum. The code below is a tester to see what the possibilities are. All waveforms will be... (11 Replies)
Discussion started by: wisecracker
11 Replies

6. OS X (Apple)

Variable frequency audio generator...

Hi all... I intend to do an Audio Function Generator using Awk, (already started thanks to Don), but the biggest thing I have struggled with was variable frequency. I was going to generate differing sized waveforms on the fly but that would that would mean the frequencies are dependent on any... (2 Replies)
Discussion started by: wisecracker
2 Replies

7. OS X (Apple)

A simple variable frequency sinewave audio generator.

Hi all... Well I have not been inactive but working out how to make OSX 10.14.x command line audio player have a variable sample rate. This is a back door as afplay does not have a sample rate flag unlike aplay for ALSA, in Linux flavours. This is a DEMO only but a derivative of it will... (2 Replies)
Discussion started by: wisecracker
2 Replies
NA_RECORD(1)						    BSD General Commands Manual 					      NA_RECORD(1)

NAME
na_record -- record waveform from audio device SYNOPSIS
na_record [-h] [-f sampling rate] [-audiodevice device] [-time seconds] [-o file] [-otype type] [-ostype sample type] [-F sample rate] [-obo MSB | LSB | native] [-oswap] [-p audio device protocol] DESCRIPTION
na_record records digital audio data from the system's audio input device and writes it to the specified file. It supports a variety of out- put file formats and native audio devices. The following option flags are recognized: -h Prints a short summary of usage to standard output. -f sampling rate Sets the input sampling rate (in samples per second, i.e. Hz). Not all devices support all sampling rates, so it may be desire- able to set this separately from the output sampling rate. -audiodevice device Sets the audio device to record from, if supported by the audio protocol chosen (e.g. /dev/dsp, /dev/audio) -time seconds Stops recording after the specified number of seconds. -o file Writes sound output to the specified file -otype type Specifies the file format to use for output. Supported types currently include nist, est, dsps, snd, riff, aiff, audlab, raw, and ascii. The -h flag will show the most accurate list. The default type is nist. -F sampling rate Sets the output sampling rate (again, in samples per second, i.e. Hz). If this differs from the input sampling rate, resampling will be done. Defaults to 16000Hz. -obo byte order Sets the output byte order. Supported values are MSB, LSB, and native. Many file formats have their own byte order, or are byte order independent, so this isn't tremendously useful except for raw data. The default is the native byte order for the system audio device. -oswap Swap bytes when saving to output. -ostype sample type Sets the sample type of the output. Suported values are short, mulaw, byte, or ascii. Again, this is usually implied by the file format, so should only be used for raw data. The default is short (i.e. 16-bit PCM). -p audio device protocol Selects an audio device protocol (i.e. type of audio device) to use. This varies between different installations of Speech Tools, but defaults to the most 'native' audio device, usually Open Sound System on Linux and *BSD and /dev/audio on Solaris. ENVIRONMENT
NA_PLAY_PROTOCOL Audio protocol to use (as in the -p flag) NA_PLAY_HOST Host to record audio from when using a network audio protocol. EXAMPLES
To record five seconds of audio from /dev/dsp1 (on Linux) to foo.wav in RIFF format at 32kHz: $ na_record -time 5 -audiodevice /dev/dsp1 -o foo.wav -otype RIFF -f 32000 To record one second of audio to bar.wav in raw format in 8kHz mu-law: $ na_record -time 1 -o bar.wav -otype raw -ostype mulaw -f 8000 BUGS
The -time argument only accepts integer values (though the usage message implies otherwise) SEE ALSO
na_play(1) Edinburgh Speech Tools April 4, 2001 Edinburgh Speech Tools
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy