Project 2 Hints
- The sound file is here
- Test the audio device by writing the audio file to /dev/audio,
# cat pp.au > /dev/audio
- If you cannot hear anything from your headset, adjust volumes using the volume control applet(upper right corner of the screen) on the GNOME desktop(audioctl will not be provided).
- Please be advised that writing to /dev/audio is only allowed when you
are working from the console (you cannot write to /dev/audio with ssh.)
- If there's any problem with the sound system, report me EARLY!
- An example code for sound output
#include
#include
int main()
{
int fi, fo, n,i;
char buf[256];
fi = open("pp.au", O_RDONLY);
fo = open("/dev/audio", O_WRONLY | O_NONBLOCK);
for (i=0; i<300; ++i) {
read(fi, buf, sizeof(buf));
n = write(fo, buf, sizeof(buf));
printf("%d\n", n);
usleep(25000);
}
return 1;
}
You may notice that /dev/audio is opened with non-blocking mode since
we don't want the program blocks while playing sound; since we are using
only one process/thread the program should receive and process packets (also
feedback).
This example code writes 256 bytes to /dev/audio each time. 25ms of
usleep duration can be interpreted as your sigalarm interval. This
example sounds quite well. However, if you increase the usleep duration
you can hear some pause in playback. Likewise, if you decrease
the usleep duration the playback skips some data so that it makes some
scratch noise.