4 This file is part of polypaudio.
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
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/types.h>
34 #include <polypcore/util.h>
35 #include <polypcore/mcalign.h>
36 #include <polypcore/gccmacro.h>
38 /* A simple program for testing pa_mcalign */
40 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
41 pa_mcalign *a = pa_mcalign_new(11, NULL);
44 pa_memchunk_reset(&c);
53 c.memblock = pa_memblock_new(2048, NULL);
54 c.index = c.length = 0;
57 assert(c.index < c.memblock->length);
59 l = c.memblock->length - c.index;
61 l = l <= 1 ? l : rand() % (l-1) +1 ;
63 if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) {
64 fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
69 pa_mcalign_push(a, &c);
70 fprintf(stderr, "Read %ld bytes\n", (long)r);
74 if (c.index >= c.memblock->length) {
75 pa_memblock_unref(c.memblock);
76 pa_memchunk_reset(&c);
82 if (pa_mcalign_pop(a, &t) < 0)
85 pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length);
86 fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length);
88 pa_memblock_unref(t.memblock);
95 pa_memblock_unref(c.memblock);