1 /**
2  * Example of recording to a bucket
3  *
4  * This program creates a bucket and records into it.  The input
5  * device's current gain and line mode are used.  You may want to use
6  * aupanel to adjust these.  Once the recording has finished, you can
7  * use audemo to play the bucket.  The bucket will be automatically
8  * destroyed when this program exits.
9  *
10  * $NCDId: @(#)recordBucket.c,v 1.1 1994/04/28 23:00:36 greg Exp $
11  */
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <audio/audiolib.h>
16 #include <audio/soundlib.h>
17 
18 static void
fatalError(const char * message,const char * arg)19 fatalError(const char *message, const char *arg)
20 {
21     fprintf(stderr, message, arg);
22     fprintf(stderr, "\n");
23     exit(1);
24 }
25 
26 static void
doneCB(AuServer * aud,AuEventHandlerRec * handler,AuEvent * ev,AuPointer data)27 doneCB(AuServer *aud, AuEventHandlerRec *handler, AuEvent *ev, AuPointer data)
28 {
29     AuBool         *done = (AuBool *) data;
30 
31     *done = AuTrue;
32 }
33 
34 int
main(int argc,char ** argv)35 main(int argc, char **argv)
36 {
37     AuServer       *aud;
38     AuBool          done;
39     AuEvent         ev;
40     AuDeviceAttributes *da = NULL;
41     AuBucketID      bucket;
42     int             i;
43 
44     if (!(aud = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL)))
45 	fatalError("Can't open audio server", NULL);
46 
47     if (!(bucket = AuCreateBucket(aud, AuFormatULAW8, 1, AuAccessAllMasks,
48 				  8000, 80000, NULL, NULL)))
49 	fatalError("Error creating bucket", NULL);
50 
51     /* look for a one track input device */
52     for (i = 0; i < AuServerNumDevices(aud); i++)
53 	if ((AuDeviceKind(AuServerDevice(aud, i)) ==
54 	     AuComponentKindPhysicalInput) &&
55 	    AuDeviceNumTracks(AuServerDevice(aud, i)) == 1)
56 	{
57 	    da = AuServerDevice(aud, i);
58 	    break;
59 	}
60 
61     if (!da)
62 	fatalError("Couldn't find appropriate input device", NULL);
63 
64     printf("Press return to begin recording\n");
65     getchar();
66 
67     AuSoundRecordToBucket(aud, bucket, AuDeviceIdentifier(da), AuDeviceGain(da),
68 			  doneCB, (AuPointer) &done, AuDeviceLineMode(da),
69 			  NULL, NULL, NULL);
70 
71     while (!done)
72     {
73 	AuNextEvent(aud, AuTrue, &ev);
74 	AuDispatchEvent(aud, &ev);
75     }
76 
77     printf("Press return to quit\n");
78     getchar();
79 }
80