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 / mix.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  2KB  |  80 lines

  1. /* mix.c - mix multiple sound files
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <strings.h>
  15. #include "libst.h"
  16.  
  17. #define MAXFILES 64    /* the kernel's got a limit, why shouldn't I? */
  18. #define MYBUFSIZ 256
  19.  
  20. main( argc, argv )
  21. int argc;
  22. char *argv[];
  23.     {
  24.     FILE *files[MAXFILES];
  25.     char mybuf[MYBUFSIZ];
  26.     int nfiles, i, c, sum, gotone;
  27.  
  28.     nfiles = argc - 1;
  29.     if ( nfiles < 2 )
  30.     {
  31.     fprintf( stderr, "usage:  %s <file1> <file2> [<fileN> ...]\n", argv[0] );
  32.     exit( 1 );
  33.     }
  34.  
  35.     for ( i = 0; i < nfiles; ++i )
  36.     {
  37.     if ( strcmp( argv[i + 1], "-" ) == 0 )
  38.         files[i] = stdin;
  39.     else
  40.         {
  41.         files[i] = fopen( argv[i + 1], "r" );
  42.         if ( files[i] == NULL )
  43.         {
  44.         perror( argv[i + 1] );
  45.         exit( 1 );
  46.         }
  47.         }
  48.     }
  49.     setbuffer( stdout, mybuf, MYBUFSIZ );
  50.     
  51.     for ( ; ; )
  52.     {
  53.     sum = 0;
  54.     gotone = 0;
  55.     for ( i = 0; i < nfiles; ++i )
  56.         {
  57.         if ( files[i] != NULL )
  58.         {
  59.         c = getc( files[i] );
  60.         if ( c == EOF )
  61.             {
  62.             fclose( files[i] );
  63.             files[i] = NULL;
  64.             }
  65.         else
  66.             {
  67.             gotone = 1;
  68.             sum += st_ulaw_to_linear( (unsigned char) c );
  69.             }
  70.         }
  71.         }
  72.     if ( gotone == 0 )
  73.         break;
  74.     LINCLIP( sum );
  75.     putchar( st_linear_to_ulaw( sum ) );
  76.     }
  77.  
  78.     exit( 0 );
  79.     }
  80.