playraw.c 1017 Bytes
#include "playraw.h"

#define BSIZE 1024
#define DEF_FS 44100

char usage[] = "[-h -s -f rate] <infile";

main(int argc, char *argv[])
{
  extern char 	*optarg;
  extern int	optind, opterr;	
  int 	c;			/* Required for getopt(); */

  char *progname = argv[0];
  
  int lin_buffer[BSIZE], rin_buffer[BSIZE], eof, i, channels;
  int fs = DEF_FS;

  channels = 1;
  while ((c=getopt(argc,argv,"hsf:"))!=-1)
  switch (c) {
      case 'h':
          fprintf(stderr,"%s %s\n",progname,usage);
          exit(1);
          break;
      case 's':
          channels = 2;
          break;
  case 'f':
      if (sscanf(optarg,"%f",&fs)!=1)
          fs = DEF_FS;
          break;
  }

  initaudio(channels,fs);
  eof = 0;
  while(eof==0){
    switch (channels) {
    case 1:
      eof = getmonodata(stdin, eof, BSIZE, lin_buffer);
      break;
    case 2:
      eof = getstereodata(stdin, eof, BSIZE, lin_buffer, rin_buffer);
      break;
    }
  writeout(NULL, BSIZE, lin_buffer, rin_buffer, channels);
  }
  clearaudio();
}