linux录音跳过无效数据,linux下无法得到音频流,望有人讲解清楚录音原理,分不够再加解决方案...

C/C++ codeint Audio_Record(char *pathname,int nSampleRate,int nChannels,int fmt)

{

int dsp_fd,mix_fd,status,arg;

dsp_fd = open("/dev/dsp" , O_RDWR);  /*open dsp*/

if(dsp_fd < 0)

{

return  OPEN_DSP_FAILED;

}

// arg = nSampleRate;

//status = ioctl(dsp_fd,SOUND_PCM_READ_RATE,&arg); /*set samplerate*/

/**

if(status < 0)

{

close(dsp_fd);

return SAMPLERATE_STATUS;

}

if(arg != nSampleRate)

{

close(dsp_fd);

return SET_SAMPLERATE_FAILED;

}

**/

// arg = nChannels;  /*set channels*/

// status = ioctl(dsp_fd, SOUND_PCM_READ_CHANNELS, &arg);

/**

if(status < 0)

{

close(dsp_fd);

return CHANNELS_STATUS;

}

if( arg != nChannels)

{

close(dsp_fd);

return SET_CHANNELS_FAILED;

}

**/

// arg = fmt; /*set bit fmt*/

//status = ioctl(dsp_fd, SOUND_PCM_READ_BITS, &arg);

/**

if(status < 0)

{

close(dsp_fd);

return FMT_STATUS;

}

if(arg != fmt)

{

close(dsp_fd);

return SET_FMT_FAILED;

}

**/

arg = 0;

ioctl( dsp_fd, SNDCTL_DSP_RESET, (char *)&arg );

ioctl( dsp_fd, SNDCTL_DSP_SYNC, (char *)&arg );

arg = 1;

ioctl( dsp_fd, SNDCTL_DSP_NONBLOCK, (char*)&arg );

arg = nSampleRate;

ioctl( dsp_fd, SNDCTL_DSP_SPEED, (char *)&arg );

arg = nChannels;

ioctl( dsp_fd, SNDCTL_DSP_STEREO, 0 );

ioctl( dsp_fd, SNDCTL_DSP_CHANNELS, (char *)&arg );

arg = fmt;

ioctl( dsp_fd, SNDCTL_DSP_SETFMT, (char*)&arg );

arg = 3;

ioctl( dsp_fd, SNDCTL_DSP_SETTRIGGER, (char*)&arg );

arg = 3;

ioctl( dsp_fd, SNDCTL_DSP_SETFRAGMENT, (char*)&arg );

arg = 1;

ioctl( dsp_fd, SNDCTL_DSP_PROFILE, (char*)&arg );

FILE *file_fd = fopen(pathname,"w+");

if(file_fd == NULL)

{

close(dsp_fd);

return OPEN_FILE_FAILED;

}

int num = 2 * nChannels*nSampleRate*fmt/8;

int get_num;

unsigned char buf[num];

// Record

int j = 0;

while( 1 )

{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值