1

我正在尝试使用 simple.hpulseaudio头文件将我的声音从笔记本电脑上的麦克风录制到一个数组中,但我似乎无法弄清楚。每次我录制并重播我的录音时,我都会按照示例等发出尖锐的哔哔声,但我似乎无法理解这一点,有人可以帮助我吗?我基本上是在破解 doxygen 页面中给出的示例“parec-simple.c”。我尝试将输出路由bufstdout,然后使用 libre-office calc 绘制图表以查看输出是否看起来像声音,但事实并非如此。

这是我使用的代码

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

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

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

#define BUFSIZE 1024

FILE *output; 

/* A simple routine calling UNIX write() in a loop */
void loop_write(uint8_t *data) {
  register int size = 1023;

while (size > 0) 
{
    fprintf(output,"%"SCNu8"\n",data[size]  )  ;    
        size --;
    }

}

int main(int argc, char*argv[]) {
output = fopen("/home/donnell/output", "w");

/* The sample type to use */
static const pa_sample_spec ss = {
    .format = PA_SAMPLE_S16LE,
    .rate = 41000,
    .channels = 2
};
pa_simple *s = NULL;
int ret = 1;
int error;

/* Create the recording stream */
if (!(s = 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];

    /* Record some data ... */
    if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
        fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n",  pa_strerror(error));
        goto finish;
    }

   /* and write it to fle*/
loop_write(buf);

}

ret = 0;

finish:

if (s)
    pa_simple_free(s);

return ret;
}
4

0 回答 0