123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <pulse/simple.h>
- #include <pulse/error.h>
- #include "medianame.h"
- int main(int argc, char*argv[]) {
- int fps = 305;
-
- const uint32_t bufsize = ((48000 * 2 * 2 * 10) / fps) & ~3;
- if (argc != 2) {
- printf("usage: prog fps*10, run in recording directory\n");
- exit(1);
- }
- fps = atoi(argv[1]);
-
- static const pa_sample_spec ss = {
- .format = PA_SAMPLE_S16LE,
- .rate = 48000,
- .channels = 2
- };
- static pa_buffer_attr attr = {
- .minreq = (uint32_t) -1,
- .prebuf = (uint32_t) -1,
- .tlength = (uint32_t) -1,
- };
- pa_simple *r = NULL;
- int ret = 1;
- int error;
- const pa_buffer_attr *p_attr = &attr;
- int opt = 0;
- uint8_t *buf = malloc(bufsize);
- attr.fragsize = bufsize;
- attr.maxlength = bufsize;
-
- if (!(r = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD | opt, NULL, "record", &ss, NULL, p_attr, &error))) {
- fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
- goto finish;
- }
- for (;;) {
- char name[1024];
- int fd, res;
-
- if (pa_simple_read(r, buf, bufsize, &error) < 0) {
- fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
- goto finish;
- }
- get_name(name, ".", "48000-s16le-stereo.sa");
- fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
- res = write(fd, buf, bufsize);
- if (res != bufsize) {
- fprintf(stderr, __FILE__": could not write samples: %m\n");
- goto finish;
- }
- close(fd);
- }
- finish:
- if (r)
- pa_simple_free(r);
- return ret;
- }
|