home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
sst.tar.Z
/
sst.tar
/
sst
/
syntones.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-10
|
1KB
|
53 lines
#include <stdio.h>
#include <math.h>
#include "libst.h"
#define MYBUFSIZ 256
#define MAX_TONES 100
#define MAG 2048.0
#define SECS 5.0
main( argc, argv )
int argc;
char *argv[];
{
char mybuf[MYBUFSIZ];
int argn, num_tones, i, j, lsample;
double hzs[MAX_TONES], sample;
char *usage = "usage: %s <hz> ...\n";
argn = 1;
num_tones = 0;
while ( argn < argc )
{
hzs[num_tones] = atof( argv[argn] );
if ( hzs[num_tones] <= 0.0 || hzs[num_tones] > SAMPLES_PER_SECOND / 2 )
{
fprintf( stderr, usage, argv[0] );
exit( 1 );
}
++num_tones;
++argn;
}
if ( num_tones > 5 )
fprintf( stderr,
"%s: warning, tone generation will be slower than real time\n",
argv[0] );
setbuffer( stdout, mybuf, MYBUFSIZ );
for ( i = 0; i < SECS * SAMPLES_PER_SECOND; ++i )
{
sample = 0.0;
for ( j = 0; j < num_tones; ++j )
sample += MAG * sin( hzs[j] / SAMPLES_PER_SECOND * 2.0 * M_PI * i );
lsample = sample;
LINCLIP( lsample );
putchar( st_linear_to_ulaw( lsample ) );
}
exit( 0 );
}