uses Ext.comment /* (c)David W. Barts (davidb@scn.org) / http://www.scn.org/~davidb Oakland, CA, USA --------------0F248FB38A4CAC17417D7469 Content-Type: text/plain; charset=us-ascii; name="audioout.fs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="audioout.fs" */ \ Simple access to the audio device in Linux via sox. Sox bugs stop \ us from being able to write 32-bit cells, so we're stuck with 16-bit \ integers. Icky. \ Sox command string. Change as needed. create sox-cmd s" sox -c 1 -r 44100 -t .uw - -t ossdsp -w -s /dev/dsp" string, 0 value sox-fileid \ Opens the audio device : open-audio ( -- ) sox-cmd count w/o open-pipe abort" ? Can't open audio device" to sox-fileid ; \ Writes out a single cell to the device. Depends on endianness \ to convert a 32-bit integer to a 16 bit one. Only the least \ significant 16 bits of the cell get written. variable _buffer : _write-aud 2 sox-fileid write-file \ write the 16-bit word abort" ? Error writing to audio device" ; 65535 _buffer ! _buffer c@ [if] \ Little endian code : write-aud-cell ( w -- ) _buffer ! _buffer _write-aud ; [else] \ Big endian code : write-aud-cell ( w -- ) _buffer ! _buffer 2 + _write-aud ; [then] \ Flushes the audio device : flush-audio sox-fileid flush-file abort" ? Error flushing audio device" ; \ Closes the audio device : close-audio ( -- ) sox-fileid close-file abort" ? Can't close audio device" ;