From: http://doc.chinaunix.net/linux/200310/216273.shtml
Publisher: chinaitlab Date: 00:00:00 views: 0 (total _ Comments) view comments | I want to comment
Through the unremitting efforts of Xiaodi, he finally mastered sound card programming and realized a small recording.
Program, // hehe // admire
Of course it is still not perfect. I still have some details that I don't know very well. // shy. I will post the original code. Please help me.
Positive, // Xixi
# Include
# Include
# Include
# Include
# Include
Main ()
{
Int ID, FD, I, j;
Char testbuf [4096];
Id = open ("/dev/Audio", o_rdwr );
FD = open ("test.wav", o_rdwr );
If (ID <0 | FD <0 ){
Printf ("error in open the device! \ N ");
Printf ("ID % d \ t DSP % d \ t seq % d \ n", ID, DSP, SEQ );
Exit (-1 );
}
Post = 0;
IOCTL (ID, sndctl_dsp_reset, (char *) & I );
IOCTL (ID, sndctl_dsp_sync, (char *) & I );
I = 1;
IOCTL (ID, sndctl_dsp_nonblock, (char *) & I );
I = 8000;
IOCTL (ID, sndctl_dsp_speed, (char *) & I );
I = 1;
IOCTL (ID, sndctl_dsp_channels, (char *) & I );
I = 8;
IOCTL (ID, sndctl_dsp_setfmt, (char *) & I );
I = 3;
IOCTL (ID, sndctl_dsp_settrigger, (char *) & I );
I = 3;
IOCTL (ID, sndctl_dsp_setfragment, (char *) & I );
I = 1;
IOCTL (ID, sndctl_dsp_profile, (char *) & I );
For (j = 0; j <10 ;){
I = read (ID, testbuf, 4096 );
If (I> 0 ){
Write (FD, filebuf, I );
J ++;
}
}
Close (FD );
Close (ID );
}
The program simply stores pure audio frequency data in test.wav and uses commands
Cat test.wav>/dev/Audio can be played.
By the way, because the program needs to read and write the device files of the sound card, you must use the corresponding permissions, or
You are root.