#!../src/tops  -i -s ../sys  -u ../usr
/*
Program Tops - a stack-based computing environment
Copyright (C) 1999-2008  Dale R. Williamson

Author: Dale R. Williamson <dale.williamson@prodigy.net>

File test/tsnd  April 2008

This test writes sound bytes from file endoftheworld to the machine's 
sound card to produce speaker output.  Standard setup is assumed, with 
the sound card accessed through /dev/dsp.

File endoftheworld is from file snd-data-0.1.tar.Z, downloaded from 
   http://www.ibiblio.org/pub/Linux/kernel/sound/!INDEX.html

The original file is an 8-bit sound file with a header for a program
to play it.  The header has been removed from the file used for this 
test, since we are directly playing raw sound bytes and the non-sound 
header bytes cause a loud clicking.

----------------------------------------------------------------------*/

   if(!fname("/dev", "dsp"))
      exit(nl(.(" tsnd: sound device not found, test skipped")));

/* Open a handle called DSP to the standard sound device: */
   open("/dev/dsp", old, binary, "DSP");

   if(!rows(DSP)) exit(nl(dot("tsnd: error opening /dev/dsp")));

/* Open a handle called SONG to the file of sound bytes: */
   file(usrpath + "voice/endoftheworld", old, binary, "SONG");

   nl(.("tsnd: is speaker on?"));
   .("tsnd: writing bytes to /dev/dsp for about 25 seconds...");

/* Get all the SONG bytes and write them to DSP: */
   fput(fget(SONG, INF), DSP); 

   close(SONG);
   close(DSP);

   if(ercnt) exit();

   .(nl, "tsnd: test complete--ain't that a peach");

   nl; nl; nl;
