]> code.delx.au - pulseaudio/blob - polyp/pacat-simple.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / pacat-simple.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <errno.h>
30
31 #include <polyp/polyplib-simple.h>
32 #include <polyp/polyplib-error.h>
33
34 #define BUFSIZE 1024
35
36 int main(int argc, char*argv[]) {
37
38 /* The Sample format to use */
39 static const struct pa_sample_spec ss = {
40 .format = PA_SAMPLE_S16LE,
41 .rate = 44100,
42 .channels = 2
43 };
44
45 struct pa_simple *s = NULL;
46 int ret = 1;
47 int error;
48
49 /* Create a new playback stream */
50 if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, PA_VOLUME_NORM, &error))) {
51 fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
52 goto finish;
53 }
54
55 for (;;) {
56 uint8_t buf[BUFSIZE];
57 ssize_t r;
58
59 #if 0
60 pa_usec_t latency;
61
62 if ((latency = pa_simple_get_playback_latency(s, &error)) == (pa_usec_t) -1) {
63 fprintf(stderr, __FILE__": pa_simple_get_playback_latency() failed: %s\n", pa_strerror(error));
64 goto finish;
65 }
66
67 fprintf(stderr, "%0.0f usec \r", (float)latency);
68 #endif
69
70 /* Read some data ... */
71 if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
72 if (r == 0) /* EOF */
73 break;
74
75 fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
76 goto finish;
77 }
78
79 /* ... and play it */
80 if (pa_simple_write(s, buf, r, &error) < 0) {
81 fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
82 goto finish;
83 }
84 }
85
86 /* Make sure that every single sample was played */
87 if (pa_simple_drain(s, &error) < 0) {
88 fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));
89 goto finish;
90 }
91
92 ret = 0;
93
94 finish:
95
96 if (s)
97 pa_simple_free(s);
98
99 return ret;
100 }