本文介绍了pulseaudio的录制和回放失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图记录和回放采用脉冲音频API中的CentOS 6.2的音频数据。但它可记录和重放什么。我使用的一个code。我需要帮助得到它在我的电脑工作。我该怎么办?我的code也被如下 -

 下列块#ifdef HAVE_CONFIG_H
#包括LT&;&config.h文件GT;
#万一#包括LT&;&stdio.h中GT;
#包括LT&;&unistd.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&errno.h中GT;
#包括LT&;&fcntl.h GT;#包括LT&;脉冲/ simple.h>
#包括LT&;脉冲/ error.h>的#define BUFSIZE 32INT主(INT ARGC,CHAR *的argv []){/ *样本格式使用* /
静态常量pa_sample_spec SS = {
    .format = PA_SAMPLE_S16LE,
    .rate = 44100,
    .channels = 2
};pa_simple * s_in,* s_out = NULL;
INT RET = 1;
INT错误;
/ *创建一个新的播放流* /
如果((s_out = pa_simple_new(NULL,argv的[0],PA_STREAM_PLAYBACK,NULL,回放,&安培;!SS,NULL,NULL,&安培;错误))){
    fprintf中(标准错误,__FILE__:pa_simple_new()失败:%S \\ n,pa_strerror(错误));
    转到整理;
}  如果((s_in = pa_simple_new(NULL,argv的[0],PA_STREAM_RECORD,NULL,记录,&安培;!SS,NULL,NULL,&安培;错误))){
    fprintf中(标准错误,__FILE__:pa_simple_new()失败:%S \\ n,pa_strerror(错误));
    转到整理;
}为(;;){
    uint8_t有BUF [BUFSIZE];
    ssiz​​e_t供ř;1#如果
    pa_usec_t延迟;    如果((延迟= pa_simple_get_latency(s_in,&安培;错误))==(pa_usec_t)-1){
        fprintf中(标准错误,__FILE__:pa_simple_get_latency()失败:%S \\ n,pa_strerror(错误));
        转到整理;
    }    fprintf中(标准错误,在:%0.0微秒\\ r \\ n,(浮点)延迟);    如果((延迟= pa_simple_get_latency(s_out,&安培;错误))==(pa_usec_t)-1){
        fprintf中(标准错误,__FILE__:pa_simple_get_latency()失败:%S \\ n,pa_strerror(错误));
        转到整理;
    }    fprintf中(标准错误,出:%0.0微秒\\ r \\ n,(浮点)延迟);
#万一    如果(pa_simple_read(s_in,BUF,sizeof的(BUF),放大器;错误)小于0){        fprintf中(标准错误,__FILE__:阅读()失败:%S \\ n字符串错误(错误));
        转到整理;
    }    / * ...并播放* /
    如果(pa_simple_write(s_out,BUF,sizeof的(BUF),放大器;错误)小于0){
        fprintf中(标准错误,__FILE__:pa_simple_write()失败:%S \\ n,pa_strerror(错误));
        转到整理;
    }
}/ *确保每一个样品被演奏* /
如果(pa_simple_drain(s_out,&安培;误差)小于0){
    fprintf中(标准错误,__FILE__:pa_simple_drain()失败:%S \\ n,pa_strerror(错误));
    转到整理;
}RET = 0;完:如果(s_in)
    pa_simple_free(s_in);
如果(s_out)
    pa_simple_free(s_out);返回RET;
}


解决方案

成功完成。这是在我的操作系统错误,因为我还没有更新了一段时间的插件。后重新安装它的工作操作系统。
谢谢

I am trying to record and playback audio data using pulse audio API in centOS 6.2. But it records and playbacks nothing. I am using a code from pulseaudio. I need help to get it working in my PC. What should I do? My code is also given below-

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

#include <pulse/simple.h>
#include <pulse/error.h>

#define BUFSIZE 32

int main(int argc, char*argv[]) {

/* The Sample format to use */
static const pa_sample_spec ss = {
    .format = PA_SAMPLE_S16LE,
    .rate = 44100,
    .channels = 2
};

pa_simple *s_in, *s_out = NULL;
int ret = 1;
int error;


/* Create a new playback stream */
if (!(s_out = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
    fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
    goto finish;
}

  if (!(s_in = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
    fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
    goto finish;
}

for (;;) {
    uint8_t buf[BUFSIZE];
    ssize_t r;

#if 1
    pa_usec_t latency;

    if ((latency = pa_simple_get_latency(s_in, &error)) == (pa_usec_t) -1) {
        fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));
        goto finish;
    }

    fprintf(stderr, "In:  %0.0f usec    \r\n", (float)latency);

    if ((latency = pa_simple_get_latency(s_out, &error)) == (pa_usec_t) -1) {
        fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));
        goto finish;
    }

    fprintf(stderr, "Out: %0.0f usec    \r\n", (float)latency);
#endif

    if (pa_simple_read(s_in, buf, sizeof(buf), &error) < 0) {

        fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
        goto finish;
    }

    /* ... and play it */
    if (pa_simple_write(s_out, buf, sizeof(buf), &error) < 0) {
        fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
        goto finish;
    }
}

/* Make sure that every single sample was played */
if (pa_simple_drain(s_out, &error) < 0) {
    fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));
    goto finish;
}

ret = 0;

finish:

if (s_in)
    pa_simple_free(s_in);
if (s_out)
    pa_simple_free(s_out);

return ret;
}
解决方案

Successfully done. It was an error in my OS, because I haven't updated the plugins for a while. After re-installing the OS it worked.Thanks

这篇关于pulseaudio的录制和回放失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 20:52