3.4.1
Sound devices
The sound driver creates two devices; /dev/sound/dsp and /dev/sound/mixer.
The first device (’/dev/sound/dsp’) is used to play and record sound. It con-
trols the behaviour of the audio A/D and D/A converters. The mixer device
(’/dev/sound/mixer’) is used to change the input levels and output volumes
in our case.
The two devices are standard files that can be opened using standard C
library ’open’ function.
fd = open( "/dev/sound/dsp" , O_RDWR );
if ( fd < 0 ) {
/* opening failure */
}
...
fd = open( "/dev/sound/mixer" , O_RDWR );
if ( fd < 0 ) {
/* opening failure */
}
To play sound or music, the ’write’ function on device ’/dev/sound/dsp’
must be used.
/* open a wave file to play */
wav_fd = open( "test.wav" , O_RD );
if ( wav_fd < 0 ) {
/* opening error */
}
/* open the sound device */
dsp_fd = open( "/dev/sound/dsp" , O_RDWR );
if ( dsp_fd < 0 ) {
/* opening error */
}
...
while (1)
{
/* read some samples from the wave file */
cnt = read( wav_fd , buf , sizeof(buf) );
if ( cnt == EOF ) break;
/* write the samples into the sound device */
write( dsp_fd , buf , cnt );
}
...
K-Team S.A.
8