Sound on PI?? Help!!
dave "who can do? ratmandu!" ratcliffe
dave at sgi.com
Tue Oct 9 01:53:18 AEST 1990
In article <8868 at jarthur.Claremont.EDU> al at iris.claremont.edu (Mike Medlin) writes:
>I am stumbling around trying to figure out how to listen to sound
>samples on my Personal Iris. I have some samples in IBM format and some in
>mac format, as well as some that are called "generic" Is there anyone out
>there who can lend me a hand on how to listen to any/all of these on the IRIS??
>Please assume that I have no knowledge of the sound capabilities of the IRIS
>or how sound files are set up/read (which is darn close to the truth) If
>someone could tell me step by step how to listen to the files I have, I would
>gladly share them with you. Do I need a conversion program: mac-->iris or
>ibm-->iris?
not a sound-master in any capacity myself, but would the below from
/usr/people/4Dgifts/examples/audio/audio.c help you out at all?
/*
* audio.c:
*
* This test program was initially written to demonstrate how one would
* digitally record microphone input to a Personal Iris and place the data
* into a file (execute "audio -i -opts"). Alternately, you can play back
* the sounds or voice that you have recorded (execute "audio -o -opts").
* All that is needed to use this program is an 8 ohm speaker connected to
* the audio output and a 600 ohm microphone connected to the microphone
* input. The other audio input may be used to connect a higher level audio
* signal that doesn't require pre-amplification.
*
* resusitated by (& hats off to) Frank Demcak -- February, 1990
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/audio.h>
main(argc, argv)
int argc;
char *argv[];
{
int size, gain=100, rate=2, iflag, oflag, gflag, sflag, fflag,rflag;
char *file, *buffer;
int in, out, audio,i;
if ( argc == 1 ) {
usage:
fprintf(stderr,"usage: %s -i [-g (0-255)gain] ", argv[0]);
fprintf(stderr,"[-r (0-3)rate] -f file [-s size]\n");
fprintf(stderr," %s -o [-g (0-255)gain] ", argv[0]);
fprintf(stderr,"[-r (0-3)rate] -f file [-s size]\n");
exit(1);
}
/* Parse the record/playback options */
for ( i = 1; i < argc; i++ ) {
if ( !strcmp(argv[i],"-i") )
iflag++;
else if ( !strcmp(argv[i],"-o") )
oflag++;
else if ( !strcmp(argv[i],"-g") ) {
gflag++;
gain = atoi(argv[++i]);
} else if ( !strcmp(argv[i],"-r") ) {
rflag++;
rate = atoi(argv[++i]);
} else if ( !strcmp(argv[i],"-f") ) {
fflag++;
file = argv[++i];
} else if ( !strcmp(argv[i],"-s") ) {
sflag++;
size = atoi(argv[++i]);
} else
goto usage;
}
/* Open input or output file for record/playback */
if ( iflag ) {
if (fflag) {
/* Create a Read Write file and set permissions */
out = open(file, O_CREAT|O_RDWR);
chmod (file,00666);
} else
out = 1;
} else if ( oflag ) {
if (fflag)
/* Just open file for reading */
in = open(file, O_RDONLY);
else
in = 0;
} else {
fprintf(stderr, "must specify one of -o or -i\n");
exit(1);
}
/* printf test diag statements
printf("iflag=%i\n",iflag);
printf("oflag=%i\n",oflag);
printf("gflag=%i\n",gflag);
printf(" gain =%d\n",gain);
printf("rflag=%i\n",rflag);
printf(" rate =%d\n",rate);
printf("fflag=%i\n",fflag);
printf(" file Name=%s\n",file);
printf("sflag=%i\n",sflag);
printf(" file size=%d\n",size);
*/
/* Open audio port as a character device */
audio = open( "/dev/audio", O_RDWR );
/* This part doesn't seem to work as advertised */
/* Investigating how to turn off output while input is being recorded */
if ( gflag )
if ( iflag ) {
ioctl(audio, AUDIOCSETINGAIN, gain);
ioctl(audio, AUDIOCSETOUTGAIN, 0);
} else {
ioctl(audio, AUDIOCSETINGAIN, 0);
ioctl(audio, AUDIOCSETOUTGAIN, gain);
}
/* set audio sampling rate 0=none?,1=8k,2=16k,3=32k samples per sec */
if ( rflag )
ioctl(audio, AUDIOCSETRATE, rate);
if ( iflag ) {
if ( ! sflag ) {
fprintf(stderr,"must set a size for input\n");
exit (1);
}
buffer = (char *)malloc( size );
if ( ! buffer ) {
fprintf(stderr,"unable to get %d byte buffer\n",size);
exit(1);
}
read(audio,buffer,size);
write(out,buffer,size);
} else {
/* Assume this is an sound output request */
/* Default buffer size = 16k if nothing is specified */
if ( ! sflag )
size = 16536;
buffer = (char *)malloc( size );
if ( ! buffer ) {
fprintf(stderr,"unable to get %d byte buffer\n",size);
exit(1);
}
/*
Write to audio port the contents of specified file until EOF
This can be improved for simultaneous read/writes
Insert user customization for specific file or usr needs i.e.
while (read(in,buffer,size)!=EOF) write (audio,buffer,size);
*/
read (in,buffer,size);
write(audio,buffer,size);
}
close(file);
}
More information about the Comp.sys.sgi
mailing list