On Thu, Jan 24, 2008 at 11:41:04AM -0800, maxim wexler wrote:
> Anybody know of a gentoo/linux tone generator that
> will output test tones, sine waves, triangle waves and
> the like.
>
> Prefer command line/ncurses.
>
One of my friends coded something like this once as a plug-in for
XMMS. Can't seem to find it now. Perhaps you'd have better luck than
I.
On the other hand, a little bit of C++ should be fairly easy. First
you need the 'play' program from sox. 'play' can play files in the
'raw' format, which is just a stream of words that gives the amplitude
of the waveform. For example
play -t raw -s l -f s -c 1 -r 30000 -
takes as input stdin, plays mono channel sound from a stream that is
signed-linear, 300000 hertz sample rate, and with amplitude described
by 32 bit long word. Next you just need a waveform generator. A C++
snipplet from something I cobbled together several years ago (yes yes,
my coding practice can stand much improvement, so sue me)
#include <stdio.h>
#include <unistd.h>
#include <math.h>
int main()
{
int rate = 30000;
int coramp = 0xCEFFFFF;
int tempamp=0;
float totalamp=0;
int f_count;
while(1) for(f_count=0; f_count < rate; f_count++)
{
totalamp=sinf( ((float)f_count) * 440 / rate * 2 * M_PI);
tempamp = (int) (coramp * totalamp);
printf("%c%c%c%c%c%c%c%c", (char) (tempamp), (char) (tempamp >>
8), (char) (tempamp >> 16), (char) (tempamp >> 24), (char) (tempamp), (char)
(tempamp >> 8), (char) (tempamp >> 16), (char) (tempamp >> 24));
}
return 0;
}
Yes, it is an infinite loop.
The sinf makes it a sine wave. You can code your own triangle wave.
THe 440 makes it output A-440. It is the frequency.
coramp is an amplifying factor.
compile it, run it like
./a.out | play -t raw -s l -f s -c 1 -r 30000 -
And you should get A-440 out of your speakers.
W
--
Willie W. Wong [EMAIL PROTECTED]
408 Fine Hall, Department of Mathematics, Princeton University, Princeton
A mathematician's reputation rests on the number of bad proofs he has given.
--
[email protected] mailing list