| 
 | 
版主,请问椅一下 
这程式录下来的档案能在电脑上播放吗? 
我自己照你所发表的程式码 
简化发现还是不能在电脑上播放 
不过倒是没有播放时会延迟的现象了 
附上程式码,请版主帮我分析一下,谢谢- //录音---------------------------------------
 
 - #include <stdio.h>
 
 - #include <stdlib.h>
 
 - #include <unistd.h>
 
 - #include <fcntl.h>
 
 - #include <errno.h>
 
 - #include <sys/ioctl.h>
 
 - #include <linux/soundcard.h>/*for OSS style sound programing */
 
 - #define FMT8BITS AFMT_U8 /*unsigned 8 bits(for almost PC) */
 
 - #define FMT16BITS AFMT_S16_LE /*signed 16 bits,little endian */
 
 - #define FMT8K    8000 /*default sampling rate */
 
 - #define FMT11K   11025 /*11,22,44,48 are three pop rate */
 
 - #define FMT22K   22050
 
 - #define FMT44K   44100
 
 - #define FMT48K  48000
 
 - #define MONO     1
 
 - #define STEREO   2
 
 - #define DFT_SND_DEV  "/dev/dsp"
 
 - #define DFT_SND_FMT  FMT16BITS
 
 - #define DFT_SND_SPD  FMT44K
 
 - #define DFT_SND_CHN  STEREO
 
 - #define BUFF_SIZE  100 /*buffer size:512 Bytes */
 
  
- /************** function implementation **************/
 
  
- unsigned int snd_fmt = DFT_SND_FMT; /*sound format,bits */
 
 - unsigned int snd_chn = DFT_SND_CHN; /*sound channel number */
 
 - unsigned int snd_spd = DFT_SND_SPD; /*sound speed,frequency */
 
 - unsigned char buff[BUFF_SIZE]; /*sound buffer */
 
  
- //---------------------------------------------------------------------------
 
  
- int main(void)
 
 - {
 
 -         int dev_fd; /*sound device descriptor */
 
 -         int file_fd; /*sound data file descrit */
 
  
-         ssize_t nRD;
 
 -         
 
 -         if ((dev_fd = open(DFT_SND_DEV, O_RDONLY)) < 0)
 
 -                 {
 
 -                         printf("open dev error !");
 
 -                         return (-1);
 
 -                 }
 
 -                 
 
 -         system("rm -f *.wav");        
 
 -         printf("kill *.wav\n");
 
 -         if ((file_fd = open("/sound.wav", O_CREAT | O_WRONLY)) < 0)
 
 -                 {
 
 -                         printf("open file error !\n");
 
 -                         return (-1);
 
 -                 }
 
 -                 
 
 -         int ioctl_val;
 
 -         /* set bit format */
 
 -         ioctl_val = snd_fmt;
 
 -         if (ioctl(dev_fd, SNDCTL_DSP_SETFMT, &ioctl_val) == -1)
 
 -         {
 
 -                 printf("Set fmt error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         /*set channel */
 
 -         ioctl_val = snd_chn;
 
 -         if ((ioctl(dev_fd, SNDCTL_DSP_CHANNELS, &ioctl_val)) == -1)
 
 -         {
 
 -                 printf("set channel error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         /*set speed */
 
 -         ioctl_val = snd_spd;
 
 -         if (ioctl(dev_fd, SNDCTL_DSP_SPEED, &ioctl_val) == -1)
 
 -         {
 
 -                 printf("set speed error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         
 
 -         while (1)
 
 -         {
 
 -                 if ((nRD = read(dev_fd, buff, BUFF_SIZE)) < 0)
 
 -                 {
 
 -                         printf("read sound device failed");
 
 -                         return (-3);
 
 -                 }
 
 -                 
 
 -                  write(file_fd, buff, nRD);
 
 -         }
 
 -         
 
 -         Close(dev_fd);
 
 -         Close(file_fd);
 
 -         return 0;
 
 - }
 
  
- //播放----------------------------------
 
 - #include <stdio.h>
 
 - #include <stdlib.h>
 
 - #include <unistd.h>
 
 - #include <fcntl.h>
 
 - #include <errno.h>
 
 - #include <sys/ioctl.h>
 
 - #include <linux/soundcard.h>/*for OSS style sound programing */
 
 - #define FMT8BITS AFMT_U8 /*unsigned 8 bits(for almost PC) */
 
 - #define FMT16BITS AFMT_S16_LE /*signed 16 bits,little endian */
 
 - #define FMT8K    8000 /*default sampling rate */
 
 - #define FMT11K   11025 /*11,22,44,48 are three pop rate */
 
 - #define FMT22K   22050
 
 - #define FMT44K   44100
 
 - #define FMT48K  48000
 
 - #define MONO     1
 
 - #define STEREO   2
 
 - #define DFT_SND_DEV  "/dev/dsp"
 
 - #define DFT_SND_FMT  FMT16BITS
 
 - #define DFT_SND_SPD  FMT44K
 
 - #define DFT_SND_CHN  STEREO
 
 - #define BUFF_SIZE  100 /*buffer size:512 Bytes */
 
  
- /************** function implementation **************/
 
  
- unsigned int snd_fmt = DFT_SND_FMT; /*sound format,bits */
 
 - unsigned int snd_chn = DFT_SND_CHN; /*sound channel number */
 
 - unsigned int snd_spd = DFT_SND_SPD; /*sound speed,frequency */
 
 - unsigned char buff[BUFF_SIZE]; /*sound buffer */
 
  
- //---------------------------------------------------------------------------
 
  
- int main(void)
 
 - {
 
 -         int dev_fd; /*sound device descriptor */
 
 -         int file_fd; /*sound data file descrit */
 
 -         ssize_t nRD; /*bytes readin */
 
 -         ssize_t nWR; /*bytes write out */
 
 -         
 
 -         if ((dev_fd = open(DFT_SND_DEV, O_WRONLY)) < 0)
 
 -                 {
 
 -                         printf("open dev error !\n");
 
 -                         return (-1);
 
 -                 }
 
 -                 
 
  
-         if ((file_fd = open("/sound.wav",  O_RDONLY)) < 0)
 
 -                 {
 
 -                         printf("open file error !\n");
 
 -                         return (-1);
 
 -                 }
 
 -                 
 
 -         int ioctl_val;
 
 -         /* set bit format */
 
 -         ioctl_val = snd_fmt;
 
 -         if (ioctl(dev_fd, SNDCTL_DSP_SETFMT, &ioctl_val) == -1)
 
 -         {
 
 -                 printf("set fmt error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         /*set channel */
 
 -         ioctl_val = snd_chn;
 
 -         if ((ioctl(dev_fd, SNDCTL_DSP_CHANNELS, &ioctl_val)) == -1)
 
 -         {
 
 -                 printf("set channel error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         /*set speed */
 
 -         ioctl_val = snd_spd;
 
 -         if (ioctl(dev_fd, SNDCTL_DSP_SPEED, &ioctl_val) == -1)
 
 -         {
 
 -                 printf("set speed error !\n");
 
 -                 return (-1);
 
 -         }
 
 -         
 
 -         while (1)
 
 -         {
 
 -                 nRD = 0L; /*read amount from sound device */
 
 -                 if ((nRD = read(file_fd, buff, BUFF_SIZE)) < 0)
 
 -                 {
 
 -                         printf("read sound data file failed\n");
 
 -                         return (-4);
 
 -                 }
 
 -                 else if (nRD == 0)
 
 -                 { 
 
 -                         break;
 
 -                 }
 
 -                 nWR = nRD;
 
 -                 write(dev_fd, buff, nWR);
 
 -         }
 
 -         
 
 - //        Close(dev_fd);
 
 - //        Close(file_fd);
 
 -         return 0;
 
 - }
 
  复制代码 |   
 
 
 
 |