Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux sine wave audio generator [closed]

Tags:

linux

audio

I want to use my laptop as sinus generator under linux. But I have not found a program that can generate sound. Can someone tell me the right program or script for it. Thank you.

PS: I don't want use wine for it. PS2: I found this: "aoss siggen" and "speaker_test". But first ncurses based and second can not generate a continuous signal. May be you know more?

like image 456
smex Avatar asked Feb 24 '11 18:02

smex


1 Answers

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?