To record sound or music, the ’read’ function is used.
/* open a wave file to play */
wav_fd = open( "test.wav" , O_RDWR );
if ( wav_fd < 0 ) {
/* opening error */
}
/* open the sound device */
dsp_fd = open( "/dev/sound/dsp" , O_RDWR );
if ( dsp_fd < 0 ) {
/* opening error */
}
...
/*
* select the first input IN1 in setting
* the gain level at maximum value (100%)
*/
mix_fd = open( "/dev/sound/mixer" , O_RDWR );
value = 100;
ioctl( mix_fd , SOUND_MIXER_LINE1 , &value );
close( mix_fd );
...
while (1)
{
/* record some samples from the sound device */
cnt = read( dsp_fd , buf , sizeof(buf));
/* write the samples into the wave file */
write( dsp_fd , buf , cnt );
...
}
...
As you could see in the last example, the input channel is selected by
calling the SOUND MIXER LINE1 I/O control. This I/O control changes
the gain level of the input 1 and selects the input 1 for recording.
3.4.2
Sound device I/O controls
The I/O control are useful to read and to change the settings of the sound
device. Only the sampling rate can be changed.
Supported I/O control commands:
K-Team S.A.
9