home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / samsee.zip / SAMSEE.C < prev    next >
Text File  |  1993-01-09  |  2KB  |  95 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <graph.h>
  4.  
  5.  
  6. #define X_MAX        640
  7. #define Y_MAX        350
  8. #define Y_DIV        2
  9. #define X_RANGE        (Y_DIV/2)
  10. #define Y_RANGE        90
  11. #define Y_START        (Y_RANGE/2)
  12. #define HLP_MSG        "syntax... SAMSEE {sample filename}\n"    \
  13. "View .VOC .WAV and raw audio sample files.\n"    \
  14. "NOTE: requires EGA or VGA\n" \
  15. "Press any key to exit.\n"
  16.  
  17. void seesam_exit( void );
  18.  
  19. void main( int argc, char * argv[] )
  20. {
  21.     FILE *fp;
  22.     int ypos = 0, xpos = 0;
  23.     static unsigned char sample_byte[1];
  24.     int sub_val = 0;
  25.     char c;
  26.     
  27.     if( NULL == argv[1] )
  28.     {
  29.         fprintf( stdout, "%s", HLP_MSG );
  30.         seesam_exit();
  31.     }
  32.  
  33.     if( NULL == ( fp = fopen( argv[1], "rb" ) ) )
  34.         seesam_exit();
  35.     if( ! strcmp( "SAM", strupr( ( argv[1]+(strlen(argv[1])-3) ) ) ) )
  36.         sub_val = 128;
  37.  
  38.  
  39.  
  40.     _setvideomode( _ERESCOLOR );
  41.  
  42.  
  43.     while(1)
  44.     {
  45.         for( ypos = Y_START; ypos < Y_MAX; ypos+=Y_RANGE+(Y_RANGE/4) )
  46.         {
  47.             /* draw red zero-line and reset begin of line position */
  48.             _moveto( 0, ypos );
  49.             _setcolor(4);
  50.             _lineto( 640, ypos );
  51.  
  52.             /* lower limit line */
  53.             _moveto( 0, ypos-(Y_RANGE/Y_DIV) );
  54.             _setcolor(7);
  55.             _lineto( 640, ypos-(Y_RANGE/Y_DIV) );
  56.  
  57.             /* upper limit line */
  58.             _moveto( 0, ypos+(Y_RANGE/Y_DIV) );
  59.             _setcolor(7);
  60.             _lineto( 640, ypos+(Y_RANGE/Y_DIV) );
  61.  
  62.             _moveto( 0, ypos );
  63.             _setcolor(2);
  64.  
  65.             for( xpos = 0; xpos < X_MAX; xpos+=X_RANGE )
  66.             {
  67.                 fread( sample_byte, 1, 1, fp );
  68.                 if( feof( fp ) )
  69.                     seesam_exit();
  70.  
  71.                 sample_byte[0]+=sub_val;
  72.  
  73.                 _lineto( (int)xpos,
  74.                     (int)( ( ( ( sample_byte[0] - 128 ) *
  75.                     Y_RANGE / 256 + ypos ) ) ) );
  76.             }
  77.         }
  78.         c = getch();
  79.         if( '\x1b' == c )
  80.         {
  81.             fprintf( stdout, "Press any key to exit." );
  82.             break;
  83.         }
  84.         _clearscreen( _GCLEARSCREEN );
  85.     }
  86.     seesam_exit();
  87. }
  88.  
  89. void seesam_exit( void )
  90. {
  91.     getch();
  92.     _setvideomode( _DEFAULTMODE );
  93.     exit(0);
  94. }
  95.