关于Linux下alsa录音程序移植出现的奇怪问题

在将Linux下的alsa录音程序进行移植时遇到一个奇怪的问题,只有当read_flag1变量作为全局变量或在函数内声明为静态时,程序才能正常运行。目前尚未深入理解导致此错误的具体原因。
摘要由CSDN通过智能技术生成

以下程序是可以正常运行的:

#include <alsa/asoundlib.h>
#include <math.h>
#include <pthread.h>
#include <string.h>

#define BUFFERSIZE 4096
#define PERIOD_SIZE 1024
#define PERIODS 2
#define SAMPLE_RATE 16000
#define CHANNELS 1
#define FSIZE 2*CHANNELS

/* Use the newer ALSA API */
#define ALSA_PCM_NEW_HW_PARAMS_API

long loops; //define the record time.
int rc;	//return code.
int size;
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;//定义参数变量
unsigned int val;	
int dir;
snd_pcm_uframes_t frames;
char *buffer;	
int err;
char *file;
int fd_pcm;
int read_flag1=0;
	
/*放音初始化*/
int init_pcm_play_dri(void)
{
	/*snd_pcm_open (&pcm_handle, “default” , mode , 0)
	snd_pcm_open是Alsa库提供的打开设备调用函数,
	这里我们指定打开缺省的音频设备,并根据参数mode将
	设备置为录音或是播放状态,如果设备打开成功,
	pcm_handle便指向该设备句柄,我们用全局变量保存
	起来,方便以后使用。*/	
	rc = snd_pcm_open(&handle, "default",SND_PCM_STREAM_PLAYBACK, 0);
	
	if (rc < 0) {
		fprintf(stderr,"unable to open pcm device: %s\n",snd_strerror(rc));
		exit(1);
	}

	/* Allocate a hardware parameters object. */
	snd_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值