diff options
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/audio.c b/src/audio.c index 0c40f9f..f7a51a5 100644 --- a/src/audio.c +++ b/src/audio.c @@ -1,3 +1,5 @@ +// TODO: Rewrite with alsa, fuck pulseaudio + #include <stdio.h> #include <unistd.h> #include <string.h> @@ -10,19 +12,20 @@ #include "typedef.h" static const pa_sample_spec ss = { - .format = PA_SAMPLE_S16LE, + .format = PA_SAMPLE_S16BE, .rate = 44100, - .channels = 1 + .channels = 2 }; static pa_simple *play = NULL; +static pa_simple *rec = NULL; -int audip_play(char *buf) +int audio_play(char *buf) { int ret = 1; int error; - if(!play) { + if(play == NULL) { if (!(play = pa_simple_new(NULL, __FILE__, PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; @@ -43,38 +46,34 @@ int audip_play(char *buf) finish: - if (play) - pa_simple_free(play); + // if (play) + // pa_simple_free(play); return ret; } -int audio_record(int fd) +int audio_record(char *buf) { - pa_simple *rec = NULL; int ret = 1; int error; - if (!(rec = pa_simple_new(NULL, __FILE__, PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { - fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); - goto finish; - } - - for(;;) - { - char buf[REC_CAP]; - - if (pa_simple_read(rec, buf, sizeof(buf), &error) < 0) { - fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error)); + if(!rec) { + if (!(rec = pa_simple_new(NULL, __FILE__, PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { + fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } + } - write(fd, buf, sizeof(buf)); + if (pa_simple_read(rec, buf, REC_CAP, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error)); + goto finish; } + ret = 0; + finish: - if(rec) - pa_simple_free(rec); + // if(rec) + // pa_simple_free(rec); return ret; } |