以下程序是可以正常运行的:
#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库提供的打开设备调用函数,
这里我们指定打开缺省的音频设备,并根据参数