/*  Copyright (C) 1996  Byron Stanoszek
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 **************************************************************************/

/* snddriv.c */

/* the main program that runs in the background, playing all the music */


#include "sound.h"

#define NUMFRAG 12		/* number of fragments in buffer */

void main(argc, argv)
int argc;
char *argv[];
{
  int a, siz, audio, f=open(argv[1], O_RDONLY);
  char buf[16384];

  /* try to open the audio file */
  if((audio = open("/dev/dsp", O_WRONLY, 0)) < 0) {
    perror("/dev/dsp");
    exit(1);
  }

  if(argc > 2)
    lseek(f, atol(argv[2]), SEEK_END);

/*a=(NUMFRAG*65536)+14;   * 16384 bytes per fragment *
  ioctl(audio, SNDCTL_DSP_SETFRAGMENT, &a); */

  a=16;
  ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &a);
  a=1;
  ioctl(audio, SNDCTL_DSP_STEREO, &a);
  a=22050;
  ioctl(audio, SNDCTL_DSP_SPEED, &a);

  while((siz=read(f, buf, 16384)) > 0)
    write(audio, buf, siz);
}