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 >
C/C++ Source or Header  |  1990-01-10  |  1KB  |  53 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "libst.h"
  4.  
  5. #define MYBUFSIZ 256
  6.  
  7. #define MAX_TONES 100
  8. #define MAG 2048.0
  9. #define SECS 5.0
  10.  
  11. main( argc, argv )
  12. int argc;
  13. char *argv[];
  14.     {
  15.     char mybuf[MYBUFSIZ];
  16.     int argn, num_tones, i, j, lsample;
  17.     double hzs[MAX_TONES], sample;
  18.     char *usage = "usage:  %s <hz> ...\n";
  19.  
  20.     argn = 1;
  21.     num_tones = 0;
  22.     while ( argn < argc )
  23.     {
  24.     hzs[num_tones] = atof( argv[argn] );
  25.     if ( hzs[num_tones] <= 0.0 || hzs[num_tones] > SAMPLES_PER_SECOND / 2 )
  26.         {
  27.         fprintf( stderr, usage, argv[0] );
  28.         exit( 1 );
  29.         }
  30.     ++num_tones;
  31.     ++argn;
  32.     }
  33.  
  34.     if ( num_tones > 5 )
  35.     fprintf( stderr,
  36.         "%s: warning, tone generation will be slower than real time\n",
  37.         argv[0] );
  38.  
  39.     setbuffer( stdout, mybuf, MYBUFSIZ );
  40.  
  41.     for ( i = 0; i < SECS * SAMPLES_PER_SECOND; ++i )
  42.     {
  43.     sample = 0.0;
  44.     for ( j = 0; j < num_tones; ++j )
  45.         sample += MAG * sin( hzs[j] / SAMPLES_PER_SECOND * 2.0 * M_PI * i );
  46.     lsample = sample;
  47.     LINCLIP( lsample );
  48.     putchar( st_linear_to_ulaw( lsample ) );
  49.     }
  50.  
  51.     exit( 0 );
  52.     }
  53.