Linux recording applet, a little problem. Could you please help me?
Source: Internet
Author: User
The linux recording applet has some minor issues. Please take a look at the general Linux technology-Linux technology and application information for me. The following is a detailed description. Fd = open ("/dev/dsp", O_RDWR );
Fd2 = open ("/tmp/shengdao/sund", O_WRONLY );
Below is part of my recording code, which can be normally played back after recording. However, I added a code to point the voice data written into fd2 to the file. After this code runs for a while, I stopped running.
While (1 ){
Printf ("Say something: \ n ");
Status = read (fd, buf, sizeof (buf);/* recording */
If (write (fd2, buf, status) <0) // write the file
{
Printf ("write/tmp/shengdao/sund fail \ n ");
}
If (status! = Sizeof (buf ))
Perror ("read wrong number of bytes ");
Printf ("You said: \ n ");
Status = write (fd, buf, sizeof (buf);/* playback */
If (status! = Sizeof (buf ))
Perror ("wrote wrong number of bytes ");
/* Wait until the playback ends before resuming recording */
Status = ioctl (fd, SOUND_PCM_SYNC, 0 );
If (status =-1)
Perror ("SOUND_PCM_SYNC ioctl failed ");
}
I have modified the code based on the above, and read the sound data from the file pointed to by fd2 for playback. The following is the code, but I don't know why, that is, you cannot play the sound that I recorded before.
While (1 ){
Status = read (fd2, buf, sizeof (buf);/* read data */
Printf ("You said: \ n ");
Status = write (fd, buf, sizeof (buf);/* play sound */
If (status! = Sizeof (buf ))
Perror ("wrote wrong number of bytes ");
}
Could you please help me see why? I 've been entangled for a few days.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service