13

Is there something like a stereo (separate left-and right-channel) tone-generator for Linux? Where you can set volume and tone/pitch for each channel, and preferably also set the wave-form (sine, square, sawtooth, ...) and invert one channel (as opposed to the other).

If not, any ideas for a good places to start to make one? I guess the simplest would be to adapt existing programs like synths... But if that work poorly, are there any libraries (like SDL?) that can be used as bases for such a program?

15

It sounds like you're looking for Audacity which is a cross-platform open source audio editor. One of its features is to allow you to generate tones. It's a multi-track audio editor, so you can easily create a stereo tone.

Under the Generate menu, you're able to create Sine, Sawtooth, and Square waveform tones of arbitrary frequency, amplitude, and length without the need for recording or needing additional input files.

  • But can it generate tones "from nothing"? And I'm not intending to record and playback anything, just generate two slightly different tones (one for each channel) "for eternity". – Baard Kopperud Jul 7 '13 at 18:38
  • 1
    @BaardKopperud Yes, I updated my answer to clarify. – j883376 Jul 7 '13 at 18:47
8

You might look at speaker-test, which (on an Arch machine) I find in alsa-utils package.

speaker-test -c2 -t sine run from an xterm, gave me a 440 Hz sine wave for about 6 seconds each, alternating left and right speakers. In the xterm, it gave some information about which speaker it thought it was using.

According to the man page, it can do sine waves of arbitrary frequency and pink noise.

  • 1
    speaker-test -c2 -t sine -f 440 will complement your example by giving the frequency parameter. Thanku. – christian Jun 3 '18 at 12:37
4

The siggen program should do the trick.

screenshot of siggen

It has two channels with independent signals and a phase between them. Each channel can do these signal types:

  • sine
  • cosine
  • square
  • triangle
  • sawtooth
  • pulse
  • noise

You can run it in stereo mode like this:

$ siggen -2

Since /dev/dsp is deprecated in most modern Linux distros, you will probably need to install a compatibility library. On Debian-based distros, install the alsa-oss package and run it like this:

$ aoss siggen -2

You can also try it with the PulseAudio OSS Wrapper:

$ padsp siggen -2
  • I get: [siggen] Input/output error : /dev/dsp – Ole Tange Apr 17 at 19:47
  • Hm. Does the PulseAudio OSS wrapper help at all? – Nathaniel M. Beaver Apr 17 at 20:02
  • Yep. It worked. – Ole Tange Apr 18 at 7:14
1

The saugns program can also do it. (It is a command-line audio generator (currently) supporting 8 wave types and FM/PM/AM modulation techniques.)

To generate two stereo-separated 100 Hz waves, one a sine and one a triangle, and one with inverted amplitude, the following script can be pasted into a file and ran through the program (as in ./saugns filename):

Osin f100 a0.5 t2 P0
Otri f100 a(-0.5) t2 P1

The ts specify time, in seconds.

The Ps are for per-voice panning (0.0 = left, 1.0 = right). This may be changed to something other than P in future versions; the README file describes the current syntax.

Edit: I'm indeed the developer of the program.

Also, an alternative way of flipping the amplitude (for some wave types, e.g. sin but not saw), is to set the phase using a lowercase p. Adding p0.5 sets phase to 50% of the wave cycle (negative half). Further, as there's no named cosine type, p0.25 is the way to turn sine into cosine (or p0.75 for negative cosine).

  • Hi Joel. Welcome to Unix & Linux. I've upvoted your answer as it's a great first post. I thought I'd mention that if you're a maintainer or developer of a project, it's standard practice to disclose this information. While not really an issue for GPL software, it's worth being aware of unix.stackexchange.com/help/promotion For useful Free/Libre software, I'd imagine that you'd be more likely to get upvoted on this site if users know you're one of the developers behind the project. – Anthony Geoghegan Jun 20 at 0:17
0

You might be looking for Gnaural.

  • 3
    It would be best to edit this answer to include more information about how this program provides the features being asked about - similar to the other answers previously posted. – Anthony Geoghegan Aug 17 '18 at 17:46
0

You can easily synthesize tones with SoX. There were some stumbling blocks but I was eventually able to figure it out.

I had trouble interfacing SoX with PulseAudio so I just pipe sox raw data into paplay.

The pipeline is tedious so I created a script:

$ cat sox-paplay
#!/bin/bash
: ${HZ:=44100}
: ${NCHAN:=6}
: ${SINK:=mysink}
sox -c $NCHAN -n -t raw -r $HZ -L -b 16 - "$@" | paplay --no-remix --no-remap --raw -v -p --rate $HZ -d $SINK --channels $NCHAN

e.g.

sox-paplay synth sine 1000 gain -5 remix -m 0 0 1 0 0 0

The remix effect is just used to send the result to a specific channel. It is much more powerful but we only use the basic functionality here. In this example we have a six-channel device and we're sending a tone to the third channel.

I originally created an ALSA device wrapping the PulseAudio device, but then I found that it is impossible to control the channel mapping using ALSA, and so random channels were getting mixed together according to how my custom channel-map differed from the ALSA default. This is why I have --no-remix --no-remap in paplay above; I just want the raw channel ordering for the sox command.

I kind of wish that audio stuff on Linux had better documentation and error reporting.

You may be interested in an answer I posted recently showing how to set the PulseAudio Equalizer from the command-line.

0

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: https://stackoverflow.com/questions/732699/how-is-audio-represented-with-numbers-in-computers/36510894#36510894

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.