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:
- https://ffmpeg.org/ffmpeg-filters.html#sine
- https://www.ffmpeg.org/ffmpeg-devices.html#lavfi
The other section sunder Audio sources document other useful sound generation algorithms in addition to sine
, e.g.:
- anoisesrc: several noises
- aevalsrc takes arbitrary mathematical expressions!
Bibliography:
- https://superuser.com/questions/724391/how-to-generate-a-sine-wave-with-ffmpeg
- How to run ffplay as a window-less process?
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?