/* file_play.c */ /* * Copyright (c) 2001 Bruce R. Montague * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF * SUCH DAMAGE. */ /* * Program to play a PCM sound file. * * ">file_play foo.pcm" */ #include #include #include #include #include #define BUF_SIZE 512 /* Args: 0:progname 1:file_name */ /*--------------------------------------------------*/ int main( int argc, char *argv[] ) { char *file_name; if( argc != 2) { printf( "\n >file_play file_name\n\n" ); exit(1); } file_name = argv[1]; do_file_replay( file_name ); } /*--------------------------------------------------*/ int do_file_replay( char *file_name ) { char *buf_p; int fin, bytes_in; open_au_dev( "/dev/dsp", O_WRONLY ); fin = open( file_name, O_RDONLY, 0 ); if( !fin ) { printf( "\n Cant open file <%s>\n", file_name ); exit(1); } buf_p = malloc( BUF_SIZE ); if( !buf_p ) { printf( "\n Cant malloc!\n" ); exit(1); } for(;;) { bytes_in = read( fin, buf_p, 512 ); if( !bytes_in ) break; write_au_dev( buf_p, bytes_in ); } free( buf_p ); close( fin ); close_au_dev(); }