Guest User

Pulse Audio RecPlay

a guest
Mar 25th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <fcntl.h>
  10.  
  11. #include <pulse/simple.h>
  12. #include <pulse/error.h>
  13. #include <pulse/gccmacro.h>
  14.  
  15. #define BUFSIZE 1024
  16.  
  17. int main(int argc, char*argv[])
  18. {
  19.     /* The sample type to use */
  20.     static const pa_sample_spec ss =
  21.     {
  22.         .format = PA_SAMPLE_S16LE,
  23.         .rate = 22050,
  24.         .channels = 1
  25.     };
  26.     pa_simple *s = NULL; pa_simple *s2 = NULL;
  27.     int ret = 1;
  28.     int error;
  29.             uint8_t buf[BUFSIZE];
  30.  
  31.     /* Create the recording stream */
  32.     if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
  33.         fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
  34.         goto finish;
  35.     }
  36.    
  37.     if (!(s2 = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
  38.         fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
  39.         goto finish;
  40.     }    
  41.    
  42.         for (;;) {
  43.  
  44.  
  45.         /* Record some data ... */
  46.         if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
  47.             fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
  48.             goto finish;
  49.         }
  50.  
  51.         /* ... and play it */
  52.         if (pa_simple_write(s2, buf, sizeof(buf), &error) < 0) {
  53.           fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
  54.            goto finish;
  55.         }
  56.     }
  57.  
  58.    finish:
  59.  
  60.     if (s)
  61.         pa_simple_free(s);
  62.  
  63.     return ret;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment