Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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>
- #include <pulse/gccmacro.h>
- #define BUFSIZE 1024
- int main(int argc, char*argv[])
- {
- /* The sample type to use */
- static const pa_sample_spec ss =
- {
- .format = PA_SAMPLE_S16LE,
- .rate = 22050,
- .channels = 1
- };
- pa_simple *s = NULL; pa_simple *s2 = NULL;
- int ret = 1;
- int error;
- uint8_t buf[BUFSIZE];
- /* 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;
- }
- if (!(s2 = 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;
- }
- for (;;) {
- /* 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 play it */
- if (pa_simple_write(s2, buf, sizeof(buf), &error) < 0) {
- fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
- goto finish;
- }
- }
- finish:
- if (s)
- pa_simple_free(s);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment