ffmpeg
ffmpeg can do it, as usual.
Create a 5 seconds mono 1000Hz sinusoidal out.wav
sound file:
sudo apt-get install ffmpeg
ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" out.wav
Stereo instead:
ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -ac 2 out.wav
The file will be 2x as large, and ffprobe
will say it has 2 channels
instead of 1 channel
.
Play the audio for 5 seconds without creating a file:
ffplay -f lavfi -i "sine=frequency=1000:duration=5" -autoexit -nodisp
Play forever until you go mad:
ffplay -f lavfi -i "sine=frequency=1000" -nodisp
Documentation:
The other section sunder Audio sources document other useful sound generation algorithms in addition to sine
, e.g.:
Bibliography:
Tested in Ubuntu 18.04, ffmpeg 3.4.6.
Minimal C audio generation example without extra libraries
Just for fun: How is audio represented with numbers in computers?