4
* Minimal record and playback test.
11
/* #include <getopt.h> */
19
#include <sys/soundcard.h>
21
#define NUM_BYTES (64*1024)
22
#define BLOCK_SIZE (4*1024)
24
#define AUDIO "/dev/dsp"
26
char buffer[NUM_BYTES];
30
main (int argc, char *argv[])
37
/********** RECORD ********************/
38
/* Open audio device. */
39
audioDev = open (AUDIO, O_RDONLY, 0);
46
/* Set to 16 bit samples. */
48
ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
51
perror("Unable to set the sample size.");
55
/* Record in blocks */
56
printf("Begin recording.\n");
59
while( numLeft >= BLOCK_SIZE )
61
if ( (num = read (audioDev, ptr, BLOCK_SIZE)) < 0 )
68
printf("Read %d bytes\n", num);
76
/********** PLAYBACK ********************/
77
/* Open audio device for writing. */
78
audioDev = open (AUDIO, O_WRONLY, 0);
85
/* Set to 16 bit samples. */
87
ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
90
perror("Unable to set the sample size.");
95
printf("Begin playing.\n");
98
while( numLeft >= BLOCK_SIZE )
100
if ( (num = write (audioDev, ptr, BLOCK_SIZE)) < 0 )
107
printf("Wrote %d bytes\n", num);