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 / record.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  1KB  |  76 lines

  1. /* record.c - record from the microphone input
  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 <fcntl.h>
  15. #include <sys/signal.h>
  16. #include "libsst.h"
  17.  
  18. #define MYBUF 256
  19.  
  20. int sst_fd;
  21.  
  22. main( argc, argv )
  23. int argc;
  24. char *argv[];
  25.     {
  26.     int rrtn, wrtn;
  27.     unsigned char buf[MYBUF];
  28.     int file_fd;
  29.     int sighandler();
  30.  
  31.     sst_fd = sst_open( );
  32.     file_fd = 1;
  33.     (void) signal( SIGHUP, sighandler );
  34.     (void) signal( SIGINT, sighandler );
  35.  
  36.     if ( ioctl( sst_fd, AUDIOREADSTART, &rrtn ) < 0 )
  37.     {
  38.     perror( "AUDIOREADSTART" );
  39.     exit( 1 );
  40.     }
  41.  
  42.     for ( ; ; )
  43.     {
  44.     rrtn = read( sst_fd, buf, MYBUF );
  45.     if ( rrtn < 0 )
  46.         {
  47.         perror( "read" );
  48.         exit( 1 );
  49.         }
  50.     if ( rrtn == 0 )
  51.         break;
  52.  
  53.     wrtn = write( file_fd, buf, rrtn );
  54.     if ( wrtn < 0 )
  55.         {
  56.         perror( "write" );
  57.         exit( 1 );
  58.         }
  59.     if ( wrtn != rrtn )
  60.         {
  61.         fprintf( stderr, "record: rrtn = %d, wrtn = %d\n", rrtn, wrtn );
  62.         exit( 1 );
  63.         }
  64.     }
  65.  
  66.     sst_close( file_fd );
  67.     exit( 0 );
  68.     }
  69.  
  70. int
  71. sighandler( )
  72.     {
  73.     sst_close( sst_fd );
  74.     exit( 1 );
  75.     }
  76.